require 'test_helper' module Wovnrb class HtmlReplaceMarkerTest < WovnMiniTest def test_add_comment_value marker = HtmlReplaceMarker.new assert_equal('', marker.add_comment_value('hello')) end def test_add_comment_value_multiple_times maker = HtmlReplaceMarker.new assert_equal('', maker.add_comment_value('hello')) assert_equal('', maker.add_comment_value('hello')) assert_equal('', maker.add_comment_value('hello')) assert_equal('', maker.add_comment_value('hello')) end def test_add_same_comment_value_multiple_times marker = HtmlReplaceMarker.new 25.times do |i| assert_equal("", marker.add_comment_value('hello')) end end def test_revert marker = HtmlReplaceMarker.new original_html = '
hello replacement world ' key = marker.add_comment_value('hello') new_html = original_html.sub('hello', key) assert_equal("#{key} replacement world ", new_html) assert_equal(original_html, marker.revert(new_html)) end def test_revert_multiple_values marker = HtmlReplaceMarker.new original_html = 'hello replacement world ' key1 = marker.add_comment_value('hello') key2 = marker.add_comment_value('replacement') key3 = marker.add_comment_value('world') new_html = original_html.sub('hello', key1) new_html = new_html.sub('replacement', key2).sub('world', key3) assert_equal("#{key1} #{key2} #{key3} ", new_html) assert_equal(original_html, marker.revert(new_html)) end def test_revert_multiple_similar_values marker = HtmlReplaceMarker.new original_html = '' 25.times { |i| original_html += "hello_#{i}" } original_html += '' new_html = original_html keys = [] 25.times do |i| key = marker.add_comment_value("hello_#{i}") keys << key new_html = new_html.sub("hello_#{i}", key) end assert_equal(false, new_html.include?('hello')) assert_equal(original_html, marker.revert(new_html)) end def test_revert_same_value marker = HtmlReplaceMarker.new original_html = 'hellohellohello' key1 = marker.add_comment_value('hello') key2 = marker.add_comment_value('hello') key3 = marker.add_comment_value('hello') new_html = "#{key1}#{key2}#{key3}" assert_equal(original_html, marker.revert(new_html)) end end end