Sha256: 1da44cbc037c05275d51c09547f42e771aab1ed7fb999809f0edbb720779c394

Contents?: true

Size: 1.45 KB

Versions: 24

Compression:

Stored size: 1.45 KB

Contents

# -*- encoding: UTF-8 -*-
require 'test_helper'
require 'webmock/minitest'

module Wovnrb
  class TextReplacerTest < WovnMiniTest
    def test_replace
      replacer = TextReplacer.new({
        'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
      })

      dom = Wovnrb.get_dom('Hello')
      replacer.replace(dom, Lang.new('ja'))

      node = dom.xpath('//text()')[0]
      assert_equal('こんにちは', node.content)
      assert_equal('wovn-src:Hello', node.previous.content)
    end

    def test_replace_multiple
      replacer = TextReplacer.new({
        'Hello' => {'ja' => [{'data' => 'こんにちは'}]},
        'Bye' => {'ja' => [{'data' => 'さようなら'}]}
      })

      dom = Wovnrb.get_dom('<span>Hello</span><span>Bye</span>')
      replacer.replace(dom, Lang.new('ja'))

      node = dom.xpath('//text()')[0]
      node2 = dom.xpath('//text()')[1]
      assert_equal('こんにちは', node.content)
      assert_equal('wovn-src:Hello', node.previous.content)
      assert_equal('さようなら', node2.content)
      assert_equal('wovn-src:Bye', node2.previous.content)
    end

    def test_replace_wovn_ignore
      replacer = TextReplacer.new({
        'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
      })

      dom = Wovnrb.get_dom('<div wovn-ignore>Hello</div>')
      replacer.replace(dom, Lang.new('ja'))

      node = dom.xpath('//text()')[0]
      assert_equal('Hello', node.content)
      assert_nil(node.previous)
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
wovnrb-1.0.6 test/lib/html_replacers/text_replacer_test.rb
wovnrb-1.0.5 test/lib/html_replacers/text_replacer_test.rb
wovnrb-1.0.4 test/lib/html_replacers/text_replacer_test.rb
wovnrb-1.0.2 test/lib/html_replacers/text_replacer_test.rb
wovnrb-1.0.1 test/lib/html_replacers/text_replacer_test.rb
wovnrb-1.0.0 test/lib/html_replacers/text_replacer_test.rb
wovnrb-0.2.30 test/lib/html_replacers/text_replacer_test.rb
wovnrb-0.2.29 test/lib/html_replacers/text_replacer_test.rb
wovnrb-0.2.28 test/lib/html_replacers/text_replacer_test.rb
wovnrb-0.2.27 test/lib/html_replacers/text_replacer_test.rb
wovnrb-0.2.26 test/lib/html_replacers/text_replacer_test.rb
wovnrb-0.2.25 test/lib/html_replacers/text_replacer_test.rb
wovnrb-0.2.24 test/lib/html_replacers/text_replacer_test.rb
wovnrb-0.2.23 test/lib/html_replacers/text_replacer_test.rb
wovnrb-0.2.22 test/lib/html_replacers/text_replacer_test.rb
wovnrb-0.2.21 test/lib/html_replacers/text_replacer_test.rb
wovnrb-0.2.20 test/lib/html_replacers/text_replacer_test.rb
wovnrb-0.2.19 test/lib/html_replacers/text_replacer_test.rb
wovnrb-0.2.18 test/lib/html_replacers/text_replacer_test.rb
wovnrb-0.2.17 test/lib/html_replacers/text_replacer_test.rb