Skip to content

Commit

Permalink
cue: add a regression test for invalid pattern matching syntax errors
Browse files Browse the repository at this point in the history
The new evaluator correctly shows these as errors, whereas the old
evaluator would seem to discard the error entirely.

Closes #3555.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ib76446dcac2150da3cf728895d5a0f6b853088db
  • Loading branch information
mvdan committed Dec 27, 2024
1 parent 2589f7f commit 6ab6ce5
Showing 1 changed file with 148 additions and 7 deletions.
155 changes: 148 additions & 7 deletions cue/testdata/references/labels.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,150 @@ underscore: e: {
// }
// }
// c2: c1 & { x: _ }

invalidPattern: {
[=~"BAD)" & =~"x"]: string
y: 123
}
-- out/eval/stats --
Leaks: 0
Freed: 58
Reused: 52
Leaks: 1
Freed: 61
Reused: 56
Allocs: 6
Retain: 3
Retain: 4

Unifications: 60
Conjuncts: 109
Disjuncts: 65
-- out/evalalpha --
Errors:
invalidPattern: invalid regexp: error parsing regexp: unexpected ): `BAD)`:
./in.cue:96:22

Unifications: 56
Conjuncts: 103
Disjuncts: 61
Result:
(_|_){
// [eval]
a: (struct){
bar: (string){ "bar" }
}
b: (struct){
bar: (string){ "bar" }
}
c: (struct){
bar: (string){ "bar" }
}
d: (struct){
bar: (struct){
name: (string){ "bar" }
}
}
e: (struct){
foo: (struct){
bar: (string){ "foobar" }
}
}
patternField: (struct){
t1: (struct){
a: (struct){
r: (int){ 0 }
b: (null){ null }
}
}
t2: (struct){
a: (struct){
r: (int){ 0 }
z: (int){ 1 }
b: (int){ 1 }
}
}
}
bar: (int){ 3 }
f1: (struct){
foo3: (struct){
name: (string){ "xx" }
foo: (string){ "xx" }
foo3baz: (struct){
name: (string){ "xx" }
a: (string){ "xx" }
b: (string){ "xx" }
}
}
}
c1: (struct){
foo3: (struct){
x: (struct){
name: (string){ "x" }
foo: (string){ "x" }
}
}
}
emptyLabel: (struct){
"": (int){ 1 }
a: (int){ 1 }
}
underscore: (struct){
a: (struct){
foo: (#struct){
"_": (string){ "bar" }
}
#Foo: (#struct){
}
}
c: (struct){
foo: (struct){
"_": (string){ "any" }
}
}
d: (struct){
bar: (#struct){
"_": (string){ "any" }
}
#bar: (#struct){
}
}
e: (struct){
baz: (#struct){
"_h": (string){ "any" }
}
#baz: (#struct){
}
}
}
invalidPattern: (_|_){
// [eval] invalidPattern: invalid regexp: error parsing regexp: unexpected ): `BAD)`:
// ./in.cue:96:22
y: (int){ 123 }
}
}
-- diff/explanation --
The new evaluator correctly points out that the pattern matching regular expression has invalid syntax.
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -1,4 +1,10 @@
-(struct){
+Errors:
+invalidPattern: invalid regexp: error parsing regexp: unexpected ): `BAD)`:
+ ./in.cue:96:22
+
+Result:
+(_|_){
+ // [eval]
a: (struct){
bar: (string){ "bar" }
}
@@ -85,7 +91,9 @@
}
}
}
- invalidPattern: (struct){
+ invalidPattern: (_|_){
+ // [eval] invalidPattern: invalid regexp: error parsing regexp: unexpected ): `BAD)`:
+ // ./in.cue:96:22
y: (int){ 123 }
}
}
-- out/eval --
(struct){
a: (struct){
Expand Down Expand Up @@ -190,6 +324,9 @@ Disjuncts: 61
}
}
}
invalidPattern: (struct){
y: (int){ 123 }
}
}
-- out/compile --
--- in.cue
Expand Down Expand Up @@ -338,4 +475,8 @@ Disjuncts: 61
baz: 〈0;#baz〉
}
}
invalidPattern: {
[(=~"BAD)" & =~"x")]: string
y: 123
}
}

0 comments on commit 6ab6ce5

Please sign in to comment.