MCPcopy
hub / github.com/google/mangle / TestBoundsCheckingNegative

Function TestBoundsCheckingNegative

analysis/declcheck_test.go:141–188  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

139}
140
141func TestBoundsCheckingNegative(t *testing.T) {
142 tests := []struct {
143 name string
144 boundDecl ast.BoundDecl
145 }{
146 {
147 name: "not enough bounds",
148 boundDecl: ast.NewBoundDecl(ast.StringBound),
149 },
150 {
151 name: "bad type expressions - too many args",
152 boundDecl: ast.NewBoundDecl(
153 ast.ApplyFn{symbols.ListType, []ast.BaseTerm{ast.NumberBound, ast.AnyBound}},
154 ast.AnyBound),
155 },
156 {
157 name: "bad type expression - not enough args",
158 boundDecl: ast.NewBoundDecl(
159 ast.AnyBound,
160 ast.ApplyFn{symbols.PairType, []ast.BaseTerm{ast.NumberBound}}),
161 },
162 {
163 name: "bad type expression - empty union",
164 boundDecl: ast.NewBoundDecl(
165 ast.AnyBound,
166 ast.ApplyFn{symbols.UnionType, nil}),
167 },
168 {
169 name: "bad type expression - tuple with less than 3 args",
170 boundDecl: ast.NewBoundDecl(
171 ast.AnyBound,
172 ast.ApplyFn{symbols.TupleType, []ast.BaseTerm{ast.NumberBound}}),
173 },
174 {
175 name: "predicate bound not allowed in structured type expression",
176 boundDecl: ast.NewBoundDecl(
177 ast.ApplyFn{symbols.ListType, []ast.BaseTerm{ast.String("foo")}},
178 ast.ApplyFn{symbols.PairType, []ast.BaseTerm{ast.NumberBound, ast.AnyBound}}),
179 },
180 }
181 for _, test := range tests {
182 t.Run(test.name, func(t *testing.T) {
183 if errs := checkBoundDecl(test.boundDecl); errs == nil {
184 t.Errorf("%s: expected error %+v", test.name, test.boundDecl)
185 }
186 })
187 }
188}
189
190func TestDescrCheckingPositive(t *testing.T) {
191 tests := []struct {

Callers

nothing calls this directly

Calls 3

NewBoundDeclFunction · 0.92
StringFunction · 0.92
checkBoundDeclFunction · 0.85

Tested by

no test coverage detected