Use macro per-test-file
Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
parent
605798674f
commit
06816567ff
49 changed files with 213 additions and 271 deletions
|
|
@ -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
|
||||
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: [
|
||||
|
|
@ -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: [
|
||||
|
|
@ -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: {
|
||||
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:
|
||||
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: [
|
||||
|
|
@ -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: [
|
||||
|
|
@ -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: {},
|
||||
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
|
||||
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: [
|
||||
|
|
@ -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: [
|
||||
|
|
@ -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: {
|
||||
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
|
||||
expression: parsed
|
||||
input_file: tests/cases/interpolation.nomo
|
||||
info:
|
||||
input: "Hello! I'm {{= name }}"
|
||||
context:
|
||||
name: Hemera
|
||||
---
|
||||
ParsedTemplate {
|
||||
tokens: [
|
||||
|
|
@ -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: [
|
||||
|
|
@ -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: {},
|
||||
|
|
@ -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"
|
||||
|
|
@ -4,7 +4,6 @@ expression: parsed
|
|||
info:
|
||||
input: "{{ if true }}\n Hello World!\n{{ end }}"
|
||||
context: {}
|
||||
input_file: tests/cases/literals.nomo
|
||||
---
|
||||
ParsedTemplate {
|
||||
tokens: [
|
||||
|
|
@ -4,7 +4,6 @@ expression: ast
|
|||
info:
|
||||
input: "{{ if true }}\n Hello World!\n{{ end }}"
|
||||
context: {}
|
||||
input_file: tests/cases/literals.nomo
|
||||
---
|
||||
TemplateAst {
|
||||
root: [
|
||||
|
|
@ -4,7 +4,6 @@ expression: emit
|
|||
info:
|
||||
input: "{{ if true }}\n Hello World!\n{{ end }}"
|
||||
context: {}
|
||||
input_file: tests/cases/literals.nomo
|
||||
---
|
||||
VMInstructions {
|
||||
labels: {
|
||||
|
|
@ -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"
|
||||
|
|
@ -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: [
|
||||
|
|
@ -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: [
|
||||
|
|
@ -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: {},
|
||||
|
|
@ -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"
|
||||
|
|
@ -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: [
|
||||
|
|
@ -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: [
|
||||
|
|
@ -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: {},
|
||||
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
|
||||
expression: parsed
|
||||
input_file: tests/cases/simple.nomo
|
||||
info:
|
||||
input: Hello World!
|
||||
context: {}
|
||||
---
|
||||
ParsedTemplate {
|
||||
tokens: [
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: ast
|
||||
input_file: tests/cases/simple.nomo
|
||||
info:
|
||||
input: Hello World!
|
||||
context: {}
|
||||
---
|
||||
TemplateAst {
|
||||
root: [
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: emit
|
||||
input_file: tests/cases/simple.nomo
|
||||
info:
|
||||
input: Hello World!
|
||||
context: {}
|
||||
---
|
||||
VMInstructions {
|
||||
labels: {},
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
---
|
||||
source: tests/file_tests.rs
|
||||
expression: output
|
||||
input_file: tests/cases/simple.nomo
|
||||
info:
|
||||
input: Hello World!
|
||||
context: {}
|
||||
---
|
||||
"Hello World!"
|
||||
|
|
@ -8,7 +8,6 @@ info:
|
|||
values:
|
||||
- one
|
||||
- two
|
||||
input_file: tests/cases/simple_for.nomo
|
||||
---
|
||||
ParsedTemplate {
|
||||
tokens: [
|
||||
|
|
@ -8,7 +8,6 @@ info:
|
|||
values:
|
||||
- one
|
||||
- two
|
||||
input_file: tests/cases/simple_for.nomo
|
||||
---
|
||||
TemplateAst {
|
||||
root: [
|
||||
|
|
@ -8,7 +8,6 @@ info:
|
|||
values:
|
||||
- one
|
||||
- two
|
||||
input_file: tests/cases/simple_for.nomo
|
||||
---
|
||||
VMInstructions {
|
||||
labels: {
|
||||
|
|
@ -8,6 +8,5 @@ info:
|
|||
values:
|
||||
- one
|
||||
- two
|
||||
input_file: tests/cases/simple_for.nomo
|
||||
---
|
||||
"one\ntwo\n\nNo Values >:C"
|
||||
|
|
@ -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: [
|
||||
|
|
@ -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: [
|
||||
|
|
@ -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: {
|
||||
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,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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue