Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

gleam / compiler-core / src / javascript / tests / consts.rs
2.7 kB 172 lines
1// SPDX-License-Identifier: Apache-2.0 2// SPDX-FileCopyrightText: 2024 The Gleam contributors 3 4use crate::assert_js; 5 6#[test] 7fn custom_type_constructor_imported_and_aliased() { 8 assert_js!( 9 ("package", "other_module", "pub type T { A }"), 10 r#"import other_module.{A as B} 11 12pub const local = B 13"#, 14 ); 15} 16 17#[test] 18fn imported_aliased_ok() { 19 assert_js!( 20 r#"import gleam.{Ok as Y} 21 22pub type X { 23 Ok 24} 25 26pub const y = Y 27"#, 28 ); 29} 30 31#[test] 32fn imported_ok() { 33 assert_js!( 34 r#"import gleam 35 36pub type X { 37 Ok 38} 39 40pub const y = gleam.Ok 41"#, 42 ); 43} 44 45#[test] 46fn constant_constructor_gets_pure_annotation() { 47 assert_js!( 48 r#" 49pub type X { 50 X(Int, List(String)) 51} 52 53pub const x = X(1, ["1"]) 54pub const y = X(1, []) 55 "# 56 ); 57} 58 59#[test] 60fn constant_list_with_constructors_gets_pure_annotation() { 61 assert_js!( 62 r#" 63pub type X { 64 X(Int, List(String)) 65} 66 67pub const x = [X(1, ["1"])] 68pub const y = [X(1, ["1"])] 69 "# 70 ); 71} 72 73#[test] 74fn constant_tuple_with_constructors_gets_pure_annotation() { 75 assert_js!( 76 r#" 77pub type X { 78 X(Int, List(String)) 79} 80 81pub const x = #(X(1, ["1"])) 82pub const y = #(X(1, ["1"])) 83 "# 84 ); 85} 86 87#[test] 88fn literal_int_does_not_get_constant_annotation() { 89 assert_js!("pub const a = 1"); 90} 91 92#[test] 93fn literal_float_does_not_get_constant_annotation() { 94 assert_js!("pub const a = 1.1"); 95} 96 97#[test] 98fn literal_string_does_not_get_constant_annotation() { 99 assert_js!("pub const a = \"1\""); 100} 101 102#[test] 103fn literal_bool_does_not_get_constant_annotation() { 104 assert_js!( 105 " 106 pub const a = True 107 pub const b = False 108 " 109 ); 110} 111 112#[test] 113fn literal_list_does_not_get_constant_annotation() { 114 assert_js!("pub const a = [1, 2, 3]"); 115} 116 117#[test] 118fn literal_tuple_does_not_get_constant_annotation() { 119 assert_js!("pub const a = #(1, 2, 3)"); 120} 121 122#[test] 123fn literal_nil_does_not_get_constant_annotation() { 124 assert_js!("pub const a = Nil"); 125} 126 127// https://github.com/lpil/decode/pull/6 128#[test] 129fn constructor_function_in_constant() { 130 assert_js!("pub const a = Ok"); 131} 132 133#[test] 134fn constants_get_their_own_jsdoc_comment() { 135 assert_js!( 136 " 137/// 11 is clearly the best number! 138pub const jaks_favourite_number = 11 139" 140 ); 141} 142 143#[test] 144fn list_prepend() { 145 assert_js!( 146 " 147const wibble = [2, 3, 4] 148pub const wobble = [0, 1, ..wibble] 149" 150 ); 151} 152 153#[test] 154fn list_prepend_from_other_module() { 155 assert_js!( 156 ("mod", "pub const wibble = [2, 3, 4]"), 157 " 158import mod 159 160pub const wobble = [0, 1, ..mod.wibble] 161" 162 ); 163} 164 165#[test] 166fn list_prepend_literal() { 167 assert_js!( 168 " 169pub const wibble = [0, 1, ..[2, 3, 4]] 170" 171 ); 172}