sandwich

A funny programming language written in Rust
git clone https://tilde.team/~karx/sandwich.git
Log | Files | Refs | README | LICENSE

commit 154cac779a99d6b7f5f5d874a52fa6ebdc888c7f
parent 80f4556786da166cc233bb8f4fdb497e54d75b3c
Author: ~karx <karx@tilde.team>
Date:   Sun,  7 Feb 2021 19:35:00 +0000

Add test suite

Diffstat:
Msrc/main.rs | 28++++++++++++++++++++++++++++
1 file changed, 28 insertions(+), 0 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -128,3 +128,30 @@ fn main() { let mut prog = Program::from_string(contents); prog.run(); } + +#[cfg(test)] +mod tests { + use super::*; + + fn make_program(contents: &str) -> Program { + Program::from_string(contents.to_string()) + } + + #[test] + fn test_math() { + assert_eq!(eval::do_math("2-2".to_string(), '+'), 4); + } + + #[test] + #[should_panic] + fn test_undefined_opcode() { + make_program("Hello\nWorld!").run(); + } + + #[test] + #[should_panic] + fn test_undefined_variable() { + make_program("p$v").run(); + } + +}+ \ No newline at end of file