MCPcopy
hub / github.com/cortexlabs/cortex / TestObj

Function TestObj

pkg/lib/strings/stringify_test.go:56–257  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

54func (t Test3) Test() {}
55
56func TestObj(t *testing.T) {
57 var a interface{}
58 require.Equal(t, "<null>", Obj(a))
59 var b []string
60 require.Equal(t, "<null>", Obj(b))
61 var c *string
62 require.Equal(t, "<null>", Obj(c))
63
64 require.Equal(t, "true", Obj(true))
65 require.Equal(t, "2.2", Obj(float32(2.2)))
66 require.Equal(t, "2.0", Obj(float32(2)))
67 require.Equal(t, "2.0", Obj(float64(2)))
68 require.Equal(t, "3", Obj(int(3)))
69 require.Equal(t, "3", Obj(pointer.Int(3)))
70 require.Equal(t, "-3", Obj(int8(-3)))
71 require.Equal(t, "3", Obj(int16(3)))
72 require.Equal(t, "-3", Obj(int32(-3)))
73 require.Equal(t, "3", Obj(int64(3)))
74 require.Equal(t, "4", Obj(int(4)))
75 require.Equal(t, "4", Obj(int8(4)))
76 require.Equal(t, "4", Obj(int16(4)))
77 require.Equal(t, "4", Obj(int32(4)))
78 require.Equal(t, "4", Obj(int64(4)))
79 require.Equal(t, `""`, Obj(""))
80 require.Equal(t, `"test"`, Obj("test"))
81 require.Equal(t, `"test"`, Obj(pointer.String("test")))
82
83 var myFloat MyFloat = 2
84 require.Equal(t, "2.0", Obj(myFloat))
85 var myString MyString = "test"
86 require.Equal(t, `"test"`, Obj(myString))
87
88 strSlice := []string{"a", "b", "c"}
89 require.Equal(t, `["a", "b", "c"]`, ObjFlat(strSlice))
90 require.Equal(t, `["a", "b", "c"]`, ObjFlat(&strSlice))
91 intSlice := []int8{1, 2, 3}
92 require.Equal(t, `[1, 2, 3]`, ObjFlat(intSlice))
93 mixedSlice := []interface{}{int(1), float64(2), "three", ""}
94 require.Equal(t, `[1, 2.0, "three", ""]`, ObjFlat(mixedSlice))
95 nestedSlice := []interface{}{int(1), "three", strSlice, []interface{}{"a", []float64{1, 2.2}}}
96 require.Equal(t, `[1, "three", ["a", "b", "c"], ["a", [1.0, 2.2]]]`, ObjFlat(nestedSlice))
97
98 strMap := map[string]string{"b": "y", "a": "x"}
99 require.Equal(t, `{"a": "x", "b": "y"}`, ObjFlat(strMap))
100 require.Equal(t, `{"a": "x", "b": "y"}`, ObjFlat(&strMap))
101 mixedMap := map[interface{}]interface{}{"1": "a", true: strMap, int(3): strSlice}
102 require.Equal(t, `{"1": "a", 3: ["a", "b", "c"], true: {"a": "x", "b": "y"}}`, ObjFlat(mixedMap))
103
104 myNested := MyNested{myFloat: []MyString{myString, myString}}
105 require.Equal(t, `{2.0: ["test", "test"]}`, ObjFlat(myNested))
106
107 emptyMap := map[interface{}]interface{}{}
108 require.Equal(t, `{}`, Obj(emptyMap))
109 require.Equal(t, `{}`, ObjFlat(emptyMap))
110
111 emptyCollectionsInMap := map[interface{}]interface{}{"empty_map": map[interface{}]interface{}{}, "a": "b", "empty_slice": []interface{}{}}
112 require.Equal(t, `{"a": "b", "empty_map": {}, "empty_slice": []}`, ObjFlat(emptyCollectionsInMap))
113 require.Equal(t, `{

Callers

nothing calls this directly

Calls 6

IntFunction · 0.92
StringFunction · 0.92
Float64Function · 0.92
ObjFunction · 0.85
ObjFlatFunction · 0.85
EqualMethod · 0.80

Tested by

no test coverage detected