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
mod common;

// Tests all the example code in the README file

#[test]
fn readme_printing() {
	common::test_program(
		"
print \"hello world\" // \"hello world\"
print \"hello\" \"world\" // hello world
print 5 \"+\" 3 \"=\" 5 + 3 // \"5 + 3 = 8\"
",
		"hello world\nhello world\n5 + 3 = 8\n",
	);
}

#[test]
fn readme_variables() {
	common::test_program(
		"
a = 3
print a // \"3\"
print b // \"0\"
	",
		"3\n0\n",
	);
}

#[test]
fn readme_comparisons() {
	common::test_program(
		"
a = 3
print a = 3 // \"true\"
print not a = 3 // \"false\"
print a < 3 // \"false\"
print a > 3 // \"false\"
print a <= 3 // \"true\"
print a >= 3 // \"true\"
    ",
		"true\nfalse\nfalse\nfalse\ntrue\ntrue\n",
	);
}

#[test]
fn readme_if() {
	common::test_program(
		"
if 3 = 3 then
    print \"hello world\" // runs
end if

if not a then
    print \"hello world\" // runs, because a is implicitly 0
end if

if b = 2 then
elseif b = 3 then
elseif b = 4 then
else
end if
        ",
		"hello world\nhello world\n",
	);
}

#[test]
fn readme_while() {
	common::test_program(
		"
a = 0
while a < 10
    print a // prints 0 1 2 3 4 5 6 7 8 9, each on a newline
    a = a + 1
wend
        ",
		"0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n",
	);
}

#[test]
fn readme_for() {
	common::test_program(
		"
for x = 10 to 20
    print x // prints 10 11 12 13 14 15 16 17 18 19 20, each on a newline
next x
        ",
		"10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n",
	);
}

#[test]
fn readme_function() {
	common::test_program(
		"
print a(\"hello\", \"world\") // \"helloworld\"

function a(b, c)
    return b + c
end function
        ",
		"helloworld\n",
	);
}