better_html 0.0.12 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/better_html.rb +0 -2
- data/lib/better_html/ast/iterator.rb +32 -0
- data/lib/better_html/ast/node.rb +14 -0
- data/lib/better_html/better_erb/runtime_checks.rb +3 -3
- data/lib/better_html/config.rb +12 -0
- data/lib/better_html/parser.rb +286 -0
- data/lib/better_html/test_helper/ruby_expr.rb +8 -5
- data/lib/better_html/test_helper/safe_erb_tester.rb +121 -108
- data/lib/better_html/test_helper/safe_lodash_tester.rb +44 -42
- data/lib/better_html/tokenizer/base_erb.rb +79 -0
- data/lib/better_html/tokenizer/html_erb.rb +31 -0
- data/lib/better_html/{node_iterator → tokenizer}/html_lodash.rb +30 -34
- data/lib/better_html/tokenizer/javascript_erb.rb +15 -0
- data/lib/better_html/{node_iterator → tokenizer}/location.rb +9 -3
- data/lib/better_html/tokenizer/token.rb +16 -0
- data/lib/better_html/tokenizer/token_array.rb +54 -0
- data/lib/better_html/tree/attribute.rb +31 -0
- data/lib/better_html/tree/attributes_list.rb +25 -0
- data/lib/better_html/tree/tag.rb +39 -0
- data/lib/better_html/version.rb +1 -1
- data/test/better_html/parser_test.rb +279 -0
- data/test/better_html/test_helper/safe_erb_tester_test.rb +11 -0
- data/test/better_html/test_helper/safe_lodash_tester_test.rb +11 -1
- data/test/better_html/tokenizer/html_erb_test.rb +158 -0
- data/test/better_html/tokenizer/html_lodash_test.rb +98 -0
- data/test/better_html/tokenizer/location_test.rb +57 -0
- data/test/better_html/tokenizer/token_array_test.rb +144 -0
- data/test/better_html/tokenizer/token_test.rb +15 -0
- metadata +45 -30
- data/lib/better_html/node_iterator.rb +0 -144
- data/lib/better_html/node_iterator/attribute.rb +0 -34
- data/lib/better_html/node_iterator/base.rb +0 -27
- data/lib/better_html/node_iterator/cdata.rb +0 -8
- data/lib/better_html/node_iterator/comment.rb +0 -8
- data/lib/better_html/node_iterator/content_node.rb +0 -13
- data/lib/better_html/node_iterator/element.rb +0 -26
- data/lib/better_html/node_iterator/html_erb.rb +0 -70
- data/lib/better_html/node_iterator/javascript_erb.rb +0 -55
- data/lib/better_html/node_iterator/text.rb +0 -8
- data/lib/better_html/node_iterator/token.rb +0 -8
- data/lib/better_html/tree.rb +0 -113
- data/test/better_html/node_iterator/html_erb_test.rb +0 -116
- data/test/better_html/node_iterator/html_lodash_test.rb +0 -132
- data/test/better_html/node_iterator/location_test.rb +0 -36
- data/test/better_html/node_iterator_test.rb +0 -221
- data/test/better_html/tree_test.rb +0 -110
@@ -1,110 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module BetterHtml
|
4
|
-
class TreeTest < ActiveSupport::TestCase
|
5
|
-
test "simple node" do
|
6
|
-
tree = Tree.new("<div></div>")
|
7
|
-
assert_predicate tree.errors, :empty?
|
8
|
-
|
9
|
-
assert_equal 1, tree.root.size
|
10
|
-
assert_equal 'div', tree.root[0].name
|
11
|
-
assert_equal true, tree.root[0].closed?
|
12
|
-
assert_equal false, tree.root[0].self_closing?
|
13
|
-
end
|
14
|
-
|
15
|
-
test "simple self-closing node" do
|
16
|
-
tree = Tree.new("<meta />")
|
17
|
-
assert_predicate tree.errors, :empty?
|
18
|
-
|
19
|
-
assert_equal 1, tree.root.size
|
20
|
-
assert_equal 'meta', tree.root[0].name
|
21
|
-
assert_equal true, tree.root[0].closed?
|
22
|
-
assert_equal true, tree.root[0].self_closing?
|
23
|
-
end
|
24
|
-
|
25
|
-
test "mismatched closing tag" do
|
26
|
-
tree = Tree.new("<div></p></div>")
|
27
|
-
assert_equal 1, tree.errors.size
|
28
|
-
assert_equal "mismatched </p> in <div> element", tree.errors[0].message
|
29
|
-
|
30
|
-
assert_equal 1, tree.root.size
|
31
|
-
assert_equal 'div', tree.root[0].name
|
32
|
-
assert_equal true, tree.root[0].closed?
|
33
|
-
assert_equal false, tree.root[0].self_closing?
|
34
|
-
end
|
35
|
-
|
36
|
-
test "mismatched closing tag at root" do
|
37
|
-
tree = Tree.new("</p>")
|
38
|
-
assert_equal 1, tree.errors.size
|
39
|
-
assert_equal "mismatched </p> at root of tree", tree.errors[0].message
|
40
|
-
|
41
|
-
assert_predicate tree.root, :empty?
|
42
|
-
end
|
43
|
-
|
44
|
-
test "node with text content" do
|
45
|
-
tree = Tree.new("<div>text</div>")
|
46
|
-
assert_predicate tree.errors, :empty?
|
47
|
-
|
48
|
-
assert_equal 1, tree.root.size
|
49
|
-
div = tree.root[0]
|
50
|
-
assert_equal 1, div.size
|
51
|
-
assert_equal 'text', div[0].content
|
52
|
-
end
|
53
|
-
|
54
|
-
test "extract erb from text node" do
|
55
|
-
tree = Tree.new("<div>before<%= foo %>after</div>")
|
56
|
-
assert_predicate tree.errors, :empty?
|
57
|
-
|
58
|
-
assert_equal 1, tree.root.size
|
59
|
-
div = tree.root[0]
|
60
|
-
assert_equal 1, div.size
|
61
|
-
text = div[0]
|
62
|
-
assert_equal 3, text.content_parts.size
|
63
|
-
assert_equal 'before', text.content_parts[0].text
|
64
|
-
assert_equal '<%= foo %>', text.content_parts[1].text
|
65
|
-
assert_equal ' foo ', text.content_parts[1].code
|
66
|
-
assert_equal 'after', text.content_parts[2].text
|
67
|
-
end
|
68
|
-
|
69
|
-
test "closing tag for void element" do
|
70
|
-
tree = Tree.new("<br></br>")
|
71
|
-
assert_equal 1, tree.errors.size
|
72
|
-
assert_equal "end of tag for void element: </br>", tree.errors[0].message
|
73
|
-
|
74
|
-
assert_equal 1, tree.root.size
|
75
|
-
assert_equal 'br', tree.root[0].name
|
76
|
-
assert_equal true, tree.root[0].closed?
|
77
|
-
assert_equal false, tree.root[0].self_closing?
|
78
|
-
assert_equal true, tree.root[0].void?
|
79
|
-
end
|
80
|
-
|
81
|
-
test "properly self-closed void element" do
|
82
|
-
tree = Tree.new("<br/>")
|
83
|
-
assert_predicate tree.errors, :empty?
|
84
|
-
|
85
|
-
assert_equal 1, tree.root.size
|
86
|
-
assert_equal 'br', tree.root[0].name
|
87
|
-
assert_equal true, tree.root[0].closed?
|
88
|
-
assert_equal true, tree.root[0].self_closing?
|
89
|
-
assert_equal true, tree.root[0].void?
|
90
|
-
end
|
91
|
-
|
92
|
-
test "void elements are nested properly" do
|
93
|
-
tree = Tree.new("<div><hr>test</hr></div>")
|
94
|
-
assert_equal 1, tree.errors.size
|
95
|
-
assert_equal "end of tag for void element: </hr>", tree.errors[0].message
|
96
|
-
|
97
|
-
assert_equal 1, tree.root.size
|
98
|
-
div = tree.root[0]
|
99
|
-
assert_equal 2, div.size
|
100
|
-
assert_equal true, div[0].element?
|
101
|
-
assert_equal true, div[1].text?
|
102
|
-
end
|
103
|
-
|
104
|
-
test "parser errors are bubbled up" do
|
105
|
-
tree = Tree.new("<>")
|
106
|
-
assert_equal 1, tree.errors.size
|
107
|
-
assert_equal "expected '/' or tag name", tree.errors[0].message
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|