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

Configure Feed

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

Add disjoint string prefix with guard test

+62
+30
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__strings__disjoint_string_prefixes_with_guard.snap
··· 1 + --- 2 + source: compiler-core/src/javascript/tests/strings.rs 3 + expression: "\npub fn classify(input: String) -> String {\n case input {\n \"aa\" <> rest if rest == \"x\" -> rest\n \"b\" <> _ -> \"b-start\"\n _ -> \"other\"\n }\n}\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + pub fn classify(input: String) -> String { 8 + case input { 9 + "aa" <> rest if rest == "x" -> rest 10 + "b" <> _ -> "b-start" 11 + _ -> "other" 12 + } 13 + } 14 + 15 + 16 + ----- COMPILED JAVASCRIPT 17 + export function classify(input) { 18 + if (input.startsWith("aa")) { 19 + let rest = input.slice(2); 20 + if (rest === "x") { 21 + return rest; 22 + } else { 23 + return "other"; 24 + } 25 + } else if (input.charCodeAt(0) === 98) { 26 + return "b-start"; 27 + } else { 28 + return "other"; 29 + } 30 + }
+16
compiler-core/src/javascript/tests/strings.rs
··· 420 420 "#, 421 421 ); 422 422 } 423 + 424 + // https://github.com/gleam-lang/gleam/issues/5856 425 + #[test] 426 + fn disjoint_string_prefixes_with_guard() { 427 + assert_js!( 428 + r#" 429 + pub fn classify(input: String) -> String { 430 + case input { 431 + "aa" <> rest if rest == "x" -> rest 432 + "b" <> _ -> "b-start" 433 + _ -> "other" 434 + } 435 + } 436 + "#, 437 + ); 438 + }
+16
test/language/test/language/string_pattern_matching_test.gleam
··· 244 244 assert classify("🫥z") == "z" 245 245 assert classify("abc") == "other" 246 246 } 247 + 248 + // https://github.com/gleam-lang/gleam/issues/5856 249 + pub fn disjoint_string_prefixes_with_guard_test() { 250 + let classify = fn(input: String) -> String { 251 + case input { 252 + "aa" <> rest if rest == "x" -> rest 253 + "b" <> _ -> "b-start" 254 + _ -> "other" 255 + } 256 + } 257 + 258 + assert classify("aax") == "x" 259 + assert classify("aay") == "other" 260 + assert classify("bcd") == "b-start" 261 + assert classify("zzz") == "other" 262 + }