|
| 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