⭐️ A friendly language for building type-safe, scalable systems!
at main 2.1 kB view raw
1use crate::assert_js; 2 3#[test] 4fn assert_variable() { 5 assert_js!( 6 " 7pub fn main() { 8 let x = True 9 assert x 10} 11" 12 ); 13} 14 15#[test] 16fn assert_literal() { 17 assert_js!( 18 " 19pub fn main() { 20 assert False 21} 22" 23 ); 24} 25 26#[test] 27fn assert_binary_operation() { 28 assert_js!( 29 " 30pub fn main() { 31 let x = True 32 assert x || False 33} 34" 35 ); 36} 37 38#[test] 39fn assert_binary_operation2() { 40 assert_js!( 41 " 42pub fn eq(a, b) { 43 assert a == b 44} 45" 46 ); 47} 48 49#[test] 50fn assert_binary_operation3() { 51 assert_js!( 52 " 53pub fn assert_answer(x) { 54 assert x == 42 55} 56" 57 ); 58} 59 60#[test] 61fn assert_function_call() { 62 assert_js!( 63 " 64fn bool() { 65 True 66} 67 68pub fn main() { 69 assert bool() 70} 71" 72 ); 73} 74 75#[test] 76fn assert_function_call2() { 77 assert_js!( 78 " 79fn and(a, b) { 80 a && b 81} 82 83pub fn go(x) { 84 assert and(True, x) 85} 86" 87 ); 88} 89 90#[test] 91fn assert_nested_function_call() { 92 assert_js!( 93 " 94fn and(x, y) { 95 x && y 96} 97 98pub fn main() { 99 assert and(and(True, False), True) 100} 101" 102 ); 103} 104 105#[test] 106fn assert_binary_operator_with_side_effects() { 107 assert_js!( 108 " 109fn wibble(a, b) { 110 let result = a + b 111 result == 10 112} 113 114pub fn go(x) { 115 assert True && wibble(1, 4) 116} 117" 118 ); 119} 120 121#[test] 122fn assert_binary_operator_with_side_effects2() { 123 assert_js!( 124 " 125fn wibble(a, b) { 126 let result = a + b 127 result == 10 128} 129 130pub fn go(x) { 131 assert wibble(5, 5) && wibble(4, 6) 132} 133" 134 ); 135} 136 137#[test] 138fn assert_with_message() { 139 assert_js!( 140 r#" 141pub fn main() { 142 assert True as "This shouldn't fail" 143} 144"# 145 ); 146} 147 148#[test] 149fn assert_with_block_message() { 150 assert_js!( 151 r#" 152fn identity(a) { 153 a 154} 155 156pub fn main() { 157 assert identity(True) as { 158 let message = identity("This shouldn't fail") 159 message 160 } 161} 162"# 163 ); 164} 165 166#[test] 167fn assert_nil_always_throws() { 168 assert_js!( 169 r#" 170pub fn go(x: Nil) { 171 let assert Nil = x 172} 173"# 174 ); 175} 176 177// https://github.com/gleam-lang/gleam/issues/4643 178#[test] 179fn assert_with_pipe_on_right() { 180 assert_js!( 181 " 182fn add(a, b) { a + b } 183 184pub fn main() { 185 assert 3 == 1 |> add(2) 186} 187" 188 ); 189}