@@ -20,6 +20,21 @@ def test_doc_tag
2020 assert_template_result ( '' , template )
2121 end
2222
23+ def test_doc_tag_body_content
24+ doc_content = " Documentation content\n @param {string} foo - test\n "
25+ template_source = "{% doc %}#{ doc_content } {% enddoc %}"
26+
27+ doc_tag = nil
28+ ParseTreeVisitor
29+ . for ( Template . parse ( template_source ) . root )
30+ . add_callback_for ( Liquid ::Doc ) do |tag |
31+ doc_tag = tag
32+ end
33+ . visit
34+
35+ assert_equal ( doc_content , doc_tag . nodelist . first . to_s )
36+ end
37+
2338 def test_doc_tag_does_not_support_extra_arguments
2439 error = assert_raises ( Liquid ::SyntaxError ) do
2540 template = <<~LIQUID . chomp
@@ -116,6 +131,20 @@ def test_doc_tag_ignores_malformed_syntax
116131 assert_template_result ( '' , template )
117132 end
118133
134+ def test_doc_tag_captures_token_before_enddoc
135+ template_source = "{% doc %}{{ incomplete{% enddoc %}"
136+
137+ doc_tag = nil
138+ ParseTreeVisitor
139+ . for ( Template . parse ( template_source ) . root )
140+ . add_callback_for ( Liquid ::Doc ) do |tag |
141+ doc_tag = tag
142+ end
143+ . visit
144+
145+ assert_equal ( "{{ incomplete" , doc_tag . nodelist . first . to_s )
146+ end
147+
119148 def test_doc_tag_preserves_error_line_numbers
120149 template = Liquid ::Template . parse ( <<~LIQUID . chomp , line_numbers : true )
121150 {% doc %}
@@ -145,11 +174,11 @@ def test_doc_tag_whitespace_control
145174
146175 def test_doc_tag_delimiter_handling
147176 assert_template_result ( '' , <<~LIQUID . chomp )
148- {% if true %}
149- {% doc %}
150- {% docEXTRA %}wut{% enddocEXTRA %}xyz
151- {% enddoc %}
152- {% endif %}
177+ {%- if true - %}
178+ {%- doc - %}
179+ {%- docEXTRA - %}wut{% enddocEXTRA - %}xyz
180+ {%- enddoc - %}
181+ {%- endif - %}
153182 LIQUID
154183
155184 assert_template_result ( '' , "{% doc %}123{% enddoc xyz %}" )
@@ -167,6 +196,80 @@ def test_doc_tag_visitor
167196 )
168197 end
169198
199+ def test_doc_tag_blank_with_empty_content
200+ template_source = "{% doc %}{% enddoc %}"
201+
202+ doc_tag = nil
203+ ParseTreeVisitor
204+ . for ( Template . parse ( template_source ) . root )
205+ . add_callback_for ( Liquid ::Doc ) do |tag |
206+ doc_tag = tag
207+ end
208+ . visit
209+
210+ assert_equal ( true , doc_tag . blank? )
211+ end
212+
213+ def test_doc_tag_blank_with_content
214+ template_source = "{% doc %}Some documentation{% enddoc %}"
215+
216+ doc_tag = nil
217+ ParseTreeVisitor
218+ . for ( Template . parse ( template_source ) . root )
219+ . add_callback_for ( Liquid ::Doc ) do |tag |
220+ doc_tag = tag
221+ end
222+ . visit
223+
224+ assert_equal ( false , doc_tag . blank? )
225+ end
226+
227+ def test_doc_tag_blank_with_whitespace_only
228+ template_source = "{% doc %} {% enddoc %}"
229+
230+ doc_tag = nil
231+ ParseTreeVisitor
232+ . for ( Template . parse ( template_source ) . root )
233+ . add_callback_for ( Liquid ::Doc ) do |tag |
234+ doc_tag = tag
235+ end
236+ . visit
237+
238+ assert_equal ( false , doc_tag . blank? )
239+ end
240+
241+ def test_doc_tag_nodelist_returns_array_with_body
242+ doc_content = "Documentation content\n @param {string} foo"
243+ template_source = "{% doc %}#{ doc_content } {% enddoc %}"
244+
245+ doc_tag = nil
246+ ParseTreeVisitor
247+ . for ( Template . parse ( template_source ) . root )
248+ . add_callback_for ( Liquid ::Doc ) do |tag |
249+ doc_tag = tag
250+ end
251+ . visit
252+
253+ assert_equal ( [ doc_content ] , doc_tag . nodelist )
254+ assert_equal ( 1 , doc_tag . nodelist . length )
255+ assert_equal ( doc_content , doc_tag . nodelist . first )
256+ end
257+
258+ def test_doc_tag_nodelist_with_empty_content
259+ template_source = "{% doc %}{% enddoc %}"
260+
261+ doc_tag = nil
262+ ParseTreeVisitor
263+ . for ( Template . parse ( template_source ) . root )
264+ . add_callback_for ( Liquid ::Doc ) do |tag |
265+ doc_tag = tag
266+ end
267+ . visit
268+
269+ assert_equal ( [ "" ] , doc_tag . nodelist )
270+ assert_equal ( 1 , doc_tag . nodelist . length )
271+ end
272+
170273 private
171274
172275 def traversal ( template )
0 commit comments