-
Notifications
You must be signed in to change notification settings - Fork 4
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
12509d5
commit 94329c5
Showing
2 changed files
with
80 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,8 @@ defmodule I32ConveniencesTest do | |
(char >= ?A &&& char <= ?Z) or | ||
(char >= ?0 &&& char <= ?9) or | ||
I32.in?(char, [?~, ?_, ?-, ?.]) | ||
# I32.in?(char, ~C{~_-.}) | ||
|
||
# I32.in?(char, ~C{~_-.}) | ||
|
||
# I32.in_inclusive_range?(char, ?a, ?z) or | ||
# I32.in_inclusive_range?(char, ?A, ?Z) or | ||
|
@@ -61,66 +62,86 @@ defmodule I32ConveniencesTest do | |
|
||
test "attr_writer works" do | ||
assert Attrs.to_wat() === """ | ||
(module $Attrs | ||
(global $first (mut i32) (i32.const 7)) | ||
(func $first= (export "first=") (param $new_value i32) | ||
(local.get $new_value) | ||
(global.set $first) | ||
) | ||
) | ||
""" | ||
(module $Attrs | ||
(global $first (mut i32) (i32.const 7)) | ||
(func $first= (export "first=") (param $new_value i32) | ||
(local.get $new_value) | ||
(global.set $first) | ||
) | ||
) | ||
""" | ||
|
||
assert Wasm.call(Attrs, :"first=", 9) == nil | ||
end | ||
|
||
test "I32.match output int" do | ||
assert (OrbHelper.module_wat do | ||
use Orb | ||
use Orb | ||
|
||
defw get_path(), I32.String, state: I32 do | ||
state = 0 | ||
defw get_path(), I32.String, state: I32 do | ||
state = 0 | ||
|
||
I32.match state do | ||
0 -> 100 | ||
1 -> 200 | ||
end | ||
end | ||
end) =~ "(i32.const 100)" | ||
I32.match state do | ||
0 -> 100 | ||
1 -> 200 | ||
end | ||
end | ||
end) =~ "(i32.const 100)" | ||
end | ||
|
||
test "I32.match output string constant" do | ||
assert (OrbHelper.module_wat do | ||
use Orb | ||
use Orb | ||
|
||
defw get_path(), I32.String, state: I32 do | ||
state = 0 | ||
defw get_path(), I32.String, state: I32 do | ||
state = 0 | ||
|
||
I32.match state do | ||
0 -> ~S[/initial] | ||
1 -> ~S[/disconnected] | ||
end | ||
end | ||
end) =~ "/initial" | ||
I32.match state do | ||
0 -> ~S[/initial] | ||
1 -> ~S[/disconnected] | ||
end | ||
end | ||
end) =~ "/initial" | ||
end | ||
|
||
test "can return string constant" do | ||
assert (OrbHelper.module_wat do | ||
use Orb | ||
|
||
global do | ||
@method "GET" | ||
end | ||
|
||
defw text_html(), I32.String do | ||
if not I32.String.streq(@method, "GET") do | ||
return(~S""" | ||
<!doctype html> | ||
<h1>Method not allowed</h1> | ||
""") | ||
end | ||
use Orb | ||
|
||
global do | ||
@method "GET" | ||
Check warning on line 112 in test/i32/conveniences_test.exs GitHub Actions / Build and test (26.0.2, 1.15.2)
Check warning on line 112 in test/i32/conveniences_test.exs GitHub Actions / Build and test (25.3.2, 1.15.2)
|
||
end | ||
|
||
defw text_html(), I32.String do | ||
if not I32.String.streq(@method, "GET") do | ||
return(~S""" | ||
<!doctype html> | ||
<h1>Method not allowed</h1> | ||
""") | ||
end | ||
|
||
"<p>Hello</p>" | ||
end | ||
end) =~ "Method not allowed" | ||
end | ||
|
||
"<p>Hello</p>" | ||
end | ||
end) =~ "Method not allowed" | ||
test "I32.sum!" do | ||
assert 30 = | ||
(OrbHelper.module_wat do | ||
use Orb | ||
|
||
defwp(ten(), I32, do: 10) | ||
|
||
defw sum(), I32 do | ||
I32.sum!([ | ||
byte_size("hello"), | ||
byte_size("beautiful"), | ||
byte_size("world"), | ||
if(ten(), do: 1, else: 200), | ||
ten() | ||
]) | ||
end | ||
end) | ||
|> Wasm.call(:sum) | ||
end | ||
end |