MCPcopy Create free account
hub / github.com/buke/quickjs-go / TestValueProperties

Function TestValueProperties

value_test.go:1189–1242  ·  view source on GitHub ↗

TestValueProperties tests property operations

(t *testing.T)

Source from the content-addressed store, hash-verified

1187
1188// TestValueProperties tests property operations
1189func TestValueProperties(t *testing.T) {
1190 useStableOwnerHooksForLegacySubtests(t)
1191
1192 rt := NewRuntime()
1193 defer rt.Close()
1194 ctx := rt.NewContext()
1195 defer ctx.Close()
1196
1197 // Updated to use New* methods
1198 obj := ctx.NewObject()
1199 defer obj.Free()
1200
1201 // Test basic property operations
1202 obj.Set("name", ctx.NewString("test"))
1203 obj.Set("value", ctx.NewInt32(42))
1204
1205 require.True(t, obj.Has("name"))
1206 require.False(t, obj.Has("nonexistent"))
1207
1208 nameVal := obj.Get("name")
1209 defer nameVal.Free()
1210 require.Equal(t, "test", nameVal.String())
1211
1212 require.True(t, obj.Delete("value"))
1213 require.False(t, obj.Delete("nonexistent"))
1214
1215 // Test indexed operations
1216 obj.SetIdx(0, ctx.NewString("index0"))
1217 require.True(t, obj.HasIdx(0))
1218 require.False(t, obj.HasIdx(99))
1219
1220 idx0Val := obj.GetIdx(0)
1221 defer idx0Val.Free()
1222 require.Equal(t, "index0", idx0Val.String())
1223
1224 require.True(t, obj.DeleteIdx(0))
1225 require.False(t, obj.DeleteIdx(99))
1226
1227 // Test PropertyNames
1228 obj.Set("a", ctx.NewString("value_a"))
1229 obj.Set("b", ctx.NewString("value_b"))
1230
1231 names, err := obj.PropertyNames()
1232 require.NoError(t, err)
1233 require.Contains(t, names, "a")
1234 require.Contains(t, names, "b")
1235
1236 // Test PropertyNames error case
1237 str := ctx.NewString("test")
1238 defer str.Free()
1239 _, err = str.PropertyNames()
1240 require.Error(t, err)
1241 require.Contains(t, err.Error(), "value does not contain properties")
1242}
1243
1244// TestValueFunctionCalls tests function calls and constructors
1245func TestValueFunctionCalls(t *testing.T) {

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
NewContextMethod · 0.95
CloseMethod · 0.95
NewObjectMethod · 0.95
NewStringMethod · 0.95
NewInt32Method · 0.95
NewRuntimeFunction · 0.85
SetMethod · 0.80
HasMethod · 0.80
GetMethod · 0.80
EqualMethod · 0.80

Tested by

no test coverage detected