Skip to content

Commit a0487cf

Browse files
authored
Fix WASM sysroot breaking runtime behavior (#37)
* Fix WASM sysroot breaking runtime behavior * Add WASM tests to CI
1 parent 22f6407 commit a0487cf

15 files changed

+147
-120
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,28 @@ jobs:
1818
run: cargo build --verbose
1919
- name: Run tests
2020
run: cargo test --verbose
21+
test-wasm:
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- uses: actions/checkout@v3
26+
- name: Install wasm32 target
27+
uses: actions-rs/toolchain@v1
28+
with:
29+
toolchain: stable
30+
target: wasm32-unknown-unknown
31+
- name: Install WebAssembly test runner
32+
uses: actions-rs/cargo@v1
33+
with:
34+
command: install
35+
args: wasm-bindgen-cli --version 0.2.83
36+
- name: Run tests
37+
uses: actions-rs/cargo@v1
38+
env:
39+
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER: wasm-bindgen-test-runner
40+
with:
41+
command: test
42+
args: -p rust-sitter-example --target wasm32-unknown-unknown --tests --no-fail-fast
2143
lint:
2244
runs-on: ubuntu-latest
2345
steps:

Cargo.lock

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ rust-sitter-tool = { path = "../tool" }
2020

2121
[dev-dependencies]
2222
insta = "1.7.1"
23+
wasm-bindgen-test = "0.3.0"

example/src/arithmetic.rs

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[rust_sitter::grammar("arithmetic")]
22
pub mod grammar {
33
#[rust_sitter::language]
4-
#[derive(Debug)]
4+
#[derive(PartialEq, Eq, Debug)]
55
pub enum Expression {
66
Number(#[rust_sitter::leaf(pattern = r"\d+", transform = |v| v.parse().unwrap())] i32),
77
#[rust_sitter::prec_left(1)]
@@ -28,18 +28,77 @@ pub mod grammar {
2828
#[cfg(test)]
2929
mod tests {
3030
use super::*;
31+
use grammar::Expression;
3132

33+
#[wasm_bindgen_test::wasm_bindgen_test]
3234
#[test]
33-
fn arithmetic_grammar() {
34-
// successful parses
35-
insta::assert_debug_snapshot!(grammar::parse("1"));
36-
insta::assert_debug_snapshot!(grammar::parse("1 - 2"));
37-
insta::assert_debug_snapshot!(grammar::parse("1 - 2 - 3"));
38-
insta::assert_debug_snapshot!(grammar::parse("1 - 2 * 3"));
39-
insta::assert_debug_snapshot!(grammar::parse("1 * 2 * 3"));
40-
insta::assert_debug_snapshot!(grammar::parse("1 * 2 - 3"));
41-
42-
// failed parses
35+
fn successful_parses() {
36+
assert_eq!(grammar::parse("1").unwrap(), Expression::Number(1));
37+
38+
assert_eq!(
39+
grammar::parse("1 - 2").unwrap(),
40+
Expression::Sub(
41+
Box::new(Expression::Number(1)),
42+
(),
43+
Box::new(Expression::Number(2))
44+
)
45+
);
46+
47+
assert_eq!(
48+
grammar::parse("1 - 2 - 3").unwrap(),
49+
Expression::Sub(
50+
Box::new(Expression::Sub(
51+
Box::new(Expression::Number(1)),
52+
(),
53+
Box::new(Expression::Number(2))
54+
)),
55+
(),
56+
Box::new(Expression::Number(3))
57+
)
58+
);
59+
60+
assert_eq!(
61+
grammar::parse("1 - 2 * 3").unwrap(),
62+
Expression::Sub(
63+
Box::new(Expression::Number(1)),
64+
(),
65+
Box::new(Expression::Mul(
66+
Box::new(Expression::Number(2)),
67+
(),
68+
Box::new(Expression::Number(3))
69+
))
70+
)
71+
);
72+
73+
assert_eq!(
74+
grammar::parse("1 * 2 * 3").unwrap(),
75+
Expression::Mul(
76+
Box::new(Expression::Mul(
77+
Box::new(Expression::Number(1)),
78+
(),
79+
Box::new(Expression::Number(2))
80+
)),
81+
(),
82+
Box::new(Expression::Number(3))
83+
)
84+
);
85+
86+
assert_eq!(
87+
grammar::parse("1 * 2 - 3").unwrap(),
88+
Expression::Sub(
89+
Box::new(Expression::Mul(
90+
Box::new(Expression::Number(1)),
91+
(),
92+
Box::new(Expression::Number(2))
93+
)),
94+
(),
95+
Box::new(Expression::Number(3))
96+
)
97+
);
98+
}
99+
100+
#[test]
101+
fn failed_parses() {
43102
insta::assert_debug_snapshot!(grammar::parse("1 + 2"));
44103
insta::assert_debug_snapshot!(grammar::parse("1 - 2 -"));
45104
insta::assert_debug_snapshot!(grammar::parse("a1"));

example/src/snapshots/rust_sitter_example__arithmetic__tests__arithmetic_grammar-2.snap

Lines changed: 0 additions & 15 deletions
This file was deleted.

example/src/snapshots/rust_sitter_example__arithmetic__tests__arithmetic_grammar-3.snap

Lines changed: 0 additions & 21 deletions
This file was deleted.

example/src/snapshots/rust_sitter_example__arithmetic__tests__arithmetic_grammar-4.snap

Lines changed: 0 additions & 21 deletions
This file was deleted.

example/src/snapshots/rust_sitter_example__arithmetic__tests__arithmetic_grammar-5.snap

Lines changed: 0 additions & 21 deletions
This file was deleted.

example/src/snapshots/rust_sitter_example__arithmetic__tests__arithmetic_grammar-6.snap

Lines changed: 0 additions & 21 deletions
This file was deleted.

example/src/snapshots/rust_sitter_example__arithmetic__tests__arithmetic_grammar.snap

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)