diff --git a/Cargo.lock b/Cargo.lock index 6a3e2bc..729eb06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index fe1e716..8e383d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/benches/asting.rs b/benches/asting.rs deleted file mode 100644 index 1528069..0000000 --- a/benches/asting.rs +++ /dev/null @@ -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); diff --git a/src/ast/snapshots/nomo__ast__tests__check_nested_simple_if.snap b/src/ast/snapshots/nomo__ast__tests__check_nested_simple_if.snap new file mode 100644 index 0000000..27bbdad --- /dev/null +++ b/src/ast/snapshots/nomo__ast__tests__check_nested_simple_if.snap @@ -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), + }, + ], +} diff --git a/tests/cases/condition.1-parsed.snap b/tests/cases/1-parsed@condition.snap similarity index 87% rename from tests/cases/condition.1-parsed.snap rename to tests/cases/1-parsed@condition.snap index e2ec981..9a4d638 100644 --- a/tests/cases/condition.1-parsed.snap +++ b/tests/cases/1-parsed@condition.snap @@ -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: [ diff --git a/tests/cases/identifiers.1-parsed.snap b/tests/cases/1-parsed@identifiers.snap similarity index 97% rename from tests/cases/identifiers.1-parsed.snap rename to tests/cases/1-parsed@identifiers.snap index acc7ff8..31760f1 100644 --- a/tests/cases/identifiers.1-parsed.snap +++ b/tests/cases/1-parsed@identifiers.snap @@ -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: [ diff --git a/tests/cases/if_else_if.1-parsed.snap b/tests/cases/1-parsed@if_else_if.snap similarity index 85% rename from tests/cases/if_else_if.1-parsed.snap rename to tests/cases/1-parsed@if_else_if.snap index 06161fa..287fce6 100644 --- a/tests/cases/if_else_if.1-parsed.snap +++ b/tests/cases/1-parsed@if_else_if.snap @@ -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: [ diff --git a/tests/cases/interpolation.1-parsed.snap b/tests/cases/1-parsed@interpolation.snap similarity index 84% rename from tests/cases/interpolation.1-parsed.snap rename to tests/cases/1-parsed@interpolation.snap index 44d635a..662117b 100644 --- a/tests/cases/interpolation.1-parsed.snap +++ b/tests/cases/1-parsed@interpolation.snap @@ -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: [ diff --git a/tests/cases/literals.1-parsed.snap b/tests/cases/1-parsed@literals.snap similarity index 94% rename from tests/cases/literals.1-parsed.snap rename to tests/cases/1-parsed@literals.snap index 0a528a6..bc0d851 100644 --- a/tests/cases/literals.1-parsed.snap +++ b/tests/cases/1-parsed@literals.snap @@ -4,6 +4,7 @@ expression: parsed info: input: "{{ if true }}\n Hello World!\n{{ end }}" context: {} +input_file: tests/cases/literals.nomo --- ParsedTemplate { tokens: [ diff --git a/tests/cases/maths.1-parsed.snap b/tests/cases/1-parsed@maths.snap similarity index 98% rename from tests/cases/maths.1-parsed.snap rename to tests/cases/1-parsed@maths.snap index d779936..837a801 100644 --- a/tests/cases/maths.1-parsed.snap +++ b/tests/cases/1-parsed@maths.snap @@ -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: [ diff --git a/tests/cases/multiple.1-parsed.snap b/tests/cases/1-parsed@multiple.snap similarity index 84% rename from tests/cases/multiple.1-parsed.snap rename to tests/cases/1-parsed@multiple.snap index d04d1a3..89c0a2a 100644 --- a/tests/cases/multiple.1-parsed.snap +++ b/tests/cases/1-parsed@multiple.snap @@ -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: [ diff --git a/tests/cases/simple.1-parsed.snap b/tests/cases/1-parsed@simple.snap similarity index 76% rename from tests/cases/simple.1-parsed.snap rename to tests/cases/1-parsed@simple.snap index 6a95bef..1bb543e 100644 --- a/tests/cases/simple.1-parsed.snap +++ b/tests/cases/1-parsed@simple.snap @@ -1,9 +1,7 @@ --- source: tests/file_tests.rs expression: parsed -info: - input: Hello World! - context: {} +input_file: tests/cases/simple.nomo --- ParsedTemplate { tokens: [ diff --git a/tests/cases/simple_for.1-parsed.snap b/tests/cases/1-parsed@simple_for.snap similarity index 98% rename from tests/cases/simple_for.1-parsed.snap rename to tests/cases/1-parsed@simple_for.snap index a4b269f..4e391b7 100644 --- a/tests/cases/simple_for.1-parsed.snap +++ b/tests/cases/1-parsed@simple_for.snap @@ -8,6 +8,7 @@ info: values: - one - two +input_file: tests/cases/simple_for.nomo --- ParsedTemplate { tokens: [ diff --git a/tests/cases/trim_whitespace.1-parsed.snap b/tests/cases/1-parsed@trim_whitespace.snap similarity index 89% rename from tests/cases/trim_whitespace.1-parsed.snap rename to tests/cases/1-parsed@trim_whitespace.snap index f8f1912..b95d570 100644 --- a/tests/cases/trim_whitespace.1-parsed.snap +++ b/tests/cases/1-parsed@trim_whitespace.snap @@ -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: [ diff --git a/tests/cases/condition.2-ast.snap b/tests/cases/2-ast@condition.snap similarity index 92% rename from tests/cases/condition.2-ast.snap rename to tests/cases/2-ast@condition.snap index 40e042f..ae3a62e 100644 --- a/tests/cases/condition.2-ast.snap +++ b/tests/cases/2-ast@condition.snap @@ -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: [ diff --git a/tests/cases/identifiers.2-ast.snap b/tests/cases/2-ast@identifiers.snap similarity index 97% rename from tests/cases/identifiers.2-ast.snap rename to tests/cases/2-ast@identifiers.snap index 932b2f6..4333d9d 100644 --- a/tests/cases/identifiers.2-ast.snap +++ b/tests/cases/2-ast@identifiers.snap @@ -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: [ diff --git a/tests/cases/if_else_if.2-ast.snap b/tests/cases/2-ast@if_else_if.snap similarity index 91% rename from tests/cases/if_else_if.2-ast.snap rename to tests/cases/2-ast@if_else_if.snap index eba26c3..3bc850b 100644 --- a/tests/cases/if_else_if.2-ast.snap +++ b/tests/cases/2-ast@if_else_if.snap @@ -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: [ diff --git a/tests/cases/interpolation.2-ast.snap b/tests/cases/2-ast@interpolation.snap similarity index 86% rename from tests/cases/interpolation.2-ast.snap rename to tests/cases/2-ast@interpolation.snap index 377f6f3..272123a 100644 --- a/tests/cases/interpolation.2-ast.snap +++ b/tests/cases/2-ast@interpolation.snap @@ -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: [ diff --git a/tests/cases/literals.2-ast.snap b/tests/cases/2-ast@literals.snap similarity index 97% rename from tests/cases/literals.2-ast.snap rename to tests/cases/2-ast@literals.snap index 74b53ba..85453dc 100644 --- a/tests/cases/literals.2-ast.snap +++ b/tests/cases/2-ast@literals.snap @@ -4,6 +4,7 @@ expression: ast info: input: "{{ if true }}\n Hello World!\n{{ end }}" context: {} +input_file: tests/cases/literals.nomo --- TemplateAst { root: [ diff --git a/tests/cases/maths.2-ast.snap b/tests/cases/2-ast@maths.snap similarity index 98% rename from tests/cases/maths.2-ast.snap rename to tests/cases/2-ast@maths.snap index 45be132..6aa9130 100644 --- a/tests/cases/maths.2-ast.snap +++ b/tests/cases/2-ast@maths.snap @@ -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: [ diff --git a/tests/cases/multiple.2-ast.snap b/tests/cases/2-ast@multiple.snap similarity index 86% rename from tests/cases/multiple.2-ast.snap rename to tests/cases/2-ast@multiple.snap index 9adbc67..3f8b6ea 100644 --- a/tests/cases/multiple.2-ast.snap +++ b/tests/cases/2-ast@multiple.snap @@ -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: [ diff --git a/tests/cases/simple.2-ast.snap b/tests/cases/2-ast@simple.snap similarity index 79% rename from tests/cases/simple.2-ast.snap rename to tests/cases/2-ast@simple.snap index edc75fe..48a5a9c 100644 --- a/tests/cases/simple.2-ast.snap +++ b/tests/cases/2-ast@simple.snap @@ -1,9 +1,7 @@ --- source: tests/file_tests.rs expression: ast -info: - input: Hello World! - context: {} +input_file: tests/cases/simple.nomo --- TemplateAst { root: [ diff --git a/tests/cases/simple_for.2-ast.snap b/tests/cases/2-ast@simple_for.snap similarity index 98% rename from tests/cases/simple_for.2-ast.snap rename to tests/cases/2-ast@simple_for.snap index 3a9c2d8..5071ece 100644 --- a/tests/cases/simple_for.2-ast.snap +++ b/tests/cases/2-ast@simple_for.snap @@ -8,6 +8,7 @@ info: values: - one - two +input_file: tests/cases/simple_for.nomo --- TemplateAst { root: [ diff --git a/tests/cases/trim_whitespace.2-ast.snap b/tests/cases/2-ast@trim_whitespace.snap similarity index 92% rename from tests/cases/trim_whitespace.2-ast.snap rename to tests/cases/2-ast@trim_whitespace.snap index bcd0a35..0e20a97 100644 --- a/tests/cases/trim_whitespace.2-ast.snap +++ b/tests/cases/2-ast@trim_whitespace.snap @@ -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: [ diff --git a/tests/cases/condition.3-instructions.snap b/tests/cases/3-instructions@condition.snap similarity index 91% rename from tests/cases/condition.3-instructions.snap rename to tests/cases/3-instructions@condition.snap index a317547..5f79488 100644 --- a/tests/cases/condition.3-instructions.snap +++ b/tests/cases/3-instructions@condition.snap @@ -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: { diff --git a/tests/cases/identifiers.3-instructions.snap b/tests/cases/3-instructions@identifiers.snap similarity index 98% rename from tests/cases/identifiers.3-instructions.snap rename to tests/cases/3-instructions@identifiers.snap index f3d8ddc..9556d23 100644 --- a/tests/cases/identifiers.3-instructions.snap +++ b/tests/cases/3-instructions@identifiers.snap @@ -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: {}, diff --git a/tests/cases/if_else_if.3-instructions.snap b/tests/cases/3-instructions@if_else_if.snap similarity index 90% rename from tests/cases/if_else_if.3-instructions.snap rename to tests/cases/3-instructions@if_else_if.snap index 5504ab9..124556e 100644 --- a/tests/cases/if_else_if.3-instructions.snap +++ b/tests/cases/3-instructions@if_else_if.snap @@ -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: { diff --git a/tests/cases/interpolation.3-instructions.snap b/tests/cases/3-instructions@interpolation.snap similarity index 88% rename from tests/cases/interpolation.3-instructions.snap rename to tests/cases/3-instructions@interpolation.snap index c47d18a..82dc16b 100644 --- a/tests/cases/interpolation.3-instructions.snap +++ b/tests/cases/3-instructions@interpolation.snap @@ -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: {}, diff --git a/tests/cases/literals.3-instructions.snap b/tests/cases/3-instructions@literals.snap similarity index 96% rename from tests/cases/literals.3-instructions.snap rename to tests/cases/3-instructions@literals.snap index 3955988..7f68e85 100644 --- a/tests/cases/literals.3-instructions.snap +++ b/tests/cases/3-instructions@literals.snap @@ -4,6 +4,7 @@ expression: emit info: input: "{{ if true }}\n Hello World!\n{{ end }}" context: {} +input_file: tests/cases/literals.nomo --- VMInstructions { labels: { diff --git a/tests/cases/maths.3-instructions.snap b/tests/cases/3-instructions@maths.snap similarity index 99% rename from tests/cases/maths.3-instructions.snap rename to tests/cases/3-instructions@maths.snap index 7722f26..d6a4920 100644 --- a/tests/cases/maths.3-instructions.snap +++ b/tests/cases/3-instructions@maths.snap @@ -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: {}, diff --git a/tests/cases/multiple.3-instructions.snap b/tests/cases/3-instructions@multiple.snap similarity index 88% rename from tests/cases/multiple.3-instructions.snap rename to tests/cases/3-instructions@multiple.snap index ef538c1..b6f13eb 100644 --- a/tests/cases/multiple.3-instructions.snap +++ b/tests/cases/3-instructions@multiple.snap @@ -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: {}, diff --git a/tests/cases/simple.3-instructions.snap b/tests/cases/3-instructions@simple.snap similarity index 82% rename from tests/cases/simple.3-instructions.snap rename to tests/cases/3-instructions@simple.snap index ce35108..752a53b 100644 --- a/tests/cases/simple.3-instructions.snap +++ b/tests/cases/3-instructions@simple.snap @@ -1,9 +1,7 @@ --- source: tests/file_tests.rs expression: emit -info: - input: Hello World! - context: {} +input_file: tests/cases/simple.nomo --- VMInstructions { labels: {}, diff --git a/tests/cases/simple_for.3-instructions.snap b/tests/cases/3-instructions@simple_for.snap similarity index 98% rename from tests/cases/simple_for.3-instructions.snap rename to tests/cases/3-instructions@simple_for.snap index f082c47..0cac073 100644 --- a/tests/cases/simple_for.3-instructions.snap +++ b/tests/cases/3-instructions@simple_for.snap @@ -8,6 +8,7 @@ info: values: - one - two +input_file: tests/cases/simple_for.nomo --- VMInstructions { labels: { diff --git a/tests/cases/trim_whitespace.3-instructions.snap b/tests/cases/3-instructions@trim_whitespace.snap similarity index 90% rename from tests/cases/trim_whitespace.3-instructions.snap rename to tests/cases/3-instructions@trim_whitespace.snap index 31112d0..5c1ad06 100644 --- a/tests/cases/trim_whitespace.3-instructions.snap +++ b/tests/cases/3-instructions@trim_whitespace.snap @@ -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: { diff --git a/tests/cases/4-output@condition.snap b/tests/cases/4-output@condition.snap new file mode 100644 index 0000000..1d5af6f --- /dev/null +++ b/tests/cases/4-output@condition.snap @@ -0,0 +1,6 @@ +--- +source: tests/file_tests.rs +expression: output +input_file: tests/cases/condition.nomo +--- +"\n Hello World!\n\n\nmore" diff --git a/tests/cases/4-output@identifiers.snap b/tests/cases/4-output@identifiers.snap new file mode 100644 index 0000000..33a3457 --- /dev/null +++ b/tests/cases/4-output@identifiers.snap @@ -0,0 +1,6 @@ +--- +source: tests/file_tests.rs +expression: output +input_file: tests/cases/identifiers.nomo +--- +"Foo\nFoo\nFoo\nFoo\nFoo\nFoo" diff --git a/tests/cases/4-output@if_else_if.snap b/tests/cases/4-output@if_else_if.snap new file mode 100644 index 0000000..c815937 --- /dev/null +++ b/tests/cases/4-output@if_else_if.snap @@ -0,0 +1,6 @@ +--- +source: tests/file_tests.rs +expression: output +input_file: tests/cases/if_else_if.nomo +--- +"\n Hello World!\n" diff --git a/tests/cases/interpolation.4-output.snap b/tests/cases/4-output@interpolation.snap similarity index 52% rename from tests/cases/interpolation.4-output.snap rename to tests/cases/4-output@interpolation.snap index b7e4214..f27078d 100644 --- a/tests/cases/interpolation.4-output.snap +++ b/tests/cases/4-output@interpolation.snap @@ -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" diff --git a/tests/cases/literals.4-output.snap b/tests/cases/4-output@literals.snap similarity index 80% rename from tests/cases/literals.4-output.snap rename to tests/cases/4-output@literals.snap index 60c99e3..3a38d32 100644 --- a/tests/cases/literals.4-output.snap +++ b/tests/cases/4-output@literals.snap @@ -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" diff --git a/tests/cases/maths.4-output.snap b/tests/cases/4-output@maths.snap similarity index 81% rename from tests/cases/maths.4-output.snap rename to tests/cases/4-output@maths.snap index b694479..ab89da7 100644 --- a/tests/cases/maths.4-output.snap +++ b/tests/cases/4-output@maths.snap @@ -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" diff --git a/tests/cases/4-output@multiple.snap b/tests/cases/4-output@multiple.snap new file mode 100644 index 0000000..b6a763a --- /dev/null +++ b/tests/cases/4-output@multiple.snap @@ -0,0 +1,6 @@ +--- +source: tests/file_tests.rs +expression: output +input_file: tests/cases/multiple.nomo +--- +"Hi there! My name is Hemera Green" diff --git a/tests/cases/simple.4-output.snap b/tests/cases/4-output@simple.snap similarity index 62% rename from tests/cases/simple.4-output.snap rename to tests/cases/4-output@simple.snap index 9dd7070..35ba658 100644 --- a/tests/cases/simple.4-output.snap +++ b/tests/cases/4-output@simple.snap @@ -1,8 +1,6 @@ --- source: tests/file_tests.rs expression: output -info: - input: Hello World! - context: {} +input_file: tests/cases/simple.nomo --- "Hello World!" diff --git a/tests/cases/simple_for.4-output.snap b/tests/cases/4-output@simple_for.snap similarity index 88% rename from tests/cases/simple_for.4-output.snap rename to tests/cases/4-output@simple_for.snap index ac83af5..0c2ca8d 100644 --- a/tests/cases/simple_for.4-output.snap +++ b/tests/cases/4-output@simple_for.snap @@ -8,5 +8,6 @@ info: values: - one - two +input_file: tests/cases/simple_for.nomo --- "one\ntwo\n\nNo Values >:C" diff --git a/tests/cases/4-output@trim_whitespace.snap b/tests/cases/4-output@trim_whitespace.snap new file mode 100644 index 0000000..03e2039 --- /dev/null +++ b/tests/cases/4-output@trim_whitespace.snap @@ -0,0 +1,6 @@ +--- +source: tests/file_tests.rs +expression: output +input_file: tests/cases/trim_whitespace.nomo +--- +"Hello Hemera" diff --git a/tests/cases/condition.4-output.snap b/tests/cases/condition.4-output.snap deleted file mode 100644 index bfdf149..0000000 --- a/tests/cases/condition.4-output.snap +++ /dev/null @@ -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" diff --git a/tests/cases/identifiers.4-output.snap b/tests/cases/identifiers.4-output.snap deleted file mode 100644 index 5834f52..0000000 --- a/tests/cases/identifiers.4-output.snap +++ /dev/null @@ -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" diff --git a/tests/cases/if_else_if.4-output.snap b/tests/cases/if_else_if.4-output.snap deleted file mode 100644 index 1cc7406..0000000 --- a/tests/cases/if_else_if.4-output.snap +++ /dev/null @@ -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" diff --git a/tests/cases/multiple.4-output.snap b/tests/cases/multiple.4-output.snap deleted file mode 100644 index d1047d4..0000000 --- a/tests/cases/multiple.4-output.snap +++ /dev/null @@ -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" diff --git a/tests/cases/trim_whitespace.4-output.snap b/tests/cases/trim_whitespace.4-output.snap deleted file mode 100644 index cde8c8b..0000000 --- a/tests/cases/trim_whitespace.4-output.snap +++ /dev/null @@ -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" diff --git a/tests/file_tests.rs b/tests/file_tests.rs index db3c666..523758d 100644 --- a/tests/file_tests.rs +++ b/tests/file_tests.rs @@ -1,64 +1,64 @@ 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, } -fn check_for_input([path]: [&Path; 1]) { - let mut settings = insta::Settings::clone_current(); - settings.set_snapshot_path("cases"); - settings.set_prepend_module_to_snapshot(false); +#[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 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)); - let map = if !context.is_empty() { - serde_json::from_str::>(context).unwrap() - } else { - HashMap::new() - }; + let map = if !context.is_empty() { + serde_json::from_str::>(context).unwrap() + } else { + HashMap::new() + }; - settings.set_info(&Info { - input: input.to_string(), - context: map.clone(), - }); + settings.set_info(&Info { + input: input.to_string(), + context: map.clone(), + }); - let mut context = Context::new(); + let mut context = Context::new(); - for (k, v) in map { - context.try_insert(k, v).unwrap(); - } - - let parsed = nomo::parser::parse(input.into()).unwrap(); - - let _guard = settings.bind_to_scope(); - - insta::assert_debug_snapshot!(format!("{basename}.1-parsed"), parsed); - - let ast = match nomo::ast::parse(parsed.tokens()) { - Ok(ast) => ast, - Err(err) => { - eprintln!("{}", err.to_report(input)); - panic!("Could not evaluate ast"); + for (k, v) in map { + context.try_insert(k, v).unwrap(); } - }; - insta::assert_debug_snapshot!(format!("{basename}.2-ast"), ast); + let parsed = nomo::parser::parse(input.into()).unwrap(); - let emit = nomo::emit::emit_machine(ast); + let _guard = settings.bind_to_scope(); - insta::assert_debug_snapshot!(format!("{basename}.3-instructions"), emit); + insta::assert_debug_snapshot!("1-parsed", parsed); - let output = nomo::eval::execute(&emit, &context).unwrap(); + let ast = match nomo::ast::parse(parsed.tokens()) { + Ok(ast) => ast, + Err(err) => { + eprintln!("{}", err.to_report(input)); + panic!("Could not evaluate ast"); + } + }; - insta::assert_debug_snapshot!(format!("{basename}.4-output"), output); + insta::assert_debug_snapshot!("2-ast", ast); + + let emit = nomo::emit::emit_machine(ast); + + insta::assert_debug_snapshot!("3-instructions", emit); + + let output = nomo::eval::execute(&emit, &context).unwrap(); + + insta::assert_debug_snapshot!("4-output", output); + }); }