Skip to content

Commit d730a9b

Browse files
committed
add kwargs test
1 parent 172edde commit d730a9b

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

kw_test.go

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package gp
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
)
7+
8+
func TestSplitArgs(t *testing.T) {
9+
tests := []struct {
10+
name string
11+
args []any
12+
wantTup Tuple
13+
wantKw KwArgs
14+
}{
15+
{
16+
name: "empty args",
17+
args: []any{},
18+
wantTup: MakeTuple(),
19+
wantKw: nil,
20+
},
21+
{
22+
name: "only positional args",
23+
args: []any{1, "two", 3.0},
24+
wantTup: MakeTuple(1, "two", 3.0),
25+
wantKw: nil,
26+
},
27+
{
28+
name: "with kwargs",
29+
args: []any{1, "two", KwArgs{"a": 1, "b": "test"}},
30+
wantTup: MakeTuple(1, "two"),
31+
wantKw: KwArgs{"a": 1, "b": "test"},
32+
},
33+
{
34+
name: "only kwargs",
35+
args: []any{KwArgs{"x": 10, "y": 20}},
36+
wantTup: MakeTuple(),
37+
wantKw: KwArgs{"x": 10, "y": 20},
38+
},
39+
}
40+
41+
for _, tt := range tests {
42+
t.Run(tt.name, func(t *testing.T) {
43+
gotTup, gotKw := splitArgs(tt.args...)
44+
45+
if !reflect.DeepEqual(gotTup, tt.wantTup) {
46+
t.Errorf("splitArgs() tuple = %v, want %v", gotTup, tt.wantTup)
47+
}
48+
49+
if !reflect.DeepEqual(gotKw, tt.wantKw) {
50+
t.Errorf("splitArgs() kwargs = %v, want %v", gotKw, tt.wantKw)
51+
}
52+
})
53+
}
54+
}
55+
56+
func TestKwArgs(t *testing.T) {
57+
kw := KwArgs{
58+
"name": "test",
59+
"age": 42,
60+
}
61+
62+
// Test type assertion
63+
if _, ok := interface{}(kw).(KwArgs); !ok {
64+
t.Error("KwArgs failed type assertion")
65+
}
66+
67+
// Test map operations
68+
kw["new"] = "value"
69+
if v, ok := kw["new"]; !ok || v != "value" {
70+
t.Error("KwArgs map operations failed")
71+
}
72+
}

0 commit comments

Comments
 (0)