(t *testing.T)
| 1181 | } |
| 1182 | |
| 1183 | func TestLibrarySubsetValidate(t *testing.T) { |
| 1184 | tests := []struct { |
| 1185 | name string |
| 1186 | lib *LibrarySubset |
| 1187 | want error |
| 1188 | }{ |
| 1189 | { |
| 1190 | name: "nil library", |
| 1191 | lib: nil, |
| 1192 | }, |
| 1193 | { |
| 1194 | name: "empty library", |
| 1195 | lib: NewLibrarySubset(), |
| 1196 | }, |
| 1197 | { |
| 1198 | name: "only excluded funcs", |
| 1199 | lib: NewLibrarySubset().AddExcludedFunctions(NewFunction("size", nil)), |
| 1200 | }, |
| 1201 | { |
| 1202 | name: "only included funcs", |
| 1203 | lib: NewLibrarySubset().AddIncludedFunctions(NewFunction("size", nil)), |
| 1204 | }, |
| 1205 | { |
| 1206 | name: "only excluded macros", |
| 1207 | lib: NewLibrarySubset().AddExcludedMacros("has"), |
| 1208 | }, |
| 1209 | { |
| 1210 | name: "only included macros", |
| 1211 | lib: NewLibrarySubset().AddIncludedMacros("exists"), |
| 1212 | }, |
| 1213 | { |
| 1214 | name: "both included and excluded funcs", |
| 1215 | lib: NewLibrarySubset(). |
| 1216 | AddIncludedFunctions(NewFunction("size", nil)). |
| 1217 | AddExcludedFunctions(NewFunction("size", nil)), |
| 1218 | want: errors.New("invalid subset"), |
| 1219 | }, |
| 1220 | { |
| 1221 | name: "both included and excluded macros", |
| 1222 | lib: NewLibrarySubset(). |
| 1223 | AddIncludedMacros("has"). |
| 1224 | AddExcludedMacros("exists"), |
| 1225 | want: errors.New("invalid subset"), |
| 1226 | }, |
| 1227 | } |
| 1228 | |
| 1229 | for _, tst := range tests { |
| 1230 | tc := tst |
| 1231 | t.Run(tc.name, func(t *testing.T) { |
| 1232 | err := tc.lib.Validate() |
| 1233 | if err == nil && tc.want == nil { |
| 1234 | return |
| 1235 | } |
| 1236 | if err == nil && tc.want != nil { |
| 1237 | t.Fatalf("lib.Validate() got valid, wanted error %v", tc.want) |
| 1238 | } |
| 1239 | if err != nil && tc.want == nil { |
| 1240 | t.Fatalf("lib.Validate() got error %v, wanted nil error", err) |
nothing calls this directly
no test coverage detected