35 lines
878 B
Rust
35 lines
878 B
Rust
extern crate rustijvm;
|
|
|
|
use std::fs::File;
|
|
use std::io::{Seek, SeekFrom, Read};
|
|
|
|
fn run_bfi(file: &str) -> String {
|
|
let file = File::open(file).expect("Missing bf file");
|
|
let rc = rustijvm::stubs::output_stub();
|
|
let mut machine = rustijvm::machine::Machine::new_from_file("files/bonus/bfi.ijvm").unwrap();
|
|
machine.set_output(rc.clone());
|
|
machine.set_input(Box::new(file));
|
|
|
|
machine.run().unwrap();
|
|
|
|
let mut out = rc.lock().unwrap();
|
|
let mut string = String::new();
|
|
|
|
out.seek(SeekFrom::Start(0)).unwrap();
|
|
out.read_to_string(&mut string).unwrap();
|
|
|
|
string
|
|
}
|
|
|
|
#[test]
|
|
fn bonusheap_hello_world() {
|
|
let output = run_bfi("files/bonus/brainfuck/hello_world.bf");
|
|
assert_eq!(output, "Hello World!\n");
|
|
}
|
|
|
|
#[test]
|
|
fn bonusheap_dank() {
|
|
let output = run_bfi("files/bonus/brainfuck/dank.bf");
|
|
assert_eq!(output, "MoarTests");
|
|
}
|