⭐️ A friendly language for building type-safe, scalable systems!
at main 1.5 kB view raw
1use crate::{assert_js, assert_ts_def}; 2 3#[test] 4fn list_literals() { 5 assert_js!( 6 r#" 7pub fn go(x) { 8 [] 9 [1] 10 [1, 2] 11 [1, 2, ..x] 12} 13"#, 14 ); 15} 16 17#[test] 18fn long_list_literals() { 19 assert_js!( 20 r#" 21pub fn go() { 22 [111111111111111111111111111111111111111111111111111111111111111111111111] 23 [11111111111111111111111111111111111111111111, 1111111111111111111111111111111111111111111] 24} 25"#, 26 ); 27} 28 29#[test] 30fn multi_line_list_literals() { 31 assert_js!( 32 r#" 33pub fn go(x) { 34 [{True 1}] 35} 36"#, 37 ); 38} 39 40#[test] 41fn list_constants() { 42 assert_js!( 43 r#" 44pub const a = [] 45pub const b = [1, 2, 3] 46"#, 47 ); 48} 49 50#[test] 51fn list_constants_typescript() { 52 assert_ts_def!( 53 r#" 54pub const a = [] 55pub const b = [1, 2, 3] 56"#, 57 ); 58} 59 60#[test] 61fn list_destructuring() { 62 assert_js!( 63 r#" 64pub fn go(x, y) { 65 let assert [] = x 66 let assert [a] = x 67 let assert [1, 2] = x 68 let assert [_, #(3, b)] = y 69 let assert [head, ..tail] = y 70} 71"#, 72 ); 73} 74 75#[test] 76fn equality() { 77 assert_js!( 78 r#" 79pub fn go() { 80 [] == [1] 81 [] != [1] 82} 83"#, 84 ); 85} 86 87#[test] 88fn case() { 89 assert_js!( 90 r#" 91pub fn go(xs) { 92 case xs { 93 [] -> 0 94 [_] -> 1 95 [_, _] -> 2 96 _ -> 9999 97 } 98} 99"#, 100 ); 101} 102 103// https://github.com/gleam-lang/gleam/issues/2904 104#[test] 105fn tight_empty_list() { 106 assert_js!( 107 r#" 108pub fn go(func) { 109 let huuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuge_variable = [] 110} 111"#, 112 ); 113}