# frozen_string_literal: true require "test_helper" class ParagraphTest < Minitest::Test include EzdocTestHelpers def test_simple_paragraph xml = create_doc_and_read_xml { |doc| doc.p "Hello World" } assert_includes xml, "" assert_includes xml, "" assert_includes xml, "").count end def test_paragraph_with_block_and_multiple_text_runs xml = create_doc_and_read_xml do |doc| doc.p do doc.text "Part one " doc.text "Part two " doc.text "Part three" end end assert_includes xml, "Part one " assert_includes xml, "Part two " assert_includes xml, "Part three" assert_equal 3, xml.scan("").count end def test_paragraph_preserves_whitespace xml = create_doc_and_read_xml do |doc| doc.p do doc.text " leading spaces" doc.text "trailing spaces " doc.text " both " end end assert_includes xml, 'xml:space="preserve"' assert_includes xml, " leading spaces" assert_includes xml, "trailing spaces " assert_includes xml, " both " end def test_paragraph_with_special_characters xml = create_doc_and_read_xml do |doc| doc.p "Special chars: <>&\"'" doc.p "Unicode: café, naïve, 日本語" end # XML should escape special characters assert_includes xml, "<" assert_includes xml, ">" assert_includes xml, "&" assert_includes xml, "café" assert_includes xml, "日本語" end def test_empty_paragraph_with_block xml = create_doc_and_read_xml do |doc| doc.p {} # rubocop:disable Lint/EmptyBlock end # Empty paragraph may be self-closing or have opening tag assert(xml.include?("") || xml.include?(""), "Should contain paragraph element") end def test_long_text_content long_text = "x" * 10_000 xml = create_doc_and_read_xml do |doc| doc.p long_text end assert_includes xml, long_text end def test_unicode_content xml = create_doc_and_read_xml do |doc| doc.p "Emoji: 🎉🚀💻" doc.p "Chinese: 你好世界" doc.p "Arabic: مرحبا بالعالم" doc.p "Russian: Привет мир" end assert_includes xml, "🎉🚀💻" assert_includes xml, "你好世界" assert_includes xml, "مرحبا بالعالم" assert_includes xml, "Привет мир" end def test_newlines_in_text xml = create_doc_and_read_xml do |doc| doc.p "Line 1\nLine 2\nLine 3" end # Newlines should be preserved in the text assert_includes xml, "Line 1\nLine 2\nLine 3" end end