From 742c16dccef17a57494fe5846818cfc3324bbd45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Tue, 16 Feb 2021 23:45:45 +0100 Subject: add tests for unusued variables --- src/lib.rs | 14 ++++++++++++++ src/vm.rs | 9 ++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 77176c4..7ef13f9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -856,6 +856,20 @@ mod tests { assert_errs!(run_string("a :: B()\n", true, Vec::new()), [ErrorKind::SyntaxError(_, _)]); } + #[test] + fn unused_variable() { + assert_errs!(run_string("a := 1", true, Vec::new()), [ErrorKind::SyntaxError(1, _)]); + } + + #[test] + fn unused_upvalue() { + assert_errs!(run_string("a := 1\nf :: fn { a = 2 }\nf()", true, Vec::new()), [ErrorKind::SyntaxError(1, _)]); + } + + #[test] + fn unused_function() { + assert_errs!(run_string("a := 1\nf := fn { a }\n", true, Vec::new()), [ErrorKind::SyntaxError(2, _)]); + } macro_rules! test_multiple { ($mod:ident, $( $fn:ident : $prog:literal ),+ $( , )? ) => { diff --git a/src/vm.rs b/src/vm.rs index f5c1cf0..70cb5e4 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -831,15 +831,18 @@ mod tests { test_string!(uncallable_type, " f := fn i: int { i() - }", + } + f", [ErrorKind::TypeError(_, _)]); test_string!(wrong_params, " - f : fn -> int = fn a: int -> int {}", + f : fn -> int = fn a: int -> int {} + f", [ErrorKind::TypeError(_, _), ErrorKind::TypeError(_, _)]); test_string!(wrong_ret, " - f : fn -> int = fn {}", + f : fn -> int = fn {} + f", [ErrorKind::TypeError(_, _)]); } } -- cgit v1.2.1