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