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