Sha256: f31ac24774e32c0758329773e90f78c52bc6a721e924802710cb1d00c1d7888f

Contents?: true

Size: 1.56 KB

Versions: 5

Compression:

Stored size: 1.56 KB

Contents

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

module Wovnrb
  class TextReplacerTest < WovnMiniTest
    def test_replace
      store = Store.instance
      replacer = TextReplacer.new(store,{
        '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
      store = Store.instance
      replacer = TextReplacer.new(store, {
        '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
      store = Store.instance
      replacer = TextReplacer.new(store, {
        '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

5 entries across 5 versions & 1 rubygems

Version Path
wovnrb-1.0.11 test/lib/html_replacers/text_replacer_test.rb
wovnrb-1.0.10 test/lib/html_replacers/text_replacer_test.rb
wovnrb-1.0.9 test/lib/html_replacers/text_replacer_test.rb
wovnrb-1.0.8 test/lib/html_replacers/text_replacer_test.rb
wovnrb-1.0.7 test/lib/html_replacers/text_replacer_test.rb