Skip to content

Commit

Permalink
playground: declare an eval function
Browse files Browse the repository at this point in the history
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í <[email protected]>
Change-Id: I976dd4c81b812e3b14b9c1836570161fa98db13e
Dispatch-Trailer: {"type":"trybot","CL":1170942,"patchset":1,"ref":"refs/changes/42/1170942/1","targetBranch":"alpha"}
  • Loading branch information
mvdan authored and cueckoo committed Oct 19, 2023
1 parent 4ad18b4 commit 16f1829
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion playground/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type function string

const (
functionExport function = "export"
functionEval function = "eval"
functionDef function = "def"
)

Expand All @@ -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)
}
Expand Down
7 changes: 5 additions & 2 deletions playground/impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", ""},

Expand All @@ -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
Expand All @@ -78,7 +81,7 @@ var testTable = []struct {
"",
},
{
inputCUE, functionExport, outputCUE,
inputCUE, functionEval, outputCUE,
`
x: x2: "foo"
y: x.missing
Expand Down

0 comments on commit 16f1829

Please sign in to comment.