Skip to content

Commit

Permalink
add kwargs test
Browse files Browse the repository at this point in the history
  • Loading branch information
cpunion committed Nov 3, 2024
1 parent 172edde commit d730a9b
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions kw_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package gp

import (
"reflect"
"testing"
)

func TestSplitArgs(t *testing.T) {
tests := []struct {
name string
args []any
wantTup Tuple
wantKw KwArgs
}{
{
name: "empty args",
args: []any{},
wantTup: MakeTuple(),
wantKw: nil,
},
{
name: "only positional args",
args: []any{1, "two", 3.0},
wantTup: MakeTuple(1, "two", 3.0),
wantKw: nil,
},
{
name: "with kwargs",
args: []any{1, "two", KwArgs{"a": 1, "b": "test"}},
wantTup: MakeTuple(1, "two"),
wantKw: KwArgs{"a": 1, "b": "test"},
},
{
name: "only kwargs",
args: []any{KwArgs{"x": 10, "y": 20}},
wantTup: MakeTuple(),
wantKw: KwArgs{"x": 10, "y": 20},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotTup, gotKw := splitArgs(tt.args...)

if !reflect.DeepEqual(gotTup, tt.wantTup) {
t.Errorf("splitArgs() tuple = %v, want %v", gotTup, tt.wantTup)
}

if !reflect.DeepEqual(gotKw, tt.wantKw) {
t.Errorf("splitArgs() kwargs = %v, want %v", gotKw, tt.wantKw)
}
})
}
}

func TestKwArgs(t *testing.T) {
kw := KwArgs{
"name": "test",
"age": 42,
}

// Test type assertion
if _, ok := interface{}(kw).(KwArgs); !ok {
t.Error("KwArgs failed type assertion")
}

// Test map operations
kw["new"] = "value"
if v, ok := kw["new"]; !ok || v != "value" {
t.Error("KwArgs map operations failed")
}
}

0 comments on commit d730a9b

Please sign in to comment.