Heap bonus!
This commit is contained in:
36
tests/bonusheap.rs
Normal file
36
tests/bonusheap.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
extern crate rustijvm;
|
||||
|
||||
use std::fs::File;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Mutex;
|
||||
use std::io::{Cursor, Seek, SeekFrom, Read};
|
||||
|
||||
fn run_bfi(file: &str) -> String {
|
||||
let file = File::open(file).expect("Missing bf file");
|
||||
let rc = Rc::new(Mutex::new(Cursor::new(Vec::new())));
|
||||
let mut machine = rustijvm::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");
|
||||
}
|
||||
Reference in New Issue
Block a user