Skip to content

Commit 031ad85

Browse files
committed
add List tests
1 parent 7ab92b1 commit 031ad85

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

list_test.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package gp
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestMakeList(t *testing.T) {
8+
tests := []struct {
9+
name string
10+
args []any
11+
wantLen int
12+
wantVals []any
13+
}{
14+
{
15+
name: "empty list",
16+
args: []any{},
17+
wantLen: 0,
18+
wantVals: []any{},
19+
},
20+
{
21+
name: "integers",
22+
args: []any{1, 2, 3},
23+
wantLen: 3,
24+
wantVals: []any{1, 2, 3},
25+
},
26+
{
27+
name: "mixed types",
28+
args: []any{1, "hello", 3.14},
29+
wantLen: 3,
30+
wantVals: []any{1, "hello", 3.14},
31+
},
32+
}
33+
34+
for _, tt := range tests {
35+
t.Run(tt.name, func(t *testing.T) {
36+
list := MakeList(tt.args...)
37+
38+
if got := list.Len(); got != tt.wantLen {
39+
t.Errorf("MakeList() len = %v, want %v", got, tt.wantLen)
40+
}
41+
42+
for i, want := range tt.wantVals {
43+
got := list.GetItem(i).String()
44+
if got != From(want).String() {
45+
t.Errorf("MakeList() item[%d] = %v, want %v", i, got, want)
46+
}
47+
}
48+
})
49+
}
50+
}
51+
52+
func TestList_SetItem(t *testing.T) {
53+
list := MakeList(1, 2, 3)
54+
list.SetItem(1, From("test"))
55+
56+
// Get the raw value without quotes for comparison
57+
got := list.GetItem(1).String()
58+
59+
if got != "test" {
60+
t.Errorf("List.SetItem() = %v, want %v", got, "test")
61+
}
62+
}
63+
64+
func TestList_Append(t *testing.T) {
65+
list := MakeList(1, 2)
66+
initialLen := list.Len()
67+
68+
list.Append(From(3))
69+
70+
if got := list.Len(); got != initialLen+1 {
71+
t.Errorf("List.Append() length = %v, want %v", got, initialLen+1)
72+
}
73+
74+
if got := list.GetItem(2).String(); got != From(3).String() {
75+
t.Errorf("List.Append() last item = %v, want %v", got, From(3).String())
76+
}
77+
}
78+
79+
func TestList_Len(t *testing.T) {
80+
tests := []struct {
81+
name string
82+
args []any
83+
want int
84+
}{
85+
{"empty list", []any{}, 0},
86+
{"single item", []any{1}, 1},
87+
{"multiple items", []any{1, 2, 3}, 3},
88+
}
89+
90+
for _, tt := range tests {
91+
t.Run(tt.name, func(t *testing.T) {
92+
list := MakeList(tt.args...)
93+
if got := list.Len(); got != tt.want {
94+
t.Errorf("List.Len() = %v, want %v", got, tt.want)
95+
}
96+
})
97+
}
98+
}

0 commit comments

Comments
 (0)