5
5
)
6
6
7
7
func TestDictFromPairs (t * testing.T ) {
8
+ setupTest (t )
8
9
// Add panic test case
9
- t . Run ( "odd number of arguments" , func (t * testing. T ) {
10
+ func () {
10
11
defer func () {
11
12
if r := recover (); r == nil {
12
13
t .Errorf ("DictFromPairs() with odd number of arguments should panic" )
@@ -16,7 +17,7 @@ func TestDictFromPairs(t *testing.T) {
16
17
}()
17
18
18
19
DictFromPairs ("key1" , "value1" , "key2" ) // Should panic
19
- })
20
+ }( )
20
21
21
22
tests := []struct {
22
23
name string
@@ -39,23 +40,22 @@ func TestDictFromPairs(t *testing.T) {
39
40
}
40
41
41
42
for _ , tt := range tests {
42
- t .Run (tt .name , func (t * testing.T ) {
43
- dict := DictFromPairs (tt .pairs ... )
44
-
45
- // Verify each key-value pair
46
- for i := 0 ; i < len (tt .wantKeys ); i ++ {
47
- key := From (tt .wantKeys [i ])
48
- val := dict .Get (key )
49
- if ! ObjectsAreEqual (val , From (tt .wantVals [i ])) {
50
- t .Errorf ("DictFromPairs() got value %v for key %v, want %v" ,
51
- val , tt .wantKeys [i ], tt .wantVals [i ])
52
- }
43
+ dict := DictFromPairs (tt .pairs ... )
44
+
45
+ // Verify each key-value pair
46
+ for i := 0 ; i < len (tt .wantKeys ); i ++ {
47
+ key := From (tt .wantKeys [i ])
48
+ val := dict .Get (key )
49
+ if ! ObjectsAreEqual (val , From (tt .wantVals [i ])) {
50
+ t .Errorf ("DictFromPairs() got value %v for key %v, want %v" ,
51
+ val , tt .wantKeys [i ], tt .wantVals [i ])
53
52
}
54
- })
53
+ }
55
54
}
56
55
}
57
56
58
57
func TestMakeDict (t * testing.T ) {
58
+ setupTest (t )
59
59
tests := []struct {
60
60
name string
61
61
m map [any ]any
@@ -78,22 +78,21 @@ func TestMakeDict(t *testing.T) {
78
78
}
79
79
80
80
for _ , tt := range tests {
81
- t .Run (tt .name , func (t * testing.T ) {
82
- dict := MakeDict (tt .m )
83
-
84
- // Verify each key-value pair
85
- for k , v := range tt .m {
86
- key := From (k )
87
- got := dict .Get (key )
88
- if ! ObjectsAreEqual (got , From (v )) {
89
- t .Errorf ("MakeDict() got value %v for key %v, want %v" , got , k , v )
90
- }
81
+ dict := MakeDict (tt .m )
82
+
83
+ // Verify each key-value pair
84
+ for k , v := range tt .m {
85
+ key := From (k )
86
+ got := dict .Get (key )
87
+ if ! ObjectsAreEqual (got , From (v )) {
88
+ t .Errorf ("MakeDict() got value %v for key %v, want %v" , got , k , v )
91
89
}
92
- })
90
+ }
93
91
}
94
92
}
95
93
96
94
func TestDictSetGet (t * testing.T ) {
95
+ setupTest (t )
97
96
dict := DictFromPairs ()
98
97
99
98
// Test Set and Get
@@ -108,6 +107,7 @@ func TestDictSetGet(t *testing.T) {
108
107
}
109
108
110
109
func TestDictSetGetString (t * testing.T ) {
110
+ setupTest (t )
111
111
dict := DictFromPairs ()
112
112
113
113
// Test SetString and GetString
@@ -121,6 +121,7 @@ func TestDictSetGetString(t *testing.T) {
121
121
}
122
122
123
123
func TestDictDel (t * testing.T ) {
124
+ setupTest (t )
124
125
dict := DictFromPairs ("test_key" , "test_value" )
125
126
key := From ("test_key" )
126
127
@@ -141,6 +142,7 @@ func TestDictDel(t *testing.T) {
141
142
}
142
143
143
144
func TestDictForEach (t * testing.T ) {
145
+ setupTest (t )
144
146
dict := DictFromPairs (
145
147
"key1" , "value1" ,
146
148
"key2" , "value2" ,
0 commit comments