| 241 | } |
| 242 | |
| 243 | func 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 | |
| 277 | type testStringerArray [8]byte |
| 278 | |