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

Function TestGoMapReflectKeyToString

object_gomap_reflect_test.go:313–350  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

311}
312
313func 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}

Callers

nothing calls this directly

Calls 7

NewFunction · 0.85
asciiStringTypeAlias · 0.85
ToValueMethod · 0.80
ToObjectMethod · 0.65
KeysMethod · 0.65
stringKeysMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…