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