Skip to content

Commit

Permalink
refactor: trim whitespace in compiler only
Browse files Browse the repository at this point in the history
  • Loading branch information
zmalatrax committed Nov 6, 2024
1 parent 53fb010 commit 16ec612
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 1 addition & 3 deletions crates/brainfuck_vm/src/bin/brainfuck_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ fn main() {
// Constructs a subscriber whose severity level is filtered by `RUST_LOG`
fmt().with_env_filter(EnvFilter::from_default_env()).init();

let code = fs::read_to_string(&args.filename)
.expect("Failed to read file")
.replace(' ', "");
let code = fs::read_to_string(&args.filename).expect("Failed to read file");
let mut bf_compiler = Compiler::new(code);
let ins = bf_compiler.compile();
tracing::info!(
Expand Down
9 changes: 9 additions & 0 deletions crates/brainfuck_vm/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ mod tests {
assert_eq!(expected_trimmed_code, compiler.code,);
}

#[test]
fn test_whitespace() {
let code = " + +> , < [> + .< - ] ".to_string();
let compiler = Compiler::new(code);
let expected_trimmed_code =
vec!['+', '+', '>', ',', '<', '[', '>', '+', '.', '<', '-', ']'];
assert_eq!(expected_trimmed_code, compiler.code,);
}

#[test]
fn test_compile() {
let code = "++>,<[>+.<-]".to_string();
Expand Down

0 comments on commit 16ec612

Please sign in to comment.