1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-19 19:55:30 +08:00
otto/otto_error_test.go
Robert Krimen ad8a97c028 New parser
* Faster, more straightforward, etc.
* More advanced object literals (get ..., set ...)
* More tests using JavaScript from the wild (http://cdnjs.com/)
2014-04-10 20:42:25 -07:00

50 lines
790 B
Go

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