Debian Codegraph @

model/orderedmap/map_test.go

raw symbols SCIP
1 package orderedmap_testscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap_test`/
2
3 import (
4 "testingscip-go gomod github.com/golang/go/src go1.25 testing/"
5
6 "github.com/tomwright/dasel/v3/model/orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/"
7 )
8
9 func TestNewMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap_test`/TestNewMap().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) {
10 m := orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.NewMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/NewMap().()
11 if m.Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Len().() != 0 {
12 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("expected Len 0, got %d", m.Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Len().())
13 }
14 if len(m.Keysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Keys().()) != 0 {
15 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().("expected empty keys")
16 }
17 }
18
19 func TestSetGetscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap_test`/TestSetGet().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) {
20 m := orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.NewMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/NewMap().()
21 m.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("a", 1)
22
23 v, ok := m.Getscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Get().("a")
24 if !ok {
25 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().("expected key a to exist")
26 }
27 if v != 1 {
28 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("expected 1, got %v", v)
29 }
30
31 // Missing key.
32 _, ok = m.Getscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Get().("missing")
33 if ok {
34 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().("expected key missing to not exist")
35 }
36 }
37
38 func TestSetOverwritescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap_test`/TestSetOverwrite().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) {
39 m := orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.NewMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/NewMap().()
40 m.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("a", 1)
41 m.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("a", 2)
42
43 v, _ := m.Getscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Get().("a")
44 if v != 2 {
45 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("expected 2, got %v", v)
46 }
47 // Overwrite must not duplicate the key.
48 if m.Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Len().() != 1 {
49 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("expected Len 1, got %d", m.Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Len().())
50 }
51 }
52
53 func TestDeletescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap_test`/TestDelete().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) {
54 m := orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.NewMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/NewMap().()
55 m.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("a", 1)
56 m.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("b", 2)
57 m.Deletescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Delete().("a")
58
59 _, ok := m.Getscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Get().("a")
60 if ok {
61 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().("expected key a to be deleted")
62 }
63 if m.Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Len().() != 1 {
64 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("expected Len 1, got %d", m.Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Len().())
65 }
66 keys := m.Keysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Keys().()
67 if len(keys) != 1 || keys[0] != "b" {
68 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("expected keys [b], got %v", keys)
69 }
70 }
71
72 func TestDeleteNonExistentscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap_test`/TestDeleteNonExistent().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) {
73 m := orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.NewMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/NewMap().()
74 m.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("a", 1)
75 m.Deletescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Delete().("nope") // no-op
76 if m.Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Len().() != 1 {
77 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("expected Len 1, got %d", m.Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Len().())
78 }
79 }
80
81 func TestLenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap_test`/TestLen().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) {
82 m := orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.NewMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/NewMap().()
83 if m.Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Len().() != 0 {
84 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("expected 0, got %d", m.Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Len().())
85 }
86 m.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("a", 1)
87 m.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("b", 2)
88 if m.Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Len().() != 2 {
89 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("expected 2, got %d", m.Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Len().())
90 }
91 m.Deletescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Delete().("a")
92 if m.Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Len().() != 1 {
93 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("expected 1, got %d", m.Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Len().())
94 }
95 }
96
97 func TestKeysOrderscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap_test`/TestKeysOrder().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) {
98 m := orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.NewMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/NewMap().()
99 m.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("c", 3)
100 m.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("a", 1)
101 m.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("b", 2)
102
103 keys := m.Keysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Keys().()
104 expected := []string{"c", "a", "b"}
105 if len(keys) != len(expected) {
106 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("expected %v, got %v", expected, keys)
107 }
108 for i, k := range expected {
109 if keys[i] != k {
110 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("expected key %d to be %s, got %s", i, k, keys[i])
111 }
112 }
113 }
114
115 func TestKeyValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap_test`/TestKeyValues().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) {
116 m := orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.NewMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/NewMap().()
117 m.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("x", 10)
118 m.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("y", 20)
119
120 kvs := m.KeyValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#KeyValues().()
121 if len(kvs) != 2 {
122 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("expected 2 pairs, got %d", len(kvs))
123 }
124 if kvs[0].Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/KeyValue#Key. != "x" || kvs[0].Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/KeyValue#Value. != 10 {
125 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("unexpected first pair: %v", kvs[0])
126 }
127 if kvs[1].Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/KeyValue#Key. != "y" || kvs[1].Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/KeyValue#Value. != 20 {
128 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("unexpected second pair: %v", kvs[1])
129 }
130 }
131
132 func TestEqualscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap_test`/TestEqual().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) {
133 a := orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.NewMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/NewMap().()
134 a.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("x", 1)
135 a.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("y", 2)
136
137 b := orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.NewMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/NewMap().()
138 b.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("x", 1)
139 b.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("y", 2)
140
141 if !a.Equalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Equal().(b) {
142 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().("expected maps to be equal")
143 }
144
145 // Different value.
146 c := orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.NewMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/NewMap().()
147 c.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("x", 1)
148 c.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("y", 99)
149 if a.Equalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Equal().(c) {
150 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().("expected maps to not be equal (different value)")
151 }
152
153 // Different key order.
154 d := orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.NewMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/NewMap().()
155 d.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("y", 2)
156 d.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("x", 1)
157 if a.Equalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Equal().(d) {
158 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().("expected maps to not be equal (different order)")
159 }
160
161 // Different length.
162 e := orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.NewMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/NewMap().()
163 e.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("x", 1)
164 if a.Equalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Equal().(e) {
165 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().("expected maps to not be equal (different length)")
166 }
167 }
168
169 func TestFromMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap_test`/TestFromMap().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) {
170 src := map[string]any{"a": 1, "b": 2, "c": 3}
171 m := orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.FromMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/FromMap().(src)
172
173 if m.Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Len().() != 3 {
174 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("expected Len 3, got %d", m.Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Len().())
175 }
176 for k, v := range src {
177 got, ok := m.Getscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Get().(k)
178 if !ok {
179 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("expected key %s to exist", k)
180 }
181 if got != v {
182 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("expected %v for key %s, got %v", v, k, got)
183 }
184 }
185 }
186
187 func TestUnorderedDatascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap_test`/TestUnorderedData().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) {
188 m := orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.NewMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/NewMap().()
189 m.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("a", 1)
190 m.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().("b", 2)
191
192 data := m.UnorderedDatascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#UnorderedData().()
193 if len(data) != 2 {
194 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("expected 2 entries, got %d", len(data))
195 }
196 if data["a"] != 1 || data["b"] != 2 {
197 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("unexpected data: %v", data)
198 }
199 }