1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package path
16
17 import (
18 "testing"
19
20 "cuelang.org/go/cue"
21 "cuelang.org/go/internal/core/adt"
22 "cuelang.org/go/internal/core/runtime"
23 )
24
25
26 func TestToFeatureType(t *testing.T) {
27 testCases := []struct {
28 s cue.SelectorType
29 f adt.FeatureType
30 }{{
31 cue.InvalidSelectorType,
32 adt.InvalidLabelType,
33 }, {
34 cue.StringLabel,
35 adt.StringLabel,
36 }, {
37 cue.IndexLabel,
38 adt.IntLabel,
39 }, {
40 cue.DefinitionLabel,
41 adt.DefinitionLabel,
42 }, {
43 cue.HiddenLabel,
44 adt.HiddenLabel,
45 }, {
46 cue.HiddenDefinitionLabel,
47 adt.HiddenDefinitionLabel,
48 }, {
49 cue.StringLabel | cue.OptionalConstraint,
50 adt.StringLabel,
51 }, {
52 cue.OptionalConstraint,
53 adt.InvalidLabelType,
54 }}
55 for _, tc := range testCases {
56 t.Run(tc.s.String(), func(t *testing.T) {
57 if got := ToFeatureType(tc.s); got != tc.f {
58 t.Errorf("got %v, want %v", got, tc.f)
59 }
60 })
61 }
62 }
63
64 func TestMakeFeature(t *testing.T) {
65 testCases := []struct {
66 sel cue.Selector
67 str string
68 }{{
69 sel: cue.Str("s-t"),
70 str: `"s-t"`,
71 }, {
72
73 sel: cue.Str("s-t").Optional(),
74 str: `"s-t"`,
75 }, {
76 sel: cue.Index(5),
77 str: "5",
78 }, {
79 sel: cue.Def("#Foo"),
80 str: "#Foo",
81 }, {
82 sel: cue.Hid("_foo", "pkg"),
83 str: "_foo",
84 }, {
85 sel: cue.Hid("_#foo", "pkg"),
86 str: "_#foo",
87 }, {
88 sel: cue.AnyString,
89 str: `_`,
90 }}
91 for _, tc := range testCases {
92 r := runtime.New()
93 t.Run(tc.sel.String(), func(t *testing.T) {
94 got := MakeFeature(r, tc.sel).SelectorString(r)
95 if got != tc.str {
96 t.Errorf("got %v, want %v", got, tc.str)
97 }
98 })
99 }
100 }
101
View as plain text