From 2b1200ea46e31f862782b68cd0992cac3b554b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 15 Jan 2021 16:02:01 +0100 Subject: export macros and test typecheck --- src/lib.rs | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 9713eb3..7441eb7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,15 +32,15 @@ pub fn run(tokens: TokenStream, path: &Path, print: bool) -> Result<(), Vec { println!("{} => {:?}", stringify!($result), $result); assert!(matches!( $result.unwrap_err().as_slice(), - &[$(Error { + &[$($crate::error::Error { kind: $kind, file: _, line: _, @@ -51,21 +51,40 @@ mod tests { }; } - #[test] - fn unreachable_token() { - assert_errs!(run_string("\n", true), [ErrorKind::Unreachable]); + #[macro_export] + macro_rules! test_string { + ($fn:ident, $prog:literal) => { + #[test] + fn $fn() { + $crate::run_string($prog, true).unwrap(); + } + }; + ($fn:ident, $prog:literal, $errs:tt) => { + #[test] + fn $fn() { + $crate::assert_errs!($crate::run_string($prog, true), $errs); + } + } } + #[macro_export] macro_rules! test_file { ($fn:ident, $path:literal) => { #[test] fn $fn() { let file = Path::new($path); - assert!(run_file(&file, true).is_ok()); + run_file(&file, true).unwrap(); } }; } + use crate::error::ErrorKind; + + #[test] + fn unreachable_token() { + assert_errs!(run_string("\n", true), [ErrorKind::Unreachable]); + } + test_file!(order_of_operations, "tests/order-of-operations.tdy"); test_file!(variables, "tests/variables.tdy"); test_file!(scoping, "tests/scoping.tdy"); -- cgit v1.2.1