Skip to content

Commit 6b80a11

Browse files
committed
Add tests for stable ordering
Signed-off-by: Graham Dennis <[email protected]>
1 parent b8f87dc commit 6b80a11

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

Diff for: cue/errors/errors_test.go

+34-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package errors
1717
import (
1818
"bytes"
1919
"fmt"
20+
"slices"
2021
"testing"
2122

2223
"cuelang.org/go/cue/token"
@@ -79,14 +80,44 @@ func TestErrorList_Sort(t *testing.T) {
7980
}
8081

8182
func TestErrorList_RemoveMultiples(t *testing.T) {
83+
error1 := Promote(fmt.Errorf("error1"), "msg1")
84+
error2 := Promote(fmt.Errorf("error2"), "msg2")
85+
8286
tests := []struct {
8387
name string
84-
p *list
88+
p list
89+
want list
8590
}{
86-
// TODO: Add test cases.
91+
{
92+
name: "SingleError",
93+
p: list{error1},
94+
want: list{error1},
95+
},
96+
{
97+
name: "TwoErrorsNoDuplicatesOrder12",
98+
p: list{error1, error2},
99+
want: list{error1, error2},
100+
},
101+
{
102+
name: "TwoErrorsNoDuplicatesOrder21",
103+
p: list{error2, error1},
104+
want: list{error2, error1},
105+
},
106+
{
107+
name: "TwoErrorsDuplicates",
108+
p: list{error1, error1},
109+
want: list{error1},
110+
},
111+
{
112+
name: "ThreeErrorsPreserveOrder",
113+
p: list{error1, error2, error1},
114+
want: list{error1, error2},
115+
},
87116
}
88117
for _, tt := range tests {
89-
tt.p.RemoveMultiples()
118+
if got := tt.p.RemoveMultiples(); !slices.Equal(got, tt.want) {
119+
t.Errorf("%q. list.RemoveMultiples() list = %v, want = %v", tt.name, got, tt.want)
120+
}
90121
}
91122
}
92123

0 commit comments

Comments
 (0)