cuelang.org/go@v0.10.1/internal/core/adt/feature_test.go (about) 1 // Copyright 2020 CUE Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 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 }