diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index aab90eee86..5baeea81c8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -140,6 +140,7 @@ quick_lint_js_add_executable( test-parse-expression-typescript.cpp test-parse-expression.cpp test-parse-function.cpp + test-parse-jsx-react.cpp test-parse-jsx.cpp test-parse-loop.cpp test-parse-module.cpp diff --git a/test/test-parse-jsx-react.cpp b/test/test-parse-jsx-react.cpp new file mode 100644 index 0000000000..0ca0cbc968 --- /dev/null +++ b/test/test-parse-jsx-react.cpp @@ -0,0 +1,112 @@ +// Copyright (C) 2020 Matthew "strager" Glazar +// See end of file for extended copyright information. + +#include +#include +#include +#include +#include +#include + +namespace quick_lint_js { +namespace { +class Test_Parse_JSX_React : public Test_Parse_Expression {}; + +TEST_F(Test_Parse_JSX_React, correctly_capitalized_attribute) { + test_parse_and_visit_module(u8R"(c = ;)"_sv, no_diags, + jsx_options); + + test_parse_and_visit_module(u8R"(c =
;)"_sv, + no_diags, jsx_options); +} + +TEST_F(Test_Parse_JSX_React, event_attributes_should_be_camel_case) { + test_parse_and_visit_module( + u8"c =
;"_sv, // + u8" ^^^^^^^ Diag_JSX_Event_Attribute_Should_Be_Camel_Case.attribute_name"_diag + u8"{.expected_attribute_name=onClick}"_diag, // + jsx_options); + + // TODO(strager): Should we also report that the handler's value is missing? + test_parse_and_visit_module( + u8"c =
;"_sv, // + u8" ^^^^^^^ Diag_JSX_Event_Attribute_Should_Be_Camel_Case.attribute_name"_diag + u8"{.expected_attribute_name=onClick}"_diag, // + jsx_options); + + test_parse_and_visit_module( + u8"c =
;"_sv, // + u8" ^^^^^^^^^^^^ Diag_JSX_Event_Attribute_Should_Be_Camel_Case.attribute_name"_diag + u8"{.expected_attribute_name=onMouseEnter}"_diag, // + jsx_options); + + test_parse_and_visit_module( + u8"c =
;"_sv, // + u8" ^^^^^^^^^^^^^ Diag_JSX_Event_Attribute_Should_Be_Camel_Case.attribute_name"_diag + u8"{.expected_attribute_name=onCustomevent}"_diag, // + jsx_options); +} + +TEST_F(Test_Parse_JSX_React, miscapitalized_attribute) { + test_parse_and_visit_module( + u8"c = ;"_sv, // + u8" ^^^^^^^ Diag_JSX_Attribute_Has_Wrong_Capitalization.attribute_name"_diag + u8"{.expected_attribute_name=colSpan}"_diag, // + jsx_options); + + test_parse_and_visit_module( + u8"c =
;"_sv, // + u8" ^^^^^^^^^^^^ Diag_JSX_Attribute_Has_Wrong_Capitalization.attribute_name"_diag + u8"{.expected_attribute_name=onMouseEnter}"_diag, // + jsx_options); + + test_parse_and_visit_module( + u8"c =
;"_sv, // + u8" ^^^^^^^^^^^^ Diag_JSX_Attribute_Has_Wrong_Capitalization.attribute_name"_diag + u8"{.expected_attribute_name=onMouseEnter}"_diag, // + jsx_options); +} + +TEST_F(Test_Parse_JSX_React, commonly_misspelled_attribute) { + test_parse_and_visit_module( + u8"c = ;"_sv, // + u8" ^^^^^ Diag_JSX_Attribute_Renamed_By_React.attribute_name"_diag + u8"{.react_attribute_name=className}"_diag, // + jsx_options); +} + +TEST_F(Test_Parse_JSX_React, attribute_checking_ignores_namespaced_attributes) { + test_parse_and_visit_module(u8R"(c =
;)"_sv, + no_diags, jsx_options); + test_parse_and_visit_module( + u8R"(c =
;)"_sv, no_diags, + jsx_options); + test_parse_and_visit_module(u8R"(c =
;)"_sv, + no_diags, jsx_options); +} + +TEST_F(Test_Parse_JSX_React, attribute_checking_ignores_namespaced_elements) { + test_parse_and_visit_module(u8R"(c = ;)"_sv, + no_diags, jsx_options); + test_parse_and_visit_module(u8R"(c = ;)"_sv, no_diags, + jsx_options); +} + +TEST_F(Test_Parse_JSX_React, attribute_checking_ignores_user_components) { + test_parse_and_visit_module( + u8R"(c = ;)"_sv, no_diags, + jsx_options); + + test_parse_and_visit_module(u8R"(c = ;)"_sv, + no_diags, jsx_options); + + test_parse_and_visit_module( + u8R"(c = ;)"_sv, no_diags, + jsx_options); + + test_parse_and_visit_module( + u8R"(c = ;)"_sv, no_diags, + jsx_options); +} +} +} diff --git a/test/test-parse-jsx.cpp b/test/test-parse-jsx.cpp index 04937820ff..41d2b6189a 100644 --- a/test/test-parse-jsx.cpp +++ b/test/test-parse-jsx.cpp @@ -448,103 +448,6 @@ TEST_F(Test_Parse_JSX, adjacent_tags_without_outer_fragment) { } } -TEST_F(Test_Parse_JSX, correctly_capitalized_attribute) { - test_parse_and_visit_module(u8R"(c = ;)"_sv, no_diags, - jsx_options); - - test_parse_and_visit_module(u8R"(c =
;)"_sv, - no_diags, jsx_options); -} - -TEST_F(Test_Parse_JSX, event_attributes_should_be_camel_case) { - test_parse_and_visit_module( - u8"c =
;"_sv, // - u8" ^^^^^^^ Diag_JSX_Event_Attribute_Should_Be_Camel_Case.attribute_name"_diag - u8"{.expected_attribute_name=onClick}"_diag, // - jsx_options); - - // TODO(strager): Should we also report that the handler's value is missing? - test_parse_and_visit_module( - u8"c =
;"_sv, // - u8" ^^^^^^^ Diag_JSX_Event_Attribute_Should_Be_Camel_Case.attribute_name"_diag - u8"{.expected_attribute_name=onClick}"_diag, // - jsx_options); - - test_parse_and_visit_module( - u8"c =
;"_sv, // - u8" ^^^^^^^^^^^^ Diag_JSX_Event_Attribute_Should_Be_Camel_Case.attribute_name"_diag - u8"{.expected_attribute_name=onMouseEnter}"_diag, // - jsx_options); - - test_parse_and_visit_module( - u8"c =
;"_sv, // - u8" ^^^^^^^^^^^^^ Diag_JSX_Event_Attribute_Should_Be_Camel_Case.attribute_name"_diag - u8"{.expected_attribute_name=onCustomevent}"_diag, // - jsx_options); -} - -TEST_F(Test_Parse_JSX, miscapitalized_attribute) { - test_parse_and_visit_module( - u8"c = ;"_sv, // - u8" ^^^^^^^ Diag_JSX_Attribute_Has_Wrong_Capitalization.attribute_name"_diag - u8"{.expected_attribute_name=colSpan}"_diag, // - jsx_options); - - test_parse_and_visit_module( - u8"c =
;"_sv, // - u8" ^^^^^^^^^^^^ Diag_JSX_Attribute_Has_Wrong_Capitalization.attribute_name"_diag - u8"{.expected_attribute_name=onMouseEnter}"_diag, // - jsx_options); - - test_parse_and_visit_module( - u8"c =
;"_sv, // - u8" ^^^^^^^^^^^^ Diag_JSX_Attribute_Has_Wrong_Capitalization.attribute_name"_diag - u8"{.expected_attribute_name=onMouseEnter}"_diag, // - jsx_options); -} - -TEST_F(Test_Parse_JSX, commonly_misspelled_attribute) { - test_parse_and_visit_module( - u8"c = ;"_sv, // - u8" ^^^^^ Diag_JSX_Attribute_Renamed_By_React.attribute_name"_diag - u8"{.react_attribute_name=className}"_diag, // - jsx_options); -} - -TEST_F(Test_Parse_JSX, attribute_checking_ignores_namespaced_attributes) { - test_parse_and_visit_module(u8R"(c =
;)"_sv, - no_diags, jsx_options); - test_parse_and_visit_module( - u8R"(c =
;)"_sv, no_diags, - jsx_options); - test_parse_and_visit_module(u8R"(c =
;)"_sv, - no_diags, jsx_options); -} - -TEST_F(Test_Parse_JSX, attribute_checking_ignores_namespaced_elements) { - test_parse_and_visit_module(u8R"(c = ;)"_sv, - no_diags, jsx_options); - test_parse_and_visit_module(u8R"(c = ;)"_sv, no_diags, - jsx_options); -} - -TEST_F(Test_Parse_JSX, attribute_checking_ignores_user_components) { - test_parse_and_visit_module( - u8R"(c = ;)"_sv, no_diags, - jsx_options); - - test_parse_and_visit_module(u8R"(c = ;)"_sv, - no_diags, jsx_options); - - test_parse_and_visit_module( - u8R"(c = ;)"_sv, no_diags, - jsx_options); - - test_parse_and_visit_module( - u8R"(c = ;)"_sv, no_diags, - jsx_options); -} - TEST_F(Test_Parse_JSX, prop_needs_an_expression) { test_parse_and_visit_module( u8"c = ;"_sv, //