Skip to content

Commit

Permalink
tools/trim: convert inline tests to txtar
Browse files Browse the repository at this point in the history
txtar is the preferred mechanism for tests that drive cue.
Convert all existing trim tests to txtar.
The txtar tests run as part of the existing TestTrimFiles target
(renamed from TestData to be a little more descriptive).
Remove TestX because the TxTarTest code supports DebugArchive which
allows easy overriding for the purposes of experimentation.

Signed-off-by: Matthew Sackman <[email protected]>
Change-Id: I985f2e27b32fe01fb6b36b5e124cbb5c986c180e
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1197348
Reviewed-by: Daniel Martí <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
cuematthew committed Jul 8, 2024
1 parent 4eecacd commit 8079151
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 296 deletions.
8 changes: 8 additions & 0 deletions tools/trim/testdata/defaults_can_remove_non-defaults.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# TODO: make this optional
-- in.cue --
foo: [string]: a: *1 | int
foo: b: a: 1
-- out/trim --
== in.cue
foo: [string]: a: *1 | int
foo: b: {}
27 changes: 27 additions & 0 deletions tools/trim/testdata/do_not_overmark_comprehension.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- in.cue --
foo: multipath: {
t: [string]: { x: 5 }

// Don't remove u!
t: u: { x: 5 }
}

group: {
for k, v in foo {
comp: "\(k)": v
}
}
-- out/trim --
== in.cue
foo: multipath: {
t: [string]: {x: 5}

// Don't remove u!
t: u: {}
}

group: {
for k, v in foo {
comp: "\(k)": v
}
}
7 changes: 7 additions & 0 deletions tools/trim/testdata/do_not_remove_field.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- in.cue --
{[_]: x: "hello"}
a: x: "hello"
-- out/trim --
== in.cue
{[_]: x: "hello"}
a: {}
9 changes: 9 additions & 0 deletions tools/trim/testdata/issue303.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- in.cue --
foo: c: true
foo: #M
#M: c?: bool
-- out/trim --
== in.cue
foo: c: true
foo: #M
#M: c?: bool
15 changes: 15 additions & 0 deletions tools/trim/testdata/list_removal_1.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- in.cue --
service: [string]: {
ports: [{a: 1}, {a: 1}, ...{ extra: 3 }]
}
service: a: {
ports: [{a: 1}, {a: 1, extra: 3}, {}, { extra: 3 }]
}
-- out/trim --
== in.cue
service: [string]: {
ports: [{a: 1}, {a: 1}, ...{extra: 3}]
}
service: a: {
ports: [{}, {extra: 3}, {}, {}]
}
13 changes: 13 additions & 0 deletions tools/trim/testdata/list_removal_2.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- in.cue --
service: [string]: {
ports: [{a: 1}, {a: 1}, ...{ extra: 3 }]
}
service: a: {
ports: [{a: 1}, {a: 1,}]
}
-- out/trim --
== in.cue
service: [string]: {
ports: [{a: 1}, {a: 1}, ...{extra: 3}]
}
service: a: {}
23 changes: 23 additions & 0 deletions tools/trim/testdata/optional_does_not_remove_required.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- in.cue --
a: ["aFoo"]: 3
a: aFoo: _

a: {
{["aFoo"]: 3}
aFoo: _
}

["aFoo"]: 3
aFoo: _
-- out/trim --
== in.cue
a: ["aFoo"]: 3
a: aFoo: _

a: {
{["aFoo"]: 3}
aFoo: _
}

["aFoo"]: 3
aFoo: _
45 changes: 45 additions & 0 deletions tools/trim/testdata/remove_due_to_simplification.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- in.cue --
foo: [string]: {
t: [string]: {
x: >=0 & <=5
}
}

foo: multipath: {
t: [string]: {
// Combined with the other constraints, we know the value must be 5 and
// thus the entry below can be eliminated.
x: >=5 & <=8 & int
}

t: u: { x: 5 }
}

group: {
for k, v in foo {
comp: "\(k)": v
}
}
-- out/trim --
== in.cue
foo: [string]: {
t: [string]: {
x: >=0 & <=5
}
}

foo: multipath: {
t: [string]: {
// Combined with the other constraints, we know the value must be 5 and
// thus the entry below can be eliminated.
x: >=5 & <=8 & int
}

t: u: {}
}

group: {
for k, v in foo {
comp: "\(k)": v
}
}
18 changes: 18 additions & 0 deletions tools/trim/testdata/remove_implied_interpolations.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- in.cue --
foo: [string]: {
a: string
b: "--\(a)--"
}
foo: entry: {
a: "insert"
b: "--insert--"
}
-- out/trim --
== in.cue
foo: [string]: {
a: string
b: "--\(a)--"
}
foo: entry: {
a: "insert"
}
29 changes: 29 additions & 0 deletions tools/trim/testdata/remove_top-level_struct.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- in.cue --
a: b: 3
for k, v in a {
c: "\(k)": v
}
c: b: 3

z: {

a: b: 3
for k, v in a {
c: "\(k)": v
}
c: b: 3
}
-- out/trim --
== in.cue
a: b: 3
for k, v in a {
c: "\(k)": v
}

z: {

a: b: 3
for k, v in a {
c: "\(k)": v
}
}
Loading

0 comments on commit 8079151

Please sign in to comment.