-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtag_test.rb
154 lines (122 loc) · 3.2 KB
/
tag_test.rb
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
150
151
152
153
154
# frozen_string_literal: true
require "test_helper"
class TagTest < Minitest::Test
def test_plain
assert_format("%div")
end
def test_value
assert_format("%div Hello, world!")
end
def test_class
assert_format("%p.foo")
end
def test_class_multiple
assert_format("%p.foo.bar.baz")
end
def test_id
assert_format("%p#foo")
end
def test_classes_and_id
assert_format("%p.foo.bar#baz")
end
def test_self_closing
assert_format("%br/")
end
def test_whitespace_removal_left_single_line
assert_format('%p>= "Foo\\nBar"')
end
def test_whitespace_removal_right_single_line
assert_format('%p<= "Foo\\nBar"')
end
def test_whitespace_removal_right_multi_line
assert_format(<<~HAML)
%blockquote<
%div
Foo!
HAML
end
def test_dynamic_attributes
assert_format("%span{html_attrs('fr-fr')}")
end
def test_dynamic_attributes_nested_hash
assert_format("%div{data: { controller: \"lesson-evaluation\" }}")
end
def test_dynamic_attributes_nested_hash_single_quotes
assert_format(
"%div{data: { controller: \"lesson-evaluation\" }}",
"%div{data: { controller: 'lesson-evaluation' }}",
options: SyntaxTree::Formatter::Options.new(quote: "'")
)
end
def test_dynamic_attributes_integers
assert_format("%span{foo: 1}")
end
def test_dynamic_attributes_html_style
assert_format("%img(title=@title alt=@alt)/")
end
def test_dynamic_attributes_boolean
assert_format("%span(foo)", "%span{foo: true}")
end
def test_dynamic_attributes_strings
assert_format(
"%section(xml:lang=\"en\" title=\"title\")",
"%section{\"xml:lang\": \"en\", title: \"title\"}"
)
end
def test_dynamic_attributes_strings_single_quotes
assert_format(
"%section(xml:lang=\"en\" title=\"title\")",
"%section{'xml:lang': 'en', title: 'title'}",
options: SyntaxTree::Formatter::Options.new(quote: "'")
)
end
def test_dynamic_attributes_with_at
assert_format("%span{\"@click\": \"open = true\"}")
end
def test_static_attributes
assert_format("%span{:foo => \"bar\"}", "%span{foo: \"bar\"}")
end
def test_object_reference
assert_format(<<~HAML)
%div[@user, :greeting]
%bar[290]/
Hello!
HAML
end
def test_long_declaration_before_text
long = "a" * 80
assert_format("%button{ data: { current: #{long} } } foo", <<~HAML)
%button{
data: {
current: #{long}
}
}
foo
HAML
end
def test_quotes_in_strings
assert_format("%div{title: 'escape \" quotes'}")
end
def test_interpolation_in_strings
source = <<~HAML
%div{style: "background: center/cover url(\#{url_for(page.resource.file)})"}
HAML
options = SyntaxTree::Formatter::Options.new(quote: "'")
assert_format(source, options: options)
end
def test_interpolation_in_value
assert_format("%p <small>hello</small>\"\#{1 + 2} little pigs\"")
end
def test_preserve
assert_format("%p~ foo")
end
def test_escape_html
assert_format("%p&= foo")
end
def test_preserve_escape_html
assert_format("%p&~ foo")
end
def test_unescape
assert_format("%p!= foo")
end
end