Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ jobs:
with:
command: fmt
args: --all -- --check

- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
args: --all
107 changes: 107 additions & 0 deletions rustico/tests/basic_syntax.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Test basic syntax translations

#[test]
fn test_basic_function() {
rustico::rustico! {
función prueba() -> e32 {
retorna 42;
}
}

assert_eq!(prueba(), 42);
}

#[test]
fn test_let_and_mut() {
rustico::rustico! {
función prueba_variables() -> e32 {
sea x = 5;
sea mutable y = 10;
y = y + x;
retorna y;
}
}

assert_eq!(prueba_variables(), 15);
}

#[test]
fn test_if_else() {
rustico::rustico! {
función prueba_condicional(val: e32) -> e32 {
si val > 10 {
retorna 1;
} sino {
retorna 0;
}
}
}

assert_eq!(prueba_condicional(15), 1);
assert_eq!(prueba_condicional(5), 0);
}

#[test]
fn test_match() {
rustico::rustico! {
función prueba_macheo(val: e32) -> e32 {
machea val {
1 => 10,
2 => 20,
_ => 0
}
}
}

assert_eq!(prueba_macheo(1), 10);
assert_eq!(prueba_macheo(2), 20);
assert_eq!(prueba_macheo(99), 0);
}

#[test]
fn test_for_loop() {
rustico::rustico! {
función prueba_bucle_para() -> e32 {
sea mutable suma = 0;
para i de 0..5 {
suma = suma + i;
}
retorna suma;
}
}

assert_eq!(prueba_bucle_para(), 10);
}

#[test]
fn test_while_loop() {
rustico::rustico! {
función prueba_mientras() -> e32 {
sea mutable contador = 0;
mientras contador < 5 {
contador = contador + 1;
}
retorna contador;
}
}

assert_eq!(prueba_mientras(), 5);
}

#[test]
fn test_loop_and_break() {
rustico::rustico! {
función prueba_bucle_infinito() -> e32 {
sea mutable x = 0;
bucle {
x = x + 1;
si x == 10 {
rompe;
}
}
retorna x;
}
}

assert_eq!(prueba_bucle_infinito(), 10);
}
203 changes: 203 additions & 0 deletions rustico/tests/keyword_alternatives.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
// Test various keyword alternatives

#[test]
fn test_function_alternatives() {
rustico::rustico! {
// función with tilde
función con_tilde() -> e32 { 1 }

// funcion without tilde
funcion sin_tilde() -> e32 { 2 }
}

assert_eq!(con_tilde(), 1);
assert_eq!(sin_tilde(), 2);
}

#[test]
fn test_let_alternatives() {
rustico::rustico! {
función prueba_deja() -> e32 {
deja x = 10;
x
}

función prueba_sea() -> e32 {
sea y = 20;
y
}
}

assert_eq!(prueba_deja(), 10);
assert_eq!(prueba_sea(), 20);
}

#[test]
fn test_return_alternatives() {
rustico::rustico! {
función usa_retorna() -> e32 {
retorna 1;
}

función usa_devuelve() -> e32 {
devuelve 2;
}
}

assert_eq!(usa_retorna(), 1);
assert_eq!(usa_devuelve(), 2);
}

#[test]
fn test_loop_alternatives() {
rustico::rustico! {
función usa_bucle() -> e32 {
sea mutable x = 0;
bucle {
x = x + 1;
si x == 5 {
rompe;
}
}
x
}

función usa_ciclo() -> e32 {
sea mutable y = 0;
ciclo {
y = y + 1;
si y == 3 {
romper;
}
}
y
}
}

assert_eq!(usa_bucle(), 5);
assert_eq!(usa_ciclo(), 3);
}

#[test]
fn test_unwrap_alternatives() {
rustico::rustico! {
función usa_pelar() -> e32 {
Alguno(10).pelar()
}

función usa_desenvolver() -> e32 {
Alguno(20).desenvolver()
}

función usa_destapar() -> e32 {
Alguno(30).destapar()
}
}

assert_eq!(usa_pelar(), 10);
assert_eq!(usa_desenvolver(), 20);
assert_eq!(usa_destapar(), 30);
}

#[test]
fn test_self_alternatives() {
rustico::rustico! {
estructura UsaYo {
valor: e32,
}

implementa UsaYo {
función con_yo(&yo) -> e32 {
yo.valor
}
}

estructura UsaMismo {
valor: e32,
}

implementa UsaMismo {
función con_mismo(&mismo) -> e32 {
mismo.valor
}
}
}

let obj1 = UsaYo { valor: 100 };
let obj2 = UsaMismo { valor: 200 };
assert_eq!(obj1.con_yo(), 100);
assert_eq!(obj2.con_mismo(), 200);
}

#[test]
fn test_pub_alternatives() {
rustico::rustico! {
púb función con_tilde() -> e32 { 1 }
publico función sin_tilde() -> e32 { 2 }
}

assert_eq!(con_tilde(), 1);
assert_eq!(sin_tilde(), 2);
}

#[test]
fn test_match_alternatives() {
rustico::rustico! {
función usa_machea(x: e32) -> e32 {
machea x {
1 => 10,
_ => 0,
}
}

función usa_encaja(x: e32) -> e32 {
encaja x {
2 => 20,
_ => 0,
}
}
}

assert_eq!(usa_machea(1), 10);
assert_eq!(usa_encaja(2), 20);
}

#[test]
fn test_for_alternatives() {
rustico::rustico! {
función usa_para() -> e32 {
sea mutable suma = 0;
para i de 0..3 {
suma = suma + i;
}
suma
}

función usa_por() -> e32 {
sea mutable suma = 0;
por i de 0..3 {
suma = suma + i;
}
suma
}
}

assert_eq!(usa_para(), 3);
assert_eq!(usa_por(), 3);
}

#[test]
fn test_expect_alternatives() {
rustico::rustico! {
función usa_confia() -> e32 {
Alguno(42).confia("debe existir")
}

función usa_asume() -> e32 {
Alguno(43).asume("debe existir")
}
}

assert_eq!(usa_confia(), 42);
assert_eq!(usa_asume(), 43);
}
Loading
Loading