Add more tests
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
6788ddbbb6
commit
761600a759
36
src/main.rs
36
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue