wovnrb 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +1 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +308 -0
- data/Rakefile +13 -14
- data/lib/wovnrb.rb +43 -98
- data/lib/wovnrb/api_translator.rb +143 -0
- data/lib/wovnrb/headers.rb +78 -92
- data/lib/wovnrb/helpers/nokogumbo_helper.rb +1 -1
- data/lib/wovnrb/lang.rb +93 -125
- data/lib/wovnrb/railtie.rb +5 -7
- data/lib/wovnrb/services/glob.rb +3 -3
- data/lib/wovnrb/services/html_converter.rb +192 -0
- data/lib/wovnrb/services/html_replace_marker.rb +38 -0
- data/lib/wovnrb/services/wovn_logger.rb +8 -4
- data/lib/wovnrb/settings.rb +5 -3
- data/lib/wovnrb/store.rb +35 -26
- data/lib/wovnrb/text_caches/cache_base.rb +3 -2
- data/lib/wovnrb/text_caches/memory_cache.rb +2 -2
- data/lib/wovnrb/version.rb +1 -1
- data/test/fixtures/html/test.html +8 -0
- data/test/fixtures/html/test_translated.html +8 -0
- data/test/lib/api_translator_test.rb +109 -0
- data/test/lib/headers_test.rb +84 -55
- data/test/lib/lang_test.rb +157 -357
- data/test/lib/services/glob_test.rb +1 -1
- data/test/lib/services/html_converter_test.rb +166 -0
- data/test/lib/services/html_replace_marker_test.rb +75 -0
- data/test/lib/services/wovn_logger_test.rb +6 -6
- data/test/lib/store_test.rb +25 -69
- data/test/lib/text_caches/cache_base_test.rb +1 -1
- data/test/lib/text_caches/memory_cache_test.rb +10 -11
- data/test/lib/wovnrb_test.rb +77 -310
- data/test/test_helper.rb +22 -32
- data/wovnrb.gemspec +35 -44
- metadata +86 -205
- data/ext/dom/Makefile +0 -239
- data/lib/wovnrb/api_data.rb +0 -59
- data/lib/wovnrb/html_replacers/image_replacer.rb +0 -69
- data/lib/wovnrb/html_replacers/input_replacer.rb +0 -38
- data/lib/wovnrb/html_replacers/link_replacer.rb +0 -78
- data/lib/wovnrb/html_replacers/meta_replacer.rb +0 -28
- data/lib/wovnrb/html_replacers/replacer_base.rb +0 -49
- data/lib/wovnrb/html_replacers/script_replacer.rb +0 -39
- data/lib/wovnrb/html_replacers/text_replacer.rb +0 -21
- data/lib/wovnrb/html_replacers/unified_values/dst_swapping_targets_creator.rb +0 -76
- data/lib/wovnrb/html_replacers/unified_values/element_category.rb +0 -242
- data/lib/wovnrb/html_replacers/unified_values/node_swapping_targets_creator.rb +0 -134
- data/lib/wovnrb/html_replacers/unified_values/text_replacer.rb +0 -35
- data/lib/wovnrb/html_replacers/unified_values/text_scraper.rb +0 -152
- data/lib/wovnrb/html_replacers/unified_values/values_stack.rb +0 -65
- data/lib/wovnrb/services/url.rb +0 -12
- data/lib/wovnrb/services/value_agent.rb +0 -9
- data/test/fixtures/unified_values/site_html/simple_actual.html +0 -96
- data/test/fixtures/unified_values/site_html/simple_expected.json +0 -251
- data/test/fixtures/unified_values/site_html/wovn.io_actual.html +0 -686
- data/test/fixtures/unified_values/site_html/wovn.io_expected.json +0 -543
- data/test/fixtures/unified_values/site_html/www.yahoo.co.jp_actual.html +0 -1024
- data/test/fixtures/unified_values/site_html/www.yahoo.co.jp_expected.json +0 -3345
- data/test/fixtures/unified_values/small_html/block_inside_inline_actual.html +0 -12
- data/test/fixtures/unified_values/small_html/block_inside_inline_expected.json +0 -22
- data/test/fixtures/unified_values/small_html/br_tag_actual.html +0 -10
- data/test/fixtures/unified_values/small_html/br_tag_expected.json +0 -12
- data/test/fixtures/unified_values/small_html/comment_tag_actual.html +0 -12
- data/test/fixtures/unified_values/small_html/comment_tag_expected.json +0 -10
- data/test/fixtures/unified_values/small_html/complex_text_with_html_entity_actual.html +0 -7
- data/test/fixtures/unified_values/small_html/complex_text_with_html_entity_expected.json +0 -11
- data/test/fixtures/unified_values/small_html/deep_nested_block_actual.html +0 -14
- data/test/fixtures/unified_values/small_html/deep_nested_block_expected.json +0 -8
- data/test/fixtures/unified_values/small_html/deep_nested_inline_actual.html +0 -20
- data/test/fixtures/unified_values/small_html/deep_nested_inline_expected.json +0 -20
- data/test/fixtures/unified_values/small_html/empty_tag_actual.html +0 -10
- data/test/fixtures/unified_values/small_html/empty_tag_expected.json +0 -12
- data/test/fixtures/unified_values/small_html/empty_text_actual.html +0 -12
- data/test/fixtures/unified_values/small_html/empty_text_expected.json +0 -1
- data/test/fixtures/unified_values/small_html/ignore_tag_actual.html +0 -12
- data/test/fixtures/unified_values/small_html/ignore_tag_expected.json +0 -16
- data/test/fixtures/unified_values/small_html/ignored_class_actual.html +0 -10
- data/test/fixtures/unified_values/small_html/ignored_class_expected.json +0 -13
- data/test/fixtures/unified_values/small_html/img_actual.html +0 -12
- data/test/fixtures/unified_values/small_html/img_expected.json +0 -23
- data/test/fixtures/unified_values/small_html/nested_and_complex_wovn_ignore_actual.html +0 -10
- data/test/fixtures/unified_values/small_html/nested_and_complex_wovn_ignore_expected.json +0 -16
- data/test/fixtures/unified_values/small_html/nested_text_value_actual.html +0 -10
- data/test/fixtures/unified_values/small_html/nested_text_value_expected.json +0 -12
- data/test/fixtures/unified_values/small_html/nested_text_value_mixed_plan_text_actual.html +0 -10
- data/test/fixtures/unified_values/small_html/nested_text_value_mixed_plan_text_expected.json +0 -14
- data/test/fixtures/unified_values/small_html/option_tag_actual.html +0 -9
- data/test/fixtures/unified_values/small_html/option_tag_expected.json +0 -13
- data/test/fixtures/unified_values/small_html/text_different_inline_each_other_actual.html +0 -10
- data/test/fixtures/unified_values/small_html/text_different_inline_each_other_expected.json +0 -22
- data/test/fixtures/unified_values/small_html/text_in_svg_actual.html +0 -9
- data/test/fixtures/unified_values/small_html/text_in_svg_expected.json +0 -8
- data/test/fixtures/unified_values/small_html/text_with_html_entity_actual.html +0 -6
- data/test/fixtures/unified_values/small_html/text_with_html_entity_expected.json +0 -8
- data/test/fixtures/unified_values/small_html/unknown_or_custom_tag_actual.html +0 -12
- data/test/fixtures/unified_values/small_html/unknown_or_custom_tag_expected.json +0 -24
- data/test/fixtures/unified_values/small_html/unnecessay_top_end_tag_actual.html +0 -12
- data/test/fixtures/unified_values/small_html/unnecessay_top_end_tag_expected.json +0 -14
- data/test/fixtures/unified_values/small_html/wovn_ignore_actual.html +0 -10
- data/test/fixtures/unified_values/small_html/wovn_ignore_expected.json +0 -13
- data/test/lib/api_data_test.rb +0 -83
- data/test/lib/html_replacers/image_replacer_test.rb +0 -165
- data/test/lib/html_replacers/input_replacer_test.rb +0 -140
- data/test/lib/html_replacers/link_replacer_test.rb +0 -328
- data/test/lib/html_replacers/meta_replacer_test.rb +0 -157
- data/test/lib/html_replacers/replacer_base_test.rb +0 -128
- data/test/lib/html_replacers/script_replacer_test.rb +0 -139
- data/test/lib/html_replacers/text_replacer_test.rb +0 -99
- data/test/lib/html_replacers/unified_values/dst_swapping_targets_creator_test.rb +0 -137
- data/test/lib/html_replacers/unified_values/element_category_test.rb +0 -49
- data/test/lib/html_replacers/unified_values/node_swapping_targets_creator_test.rb +0 -137
- data/test/lib/html_replacers/unified_values/text_replacer_test.rb +0 -270
- data/test/lib/html_replacers/unified_values/text_scraper_test.rb +0 -121
- data/test/lib/html_replacers/unified_values/values_stack_test.rb +0 -122
- data/test/lib/services/url_test.rb +0 -9
- data/test/lib/services/value_agent_test.rb +0 -32
- data/test/services/url_test.rb +0 -163
- data/values/values +0 -1
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Wovnrb
|
4
|
-
module UnifiedValues
|
5
|
-
class ElementCategoryTest < WovnMiniTest
|
6
|
-
def test_contents
|
7
|
-
assert_equal(116, ElementCategory::CONTENT_TYPES.size)
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_inline_elements
|
11
|
-
expected_inlines = %w[a abbr b bdi bdo button cite code data dfn em i kbd label legend mark meter option q rb rp rt rtc s samp small span strong sub sup time u var]
|
12
|
-
assert_same_elements(expected_inlines, ElementCategory::INLINE_ELEMENTS.to_a)
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_empty_elements
|
16
|
-
expected_inlines = %w[br param source track wbr input]
|
17
|
-
assert_same_elements(expected_inlines, ElementCategory::EMPTY_ELEMENTS.to_a)
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_ignore_elements
|
21
|
-
expected_inlines = %w[area audio canvas embed iframe img map meta object picture video]
|
22
|
-
assert_same_elements(expected_inlines, ElementCategory::IGNORE_ELEMENTS.to_a)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_skip_elements
|
26
|
-
expected_inlines = %w[base link noscript script style template]
|
27
|
-
assert_same_elements(expected_inlines, ElementCategory::SKIP_ELEMENTS.to_a)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_skip_elements_without_attributes
|
31
|
-
expected_inlines = %w[textarea]
|
32
|
-
assert_same_elements(expected_inlines, ElementCategory::SKIP_ELEMENTS_WITHOUT_ATTRIBUTES.to_a)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_block_elements
|
36
|
-
expected_inlines = %w[address article aside bb blockquote body caption col colgroup datalist dd del details dialog div dl dt fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hgroup hr html ins li main menu nav ol optgroup output p pre progress ruby section select slot summary svg table tbody td tfoot th thead title tr ul]
|
37
|
-
assert_same_elements(expected_inlines, ElementCategory::BLOCK_ELEMENTS.to_a)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_no_duplication
|
41
|
-
elements = ElementCategory::INLINE_ELEMENTS + ElementCategory::EMPTY_ELEMENTS + ElementCategory::IGNORE_ELEMENTS + ElementCategory::SKIP_ELEMENTS + ElementCategory::SKIP_ELEMENTS_WITHOUT_ATTRIBUTES + ElementCategory::BLOCK_ELEMENTS
|
42
|
-
element_size_sum = ElementCategory::INLINE_ELEMENTS.size + ElementCategory::EMPTY_ELEMENTS.size + ElementCategory::IGNORE_ELEMENTS.size + ElementCategory::SKIP_ELEMENTS.size + ElementCategory::SKIP_ELEMENTS_WITHOUT_ATTRIBUTES.size + ElementCategory::BLOCK_ELEMENTS.size
|
43
|
-
|
44
|
-
assert_equal(elements.size, ElementCategory::CONTENT_TYPES.size)
|
45
|
-
assert_equal(element_size_sum, ElementCategory::CONTENT_TYPES.size)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,137 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Wovnrb
|
4
|
-
module UnifiedValues
|
5
|
-
class NodeSwappingTargetsCreatorTest < WovnMiniTest
|
6
|
-
def test_run
|
7
|
-
html = 'a<a>b</a>c'
|
8
|
-
result = TextScraper.new(Set.new).run(Nokogiri::HTML5(html))
|
9
|
-
|
10
|
-
nodes_info = [
|
11
|
-
{
|
12
|
-
nodes: result.first[:nodes]
|
13
|
-
}
|
14
|
-
]
|
15
|
-
|
16
|
-
NodeSwappingTargetsCreator.new(nodes_info).run!
|
17
|
-
assert_equal(%w[a b c], nodes_info[0][:swapping_targets].map(&:to_s))
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_run_with_data_stated_by_tag
|
21
|
-
html = '<a>b</a>c'
|
22
|
-
result = TextScraper.new(Set.new).run(Nokogiri::HTML5(html))
|
23
|
-
nodes = result.first[:nodes]
|
24
|
-
nodes_info = [
|
25
|
-
{
|
26
|
-
nodes: nodes
|
27
|
-
}
|
28
|
-
]
|
29
|
-
|
30
|
-
NodeSwappingTargetsCreator.new(nodes_info).run!
|
31
|
-
dummy = NodeSwappingTargetsCreator.new('').create_dummy_empty_text_node(next_node: nodes[0])
|
32
|
-
|
33
|
-
assert_equal(['', 'b', 'c'], nodes_info[0][:swapping_targets].map(&:to_s))
|
34
|
-
|
35
|
-
text_for_dummy = 'a'
|
36
|
-
dummy.content = text_for_dummy
|
37
|
-
assert_equal(text_for_dummy, nodes[0].previous.to_s)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_run_with_data_ended_by_tag
|
41
|
-
html = 'a<a>b</a>'
|
42
|
-
result = TextScraper.new(Set.new).run(Nokogiri::HTML5(html))
|
43
|
-
nodes = result.first[:nodes]
|
44
|
-
nodes_info = [
|
45
|
-
{
|
46
|
-
nodes: nodes
|
47
|
-
}
|
48
|
-
]
|
49
|
-
|
50
|
-
NodeSwappingTargetsCreator.new(nodes_info).run!
|
51
|
-
dummy = NodeSwappingTargetsCreator.new('').create_dummy_empty_text_node(previous_node: nodes[-1])
|
52
|
-
|
53
|
-
assert_equal(['a', 'b', ''], nodes_info[0][:swapping_targets].map(&:to_s))
|
54
|
-
|
55
|
-
text_for_dummy = 'a'
|
56
|
-
dummy.content = text_for_dummy
|
57
|
-
assert_equal(text_for_dummy, nodes[-1].next.to_s)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_run_with_data_with_no_content_inside_tag
|
61
|
-
html = 'a<a></a>c'
|
62
|
-
result = TextScraper.new(Set.new).run(Nokogiri::HTML5(html))
|
63
|
-
nodes = result.first[:nodes]
|
64
|
-
nodes_info = [
|
65
|
-
{
|
66
|
-
nodes: nodes
|
67
|
-
}
|
68
|
-
]
|
69
|
-
|
70
|
-
NodeSwappingTargetsCreator.new(nodes_info).run!
|
71
|
-
dummy = NodeSwappingTargetsCreator.new('').create_dummy_empty_text_node(next_node: nodes[2])
|
72
|
-
|
73
|
-
assert_equal(['a', '', 'c'], nodes_info[0][:swapping_targets].map(&:to_s))
|
74
|
-
|
75
|
-
text_for_dummy = 'a'
|
76
|
-
dummy.content = text_for_dummy
|
77
|
-
assert_equal(text_for_dummy, nodes[2].previous.to_s)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_run_with_data_without_tag
|
81
|
-
html = 'a'
|
82
|
-
result = TextScraper.new(Set.new).run(Nokogiri::HTML5(html))
|
83
|
-
nodes = result.first[:nodes]
|
84
|
-
nodes_info = [
|
85
|
-
{
|
86
|
-
nodes: nodes
|
87
|
-
}
|
88
|
-
]
|
89
|
-
|
90
|
-
NodeSwappingTargetsCreator.new(nodes_info).run!
|
91
|
-
assert_equal(['a'], nodes_info[0][:swapping_targets].map(&:to_s))
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_run_with_data_with_wovn_ignore
|
95
|
-
html = 'a<a wovn-ignore>b</a>c'
|
96
|
-
result = TextScraper.new(Set.new).run(Nokogiri::HTML5(html))
|
97
|
-
|
98
|
-
nodes_info = [
|
99
|
-
{
|
100
|
-
nodes: result.first[:nodes]
|
101
|
-
}
|
102
|
-
]
|
103
|
-
|
104
|
-
NodeSwappingTargetsCreator.new(nodes_info).run!
|
105
|
-
assert_equal(%w[a c], nodes_info[0][:swapping_targets].map(&:to_s))
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_run_with_data_with_closing_tag
|
109
|
-
html = 'a<br>bc'
|
110
|
-
result = TextScraper.new(Set.new).run(Nokogiri::HTML5(html))
|
111
|
-
|
112
|
-
nodes_info = [
|
113
|
-
{
|
114
|
-
nodes: result.first[:nodes]
|
115
|
-
}
|
116
|
-
]
|
117
|
-
|
118
|
-
NodeSwappingTargetsCreator.new(nodes_info).run!
|
119
|
-
assert_equal(%w[a bc], nodes_info[0][:swapping_targets].map(&:to_s))
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_run_with_data_with_both_closing_tag_and_no_closing_tag
|
123
|
-
html = 'a<a>b<br>c</a>d'
|
124
|
-
result = TextScraper.new(Set.new).run(Nokogiri::HTML5(html))
|
125
|
-
|
126
|
-
nodes_info = [
|
127
|
-
{
|
128
|
-
nodes: result.first[:nodes]
|
129
|
-
}
|
130
|
-
]
|
131
|
-
|
132
|
-
NodeSwappingTargetsCreator.new(nodes_info).run!
|
133
|
-
assert_equal(%w[a b c d], nodes_info[0][:swapping_targets].map(&:to_s))
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
@@ -1,270 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Wovnrb
|
4
|
-
module UnifiedValues
|
5
|
-
module UnifiedValues
|
6
|
-
class TextReplacerTest < WovnMiniTest
|
7
|
-
def test_replace
|
8
|
-
inner_html = <<-HTML
|
9
|
-
<div>
|
10
|
-
a <span>b</span> c
|
11
|
-
</div>
|
12
|
-
<div>
|
13
|
-
a<span>b</span>
|
14
|
-
</div>
|
15
|
-
<div>
|
16
|
-
<span> b </span>c
|
17
|
-
</div>
|
18
|
-
HTML
|
19
|
-
|
20
|
-
expected_body = <<-HTML
|
21
|
-
<div>
|
22
|
-
<!--wovn-src:
|
23
|
-
a -->あ<span><!--wovn-src:b-->い</span><!--wovn-src: c
|
24
|
-
-->う</div>
|
25
|
-
<div>
|
26
|
-
<!--wovn-src:
|
27
|
-
a-->\u200b<span><!--wovn-src:b-->い</span><!--wovn-src:-->う
|
28
|
-
</div>
|
29
|
-
<div>
|
30
|
-
<!--wovn-src:-->あ<span><!--wovn-src: b -->い</span><!--wovn-src:c
|
31
|
-
-->\u200b</div>
|
32
|
-
HTML
|
33
|
-
|
34
|
-
text_index = {
|
35
|
-
'a<span>b</span>c' =>
|
36
|
-
{ 'ja' =>
|
37
|
-
[{ 'data' => 'あ<span>い</span>う' }] },
|
38
|
-
'a<span>b</span>' =>
|
39
|
-
{ 'ja' =>
|
40
|
-
[{ 'data' => '<span>い</span>う' }] },
|
41
|
-
'<span>b</span>c' =>
|
42
|
-
{ 'ja' =>
|
43
|
-
[{ 'data' => 'あ<span>い</span>' }] }
|
44
|
-
}
|
45
|
-
|
46
|
-
assert_text_replace(text_index, inner_html, expected_body)
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
def test_replace_with_dst_with_spaces
|
51
|
-
inner_html = <<-HTML
|
52
|
-
<html>
|
53
|
-
<body>
|
54
|
-
<div>
|
55
|
-
a <span>b</span> c
|
56
|
-
</div>
|
57
|
-
<div>
|
58
|
-
a<span>b</span>
|
59
|
-
</div>
|
60
|
-
<div>
|
61
|
-
<span> b </span>c
|
62
|
-
</div>
|
63
|
-
</body>
|
64
|
-
</html>
|
65
|
-
HTML
|
66
|
-
|
67
|
-
expected_body = <<-HTML
|
68
|
-
<div>
|
69
|
-
<!--wovn-src:
|
70
|
-
a -->あ <span><!--wovn-src:b--> い </span><!--wovn-src: c
|
71
|
-
--> う</div>
|
72
|
-
<div>
|
73
|
-
<!--wovn-src:
|
74
|
-
a-->\u200b<span><!--wovn-src:b--> い </span><!--wovn-src:--> う
|
75
|
-
</div>
|
76
|
-
<div>
|
77
|
-
<!--wovn-src:-->あ <span><!--wovn-src: b --> い </span><!--wovn-src:c
|
78
|
-
-->\u200b</div>
|
79
|
-
HTML
|
80
|
-
|
81
|
-
text_index = {
|
82
|
-
'a<span>b</span>c' =>
|
83
|
-
{ 'ja' =>
|
84
|
-
[{ 'data' => 'あ <span> い </span> う' }] },
|
85
|
-
'a<span>b</span>' =>
|
86
|
-
{ 'ja' =>
|
87
|
-
[{ 'data' => '<span> い </span> う' }] },
|
88
|
-
'<span>b</span>c' =>
|
89
|
-
{ 'ja' =>
|
90
|
-
[{ 'data' => 'あ <span> い </span>' }] }
|
91
|
-
}
|
92
|
-
|
93
|
-
assert_text_replace(text_index, inner_html, expected_body)
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_replace_with_empty_translations
|
97
|
-
html = <<-HTML
|
98
|
-
<html>
|
99
|
-
<body>
|
100
|
-
<p> a </p>
|
101
|
-
<div>
|
102
|
-
a <span> b </span> c
|
103
|
-
</div>
|
104
|
-
</body>
|
105
|
-
</html>
|
106
|
-
HTML
|
107
|
-
|
108
|
-
expected_body = <<-HTML
|
109
|
-
<p><!--wovn-src: a -->\u200b</p>
|
110
|
-
<div>
|
111
|
-
<!--wovn-src:
|
112
|
-
a -->\u200b<span><!--wovn-src: b -->い</span><!--wovn-src: c
|
113
|
-
-->\u200b</div>
|
114
|
-
HTML
|
115
|
-
|
116
|
-
text_index = {
|
117
|
-
'a<span>b</span>c' =>
|
118
|
-
{ 'ja' =>
|
119
|
-
[{ 'data' => '<span>い</span>' }] },
|
120
|
-
'a' =>
|
121
|
-
{ 'ja' =>
|
122
|
-
[{ 'data' => "\u200b" }] }
|
123
|
-
}
|
124
|
-
|
125
|
-
assert_text_replace(text_index, html, expected_body)
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_replace_with_comment
|
129
|
-
html = <<-HTML
|
130
|
-
<html>
|
131
|
-
<body>
|
132
|
-
<div>
|
133
|
-
<!-- comment -->
|
134
|
-
a <span>b</span> c
|
135
|
-
</div>
|
136
|
-
</body>
|
137
|
-
</html>
|
138
|
-
HTML
|
139
|
-
|
140
|
-
expected_body = <<-HTML
|
141
|
-
<div>
|
142
|
-
<!-- comment --><!--wovn-src:
|
143
|
-
a -->あ<span><!--wovn-src:b-->い</span><!--wovn-src: c
|
144
|
-
-->う</div>
|
145
|
-
HTML
|
146
|
-
|
147
|
-
text_index = {
|
148
|
-
'a<span>b</span>c' =>
|
149
|
-
{ 'ja' =>
|
150
|
-
[{ 'data' => 'あ<span>い</span>う' }] }
|
151
|
-
}
|
152
|
-
|
153
|
-
assert_text_replace(text_index, html, expected_body)
|
154
|
-
end
|
155
|
-
|
156
|
-
def test_replace_with_comment_inside_content
|
157
|
-
html = <<-HTML
|
158
|
-
<html>
|
159
|
-
<body>
|
160
|
-
<div>
|
161
|
-
a<!-- comment --> <span><!-- comment -->b<!-- comment --></span><!-- comment --> c<!-- comment -->
|
162
|
-
</div>
|
163
|
-
</body>
|
164
|
-
</html>
|
165
|
-
HTML
|
166
|
-
|
167
|
-
expected_body = <<-HTML
|
168
|
-
<div>
|
169
|
-
<!--wovn-src:
|
170
|
-
a-->あ<!-- comment --> <span><!-- comment --><!--wovn-src:b-->い<!-- comment --></span><!-- comment --><!--wovn-src: c-->う<!-- comment -->
|
171
|
-
</div>
|
172
|
-
HTML
|
173
|
-
|
174
|
-
text_index = {
|
175
|
-
'a<span>b</span>c' =>
|
176
|
-
{ 'ja' =>
|
177
|
-
[{ 'data' => 'あ<span>い</span>う' }] }
|
178
|
-
}
|
179
|
-
|
180
|
-
assert_text_replace(text_index, html, expected_body)
|
181
|
-
end
|
182
|
-
|
183
|
-
def test_replace_without_destination_of_expected_lang
|
184
|
-
html = <<-HTML
|
185
|
-
<html>
|
186
|
-
<body>
|
187
|
-
<div>
|
188
|
-
a <span>b</span> c
|
189
|
-
</div>
|
190
|
-
</body>
|
191
|
-
</html>
|
192
|
-
HTML
|
193
|
-
|
194
|
-
expected_body = <<-HTML
|
195
|
-
<div>
|
196
|
-
a <span>b</span> c
|
197
|
-
</div>
|
198
|
-
HTML
|
199
|
-
|
200
|
-
text_index = {
|
201
|
-
'a<span>b</span>c' =>
|
202
|
-
{ 'it' =>
|
203
|
-
[{ 'data' => 'あ<span>い</span>う' }] }
|
204
|
-
}
|
205
|
-
|
206
|
-
assert_text_replace(text_index, html, expected_body)
|
207
|
-
end
|
208
|
-
|
209
|
-
def test_replace_without_expected_destination
|
210
|
-
html = <<-HTML
|
211
|
-
<html>
|
212
|
-
<body>
|
213
|
-
<div>
|
214
|
-
a <span>b</span> c
|
215
|
-
</div>
|
216
|
-
</body>
|
217
|
-
</html>
|
218
|
-
HTML
|
219
|
-
|
220
|
-
expected_body = <<-HTML
|
221
|
-
<div>
|
222
|
-
a <span>b</span> c
|
223
|
-
</div>
|
224
|
-
HTML
|
225
|
-
|
226
|
-
text_index = {}
|
227
|
-
|
228
|
-
assert_text_replace(text_index, html, expected_body)
|
229
|
-
end
|
230
|
-
|
231
|
-
def test_replace_data_without_tag
|
232
|
-
html = <<-HTML
|
233
|
-
<html>
|
234
|
-
<body>
|
235
|
-
<div>
|
236
|
-
apple
|
237
|
-
</div>
|
238
|
-
</body>
|
239
|
-
</html>
|
240
|
-
HTML
|
241
|
-
|
242
|
-
expected_body = <<-HTML
|
243
|
-
<!--wovn-src:
|
244
|
-
apple
|
245
|
-
-->りんご</div>
|
246
|
-
HTML
|
247
|
-
|
248
|
-
text_index = {
|
249
|
-
'apple' =>
|
250
|
-
{ 'ja' =>
|
251
|
-
[{ 'data' => 'りんご' }] }
|
252
|
-
}
|
253
|
-
|
254
|
-
assert_text_replace(text_index, html, expected_body)
|
255
|
-
end
|
256
|
-
|
257
|
-
private
|
258
|
-
|
259
|
-
def assert_text_replace(text_index, body, expected_body)
|
260
|
-
store = Store.instance
|
261
|
-
dom = Wovnrb.get_dom(body)
|
262
|
-
replacer = TextReplacer.new(store, text_index)
|
263
|
-
replacer.replace(dom, Lang.new('ja'))
|
264
|
-
|
265
|
-
assert(dom.to_html.include?(expected_body))
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|