This repository has been archived by the owner on Nov 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/core/adt: distinguish dynamic fields from pattern constraints
Change-Id: I3a6418ebb6493c48f10b70670d3178dc69ecf886 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6652 Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
- Loading branch information
Showing
3 changed files
with
87 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2020 CUE Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package eval_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"cuelang.org/go/cue/parser" | ||
"cuelang.org/go/internal/core/adt" | ||
"cuelang.org/go/internal/core/compile" | ||
"cuelang.org/go/internal/core/eval" | ||
"cuelang.org/go/internal/core/runtime" | ||
) | ||
|
||
func TestOptionalTypes(t *testing.T) { | ||
testCases := []struct { | ||
in string | ||
out adt.OptionalType | ||
}{{ | ||
in: ` | ||
... | ||
`, | ||
out: adt.HasAdditional | adt.IsOpen, | ||
}, { | ||
in: ` | ||
[string]: int | ||
`, | ||
// adt.IsOpen means fully defined in this context, which this is not. | ||
out: adt.HasPattern, | ||
}, { | ||
in: ` | ||
bar: 3 // Not counted, as it is not optional. | ||
{[string]: int} // embedded into end result. | ||
"\(bar)": int | ||
`, | ||
out: adt.HasPattern | adt.HasDynamic, | ||
}, { | ||
in: ` | ||
bar?: 3 | ||
`, | ||
out: adt.HasField, | ||
}} | ||
for _, tc := range testCases { | ||
t.Run("", func(t *testing.T) { | ||
ctx := eval.NewContext(runtime.New(), nil) | ||
f, err := parser.ParseFile("opt", tc.in) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
v, errs := compile.Files(nil, ctx, f) | ||
if errs != nil { | ||
t.Fatal(errs) | ||
} | ||
|
||
v.Finalize(ctx) | ||
|
||
got := v.OptionalTypes() | ||
if got != tc.out { | ||
t.Errorf("got %x; want %x", got, tc.out) | ||
} | ||
}) | ||
} | ||
} |