# frozen_string_literal: true require_relative "../test_helper" module Parser class TextContentTest < Minitest::Spec include SnapshotUtils test "text content" do assert_parsed_snapshot("Hello World") end test "text content inside tag" do assert_parsed_snapshot("

Hello World

") end test "text content with tag after" do assert_parsed_snapshot("HelloWorld") end test "text content with tag before" do assert_parsed_snapshot("HelloWorld") end test "text content with tag around" do assert_parsed_snapshot("HelloWorld") end test "text content that exceeds initial hb_buffer_T size (ca. 4K)" do initial_hb_buffer_capacity = 1024 # bytes content = cyclic_string((((initial_hb_buffer_capacity * 2) + 1) * 2) + 1) result = assert_parsed_snapshot(%(
#{content}
)) assert_equal content, result.value.children.first.body.first.content end test "text content that exceeds initial hb_buffer_T size (ca. 8K)" do initial_hb_buffer_capacity = 1024 # bytes content = cyclic_string((((((initial_hb_buffer_capacity * 2) + 1) * 2) + 1) * 2) + 1) result = assert_parsed_snapshot(%(
#{content}
)) assert_equal content, result.value.children.first.body.first.content end test "exclamation as only content" do assert_parsed_snapshot("!") end test "comma as only content" do assert_parsed_snapshot(",") end test "dollar sign as only content" do assert_parsed_snapshot("$") end test "dash as only content" do assert_parsed_snapshot("-") end test "period as only content" do assert_parsed_snapshot(".") end test "percent as only content" do assert_parsed_snapshot("%") end test "slash as only content" do assert_parsed_snapshot("/") end test "underscore as only content" do assert_parsed_snapshot("_") end test "colon as only content" do assert_parsed_snapshot(":") end test "semicolon as only content" do assert_parsed_snapshot(";") end test "ampersand as only content" do assert_parsed_snapshot("&") end test "equals as only content" do assert_parsed_snapshot("=") end test "a-umlaut as only content" do assert_parsed_snapshot("ä") end test "o-umlaut as only content" do assert_parsed_snapshot("ö") end test "u-umlaut as only content" do assert_parsed_snapshot("ü") end test "emoji as only content" do assert_parsed_snapshot("🌿") end test "non-breaking space (U+00A0) as only content" do assert_parsed_snapshot(" ") end test "non-breaking space mixed with ERB - issue 310" do assert_parsed_snapshot("

<%= hello %> !

") end test "multiple non-breaking spaces in text" do assert_parsed_snapshot("

Hello World

") end test "non-breaking space in attribute value" do assert_parsed_snapshot('
Content
') end test "at symbol (@) in text content - issue 285" do assert_parsed_snapshot("

Did we get it wrong? Respond with @reverse to remove the receipt.

") end test "at symbol at beginning of text" do assert_parsed_snapshot("@username") end test "multiple at symbols in text" do assert_parsed_snapshot("

Email me @john@example.com

") end test "at symbol mixed with ERB" do assert_parsed_snapshot("

Contact <%= user.name %> @support

") end test "at symbol in attribute value" do assert_parsed_snapshot('Contact @support') end test "backtick with HTML tags - issue 467" do assert_parsed_snapshot("a `` c") end test "backslash-prefixed text stays literal - issue 635" do assert_parsed_snapshot("

\\Asome-regexp\\z

") end # https://github.com/lobsters/lobsters/blob/75f9a53077d5aeaeadbb8271def0479dd8fcd761/app/views/domains/edit.html.erb#L11 test "backslash-prefixed text - issue 633" do assert_parsed_snapshot <<~HTML

Regexp with captures, must consume whole string like: \\Ahttps?://github.com/+([^/]+).*\\z

HTML end test "greater than sign as text content - issue 914" do assert_parsed_snapshot(">") end test "greater than sign in text content" do assert_parsed_snapshot("

5 > 3

") end test "multiple greater than signs in text content" do assert_parsed_snapshot("a >> b") end test "greater than sign at start of text content" do assert_parsed_snapshot("> quote") end test "less than sign as text content" do assert_parsed_snapshot("<") end test "less than sign in text content" do assert_parsed_snapshot("

5 < 3

") end test "multiple less than signs in text content" do assert_parsed_snapshot("<<") end test "less than sign at start of text content" do assert_parsed_snapshot("< quote") end test "less than and greater than in text content" do assert_parsed_snapshot("

a < b > c

") end test "arrow in text content" do assert_parsed_snapshot("a -> b") end test "generic syntax in text content" do assert_parsed_snapshot("Array") end test "less than followed by space" do assert_parsed_snapshot("

< /span>

") end test "less than followed by number" do assert_parsed_snapshot("

<5

") end test "triple less than" do assert_parsed_snapshot("<<<") end test "heredoc style" do assert_parsed_snapshot("<<~HTML") end test "bit shift operators" do assert_parsed_snapshot("x << 2 >> 1") end test "spaceship operator" do assert_parsed_snapshot("a <=> b") end test "not equal operator" do assert_parsed_snapshot("a <> b") end test "less than or equal" do assert_parsed_snapshot("a <= b") end test "greater than or equal" do assert_parsed_snapshot("a >= b") end test "xml-like content in code" do assert_parsed_snapshot("") end test "template literal style" do assert_parsed_snapshot("${value}") end end end