An xBASIC interpreter library written in Rust. xBASIC is a language loosely based off of QBasic.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Stephen 9d0e24c425 Added *= += -= /= ^= %= 18 hours ago
..
arithmetic.rs Added *= += -= /= ^= %= 18 hours ago
bedmas.rs Give IO ownership to XBasic object 4 days ago
call_function_from_rust.rs Give IO ownership to XBasic object 4 days ago
common.rs Give IO ownership to XBasic object 4 days ago
control.rs Give IO ownership to XBasic object 4 days ago
equality.rs Add string equality test 2 days ago
errors.rs Give IO ownership to XBasic object 4 days ago
functions.rs Give IO ownership to XBasic object 4 days ago
input.rs Give IO ownership to XBasic object 4 days ago
limits.rs Give IO ownership to XBasic object 4 days ago
literals.rs Escapeable literals 2 days ago
logical.rs Give IO ownership to XBasic object 4 days ago
misc.rs Fix comment on last line causing error 4 days ago
native_functions.rs Give IO ownership to XBasic object 4 days ago
readme.rs Comments and other small changes/improvements 4 weeks ago
std.rs Basic std(typeof) 2 weeks ago
unary.rs Give IO ownership to XBasic object 4 days ago
variables.rs Give IO ownership to XBasic object 4 days ago

readme.rs

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",
);
}