xgo/runtime/vm_boolean_test.go
Daniel 3500c686b3
Improvements on compiler/VM error reporting (filename:line:col)
- add type infos to VM error messages
- add 'Name' to UserFunction objects 
- add 'expectErrorString' to VM tests
- replace vm.expectError() with vm.expectErrorString() to make it more explicit
- add source map info to VM error messages
- optimization in function calls
- add file/line/col info to compiler errors
- change stdlib module to be loaded from VM (instead of compiler) so they can be properly loaded after the source is compiled into binary
- VM can take builtin modules optionally
2019-02-20 16:26:11 -08:00

55 lines
1.6 KiB
Go

package runtime_test
import (
"testing"
)
func TestBoolean(t *testing.T) {
expect(t, `out = true`, true)
expect(t, `out = false`, false)
expect(t, `out = 1 < 2`, true)
expect(t, `out = 1 > 2`, false)
expect(t, `out = 1 < 1`, false)
expect(t, `out = 1 > 2`, false)
expect(t, `out = 1 == 1`, true)
expect(t, `out = 1 != 1`, false)
expect(t, `out = 1 == 2`, false)
expect(t, `out = 1 != 2`, true)
expect(t, `out = 1 <= 2`, true)
expect(t, `out = 1 >= 2`, false)
expect(t, `out = 1 <= 1`, true)
expect(t, `out = 1 >= 2`, false)
expect(t, `out = true == true`, true)
expect(t, `out = false == false`, true)
expect(t, `out = true == false`, false)
expect(t, `out = true != false`, true)
expect(t, `out = false != true`, true)
expect(t, `out = (1 < 2) == true`, true)
expect(t, `out = (1 < 2) == false`, false)
expect(t, `out = (1 > 2) == true`, false)
expect(t, `out = (1 > 2) == false`, true)
expectError(t, `5 + true`, "invalid operation")
expectError(t, `5 + true; 5`, "invalid operation")
expectError(t, `-true`, "invalid operation")
expectError(t, `true + false`, "invalid operation")
expectError(t, `5; true + false; 5`, "invalid operation")
expectError(t, `if (10 > 1) { true + false; }`, "invalid operation")
expectError(t, `
func() {
if (10 > 1) {
if (10 > 1) {
return true + false;
}
return 1;
}
}()
`, "invalid operation")
expectError(t, `if (true + false) { 10 }`, "invalid operation")
expectError(t, `10 + (true + false)`, "invalid operation")
expectError(t, `(true + false) + 20`, "invalid operation")
expectError(t, `!(true + false)`, "invalid operation")
}