Compare commits
3 commits
605798674f
...
d41cd57847
| Author | SHA1 | Date | |
|---|---|---|---|
| d41cd57847 | |||
| 9aeeb4eb5b | |||
| 06816567ff |
50 changed files with 272 additions and 271 deletions
13
Cargo.lock
generated
13
Cargo.lock
generated
|
|
@ -442,6 +442,7 @@ dependencies = [
|
||||||
"insta",
|
"insta",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"test_each_file",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"winnow",
|
"winnow",
|
||||||
]
|
]
|
||||||
|
|
@ -701,6 +702,18 @@ dependencies = [
|
||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "test_each_file"
|
||||||
|
version = "0.3.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "44619e49a1f62888c271dc50533f036363a7936f99c7cb467ca9d45224cf83b3"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "2.0.18"
|
version = "2.0.18"
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,10 @@ edition = "2024"
|
||||||
name = "parsing"
|
name = "parsing"
|
||||||
harness = false
|
harness = false
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "asting"
|
||||||
|
harness = false
|
||||||
|
|
||||||
[profile.bench]
|
[profile.bench]
|
||||||
debug = true
|
debug = true
|
||||||
|
|
||||||
|
|
@ -23,6 +27,7 @@ criterion = "0.8.2"
|
||||||
insta = { version = "1.46.3", features = ["glob", "serde"] }
|
insta = { version = "1.46.3", features = ["glob", "serde"] }
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
serde_json = "1.0.149"
|
serde_json = "1.0.149"
|
||||||
|
test_each_file = "0.3.7"
|
||||||
|
|
||||||
[profile.dev.package]
|
[profile.dev.package]
|
||||||
insta.opt-level = 3
|
insta.opt-level = 3
|
||||||
|
|
|
||||||
54
benches/asting.rs
Normal file
54
benches/asting.rs
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
use criterion::BenchmarkId;
|
||||||
|
use criterion::Criterion;
|
||||||
|
use criterion::criterion_group;
|
||||||
|
use criterion::criterion_main;
|
||||||
|
use nomo::input::NomoInput;
|
||||||
|
|
||||||
|
fn asting_benchmark(c: &mut Criterion) {
|
||||||
|
let mut parsing = c.benchmark_group("Asting");
|
||||||
|
|
||||||
|
for size in [1, 10, 200, 1000] {
|
||||||
|
let mut input = String::new();
|
||||||
|
|
||||||
|
for _ in 0..size {
|
||||||
|
input.push_str("{{ if foo }}{{= variable }}{{ end }}");
|
||||||
|
}
|
||||||
|
|
||||||
|
let input = NomoInput::from(input);
|
||||||
|
|
||||||
|
parsing.throughput(criterion::Throughput::Bytes(input.len() as u64));
|
||||||
|
parsing.bench_with_input(BenchmarkId::from_parameter(size), &input, |b, input| {
|
||||||
|
b.iter(|| {
|
||||||
|
let tokens = nomo::parser::parse(input.clone()).unwrap();
|
||||||
|
let _ast = nomo::ast::parse(tokens.tokens()).unwrap();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn asting_nested(c: &mut Criterion) {
|
||||||
|
let mut parsing = c.benchmark_group("Asting");
|
||||||
|
|
||||||
|
for size in [1, 2, 8, 12] {
|
||||||
|
let mut input = String::new();
|
||||||
|
|
||||||
|
for _ in 0..size {
|
||||||
|
input = format!(
|
||||||
|
"{{{{ for foo in bar }}}} {input} {{{{ if foo }}}} Hi! {input} {{{{ end }}}} Yooo {{{{ end }}}}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let input = NomoInput::from(input);
|
||||||
|
|
||||||
|
parsing.throughput(criterion::Throughput::Bytes(input.len() as u64));
|
||||||
|
parsing.bench_with_input(BenchmarkId::from_parameter(size), &input, |b, input| {
|
||||||
|
b.iter(|| {
|
||||||
|
let tokens = nomo::parser::parse(input.clone()).unwrap();
|
||||||
|
let _ast = nomo::ast::parse(tokens.tokens()).unwrap();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!(benches, asting_benchmark, asting_nested);
|
||||||
|
criterion_main!(benches);
|
||||||
|
|
@ -1,152 +0,0 @@
|
||||||
---
|
|
||||||
source: src/ast/mod.rs
|
|
||||||
expression: parsed
|
|
||||||
---
|
|
||||||
ParsedTemplate {
|
|
||||||
tokens: [
|
|
||||||
TemplateToken {
|
|
||||||
kind: LeftDelim,
|
|
||||||
source: "{{" (0..2),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Whitespace,
|
|
||||||
source: " " (2..3),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: ConditionalIf,
|
|
||||||
source: "if" (3..5),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Whitespace,
|
|
||||||
source: " " (5..6),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Ident,
|
|
||||||
source: "foo" (6..9),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Whitespace,
|
|
||||||
source: " " (9..10),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: RightDelim,
|
|
||||||
source: "}}" (10..12),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Whitespace,
|
|
||||||
source: "\n " (12..25),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: LeftDelim,
|
|
||||||
source: "{{" (25..27),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Whitespace,
|
|
||||||
source: " " (27..28),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: ConditionalIf,
|
|
||||||
source: "if" (28..30),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Whitespace,
|
|
||||||
source: " " (30..31),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Ident,
|
|
||||||
source: "bar" (31..34),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Whitespace,
|
|
||||||
source: " " (34..35),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: RightDelim,
|
|
||||||
source: "}}" (35..37),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Whitespace,
|
|
||||||
source: "\n " (37..54),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Content,
|
|
||||||
source: "Hiii" (54..58),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Whitespace,
|
|
||||||
source: "\n " (58..71),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: LeftDelim,
|
|
||||||
source: "{{" (71..73),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Whitespace,
|
|
||||||
source: " " (73..74),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: End,
|
|
||||||
source: "end" (74..77),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Whitespace,
|
|
||||||
source: " " (77..78),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: RightDelim,
|
|
||||||
source: "}}" (78..80),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Whitespace,
|
|
||||||
source: "\n " (80..89),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: LeftDelim,
|
|
||||||
source: "{{" (89..91),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Whitespace,
|
|
||||||
source: " " (91..92),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: End,
|
|
||||||
source: "end" (92..95),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Whitespace,
|
|
||||||
source: " " (95..96),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: RightDelim,
|
|
||||||
source: "}}" (96..98),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Whitespace,
|
|
||||||
source: "\n\n " (98..108),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: LeftDelim,
|
|
||||||
source: "{{" (108..110),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Whitespace,
|
|
||||||
source: " " (110..111),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Ident,
|
|
||||||
source: "value" (111..116),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Whitespace,
|
|
||||||
source: " " (116..117),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: RightDelim,
|
|
||||||
source: "}}" (117..119),
|
|
||||||
},
|
|
||||||
TemplateToken {
|
|
||||||
kind: Whitespace,
|
|
||||||
source: "\n " (119..128),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
---
|
|
||||||
source: tests/file_tests.rs
|
|
||||||
expression: output
|
|
||||||
input_file: tests/cases/condition.nomo
|
|
||||||
---
|
|
||||||
"\n Hello World!\n\n\nmore"
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
---
|
|
||||||
source: tests/file_tests.rs
|
|
||||||
expression: output
|
|
||||||
input_file: tests/cases/identifiers.nomo
|
|
||||||
---
|
|
||||||
"Foo\nFoo\nFoo\nFoo\nFoo\nFoo"
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
---
|
|
||||||
source: tests/file_tests.rs
|
|
||||||
expression: output
|
|
||||||
input_file: tests/cases/if_else_if.nomo
|
|
||||||
---
|
|
||||||
"\n Hello World!\n"
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
---
|
|
||||||
source: tests/file_tests.rs
|
|
||||||
expression: output
|
|
||||||
input_file: tests/cases/multiple.nomo
|
|
||||||
---
|
|
||||||
"Hi there! My name is Hemera Green"
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
---
|
|
||||||
source: tests/file_tests.rs
|
|
||||||
expression: output
|
|
||||||
input_file: tests/cases/trim_whitespace.nomo
|
|
||||||
---
|
|
||||||
"Hello Hemera"
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: parsed
|
expression: parsed
|
||||||
input_file: tests/cases/condition.nomo
|
info:
|
||||||
|
input: "{{ if test }}\n Hello World!\n{{ end }}\n\n{{= stuff }}"
|
||||||
|
context:
|
||||||
|
stuff: more
|
||||||
|
test: true
|
||||||
---
|
---
|
||||||
ParsedTemplate {
|
ParsedTemplate {
|
||||||
tokens: [
|
tokens: [
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: ast
|
expression: ast
|
||||||
input_file: tests/cases/condition.nomo
|
info:
|
||||||
|
input: "{{ if test }}\n Hello World!\n{{ end }}\n\n{{= stuff }}"
|
||||||
|
context:
|
||||||
|
stuff: more
|
||||||
|
test: true
|
||||||
---
|
---
|
||||||
TemplateAst {
|
TemplateAst {
|
||||||
root: [
|
root: [
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: emit
|
expression: emit
|
||||||
input_file: tests/cases/condition.nomo
|
info:
|
||||||
|
input: "{{ if test }}\n Hello World!\n{{ end }}\n\n{{= stuff }}"
|
||||||
|
context:
|
||||||
|
stuff: more
|
||||||
|
test: true
|
||||||
---
|
---
|
||||||
VMInstructions {
|
VMInstructions {
|
||||||
labels: {
|
labels: {
|
||||||
10
tests/cases/condition.4-output.snap
Normal file
10
tests/cases/condition.4-output.snap
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
source: tests/file_tests.rs
|
||||||
|
expression: output
|
||||||
|
info:
|
||||||
|
input: "{{ if test }}\n Hello World!\n{{ end }}\n\n{{= stuff }}"
|
||||||
|
context:
|
||||||
|
stuff: more
|
||||||
|
test: true
|
||||||
|
---
|
||||||
|
"\n Hello World!\n\n\nmore"
|
||||||
|
|
@ -4,13 +4,12 @@ expression: parsed
|
||||||
info:
|
info:
|
||||||
input: "{{= _name }}\n{{= a_name }}\n{{= name }}\n{{= _name1 }}\n{{= _namE }}\n{{= name1 }}"
|
input: "{{= _name }}\n{{= a_name }}\n{{= name }}\n{{= _name1 }}\n{{= _namE }}\n{{= name1 }}"
|
||||||
context:
|
context:
|
||||||
_namE: Foo
|
|
||||||
name1: Foo
|
name1: Foo
|
||||||
name: Foo
|
|
||||||
_name: Foo
|
_name: Foo
|
||||||
|
_namE: Foo
|
||||||
a_name: Foo
|
a_name: Foo
|
||||||
|
name: Foo
|
||||||
_name1: Foo
|
_name1: Foo
|
||||||
input_file: tests/cases/identifiers.nomo
|
|
||||||
---
|
---
|
||||||
ParsedTemplate {
|
ParsedTemplate {
|
||||||
tokens: [
|
tokens: [
|
||||||
|
|
@ -4,13 +4,12 @@ expression: ast
|
||||||
info:
|
info:
|
||||||
input: "{{= _name }}\n{{= a_name }}\n{{= name }}\n{{= _name1 }}\n{{= _namE }}\n{{= name1 }}"
|
input: "{{= _name }}\n{{= a_name }}\n{{= name }}\n{{= _name1 }}\n{{= _namE }}\n{{= name1 }}"
|
||||||
context:
|
context:
|
||||||
_namE: Foo
|
|
||||||
name1: Foo
|
name1: Foo
|
||||||
name: Foo
|
|
||||||
_name: Foo
|
_name: Foo
|
||||||
|
_namE: Foo
|
||||||
a_name: Foo
|
a_name: Foo
|
||||||
|
name: Foo
|
||||||
_name1: Foo
|
_name1: Foo
|
||||||
input_file: tests/cases/identifiers.nomo
|
|
||||||
---
|
---
|
||||||
TemplateAst {
|
TemplateAst {
|
||||||
root: [
|
root: [
|
||||||
|
|
@ -4,13 +4,12 @@ expression: emit
|
||||||
info:
|
info:
|
||||||
input: "{{= _name }}\n{{= a_name }}\n{{= name }}\n{{= _name1 }}\n{{= _namE }}\n{{= name1 }}"
|
input: "{{= _name }}\n{{= a_name }}\n{{= name }}\n{{= _name1 }}\n{{= _namE }}\n{{= name1 }}"
|
||||||
context:
|
context:
|
||||||
_namE: Foo
|
|
||||||
name1: Foo
|
name1: Foo
|
||||||
name: Foo
|
|
||||||
_name: Foo
|
_name: Foo
|
||||||
|
_namE: Foo
|
||||||
a_name: Foo
|
a_name: Foo
|
||||||
|
name: Foo
|
||||||
_name1: Foo
|
_name1: Foo
|
||||||
input_file: tests/cases/identifiers.nomo
|
|
||||||
---
|
---
|
||||||
VMInstructions {
|
VMInstructions {
|
||||||
labels: {},
|
labels: {},
|
||||||
14
tests/cases/identifiers.4-output.snap
Normal file
14
tests/cases/identifiers.4-output.snap
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
---
|
||||||
|
source: tests/file_tests.rs
|
||||||
|
expression: output
|
||||||
|
info:
|
||||||
|
input: "{{= _name }}\n{{= a_name }}\n{{= name }}\n{{= _name1 }}\n{{= _namE }}\n{{= name1 }}"
|
||||||
|
context:
|
||||||
|
name1: Foo
|
||||||
|
_name: Foo
|
||||||
|
_namE: Foo
|
||||||
|
a_name: Foo
|
||||||
|
name: Foo
|
||||||
|
_name1: Foo
|
||||||
|
---
|
||||||
|
"Foo\nFoo\nFoo\nFoo\nFoo\nFoo"
|
||||||
|
|
@ -1,7 +1,12 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: parsed
|
expression: parsed
|
||||||
input_file: tests/cases/if_else_if.nomo
|
info:
|
||||||
|
input: "{{ if test }}\n Not Hello World! :C\n{{ else if another_test }}\n Hello World!\n{{ end }}"
|
||||||
|
context:
|
||||||
|
test: false
|
||||||
|
stuff: more
|
||||||
|
another_test: true
|
||||||
---
|
---
|
||||||
ParsedTemplate {
|
ParsedTemplate {
|
||||||
tokens: [
|
tokens: [
|
||||||
|
|
@ -1,7 +1,12 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: ast
|
expression: ast
|
||||||
input_file: tests/cases/if_else_if.nomo
|
info:
|
||||||
|
input: "{{ if test }}\n Not Hello World! :C\n{{ else if another_test }}\n Hello World!\n{{ end }}"
|
||||||
|
context:
|
||||||
|
test: false
|
||||||
|
stuff: more
|
||||||
|
another_test: true
|
||||||
---
|
---
|
||||||
TemplateAst {
|
TemplateAst {
|
||||||
root: [
|
root: [
|
||||||
|
|
@ -1,7 +1,12 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: emit
|
expression: emit
|
||||||
input_file: tests/cases/if_else_if.nomo
|
info:
|
||||||
|
input: "{{ if test }}\n Not Hello World! :C\n{{ else if another_test }}\n Hello World!\n{{ end }}"
|
||||||
|
context:
|
||||||
|
test: false
|
||||||
|
stuff: more
|
||||||
|
another_test: true
|
||||||
---
|
---
|
||||||
VMInstructions {
|
VMInstructions {
|
||||||
labels: {
|
labels: {
|
||||||
11
tests/cases/if_else_if.4-output.snap
Normal file
11
tests/cases/if_else_if.4-output.snap
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
---
|
||||||
|
source: tests/file_tests.rs
|
||||||
|
expression: output
|
||||||
|
info:
|
||||||
|
input: "{{ if test }}\n Not Hello World! :C\n{{ else if another_test }}\n Hello World!\n{{ end }}"
|
||||||
|
context:
|
||||||
|
test: false
|
||||||
|
stuff: more
|
||||||
|
another_test: true
|
||||||
|
---
|
||||||
|
"\n Hello World!\n"
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: parsed
|
expression: parsed
|
||||||
input_file: tests/cases/interpolation.nomo
|
info:
|
||||||
|
input: "Hello! I'm {{= name }}"
|
||||||
|
context:
|
||||||
|
name: Hemera
|
||||||
---
|
---
|
||||||
ParsedTemplate {
|
ParsedTemplate {
|
||||||
tokens: [
|
tokens: [
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: ast
|
expression: ast
|
||||||
input_file: tests/cases/interpolation.nomo
|
info:
|
||||||
|
input: "Hello! I'm {{= name }}"
|
||||||
|
context:
|
||||||
|
name: Hemera
|
||||||
---
|
---
|
||||||
TemplateAst {
|
TemplateAst {
|
||||||
root: [
|
root: [
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: emit
|
expression: emit
|
||||||
input_file: tests/cases/interpolation.nomo
|
info:
|
||||||
|
input: "Hello! I'm {{= name }}"
|
||||||
|
context:
|
||||||
|
name: Hemera
|
||||||
---
|
---
|
||||||
VMInstructions {
|
VMInstructions {
|
||||||
labels: {},
|
labels: {},
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: output
|
expression: output
|
||||||
input_file: tests/cases/interpolation.nomo
|
info:
|
||||||
|
input: "Hello! I'm {{= name }}"
|
||||||
|
context:
|
||||||
|
name: Hemera
|
||||||
---
|
---
|
||||||
"Hello! I'm Hemera"
|
"Hello! I'm Hemera"
|
||||||
|
|
@ -4,7 +4,6 @@ expression: parsed
|
||||||
info:
|
info:
|
||||||
input: "{{ if true }}\n Hello World!\n{{ end }}"
|
input: "{{ if true }}\n Hello World!\n{{ end }}"
|
||||||
context: {}
|
context: {}
|
||||||
input_file: tests/cases/literals.nomo
|
|
||||||
---
|
---
|
||||||
ParsedTemplate {
|
ParsedTemplate {
|
||||||
tokens: [
|
tokens: [
|
||||||
|
|
@ -4,7 +4,6 @@ expression: ast
|
||||||
info:
|
info:
|
||||||
input: "{{ if true }}\n Hello World!\n{{ end }}"
|
input: "{{ if true }}\n Hello World!\n{{ end }}"
|
||||||
context: {}
|
context: {}
|
||||||
input_file: tests/cases/literals.nomo
|
|
||||||
---
|
---
|
||||||
TemplateAst {
|
TemplateAst {
|
||||||
root: [
|
root: [
|
||||||
|
|
@ -4,7 +4,6 @@ expression: emit
|
||||||
info:
|
info:
|
||||||
input: "{{ if true }}\n Hello World!\n{{ end }}"
|
input: "{{ if true }}\n Hello World!\n{{ end }}"
|
||||||
context: {}
|
context: {}
|
||||||
input_file: tests/cases/literals.nomo
|
|
||||||
---
|
---
|
||||||
VMInstructions {
|
VMInstructions {
|
||||||
labels: {
|
labels: {
|
||||||
|
|
@ -4,6 +4,5 @@ expression: output
|
||||||
info:
|
info:
|
||||||
input: "{{ if true }}\n Hello World!\n{{ end }}"
|
input: "{{ if true }}\n Hello World!\n{{ end }}"
|
||||||
context: {}
|
context: {}
|
||||||
input_file: tests/cases/literals.nomo
|
|
||||||
---
|
---
|
||||||
"\n Hello World!\n"
|
"\n Hello World!\n"
|
||||||
|
|
@ -4,7 +4,6 @@ expression: parsed
|
||||||
info:
|
info:
|
||||||
input: "{{= 5 * 3 }}\n{{= 2 * 3 + 4 * 3 }}\n{{= 3 / 3 + 3 }}"
|
input: "{{= 5 * 3 }}\n{{= 2 * 3 + 4 * 3 }}\n{{= 3 / 3 + 3 }}"
|
||||||
context: {}
|
context: {}
|
||||||
input_file: tests/cases/maths.nomo
|
|
||||||
---
|
---
|
||||||
ParsedTemplate {
|
ParsedTemplate {
|
||||||
tokens: [
|
tokens: [
|
||||||
|
|
@ -4,7 +4,6 @@ expression: ast
|
||||||
info:
|
info:
|
||||||
input: "{{= 5 * 3 }}\n{{= 2 * 3 + 4 * 3 }}\n{{= 3 / 3 + 3 }}"
|
input: "{{= 5 * 3 }}\n{{= 2 * 3 + 4 * 3 }}\n{{= 3 / 3 + 3 }}"
|
||||||
context: {}
|
context: {}
|
||||||
input_file: tests/cases/maths.nomo
|
|
||||||
---
|
---
|
||||||
TemplateAst {
|
TemplateAst {
|
||||||
root: [
|
root: [
|
||||||
|
|
@ -4,7 +4,6 @@ expression: emit
|
||||||
info:
|
info:
|
||||||
input: "{{= 5 * 3 }}\n{{= 2 * 3 + 4 * 3 }}\n{{= 3 / 3 + 3 }}"
|
input: "{{= 5 * 3 }}\n{{= 2 * 3 + 4 * 3 }}\n{{= 3 / 3 + 3 }}"
|
||||||
context: {}
|
context: {}
|
||||||
input_file: tests/cases/maths.nomo
|
|
||||||
---
|
---
|
||||||
VMInstructions {
|
VMInstructions {
|
||||||
labels: {},
|
labels: {},
|
||||||
|
|
@ -4,6 +4,5 @@ expression: output
|
||||||
info:
|
info:
|
||||||
input: "{{= 5 * 3 }}\n{{= 2 * 3 + 4 * 3 }}\n{{= 3 / 3 + 3 }}"
|
input: "{{= 5 * 3 }}\n{{= 2 * 3 + 4 * 3 }}\n{{= 3 / 3 + 3 }}"
|
||||||
context: {}
|
context: {}
|
||||||
input_file: tests/cases/maths.nomo
|
|
||||||
---
|
---
|
||||||
"15\n18\n4"
|
"15\n18\n4"
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: parsed
|
expression: parsed
|
||||||
input_file: tests/cases/multiple.nomo
|
info:
|
||||||
|
input: "Hi there! My name is {{= name }} {{= lastname }}"
|
||||||
|
context:
|
||||||
|
name: Hemera
|
||||||
|
lastname: Green
|
||||||
---
|
---
|
||||||
ParsedTemplate {
|
ParsedTemplate {
|
||||||
tokens: [
|
tokens: [
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: ast
|
expression: ast
|
||||||
input_file: tests/cases/multiple.nomo
|
info:
|
||||||
|
input: "Hi there! My name is {{= name }} {{= lastname }}"
|
||||||
|
context:
|
||||||
|
name: Hemera
|
||||||
|
lastname: Green
|
||||||
---
|
---
|
||||||
TemplateAst {
|
TemplateAst {
|
||||||
root: [
|
root: [
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: emit
|
expression: emit
|
||||||
input_file: tests/cases/multiple.nomo
|
info:
|
||||||
|
input: "Hi there! My name is {{= name }} {{= lastname }}"
|
||||||
|
context:
|
||||||
|
name: Hemera
|
||||||
|
lastname: Green
|
||||||
---
|
---
|
||||||
VMInstructions {
|
VMInstructions {
|
||||||
labels: {},
|
labels: {},
|
||||||
10
tests/cases/multiple.4-output.snap
Normal file
10
tests/cases/multiple.4-output.snap
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
source: tests/file_tests.rs
|
||||||
|
expression: output
|
||||||
|
info:
|
||||||
|
input: "Hi there! My name is {{= name }} {{= lastname }}"
|
||||||
|
context:
|
||||||
|
name: Hemera
|
||||||
|
lastname: Green
|
||||||
|
---
|
||||||
|
"Hi there! My name is Hemera Green"
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: parsed
|
expression: parsed
|
||||||
input_file: tests/cases/simple.nomo
|
info:
|
||||||
|
input: Hello World!
|
||||||
|
context: {}
|
||||||
---
|
---
|
||||||
ParsedTemplate {
|
ParsedTemplate {
|
||||||
tokens: [
|
tokens: [
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: ast
|
expression: ast
|
||||||
input_file: tests/cases/simple.nomo
|
info:
|
||||||
|
input: Hello World!
|
||||||
|
context: {}
|
||||||
---
|
---
|
||||||
TemplateAst {
|
TemplateAst {
|
||||||
root: [
|
root: [
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: emit
|
expression: emit
|
||||||
input_file: tests/cases/simple.nomo
|
info:
|
||||||
|
input: Hello World!
|
||||||
|
context: {}
|
||||||
---
|
---
|
||||||
VMInstructions {
|
VMInstructions {
|
||||||
labels: {},
|
labels: {},
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: output
|
expression: output
|
||||||
input_file: tests/cases/simple.nomo
|
info:
|
||||||
|
input: Hello World!
|
||||||
|
context: {}
|
||||||
---
|
---
|
||||||
"Hello World!"
|
"Hello World!"
|
||||||
|
|
@ -8,7 +8,6 @@ info:
|
||||||
values:
|
values:
|
||||||
- one
|
- one
|
||||||
- two
|
- two
|
||||||
input_file: tests/cases/simple_for.nomo
|
|
||||||
---
|
---
|
||||||
ParsedTemplate {
|
ParsedTemplate {
|
||||||
tokens: [
|
tokens: [
|
||||||
|
|
@ -8,7 +8,6 @@ info:
|
||||||
values:
|
values:
|
||||||
- one
|
- one
|
||||||
- two
|
- two
|
||||||
input_file: tests/cases/simple_for.nomo
|
|
||||||
---
|
---
|
||||||
TemplateAst {
|
TemplateAst {
|
||||||
root: [
|
root: [
|
||||||
|
|
@ -8,7 +8,6 @@ info:
|
||||||
values:
|
values:
|
||||||
- one
|
- one
|
||||||
- two
|
- two
|
||||||
input_file: tests/cases/simple_for.nomo
|
|
||||||
---
|
---
|
||||||
VMInstructions {
|
VMInstructions {
|
||||||
labels: {
|
labels: {
|
||||||
|
|
@ -8,6 +8,5 @@ info:
|
||||||
values:
|
values:
|
||||||
- one
|
- one
|
||||||
- two
|
- two
|
||||||
input_file: tests/cases/simple_for.nomo
|
|
||||||
---
|
---
|
||||||
"one\ntwo\n\nNo Values >:C"
|
"one\ntwo\n\nNo Values >:C"
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: parsed
|
expression: parsed
|
||||||
input_file: tests/cases/trim_whitespace.nomo
|
info:
|
||||||
|
input: "{{ if test -}}\n Hello {{= stuff -}}\n{{- end }}"
|
||||||
|
context:
|
||||||
|
stuff: Hemera
|
||||||
|
test: true
|
||||||
---
|
---
|
||||||
ParsedTemplate {
|
ParsedTemplate {
|
||||||
tokens: [
|
tokens: [
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: ast
|
expression: ast
|
||||||
input_file: tests/cases/trim_whitespace.nomo
|
info:
|
||||||
|
input: "{{ if test -}}\n Hello {{= stuff -}}\n{{- end }}"
|
||||||
|
context:
|
||||||
|
stuff: Hemera
|
||||||
|
test: true
|
||||||
---
|
---
|
||||||
TemplateAst {
|
TemplateAst {
|
||||||
root: [
|
root: [
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
---
|
---
|
||||||
source: tests/file_tests.rs
|
source: tests/file_tests.rs
|
||||||
expression: emit
|
expression: emit
|
||||||
input_file: tests/cases/trim_whitespace.nomo
|
info:
|
||||||
|
input: "{{ if test -}}\n Hello {{= stuff -}}\n{{- end }}"
|
||||||
|
context:
|
||||||
|
stuff: Hemera
|
||||||
|
test: true
|
||||||
---
|
---
|
||||||
VMInstructions {
|
VMInstructions {
|
||||||
labels: {
|
labels: {
|
||||||
10
tests/cases/trim_whitespace.4-output.snap
Normal file
10
tests/cases/trim_whitespace.4-output.snap
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
source: tests/file_tests.rs
|
||||||
|
expression: output
|
||||||
|
info:
|
||||||
|
input: "{{ if test -}}\n Hello {{= stuff -}}\n{{- end }}"
|
||||||
|
context:
|
||||||
|
stuff: Hemera
|
||||||
|
test: true
|
||||||
|
---
|
||||||
|
"Hello Hemera"
|
||||||
|
|
@ -1,21 +1,22 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
use nomo::Context;
|
use nomo::Context;
|
||||||
|
|
||||||
|
test_each_file::test_each_path! { for ["nomo"] in "./tests/cases/" as cases => check_for_input }
|
||||||
|
|
||||||
#[derive(serde::Serialize)]
|
#[derive(serde::Serialize)]
|
||||||
struct Info {
|
struct Info {
|
||||||
input: String,
|
input: String,
|
||||||
context: HashMap<String, serde_json::Value>,
|
context: HashMap<String, serde_json::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
fn check_for_input([path]: [&Path; 1]) {
|
||||||
fn check_cases() {
|
|
||||||
insta::glob!("cases/*.nomo", |path| {
|
|
||||||
let mut settings = insta::Settings::clone_current();
|
let mut settings = insta::Settings::clone_current();
|
||||||
settings.set_snapshot_path("cases");
|
settings.set_snapshot_path("cases");
|
||||||
settings.set_snapshot_suffix(path.file_stem().unwrap().display().to_string());
|
|
||||||
settings.set_prepend_module_to_snapshot(false);
|
settings.set_prepend_module_to_snapshot(false);
|
||||||
|
|
||||||
|
let basename = path.file_stem().unwrap().to_string_lossy();
|
||||||
let input = std::fs::read_to_string(path).unwrap();
|
let input = std::fs::read_to_string(path).unwrap();
|
||||||
|
|
||||||
let (context, input) = input.split_once("\n---\n").unwrap_or_else(|| ("", &input));
|
let (context, input) = input.split_once("\n---\n").unwrap_or_else(|| ("", &input));
|
||||||
|
|
@ -41,7 +42,7 @@ fn check_cases() {
|
||||||
|
|
||||||
let _guard = settings.bind_to_scope();
|
let _guard = settings.bind_to_scope();
|
||||||
|
|
||||||
insta::assert_debug_snapshot!("1-parsed", parsed);
|
insta::assert_debug_snapshot!(format!("{basename}.1-parsed"), parsed);
|
||||||
|
|
||||||
let ast = match nomo::ast::parse(parsed.tokens()) {
|
let ast = match nomo::ast::parse(parsed.tokens()) {
|
||||||
Ok(ast) => ast,
|
Ok(ast) => ast,
|
||||||
|
|
@ -51,14 +52,13 @@ fn check_cases() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
insta::assert_debug_snapshot!("2-ast", ast);
|
insta::assert_debug_snapshot!(format!("{basename}.2-ast"), ast);
|
||||||
|
|
||||||
let emit = nomo::emit::emit_machine(ast);
|
let emit = nomo::emit::emit_machine(ast);
|
||||||
|
|
||||||
insta::assert_debug_snapshot!("3-instructions", emit);
|
insta::assert_debug_snapshot!(format!("{basename}.3-instructions"), emit);
|
||||||
|
|
||||||
let output = nomo::eval::execute(&emit, &context).unwrap();
|
let output = nomo::eval::execute(&emit, &context).unwrap();
|
||||||
|
|
||||||
insta::assert_debug_snapshot!("4-output", output);
|
insta::assert_debug_snapshot!(format!("{basename}.4-output"), output);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue