diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-01-16 01:46:12 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-01-16 01:46:12 +0100 |
| commit | e4c01e1c86bd9035750d91762f7a0868f0f56d54 (patch) | |
| tree | f41bdad633874a94c84b6d54695a6bf95b0eb317 /src | |
| parent | 85b12e35035af28a20d70b1fe3b319156004b24b (diff) | |
| download | sylt-e4c01e1c86bd9035750d91762f7a0868f0f56d54.tar.gz | |
move some tests to strings and test_multiple!
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 78 |
1 files changed, 75 insertions, 3 deletions
@@ -85,10 +85,82 @@ mod tests { assert_errs!(run_string("<!>\n", true), [ErrorKind::Unreachable]); } - test_file!(order_of_operations, "tests/order-of-operations.tdy"); - test_file!(variables, "tests/variables.tdy"); + macro_rules! test_multiple { + ($mod:ident, $( $fn:ident : $prog:literal ),+ $( , )? ) => { + mod $mod { + $( test_string!($fn, $prog); )+ + } + } + } + + test_multiple!( + order_of_operations, + terms_and_factors: "1 + 1 * 2 <=> 3 + 1 * 2 + 3 <=> 5", + in_rhs: "5 <=> 1 * 2 + 3", + parenthesis: "(1 + 2) * 3 <=> 9", + negation: "-1 <=> 0 - 1 + -1 + 2 <=> 1 + -(1 + 2) <=> -3 + 1 + -1 <=> 0 + 2 * -1 <=> -2", + ); + + test_multiple!( + variables, + single_variable: "a := 1 + a <=> 1", + two_variables: "a := 1 + b := 2 + a <=> 1 + b <=> 2", + stack_ordering: "a := 1 + b := 2 + b <=> 2 + a <=> 1", + assignment: "a := 1 + b := 2 + a = b + a <=> 2 + b <=> 2", + ); + + test_multiple!( + if_, + compare_constants_equality: "if 1 == 2 { + <!> + }", + compare_constants_unequality: "if 1 != 1 { + <!> + }", + compare_variable: "a := 1 + if a == 0 { + <!> + } + if a != 1 { + <!> + }", + else_: "a := 1 + res := 0 + if a == 0 { + <!> + } else { + res = 1 + } + res <=> 1", + else_if: "a := 1 + res := 0 + if a == 0 { + <!> + } else if a == 1 { + res = 1 + } else { + <!> + } + res <=> 1", + ); + test_file!(scoping, "tests/scoping.tdy"); - test_file!(if_, "tests/if.tdy"); test_file!(for_, "tests/for.tdy"); test_file!(fun, "tests/fun.tdy"); } |
