1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::str;
use common::BfResult;
use traits::Interpretable;
pub const FACTOR_SRC: &[u8] = include_bytes!("../bf/factor.bf");
pub const HELLO_WORLD_SRC: &[u8] =
b"++++++[>++++++++++++<-]>.\
>++++++++++[>++++++++++<-]>+.\
+++++++..+++.>++++[>+++++++++++<-]>.\
<+++[>----<-]>.<<<<<+++[>+++++<-]>.\
>>.+++.------.--------.>>+.";
pub fn assert_interpret<I: Interpretable + ?Sized>(program: &I, input: &[u8], output: &[u8]) {
assert_interpret_result(program, input, Ok(output));
}
pub fn assert_interpret_result<I>(program: &I, input: &[u8], output: BfResult<&[u8]>)
where I: Interpretable + ?Sized
{
let actual_bytes = program.interpret_memory(None, input);
let actual = actual_bytes.map(|bytes| str::from_utf8(&bytes).unwrap().to_owned());
let expected = output.map(|bytes| str::from_utf8(bytes).unwrap().to_owned());
assert_eq!(actual, expected);
}