Use macro per-test-file

Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
Marcel Müller 2026-03-12 18:15:20 +01:00
parent 605798674f
commit 06816567ff
49 changed files with 213 additions and 271 deletions

View file

@ -1,6 +0,0 @@
---
source: tests/file_tests.rs
expression: output
input_file: tests/cases/condition.nomo
---
"\n Hello World!\n\n\nmore"

View file

@ -1,6 +0,0 @@
---
source: tests/file_tests.rs
expression: output
input_file: tests/cases/identifiers.nomo
---
"Foo\nFoo\nFoo\nFoo\nFoo\nFoo"

View file

@ -1,6 +0,0 @@
---
source: tests/file_tests.rs
expression: output
input_file: tests/cases/if_else_if.nomo
---
"\n Hello World!\n"

View file

@ -1,6 +0,0 @@
---
source: tests/file_tests.rs
expression: output
input_file: tests/cases/multiple.nomo
---
"Hi there! My name is Hemera Green"

View file

@ -1,6 +0,0 @@
---
source: tests/file_tests.rs
expression: output
input_file: tests/cases/trim_whitespace.nomo
---
"Hello Hemera"

View file

@ -1,7 +1,11 @@
---
source: tests/file_tests.rs
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 {
tokens: [

View file

@ -1,7 +1,11 @@
---
source: tests/file_tests.rs
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 {
root: [

View file

@ -1,7 +1,11 @@
---
source: tests/file_tests.rs
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 {
labels: {

View 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"

View file

@ -4,13 +4,12 @@ expression: parsed
info:
input: "{{= _name }}\n{{= a_name }}\n{{= name }}\n{{= _name1 }}\n{{= _namE }}\n{{= name1 }}"
context:
_namE: Foo
name1: Foo
name: Foo
_name: Foo
_namE: Foo
a_name: Foo
name: Foo
_name1: Foo
input_file: tests/cases/identifiers.nomo
---
ParsedTemplate {
tokens: [

View file

@ -4,13 +4,12 @@ expression: ast
info:
input: "{{= _name }}\n{{= a_name }}\n{{= name }}\n{{= _name1 }}\n{{= _namE }}\n{{= name1 }}"
context:
_namE: Foo
name1: Foo
name: Foo
_name: Foo
_namE: Foo
a_name: Foo
name: Foo
_name1: Foo
input_file: tests/cases/identifiers.nomo
---
TemplateAst {
root: [

View file

@ -4,13 +4,12 @@ expression: emit
info:
input: "{{= _name }}\n{{= a_name }}\n{{= name }}\n{{= _name1 }}\n{{= _namE }}\n{{= name1 }}"
context:
_namE: Foo
name1: Foo
name: Foo
_name: Foo
_namE: Foo
a_name: Foo
name: Foo
_name1: Foo
input_file: tests/cases/identifiers.nomo
---
VMInstructions {
labels: {},

View 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"

View file

@ -1,7 +1,12 @@
---
source: tests/file_tests.rs
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 {
tokens: [

View file

@ -1,7 +1,12 @@
---
source: tests/file_tests.rs
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 {
root: [

View file

@ -1,7 +1,12 @@
---
source: tests/file_tests.rs
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 {
labels: {

View 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"

View file

@ -1,7 +1,10 @@
---
source: tests/file_tests.rs
expression: parsed
input_file: tests/cases/interpolation.nomo
info:
input: "Hello! I'm {{= name }}"
context:
name: Hemera
---
ParsedTemplate {
tokens: [

View file

@ -1,7 +1,10 @@
---
source: tests/file_tests.rs
expression: ast
input_file: tests/cases/interpolation.nomo
info:
input: "Hello! I'm {{= name }}"
context:
name: Hemera
---
TemplateAst {
root: [

View file

@ -1,7 +1,10 @@
---
source: tests/file_tests.rs
expression: emit
input_file: tests/cases/interpolation.nomo
info:
input: "Hello! I'm {{= name }}"
context:
name: Hemera
---
VMInstructions {
labels: {},

View file

@ -1,6 +1,9 @@
---
source: tests/file_tests.rs
expression: output
input_file: tests/cases/interpolation.nomo
info:
input: "Hello! I'm {{= name }}"
context:
name: Hemera
---
"Hello! I'm Hemera"

View file

@ -4,7 +4,6 @@ expression: parsed
info:
input: "{{ if true }}\n Hello World!\n{{ end }}"
context: {}
input_file: tests/cases/literals.nomo
---
ParsedTemplate {
tokens: [

View file

@ -4,7 +4,6 @@ expression: ast
info:
input: "{{ if true }}\n Hello World!\n{{ end }}"
context: {}
input_file: tests/cases/literals.nomo
---
TemplateAst {
root: [

View file

@ -4,7 +4,6 @@ expression: emit
info:
input: "{{ if true }}\n Hello World!\n{{ end }}"
context: {}
input_file: tests/cases/literals.nomo
---
VMInstructions {
labels: {

View file

@ -4,6 +4,5 @@ expression: output
info:
input: "{{ if true }}\n Hello World!\n{{ end }}"
context: {}
input_file: tests/cases/literals.nomo
---
"\n Hello World!\n"

View file

@ -4,7 +4,6 @@ expression: parsed
info:
input: "{{= 5 * 3 }}\n{{= 2 * 3 + 4 * 3 }}\n{{= 3 / 3 + 3 }}"
context: {}
input_file: tests/cases/maths.nomo
---
ParsedTemplate {
tokens: [

View file

@ -4,7 +4,6 @@ expression: ast
info:
input: "{{= 5 * 3 }}\n{{= 2 * 3 + 4 * 3 }}\n{{= 3 / 3 + 3 }}"
context: {}
input_file: tests/cases/maths.nomo
---
TemplateAst {
root: [

View file

@ -4,7 +4,6 @@ expression: emit
info:
input: "{{= 5 * 3 }}\n{{= 2 * 3 + 4 * 3 }}\n{{= 3 / 3 + 3 }}"
context: {}
input_file: tests/cases/maths.nomo
---
VMInstructions {
labels: {},

View file

@ -4,6 +4,5 @@ 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"

View file

@ -1,7 +1,11 @@
---
source: tests/file_tests.rs
expression: parsed
input_file: tests/cases/multiple.nomo
info:
input: "Hi there! My name is {{= name }} {{= lastname }}"
context:
name: Hemera
lastname: Green
---
ParsedTemplate {
tokens: [

View file

@ -1,7 +1,11 @@
---
source: tests/file_tests.rs
expression: ast
input_file: tests/cases/multiple.nomo
info:
input: "Hi there! My name is {{= name }} {{= lastname }}"
context:
name: Hemera
lastname: Green
---
TemplateAst {
root: [

View file

@ -1,7 +1,11 @@
---
source: tests/file_tests.rs
expression: emit
input_file: tests/cases/multiple.nomo
info:
input: "Hi there! My name is {{= name }} {{= lastname }}"
context:
name: Hemera
lastname: Green
---
VMInstructions {
labels: {},

View 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"

View file

@ -1,7 +1,9 @@
---
source: tests/file_tests.rs
expression: parsed
input_file: tests/cases/simple.nomo
info:
input: Hello World!
context: {}
---
ParsedTemplate {
tokens: [

View file

@ -1,7 +1,9 @@
---
source: tests/file_tests.rs
expression: ast
input_file: tests/cases/simple.nomo
info:
input: Hello World!
context: {}
---
TemplateAst {
root: [

View file

@ -1,7 +1,9 @@
---
source: tests/file_tests.rs
expression: emit
input_file: tests/cases/simple.nomo
info:
input: Hello World!
context: {}
---
VMInstructions {
labels: {},

View file

@ -1,6 +1,8 @@
---
source: tests/file_tests.rs
expression: output
input_file: tests/cases/simple.nomo
info:
input: Hello World!
context: {}
---
"Hello World!"

View file

@ -8,7 +8,6 @@ info:
values:
- one
- two
input_file: tests/cases/simple_for.nomo
---
ParsedTemplate {
tokens: [

View file

@ -8,7 +8,6 @@ info:
values:
- one
- two
input_file: tests/cases/simple_for.nomo
---
TemplateAst {
root: [

View file

@ -8,7 +8,6 @@ info:
values:
- one
- two
input_file: tests/cases/simple_for.nomo
---
VMInstructions {
labels: {

View file

@ -8,6 +8,5 @@ info:
values:
- one
- two
input_file: tests/cases/simple_for.nomo
---
"one\ntwo\n\nNo Values >:C"

View file

@ -1,7 +1,11 @@
---
source: tests/file_tests.rs
expression: parsed
input_file: tests/cases/trim_whitespace.nomo
info:
input: "{{ if test -}}\n Hello {{= stuff -}}\n{{- end }}"
context:
stuff: Hemera
test: true
---
ParsedTemplate {
tokens: [

View file

@ -1,7 +1,11 @@
---
source: tests/file_tests.rs
expression: ast
input_file: tests/cases/trim_whitespace.nomo
info:
input: "{{ if test -}}\n Hello {{= stuff -}}\n{{- end }}"
context:
stuff: Hemera
test: true
---
TemplateAst {
root: [

View file

@ -1,7 +1,11 @@
---
source: tests/file_tests.rs
expression: emit
input_file: tests/cases/trim_whitespace.nomo
info:
input: "{{ if test -}}\n Hello {{= stuff -}}\n{{- end }}"
context:
stuff: Hemera
test: true
---
VMInstructions {
labels: {

View 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"

View file

@ -1,4 +1,5 @@
use std::collections::HashMap;
use std::path::Path;
use nomo::Context;
@ -8,57 +9,55 @@ struct Info {
context: HashMap<String, serde_json::Value>,
}
#[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);
test_each_file::test_each_path! { for ["nomo"] in "./tests/cases/" => check_for_input }
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);
let input = std::fs::read_to_string(path).unwrap();
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));
let (context, input) = input.split_once("\n---\n").unwrap_or_else(|| ("", &input));
let map = if !context.is_empty() {
serde_json::from_str::<HashMap<String, serde_json::Value>>(context).unwrap()
} else {
HashMap::new()
};
let map = if !context.is_empty() {
serde_json::from_str::<HashMap<String, serde_json::Value>>(context).unwrap()
} else {
HashMap::new()
};
settings.set_info(&Info {
input: input.to_string(),
context: map.clone(),
});
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!("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");
}
};
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);
settings.set_info(&Info {
input: input.to_string(),
context: map.clone(),
});
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");
}
};
insta::assert_debug_snapshot!(format!("{basename}.2-ast"), ast);
let emit = nomo::emit::emit_machine(ast);
insta::assert_debug_snapshot!(format!("{basename}.3-instructions"), emit);
let output = nomo::eval::execute(&emit, &context).unwrap();
insta::assert_debug_snapshot!(format!("{basename}.4-output"), output);
}