From 0ffb5d2de6863208914735814569d295d5f31e21 Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Fri, 30 Aug 2024 10:47:52 +0200 Subject: [PATCH] internal/core/adt: add tests to prepare for bug fix Note that the results for "embed" are different from the results of "direct", even though they should not be. The results of "direct" are correct. This fix is in a follow-up CL. Signed-off-by: Marcel van Lohuizen Change-Id: Ifa2801a2566309a17b0cd3bcf3a193125b0286f9 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200327 Unity-Result: CUE porcuepine TryBot-Result: CUEcueckoo Reviewed-by: Roger Peppe --- cue/testdata/builtins/matchn.txtar | 308 +++++++++++++++++++++++++++-- 1 file changed, 293 insertions(+), 15 deletions(-) diff --git a/cue/testdata/builtins/matchn.txtar b/cue/testdata/builtins/matchn.txtar index 239141b5b..ba1af3377 100644 --- a/cue/testdata/builtins/matchn.txtar +++ b/cue/testdata/builtins/matchn.txtar @@ -112,16 +112,35 @@ allOf: { multiple1OK1: 15 } + +bare: { + embed: t1: { + a: {matchN(1, [>10])} + b: {a} + } + embed: t2: { + b: {a} + a: {matchN(1, [>10])} + } + direct: t1: { + a: matchN(1, [>10]) + b: a + } + direct: t2: { + b: a + a: matchN(1, [>10]) + } +} -- out/eval/stats -- -Leaks: 3 -Freed: 505 -Reused: 497 -Allocs: 11 -Retain: 40 +Leaks: 8 +Freed: 535 +Reused: 530 +Allocs: 13 +Retain: 52 -Unifications: 496 -Conjuncts: 859 -Disjuncts: 545 +Unifications: 531 +Conjuncts: 918 +Disjuncts: 585 -- out/eval -- Errors: match.singleErr: invalid value {a:"foo"} (does not satisfy matchN(1, [{a:int}])): 0 matched, expected 1: @@ -172,6 +191,22 @@ allOf.multiple1Err3: invalid value 5 (does not satisfy matchN(2, [math.MultipleO ./in.cue:106:20 ./in.cue:106:27 ./in.cue:110:17 +bare.embed.t1.a: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + ./in.cue:117:7 + ./in.cue:117:6 + ./in.cue:117:14 +bare.embed.t1.b: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + ./in.cue:117:7 + ./in.cue:117:14 + ./in.cue:118:6 +bare.embed.t2.a: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + ./in.cue:122:7 + ./in.cue:122:6 + ./in.cue:122:14 +bare.embed.t2.b: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + ./in.cue:122:7 + ./in.cue:121:6 + ./in.cue:122:14 Result: (_|_){ @@ -340,6 +375,64 @@ Result: } multiple1OK1: (int){ 15 } } + bare: (_|_){ + // [eval] + embed: (_|_){ + // [eval] + t1: (_|_){ + // [eval] + a: (_|_){ + // [eval] bare.embed.t1.a: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + // ./in.cue:117:7 + // ./in.cue:117:6 + // ./in.cue:117:14 + } + b: (_|_){ + // [eval] bare.embed.t1.b: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + // ./in.cue:117:7 + // ./in.cue:117:14 + // ./in.cue:118:6 + } + } + t2: (_|_){ + // [eval] + b: (_|_){ + // [eval] bare.embed.t2.b: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + // ./in.cue:122:7 + // ./in.cue:121:6 + // ./in.cue:122:14 + } + a: (_|_){ + // [eval] bare.embed.t2.a: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + // ./in.cue:122:7 + // ./in.cue:122:6 + // ./in.cue:122:14 + } + } + } + direct: (struct){ + t1: (struct){ + a: (_){ matchN(1, (#list){ + 0: (_|_){// >10 + } + }) } + b: (_){ matchN(1, (#list){ + 0: (_|_){// >10 + } + }) } + } + t2: (struct){ + b: (_){ matchN(1, (#list){ + 0: (_|_){// >10 + } + }) } + a: (_){ matchN(1, (#list){ + 0: (_|_){// >10 + } + }) } + } + } + } } -- out/evalalpha -- Errors: @@ -385,6 +478,18 @@ allOf.multiple1Err3: invalid value 5 (does not satisfy matchN(2, [math.MultipleO ./in.cue:106:20 ./in.cue:106:27 ./in.cue:110:17 +bare.embed.t1.a: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + ./in.cue:117:7 + ./in.cue:117:14 +bare.embed.t1.b: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + ./in.cue:117:7 + ./in.cue:117:14 +bare.embed.t2.a: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + ./in.cue:122:7 + ./in.cue:122:14 +bare.embed.t2.b: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + ./in.cue:122:7 + ./in.cue:122:14 Result: (_|_){ @@ -546,6 +651,56 @@ Result: } multiple1OK1: (int){ 15 } } + bare: (_|_){ + // [eval] + embed: (_|_){ + // [eval] + t1: (_|_){ + // [eval] + a: (_|_){ + // [eval] bare.embed.t1.a: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + // ./in.cue:117:7 + // ./in.cue:117:14 + } + b: (_|_){ + // [eval] bare.embed.t1.b: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + // ./in.cue:117:7 + // ./in.cue:117:14 + } + } + t2: (_|_){ + // [eval] + b: (_|_){ + // [eval] bare.embed.t2.b: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + // ./in.cue:122:7 + // ./in.cue:122:14 + } + a: (_|_){ + // [eval] bare.embed.t2.a: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + // ./in.cue:122:7 + // ./in.cue:122:14 + } + } + } + direct: (struct){ + t1: (struct){ + a: (_){ matchN(1, (#list){ + 0: (number){ >10 } + }) } + b: (_){ matchN(1, (#list){ + 0: (number){ >10 } + }) } + } + t2: (struct){ + b: (_){ matchN(1, (#list){ + 0: (number){ >10 } + }) } + a: (_){ matchN(1, (#list){ + 0: (number){ >10 } + }) } + } + } + } } -- diff/-out/evalalpha<==>+out/eval -- diff old new @@ -580,7 +735,27 @@ diff old new oneOf.multiple1Err1: invalid value 1 (does not satisfy matchN(1, [math.MultipleOf(3),math.MultipleOf(5)])): 0 matched, expected 1: ./in.cue:84:20 ./in.cue:84:27 -@@ -63,7 +57,6 @@ +@@ -49,19 +43,15 @@ + ./in.cue:110:17 + bare.embed.t1.a: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + ./in.cue:117:7 +- ./in.cue:117:6 + ./in.cue:117:14 + bare.embed.t1.b: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + ./in.cue:117:7 + ./in.cue:117:14 +- ./in.cue:118:6 + bare.embed.t2.a: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + ./in.cue:122:7 +- ./in.cue:122:6 + ./in.cue:122:14 + bare.embed.t2.b: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + ./in.cue:122:7 +- ./in.cue:121:6 + ./in.cue:122:14 + + Result: +@@ -79,7 +69,6 @@ // [eval] match.singleErr: invalid value {a:"foo"} (does not satisfy matchN(1, [{a:int}])): 0 matched, expected 1: // ./in.cue:8:17 // ./in.cue:8:24 @@ -588,7 +763,7 @@ diff old new a: (string){ "foo" } } incompleteOK: (struct){ -@@ -73,7 +66,6 @@ +@@ -89,7 +78,6 @@ // [eval] match.incompleteErr: invalid value {a:string} (does not satisfy matchN(1, [{a:int}])): 0 matched, expected 1: // ./in.cue:12:21 // ./in.cue:12:28 @@ -596,7 +771,7 @@ diff old new a: (string){ string } } #A: (#struct){ -@@ -86,8 +78,7 @@ +@@ -102,8 +90,7 @@ 0: (int){ 2 } }), int) }) } pickTopOK2: (int){ &(matchN(1, (#list){ @@ -606,7 +781,7 @@ diff old new }), int) } pickTopErr: (int){ &(matchN(1, (#list){ 0: (int){ 2 } -@@ -102,7 +93,6 @@ +@@ -118,7 +105,6 @@ // [eval] match.defaults.pickNested1Err: invalid value {a:*3 | int} (does not satisfy matchN(1, [{a:2}])): 0 matched, expected 1: // ./in.cue:36:23 // ./in.cue:36:30 @@ -614,7 +789,7 @@ diff old new a: (int){ |(*(int){ 3 }, (int){ int }) } } pickNested2OK1: (struct){ -@@ -115,7 +105,6 @@ +@@ -131,7 +117,6 @@ // [eval] match.defaults.pickNested2Err: invalid value {a:*3 | int} (does not satisfy matchN(1, [{a:<=2}])): 0 matched, expected 1: // ./in.cue:41:23 // ./in.cue:41:30 @@ -622,7 +797,7 @@ diff old new a: (int){ |(*(int){ 3 }, (int){ int }) } } } -@@ -150,7 +139,6 @@ +@@ -166,7 +151,6 @@ // [eval] not.singleErr: invalid value {a:2} (does not satisfy matchN(0, [{a:int}])): 1 matched, expected 0: // ./in.cue:74:17 // ./in.cue:74:24 @@ -630,7 +805,7 @@ diff old new a: (int){ 2 } } doubleOK: (struct){ -@@ -157,10 +145,9 @@ +@@ -173,10 +157,9 @@ a: (int){ 2 } } doubleErr: (_|_){ @@ -642,6 +817,67 @@ diff old new a: (string){ "foo" } } } +@@ -240,7 +223,6 @@ + a: (_|_){ + // [eval] bare.embed.t1.a: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + // ./in.cue:117:7 +- // ./in.cue:117:6 + // ./in.cue:117:14 + } + b: (_|_){ +@@ -247,7 +229,6 @@ + // [eval] bare.embed.t1.b: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + // ./in.cue:117:7 + // ./in.cue:117:14 +- // ./in.cue:118:6 + } + } + t2: (_|_){ +@@ -255,13 +236,11 @@ + b: (_|_){ + // [eval] bare.embed.t2.b: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + // ./in.cue:122:7 +- // ./in.cue:121:6 + // ./in.cue:122:14 + } + a: (_|_){ + // [eval] bare.embed.t2.a: invalid value {} (does not satisfy matchN(1, [>10])): 0 matched, expected 1: + // ./in.cue:122:7 +- // ./in.cue:122:6 + // ./in.cue:122:14 + } + } +@@ -269,22 +248,18 @@ + direct: (struct){ + t1: (struct){ + a: (_){ matchN(1, (#list){ +- 0: (_|_){// >10 +- } +- }) } +- b: (_){ matchN(1, (#list){ +- 0: (_|_){// >10 +- } ++ 0: (number){ >10 } ++ }) } ++ b: (_){ matchN(1, (#list){ ++ 0: (number){ >10 } + }) } + } + t2: (struct){ + b: (_){ matchN(1, (#list){ +- 0: (_|_){// >10 +- } +- }) } +- a: (_){ matchN(1, (#list){ +- 0: (_|_){// >10 +- } ++ 0: (number){ >10 } ++ }) } ++ a: (_){ matchN(1, (#list){ ++ 0: (number){ >10 } + }) } + } + } -- diff/explanation -- The old evaluator does not correctly handle ToDataAll if a node is mid-evaluation. The new evaluator does. @@ -829,4 +1065,46 @@ Missing error positions. multiple1Err3: 5 multiple1OK1: 15 } + bare: { + embed: { + t1: { + a: { + matchN(1, [ + >10, + ]) + } + b: { + 〈1;a〉 + } + } + } + embed: { + t2: { + b: { + 〈1;a〉 + } + a: { + matchN(1, [ + >10, + ]) + } + } + } + direct: { + t1: { + a: matchN(1, [ + >10, + ]) + b: 〈0;a〉 + } + } + direct: { + t2: { + b: 〈0;a〉 + a: matchN(1, [ + >10, + ]) + } + } + } }