...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package adt_test
16
17 import (
18 "testing"
19
20 "cuelang.org/go/cue/parser"
21 "cuelang.org/go/internal/core/adt"
22 "cuelang.org/go/internal/core/compile"
23 "cuelang.org/go/internal/core/eval"
24 "cuelang.org/go/internal/core/runtime"
25 )
26
27 func TestOptionalTypes(t *testing.T) {
28 testCases := []struct {
29 in string
30 out adt.OptionalType
31 }{{
32 in: `
33 ...
34 `,
35 out: adt.IsOpen,
36 }, {
37 in: `
38 [string]: int
39 `,
40
41 out: adt.HasPattern,
42 }, {
43 in: `
44 bar: 3 // Not counted, as it is not optional.
45 [string]: int // embedded into end result.
46 "\(bar)": int
47 `,
48 out: adt.HasPattern | adt.HasDynamic,
49 }}
50 for _, tc := range testCases {
51 t.Run("", func(t *testing.T) {
52 ctx := eval.NewContext(runtime.New(), nil)
53 f, err := parser.ParseFile("opt", tc.in)
54 if err != nil {
55 t.Fatal(err)
56 }
57
58 v, errs := compile.Files(nil, ctx, "", f)
59 if errs != nil {
60 t.Fatal(errs)
61 }
62
63 v.Finalize(ctx)
64
65 got := v.OptionalTypes()
66 if got != tc.out {
67 t.Errorf("got %x; want %x", got, tc.out)
68 }
69 })
70 }
71 }
72
View as plain text