1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-19 19:55:30 +08:00
otto/object_test.go
2013-05-02 21:06:22 +02:00

65 lines
1.2 KiB
Go

package otto
import (
. "./terst"
"testing"
)
func TestObject_(t *testing.T) {
Terst(t)
object := newObject(nil, "")
IsTrue(object != nil)
object.put("xyzzy", toValue("Nothing happens."), true)
Is(object.get("xyzzy"), "Nothing happens.")
}
func TestStringObject(t *testing.T) {
Terst(t)
object := New().runtime.newStringObject(toValue("xyzzy"))
Is(object.get("1"), "y")
Is(object.get("10"), "undefined")
Is(object.get("2"), "z")
}
func TestObject_getPrototypeOf(t *testing.T) {
Terst(t)
test := runTest()
test(`
abc = {};
def = Object.getPrototypeOf(abc);
ghi = Object.getPrototypeOf(def);
[abc,def,ghi,ghi+""];
`, "[object Object],[object Object],,null")
}
func TestObject_new(t *testing.T) {
Terst(t)
test := runTest()
test(`
[ new Object("abc"), new Object(2+2) ];
`, "abc,4")
}
func TestObject_toLocaleString(t *testing.T) {
Terst(t)
test := runTest()
test(`
({}).toLocaleString();
`, "[object Object]")
test(`
object = {
toString: function() {
return "Nothing happens.";
}
};
object.toLocaleString();
`, "Nothing happens.")
}