Skip to content

Commit ae782cf

Browse files
GearsDatapackslpil
authored andcommitted
Add test case
1 parent 4280f7f commit ae782cf

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

compiler-core/src/erlang/tests/case.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,18 @@ pub fn main() {
185185
"#
186186
);
187187
}
188+
189+
#[test]
190+
fn bit_array_assignment_different_string_encodings() {
191+
assert_erl!(
192+
r#"
193+
pub fn main() {
194+
case <<>> {
195+
<<"wibble" as m:utf16, _:bits>>
196+
| <<"wobble" as m:utf32, 1, _:bits>> -> m
197+
_ -> ""
198+
}
199+
}
200+
"#
201+
);
202+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
source: compiler-core/src/erlang/tests/case.rs
3+
expression: "\npub fn main() {\n case <<>> {\n <<\"wibble\" as m:utf16, _:bits>>\n | <<\"wobble\" as m:utf32, 1, _:bits>> -> m\n _ -> \"\"\n }\n}\n"
4+
---
5+
----- SOURCE CODE
6+
7+
pub fn main() {
8+
case <<>> {
9+
<<"wibble" as m:utf16, _:bits>>
10+
| <<"wobble" as m:utf32, 1, _:bits>> -> m
11+
_ -> ""
12+
}
13+
}
14+
15+
16+
----- COMPILED ERLANG
17+
-module(my@mod).
18+
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
19+
20+
-export([main/0]).
21+
22+
-file("project/test/my/mod.gleam", 2).
23+
-spec main() -> binary().
24+
main() ->
25+
case <<>> of
26+
<<"wibble"/utf16, _/bitstring>> ->
27+
M@1 = <<"wibble"/utf8>>,
28+
M@1;
29+
30+
<<"wobble"/utf32, 1, _/bitstring>> ->
31+
M@1 = <<"wobble"/utf8>>,
32+
M@1;
33+
34+
_ ->
35+
<<""/utf8>>
36+
end.

0 commit comments

Comments
 (0)