Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
msharipov committed Mar 14, 2024
1 parent 9e034a4 commit 313e1cf
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 8 deletions.
4 changes: 4 additions & 0 deletions po/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2417,6 +2417,10 @@ msgstr ""
msgid "namespace alias cannot use 'import type'"
msgstr ""

#: src/quick-lint-js/diag/diagnostic-metadata-generated.cpp
msgid "invalid syntax; missing parentheses around {0}"
msgstr ""

#: test/test-diagnostic-formatter.cpp
#: test/test-vim-qflist-json-diag-reporter.cpp
msgid "something happened"
Expand Down
14 changes: 14 additions & 0 deletions src/quick-lint-js/diag/diagnostic-metadata-generated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6929,6 +6929,20 @@ const QLJS_CONSTINIT Diagnostic_Info all_diagnostic_infos[] = {
},
},
},

// Diag_To_String_After_Increment
{
.code = 721,
.severity = Diagnostic_Severity::error,
.message_formats = {
QLJS_TRANSLATABLE("invalid syntax; missing parentheses around {0}"),
},
.message_args = {
{
Diagnostic_Message_Arg_Info(offsetof(Diag_To_String_After_Increment, increment), Diagnostic_Arg_Type::source_code_span),
},
},
},
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/quick-lint-js/diag/diagnostic-metadata-generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,11 @@ namespace quick_lint_js {
QLJS_DIAG_TYPE_NAME(Diag_Multiple_Export_Defaults) \
QLJS_DIAG_TYPE_NAME(Diag_Unintuitive_Bitshift_Precedence) \
QLJS_DIAG_TYPE_NAME(Diag_TypeScript_Namespace_Alias_Cannot_Use_Import_Type) \
QLJS_DIAG_TYPE_NAME(Diag_To_String_After_Increment) \
/* END */
// clang-format on

inline constexpr int Diag_Type_Count = 462;
inline constexpr int Diag_Type_Count = 463;

extern const Diagnostic_Info all_diagnostic_infos[Diag_Type_Count];
}
Expand Down
6 changes: 3 additions & 3 deletions src/quick-lint-js/diag/diagnostic-types-2.h
Original file line number Diff line number Diff line change
Expand Up @@ -3603,11 +3603,11 @@ struct Diag_TypeScript_Namespace_Alias_Cannot_Use_Import_Type {
Source_Code_Span type_keyword;
};

struct Diag_To_String_After_Increment {
struct Diag_To_String_After_Postfix {
[[qljs::diag("E0721", Diagnostic_Severity::error)]] //
[[qljs::message("invalid syntax; missing parentheses around {0}",
ARG(increment))]] //
Source_Code_Span increment;
ARG(postfix_expression))]] //
Source_Code_Span postfix_expression;
};
}
QLJS_WARNING_POP
Expand Down
4 changes: 3 additions & 1 deletion src/quick-lint-js/i18n/translation-table-generated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ const Translation_Table translation_data = {
{47, 43, 47, 54, 35, 38}, //
{31, 39, 32, 33, 28, 27}, //
{34, 15, 43, 40, 37, 33}, //
{39, 51, 50, 40, 38, 39}, //
{0, 0, 0, 0, 0, 39}, //
{39, 51, 50, 40, 38, 47}, //
{57, 72, 67, 55, 0, 41}, //
{0, 0, 0, 58, 0, 50}, //
{0, 0, 0, 22, 0, 19}, //
Expand Down Expand Up @@ -2235,6 +2236,7 @@ const Translation_Table translation_data = {
u8"invalid function parameter\0"
u8"invalid hex escape sequence: {0}\0"
u8"invalid lone literal in object literal\0"
u8"invalid syntax; missing parentheses around {0}\0"
u8"keywords cannot contain escape sequences\0"
u8"label named 'await' not allowed in async function\0"
u8"labelled statement\0"
Expand Down
5 changes: 3 additions & 2 deletions src/quick-lint-js/i18n/translation-table-generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ namespace quick_lint_js {
using namespace std::literals::string_view_literals;

constexpr std::uint32_t translation_table_locale_count = 5;
constexpr std::uint16_t translation_table_mapping_table_size = 606;
constexpr std::size_t translation_table_string_table_size = 82441;
constexpr std::uint16_t translation_table_mapping_table_size = 607;
constexpr std::size_t translation_table_string_table_size = 82488;
constexpr std::size_t translation_table_locale_table_size = 35;

QLJS_CONSTEVAL std::uint16_t translation_table_const_look_up(
Expand Down Expand Up @@ -378,6 +378,7 @@ QLJS_CONSTEVAL std::uint16_t translation_table_const_look_up(
"invalid function parameter"sv,
"invalid hex escape sequence: {0}"sv,
"invalid lone literal in object literal"sv,
"invalid syntax; missing parentheses around {0}"sv,
"keywords cannot contain escape sequences"sv,
"label named 'await' not allowed in async function"sv,
"labelled statement"sv,
Expand Down
13 changes: 12 additions & 1 deletion src/quick-lint-js/i18n/translation-table-test-generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct Translated_String {
};

// clang-format off
inline const Translated_String test_translation_table[605] = {
inline const Translated_String test_translation_table[606] = {
{
"\"global-groups\" entries must be strings"_translatable,
u8"\"global-groups\" entries must be strings",
Expand Down Expand Up @@ -3900,6 +3900,17 @@ inline const Translated_String test_translation_table[605] = {
u8"ogiltigt l\u00e5neuttryck i objektliteral",
},
},
{
"invalid syntax; missing parentheses around {0}"_translatable,
u8"invalid syntax; missing parentheses around {0}",
{
u8"invalid syntax; missing parentheses around {0}",
u8"invalid syntax; missing parentheses around {0}",
u8"invalid syntax; missing parentheses around {0}",
u8"invalid syntax; missing parentheses around {0}",
u8"invalid syntax; missing parentheses around {0}",
},
},
{
"keywords cannot contain escape sequences"_translatable,
u8"keywords cannot contain escape sequences",
Expand Down
9 changes: 9 additions & 0 deletions test/test-parse-warning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,15 @@ TEST_F(Test_Parse_Warning, early_exit_does_not_trigger_fallthrough_warning) {
no_diags);
}
}

TEST_F(Test_Parse_Warning, to_string_called_directly_after_postfix) {
test_parse_and_visit_expression(
u8"x++.toString()"_sv, //
u8"^^^ Diag_To_String_After_Postfix"_diag);
test_parse_and_visit_expression(
u8"(x++).toString()"_sv,
no_diags);
}
}
}

Expand Down

0 comments on commit 313e1cf

Please sign in to comment.