Skip to content

Commit

Permalink
cue: add tests for Unify
Browse files Browse the repository at this point in the history
We will soon make Unify use the implemenation in adt.
We add tests to track regressions and bug fixes.

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I90055337d2de9b26de28c61369dd47eb61a37adf
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1208486
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
mpvl committed Feb 7, 2025
1 parent 0e42b0b commit b582d7f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
68 changes: 66 additions & 2 deletions cue/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2098,7 +2098,11 @@ func TestUnify(t *testing.T) {
value string
pathA string
pathB string
pathC string
want string

skipv2 bool
skipv3 bool
}
testCases := []testCase{{
value: `4`,
Expand Down Expand Up @@ -2148,14 +2152,74 @@ func TestUnify(t *testing.T) {
pathA: a,
pathB: "#B",
want: `{}`,
}, {
skipv3: true,

value: `
a: obj: initialField: "foo"
a: #x
#x: obj?: _
b: obj: extraField: "bar"
`,
pathA: a,
pathB: b,
want: `{"obj":{"initialField":"foo","extraField":"bar"}}`,
}, {
value: `
a: obj: initialField: "foo"
a: #x
#x: obj?: {...}
b: obj: extraField: "bar"
`,
pathA: a,
pathB: b,
want: `{"obj":{"initialField":"foo","extraField":"bar"}}`,
}, {
skipv2: true,
skipv3: true,

value: `
a: obj: initialField: "foo"
#x: obj?: _
b: obj: extraField: "bar"
`,
pathA: a,
pathB: "#x",
pathC: b,
want: `{"obj":{"initialField":"foo","extraField":"bar"}}`,
}, {
value: `
a: obj: initialField: "foo"
#x: obj?: {...}
a: #x
b: extraField: "bar"
`,
pathA: "a.obj",
pathB: b,
want: `{"initialField":"foo","extraField":"bar"}`,
}}

matrix := cuetdtest.FullMatrix

// TODO(tdtest): use cuetest.Run when supported.
cuetdtest.FullMatrix.Do(t, func(t *testing.T, m *cuetdtest.M) {
matrix.Do(t, func(t *testing.T, m *cuetdtest.M) {
tdtest.Run(t, testCases, func(t *cuetest.T, tc *testCase) {
if tc.skipv2 {
m.TODO_V2(t)
}
if tc.skipv3 {
m.TODO_V3(t)
}

v := getValue(m, tc.value)
x := v.LookupPath(cue.ParsePath(tc.pathA))
y := v.LookupPath(cue.ParsePath(tc.pathB))
b, err := x.Unify(y).MarshalJSON()
x = x.Unify(y)
if tc.pathC != "" {
z := v.LookupPath(cue.ParsePath(tc.pathC))
x = x.Unify(z)
}
b, err := x.MarshalJSON()
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 6 additions & 0 deletions internal/cuetdtest/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ func (m Matrix) Do(t *testing.T, f func(t *testing.T, m *M)) {
}
}

func (m *M) TODO_V2(t testing.TB) {
if m.version == internal.DefaultVersion {
t.Skip("Skipping v2")
}
}

func (m *M) TODO_V3(t testing.TB) {
if m.version == internal.DevVersion {
t.Skip("Skipping v3")
Expand Down

0 comments on commit b582d7f

Please sign in to comment.