Skip to content

Commit 2b82584

Browse files
committed
cue: prepare TestConjunctDedup for more cases
Issue #3847 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: Ic9246e063f31c3d2a183a589b8e07b828ac5a25b Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1212213 Reviewed-by: Matthew Sackman <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 6912a11 commit 2b82584

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

cue/types_test.go

+31-27
Original file line numberDiff line numberDiff line change
@@ -2408,41 +2408,45 @@ func TestUnifyAccept(t *testing.T) {
24082408
//
24092409
// Issue #3829
24102410
func TestConjunctDedup(t *testing.T) {
2411-
const str = `
2412-
#t: {} | {f1: int}
2413-
#t: {f: string}
2414-
`
2415-
2416-
const want = `
2417-
{
2411+
type testCase struct {
2412+
value string
2413+
want string
2414+
}
2415+
testCases := []testCase{{
2416+
value: `
2417+
#t: {} | {f1: int}
2418+
#t: {f: string}
2419+
`,
2420+
want: `{
24182421
f: string
24192422
} | {
24202423
f1: int
24212424
f: string
2422-
}
2423-
`
2424-
2425-
cuetdtest.FullMatrix.Run(t, "test", func(t *testing.T, m *cuetdtest.M) {
2426-
ctx := m.CueContext()
2427-
tPath := cue.MakePath(cue.Def("#t"))
2428-
vOrig := ctx.CompileString(str).LookupPath(tPath)
2425+
}`,
2426+
}}
24292427

2430-
if err := vOrig.Err(); err != nil {
2431-
t.Fatal(err)
2432-
}
2428+
matrix := cuetdtest.FullMatrix
2429+
matrix.Do(t, func(t *testing.T, m *cuetdtest.M) {
2430+
tdtest.Run(t, testCases, func(t *cuetest.T, tc *testCase) {
2431+
ctx := m.CueContext()
2432+
tPath := cue.MakePath(cue.Def("#t"))
2433+
vOrig := ctx.CompileString(tc.value).LookupPath(tPath)
24332434

2434-
_, args := vOrig.Expr()
2435+
if err := vOrig.Err(); err != nil {
2436+
t.Fatal(err)
2437+
}
24352438

2436-
var v cue.Value
2437-
v = v.UnifyAccept(args[0], vOrig)
2438-
v = v.UnifyAccept(args[1], vOrig)
2439+
_, args := vOrig.Expr()
24392440

2440-
if err := v.Err(); err != nil {
2441-
t.Fatal(errors.Details(v.Err(), nil))
2442-
}
2443-
if got := fmt.Sprint(v); got != strings.TrimSpace(want) {
2444-
t.Errorf("got %s; want %s", got, want)
2445-
}
2441+
var v cue.Value
2442+
for _, a := range args {
2443+
v = v.UnifyAccept(a, vOrig)
2444+
if err := v.Err(); err != nil {
2445+
t.Fatal(errors.Details(v.Err(), nil))
2446+
}
2447+
}
2448+
t.Equal(fmt.Sprint(v), tc.want)
2449+
})
24462450
})
24472451
}
24482452

0 commit comments

Comments
 (0)