MCPcopy Create free account
hub / github.com/dop251/goja / TestCopyOnChangeSort

Function TestCopyOnChangeSort

object_goarray_reflect_test.go:243–275  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

241}
242
243func TestCopyOnChangeSort(t *testing.T) {
244 a := []struct {
245 Test string
246 }{{"2"}, {"1"}}
247
248 vm := New()
249 vm.Set("a", &a)
250
251 _, err := vm.RunString(`
252 let a0 = a[0];
253 let a1 = a[1];
254 a.sort((a, b) => a.Test.localeCompare(b.Test));
255 if (a[0].Test !== "1") {
256 throw new Error("a[0]: " + a[0]);
257 }
258 if (a[1].Test !== "2") {
259 throw new Error("a[1]: " + a[1]);
260 }
261 if (a0 !== a[1]) {
262 throw new Error("a0 !== a[1]");
263 }
264 if (a1 !== a[0]) {
265 throw new Error("a1 !== a[0]");
266 }
267 `)
268 if err != nil {
269 t.Fatal(err)
270 }
271
272 if a[0].Test != "1" || a[1].Test != "2" {
273 t.Fatal(a)
274 }
275}
276
277type testStringerArray [8]byte
278

Callers

nothing calls this directly

Calls 3

NewFunction · 0.85
RunStringMethod · 0.80
SetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…