Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: trim whitespace in compiler only #12

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 10 additions & 1 deletion crates/brainfuck_vm/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ mod tests {
let compiler = Compiler::new(code);
let expected_trimmed_code =
vec!['+', '+', '>', ',', '<', '[', '>', '+', '.', '<', '-', ']'];
assert_eq!(expected_trimmed_code, compiler.code,);
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]
Expand Down