@@ -149,31 +149,34 @@ class HasSymbolsMatcher {
149
149
150
150
bool MatchAndExplain (const ParseResult& result, std::ostream* listener)
151
151
const {
152
- auto actualSymbols = symbolNames (result.getSymbolTable ().getSymbols ());
152
+ // Note: Need set or sorted vector for set_difference.
153
+ auto actualSymbolsSorted =
154
+ symbolNames (result.getSymbolTable ().getSymbols ());
155
+ std::sort (actualSymbolsSorted.begin (), actualSymbolsSorted.end ());
156
+ std::vector<std::string> extraSymbols;
157
+ auto expectedSymbolsSorted = expectedSymbols_;
158
+ std::sort (expectedSymbolsSorted.begin (), expectedSymbolsSorted.end ());
153
159
if (listener != nullptr ) {
154
- std::vector<std::string> extraSymbols (actualSymbols.size ());
155
160
auto end = std::set_difference (
156
- actualSymbols.begin (),
157
- actualSymbols.end (),
158
- expectedSymbols_.begin (),
159
- expectedSymbols_.end (),
160
- extraSymbols.begin ());
161
- extraSymbols.resize (end - extraSymbols.begin ());
161
+ actualSymbolsSorted.begin (),
162
+ actualSymbolsSorted.end (),
163
+ expectedSymbolsSorted.begin (),
164
+ expectedSymbolsSorted.end (),
165
+ std::back_inserter (extraSymbols));
162
166
if (!extraSymbols.empty ()) {
163
167
*listener << std::endl << " with extra symbols: " ;
164
168
for (const auto & symbol : extraSymbols) {
165
169
*listener << " \" " << symbol << " \" " ;
166
170
}
167
171
}
168
172
169
- std::vector<std::string> missingSymbols (expectedSymbols_. size ()) ;
173
+ std::vector<std::string> missingSymbols;
170
174
end = std::set_difference (
171
- expectedSymbols_.begin (),
172
- expectedSymbols_.end (),
173
- actualSymbols.begin (),
174
- actualSymbols.end (),
175
- missingSymbols.begin ());
176
- missingSymbols.resize (end - missingSymbols.begin ());
175
+ expectedSymbolsSorted.begin (),
176
+ expectedSymbolsSorted.end (),
177
+ actualSymbolsSorted.begin (),
178
+ actualSymbolsSorted.end (),
179
+ std::back_inserter (missingSymbols));
177
180
if (!missingSymbols.empty ()) {
178
181
if (!extraSymbols.empty ()) {
179
182
*listener << " , and missing symbols: " ;
@@ -185,7 +188,7 @@ class HasSymbolsMatcher {
185
188
}
186
189
}
187
190
}
188
- return actualSymbols == expectedSymbols_ ;
191
+ return actualSymbolsSorted == expectedSymbolsSorted ;
189
192
}
190
193
191
194
void DescribeTo (std::ostream* os) const {
0 commit comments