xbasic 0.3.1

A library that allows adding a scripting language onto your project with ease. This lets your users write their own arbitrary logic.
Documentation
use criterion::{criterion_group, criterion_main, Criterion};
use xbasic::basic_io::BasicIO;
use xbasic::xbasic::XBasic;

pub struct TestIO {
	expected: &'static str,
	actual: String,
}

impl TestIO {
	pub fn new(expected: &'static str) -> Self {
		Self {
			expected,
			actual: String::new(),
		}
	}

	pub fn check(&self) {
		assert_eq!(self.expected, self.actual);
	}
}

impl BasicIO for TestIO {
	fn read_line(&mut self) -> String {
		unimplemented!()
	}

	fn write_line(&mut self, line: String) {
		self.actual += &(line + "\n");
	}
}

fn recursive_benchmark(c: &mut Criterion) {
	let test_io = TestIO::new("");
	let mut xb = XBasic::new(test_io);
	c.bench_function("fib 20", |b| {
		b.iter(|| {
			xb.run(
				"
fib(20)

function fib(n)
    if n < 2 then
        return n
    end if
    return fib(n - 1) + fib(n - 2)
end function
			",
			)
		})
	});
}

criterion_group!(benches, recursive_benchmark);
criterion_main!(benches);