# frozen_string_literal: true require_relative "../test_helper" module Parser class ScriptStyleTest < Minitest::Spec include SnapshotUtils test "script tag with less than comparison" do assert_parsed_snapshot(%()) end test "script tag with greater than comparison" do assert_parsed_snapshot(%()) end test "script tag with HTML in string literal" do assert_parsed_snapshot(%()) end test "script tag with HTML in comment" do assert_parsed_snapshot(%()) end test "script tag with multiline comment containing HTML" do assert_parsed_snapshot(<<~HTML) HTML end test "script tag with ERB-like content in string" do # TODO: this is not right yet assert_parsed_snapshot(%()) end test "script tag with incomplete ERB-like content" do assert_parsed_snapshot(%()) end test "script tag with closing script tag in string" do assert_parsed_snapshot(%(";)) end test "script tag with escaped closing tag in string" do assert_parsed_snapshot(%()) end test "script tag with actual ERB interpolation" do assert_parsed_snapshot(%()) end test "script tag with multiple ERB interpolations" do assert_parsed_snapshot(<<~HTML) HTML end test "script tag with complex JavaScript including comparisons and HTML strings" do assert_parsed_snapshot(<<~HTML) HTML end test "style tag with child selector" do assert_parsed_snapshot(%()) end test "style tag with attribute selector containing HTML" do assert_parsed_snapshot(%()) end test "style tag with content property containing HTML" do assert_parsed_snapshot(%()) end test "style tag with ERB interpolation" do assert_parsed_snapshot(%()) end test "style tag with complex CSS including HTML-like content" do assert_parsed_snapshot(<<~HTML) HTML end test "nested script tags (inner in string)" do assert_parsed_snapshot(<<~HTML) HTML end test "script tag with regex containing angle brackets" do assert_parsed_snapshot(%()) end test "style tag with media query and nested selectors" do assert_parsed_snapshot(<<~HTML) HTML end test "script tag with template literals containing HTML" do assert_parsed_snapshot(<<~HTML) HTML end test "script tag with JSX-like syntax" do assert_parsed_snapshot(<<~HTML) HTML end test "empty script and style tags" do assert_parsed_snapshot(%()) end test "script tag followed by style tag with complex content" do assert_parsed_snapshot(<<~HTML) HTML end test "script tag with minified JavaScript containing many angle brackets" do assert_parsed_snapshot(%()) end test "script tag with JSON containing HTML" do assert_parsed_snapshot(<<~HTML) HTML end test "style tag with CSS custom properties and calc" do assert_parsed_snapshot(<<~HTML) HTML end test "script tag with incomplete ERB tag at end" do assert_parsed_snapshot(%()) end test "script tag with only ERB-like characters" do assert_parsed_snapshot(%()) end test "real world example - Google Analytics" do assert_parsed_snapshot(<<~HTML) HTML end test "real world example - Klaviyo script from issue 271" do assert_parsed_snapshot(<<~HTML) HTML end test "script tag with single quote strings containing closing tags" do assert_parsed_snapshot(%('; var s2 = '';)) end test "script tag with double quote strings containing closing tags" do assert_parsed_snapshot(%("; var s2 = "";)) end test "script tag with template literals containing closing tags" do assert_parsed_snapshot(%(`;)) end test "script tag with escaped quotes in strings" do assert_parsed_snapshot(%(\\" yesterday";)) end test "style tag with quotes containing HTML-like content" do assert_parsed_snapshot(%("; })) end test "script tag with mixed quote types and closing tags" do assert_parsed_snapshot(<<~HTML) '; var double = ""; console.log("All strings parsed correctly"); HTML end test "script tag with ERB inside string literals (ERB always processed)" do assert_parsed_snapshot(<<~HTML) HTML end test "script tag with ERB outside vs inside strings" do assert_parsed_snapshot(<<~HTML) HTML end test "script tag with ERB in double quotes" do assert_parsed_snapshot(%()) end test "script tag with ERB in single quotes" do assert_parsed_snapshot(%()) end test "script tag with ERB in template literals" do assert_parsed_snapshot(%()) end test "script tag with multiple ERB tags in one string" do assert_parsed_snapshot(%()) end test "script tag with ERB in different quote types same line" do assert_parsed_snapshot(%()) end test "style tag with ERB in CSS strings" do assert_parsed_snapshot(<<~HTML) HTML end test "script tag with closing tag in single-line comment" do assert_parsed_snapshot(<<~HTML) HTML end test "script tag with closing tag in multi-line comment" do assert_parsed_snapshot(<<~HTML) */ HTML end test "script tag with closing tag in complex multi-line comment" do assert_parsed_snapshot(<<~HTML) inside * and some more content */ console.log("actual code"); HTML end test "script tag with mixed comments and strings" do assert_parsed_snapshot(<<~HTML) var str = "String with "; /* Multi-line comment with inside */ var another = 'Single quote '; HTML end test "script tag with nested comment markers" do assert_parsed_snapshot(<<~HTML) HTML end test "script tag with ERB in comments" do assert_parsed_snapshot(<<~HTML) HTML end test "script tag with complex multi-line comment containing closing tag" do assert_parsed_snapshot(<<~HTML) */ HTML end test "script tag with template literal containing closing tag (multiline)" do assert_parsed_snapshot(<<~HTML) ` HTML end test "script tag with closing tag on comment line" do assert_parsed_snapshot(<<~HTML)
Before
After
HTML end test "script tag with closing div tag in string" do assert_parsed_snapshot(%()) end end end