|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'test_helper' |
| 4 | + |
| 5 | +class InlineCommentTest < Minitest::Test |
| 6 | + include Liquid |
| 7 | + |
| 8 | + def test_inline_comment_returns_nothing |
| 9 | + assert_template_result('', '{%- # this is an inline comment -%}') |
| 10 | + assert_template_result('', '{%-# this is an inline comment -%}') |
| 11 | + assert_template_result('', '{% # this is an inline comment %}') |
| 12 | + assert_template_result('', '{%# this is an inline comment %}') |
| 13 | + end |
| 14 | + |
| 15 | + def test_inline_comment_does_not_require_a_space_after_the_pound_sign |
| 16 | + assert_template_result('', '{%#this is an inline comment%}') |
| 17 | + end |
| 18 | + |
| 19 | + def test_liquid_inline_comment_returns_nothing |
| 20 | + assert_template_result('Hey there, how are you doing today?', <<~LIQUID) |
| 21 | + {%- liquid |
| 22 | + # This is how you'd write a block comment in a liquid tag. |
| 23 | + # It looks a lot like what you'd have in ruby. |
| 24 | +
|
| 25 | + # You can use it as inline documentation in your |
| 26 | + # liquid blocks to explain why you're doing something. |
| 27 | + echo "Hey there, " |
| 28 | +
|
| 29 | + # It won't affect the output. |
| 30 | + echo "how are you doing today?" |
| 31 | + -%} |
| 32 | + LIQUID |
| 33 | + end |
| 34 | + |
| 35 | + def test_inline_comment_can_be_written_on_multiple_lines |
| 36 | + assert_template_result('', <<~LIQUID) |
| 37 | + {%- |
| 38 | + # That kind of block comment is also allowed. |
| 39 | + # It would only be a stylistic difference. |
| 40 | + # Much like JavaScript's /* */ comments and their |
| 41 | + # leading * on new lines. |
| 42 | + -%} |
| 43 | + LIQUID |
| 44 | + end |
| 45 | + |
| 46 | + def test_inline_comment_multiple_pound_signs |
| 47 | + assert_template_result('', <<~LIQUID) |
| 48 | + {%- liquid |
| 49 | + ###################################### |
| 50 | + # We support comments like this too. # |
| 51 | + ###################################### |
| 52 | + -%} |
| 53 | + LIQUID |
| 54 | + end |
| 55 | + |
| 56 | + def test_inline_comments_require_the_pound_sign_on_every_new_line |
| 57 | + assert_match_syntax_error("Each line of comments must be prefixed by the '#' character", <<~LIQUID) |
| 58 | + {%- |
| 59 | + # some comment |
| 60 | + echo 'hello world' |
| 61 | + -%} |
| 62 | + LIQUID |
| 63 | + end |
| 64 | + |
| 65 | + def test_inline_comment_does_not_support_nested_tags |
| 66 | + assert_template_result(' -%}', "{%- # {% echo 'hello world' %} -%}") |
| 67 | + end |
| 68 | +end |
0 commit comments