(t *testing.T)
| 1074 | } |
| 1075 | |
| 1076 | func TestLibrarySubsetValidate(t *testing.T) { |
| 1077 | tests := []struct { |
| 1078 | name string |
| 1079 | lib *LibrarySubset |
| 1080 | want error |
| 1081 | }{ |
| 1082 | { |
| 1083 | name: "nil library", |
| 1084 | lib: NewLibrarySubset(), |
| 1085 | }, |
| 1086 | { |
| 1087 | name: "empty library", |
| 1088 | lib: NewLibrarySubset(), |
| 1089 | }, |
| 1090 | { |
| 1091 | name: "only excluded funcs", |
| 1092 | lib: NewLibrarySubset().AddExcludedFunctions(NewFunction("size", nil)), |
| 1093 | }, |
| 1094 | { |
| 1095 | name: "only included funcs", |
| 1096 | lib: NewLibrarySubset().AddIncludedFunctions(NewFunction("size", nil)), |
| 1097 | }, |
| 1098 | { |
| 1099 | name: "only excluded macros", |
| 1100 | lib: NewLibrarySubset().AddExcludedMacros("has"), |
| 1101 | }, |
| 1102 | { |
| 1103 | name: "only included macros", |
| 1104 | lib: NewLibrarySubset().AddIncludedMacros("exists"), |
| 1105 | }, |
| 1106 | { |
| 1107 | name: "both included and excluded funcs", |
| 1108 | lib: NewLibrarySubset(). |
| 1109 | AddIncludedFunctions(NewFunction("size", nil)). |
| 1110 | AddExcludedFunctions(NewFunction("size", nil)), |
| 1111 | want: errors.New("invalid subset"), |
| 1112 | }, |
| 1113 | { |
| 1114 | name: "both included and excluded macros", |
| 1115 | lib: NewLibrarySubset(). |
| 1116 | AddIncludedMacros("has"). |
| 1117 | AddExcludedMacros("exists"), |
| 1118 | want: errors.New("invalid subset"), |
| 1119 | }, |
| 1120 | } |
| 1121 | |
| 1122 | for _, tst := range tests { |
| 1123 | tc := tst |
| 1124 | t.Run(tc.name, func(t *testing.T) { |
| 1125 | err := tc.lib.Validate() |
| 1126 | if err == nil && tc.want == nil { |
| 1127 | return |
| 1128 | } |
| 1129 | if err == nil && tc.want != nil { |
| 1130 | t.Fatalf("lib.Validate() got valid, wanted error %v", tc.want) |
| 1131 | } |
| 1132 | if err != nil && tc.want == nil { |
| 1133 | t.Fatalf("lib.Validate() got error %v, wanted nil error", err) |
nothing calls this directly
no test coverage detected