Added more tests

This commit is contained in:
2025-03-14 00:08:58 +01:00
parent ac14ab4f7a
commit 06f3af256b
6 changed files with 42 additions and 0 deletions

View File

@ -37,6 +37,8 @@ func (f *Function) CompileAssign(node *ast.Assign) error {
switch leftValue := leftValue.(type) {
case *eval.Register:
// TODO: Reservation needs to be canceled on defer
f.CurrentScope().Reserve(leftValue.Register)
f.Execute(operation, leftValue.Register, right)
case *eval.Memory:
// TODO: Reservation needs to be canceled on defer

9
tests/programs/add.q Normal file
View File

@ -0,0 +1,9 @@
main() {
assert 0 + 0 == 0
assert 1 + 1 == 2
assert 1 + 2 == 3
assert 2 + 1 == 3
assert 2 + 2 == 4
assert 4 + 2 == 6
assert 8 + 2 == 10
}

9
tests/programs/div.q Normal file
View File

@ -0,0 +1,9 @@
main() {
assert 0 / 1 == 0
assert 1 / 1 == 1
assert 1 / 2 == 0
assert 2 / 1 == 2
assert 2 / 2 == 1
assert 4 / 2 == 2
assert 8 / 2 == 4
}

9
tests/programs/mul.q Normal file
View File

@ -0,0 +1,9 @@
main() {
assert 0 * 0 == 0
assert 1 * 1 == 1
assert 1 * 2 == 2
assert 2 * 1 == 2
assert 2 * 2 == 4
assert 4 * 2 == 8
assert 8 * 2 == 16
}

9
tests/programs/sub.q Normal file
View File

@ -0,0 +1,9 @@
main() {
assert 0 - 0 == 0
assert 1 - 1 == 0
assert 1 - 2 == -1
assert 2 - 1 == 1
assert 2 - 2 == 0
assert 4 - 2 == 2
assert 8 - 2 == 6
}

View File

@ -26,6 +26,10 @@ var programs = []struct {
{"reuse", 0},
{"return", 0},
{"return-multi", 0},
{"add", 0},
{"sub", 0},
{"mul", 0},
{"div", 0},
{"math", 0},
{"precedence", 0},
{"operator-number", 0},