1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package adt_test
16
17 import (
18 "strconv"
19 "testing"
20
21 "cuelang.org/go/internal/core/adt"
22 "cuelang.org/go/internal/core/runtime"
23 )
24
25 func TestFeatureBool(t *testing.T) {
26 r := runtime.New()
27 ctx := adt.NewContext(r, &adt.Vertex{})
28
29 makeInt := func(x int64) adt.Feature {
30 f, _ := adt.MakeLabel(nil, 2, adt.IntLabel)
31 return f
32 }
33
34 testCases := []struct {
35 in adt.Feature
36 isRegular bool
37 isDefinition bool
38 isHidden bool
39 isString bool
40 isInt bool
41 }{{
42 in: ctx.StringLabel("foo"),
43 isRegular: true,
44 isString: true,
45 }, {
46 in: ctx.StringLabel("_"),
47 isRegular: true,
48 isString: true,
49 }, {
50 in: ctx.StringLabel("_#foo"),
51 isRegular: true,
52 isString: true,
53 }, {
54 in: ctx.StringLabel("#foo"),
55 isRegular: true,
56 isString: true,
57 }, {
58 in: adt.MakeStringLabel(r, "foo"),
59 isRegular: true,
60 isString: true,
61 }, {
62 in: adt.MakeStringLabel(r, "_"),
63 isRegular: true,
64 isString: true,
65 }, {
66 in: adt.MakeStringLabel(r, "_#foo"),
67 isRegular: true,
68 isString: true,
69 }, {
70 in: adt.MakeStringLabel(r, "#foo"),
71 isRegular: true,
72 isString: true,
73 }, {
74 in: makeInt(4),
75 isRegular: true,
76 isInt: true,
77 }, {
78 in: adt.MakeIdentLabel(r, "foo", "main"),
79 isRegular: true,
80 isString: true,
81 }, {
82 in: adt.MakeIdentLabel(r, "#foo", "main"),
83 isDefinition: true,
84 }, {
85 in: adt.MakeIdentLabel(r, "_#foo", "main"),
86 isDefinition: true,
87 isHidden: true,
88 }, {
89 in: adt.MakeIdentLabel(r, "_foo", "main"),
90 isHidden: true,
91 }}
92 for i, tc := range testCases {
93 t.Run(strconv.Itoa(i), func(t *testing.T) {
94 if got := tc.in.IsRegular(); got != tc.isRegular {
95 t.Errorf("IsRegular: got %v; want %v", got, tc.isRegular)
96 }
97 if got := tc.in.IsString(); got != tc.isString {
98 t.Errorf("IsString: got %v; want %v", got, tc.isString)
99 }
100 if got := tc.in.IsInt(); got != tc.isInt {
101 t.Errorf("IsInt: got %v; want %v", got, tc.isInt)
102 }
103 if got := tc.in.IsDef(); got != tc.isDefinition {
104 t.Errorf("isDefinition: got %v; want %v", got, tc.isDefinition)
105 }
106 if got := tc.in.IsHidden(); got != tc.isHidden {
107 t.Errorf("IsHidden: got %v; want %v", got, tc.isHidden)
108 }
109 if got := tc.in.IsString(); got != tc.isString {
110 t.Errorf("IsString: got %v; want %v", got, tc.isString)
111 }
112 })
113 }
114 }
115
View as plain text