3500c686b3
- 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
22 lines
716 B
Go
22 lines
716 B
Go
package runtime_test
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestIncDec(t *testing.T) {
|
|
expect(t, `out++`, 1)
|
|
expect(t, `out--`, -1)
|
|
expect(t, `a := 0; a++; out = a`, 1)
|
|
expect(t, `a := 0; a++; a--; out = a`, 0)
|
|
|
|
// this seems strange but it works because 'a += b' is
|
|
// translated into 'a = a + b' and string type takes other types for + operator.
|
|
expect(t, `a := "foo"; a++; out = a`, "foo1")
|
|
expectError(t, `a := "foo"; a--`, "invalid operation")
|
|
|
|
expectError(t, `a++`, "unresolved reference") // not declared
|
|
expectError(t, `a--`, "unresolved reference") // not declared
|
|
//expectError(t, `a := 0; b := a++`) // inc-dec is statement not expression <- parser error
|
|
expectError(t, `4++`, "unresolved reference")
|
|
}
|