(t *testing.T)
| 311 | } |
| 312 | |
| 313 | func TestGoMapReflectKeyToString(t *testing.T) { |
| 314 | vm := New() |
| 315 | |
| 316 | test := func(v any, t *testing.T) { |
| 317 | o1 := vm.ToValue(v).ToObject(vm) |
| 318 | keys := o1.Keys() |
| 319 | sort.Strings(keys) |
| 320 | if len(keys) != 2 || keys[0] != "1" || keys[1] != "2" { |
| 321 | t.Fatal(keys) |
| 322 | } |
| 323 | |
| 324 | keys1 := o1.self.stringKeys(true, nil) |
| 325 | sort.Slice(keys1, func(a, b int) bool { |
| 326 | return strings.Compare(keys1[a].String(), keys1[b].String()) < 0 |
| 327 | }) |
| 328 | if len(keys1) != 2 || keys1[0] != asciiString("1") || keys1[1] != asciiString("2") { |
| 329 | t.Fatal(keys1) |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | t.Run("int", func(t *testing.T) { |
| 334 | m1 := map[int]any{ |
| 335 | 1: 2, |
| 336 | 2: 3, |
| 337 | } |
| 338 | test(m1, t) |
| 339 | }) |
| 340 | |
| 341 | t.Run("CustomString", func(t *testing.T) { |
| 342 | type CustomString string |
| 343 | m2 := map[CustomString]any{ |
| 344 | "1": 2, |
| 345 | "2": 3, |
| 346 | } |
| 347 | test(m2, t) |
| 348 | }) |
| 349 | |
| 350 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…