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 / erlang / tests / consts.rs
3.8 kB 251 lines
1use crate::assert_erl; 2 3// https://github.com/gleam-lang/gleam/issues/2163 4#[test] 5fn record_constructor() { 6 assert_erl!( 7 r#" 8pub type X { 9 X(Int) 10} 11 12pub const z = X 13 14pub fn main() { 15 z 16}"# 17 ); 18} 19 20// https://github.com/gleam-lang/gleam/issues/2163 21#[test] 22fn record_constructor_in_tuple() { 23 assert_erl!( 24 r#" 25pub type X { 26 X(Int) 27} 28 29pub const z = #(X) 30 31pub fn main() { 32 z 33}"# 34 ); 35} 36 37// https://github.com/gleam-lang/gleam/issues/2179 38#[test] 39fn const_type_variable() { 40 assert_erl!( 41 r#" 42fn identity(a: a) -> a { 43 a 44} 45 46const id: fn(a) -> a = identity 47"# 48 ); 49} 50 51#[test] 52fn const_generalise() { 53 assert_erl!( 54 r#" 55fn identity(a: a) -> a { 56a 57} 58 59const id = identity 60 61pub fn main(){ 62 let num = id(1) 63 let word = id("Word") 64}"# 65 ); 66} 67 68#[test] 69fn pub_const_equal_to_private_function() { 70 assert_erl!( 71 r#" 72 fn identity(a) { 73 a 74 } 75 76 pub const id = identity 77 "# 78 ); 79} 80 81#[test] 82fn pub_const_equal_to_record_with_private_function_field() { 83 assert_erl!( 84 r#" 85 fn identity(a) { 86 a 87 } 88 89 pub type Mapper(b) { 90 Mapper(fn(b) -> b) 91 } 92 93 pub const id_mapper = Mapper(identity) 94 "# 95 ); 96} 97 98#[test] 99fn pub_const_equal_to_record_with_nested_private_function_field() { 100 assert_erl!( 101 r#" 102 fn identity(a) { 103 a 104 } 105 106 pub type Mapper(b) { 107 Mapper(fn(b) -> b) 108 } 109 110 pub type Funcs(b) { 111 Funcs(mapper: Mapper(b)) 112 } 113 114 pub const id_mapper = Funcs(Mapper(identity)) 115 "# 116 ); 117} 118 119#[test] 120fn use_unqualified_pub_const_equal_to_private_function() { 121 assert_erl!( 122 r#" 123 fn identity(a) { 124 a 125 } 126 127 pub const id = identity 128 "# 129 ); 130} 131 132#[test] 133fn use_unqualified_pub_const_equal_to_record_with_private_function_field() { 134 assert_erl!( 135 r#" 136 fn identity(a) { 137 a 138 } 139 140 pub type Mapper(b) { 141 Mapper(fn(b) -> b) 142 } 143 144 pub const id_mapper = Mapper(identity) 145 "# 146 ); 147} 148 149#[test] 150fn use_qualified_pub_const_equal_to_record_with_private_function_field() { 151 assert_erl!( 152 r#" 153 fn identity(a) { 154 a 155 } 156 157 pub type Mapper(b) { 158 Mapper(fn(b) -> b) 159 } 160 161 pub const id_mapper = Mapper(identity) 162 "# 163 ); 164} 165 166#[test] 167fn use_private_in_internal() { 168 assert_erl!( 169 r#" 170 fn identity(a) { 171 a 172 } 173 174 pub type Mapper(b) { 175 Mapper(fn(b) -> b) 176 } 177 178 @internal 179 pub const id_mapper = Mapper(identity) 180 "# 181 ); 182} 183 184#[test] 185fn use_private_in_list() { 186 assert_erl!( 187 r#" 188 fn identity(a) { 189 a 190 } 191 192 pub const funcs = [identity] 193 "# 194 ) 195} 196 197#[test] 198fn use_private_in_tuple() { 199 assert_erl!( 200 r#" 201 fn identity(a) { 202 a 203 } 204 205 pub const funcs = #(identity) 206 "# 207 ) 208} 209 210#[test] 211fn list_prepend() { 212 assert_erl!( 213 " 214const wibble = [2, 3, 4] 215pub const wobble = [0, 1, ..wibble] 216 217pub fn main() { 218 wobble 219} 220" 221 ); 222} 223 224#[test] 225fn list_prepend_from_other_module() { 226 assert_erl!( 227 ("thepackage", "mod", "pub const wibble = [2, 3, 4]"), 228 " 229import mod 230 231pub const wobble = [0, 1, ..mod.wibble] 232 233pub fn main() { 234 wobble 235} 236" 237 ); 238} 239 240#[test] 241fn list_prepend_literal() { 242 assert_erl!( 243 " 244pub const wibble = [0, 1, ..[2, 3, 4]] 245 246pub fn main() { 247 wibble 248} 249" 250 ); 251}