From 16f1829bbf06fc512ba40d41d59f14f29e40fb38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Thu, 19 Oct 2023 16:24:45 +0100 Subject: [PATCH] playground: declare an eval function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mimicking "cue eval", which is separate from exporting. Note that its behavior is exactly the same as export for now; the following commits will start changing the implementation and tests. Some test cases are added to show the upcoming changes in behavior. The "incomplete values that should perhaps be an error" test cases now use eval rather than export, since we don't want to simply stop with an incomplete error like "cue export" would. Signed-off-by: Daniel Martí Change-Id: I976dd4c81b812e3b14b9c1836570161fa98db13e Dispatch-Trailer: {"type":"trybot","CL":1170942,"patchset":1,"ref":"refs/changes/42/1170942/1","targetBranch":"alpha"} --- playground/impl.go | 3 ++- playground/impl_test.go | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/playground/impl.go b/playground/impl.go index d455ed9ff9..256057481d 100644 --- a/playground/impl.go +++ b/playground/impl.go @@ -36,6 +36,7 @@ type function string const ( functionExport function = "export" + functionEval function = "eval" functionDef function = "def" ) @@ -58,7 +59,7 @@ const ( func handleCUECompile(in input, fn function, out output, inputVal string) (string, error) { // TODO implement more functions switch fn { - case functionExport, functionDef: + case functionExport, functionEval, functionDef: default: return "", fmt.Errorf("function %q is not implemented", fn) } diff --git a/playground/impl_test.go b/playground/impl_test.go index 5733fe06ca..ef1b00672c 100644 --- a/playground/impl_test.go +++ b/playground/impl_test.go @@ -34,16 +34,19 @@ var testTable = []struct { // Incomplete values. {inputCUE, functionDef, outputCUE, "foo: int", "foo: int\n", ""}, + {inputCUE, functionEval, outputCUE, "foo: int", "foo: int\n", ""}, {inputCUE, functionExport, outputCUE, "foo: int", "foo: int\n", ""}, {inputCUE, functionExport, outputJSON, "foo: int", "", "foo: incomplete value int"}, // Selecting defaults; def does less. {inputCUE, functionDef, outputCUE, "foo: int | *3", "foo: int | *3\n", ""}, + {inputCUE, functionEval, outputCUE, "foo: int | *3", "foo: 3\n", ""}, {inputCUE, functionExport, outputCUE, "foo: int | *3", "foo: 3\n", ""}, {inputCUE, functionExport, outputJSON, "foo: int | *3", "{\n \"foo\": 3\n}\n", ""}, // Simplifying values; def does less. {inputCUE, functionDef, outputCUE, "foo: [1, 2, 3][1]", "foo: [1, 2, 3][1]\n", ""}, + {inputCUE, functionEval, outputCUE, "foo: [1, 2, 3][1]", "foo: 2\n", ""}, {inputCUE, functionExport, outputCUE, "foo: [1, 2, 3][1]", "foo: 2\n", ""}, {inputCUE, functionExport, outputJSON, "foo: [1, 2, 3][1]", "{\n \"foo\": 2\n}\n", ""}, @@ -69,7 +72,7 @@ var testTable = []struct { // Cases which one could argue should be errors, beyond just being incomplete. { - inputCUE, functionExport, outputCUE, + inputCUE, functionEval, outputCUE, ` x: string y: (x): string @@ -78,7 +81,7 @@ var testTable = []struct { "", }, { - inputCUE, functionExport, outputCUE, + inputCUE, functionEval, outputCUE, ` x: x2: "foo" y: x.missing