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

Configure Feed

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

Add tests

+566 -2
+2 -2
compiler-core/src/javascript.rs
··· 206 206 } 207 207 208 208 if self.tracker.codepoint_utf16_bit_array_segment_used { 209 - self.register_prelude_usage(&mut imports, "stringToUtf16", None); 209 + self.register_prelude_usage(&mut imports, "codepointToUtf16", None); 210 210 } 211 211 212 212 if self.tracker.codepoint_utf32_bit_array_segment_used { 213 - self.register_prelude_usage(&mut imports, "stringToUtf32", None); 213 + self.register_prelude_usage(&mut imports, "codepointToUtf32", None); 214 214 } 215 215 216 216 if self.tracker.float_bit_array_segment_used {
+134
compiler-core/src/javascript/tests/bit_arrays.rs
··· 2097 2097 "# 2098 2098 ); 2099 2099 } 2100 + 2101 + #[test] 2102 + fn utf16() { 2103 + assert_js!( 2104 + r#" 2105 + pub fn main() { 2106 + <<"Hello, world!":utf16>> 2107 + } 2108 + "# 2109 + ); 2110 + } 2111 + 2112 + #[test] 2113 + fn utf16_codepoint() { 2114 + assert_js!( 2115 + r#" 2116 + fn codepoint() -> UtfCodepoint { todo } 2117 + 2118 + pub fn main() { 2119 + let my_codepoint = codepoint() 2120 + <<my_codepoint:utf16_codepoint>> 2121 + } 2122 + "# 2123 + ); 2124 + } 2125 + 2126 + #[test] 2127 + fn utf32() { 2128 + assert_js!( 2129 + r#" 2130 + pub fn main() { 2131 + <<"Hello, world!":utf32>> 2132 + } 2133 + "# 2134 + ); 2135 + } 2136 + 2137 + #[test] 2138 + fn utf32_codepoint() { 2139 + assert_js!( 2140 + r#" 2141 + fn codepoint() -> UtfCodepoint { todo } 2142 + 2143 + pub fn main() { 2144 + let my_codepoint = codepoint() 2145 + <<my_codepoint:utf32_codepoint>> 2146 + } 2147 + "# 2148 + ); 2149 + } 2150 + 2151 + #[test] 2152 + fn const_utf16() { 2153 + assert_js!( 2154 + r#" 2155 + pub const message = <<"Hello, world!":utf16>> 2156 + "# 2157 + ); 2158 + } 2159 + 2160 + #[test] 2161 + fn const_utf32() { 2162 + assert_js!( 2163 + r#" 2164 + pub const message = <<"Hello, world!":utf32>> 2165 + "# 2166 + ); 2167 + } 2168 + 2169 + #[test] 2170 + fn pattern_match_utf16() { 2171 + assert_js!( 2172 + r#" 2173 + pub fn go(x) { 2174 + let assert <<"Hello":utf16, _rest:bytes>> = x 2175 + } 2176 + "# 2177 + ); 2178 + } 2179 + 2180 + #[test] 2181 + fn pattern_match_utf32() { 2182 + assert_js!( 2183 + r#" 2184 + pub fn go(x) { 2185 + let assert <<"Hello":utf32, _rest:bytes>> = x 2186 + } 2187 + "# 2188 + ); 2189 + } 2190 + 2191 + #[test] 2192 + fn utf16_little_endian() { 2193 + assert_js!( 2194 + r#" 2195 + pub fn main() { 2196 + <<"Hello, world!":utf16-little>> 2197 + } 2198 + "# 2199 + ); 2200 + } 2201 + 2202 + #[test] 2203 + fn utf32_little_endian() { 2204 + assert_js!( 2205 + r#" 2206 + pub fn main() { 2207 + <<"Hello, world!":utf32-little>> 2208 + } 2209 + "# 2210 + ); 2211 + } 2212 + 2213 + #[test] 2214 + fn pattern_match_utf16_little_endian() { 2215 + assert_js!( 2216 + r#" 2217 + pub fn go(x) { 2218 + let assert <<"Hello":utf16-little, _rest:bytes>> = x 2219 + } 2220 + "# 2221 + ); 2222 + } 2223 + 2224 + #[test] 2225 + fn pattern_match_utf32_little_endian() { 2226 + assert_js!( 2227 + r#" 2228 + pub fn go(x) { 2229 + let assert <<"Hello":utf32-little, _rest:bytes>> = x 2230 + } 2231 + "# 2232 + ); 2233 + }
+15
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__const_utf16.snap
··· 1 + --- 2 + source: compiler-core/src/javascript/tests/bit_arrays.rs 3 + expression: "\npub const message = <<\"Hello, world!\":utf16>>\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + pub const message = <<"Hello, world!":utf16>> 8 + 9 + 10 + ----- COMPILED JAVASCRIPT 11 + import { toBitArray, stringToUtf16 } from "../gleam.mjs"; 12 + 13 + export const message = /* @__PURE__ */ toBitArray([ 14 + stringToUtf16("Hello, world!", true), 15 + ]);
+15
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__const_utf32.snap
··· 1 + --- 2 + source: compiler-core/src/javascript/tests/bit_arrays.rs 3 + expression: "\npub const message = <<\"Hello, world!\":utf32>>\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + pub const message = <<"Hello, world!":utf32>> 8 + 9 + 10 + ----- COMPILED JAVASCRIPT 11 + import { toBitArray, stringToUtf32 } from "../gleam.mjs"; 12 + 13 + export const message = /* @__PURE__ */ toBitArray([ 14 + stringToUtf32("Hello, world!", true), 15 + ]);
+40
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_match_utf16.snap
··· 1 + --- 2 + source: compiler-core/src/javascript/tests/bit_arrays.rs 3 + expression: "\npub fn go(x) {\n let assert <<\"Hello\":utf16, _rest:bytes>> = x\n}\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + pub fn go(x) { 8 + let assert <<"Hello":utf16, _rest:bytes>> = x 9 + } 10 + 11 + 12 + ----- COMPILED JAVASCRIPT 13 + import { makeError } from "../gleam.mjs"; 14 + 15 + export function go(x) { 16 + if ( 17 + x.bitSize < 80 || 18 + x.byteAt(0) !== 0 || 19 + x.byteAt(1) !== 72 || 20 + x.byteAt(2) !== 0 || 21 + x.byteAt(3) !== 101 || 22 + x.byteAt(4) !== 0 || 23 + x.byteAt(5) !== 108 || 24 + x.byteAt(6) !== 0 || 25 + x.byteAt(7) !== 108 || 26 + x.byteAt(8) !== 0 || 27 + x.byteAt(9) !== 111 || 28 + (x.bitSize - 80) % 8 !== 0 29 + ) { 30 + throw makeError( 31 + "let_assert", 32 + "my/mod", 33 + 3, 34 + "go", 35 + "Pattern match failed, no pattern matched the value.", 36 + { value: x } 37 + ) 38 + } 39 + return x; 40 + }
+40
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_match_utf16_little_endian.snap
··· 1 + --- 2 + source: compiler-core/src/javascript/tests/bit_arrays.rs 3 + expression: "\npub fn go(x) {\n let assert <<\"Hello\":utf16-little, _rest:bytes>> = x\n}\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + pub fn go(x) { 8 + let assert <<"Hello":utf16-little, _rest:bytes>> = x 9 + } 10 + 11 + 12 + ----- COMPILED JAVASCRIPT 13 + import { makeError } from "../gleam.mjs"; 14 + 15 + export function go(x) { 16 + if ( 17 + x.bitSize < 80 || 18 + x.byteAt(0) !== 72 || 19 + x.byteAt(1) !== 0 || 20 + x.byteAt(2) !== 101 || 21 + x.byteAt(3) !== 0 || 22 + x.byteAt(4) !== 108 || 23 + x.byteAt(5) !== 0 || 24 + x.byteAt(6) !== 108 || 25 + x.byteAt(7) !== 0 || 26 + x.byteAt(8) !== 111 || 27 + x.byteAt(9) !== 0 || 28 + (x.bitSize - 80) % 8 !== 0 29 + ) { 30 + throw makeError( 31 + "let_assert", 32 + "my/mod", 33 + 3, 34 + "go", 35 + "Pattern match failed, no pattern matched the value.", 36 + { value: x } 37 + ) 38 + } 39 + return x; 40 + }
+50
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_match_utf32.snap
··· 1 + --- 2 + source: compiler-core/src/javascript/tests/bit_arrays.rs 3 + expression: "\npub fn go(x) {\n let assert <<\"Hello\":utf32, _rest:bytes>> = x\n}\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + pub fn go(x) { 8 + let assert <<"Hello":utf32, _rest:bytes>> = x 9 + } 10 + 11 + 12 + ----- COMPILED JAVASCRIPT 13 + import { makeError } from "../gleam.mjs"; 14 + 15 + export function go(x) { 16 + if ( 17 + x.bitSize < 160 || 18 + x.byteAt(0) !== 0 || 19 + x.byteAt(1) !== 0 || 20 + x.byteAt(2) !== 0 || 21 + x.byteAt(3) !== 72 || 22 + x.byteAt(4) !== 0 || 23 + x.byteAt(5) !== 0 || 24 + x.byteAt(6) !== 0 || 25 + x.byteAt(7) !== 101 || 26 + x.byteAt(8) !== 0 || 27 + x.byteAt(9) !== 0 || 28 + x.byteAt(10) !== 0 || 29 + x.byteAt(11) !== 108 || 30 + x.byteAt(12) !== 0 || 31 + x.byteAt(13) !== 0 || 32 + x.byteAt(14) !== 0 || 33 + x.byteAt(15) !== 108 || 34 + x.byteAt(16) !== 0 || 35 + x.byteAt(17) !== 0 || 36 + x.byteAt(18) !== 0 || 37 + x.byteAt(19) !== 111 || 38 + (x.bitSize - 160) % 8 !== 0 39 + ) { 40 + throw makeError( 41 + "let_assert", 42 + "my/mod", 43 + 3, 44 + "go", 45 + "Pattern match failed, no pattern matched the value.", 46 + { value: x } 47 + ) 48 + } 49 + return x; 50 + }
+50
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_match_utf32_little_endian.snap
··· 1 + --- 2 + source: compiler-core/src/javascript/tests/bit_arrays.rs 3 + expression: "\npub fn go(x) {\n let assert <<\"Hello\":utf32-little, _rest:bytes>> = x\n}\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + pub fn go(x) { 8 + let assert <<"Hello":utf32-little, _rest:bytes>> = x 9 + } 10 + 11 + 12 + ----- COMPILED JAVASCRIPT 13 + import { makeError } from "../gleam.mjs"; 14 + 15 + export function go(x) { 16 + if ( 17 + x.bitSize < 160 || 18 + x.byteAt(0) !== 72 || 19 + x.byteAt(1) !== 0 || 20 + x.byteAt(2) !== 0 || 21 + x.byteAt(3) !== 0 || 22 + x.byteAt(4) !== 101 || 23 + x.byteAt(5) !== 0 || 24 + x.byteAt(6) !== 0 || 25 + x.byteAt(7) !== 0 || 26 + x.byteAt(8) !== 108 || 27 + x.byteAt(9) !== 0 || 28 + x.byteAt(10) !== 0 || 29 + x.byteAt(11) !== 0 || 30 + x.byteAt(12) !== 108 || 31 + x.byteAt(13) !== 0 || 32 + x.byteAt(14) !== 0 || 33 + x.byteAt(15) !== 0 || 34 + x.byteAt(16) !== 111 || 35 + x.byteAt(17) !== 0 || 36 + x.byteAt(18) !== 0 || 37 + x.byteAt(19) !== 0 || 38 + (x.bitSize - 160) % 8 !== 0 39 + ) { 40 + throw makeError( 41 + "let_assert", 42 + "my/mod", 43 + 3, 44 + "go", 45 + "Pattern match failed, no pattern matched the value.", 46 + { value: x } 47 + ) 48 + } 49 + return x; 50 + }
+17
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__utf16.snap
··· 1 + --- 2 + source: compiler-core/src/javascript/tests/bit_arrays.rs 3 + expression: "\npub fn main() {\n <<\"Hello, world!\":utf16>>\n}\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + pub fn main() { 8 + <<"Hello, world!":utf16>> 9 + } 10 + 11 + 12 + ----- COMPILED JAVASCRIPT 13 + import { toBitArray, stringToUtf16 } from "../gleam.mjs"; 14 + 15 + export function main() { 16 + return toBitArray([stringToUtf16("Hello, world!", true)]); 17 + }
+32
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__utf16_codepoint.snap
··· 1 + --- 2 + source: compiler-core/src/javascript/tests/bit_arrays.rs 3 + expression: "\nfn codepoint() -> UtfCodepoint { todo }\n\npub fn main() {\n let my_codepoint = codepoint()\n <<my_codepoint:utf16_codepoint>>\n}\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + fn codepoint() -> UtfCodepoint { todo } 8 + 9 + pub fn main() { 10 + let my_codepoint = codepoint() 11 + <<my_codepoint:utf16_codepoint>> 12 + } 13 + 14 + 15 + ----- COMPILED JAVASCRIPT 16 + import { makeError, toBitArray, codepointToUtf16 } from "../gleam.mjs"; 17 + 18 + function codepoint() { 19 + throw makeError( 20 + "todo", 21 + "my/mod", 22 + 2, 23 + "codepoint", 24 + "`todo` expression evaluated. This code has not yet been implemented.", 25 + {} 26 + ) 27 + } 28 + 29 + export function main() { 30 + let my_codepoint = codepoint(); 31 + return toBitArray([codepointToUtf16(my_codepoint, true)]); 32 + }
+17
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__utf16_little_endian.snap
··· 1 + --- 2 + source: compiler-core/src/javascript/tests/bit_arrays.rs 3 + expression: "\npub fn main() {\n <<\"Hello, world!\":utf16-little>>\n}\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + pub fn main() { 8 + <<"Hello, world!":utf16-little>> 9 + } 10 + 11 + 12 + ----- COMPILED JAVASCRIPT 13 + import { toBitArray, stringToUtf16 } from "../gleam.mjs"; 14 + 15 + export function main() { 16 + return toBitArray([stringToUtf16("Hello, world!", false)]); 17 + }
+17
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__utf32.snap
··· 1 + --- 2 + source: compiler-core/src/javascript/tests/bit_arrays.rs 3 + expression: "\npub fn main() {\n <<\"Hello, world!\":utf32>>\n}\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + pub fn main() { 8 + <<"Hello, world!":utf32>> 9 + } 10 + 11 + 12 + ----- COMPILED JAVASCRIPT 13 + import { toBitArray, stringToUtf32 } from "../gleam.mjs"; 14 + 15 + export function main() { 16 + return toBitArray([stringToUtf32("Hello, world!", true)]); 17 + }
+32
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__utf32_codepoint.snap
··· 1 + --- 2 + source: compiler-core/src/javascript/tests/bit_arrays.rs 3 + expression: "\nfn codepoint() -> UtfCodepoint { todo }\n\npub fn main() {\n let my_codepoint = codepoint()\n <<my_codepoint:utf32_codepoint>>\n}\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + fn codepoint() -> UtfCodepoint { todo } 8 + 9 + pub fn main() { 10 + let my_codepoint = codepoint() 11 + <<my_codepoint:utf32_codepoint>> 12 + } 13 + 14 + 15 + ----- COMPILED JAVASCRIPT 16 + import { makeError, toBitArray, codepointToUtf32 } from "../gleam.mjs"; 17 + 18 + function codepoint() { 19 + throw makeError( 20 + "todo", 21 + "my/mod", 22 + 2, 23 + "codepoint", 24 + "`todo` expression evaluated. This code has not yet been implemented.", 25 + {} 26 + ) 27 + } 28 + 29 + export function main() { 30 + let my_codepoint = codepoint(); 31 + return toBitArray([codepointToUtf32(my_codepoint, true)]); 32 + }
+17
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__utf32_little_endian.snap
··· 1 + --- 2 + source: compiler-core/src/javascript/tests/bit_arrays.rs 3 + expression: "\npub fn main() {\n <<\"Hello, world!\":utf32-little>>\n}\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + pub fn main() { 8 + <<"Hello, world!":utf32-little>> 9 + } 10 + 11 + 12 + ----- COMPILED JAVASCRIPT 13 + import { toBitArray, stringToUtf32 } from "../gleam.mjs"; 14 + 15 + export function main() { 16 + return toBitArray([stringToUtf32("Hello, world!", false)]); 17 + }
+88
test/language/test/language_test.gleam
··· 33 33 "dynamic sized bit array patterns", 34 34 dynamic_size_bit_array_pattern_tests(), 35 35 ), 36 + suite("non UTF-8 string bit arrays", non_utf8_string_bit_array_tests()), 36 37 suite("list spread", list_spread_tests()), 37 38 suite("clause guards", clause_guard_tests()), 38 39 suite("imported custom types", imported_custom_types_test()), ··· 1604 1605 let size = size + 2 1605 1606 let assert <<value:size(size)>> = <<61:6>> 1606 1607 value 1608 + }) 1609 + }), 1610 + ] 1611 + } 1612 + 1613 + fn non_utf8_string_bit_array_tests() -> List(Test) { 1614 + [ 1615 + "let assert <<\"Hello, world\":utf16>> = <<\"Hello, world\":utf16>>" 1616 + |> example(fn() { 1617 + assert_equal("Hello, world", { 1618 + let assert <<"Hello, world":utf16>> = <<"Hello, world":utf16>> 1619 + "Hello, world" 1620 + }) 1621 + }), 1622 + "let assert <<\"Hello, world\":utf32>> = <<\"Hello, world\":utf32>>" 1623 + |> example(fn() { 1624 + assert_equal("Hello, world", { 1625 + let assert <<"Hello, world":utf32>> = <<"Hello, world":utf32>> 1626 + "Hello, world" 1627 + }) 1628 + }), 1629 + "UTF-16 bytes" 1630 + |> example(fn() { 1631 + assert_equal(<<"Hello, 🌍!":utf16>>, << 1632 + 0, 72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 44, 0, 32, 216, 60, 223, 13, 1633 + 0, 33, 1634 + >>) 1635 + }), 1636 + "UTF-32 bytes" 1637 + |> example(fn() { 1638 + assert_equal(<<"Hello, 🌍!":utf32>>, << 1639 + 0, 0, 0, 72, 0, 0, 0, 101, 0, 0, 0, 108, 0, 0, 0, 108, 0, 0, 0, 111, 0, 1640 + 0, 0, 44, 0, 0, 0, 32, 0, 1, 243, 13, 0, 0, 0, 33, 1641 + >>) 1642 + }), 1643 + "UTF-16 pattern matching" 1644 + |> example(fn() { 1645 + assert_equal("Hello, 🌍!", { 1646 + let assert <<"Hello, 🌍!":utf16>> = << 1647 + 0, 72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 44, 0, 32, 216, 60, 223, 1648 + 13, 0, 33, 1649 + >> 1650 + "Hello, 🌍!" 1651 + }) 1652 + }), 1653 + "UTF-32 pattern matching" 1654 + |> example(fn() { 1655 + assert_equal("Hello, 🌍!", { 1656 + let assert <<"Hello, 🌍!":utf32>> = << 1657 + 0, 0, 0, 72, 0, 0, 0, 101, 0, 0, 0, 108, 0, 0, 0, 108, 0, 0, 0, 111, 1658 + 0, 0, 0, 44, 0, 0, 0, 32, 0, 1, 243, 13, 0, 0, 0, 33, 1659 + >> 1660 + "Hello, 🌍!" 1661 + }) 1662 + }), 1663 + "UTF-16 bytes little endian" 1664 + |> example(fn() { 1665 + assert_equal(<<"Hello, 🌍!":utf16-little>>, << 1666 + 72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 44, 0, 32, 0, 60, 216, 13, 223, 1667 + 33, 0, 1668 + >>) 1669 + }), 1670 + "UTF-32 bytes little endian" 1671 + |> example(fn() { 1672 + assert_equal(<<"Hello, 🌍!":utf32-little>>, << 1673 + 72, 0, 0, 0, 101, 0, 0, 0, 108, 0, 0, 0, 108, 0, 0, 0, 111, 0, 0, 0, 1674 + 44, 0, 0, 0, 32, 0, 0, 0, 13, 243, 1, 0, 33, 0, 0, 0, 1675 + >>) 1676 + }), 1677 + "UTF-16 pattern matching little endian" 1678 + |> example(fn() { 1679 + assert_equal("Hello, 🌍!", { 1680 + let assert <<"Hello, 🌍!":utf16-little>> = << 1681 + 72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 44, 0, 32, 0, 60, 216, 13, 1682 + 223, 33, 0, 1683 + >> 1684 + "Hello, 🌍!" 1685 + }) 1686 + }), 1687 + "UTF-32 pattern matching little endian" 1688 + |> example(fn() { 1689 + assert_equal("Hello, 🌍!", { 1690 + let assert <<"Hello, 🌍!":utf32-little>> = << 1691 + 72, 0, 0, 0, 101, 0, 0, 0, 108, 0, 0, 0, 108, 0, 0, 0, 111, 0, 0, 0, 1692 + 44, 0, 0, 0, 32, 0, 0, 0, 13, 243, 1, 0, 33, 0, 0, 0, 1693 + >> 1694 + "Hello, 🌍!" 1607 1695 }) 1608 1696 }), 1609 1697 ]