1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-12 20:27:30 +08:00
otto/otto_error_test.go
Steven Hartland a3b51c68f2
chore: enable whitespace linter and fix errors (#456)
Enable the whitespace linter and fix the errors resulting from it.

Also:
* Remove unneeded golangci-lint config for disabled linters.
* Correct test number for panic in previous commit.
2022-11-26 13:33:09 +00:00

48 lines
913 B
Go

package otto
import (
"testing"
)
func TestOttoError(t *testing.T) {
tt(t, func() {
vm := New()
_, err := vm.Run(`throw "Xyzzy"`)
is(err, "Xyzzy")
_, err = vm.Run(`throw new TypeError()`)
is(err, "TypeError")
_, err = vm.Run(`throw new TypeError("Nothing happens.")`)
is(err, "TypeError: Nothing happens.")
_, err = ToValue([]byte{})
is(err, "TypeError: invalid value (slice): missing runtime: [] ([]uint8)")
_, err = vm.Run(`
(function(){
return abcdef.length
})()
`)
is(err, "ReferenceError: 'abcdef' is not defined")
_, err = vm.Run(`
function start() {
}
start()
xyzzy()
`)
is(err, "ReferenceError: 'xyzzy' is not defined")
_, err = vm.Run(`
// Just a comment
xyzzy
`)
is(err, "ReferenceError: 'xyzzy' is not defined")
})
}