1
0
mirror of https://github.com/robertkrimen/otto synced 2025-09-28 18:45:22 +08:00
otto/otto_error_test.go
Robert Krimen c6e45a7118 Change getIdentifierReference to accept a node argument
To track/report where errors are coming from
2012-10-09 17:26:08 -07:00

50 lines
833 B
Go

package otto
import (
"testing"
. "github.com/robertkrimen/terst"
)
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: Unable to convert value: [] ([]uint8)")
_, err = Otto.Run(`
(function(){
return abcdef.length
})()
`)
Is(err, "ReferenceError: abcdef is not defined (line 3)")
_, err = Otto.Run(`
function start() {
}
start()
xyzzy()
`)
Is(err, "ReferenceError: xyzzy is not defined (line 7)")
_, err = Otto.Run(`
// Just a comment
xyzzy
`)
Is(err, "ReferenceError: xyzzy is not defined (line 4)")
}