Skip to content

Commit a3c6764

Browse files
committed
refactor(test): delete used matchers
1 parent 860c336 commit a3c6764

File tree

4 files changed

+0
-574
lines changed

4 files changed

+0
-574
lines changed

test/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ quick_lint_js_add_executable(
9595
test-debug-server.cpp
9696
test-diag-code-list.cpp
9797
test-diag-list.cpp
98-
test-diag-matcher.cpp
9998
test-diagnostic-assertion.cpp
10099
test-diagnostic-formatter.cpp
101100
test-diagnostic.cpp

test/quick-lint-js/diag-matcher.cpp

Lines changed: 0 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -16,69 +16,6 @@
1616
#include <vector>
1717

1818
namespace quick_lint_js {
19-
class Offsets_Matcher::Span_Impl
20-
: public testing::MatcherInterface<const Source_Code_Span &> {
21-
public:
22-
explicit Span_Impl(Padded_String_View code,
23-
CLI_Source_Position::Offset_Type begin_offset,
24-
CLI_Source_Position::Offset_Type end_offset)
25-
: code_(code), begin_offset_(begin_offset), end_offset_(end_offset) {}
26-
27-
void DescribeTo(std::ostream *out) const override {
28-
*out << "has begin-end offset " << this->begin_offset_ << '-'
29-
<< this->end_offset_;
30-
}
31-
32-
void DescribeNegationTo(std::ostream *out) const override {
33-
*out << "doesn't have begin-end offset " << this->begin_offset_ << '-'
34-
<< this->end_offset_;
35-
}
36-
37-
bool MatchAndExplain(const Source_Code_Span &span,
38-
testing::MatchResultListener *listener) const override {
39-
auto span_begin_offset = narrow_cast<CLI_Source_Position::Offset_Type>(
40-
span.begin() - this->code_.data());
41-
auto span_end_offset = narrow_cast<CLI_Source_Position::Offset_Type>(
42-
span.end() - this->code_.data());
43-
bool result = span_begin_offset == this->begin_offset_ &&
44-
span_end_offset == this->end_offset_;
45-
*listener << "whose begin-end offset (" << span_begin_offset << '-'
46-
<< span_end_offset << ") "
47-
<< (result ? "equals" : "doesn't equal") << " "
48-
<< this->begin_offset_ << '-' << this->end_offset_;
49-
return result;
50-
}
51-
52-
private:
53-
Padded_String_View code_;
54-
CLI_Source_Position::Offset_Type begin_offset_;
55-
CLI_Source_Position::Offset_Type end_offset_;
56-
};
57-
58-
Offsets_Matcher::Offsets_Matcher(Padded_String_View input,
59-
CLI_Source_Position::Offset_Type begin_offset,
60-
CLI_Source_Position::Offset_Type end_offset)
61-
: code_(input), begin_offset_(begin_offset), end_offset_(end_offset) {}
62-
63-
Offsets_Matcher::Offsets_Matcher(Padded_String_View input,
64-
CLI_Source_Position::Offset_Type begin_offset,
65-
String8_View text)
66-
: code_(input),
67-
begin_offset_(begin_offset),
68-
end_offset_(begin_offset + text.size()) {}
69-
70-
Offsets_Matcher::Offsets_Matcher(Offsets_Matcher &&) = default;
71-
72-
Offsets_Matcher &Offsets_Matcher::operator=(Offsets_Matcher &&) = default;
73-
74-
Offsets_Matcher::~Offsets_Matcher() = default;
75-
76-
/*implicit*/ Offsets_Matcher::operator testing::Matcher<
77-
const Source_Code_Span &>() const {
78-
return testing::Matcher<const Source_Code_Span &>(
79-
new Span_Impl(this->code_, this->begin_offset_, this->end_offset_));
80-
}
81-
8219
Source_Code_Span Diag_Matcher_Arg::get_span(const void *error_object) const {
8320
const void *member_data =
8421
reinterpret_cast<const char *>(error_object) + this->member_offset;
@@ -196,55 +133,6 @@ class Diag_Fields_Matcher_Impl_Base
196133
State state_;
197134
};
198135

199-
Diag_Matcher::Diag_Matcher(Diag_Type type) : state_{type, std::nullopt, {}} {}
200-
201-
Diag_Matcher::Diag_Matcher(Padded_String_View input, Diag_Type type,
202-
Field field_0)
203-
: state_{type, input, {field_0}} {}
204-
205-
Diag_Matcher::Diag_Matcher(Padded_String_View input, Diag_Type type,
206-
Field field_0, Field field_1)
207-
: state_{type, input, {field_0, field_1}} {}
208-
209-
Diag_Matcher::Diag_Matcher(Padded_String_View input, Diag_Type type,
210-
Field field_0, Field field_1, Field field_2)
211-
: state_{type, input, {field_0, field_1, field_2}} {}
212-
213-
class Diag_Matcher::Impl final
214-
: public Diag_Fields_Matcher_Impl_Base<Diag_Matcher::State,
215-
Diag_Matcher::Field> {
216-
public:
217-
using Base =
218-
Diag_Fields_Matcher_Impl_Base<Diag_Matcher::State, Diag_Matcher::Field>;
219-
220-
using Base::Diag_Fields_Matcher_Impl_Base;
221-
222-
protected:
223-
bool field_matches(const Any_Diag_Pointer &error, const Field &f,
224-
testing::MatchResultListener *listener) const override {
225-
QLJS_ASSERT(this->state_.input.has_value());
226-
Source_Code_Span span = f.arg.get_span(error.data);
227-
auto span_begin_offset = narrow_cast<CLI_Source_Position::Offset_Type>(
228-
span.begin() - this->state_.input->data());
229-
auto span_end_offset = narrow_cast<CLI_Source_Position::Offset_Type>(
230-
span.end() - this->state_.input->data());
231-
auto expected_end_offset = f.begin_offset + f.text.size();
232-
233-
bool span_matches = span_begin_offset == f.begin_offset &&
234-
span_end_offset == expected_end_offset;
235-
*listener << "whose ." << f.arg.member_name << " (" << span_begin_offset
236-
<< "-" << span_end_offset << ") "
237-
<< (span_matches ? "equals" : "doesn't equal") << " "
238-
<< f.begin_offset << "-" << expected_end_offset;
239-
return span_matches;
240-
}
241-
};
242-
243-
/*implicit*/ Diag_Matcher::operator testing::Matcher<
244-
const Diag_Collector::Diag &>() const {
245-
return testing::Matcher<const Diag_Collector::Diag &>(new Impl(this->state_));
246-
}
247-
248136
Diag_Matcher_2::Diag_Matcher_2(Padded_String_View input, Diag_Type type,
249137
std::vector<Field> fields)
250138
: state_{type, input, std::move(fields)} {}
@@ -339,42 +227,6 @@ Diag_Matcher_2::operator testing::Matcher<const Diag_Collector::Diag &>()
339227
Diag_Matcher_2::operator testing::Matcher<const Any_Diag_Pointer &>() const {
340228
return testing::Matcher<const Any_Diag_Pointer &>(new Impl(this->state_));
341229
}
342-
343-
Diag_Spans_Matcher::Diag_Spans_Matcher(Diag_Type type, Field field_0)
344-
: state_{type, {field_0}} {}
345-
346-
Diag_Spans_Matcher::Diag_Spans_Matcher(Diag_Type type, Field field_0,
347-
Field field_1)
348-
: state_{type, {field_0, field_1}} {}
349-
350-
class Diag_Spans_Matcher::Impl
351-
: public Diag_Fields_Matcher_Impl_Base<Diag_Spans_Matcher::State,
352-
Diag_Spans_Matcher::Field> {
353-
public:
354-
using Base = Diag_Fields_Matcher_Impl_Base<Diag_Spans_Matcher::State,
355-
Diag_Spans_Matcher::Field>;
356-
357-
using Base::Diag_Fields_Matcher_Impl_Base;
358-
359-
protected:
360-
bool field_matches(const Any_Diag_Pointer &error, const Field &f,
361-
testing::MatchResultListener *listener) const override {
362-
Source_Code_Span span = f.arg.get_span(error.data);
363-
bool span_matches = same_pointers(span, f.expected);
364-
*listener << "whose ." << f.arg.member_name << " (`"
365-
<< out_string8(span.string_view()) << "` @"
366-
<< reinterpret_cast<const void *>(span.begin()) << ") "
367-
<< (span_matches ? "equals" : "doesn't equal") << " `"
368-
<< out_string8(f.expected.string_view()) << "` @"
369-
<< reinterpret_cast<const void *>(f.expected.begin());
370-
return span_matches;
371-
}
372-
};
373-
374-
/*implicit*/ Diag_Spans_Matcher::operator testing::Matcher<
375-
const Diag_Collector::Diag &>() const {
376-
return testing::Matcher<const Diag_Collector::Diag &>(new Impl(this->state_));
377-
}
378230
}
379231

380232
// quick-lint-js finds bugs in JavaScript programs.

test/quick-lint-js/diag-matcher.h

Lines changed: 0 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -15,116 +15,7 @@
1515
#include <quick-lint-js/port/char8.h>
1616
#include <vector>
1717

18-
#define DIAG_TYPE_FIELD(diag_type, member, matcher) \
19-
::testing::VariantWith<diag_type>( \
20-
::testing::Field(#member, &diag_type::member, matcher))
21-
22-
// Equivalent to ::testing::VariantWith<type>(::testing::_), but compiles much
23-
// more quickly.
24-
#define DIAG_TYPE(type) \
25-
::quick_lint_js::Diag_Matcher(::quick_lint_js::Diag_Type::type)
26-
27-
// Equivalent to the following, but compiles much more quickly:
28-
//
29-
// DIAG_TYPE_FIELD(type, member_0,
30-
// Offsets_Matcher(code, start_0, end_or_text_0))
31-
//
32-
// but compiles much more quickly.
33-
#define DIAG_TYPE_OFFSETS(code, type, member_0, start_0, end_or_text_0) \
34-
::quick_lint_js::Diag_Matcher(code, ::quick_lint_js::Diag_Type::type, \
35-
::quick_lint_js::Diag_Matcher::Field{ \
36-
DIAG_MATCHER_ARG(type, member_0), \
37-
start_0, \
38-
end_or_text_0, \
39-
})
40-
41-
// Equivalent to the following, but compiles much more quickly:
42-
//
43-
// DIAG_TYPE_FIELD(type,
44-
// member_0, Offsets_Matcher(code, start_0, end_or_text_0),
45-
// member_1, Offsets_Matcher(code, start_1, end_or_text_1))
46-
#define DIAG_TYPE_2_OFFSETS(code, type, member_0, start_0, end_or_text_0, \
47-
member_1, start_1, end_or_text_1) \
48-
::quick_lint_js::Diag_Matcher(code, ::quick_lint_js::Diag_Type::type, \
49-
::quick_lint_js::Diag_Matcher::Field{ \
50-
DIAG_MATCHER_ARG(type, member_0), \
51-
start_0, \
52-
end_or_text_0, \
53-
}, \
54-
::quick_lint_js::Diag_Matcher::Field{ \
55-
DIAG_MATCHER_ARG(type, member_1), \
56-
start_1, \
57-
end_or_text_1, \
58-
})
59-
60-
// Equivalent to the following, but compiles much more quickly:
61-
//
62-
// DIAG_TYPE_FIELD(type, member_0, source_code_span_matcher(span_0))
63-
//
64-
// but compiles much more quickly.
65-
#define DIAG_TYPE_SPAN(type, member_0, span_0) \
66-
::quick_lint_js::Diag_Spans_Matcher( \
67-
::quick_lint_js::Diag_Type::type, \
68-
::quick_lint_js::Diag_Spans_Matcher::Field{ \
69-
DIAG_MATCHER_ARG(type, member_0), \
70-
span_0, \
71-
})
72-
73-
// Equivalent to the following, but compiles much more quickly:
74-
//
75-
// DIAG_TYPE_2_FIELD(type,
76-
// member_0, source_code_span_matcher(span_0),
77-
// member_1, source_code_span_matcher(span_1))
78-
//
79-
// but compiles much more quickly.
80-
#define DIAG_TYPE_2_SPANS(type, member_0, span_0, member_1, span_1) \
81-
::quick_lint_js::Diag_Spans_Matcher( \
82-
::quick_lint_js::Diag_Type::type, \
83-
::quick_lint_js::Diag_Spans_Matcher::Field{ \
84-
DIAG_MATCHER_ARG(type, member_0), \
85-
span_0, \
86-
}, \
87-
::quick_lint_js::Diag_Spans_Matcher::Field{ \
88-
DIAG_MATCHER_ARG(type, member_1), \
89-
span_1, \
90-
})
91-
9218
namespace quick_lint_js {
93-
class Offsets_Matcher {
94-
public:
95-
// Create an Offsets_Matcher which asserts that the matched Source_Code_Span
96-
// begins at begin_offset and ends at end_offset.
97-
explicit Offsets_Matcher(Padded_String_View input,
98-
CLI_Source_Position::Offset_Type begin_offset,
99-
CLI_Source_Position::Offset_Type end_offset);
100-
101-
// Create an Offsets_Matcher which asserts that the matched Source_Code_Span
102-
// begins at begin_offset and ends at begin_offset+strlen(text).
103-
//
104-
// TODO(strager): Also ensure the matched Source_Code_Span's content equals
105-
// text.
106-
explicit Offsets_Matcher(Padded_String_View input,
107-
CLI_Source_Position::Offset_Type begin_offset,
108-
String8_View text);
109-
110-
Offsets_Matcher(const Offsets_Matcher &) = delete;
111-
Offsets_Matcher &operator=(const Offsets_Matcher &) = delete;
112-
113-
Offsets_Matcher(Offsets_Matcher &&);
114-
Offsets_Matcher &operator=(Offsets_Matcher &&);
115-
116-
~Offsets_Matcher();
117-
118-
/*implicit*/ operator testing::Matcher<const Source_Code_Span &>() const;
119-
120-
private:
121-
class Span_Impl;
122-
123-
Padded_String_View code_;
124-
CLI_Source_Position::Offset_Type begin_offset_;
125-
CLI_Source_Position::Offset_Type end_offset_;
126-
};
127-
12819
// Metadata for a member of a diagnostic class.
12920
struct Diag_Matcher_Arg {
13021
std::string_view member_name;
@@ -160,52 +51,6 @@ struct Diag_Matcher_Arg {
16051
type::member)>(), \
16152
})
16253

163-
// A mix of ::testing::VariantWith, ::testing::Field, and Offsets_Matcher. These
164-
// are combined into one matcher to significantly reduce compile times.
165-
//
166-
// See DIAG_TYPE and DIAG_TYPE_OFFSETS for example usage.
167-
class Diag_Matcher {
168-
public:
169-
struct Field {
170-
// Must be Source_Code_Span.
171-
Diag_Matcher_Arg arg;
172-
173-
CLI_Source_Position::Offset_Type begin_offset;
174-
String8_View text;
175-
};
176-
177-
explicit Diag_Matcher(Diag_Type type);
178-
179-
// Create an Offsets_Matcher which asserts that an error's Source_Code_Span
180-
// begins at field.begin_offset and ends at
181-
// field.begin_offset+strlen(field.text).
182-
//
183-
// TODO(strager): Also ensure the error's Source_Code_Span's content equals
184-
// text.
185-
explicit Diag_Matcher(Padded_String_View input, Diag_Type type, Field);
186-
explicit Diag_Matcher(Padded_String_View input, Diag_Type type, Field, Field);
187-
explicit Diag_Matcher(Padded_String_View input, Diag_Type type, Field, Field,
188-
Field);
189-
190-
Diag_Matcher(const Diag_Matcher &) = default;
191-
Diag_Matcher(Diag_Matcher &&) = default;
192-
Diag_Matcher &operator=(const Diag_Matcher &) = default;
193-
Diag_Matcher &operator=(Diag_Matcher &&) = default;
194-
195-
/*implicit*/ operator testing::Matcher<const Diag_Collector::Diag &>() const;
196-
197-
private:
198-
class Impl;
199-
200-
struct State {
201-
Diag_Type type;
202-
std::optional<Padded_String_View> input;
203-
std::vector<Field> fields;
204-
};
205-
206-
State state_;
207-
};
208-
20954
struct Any_Diag_Pointer {
21055
Diag_Type type;
21156
const void *data;
@@ -260,43 +105,6 @@ class Diag_Matcher_2 {
260105

261106
State state_;
262107
};
263-
264-
// A mix of ::testing::VariantWith, ::testing::Field, and
265-
// source_code_span_matcher. These are combined into one matcher to
266-
// significantly reduce compile times.
267-
//
268-
// See DIAG_TYPE_SPAN for example usage.
269-
class Diag_Spans_Matcher {
270-
public:
271-
struct Field {
272-
// Must be Source_Code_Span.
273-
Diag_Matcher_Arg arg;
274-
275-
Source_Code_Span expected;
276-
};
277-
278-
// Create a matcher which asserts that an error's Source_Code_Span's
279-
// begin and end pointers equal the expected span.
280-
explicit Diag_Spans_Matcher(Diag_Type type, Field);
281-
explicit Diag_Spans_Matcher(Diag_Type type, Field, Field);
282-
283-
Diag_Spans_Matcher(const Diag_Spans_Matcher &) = default;
284-
Diag_Spans_Matcher(Diag_Spans_Matcher &&) = default;
285-
Diag_Spans_Matcher &operator=(const Diag_Spans_Matcher &) = default;
286-
Diag_Spans_Matcher &operator=(Diag_Spans_Matcher &&) = default;
287-
288-
/*implicit*/ operator testing::Matcher<const Diag_Collector::Diag &>() const;
289-
290-
private:
291-
class Impl;
292-
293-
struct State {
294-
Diag_Type type;
295-
std::vector<Field> fields;
296-
};
297-
298-
State state_;
299-
};
300108
}
301109

302110
// quick-lint-js finds bugs in JavaScript programs.

0 commit comments

Comments
 (0)