Skip to content

Commit 12fe053

Browse files
CopilotUltiRequiem
andcommitted
Add comprehensive test suite for rustico crate
Co-authored-by: UltiRequiem <[email protected]>
1 parent d5fa64e commit 12fe053

File tree

7 files changed

+736
-0
lines changed

7 files changed

+736
-0
lines changed

rustico/tests/basic_syntax.rs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Test basic syntax translations
2+
3+
#[test]
4+
fn test_basic_function() {
5+
rustico::rustico! {
6+
función prueba() -> e32 {
7+
retorna 42;
8+
}
9+
}
10+
11+
assert_eq!(prueba(), 42);
12+
}
13+
14+
#[test]
15+
fn test_let_and_mut() {
16+
rustico::rustico! {
17+
función prueba_variables() -> e32 {
18+
sea x = 5;
19+
sea mutable y = 10;
20+
y = y + x;
21+
retorna y;
22+
}
23+
}
24+
25+
assert_eq!(prueba_variables(), 15);
26+
}
27+
28+
#[test]
29+
fn test_if_else() {
30+
rustico::rustico! {
31+
función prueba_condicional(val: e32) -> e32 {
32+
si val > 10 {
33+
retorna 1;
34+
} sino {
35+
retorna 0;
36+
}
37+
}
38+
}
39+
40+
assert_eq!(prueba_condicional(15), 1);
41+
assert_eq!(prueba_condicional(5), 0);
42+
}
43+
44+
#[test]
45+
fn test_match() {
46+
rustico::rustico! {
47+
función prueba_macheo(val: e32) -> e32 {
48+
machea val {
49+
1 => 10,
50+
2 => 20,
51+
_ => 0
52+
}
53+
}
54+
}
55+
56+
assert_eq!(prueba_macheo(1), 10);
57+
assert_eq!(prueba_macheo(2), 20);
58+
assert_eq!(prueba_macheo(99), 0);
59+
}
60+
61+
#[test]
62+
fn test_for_loop() {
63+
rustico::rustico! {
64+
función prueba_bucle_para() -> e32 {
65+
sea mutable suma = 0;
66+
para i de 0..5 {
67+
suma = suma + i;
68+
}
69+
retorna suma;
70+
}
71+
}
72+
73+
assert_eq!(prueba_bucle_para(), 10);
74+
}
75+
76+
#[test]
77+
fn test_while_loop() {
78+
rustico::rustico! {
79+
función prueba_mientras() -> e32 {
80+
sea mutable contador = 0;
81+
mientras contador < 5 {
82+
contador = contador + 1;
83+
}
84+
retorna contador;
85+
}
86+
}
87+
88+
assert_eq!(prueba_mientras(), 5);
89+
}
90+
91+
#[test]
92+
fn test_loop_and_break() {
93+
rustico::rustico! {
94+
función prueba_bucle_infinito() -> e32 {
95+
sea mutable x = 0;
96+
bucle {
97+
x = x + 1;
98+
si x == 10 {
99+
rompe;
100+
}
101+
}
102+
retorna x;
103+
}
104+
}
105+
106+
assert_eq!(prueba_bucle_infinito(), 10);
107+
}
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
// Test various keyword alternatives
2+
3+
#[test]
4+
fn test_function_alternatives() {
5+
rustico::rustico! {
6+
// función with tilde
7+
función con_tilde() -> e32 { 1 }
8+
9+
// funcion without tilde
10+
funcion sin_tilde() -> e32 { 2 }
11+
}
12+
13+
assert_eq!(con_tilde(), 1);
14+
assert_eq!(sin_tilde(), 2);
15+
}
16+
17+
#[test]
18+
fn test_let_alternatives() {
19+
rustico::rustico! {
20+
función prueba_deja() -> e32 {
21+
deja x = 10;
22+
x
23+
}
24+
25+
función prueba_sea() -> e32 {
26+
sea y = 20;
27+
y
28+
}
29+
}
30+
31+
assert_eq!(prueba_deja(), 10);
32+
assert_eq!(prueba_sea(), 20);
33+
}
34+
35+
#[test]
36+
fn test_return_alternatives() {
37+
rustico::rustico! {
38+
función usa_retorna() -> e32 {
39+
retorna 1;
40+
}
41+
42+
función usa_devuelve() -> e32 {
43+
devuelve 2;
44+
}
45+
}
46+
47+
assert_eq!(usa_retorna(), 1);
48+
assert_eq!(usa_devuelve(), 2);
49+
}
50+
51+
#[test]
52+
fn test_loop_alternatives() {
53+
rustico::rustico! {
54+
función usa_bucle() -> e32 {
55+
sea mutable x = 0;
56+
bucle {
57+
x = x + 1;
58+
si x == 5 {
59+
rompe;
60+
}
61+
}
62+
x
63+
}
64+
65+
función usa_ciclo() -> e32 {
66+
sea mutable y = 0;
67+
ciclo {
68+
y = y + 1;
69+
si y == 3 {
70+
romper;
71+
}
72+
}
73+
y
74+
}
75+
}
76+
77+
assert_eq!(usa_bucle(), 5);
78+
assert_eq!(usa_ciclo(), 3);
79+
}
80+
81+
#[test]
82+
fn test_unwrap_alternatives() {
83+
rustico::rustico! {
84+
función usa_pelar() -> e32 {
85+
Alguno(10).pelar()
86+
}
87+
88+
función usa_desenvolver() -> e32 {
89+
Alguno(20).desenvolver()
90+
}
91+
92+
función usa_destapar() -> e32 {
93+
Alguno(30).destapar()
94+
}
95+
}
96+
97+
assert_eq!(usa_pelar(), 10);
98+
assert_eq!(usa_desenvolver(), 20);
99+
assert_eq!(usa_destapar(), 30);
100+
}
101+
102+
#[test]
103+
fn test_self_alternatives() {
104+
rustico::rustico! {
105+
estructura UsaYo {
106+
valor: e32,
107+
}
108+
109+
implementa UsaYo {
110+
función con_yo(&yo) -> e32 {
111+
yo.valor
112+
}
113+
}
114+
115+
estructura UsaMismo {
116+
valor: e32,
117+
}
118+
119+
implementa UsaMismo {
120+
función con_mismo(&mismo) -> e32 {
121+
mismo.valor
122+
}
123+
}
124+
}
125+
126+
let obj1 = UsaYo { valor: 100 };
127+
let obj2 = UsaMismo { valor: 200 };
128+
assert_eq!(obj1.con_yo(), 100);
129+
assert_eq!(obj2.con_mismo(), 200);
130+
}
131+
132+
#[test]
133+
fn test_pub_alternatives() {
134+
rustico::rustico! {
135+
púb función con_tilde() -> e32 { 1 }
136+
publico función sin_tilde() -> e32 { 2 }
137+
}
138+
139+
assert_eq!(con_tilde(), 1);
140+
assert_eq!(sin_tilde(), 2);
141+
}
142+
143+
#[test]
144+
fn test_match_alternatives() {
145+
rustico::rustico! {
146+
función usa_machea(x: e32) -> e32 {
147+
machea x {
148+
1 => 10,
149+
_ => 0,
150+
}
151+
}
152+
153+
función usa_encaja(x: e32) -> e32 {
154+
encaja x {
155+
2 => 20,
156+
_ => 0,
157+
}
158+
}
159+
}
160+
161+
assert_eq!(usa_machea(1), 10);
162+
assert_eq!(usa_encaja(2), 20);
163+
}
164+
165+
#[test]
166+
fn test_for_alternatives() {
167+
rustico::rustico! {
168+
función usa_para() -> e32 {
169+
sea mutable suma = 0;
170+
para i de 0..3 {
171+
suma = suma + i;
172+
}
173+
suma
174+
}
175+
176+
función usa_por() -> e32 {
177+
sea mutable suma = 0;
178+
por i de 0..3 {
179+
suma = suma + i;
180+
}
181+
suma
182+
}
183+
}
184+
185+
assert_eq!(usa_para(), 3);
186+
assert_eq!(usa_por(), 3);
187+
}
188+
189+
#[test]
190+
fn test_expect_alternatives() {
191+
rustico::rustico! {
192+
función usa_confia() -> e32 {
193+
Alguno(42).confia("debe existir")
194+
}
195+
196+
función usa_asume() -> e32 {
197+
Alguno(43).asume("debe existir")
198+
}
199+
}
200+
201+
assert_eq!(usa_confia(), 42);
202+
assert_eq!(usa_asume(), 43);
203+
}

0 commit comments

Comments
 (0)