wovnrb 1.0.13 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/wovnrb.rb +7 -0
- data/lib/wovnrb/html_replacers/replacer_base.rb +2 -1
- data/lib/wovnrb/html_replacers/unified_values/dst_swapping_targets_creator.rb +76 -0
- data/lib/wovnrb/html_replacers/unified_values/element_category.rb +242 -0
- data/lib/wovnrb/html_replacers/unified_values/node_swapping_targets_creator.rb +134 -0
- data/lib/wovnrb/html_replacers/unified_values/text_replacer.rb +35 -0
- data/lib/wovnrb/html_replacers/unified_values/text_scraper.rb +152 -0
- data/lib/wovnrb/html_replacers/unified_values/values_stack.rb +65 -0
- data/lib/wovnrb/lang.rb +6 -1
- data/lib/wovnrb/services/value_agent.rb +9 -0
- data/lib/wovnrb/store.rb +2 -9
- data/lib/wovnrb/version.rb +1 -1
- data/test/fixtures/unified_values/site_html/simple_actual.html +96 -0
- data/test/fixtures/unified_values/site_html/simple_expected.json +251 -0
- data/test/fixtures/unified_values/site_html/wovn.io_actual.html +686 -0
- data/test/fixtures/unified_values/site_html/wovn.io_expected.json +543 -0
- data/test/fixtures/unified_values/site_html/www.yahoo.co.jp_actual.html +1024 -0
- data/test/fixtures/unified_values/site_html/www.yahoo.co.jp_expected.json +3345 -0
- data/test/fixtures/unified_values/small_html/block_inside_inline_actual.html +12 -0
- data/test/fixtures/unified_values/small_html/block_inside_inline_expected.json +22 -0
- data/test/fixtures/unified_values/small_html/br_tag_actual.html +10 -0
- data/test/fixtures/unified_values/small_html/br_tag_expected.json +12 -0
- data/test/fixtures/unified_values/small_html/comment_tag_actual.html +12 -0
- data/test/fixtures/unified_values/small_html/comment_tag_expected.json +10 -0
- data/test/fixtures/unified_values/small_html/complex_text_with_html_entity_actual.html +7 -0
- data/test/fixtures/unified_values/small_html/complex_text_with_html_entity_expected.json +11 -0
- data/test/fixtures/unified_values/small_html/deep_nested_block_actual.html +14 -0
- data/test/fixtures/unified_values/small_html/deep_nested_block_expected.json +8 -0
- data/test/fixtures/unified_values/small_html/deep_nested_inline_actual.html +20 -0
- data/test/fixtures/unified_values/small_html/deep_nested_inline_expected.json +20 -0
- data/test/fixtures/unified_values/small_html/empty_tag_actual.html +10 -0
- data/test/fixtures/unified_values/small_html/empty_tag_expected.json +12 -0
- data/test/fixtures/unified_values/small_html/empty_text_actual.html +12 -0
- data/test/fixtures/unified_values/small_html/empty_text_expected.json +1 -0
- data/test/fixtures/unified_values/small_html/ignore_tag_actual.html +12 -0
- data/test/fixtures/unified_values/small_html/ignore_tag_expected.json +16 -0
- data/test/fixtures/unified_values/small_html/ignored_class_actual.html +10 -0
- data/test/fixtures/unified_values/small_html/ignored_class_expected.json +13 -0
- data/test/fixtures/unified_values/small_html/img_actual.html +12 -0
- data/test/fixtures/unified_values/small_html/img_expected.json +23 -0
- data/test/fixtures/unified_values/small_html/nested_and_complex_wovn_ignore_actual.html +10 -0
- data/test/fixtures/unified_values/small_html/nested_and_complex_wovn_ignore_expected.json +16 -0
- data/test/fixtures/unified_values/small_html/nested_text_value_actual.html +10 -0
- data/test/fixtures/unified_values/small_html/nested_text_value_expected.json +12 -0
- data/test/fixtures/unified_values/small_html/nested_text_value_mixed_plan_text_actual.html +10 -0
- data/test/fixtures/unified_values/small_html/nested_text_value_mixed_plan_text_expected.json +14 -0
- data/test/fixtures/unified_values/small_html/option_tag_actual.html +9 -0
- data/test/fixtures/unified_values/small_html/option_tag_expected.json +13 -0
- data/test/fixtures/unified_values/small_html/text_different_inline_each_other_actual.html +10 -0
- data/test/fixtures/unified_values/small_html/text_different_inline_each_other_expected.json +22 -0
- data/test/fixtures/unified_values/small_html/text_in_svg_actual.html +9 -0
- data/test/fixtures/unified_values/small_html/text_in_svg_expected.json +8 -0
- data/test/fixtures/unified_values/small_html/text_with_html_entity_actual.html +6 -0
- data/test/fixtures/unified_values/small_html/text_with_html_entity_expected.json +8 -0
- data/test/fixtures/unified_values/small_html/unknown_or_custom_tag_actual.html +12 -0
- data/test/fixtures/unified_values/small_html/unknown_or_custom_tag_expected.json +24 -0
- data/test/fixtures/unified_values/small_html/unnecessay_top_end_tag_actual.html +12 -0
- data/test/fixtures/unified_values/small_html/unnecessay_top_end_tag_expected.json +14 -0
- data/test/fixtures/unified_values/small_html/wovn_ignore_actual.html +10 -0
- data/test/fixtures/unified_values/small_html/wovn_ignore_expected.json +13 -0
- data/test/lib/html_replacers/unified_values/dst_swapping_targets_creator_test.rb +137 -0
- data/test/lib/html_replacers/unified_values/element_category_test.rb +49 -0
- data/test/lib/html_replacers/unified_values/node_swapping_targets_creator_test.rb +137 -0
- data/test/lib/html_replacers/unified_values/text_replacer_test.rb +270 -0
- data/test/lib/html_replacers/unified_values/text_scraper_test.rb +121 -0
- data/test/lib/html_replacers/unified_values/values_stack_test.rb +122 -0
- data/test/lib/lang_test.rb +59 -1
- data/test/lib/services/value_agent_test.rb +32 -0
- data/test/test_helper.rb +18 -2
- data/wovnrb.gemspec +1 -0
- metadata +134 -7
- data/spec/spec_helper.rb +0 -2
- data/spec/wovnrb_spec.rb +0 -7
@@ -0,0 +1,270 @@
|
|
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
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Wovnrb
|
4
|
+
module UnifiedValues
|
5
|
+
class TextScraperTest < WovnMiniTest
|
6
|
+
def assert_shared_fixture(base_name, ignored_classes = Set.new)
|
7
|
+
html = File.read("test/fixtures/unified_values/#{base_name}_actual.html")
|
8
|
+
expected_values = JSON.parse(File.read("test/fixtures/unified_values/#{base_name}_expected.json"))
|
9
|
+
|
10
|
+
dom = Nokogiri::HTML5.parse(html)
|
11
|
+
actual_values = TextScraper.new(ignored_classes).run(dom)
|
12
|
+
|
13
|
+
assert_shared_fixture_values(expected_values, actual_values)
|
14
|
+
end
|
15
|
+
|
16
|
+
def assert_shared_fixture_values(expected_values, actual_values)
|
17
|
+
expected_values.zip(actual_values).each do |expected_value, actual|
|
18
|
+
assert_equal(expected_value['srcs'].join, actual[:dst])
|
19
|
+
assert_equal(expected_value['srcs'].size, actual[:nodes].size)
|
20
|
+
end
|
21
|
+
assert_equal(expected_values.length, actual_values.length)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_shared_fixture
|
25
|
+
assert_shared_fixture('site_html/simple')
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_shared_fixture_of_wovn
|
29
|
+
assert_shared_fixture('site_html/wovn.io')
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_shared_fixture_of_yahoo_jp
|
33
|
+
assert_shared_fixture('site_html/www.yahoo.co.jp')
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_run_fixtures_of_nested_text_value
|
37
|
+
assert_shared_fixture('small_html/nested_text_value')
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_run_fixtures_of_nested_text_value_mixed_plan_text
|
41
|
+
assert_shared_fixture('small_html/nested_text_value_mixed_plan_text')
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_run_fixtures_of_block_inside_inline
|
45
|
+
assert_shared_fixture('small_html/block_inside_inline')
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_run_fixtures_of_br_tag
|
49
|
+
assert_shared_fixture('small_html/br_tag')
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_run_fixtures_of_empty_text
|
53
|
+
assert_shared_fixture('small_html/empty_text')
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_run_fixtures_of_comment_tag
|
57
|
+
assert_shared_fixture('small_html/comment_tag')
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_run_fixtures_of_ignore_tag
|
61
|
+
assert_shared_fixture('small_html/ignore_tag')
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_run_fixtures_of_empty_tag
|
65
|
+
assert_shared_fixture('small_html/empty_tag')
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_run_fixtures_of_deep_nested_block
|
69
|
+
assert_shared_fixture('small_html/deep_nested_block')
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_run_fixtures_of_deep_nested_inline
|
73
|
+
assert_shared_fixture('small_html/deep_nested_inline')
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_run_fixtures_of_text_different_inline_each_other
|
77
|
+
assert_shared_fixture('small_html/text_different_inline_each_other')
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_run_fixtures_of_wovn_ignore
|
81
|
+
assert_shared_fixture('small_html/wovn_ignore')
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_run_fixtures_of_ignored_class
|
85
|
+
assert_shared_fixture('small_html/ignored_class', Set.new(['ignore-me']))
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_run_fixtures_of_nested_and_complex_wovn_ignore
|
89
|
+
assert_shared_fixture('small_html/nested_and_complex_wovn_ignore')
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_run_fixtures_of_text_in_svg
|
93
|
+
assert_shared_fixture('small_html/text_in_svg')
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_run_fixtures_of_text_with_html_entity
|
97
|
+
assert_shared_fixture('small_html/text_with_html_entity')
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_run_fixtures_of_complex_text_with_html_entity
|
101
|
+
assert_shared_fixture('small_html/complex_text_with_html_entity')
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_run_fixtures_of_unknown_or_custom_tag
|
105
|
+
assert_shared_fixture('small_html/unknown_or_custom_tag')
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_run_fixtures_of_unnecessay_top_end_tag
|
109
|
+
assert_shared_fixture('small_html/unnecessay_top_end_tag')
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_run_fixtures_of_option_tag
|
113
|
+
assert_shared_fixture('small_html/option_tag')
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_run_fixtures_of_img
|
117
|
+
assert_shared_fixture('small_html/img')
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Wovnrb
|
4
|
+
module UnifiedValues
|
5
|
+
class ValueStackTest < WovnMiniTest
|
6
|
+
def setup
|
7
|
+
@doc = Nokogiri('<html></html>')
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_initialize
|
11
|
+
stack = ValuesStack.new('/html/body/path', 10)
|
12
|
+
assert_equal('/html/body/path', stack.instance_variable_get(:@head_path))
|
13
|
+
assert_equal(10, stack.instance_variable_get(:@index))
|
14
|
+
assert_equal([], stack.instance_variable_get(:@node_stack))
|
15
|
+
assert_equal([], stack.instance_variable_get(:@src_stack))
|
16
|
+
assert_equal([], stack.instance_variable_get(:@src_without_tag_stack))
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_add
|
20
|
+
stack = ValuesStack.new('/html/body/path', 10)
|
21
|
+
assert_equal([], stack.instance_variable_get(:@src_stack))
|
22
|
+
assert_equal([], stack.instance_variable_get(:@src_without_tag_stack))
|
23
|
+
|
24
|
+
text_node = Nokogiri::XML::Text.new('hello', @doc)
|
25
|
+
stack.add(text_node, 'hello')
|
26
|
+
assert_equal([text_node], stack.instance_variable_get(:@node_stack))
|
27
|
+
assert_equal(['hello'], stack.instance_variable_get(:@src_stack))
|
28
|
+
assert_equal([], stack.instance_variable_get(:@src_without_tag_stack))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_add_with_spaces
|
32
|
+
stack = ValuesStack.new('/html/body/path', 10)
|
33
|
+
assert_equal([], stack.instance_variable_get(:@src_stack))
|
34
|
+
|
35
|
+
text_node = Nokogiri::XML::Text.new(' hello ', @doc)
|
36
|
+
stack.add(text_node, ' hello ')
|
37
|
+
assert_equal([text_node], stack.instance_variable_get(:@node_stack))
|
38
|
+
assert_equal(['hello'], stack.instance_variable_get(:@src_stack))
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_add_text_element
|
42
|
+
stack = ValuesStack.new('/html/body/path', 10)
|
43
|
+
assert_equal([], stack.instance_variable_get(:@src_stack))
|
44
|
+
assert_equal([], stack.instance_variable_get(:@src_without_tag_stack))
|
45
|
+
|
46
|
+
text_node = Nokogiri::XML::Text.new('hello', @doc)
|
47
|
+
stack.add_text_element(text_node, 'hello')
|
48
|
+
assert_equal([text_node], stack.instance_variable_get(:@node_stack))
|
49
|
+
assert_equal(['hello'], stack.instance_variable_get(:@src_stack))
|
50
|
+
assert_equal(['hello'], stack.instance_variable_get(:@src_without_tag_stack))
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_add_text_element_with_special_character
|
54
|
+
stack = ValuesStack.new('/html/body/path', 10)
|
55
|
+
assert_equal([], stack.instance_variable_get(:@src_stack))
|
56
|
+
assert_equal([], stack.instance_variable_get(:@src_without_tag_stack))
|
57
|
+
text_node = Nokogiri::XML::Text.new(' <hello> ', @doc)
|
58
|
+
stack.add_text_element(text_node, ' <hello> ')
|
59
|
+
assert_equal([text_node], stack.instance_variable_get(:@node_stack))
|
60
|
+
assert_equal(['<hello>'], stack.instance_variable_get(:@src_stack))
|
61
|
+
assert_equal(['<hello>'], stack.instance_variable_get(:@src_without_tag_stack))
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_blank
|
65
|
+
stack = ValuesStack.new('/html/body/path', 10)
|
66
|
+
assert_equal(true, stack.blank?)
|
67
|
+
text_node = Nokogiri::XML::Text.new('hello', @doc)
|
68
|
+
stack.add(text_node, 'hello')
|
69
|
+
assert_equal(false, stack.blank?)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_path
|
73
|
+
stack = ValuesStack.new('/html/body/path', 10)
|
74
|
+
assert_equal('/html/body/path/text()[10]', stack.path)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_path_first_index
|
78
|
+
stack = ValuesStack.new('/html/body/path', 1)
|
79
|
+
assert_equal('/html/body/path/text()', stack.path)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_path_title
|
83
|
+
stack = ValuesStack.new('/html/head/title', 1)
|
84
|
+
assert_equal('/html/head/title', stack.path)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_src
|
88
|
+
stack = ValuesStack.new('/html/body/path', 10)
|
89
|
+
stack.instance_variable_set(:@src_stack, ['hello', '<span>', 'world'])
|
90
|
+
assert_equal('hello<span>world', stack.src)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_src_without_tag
|
94
|
+
stack = ValuesStack.new('/html/body/path', 10)
|
95
|
+
stack.instance_variable_set(:@src_without_tag_stack, ['hello', '<span>', 'world'])
|
96
|
+
assert_equal('hello<span>world', stack.src_without_tag)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_build_next_stack
|
100
|
+
stack = ValuesStack.new('/html/body/path', 10)
|
101
|
+
node1 = Nokogiri::XML::Text.new('hello', @doc)
|
102
|
+
node2 = Nokogiri::XML::Node.new('span', @doc)
|
103
|
+
node3 = Nokogiri::XML::Text.new('world', @doc)
|
104
|
+
stack.instance_variable_set(:@node_stack, [node1, node2, node3])
|
105
|
+
stack.instance_variable_set(:@src_stack, ['hello', '<span>', 'world'])
|
106
|
+
stack.instance_variable_set(:@src_without_tag_stack, ['hello', '<span>', 'world'])
|
107
|
+
assert_equal('/html/body/path', stack.instance_variable_get(:@head_path))
|
108
|
+
assert_equal(10, stack.instance_variable_get(:@index))
|
109
|
+
assert_equal([node1, node2, node3], stack.instance_variable_get(:@node_stack))
|
110
|
+
assert_equal(['hello', '<span>', 'world'], stack.instance_variable_get(:@src_stack))
|
111
|
+
assert_equal(['hello', '<span>', 'world'], stack.instance_variable_get(:@src_without_tag_stack))
|
112
|
+
|
113
|
+
next_stack = stack.build_next_stack
|
114
|
+
assert_equal('/html/body/path', next_stack.instance_variable_get(:@head_path))
|
115
|
+
assert_equal(11, next_stack.instance_variable_get(:@index))
|
116
|
+
assert_equal([], next_stack.instance_variable_get(:@node_stack))
|
117
|
+
assert_equal([], next_stack.instance_variable_get(:@src_stack))
|
118
|
+
assert_equal([], next_stack.instance_variable_get(:@src_without_tag_stack))
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|