const NEWLINE_PRINTING_PROGRAM: &str = include_str!("../../newline.bf"); const PREMATURE_PROGRAM: &str = include_str!("../../premature.bf");
const UNMATCHED_PROGRAM: &str = include_str!("../../unmatched.bf");
use super::*; #[test]
fn test_newline_program() {
use BrainfuckInstr::*;
let mut parser = Parser::new();
let output = parser
.parse(NEWLINE_PRINTING_PROGRAM)
.expect("The newline program contains no syntax errors, something is wrong with the parser.");
let expected_output: Vec<BrainfuckInstr> = vec![
DataInc, DataInc, DataInc, DataInc, DataInc,
DataInc, DataInc, DataInc, DataInc, DataInc,
PutByte
];
assert_eq!(&output, &expected_output)
}
#[test]
fn test_premature_program() {
let mut parser = Parser::new();
let output = parser
.parse(PREMATURE_PROGRAM)
.expect_err("The code in premature.bf shouldn't produce a valid instruction list.");
assert_eq!(output, SyntaxError::PrematureEndWhile(2, 1)) }
#[test]
fn test_unmatched_program() {
let mut parser = Parser::new();
let output = parser
.parse(UNMATCHED_PROGRAM)
.expect_err("The code in unmatched.bf shouldn't produce a valid instruction list.");
assert_eq!(output, SyntaxError::UnclosedWhile(1, 8)) }