Compare commits
No commits in common. "d41cd5784705453cba820ac0875f6704b16d956d" and "605798674f82020263a317f60965d8b963082804" have entirely different histories.
d41cd57847
...
605798674f
50 changed files with 267 additions and 268 deletions
13
Cargo.lock
generated
13
Cargo.lock
generated
|
|
@ -442,7 +442,6 @@ dependencies = [
|
|||
"insta",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"test_each_file",
|
||||
"thiserror",
|
||||
"winnow",
|
||||
]
|
||||
|
|
@ -702,18 +701,6 @@ dependencies = [
|
|||
"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]]
|
||||
name = "thiserror"
|
||||
version = "2.0.18"
|
||||
|
|
|
|||
|
|
@ -7,10 +7,6 @@ edition = "2024"
|
|||
name = "parsing"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "asting"
|
||||
harness = false
|
||||
|
||||
[profile.bench]
|
||||
debug = true
|
||||
|
||||
|
|
@ -27,7 +23,6 @@ criterion = "0.8.2"
|
|||
insta = { version = "1.46.3", features = ["glob", "serde"] }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde_json = "1.0.149"
|
||||
test_each_file = "0.3.7"
|
||||
|
||||
[profile.dev.package]
|
||||
insta.opt-level = 3
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
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);
|
||||
152
src/ast/snapshots/nomo__ast__tests__check_nested_simple_if.snap
Normal file
152
src/ast/snapshots/nomo__ast__tests__check_nested_simple_if.snap
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
---
|
||||
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,11 +1,7 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: parsed
|
||||
info:
|
||||
input: "{{ if test }}\n Hello World!\n{{ end }}\n\n{{= stuff }}"
|
||||
context:
|
||||
stuff: more
|
||||
test: true
|
||||
input_file: tests/cases/condition.nomo
|
||||
---
|
||||
ParsedTemplate {
|
||||
tokens: [
|
||||
|
|
@ -4,12 +4,13 @@ expression: parsed
|
|||
info:
|
||||
input: "{{= _name }}\n{{= a_name }}\n{{= name }}\n{{= _name1 }}\n{{= _namE }}\n{{= name1 }}"
|
||||
context:
|
||||
name1: Foo
|
||||
_name: Foo
|
||||
_namE: Foo
|
||||
a_name: Foo
|
||||
name1: Foo
|
||||
name: Foo
|
||||
_name: Foo
|
||||
a_name: Foo
|
||||
_name1: Foo
|
||||
input_file: tests/cases/identifiers.nomo
|
||||
---
|
||||
ParsedTemplate {
|
||||
tokens: [
|
||||
|
|
@ -1,12 +1,7 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: parsed
|
||||
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
|
||||
input_file: tests/cases/if_else_if.nomo
|
||||
---
|
||||
ParsedTemplate {
|
||||
tokens: [
|
||||
|
|
@ -1,10 +1,7 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: parsed
|
||||
info:
|
||||
input: "Hello! I'm {{= name }}"
|
||||
context:
|
||||
name: Hemera
|
||||
input_file: tests/cases/interpolation.nomo
|
||||
---
|
||||
ParsedTemplate {
|
||||
tokens: [
|
||||
|
|
@ -4,6 +4,7 @@ expression: parsed
|
|||
info:
|
||||
input: "{{ if true }}\n Hello World!\n{{ end }}"
|
||||
context: {}
|
||||
input_file: tests/cases/literals.nomo
|
||||
---
|
||||
ParsedTemplate {
|
||||
tokens: [
|
||||
|
|
@ -4,6 +4,7 @@ expression: parsed
|
|||
info:
|
||||
input: "{{= 5 * 3 }}\n{{= 2 * 3 + 4 * 3 }}\n{{= 3 / 3 + 3 }}"
|
||||
context: {}
|
||||
input_file: tests/cases/maths.nomo
|
||||
---
|
||||
ParsedTemplate {
|
||||
tokens: [
|
||||
|
|
@ -1,11 +1,7 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: parsed
|
||||
info:
|
||||
input: "Hi there! My name is {{= name }} {{= lastname }}"
|
||||
context:
|
||||
name: Hemera
|
||||
lastname: Green
|
||||
input_file: tests/cases/multiple.nomo
|
||||
---
|
||||
ParsedTemplate {
|
||||
tokens: [
|
||||
|
|
@ -1,9 +1,7 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: parsed
|
||||
info:
|
||||
input: Hello World!
|
||||
context: {}
|
||||
input_file: tests/cases/simple.nomo
|
||||
---
|
||||
ParsedTemplate {
|
||||
tokens: [
|
||||
|
|
@ -8,6 +8,7 @@ info:
|
|||
values:
|
||||
- one
|
||||
- two
|
||||
input_file: tests/cases/simple_for.nomo
|
||||
---
|
||||
ParsedTemplate {
|
||||
tokens: [
|
||||
|
|
@ -1,11 +1,7 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: parsed
|
||||
info:
|
||||
input: "{{ if test -}}\n Hello {{= stuff -}}\n{{- end }}"
|
||||
context:
|
||||
stuff: Hemera
|
||||
test: true
|
||||
input_file: tests/cases/trim_whitespace.nomo
|
||||
---
|
||||
ParsedTemplate {
|
||||
tokens: [
|
||||
|
|
@ -1,11 +1,7 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: ast
|
||||
info:
|
||||
input: "{{ if test }}\n Hello World!\n{{ end }}\n\n{{= stuff }}"
|
||||
context:
|
||||
stuff: more
|
||||
test: true
|
||||
input_file: tests/cases/condition.nomo
|
||||
---
|
||||
TemplateAst {
|
||||
root: [
|
||||
|
|
@ -4,12 +4,13 @@ expression: ast
|
|||
info:
|
||||
input: "{{= _name }}\n{{= a_name }}\n{{= name }}\n{{= _name1 }}\n{{= _namE }}\n{{= name1 }}"
|
||||
context:
|
||||
name1: Foo
|
||||
_name: Foo
|
||||
_namE: Foo
|
||||
a_name: Foo
|
||||
name1: Foo
|
||||
name: Foo
|
||||
_name: Foo
|
||||
a_name: Foo
|
||||
_name1: Foo
|
||||
input_file: tests/cases/identifiers.nomo
|
||||
---
|
||||
TemplateAst {
|
||||
root: [
|
||||
|
|
@ -1,12 +1,7 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: ast
|
||||
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
|
||||
input_file: tests/cases/if_else_if.nomo
|
||||
---
|
||||
TemplateAst {
|
||||
root: [
|
||||
|
|
@ -1,10 +1,7 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: ast
|
||||
info:
|
||||
input: "Hello! I'm {{= name }}"
|
||||
context:
|
||||
name: Hemera
|
||||
input_file: tests/cases/interpolation.nomo
|
||||
---
|
||||
TemplateAst {
|
||||
root: [
|
||||
|
|
@ -4,6 +4,7 @@ expression: ast
|
|||
info:
|
||||
input: "{{ if true }}\n Hello World!\n{{ end }}"
|
||||
context: {}
|
||||
input_file: tests/cases/literals.nomo
|
||||
---
|
||||
TemplateAst {
|
||||
root: [
|
||||
|
|
@ -4,6 +4,7 @@ expression: ast
|
|||
info:
|
||||
input: "{{= 5 * 3 }}\n{{= 2 * 3 + 4 * 3 }}\n{{= 3 / 3 + 3 }}"
|
||||
context: {}
|
||||
input_file: tests/cases/maths.nomo
|
||||
---
|
||||
TemplateAst {
|
||||
root: [
|
||||
|
|
@ -1,11 +1,7 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: ast
|
||||
info:
|
||||
input: "Hi there! My name is {{= name }} {{= lastname }}"
|
||||
context:
|
||||
name: Hemera
|
||||
lastname: Green
|
||||
input_file: tests/cases/multiple.nomo
|
||||
---
|
||||
TemplateAst {
|
||||
root: [
|
||||
|
|
@ -1,9 +1,7 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: ast
|
||||
info:
|
||||
input: Hello World!
|
||||
context: {}
|
||||
input_file: tests/cases/simple.nomo
|
||||
---
|
||||
TemplateAst {
|
||||
root: [
|
||||
|
|
@ -8,6 +8,7 @@ info:
|
|||
values:
|
||||
- one
|
||||
- two
|
||||
input_file: tests/cases/simple_for.nomo
|
||||
---
|
||||
TemplateAst {
|
||||
root: [
|
||||
|
|
@ -1,11 +1,7 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: ast
|
||||
info:
|
||||
input: "{{ if test -}}\n Hello {{= stuff -}}\n{{- end }}"
|
||||
context:
|
||||
stuff: Hemera
|
||||
test: true
|
||||
input_file: tests/cases/trim_whitespace.nomo
|
||||
---
|
||||
TemplateAst {
|
||||
root: [
|
||||
|
|
@ -1,11 +1,7 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: emit
|
||||
info:
|
||||
input: "{{ if test }}\n Hello World!\n{{ end }}\n\n{{= stuff }}"
|
||||
context:
|
||||
stuff: more
|
||||
test: true
|
||||
input_file: tests/cases/condition.nomo
|
||||
---
|
||||
VMInstructions {
|
||||
labels: {
|
||||
|
|
@ -4,12 +4,13 @@ expression: emit
|
|||
info:
|
||||
input: "{{= _name }}\n{{= a_name }}\n{{= name }}\n{{= _name1 }}\n{{= _namE }}\n{{= name1 }}"
|
||||
context:
|
||||
name1: Foo
|
||||
_name: Foo
|
||||
_namE: Foo
|
||||
a_name: Foo
|
||||
name1: Foo
|
||||
name: Foo
|
||||
_name: Foo
|
||||
a_name: Foo
|
||||
_name1: Foo
|
||||
input_file: tests/cases/identifiers.nomo
|
||||
---
|
||||
VMInstructions {
|
||||
labels: {},
|
||||
|
|
@ -1,12 +1,7 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: emit
|
||||
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
|
||||
input_file: tests/cases/if_else_if.nomo
|
||||
---
|
||||
VMInstructions {
|
||||
labels: {
|
||||
|
|
@ -1,10 +1,7 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: emit
|
||||
info:
|
||||
input: "Hello! I'm {{= name }}"
|
||||
context:
|
||||
name: Hemera
|
||||
input_file: tests/cases/interpolation.nomo
|
||||
---
|
||||
VMInstructions {
|
||||
labels: {},
|
||||
|
|
@ -4,6 +4,7 @@ expression: emit
|
|||
info:
|
||||
input: "{{ if true }}\n Hello World!\n{{ end }}"
|
||||
context: {}
|
||||
input_file: tests/cases/literals.nomo
|
||||
---
|
||||
VMInstructions {
|
||||
labels: {
|
||||
|
|
@ -4,6 +4,7 @@ expression: emit
|
|||
info:
|
||||
input: "{{= 5 * 3 }}\n{{= 2 * 3 + 4 * 3 }}\n{{= 3 / 3 + 3 }}"
|
||||
context: {}
|
||||
input_file: tests/cases/maths.nomo
|
||||
---
|
||||
VMInstructions {
|
||||
labels: {},
|
||||
|
|
@ -1,11 +1,7 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: emit
|
||||
info:
|
||||
input: "Hi there! My name is {{= name }} {{= lastname }}"
|
||||
context:
|
||||
name: Hemera
|
||||
lastname: Green
|
||||
input_file: tests/cases/multiple.nomo
|
||||
---
|
||||
VMInstructions {
|
||||
labels: {},
|
||||
|
|
@ -1,9 +1,7 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: emit
|
||||
info:
|
||||
input: Hello World!
|
||||
context: {}
|
||||
input_file: tests/cases/simple.nomo
|
||||
---
|
||||
VMInstructions {
|
||||
labels: {},
|
||||
|
|
@ -8,6 +8,7 @@ info:
|
|||
values:
|
||||
- one
|
||||
- two
|
||||
input_file: tests/cases/simple_for.nomo
|
||||
---
|
||||
VMInstructions {
|
||||
labels: {
|
||||
|
|
@ -1,11 +1,7 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: emit
|
||||
info:
|
||||
input: "{{ if test -}}\n Hello {{= stuff -}}\n{{- end }}"
|
||||
context:
|
||||
stuff: Hemera
|
||||
test: true
|
||||
input_file: tests/cases/trim_whitespace.nomo
|
||||
---
|
||||
VMInstructions {
|
||||
labels: {
|
||||
6
tests/cases/4-output@condition.snap
Normal file
6
tests/cases/4-output@condition.snap
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: output
|
||||
input_file: tests/cases/condition.nomo
|
||||
---
|
||||
"\n Hello World!\n\n\nmore"
|
||||
6
tests/cases/4-output@identifiers.snap
Normal file
6
tests/cases/4-output@identifiers.snap
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: output
|
||||
input_file: tests/cases/identifiers.nomo
|
||||
---
|
||||
"Foo\nFoo\nFoo\nFoo\nFoo\nFoo"
|
||||
6
tests/cases/4-output@if_else_if.snap
Normal file
6
tests/cases/4-output@if_else_if.snap
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: output
|
||||
input_file: tests/cases/if_else_if.nomo
|
||||
---
|
||||
"\n Hello World!\n"
|
||||
|
|
@ -1,9 +1,6 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: output
|
||||
info:
|
||||
input: "Hello! I'm {{= name }}"
|
||||
context:
|
||||
name: Hemera
|
||||
input_file: tests/cases/interpolation.nomo
|
||||
---
|
||||
"Hello! I'm Hemera"
|
||||
|
|
@ -4,5 +4,6 @@ expression: output
|
|||
info:
|
||||
input: "{{ if true }}\n Hello World!\n{{ end }}"
|
||||
context: {}
|
||||
input_file: tests/cases/literals.nomo
|
||||
---
|
||||
"\n Hello World!\n"
|
||||
|
|
@ -4,5 +4,6 @@ expression: output
|
|||
info:
|
||||
input: "{{= 5 * 3 }}\n{{= 2 * 3 + 4 * 3 }}\n{{= 3 / 3 + 3 }}"
|
||||
context: {}
|
||||
input_file: tests/cases/maths.nomo
|
||||
---
|
||||
"15\n18\n4"
|
||||
6
tests/cases/4-output@multiple.snap
Normal file
6
tests/cases/4-output@multiple.snap
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: output
|
||||
input_file: tests/cases/multiple.nomo
|
||||
---
|
||||
"Hi there! My name is Hemera Green"
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: output
|
||||
info:
|
||||
input: Hello World!
|
||||
context: {}
|
||||
input_file: tests/cases/simple.nomo
|
||||
---
|
||||
"Hello World!"
|
||||
|
|
@ -8,5 +8,6 @@ info:
|
|||
values:
|
||||
- one
|
||||
- two
|
||||
input_file: tests/cases/simple_for.nomo
|
||||
---
|
||||
"one\ntwo\n\nNo Values >:C"
|
||||
6
tests/cases/4-output@trim_whitespace.snap
Normal file
6
tests/cases/4-output@trim_whitespace.snap
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: output
|
||||
input_file: tests/cases/trim_whitespace.nomo
|
||||
---
|
||||
"Hello Hemera"
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
---
|
||||
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"
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
---
|
||||
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,11 +0,0 @@
|
|||
---
|
||||
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,10 +0,0 @@
|
|||
---
|
||||
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,10 +0,0 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: output
|
||||
info:
|
||||
input: "{{ if test -}}\n Hello {{= stuff -}}\n{{- end }}"
|
||||
context:
|
||||
stuff: Hemera
|
||||
test: true
|
||||
---
|
||||
"Hello Hemera"
|
||||
|
|
@ -1,22 +1,21 @@
|
|||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
|
||||
use nomo::Context;
|
||||
|
||||
test_each_file::test_each_path! { for ["nomo"] in "./tests/cases/" as cases => check_for_input }
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
struct Info {
|
||||
input: String,
|
||||
context: HashMap<String, serde_json::Value>,
|
||||
}
|
||||
|
||||
fn check_for_input([path]: [&Path; 1]) {
|
||||
#[test]
|
||||
fn check_cases() {
|
||||
insta::glob!("cases/*.nomo", |path| {
|
||||
let mut settings = insta::Settings::clone_current();
|
||||
settings.set_snapshot_path("cases");
|
||||
settings.set_snapshot_suffix(path.file_stem().unwrap().display().to_string());
|
||||
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 (context, input) = input.split_once("\n---\n").unwrap_or_else(|| ("", &input));
|
||||
|
|
@ -42,7 +41,7 @@ fn check_for_input([path]: [&Path; 1]) {
|
|||
|
||||
let _guard = settings.bind_to_scope();
|
||||
|
||||
insta::assert_debug_snapshot!(format!("{basename}.1-parsed"), parsed);
|
||||
insta::assert_debug_snapshot!("1-parsed", parsed);
|
||||
|
||||
let ast = match nomo::ast::parse(parsed.tokens()) {
|
||||
Ok(ast) => ast,
|
||||
|
|
@ -52,13 +51,14 @@ fn check_for_input([path]: [&Path; 1]) {
|
|||
}
|
||||
};
|
||||
|
||||
insta::assert_debug_snapshot!(format!("{basename}.2-ast"), ast);
|
||||
insta::assert_debug_snapshot!("2-ast", ast);
|
||||
|
||||
let emit = nomo::emit::emit_machine(ast);
|
||||
|
||||
insta::assert_debug_snapshot!(format!("{basename}.3-instructions"), emit);
|
||||
insta::assert_debug_snapshot!("3-instructions", emit);
|
||||
|
||||
let output = nomo::eval::execute(&emit, &context).unwrap();
|
||||
|
||||
insta::assert_debug_snapshot!(format!("{basename}.4-output"), output);
|
||||
insta::assert_debug_snapshot!("4-output", output);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue