2019-01-11 13:27:28 +03:00
|
|
|
package runtime_test
|
2019-01-09 10:17:42 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBoolean(t *testing.T) {
|
2019-03-18 18:15:26 +03:00
|
|
|
expect(t, `out = true`, nil, true)
|
|
|
|
expect(t, `out = false`, nil, false)
|
2019-01-09 10:17:42 +03:00
|
|
|
|
2019-03-18 18:15:26 +03:00
|
|
|
expect(t, `out = 1 < 2`, nil, true)
|
|
|
|
expect(t, `out = 1 > 2`, nil, false)
|
|
|
|
expect(t, `out = 1 < 1`, nil, false)
|
|
|
|
expect(t, `out = 1 > 2`, nil, false)
|
|
|
|
expect(t, `out = 1 == 1`, nil, true)
|
|
|
|
expect(t, `out = 1 != 1`, nil, false)
|
|
|
|
expect(t, `out = 1 == 2`, nil, false)
|
|
|
|
expect(t, `out = 1 != 2`, nil, true)
|
|
|
|
expect(t, `out = 1 <= 2`, nil, true)
|
|
|
|
expect(t, `out = 1 >= 2`, nil, false)
|
|
|
|
expect(t, `out = 1 <= 1`, nil, true)
|
|
|
|
expect(t, `out = 1 >= 2`, nil, false)
|
2019-01-09 10:17:42 +03:00
|
|
|
|
2019-03-18 18:15:26 +03:00
|
|
|
expect(t, `out = true == true`, nil, true)
|
|
|
|
expect(t, `out = false == false`, nil, true)
|
|
|
|
expect(t, `out = true == false`, nil, false)
|
|
|
|
expect(t, `out = true != false`, nil, true)
|
|
|
|
expect(t, `out = false != true`, nil, true)
|
|
|
|
expect(t, `out = (1 < 2) == true`, nil, true)
|
|
|
|
expect(t, `out = (1 < 2) == false`, nil, false)
|
|
|
|
expect(t, `out = (1 > 2) == true`, nil, false)
|
|
|
|
expect(t, `out = (1 > 2) == false`, nil, true)
|
2019-01-16 23:23:20 +03:00
|
|
|
|
2019-03-18 18:15:26 +03:00
|
|
|
expectError(t, `5 + true`, nil, "invalid operation")
|
|
|
|
expectError(t, `5 + true; 5`, nil, "invalid operation")
|
|
|
|
expectError(t, `-true`, nil, "invalid operation")
|
|
|
|
expectError(t, `true + false`, nil, "invalid operation")
|
|
|
|
expectError(t, `5; true + false; 5`, nil, "invalid operation")
|
|
|
|
expectError(t, `if (10 > 1) { true + false; }`, nil, "invalid operation")
|
2019-01-16 23:23:20 +03:00
|
|
|
expectError(t, `
|
2019-02-21 03:26:11 +03:00
|
|
|
func() {
|
2019-01-16 23:23:20 +03:00
|
|
|
if (10 > 1) {
|
2019-02-21 03:26:11 +03:00
|
|
|
if (10 > 1) {
|
|
|
|
return true + false;
|
|
|
|
}
|
2019-01-16 23:23:20 +03:00
|
|
|
|
2019-02-21 03:26:11 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}()
|
2019-03-18 18:15:26 +03:00
|
|
|
`, nil, "invalid operation")
|
|
|
|
expectError(t, `if (true + false) { 10 }`, nil, "invalid operation")
|
|
|
|
expectError(t, `10 + (true + false)`, nil, "invalid operation")
|
|
|
|
expectError(t, `(true + false) + 20`, nil, "invalid operation")
|
|
|
|
expectError(t, `!(true + false)`, nil, "invalid operation")
|
2019-01-09 10:17:42 +03:00
|
|
|
}
|