sandwich

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

commit 761600a75915407c8c8fb1d6b5f8488a9c98a2f4
parent 6788ddbbb62e1d01ce67d1a7121d0e34ff467a7a
Author: ~karx <karx@tilde.team>
Date:   Wed, 10 Feb 2021 20:48:33 +0000

Add more tests

Diffstat:
Msrc/main.rs | 36+++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/src/main.rs b/src/main.rs @@ -154,7 +154,7 @@ impl Program { 'l' => self.add_var(arguments), 'f' => self.add_func(arguments), '#' => {} // Do nothing for comments - _ => panic!("SyntaxError: No such opcode: {}", self.pc), + _ => panic!("SyntaxError at opcode {}: Unknown opcode {}", self.pc, opcode), } } @@ -218,4 +218,38 @@ mod tests { fn test_undefined_variable() { make_program("p$v").run(); } + + #[test] + #[should_panic] + fn test_undefined_function() { + make_program("p*x").run(); + } + + #[test] + fn test_factory() { + let prog = make_program("lhHello\nlwWorld\np$h $w"); + let vec_to_check: Vec<String> = vec!["lhHello", "lwWorld", "p$h $w"].into_iter().map(|s| s.to_string()).collect(); + + assert_eq!(prog.data, vec_to_check); + } + + #[test] + fn test_args() { + let mut prog = make_program("lhHello\nlwWorld\np$h $w"); + prog.run(); + + let args_to_check: HashMap<char, String> = [('h', String::from("Hello")), ('w', String::from("World"))].iter().cloned().collect(); + + assert_eq!(prog.vars, args_to_check); + } + + #[test] + fn test_funcs() { + let mut prog = make_program("fxa10-10\nfys10-5\np*x *y"); + prog.run(); + + let funcs_to_check: HashMap<char, String> = [('x', String::from("a10-10")), ('y', String::from("s10-5"))].iter().cloned().collect(); + + assert_eq!(prog.funcs, funcs_to_check); + } }