Add additional tests

This commit is contained in:
Greg Shuflin 2021-10-25 23:34:17 -07:00
parent e40b8ece3b
commit 48e2d9a683
3 changed files with 60 additions and 27 deletions

60
Cargo.lock generated
View File

@ -60,7 +60,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "690a62be8920ccf773ee00ef0968649b0e724cda8bd5b12286302b4ae955fdf5" checksum = "690a62be8920ccf773ee00ef0968649b0e724cda8bd5b12286302b4ae955fdf5"
dependencies = [ dependencies = [
"backtrace-sys", "backtrace-sys",
"cfg-if", "cfg-if 0.1.10",
"libc", "libc",
"rustc-demangle", "rustc-demangle",
] ]
@ -119,6 +119,12 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]] [[package]]
name = "cgmath" name = "cgmath"
version = "0.16.1" version = "0.16.1"
@ -161,7 +167,7 @@ version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6" checksum = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 0.1.10",
"lazy_static 1.4.0", "lazy_static 1.4.0",
] ]
@ -355,7 +361,7 @@ version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 0.1.10",
] ]
[[package]] [[package]]
@ -410,7 +416,7 @@ checksum = "6c722bee1037d430d0f8e687bbdbf222f27cc6e4e68d5caf630857bb2b6dbdce"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cc", "cc",
"cfg-if", "cfg-if 0.1.10",
"libc", "libc",
"void", "void",
] ]
@ -428,7 +434,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6" checksum = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6"
dependencies = [ dependencies = [
"memchr", "memchr",
"version_check", "version_check 0.1.5",
] ]
[[package]] [[package]]
@ -567,9 +573,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.4" version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afdc77cc74ec70ed262262942ebb7dac3d479e9e5cfa2da1841c0806f6cdabcc" checksum = "edc3358ebc67bc8b7fa0c007f945b0b18226f78437d61bec735a9eb96b61ee70"
dependencies = [ dependencies = [
"unicode-xid 0.2.0", "unicode-xid 0.2.0",
] ]
@ -585,11 +591,11 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.2" version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
dependencies = [ dependencies = [
"proc-macro2 1.0.4", "proc-macro2 1.0.30",
] ]
[[package]] [[package]]
@ -848,6 +854,7 @@ dependencies = [
"schala-repl", "schala-repl",
"stopwatch", "stopwatch",
"take_mut", "take_mut",
"test-case",
] ]
[[package]] [[package]]
@ -905,9 +912,9 @@ version = "1.0.101"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b133a43a1ecd55d4086bd5b4dc6c1751c68b1bfbeba7a5040442022c7e7c02e" checksum = "4b133a43a1ecd55d4086bd5b4dc6c1751c68b1bfbeba7a5040442022c7e7c02e"
dependencies = [ dependencies = [
"proc-macro2 1.0.4", "proc-macro2 1.0.30",
"quote 1.0.2", "quote 1.0.10",
"syn 1.0.5", "syn 1.0.80",
] ]
[[package]] [[package]]
@ -964,12 +971,12 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.5" version = "1.0.80"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf" checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194"
dependencies = [ dependencies = [
"proc-macro2 1.0.4", "proc-macro2 1.0.30",
"quote 1.0.2", "quote 1.0.10",
"unicode-xid 0.2.0", "unicode-xid 0.2.0",
] ]
@ -1003,6 +1010,19 @@ dependencies = [
"phf_codegen", "phf_codegen",
] ]
[[package]]
name = "test-case"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b114ece25254e97bf48dd4bfc2a12bad0647adacfe4cae1247a9ca6ad302cec"
dependencies = [
"cfg-if 1.0.0",
"proc-macro2 1.0.30",
"quote 1.0.10",
"syn 1.0.80",
"version_check 0.9.3",
]
[[package]] [[package]]
name = "thread_local" name = "thread_local"
version = "0.3.6" version = "0.3.6"
@ -1057,6 +1077,12 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
[[package]]
name = "version_check"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
[[package]] [[package]]
name = "void" name = "void"
version = "1.0.2" version = "1.0.2"

View File

@ -17,3 +17,6 @@ assert_matches = "1.5"
schala-lang-codegen = { path = "../codegen" } schala-lang-codegen = { path = "../codegen" }
schala-repl = { path = "../../schala-repl" } schala-repl = { path = "../../schala-repl" }
[dev-dependencies]
test-case = "1.2.0"

View File

@ -1,4 +1,5 @@
#![cfg(test)] #![cfg(test)]
use test_case::test_case;
use crate::symbol_table::SymbolTable; use crate::symbol_table::SymbolTable;
use crate::tree_walk_eval::State; use crate::tree_walk_eval::State;
@ -98,18 +99,21 @@ let d = if "xxx" is "yyy" then { 20 } else { 30 }
eval_assert(source, "(255, 256, 10, 30)"); eval_assert(source, "(255, 256, 10, 30)");
} }
#[test] #[test_case("sanchez", "1")]
fn basic_patterns_2() { #[test_case("mouri", "2")]
let source = r#" #[test_case("hella", "3")]
let x = "hella" #[test_case("cyrus", "4")]
fn basic_patterns_2(input: &str, expected: &str) {
let mut source = format!(r#"let x = "{}""#, input);
source.push_str(r#"
if x { if x {
is "sanchez" then 23 is "sanchez" then 1
is "mouri" then 99 is "mouri" then 2
is "hella" then 2 is "hella" then 3
is _ then 94 is _ then 4
} }
"#; "#);
eval_assert(source, "2"); eval_assert(&source, expected);
} }
#[test] #[test]