# frozen_string_literal: true require "test_helper" class ActionText::PlainTextConversionTest < ActiveSupport::TestCase test "
tags are separated by two new lines" do assert_converted_to( "Hello world!\n\nHow are you?", "
Hello world!
How are you?
" ) end test "tags are separated by two new lines" do assert_converted_to( "“Hello world!”\n\n“How are you?”", "Hello world!How are you?" ) end test "tags are separated by two new lines" do assert_converted_to( "Hello world!\n\n1. list1\n\n1. list2\n\nHow are you?", "
Hello world!
- list1
- list2
How are you?
" ) end test "tags are separated by two new lines" do assert_converted_to( "Hello world!\n\n• list1\n\n• list2\n\nHow are you?", "
Hello world!
- list1
- list2
How are you?
" ) end test "tags are separated by two new lines" do assert_converted_to( "Hello world!\n\nHow are you?", "
Hello world!
How are you?" ) end test "- tags are separated by one new line" do assert_converted_to( "• one\n• two\n• three", "
" ) end test "
- one
- two
- three
- tags without a parent list" do assert_converted_to( "• one\n• two\n• three", "
- one
- two
- three
" ) end test "basic nestedtags are indented" do assert_converted_to( "• Item 1\n • Item 2", "
" ) end test "basic nested
- Item 1
- Item 2
tags are indented" do assert_converted_to( "1. Item 1\n 1. Item 2", "
" ) end test "complex nested / mixed list tags are indented" do assert_converted_to( "• Item 0\n• Item 1\n • Item A\n 1. Item i\n 2. Item ii\n • Item B\n • Item i\n• Item 2", "
- Item 1
- Item 2
" ) end test "
- Item 0
- Item 1
- Item A
- Item i
- Item ii
- Item B
- Item i
- Item 2
tags are separated by one new line" do assert_converted_to( "Hello world!\none\ntwo\nthree", "Hello world!
" ) end test "
one
two
threetags are separated by one new line" do assert_converted_to( "Hello world!\nHow are you?", "Hello world!How are you?" ) end test "tags are converted to their plain-text representation" do assert_converted_to( "Hello world! [A condor in the mountain]", "Hello world! A condor in the mountain " ) end test "tags are converted to their plain-text representation" do assert_converted_to( "Hello world! [Cat]", 'Hello world! ' ) end test "deeply nested tags are converted" do assert_converted_to( "Hello world!\nHow are you?", ActionText::Fragment.wrap(" Hello world!").tap do |fragment| node = fragment.source.children.last 1_000.times do child = node.clone child.parent = node node = child end node.inner_html = "How are you?" end ) end test "preserves non-linebreak whitespace after text" do assert_converted_to( "Hello world!", "Hello world!" ) end test "preserves trailing linebreaks after text" do assert_converted_to( "Hello\nHow are you?", "Hello
How are you?" ) end private def assert_converted_to(plain_text, html) assert_equal plain_text, ActionText::Content.new(html).to_plain_text end end