slim 0.9.0 → 0.9.1.alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +53 -0
- data/lib/slim/version.rb +1 -1
- data/test/helper.rb +177 -0
- data/test/integration/rails/dummy/Rakefile +7 -0
- data/test/integration/rails/dummy/app/controllers/application_controller.rb +3 -0
- data/test/integration/rails/dummy/app/controllers/parents_controller.rb +84 -0
- data/test/integration/rails/dummy/app/controllers/slim_controller.rb +25 -0
- data/test/integration/rails/dummy/app/helpers/application_helper.rb +2 -0
- data/test/integration/rails/dummy/app/models/child.rb +5 -0
- data/test/integration/rails/dummy/app/models/parent.rb +6 -0
- data/test/integration/rails/dummy/app/views/layouts/application.html.slim +10 -0
- data/test/integration/rails/dummy/app/views/parents/_form.html.slim +8 -0
- data/test/integration/rails/dummy/app/views/parents/edit.html.slim +1 -0
- data/test/integration/rails/dummy/app/views/parents/new.html.slim +1 -0
- data/test/integration/rails/dummy/app/views/parents/show.html.slim +5 -0
- data/test/integration/rails/dummy/app/views/slim/_partial.html.slim +1 -0
- data/test/integration/rails/dummy/app/views/slim/content_for.html.slim +7 -0
- data/test/integration/rails/dummy/app/views/slim/erb.html.erb +1 -0
- data/test/integration/rails/dummy/app/views/slim/integers.html.slim +1 -0
- data/test/integration/rails/dummy/app/views/slim/nil.html.slim +1 -0
- data/test/integration/rails/dummy/app/views/slim/no_layout.html.slim +1 -0
- data/test/integration/rails/dummy/app/views/slim/normal.html.slim +1 -0
- data/test/integration/rails/dummy/app/views/slim/partial.html.slim +2 -0
- data/test/integration/rails/dummy/app/views/slim/variables.html.slim +1 -0
- data/test/integration/rails/dummy/config/application.rb +44 -0
- data/test/integration/rails/dummy/config/boot.rb +10 -0
- data/test/integration/rails/dummy/config/database.yml +22 -0
- data/test/integration/rails/dummy/config/environment.rb +5 -0
- data/test/integration/rails/dummy/config/environments/development.rb +26 -0
- data/test/integration/rails/dummy/config/environments/production.rb +49 -0
- data/test/integration/rails/dummy/config/environments/test.rb +35 -0
- data/test/integration/rails/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/integration/rails/dummy/config/initializers/inflections.rb +10 -0
- data/test/integration/rails/dummy/config/initializers/mime_types.rb +5 -0
- data/test/integration/rails/dummy/config/initializers/secret_token.rb +7 -0
- data/test/integration/rails/dummy/config/initializers/session_store.rb +8 -0
- data/test/integration/rails/dummy/config/locales/en.yml +5 -0
- data/test/integration/rails/dummy/config/routes.rb +60 -0
- data/test/integration/rails/dummy/config.ru +4 -0
- data/test/integration/rails/dummy/db/migrate/20101220223037_parents_and_children.rb +17 -0
- data/test/integration/rails/dummy/script/rails +6 -0
- data/test/integration/rails/test_helper.rb +10 -0
- data/test/integration/rails/test_slim_rails.rb +66 -0
- data/test/slim/test_code_blocks.rb +68 -0
- data/test/slim/test_code_escaping.rb +53 -0
- data/test/slim/test_code_evaluation.rb +201 -0
- data/test/slim/test_code_output.rb +124 -0
- data/test/slim/test_code_structure.rb +95 -0
- data/test/slim/test_embedded_engines.rb +98 -0
- data/test/slim/test_html_escaping.rb +32 -0
- data/test/slim/test_html_structure.rb +307 -0
- data/test/slim/test_parser_errors.rb +107 -0
- data/test/slim/test_ruby_errors.rb +144 -0
- data/test/slim/test_sections.rb +90 -0
- data/test/slim/test_slim_template.rb +123 -0
- data/test/slim/test_text_interpolation.rb +56 -0
- data/test/slim/test_validator.rb +47 -0
- data/test/slim/test_wrapper.rb +32 -0
- metadata +68 -7
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSlimCodeStructure < TestSlim
|
4
|
+
def test_render_with_conditional
|
5
|
+
source = %q{
|
6
|
+
div
|
7
|
+
- if show_first?
|
8
|
+
p The first paragraph
|
9
|
+
- else
|
10
|
+
p The second paragraph
|
11
|
+
}
|
12
|
+
|
13
|
+
assert_html '<div><p>The second paragraph</p></div>', source
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_render_with_consecutive_conditionals
|
17
|
+
source = %q{
|
18
|
+
div
|
19
|
+
- if show_first? true
|
20
|
+
p The first paragraph
|
21
|
+
- if show_first? true
|
22
|
+
p The second paragraph
|
23
|
+
}
|
24
|
+
|
25
|
+
assert_html '<div><p>The first paragraph</p><p>The second paragraph</p></div>', source
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_render_with_parameterized_conditional
|
29
|
+
source = %q{
|
30
|
+
div
|
31
|
+
- if show_first? false
|
32
|
+
p The first paragraph
|
33
|
+
- else
|
34
|
+
p The second paragraph
|
35
|
+
}
|
36
|
+
|
37
|
+
assert_html '<div><p>The second paragraph</p></div>', source
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_render_with_conditional_and_following_nonconditonal
|
41
|
+
source = %q{
|
42
|
+
div
|
43
|
+
- if true
|
44
|
+
p The first paragraph
|
45
|
+
- var = 42
|
46
|
+
= var
|
47
|
+
}
|
48
|
+
|
49
|
+
assert_html '<div><p>The first paragraph</p>42</div>', source
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_render_with_inline_condition
|
53
|
+
source = %q{
|
54
|
+
p = hello_world if true
|
55
|
+
}
|
56
|
+
|
57
|
+
assert_html '<p>Hello World from @env</p>', source
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_render_with_case
|
61
|
+
source = %q{
|
62
|
+
p
|
63
|
+
- case 42
|
64
|
+
- when 41
|
65
|
+
| 1
|
66
|
+
- when 42
|
67
|
+
| 42
|
68
|
+
| is the answer
|
69
|
+
}
|
70
|
+
|
71
|
+
assert_html '<p>42 is the answer</p>', source
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_render_with_slim_comments
|
75
|
+
source = %q{
|
76
|
+
p Hello
|
77
|
+
/ This is a comment
|
78
|
+
Another comment
|
79
|
+
p World
|
80
|
+
}
|
81
|
+
|
82
|
+
assert_html '<p>Hello</p><p>World</p>', source
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_render_with_yield
|
86
|
+
source = %q{
|
87
|
+
div
|
88
|
+
== yield :menu
|
89
|
+
}
|
90
|
+
|
91
|
+
assert_html '<div>This is the menu</div>', source do
|
92
|
+
'This is the menu'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSlimEmbeddedEngines < TestSlim
|
4
|
+
def test_render_with_embedded_template
|
5
|
+
source = %q{
|
6
|
+
p
|
7
|
+
- text = 'before erb block'
|
8
|
+
erb:
|
9
|
+
<b>Hello from <%= text.upcase %>!</b>
|
10
|
+
Second Line!
|
11
|
+
<% if true %><%= true %><% end %>
|
12
|
+
}
|
13
|
+
|
14
|
+
assert_html "<p><b>Hello from BEFORE ERB BLOCK!</b>\nSecond Line!\ntrue</p>", source
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_render_with_interpolated_embedded_template
|
18
|
+
source = %q{
|
19
|
+
markdown:
|
20
|
+
#Header
|
21
|
+
Hello from #{"Markdown!"}
|
22
|
+
"Second Line!"
|
23
|
+
}
|
24
|
+
assert_html "<h1>Header</h1>\n\n<p>Hello from Markdown!\n\"Second Line!\"</p>\n", source
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_render_with_javascript
|
28
|
+
# Keep the trailing space behind "javascript: "!
|
29
|
+
source = %q{
|
30
|
+
javascript:
|
31
|
+
$(function() {});
|
32
|
+
}
|
33
|
+
assert_html '<script type="text/javascript">$(function() {});</script>', source
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_render_with_ruby
|
37
|
+
source = %q{
|
38
|
+
ruby:
|
39
|
+
variable = 1 +
|
40
|
+
2
|
41
|
+
= variable
|
42
|
+
}
|
43
|
+
assert_html '3', source
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_render_with_liquid
|
47
|
+
source = %q{
|
48
|
+
p
|
49
|
+
- text = 'before liquid block'
|
50
|
+
liquid:
|
51
|
+
<span>{{text}}</span>
|
52
|
+
}
|
53
|
+
assert_html "<p><span>before liquid block</span></p>", source
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_render_with_scss
|
57
|
+
source = %q{
|
58
|
+
scss:
|
59
|
+
$color: #f00;
|
60
|
+
body { color: $color; }
|
61
|
+
}
|
62
|
+
assert_html "<style type=\"text/css\">body {\n color: red; }\n</style>", source
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_disabled_embedded_engine
|
66
|
+
source = %{
|
67
|
+
ruby:
|
68
|
+
Embedded Ruby
|
69
|
+
}
|
70
|
+
assert_runtime_error 'Embedded engine ruby is disabled', source, :enable_engines => %w(javascript)
|
71
|
+
|
72
|
+
source = %{
|
73
|
+
ruby:
|
74
|
+
Embedded Ruby
|
75
|
+
}
|
76
|
+
assert_runtime_error 'Embedded engine ruby is disabled', source, :enable_engines => %w(javascript)
|
77
|
+
|
78
|
+
source = %{
|
79
|
+
ruby:
|
80
|
+
Embedded Ruby
|
81
|
+
}
|
82
|
+
assert_runtime_error 'Embedded engine ruby is disabled', source, :disable_engines => %w(ruby)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_enabled_embedded_engine
|
86
|
+
source = %q{
|
87
|
+
javascript:
|
88
|
+
$(function() {});
|
89
|
+
}
|
90
|
+
assert_html '<script type="text/javascript">$(function() {});</script>', source, :disable_engines => %w(ruby)
|
91
|
+
|
92
|
+
source = %q{
|
93
|
+
javascript:
|
94
|
+
$(function() {});
|
95
|
+
}
|
96
|
+
assert_html '<script type="text/javascript">$(function() {});</script>', source, :enable_engines => %w(javascript)
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSlimHtmlEscaping < TestSlim
|
4
|
+
def test_html_will_not_be_escaped
|
5
|
+
source = %q{
|
6
|
+
p <Hello> World, meet "Slim".
|
7
|
+
}
|
8
|
+
|
9
|
+
assert_html '<p><Hello> World, meet "Slim".</p>', source
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_html_with_newline_will_not_be_escaped
|
13
|
+
source = %q{
|
14
|
+
p
|
15
|
+
|
|
16
|
+
<Hello> World,
|
17
|
+
meet "Slim".
|
18
|
+
}
|
19
|
+
|
20
|
+
assert_html "<p><Hello> World,\n meet \"Slim\".</p>", source
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_html_with_escaped_interpolation
|
24
|
+
source = %q{
|
25
|
+
- x = '"'
|
26
|
+
- content = '<x>'
|
27
|
+
p class="#{x}" test #{content}
|
28
|
+
}
|
29
|
+
|
30
|
+
assert_html '<p class=""">test <x></p>', source
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,307 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSlimHtmlStructure < TestSlim
|
4
|
+
def test_simple_render
|
5
|
+
# Keep the trailing space behind "body "!
|
6
|
+
source = %q{
|
7
|
+
html
|
8
|
+
head
|
9
|
+
title Simple Test Title
|
10
|
+
body
|
11
|
+
p Hello World, meet Slim.
|
12
|
+
}
|
13
|
+
|
14
|
+
assert_html '<html><head><title>Simple Test Title</title></head><body><p>Hello World, meet Slim.</p></body></html>', source
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_html_namespaces
|
18
|
+
source = %q{
|
19
|
+
html:body
|
20
|
+
html:p html:id="test" Text
|
21
|
+
}
|
22
|
+
|
23
|
+
assert_html '<html:body><html:p html:id="test">Text</html:p></html:body>', source
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_doctype
|
27
|
+
source = %q{
|
28
|
+
! doctype 5
|
29
|
+
html
|
30
|
+
}
|
31
|
+
|
32
|
+
assert_html '<!DOCTYPE html><html></html>', source
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_capitalized_doctype
|
36
|
+
source = %q{
|
37
|
+
! DOCTYPE 5
|
38
|
+
html
|
39
|
+
}
|
40
|
+
|
41
|
+
assert_html '<!DOCTYPE html><html></html>', source
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_render_with_shortcut_attributes
|
45
|
+
source = %q{
|
46
|
+
h1#title This is my title
|
47
|
+
#notice.hello.world
|
48
|
+
= hello_world
|
49
|
+
}
|
50
|
+
|
51
|
+
assert_html '<h1 id="title">This is my title</h1><div class="hello world" id="notice">Hello World from @env</div>', source
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_render_with_text_block
|
55
|
+
source = %q{
|
56
|
+
p
|
57
|
+
|
|
58
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
59
|
+
}
|
60
|
+
|
61
|
+
assert_html '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>', source
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_render_with_text_block_with_subsequent_markup
|
65
|
+
source = %q{
|
66
|
+
p
|
67
|
+
|
|
68
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
69
|
+
p Some more markup
|
70
|
+
}
|
71
|
+
|
72
|
+
assert_html '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p><p>Some more markup</p>', source
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_render_with_text_block_with_trailing_whitespace
|
76
|
+
source = %q{
|
77
|
+
' this is
|
78
|
+
a link to
|
79
|
+
a href="link" page
|
80
|
+
}
|
81
|
+
|
82
|
+
assert_html "this is\na link to <a href=\"link\">page</a>", source
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_nested_text
|
86
|
+
source = %q{
|
87
|
+
p
|
88
|
+
|
|
89
|
+
This is line one.
|
90
|
+
This is line two.
|
91
|
+
This is line three.
|
92
|
+
This is line four.
|
93
|
+
p This is a new paragraph.
|
94
|
+
}
|
95
|
+
|
96
|
+
assert_html "<p>This is line one.\n This is line two.\n This is line three.\n This is line four.</p><p>This is a new paragraph.</p>", source
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_nested_text_with_nested_html_one_same_line
|
100
|
+
source = %q{
|
101
|
+
p
|
102
|
+
| This is line one.
|
103
|
+
This is line two.
|
104
|
+
span.bold This is a bold line in the paragraph.
|
105
|
+
| This is more content.
|
106
|
+
}
|
107
|
+
|
108
|
+
assert_html "<p>This is line one.\n This is line two.<span class=\"bold\">This is a bold line in the paragraph.</span> This is more content.</p>", source
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_nested_text_with_nested_html_one_same_line2
|
112
|
+
source = %q{
|
113
|
+
p
|
114
|
+
|This is line one.
|
115
|
+
This is line two.
|
116
|
+
span.bold This is a bold line in the paragraph.
|
117
|
+
| This is more content.
|
118
|
+
}
|
119
|
+
|
120
|
+
assert_html "<p>This is line one.\n This is line two.<span class=\"bold\">This is a bold line in the paragraph.</span> This is more content.</p>", source
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_nested_text_with_nested_html
|
124
|
+
source = %q{
|
125
|
+
p
|
126
|
+
|
|
127
|
+
This is line one.
|
128
|
+
This is line two.
|
129
|
+
This is line three.
|
130
|
+
This is line four.
|
131
|
+
span.bold This is a bold line in the paragraph.
|
132
|
+
| This is more content.
|
133
|
+
}
|
134
|
+
|
135
|
+
assert_html "<p>This is line one.\n This is line two.\n This is line three.\n This is line four.<span class=\"bold\">This is a bold line in the paragraph.</span> This is more content.</p>", source
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_simple_paragraph_with_padding
|
139
|
+
source = %q{
|
140
|
+
p There will be 3 spaces in front of this line.
|
141
|
+
}
|
142
|
+
|
143
|
+
assert_html '<p> There will be 3 spaces in front of this line.</p>', source
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_paragraph_with_nested_text
|
147
|
+
source = %q{
|
148
|
+
p This is line one.
|
149
|
+
This is line two.
|
150
|
+
}
|
151
|
+
|
152
|
+
assert_html "<p>This is line one.\n This is line two.</p>", source
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_paragraph_with_padded_nested_text
|
156
|
+
source = %q{
|
157
|
+
p This is line one.
|
158
|
+
This is line two.
|
159
|
+
}
|
160
|
+
|
161
|
+
assert_html "<p> This is line one.\n This is line two.</p>", source
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_paragraph_with_attributes_and_nested_text
|
165
|
+
source = %q{
|
166
|
+
p#test class="paragraph" This is line one.
|
167
|
+
This is line two.
|
168
|
+
}
|
169
|
+
|
170
|
+
assert_html "<p class=\"paragraph\" id=\"test\">This is line one.\nThis is line two.</p>", source
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_output_code_with_leading_spaces
|
174
|
+
source = %q{
|
175
|
+
p= hello_world
|
176
|
+
p = hello_world
|
177
|
+
p = hello_world
|
178
|
+
}
|
179
|
+
|
180
|
+
assert_html '<p>Hello World from @env</p><p>Hello World from @env</p><p>Hello World from @env</p>', source
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_single_quoted_attributes
|
184
|
+
source = %q{
|
185
|
+
p class='underscored_class_name' = output_number
|
186
|
+
}
|
187
|
+
|
188
|
+
assert_html '<p class="underscored_class_name">1337</p>', source
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_nonstandard_attributes
|
192
|
+
source = %q{
|
193
|
+
p id="dashed-id" class="underscored_class_name" = output_number
|
194
|
+
}
|
195
|
+
|
196
|
+
assert_html '<p class="underscored_class_name" id="dashed-id">1337</p>', source
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_nonstandard_shortcut_attributes
|
200
|
+
source = %q{
|
201
|
+
p#dashed-id.underscored_class_name = output_number
|
202
|
+
}
|
203
|
+
|
204
|
+
assert_html '<p class="underscored_class_name" id="dashed-id">1337</p>', source
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_dashed_attributes
|
208
|
+
source = %q{
|
209
|
+
p data-info="Illudium Q-36" = output_number
|
210
|
+
}
|
211
|
+
|
212
|
+
assert_html '<p data-info="Illudium Q-36">1337</p>', source
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_dashed_attributes_with_shortcuts
|
216
|
+
source = %q{
|
217
|
+
p#marvin.martian data-info="Illudium Q-36" = output_number
|
218
|
+
}
|
219
|
+
|
220
|
+
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', source
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_parens_around_attributes
|
224
|
+
source = %q{
|
225
|
+
p(id="marvin" class="martian" data-info="Illudium Q-36") = output_number
|
226
|
+
}
|
227
|
+
|
228
|
+
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', source
|
229
|
+
end
|
230
|
+
|
231
|
+
def test_square_brackets_around_attributes
|
232
|
+
source = %q{
|
233
|
+
p[id="marvin" class="martian" data-info="Illudium Q-36"] = output_number
|
234
|
+
}
|
235
|
+
|
236
|
+
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', source
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_parens_around_attributes_with_equal_sign_snug_to_right_paren
|
240
|
+
source = %q{
|
241
|
+
p(id="marvin" class="martian" data-info="Illudium Q-36")= output_number
|
242
|
+
}
|
243
|
+
|
244
|
+
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', source
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_closed_tag
|
248
|
+
source = %q{
|
249
|
+
closed/
|
250
|
+
}
|
251
|
+
|
252
|
+
assert_html '<closed />', source, :format => :xhtml
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_attributs_with_parens_and_spaces
|
256
|
+
source = %q{label{ for='filter' }= hello_world}
|
257
|
+
assert_html '<label for="filter">Hello World from @env</label>', source
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_attributs_with_parens_and_spaces2
|
261
|
+
source = %q{label{ for='filter' } = hello_world}
|
262
|
+
assert_html '<label for="filter">Hello World from @env</label>', source
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_attributs_with_multiple_spaces
|
266
|
+
source = %q{label for='filter' class="test" = hello_world}
|
267
|
+
assert_html '<label class="test" for="filter">Hello World from @env</label>', source
|
268
|
+
end
|
269
|
+
|
270
|
+
def test_closed_tag_with_attributes
|
271
|
+
source = %q{
|
272
|
+
closed id="test" /
|
273
|
+
}
|
274
|
+
|
275
|
+
assert_html '<closed id="test" />', source, :format => :xhtml
|
276
|
+
end
|
277
|
+
|
278
|
+
def test_closed_tag_with_attributes_and_parens
|
279
|
+
source = %q{
|
280
|
+
closed(id="test")/
|
281
|
+
}
|
282
|
+
|
283
|
+
assert_html '<closed id="test" />', source, :format => :xhtml
|
284
|
+
end
|
285
|
+
|
286
|
+
def test_render_with_html_comments
|
287
|
+
source = %q{
|
288
|
+
p Hello
|
289
|
+
/! This is a comment
|
290
|
+
p World
|
291
|
+
}
|
292
|
+
|
293
|
+
assert_html "<p>Hello</p><!--This is a comment--><p>World</p>", source
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_render_with_html_comments_2
|
297
|
+
source = %q{
|
298
|
+
p Hello
|
299
|
+
/! This is a comment
|
300
|
+
Another comment
|
301
|
+
Last line of comment.
|
302
|
+
p World
|
303
|
+
}
|
304
|
+
|
305
|
+
assert_html "<p>Hello</p><!--This is a comment\n Another comment\nLast line of comment.--><p>World</p>", source
|
306
|
+
end
|
307
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestParserErrors < TestSlim
|
4
|
+
def test_correct_filename
|
5
|
+
source = %q{
|
6
|
+
! doctype 5
|
7
|
+
div Invalid
|
8
|
+
}
|
9
|
+
|
10
|
+
assert_syntax_error "Unexpected indentation\n test.slim, Line 3\n div Invalid\n ^\n ", source, :file => 'test.slim'
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_unexpected_indentation
|
14
|
+
source = %q{
|
15
|
+
! doctype 5
|
16
|
+
div Invalid
|
17
|
+
}
|
18
|
+
|
19
|
+
assert_syntax_error "Unexpected indentation\n (__TEMPLATE__), Line 3\n div Invalid\n ^\n ", source
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_unexpected_text_indentation
|
23
|
+
source = %q{
|
24
|
+
p
|
25
|
+
| text block
|
26
|
+
text
|
27
|
+
}
|
28
|
+
|
29
|
+
assert_syntax_error "Unexpected text indentation\n (__TEMPLATE__), Line 4\n text\n ^\n ", source
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_malformed_indentation
|
33
|
+
source = %q{
|
34
|
+
p
|
35
|
+
div Valid
|
36
|
+
div Invalid
|
37
|
+
}
|
38
|
+
|
39
|
+
assert_syntax_error "Malformed indentation\n (__TEMPLATE__), Line 4\n div Invalid\n ^\n ", source
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_unknown_line_indicator
|
43
|
+
source = %q{
|
44
|
+
p
|
45
|
+
div Valid
|
46
|
+
.valid
|
47
|
+
#valid
|
48
|
+
?invalid
|
49
|
+
}
|
50
|
+
|
51
|
+
assert_syntax_error "Unknown line indicator\n (__TEMPLATE__), Line 6\n ?invalid\n ^\n ", source
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_expected_closing_delimiter
|
55
|
+
source = %q{
|
56
|
+
p
|
57
|
+
img(src="img.jpg" title={title}
|
58
|
+
}
|
59
|
+
|
60
|
+
assert_syntax_error "Expected closing delimiter )\n (__TEMPLATE__), Line 3\n img(src=\"img.jpg\" title={title}\n ^\n ", source
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_expected_closing_attribute_delimiter
|
64
|
+
source = %q{
|
65
|
+
p
|
66
|
+
img src=[hash[1] + hash[2]
|
67
|
+
}
|
68
|
+
|
69
|
+
assert_syntax_error "Expected closing attribute delimiter ]\n (__TEMPLATE__), Line 3\n img src=[hash[1] + hash[2]\n ^\n ", source
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_unexpected_closing
|
73
|
+
source = %q{
|
74
|
+
p
|
75
|
+
img src=(1+1)]
|
76
|
+
}
|
77
|
+
|
78
|
+
assert_syntax_error "Unexpected closing ]\n (__TEMPLATE__), Line 3\n img src=(1+1)]\n ^\n ", source
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_invalid_empty_attribute
|
82
|
+
source = %q{
|
83
|
+
p
|
84
|
+
img{src= }
|
85
|
+
}
|
86
|
+
|
87
|
+
assert_syntax_error "Invalid empty attribute\n (__TEMPLATE__), Line 3\n img{src= }\n ^\n ", source
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_invalid_empty_attribute2
|
91
|
+
source = %q{
|
92
|
+
p
|
93
|
+
img{src=}
|
94
|
+
}
|
95
|
+
|
96
|
+
assert_syntax_error "Invalid empty attribute\n (__TEMPLATE__), Line 3\n img{src=}\n ^\n ", source
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_invalid_empty_attribute3
|
100
|
+
source = %q{
|
101
|
+
p
|
102
|
+
img src=
|
103
|
+
}
|
104
|
+
|
105
|
+
assert_syntax_error "Invalid empty attribute\n (__TEMPLATE__), Line 3\n img src=\n ^\n ", source
|
106
|
+
end
|
107
|
+
end
|