-
-
Notifications
You must be signed in to change notification settings - Fork 801
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8c45f0
commit b1758e2
Showing
7 changed files
with
193 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
.../snapshots/gleam_core__javascript__tests__bit_arrays__dynamic_size_pattern_with_unit.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
source: compiler-core/src/javascript/tests/bit_arrays.rs | ||
expression: "\nfn go(x) {\n let size = 3\n let assert <<1:size(size)-unit(2)>> = x\n}\n" | ||
--- | ||
----- SOURCE CODE | ||
|
||
fn go(x) { | ||
let size = 3 | ||
let assert <<1:size(size)-unit(2)>> = x | ||
} | ||
|
||
|
||
----- COMPILED JAVASCRIPT | ||
import { makeError, bitArraySliceToInt } from "../gleam.mjs"; | ||
|
||
function go(x) { | ||
let size = 3; | ||
if ( | ||
bitArraySliceToInt(x, 0, size * 2, true, false) !== 1 || | ||
!(x.bitSize == size * 2) | ||
) { | ||
throw makeError( | ||
"let_assert", | ||
"my/mod", | ||
4, | ||
"go", | ||
"Pattern match failed, no pattern matched the value.", | ||
{ value: x } | ||
) | ||
} | ||
return x; | ||
} |
19 changes: 19 additions & 0 deletions
19
...pt/tests/snapshots/gleam_core__javascript__tests__bit_arrays__dynamic_size_with_unit.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
source: compiler-core/src/javascript/tests/bit_arrays.rs | ||
expression: "\nfn main() {\n let size = 3\n <<1:size(size)-unit(2)>>\n}\n" | ||
--- | ||
----- SOURCE CODE | ||
|
||
fn main() { | ||
let size = 3 | ||
<<1:size(size)-unit(2)>> | ||
} | ||
|
||
|
||
----- COMPILED JAVASCRIPT | ||
import { toBitArray, sizedInt } from "../gleam.mjs"; | ||
|
||
function main() { | ||
let size = 3; | ||
return toBitArray([sizedInt(1, size * 2, true)]); | ||
} |
31 changes: 31 additions & 0 deletions
31
...ascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_with_unit.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
source: compiler-core/src/javascript/tests/bit_arrays.rs | ||
expression: "\nfn go(x) {\n let assert <<1:size(2)-unit(2), 2:size(3)-unit(4)>> = x\n}\n" | ||
--- | ||
----- SOURCE CODE | ||
|
||
fn go(x) { | ||
let assert <<1:size(2)-unit(2), 2:size(3)-unit(4)>> = x | ||
} | ||
|
||
|
||
----- COMPILED JAVASCRIPT | ||
import { makeError, bitArraySliceToInt } from "../gleam.mjs"; | ||
|
||
function go(x) { | ||
if ( | ||
bitArraySliceToInt(x, 0, 4, true, false) !== 1 || | ||
bitArraySliceToInt(x, 4, 16, true, false) !== 2 || | ||
!(x.bitSize == 16) | ||
) { | ||
throw makeError( | ||
"let_assert", | ||
"my/mod", | ||
3, | ||
"go", | ||
"Pattern match failed, no pattern matched the value.", | ||
{ value: x } | ||
) | ||
} | ||
return x; | ||
} |
17 changes: 17 additions & 0 deletions
17
.../src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__with_unit.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
source: compiler-core/src/javascript/tests/bit_arrays.rs | ||
expression: "\nfn main() {\n <<1:size(2)-unit(2), 2:size(3)-unit(4)>>\n}\n" | ||
--- | ||
----- SOURCE CODE | ||
|
||
fn main() { | ||
<<1:size(2)-unit(2), 2:size(3)-unit(4)>> | ||
} | ||
|
||
|
||
----- COMPILED JAVASCRIPT | ||
import { toBitArray, sizedInt } from "../gleam.mjs"; | ||
|
||
function main() { | ||
return toBitArray([sizedInt(1, 4, true), sizedInt(2, 12, true)]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters