Skip to content

Commit e848ab5

Browse files
committed
refactor(test): replace use of DIAG_TYPE_OFFSETS with DIAGNOSTIC_ASSERTION_SPAN
#1154
1 parent 56bdadb commit e848ab5

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

test/test-lex.cpp

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ class Test_Lex : public ::testing::Test {
5454
String8_View input, Diagnostic_Assertion,
5555
String8_View expected_identifier_name,
5656
Source_Location = Source_Location::current());
57+
void check_single_token_with_errors(
58+
String8_View input, Diagnostic_Assertion, Diagnostic_Assertion,
59+
String8_View expected_identifier_name,
60+
Source_Location = Source_Location::current());
61+
void check_single_token_with_errors(
62+
String8_View input, Span<const Diagnostic_Assertion>,
63+
String8_View expected_identifier_name,
64+
Source_Location = Source_Location::current());
5765
void check_tokens(String8_View input,
5866
std::initializer_list<Token_Type> expected_token_types,
5967
Source_Location = Source_Location::current());
@@ -1586,35 +1594,24 @@ TEST_F(Test_Lex, lex_identifier_with_out_of_range_escaped_character) {
15861594
TEST_F(Test_Lex, lex_identifier_with_out_of_range_utf_8_sequence) {
15871595
// f4 90 80 80 is U+110000
15881596
this->check_single_token_with_errors(
1589-
"too\xf4\x90\x80\x80\x62ig"_s8v, "too\xf4\x90\x80\x80\x62ig"_s8v,
1590-
[](Padded_String_View input, const auto& errors) {
1591-
EXPECT_THAT(
1592-
errors,
1593-
ElementsAreArray({
1594-
DIAG_TYPE_OFFSETS(input, Diag_Invalid_Utf_8_Sequence, //
1595-
sequence, std::strlen("too"),
1596-
"\xf4\x90\x80\x80"_s8v),
1597-
}));
1598-
});
1597+
"too\xf4\x90\x80\x80\x62ig"_s8v,
1598+
DIAGNOSTIC_ASSERTION_SPAN(Diag_Invalid_Utf_8_Sequence, //
1599+
sequence, std::strlen("too"),
1600+
"\xf4\x90\x80\x80"_s8v),
1601+
"too\xf4\x90\x80\x80\x62ig"_s8v);
15991602
}
16001603

16011604
TEST_F(Test_Lex, lex_identifier_with_malformed_utf_8_sequence) {
16021605
this->check_single_token_with_errors(
16031606
"illegal\xc0\xc1\xc2\xc3\xc4utf8\xfe\xff"_s8v,
1604-
"illegal\xc0\xc1\xc2\xc3\xc4utf8\xfe\xff"_s8v,
1605-
[](Padded_String_View input, const auto& errors) {
1606-
EXPECT_THAT(
1607-
errors,
1608-
ElementsAreArray({
1609-
DIAG_TYPE_OFFSETS(input, Diag_Invalid_Utf_8_Sequence, //
1610-
sequence, std::strlen("illegal"),
1611-
"\xc0\xc1\xc2\xc3\xc4"_s8v),
1612-
DIAG_TYPE_OFFSETS(
1613-
input, Diag_Invalid_Utf_8_Sequence, //
1614-
sequence, std::strlen("illegal\xc0\xc1\xc2\xc3\xc4utf8"),
1615-
"\xfe\xff"_s8v),
1616-
}));
1617-
});
1607+
DIAGNOSTIC_ASSERTION_SPAN(Diag_Invalid_Utf_8_Sequence, //
1608+
sequence, std::strlen("illegal"),
1609+
"\xc0\xc1\xc2\xc3\xc4"_s8v),
1610+
DIAGNOSTIC_ASSERTION_SPAN(Diag_Invalid_Utf_8_Sequence, //
1611+
sequence,
1612+
std::strlen("illegal\xc0\xc1\xc2\xc3\xc4utf8"),
1613+
"\xfe\xff"_s8v),
1614+
"illegal\xc0\xc1\xc2\xc3\xc4utf8\xfe\xff"_s8v);
16181615
}
16191616

16201617
TEST_F(Test_Lex, lex_identifier_with_disallowed_character_escape_sequence) {
@@ -2988,6 +2985,22 @@ void Test_Lex::check_single_token_with_errors(
29882985
void Test_Lex::check_single_token_with_errors(
29892986
String8_View input, Diagnostic_Assertion diag0,
29902987
String8_View expected_identifier_name, Source_Location caller) {
2988+
return this->check_single_token_with_errors(
2989+
input, Span<const Diagnostic_Assertion>({diag0}),
2990+
expected_identifier_name, caller);
2991+
}
2992+
2993+
void Test_Lex::check_single_token_with_errors(
2994+
String8_View input, Diagnostic_Assertion diag0, Diagnostic_Assertion diag1,
2995+
String8_View expected_identifier_name, Source_Location caller) {
2996+
return this->check_single_token_with_errors(
2997+
input, Span<const Diagnostic_Assertion>({diag0, diag1}),
2998+
expected_identifier_name, caller);
2999+
}
3000+
3001+
void Test_Lex::check_single_token_with_errors(
3002+
String8_View input, Span<const Diagnostic_Assertion> diagnostic_assertions,
3003+
String8_View expected_identifier_name, Source_Location caller) {
29913004
Padded_String code(input);
29923005
Diag_List_Diag_Reporter errors(&this->memory_);
29933006
std::vector<Token> lexed_tokens = this->lex_to_eof(&code, errors);
@@ -3006,7 +3019,7 @@ void Test_Lex::check_single_token_with_errors(
30063019
expected_identifier_name);
30073020
}
30083021

3009-
assert_diagnostics(&code, errors.diags(), {diag0}, caller);
3022+
assert_diagnostics(&code, errors.diags(), diagnostic_assertions, caller);
30103023
}
30113024

30123025
void Test_Lex::check_tokens(

0 commit comments

Comments
 (0)