diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2021-10-25 00:15:04 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2021-10-25 00:15:04 -0700 |
commit | b3141319b98199d75f1317ef3754c0b6b14b1f78 (patch) | |
tree | 70802b1170fa58a0b02ae9d2d02e985ab4b0b9af /tests | |
parent | 04c53bb88bfbbc5c65b25104959c66d06e2b4fa1 (diff) | |
download | casual-b3141319b98199d75f1317ef3754c0b6b14b1f78.tar.gz casual-b3141319b98199d75f1317ef3754c0b6b14b1f78.zip |
refactor into lib-style crate, and add some early tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/canonicalize.rs | 26 | ||||
-rw-r--r-- | tests/things.txt | 35 |
2 files changed, 61 insertions, 0 deletions
diff --git a/tests/canonicalize.rs b/tests/canonicalize.rs new file mode 100644 index 0000000..3ef088a --- /dev/null +++ b/tests/canonicalize.rs @@ -0,0 +1,26 @@ +use casual::{CExpr, CNumber}; + +#[test] +fn basics() { + assert_eq!( + CExpr::from_str("(+ 1 2 3)").unwrap(), + CExpr::Number(CNumber::Integer(6)), + ); +} + +#[test] +fn canonicalization() { + let cases = vec![ + ("(+ (+ a 2) (+ b 2))", "(+ 4 a b)"), + ("(+ (+ a 2) (+ b 2))", "(+ 4 a b)"), + ("(+ 1 2 b)", "(+ 3 b)"), + ("(+ 1 2 3)", "6"), + ("(* (/ 2 3) (/ 3 2))", "1"), + ]; + + for (input, output) in cases.iter() { + assert_eq!(CExpr::from_str(input).unwrap().to_string(), *output); + } +} + +// TODO: helper to read an examples file, as pairs of rows diff --git a/tests/things.txt b/tests/things.txt new file mode 100644 index 0000000..f525f6e --- /dev/null +++ b/tests/things.txt @@ -0,0 +1,35 @@ + +(+ (+ a 2) (+ b 2)) +(+ 4 a b) + +(+ 1 2 b) +(+ 3 b) + +(+ 1 2 3) +6 + +(* (/ 2 3) (/ 3 2)) +1 + +# TODO +(* (/ -2 3) (/ 3 2)) +-1 + + +(* (* a b 1) (* c d)) +(* a b c d) + +(+ (+ a b) (+ c d)) +(+ a b c d) + +(+ (+ a b 1) (+ c d 3)) +(+ 4 a b c d) + +(^ 4 -1) +(/ 1 4) + +(^ (/ 2 3) -1) +(/ 3 2) + +(^ (/ 1 3) -1) +3 |