forked from marcoroth/herb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext_content_test.rb
More file actions
149 lines (112 loc) · 3.93 KB
/
text_content_test.rb
File metadata and controls
149 lines (112 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# frozen_string_literal: true
require_relative "../test_helper"
module Parser
class TextContentTest < Minitest::Spec
include SnapshotUtils
test "text content" do
assert_parsed_snapshot("Hello World")
end
test "text content inside tag" do
assert_parsed_snapshot("<h1>Hello World</h1>")
end
test "text content with tag after" do
assert_parsed_snapshot("Hello<span>World</span>")
end
test "text content with tag before" do
assert_parsed_snapshot("<span>Hello</span>World")
end
test "text content with tag around" do
assert_parsed_snapshot("Hello<span></span>World")
end
test "text content that exceeds initial buffer_T size (ca. 4K)" do
initial_buffer_capacity = 1024 # bytes
content = cyclic_string((((initial_buffer_capacity * 2) + 1) * 2) + 1)
result = assert_parsed_snapshot(%(<div>#{content}</div>))
assert_equal content, result.value.children.first.body.first.content
end
test "text content that exceeds initial buffer_T size (ca. 8K)" do
initial_buffer_capacity = 1024 # bytes
content = cyclic_string((((((initial_buffer_capacity * 2) + 1) * 2) + 1) * 2) + 1)
result = assert_parsed_snapshot(%(<div>#{content}</div>))
assert_equal content, result.value.children.first.body.first.content
end
test "exclamation as only content" do
assert_parsed_snapshot("<b>!</b>")
end
test "comma as only content" do
assert_parsed_snapshot("<b>,</b>")
end
test "dollar sign as only content" do
assert_parsed_snapshot("<b>$</b>")
end
test "dash as only content" do
assert_parsed_snapshot("<b>-</b>")
end
test "period as only content" do
assert_parsed_snapshot("<b>.</b>")
end
test "percent as only content" do
assert_parsed_snapshot("<b>%</b>")
end
test "slash as only content" do
assert_parsed_snapshot("<b>/</b>")
end
test "underscore as only content" do
assert_parsed_snapshot("<b>_</b>")
end
test "colon as only content" do
assert_parsed_snapshot("<b>:</b>")
end
test "semicolon as only content" do
assert_parsed_snapshot("<b>;</b>")
end
test "ampersand as only content" do
assert_parsed_snapshot("<b>&</b>")
end
test "equals as only content" do
assert_parsed_snapshot("<b>=</b>")
end
test "a-umlaut as only content" do
assert_parsed_snapshot("<b>ä</b>")
end
test "o-umlaut as only content" do
assert_parsed_snapshot("<b>ö</b>")
end
test "u-umlaut as only content" do
assert_parsed_snapshot("<b>ü</b>")
end
test "emoji as only content" do
assert_parsed_snapshot("<b>🌿</b>")
end
test "non-breaking space (U+00A0) as only content" do
assert_parsed_snapshot("<b> </b>")
end
test "non-breaking space mixed with ERB - issue 310" do
assert_parsed_snapshot("<p><%= hello %> !</p>")
end
test "multiple non-breaking spaces in text" do
assert_parsed_snapshot("<p>Hello World</p>")
end
test "non-breaking space in attribute value" do
assert_parsed_snapshot('<div title="Hello World">Content</div>')
end
test "at symbol (@) in text content - issue 285" do
assert_parsed_snapshot("<p>Did we get it wrong? Respond with <em>@reverse</em> to remove the receipt.</p>")
end
test "at symbol at beginning of text" do
assert_parsed_snapshot("<span>@username</span>")
end
test "multiple at symbols in text" do
assert_parsed_snapshot("<p>Email me @john@example.com</p>")
end
test "at symbol mixed with ERB" do
assert_parsed_snapshot("<p>Contact <%= user.name %> @support</p>")
end
test "at symbol in attribute value" do
assert_parsed_snapshot('<a href="mailto:support@example.com">Contact @support</a>')
end
test "backtick with HTML tags - issue 467" do
assert_parsed_snapshot("a `<b></b>` c")
end
end
end