⭐️ A friendly language for building type-safe, scalable systems!
at main 3.3 kB view raw
1use crate::assert_js; 2 3#[test] 4fn unicode1() { 5 assert_js!( 6 r#" 7pub fn emoji() -> String { 8 "\u{1f600}" 9} 10"#, 11 ); 12} 13 14#[test] 15fn unicode2() { 16 assert_js!( 17 r#" 18pub fn y_with_dieresis() -> String { 19 "\u{0308}y" 20} 21"#, 22 ); 23} 24 25#[test] 26fn ascii_as_unicode_escape_sequence() { 27 assert_js!( 28 r#" 29pub fn y() -> String { 30 "\u{79}" 31} 32"#, 33 ) 34} 35 36#[test] 37fn unicode_escape_sequence_6_digits() { 38 assert_js!( 39 r#" 40pub fn unicode_escape_sequence_6_digits() -> String { 41 "\u{10abcd}" 42} 43"#, 44 ); 45} 46 47#[test] 48fn string_literals() { 49 assert_js!( 50 r#" 51pub fn go() { 52 "Hello, Gleam!" 53} 54"#, 55 ); 56} 57 58#[test] 59fn string_patterns() { 60 assert_js!( 61 r#" 62pub fn go(x) { 63 let assert "Hello" = x 64} 65"#, 66 ); 67} 68 69#[test] 70fn equality() { 71 assert_js!( 72 r#" 73pub fn go(a) { 74 a == "ok" 75 a != "ok" 76 a == a 77} 78"#, 79 ); 80} 81 82#[test] 83fn case() { 84 assert_js!( 85 r#" 86pub fn go(a) { 87 case a { 88 "" -> 0 89 "one" -> 1 90 "two" -> 2 91 _ -> 3 92 } 93} 94"#, 95 ); 96} 97 98#[test] 99fn string_concat() { 100 assert_js!( 101 r#" 102pub fn go() { 103 "Hello, " <> "Joe" 104} 105"#, 106 ); 107} 108 109#[test] 110fn string_prefix() { 111 assert_js!( 112 r#" 113pub fn go(x) { 114 case x { 115 "Hello, " <> name -> name 116 _ -> "Unknown" 117 } 118} 119"#, 120 ); 121} 122 123#[test] 124fn string_prefix_utf16() { 125 assert_js!( 126 r#" 127pub fn go(x) { 128 case "Θ wibble wobble" { 129 "Θ" <> rest -> rest 130 _ -> "" 131 } 132 case "🫥 is neutral dotted" { 133 "🫥" <> rest -> rest 134 _ -> "" 135 } 136 case "🇺🇸 is a cluster" { 137 "🇺🇸" <> rest -> rest 138 _ -> "" 139 } 140 case "\" is a an escaped quote" { 141 "\"" <> rest -> rest 142 _ -> "" 143 } 144 case "\\ is a an escaped backslash" { 145 "\\" <> rest -> rest 146 _ -> "" 147 } 148} 149"#, 150 ); 151} 152 153#[test] 154fn discard_concat_rest_pattern() { 155 // We can discard the right hand side, it parses and type checks ok 156 assert_js!( 157 r#" 158pub fn go(x) { 159 case x { 160 "Hello, " <> _ -> Nil 161 _ -> Nil 162 } 163} 164"#, 165 ); 166} 167 168#[test] 169fn string_prefix_assignment() { 170 assert_js!( 171 r#" 172pub fn go(x) { 173 case x { 174 "Hello, " as greeting <> name -> greeting 175 _ -> "Unknown" 176 } 177} 178"#, 179 ) 180} 181 182#[test] 183fn string_prefix_assignment_with_utf_escape_sequence() { 184 assert_js!( 185 r#" 186pub fn go(x) { 187 case x { 188 "\u{0032} " as greeting <> name -> greeting 189 "\u{0007ff} " as greeting <> name -> greeting 190 "\u{00ffff} " as greeting <> name -> greeting 191 "\u{10ffff} " as greeting <> name -> greeting 192 _ -> "Unknown" 193 } 194} 195"#, 196 ) 197} 198 199#[test] 200fn string_prefix_shadowing() { 201 assert_js!( 202 r#" 203pub fn go(x) { 204 case x { 205 "Hello, " as x <> name -> x 206 _ -> "Unknown" 207 } 208} 209"#, 210 ) 211} 212 213// https://github.com/gleam-lang/gleam/issues/2471 214#[test] 215fn string_prefix_assignment_with_multiple_subjects() { 216 assert_js!( 217 r#" 218pub fn go(x) { 219 case x { 220 "1" as prefix <> _ | "11" as prefix <> _ -> prefix 221 _ -> "Unknown" 222 } 223} 224"#, 225 ) 226} 227 228#[test] 229fn const_concat() { 230 assert_js!( 231 r#" 232pub const cute = "cute" 233pub const cute_bee = cute <> "bee" 234 235pub fn main() { 236 cute_bee 237} 238"# 239 ); 240} 241 242#[test] 243fn const_concat_multiple() { 244 assert_js!( 245 r#" 246pub const cute = "cute" 247pub const cute_bee = cute <> "bee" 248pub const cute_cute_bee_buzz = cute <> cute_bee <> "buzz" 249 250pub fn main() { 251 cute_cute_bee_buzz 252} 253"# 254 ); 255}