1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-12 20:27:30 +08:00
otto/otto_error_test.go
Robert Krimen 470b8c3b73 terst
* Update to latest github.com/robertkrimen/terst
* Clean up testing
2014-04-25 22:48:25 -07:00

49 lines
908 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")
})
}