|
| 1 | +<?php |
| 2 | + |
| 3 | +test('doc tag', function () { |
| 4 | + $template = <<<'LIQUID' |
| 5 | + {% doc %} |
| 6 | + Renders loading-spinner. |
| 7 | + @param {string} foo - some foo |
| 8 | + @param {string} [bar] - optional bar |
| 9 | + @example |
| 10 | + {% render 'loading-spinner', foo: 'foo' %} |
| 11 | + {% render 'loading-spinner', foo: 'foo', bar: 'bar' %} |
| 12 | + {% enddoc %} |
| 13 | + LIQUID; |
| 14 | + |
| 15 | + assertTemplateResult('', $template); |
| 16 | +}); |
| 17 | + |
| 18 | +test('doc tag does not support extra arguments', function () { |
| 19 | + $template = <<<'LIQUID' |
| 20 | + {% doc extra %} |
| 21 | + {% enddoc %} |
| 22 | + LIQUID; |
| 23 | + |
| 24 | + assertMatchSyntaxError('Liquid syntax error (line 2): Unexpected token Identifier: "extra"', $template); |
| 25 | +}); |
| 26 | + |
| 27 | +test('doc tag must support valid tags', function () { |
| 28 | + assertMatchSyntaxError("Liquid syntax error (line 1): 'doc' tag was never closed", '{% doc %} foo'); |
| 29 | + assertMatchSyntaxError('Liquid syntax error (line 1): Unexpected character }', '{% doc } foo {% enddoc %}'); |
| 30 | + assertMatchSyntaxError('Liquid syntax error (line 1): Unexpected character }', '{% doc } foo %}{% enddoc %}'); |
| 31 | +}); |
| 32 | + |
| 33 | +test('doc tag ignores liquid nodes', function () { |
| 34 | + $template = <<<'LIQUID' |
| 35 | + {% doc %} |
| 36 | + {% if true %} |
| 37 | + {% if ... %} |
| 38 | + {%- for ? -%} |
| 39 | + {% while true %} |
| 40 | + {% |
| 41 | + unless if |
| 42 | + %} |
| 43 | + {% endcase %} |
| 44 | + {% enddoc %} |
| 45 | + LIQUID; |
| 46 | + |
| 47 | + assertTemplateResult('', $template); |
| 48 | +}); |
| 49 | + |
| 50 | +test('doc tag ignores unclosed liquid tags', function () { |
| 51 | + $template = <<<'LIQUID' |
| 52 | + {% doc %} |
| 53 | + {% if true %} |
| 54 | + {% enddoc %} |
| 55 | + LIQUID; |
| 56 | + |
| 57 | + assertTemplateResult('', $template); |
| 58 | +}); |
| 59 | + |
| 60 | +test('doc tag does not allow nested docs', function () { |
| 61 | + $template = <<<'LIQUID' |
| 62 | + {% doc %} |
| 63 | + {% doc %} |
| 64 | + {% doc %} |
| 65 | + {% enddoc %} |
| 66 | + LIQUID; |
| 67 | + |
| 68 | + assertMatchSyntaxError('Liquid syntax error (line 4): Nested doc tags are not allowed', $template); |
| 69 | +}); |
| 70 | + |
| 71 | +test('doc tag ignores nested raw tags', function () { |
| 72 | + $template = <<<'LIQUID' |
| 73 | + {% doc %} |
| 74 | + {% raw %} |
| 75 | + {% enddoc %} |
| 76 | + LIQUID; |
| 77 | + |
| 78 | + assertTemplateResult('', $template); |
| 79 | +}); |
| 80 | + |
| 81 | +test('doc tag ignores unclosed assign', function () { |
| 82 | + $template = <<<'LIQUID' |
| 83 | + {% doc %} |
| 84 | + {% assign foo = "1" |
| 85 | + {% enddoc %} |
| 86 | + LIQUID; |
| 87 | + |
| 88 | + assertTemplateResult('', $template); |
| 89 | +}); |
| 90 | + |
| 91 | +test('doc tag ignores malformed syntax', function () { |
| 92 | + $template = <<<'LIQUID' |
| 93 | + {% doc %} |
| 94 | + {% {{ |
| 95 | + {%- enddoc %} |
| 96 | + LIQUID; |
| 97 | + |
| 98 | + assertTemplateResult('', $template); |
| 99 | +}); |
| 100 | + |
| 101 | +test('doc tag preserves error line numbers', function () { |
| 102 | + $template = <<<'LIQUID' |
| 103 | + {% doc %} |
| 104 | + {% if true %} |
| 105 | + {% enddoc %} |
| 106 | + {{ errors.standard_error }} |
| 107 | + LIQUID; |
| 108 | + |
| 109 | + $expected = <<<'TEXT' |
| 110 | +
|
| 111 | + Liquid error (line 4): Standard error |
| 112 | + TEXT; |
| 113 | + |
| 114 | + assertTemplateResult( |
| 115 | + $expected, |
| 116 | + $template, |
| 117 | + ['errors' => new \Keepsuit\Liquid\Tests\Stubs\ErrorDrop], |
| 118 | + renderErrors: true |
| 119 | + ); |
| 120 | +}); |
| 121 | + |
| 122 | +test('doc tag whitespace control', function () { |
| 123 | + assertTemplateResult('Hello!', ' {%- doc -%}123{%- enddoc -%}Hello!'); |
| 124 | + assertTemplateResult('Hello!', '{%- doc -%}123{%- enddoc -%} Hello!'); |
| 125 | + assertTemplateResult('Hello!', ' {%- doc -%}123{%- enddoc -%} Hello!'); |
| 126 | + assertTemplateResult('Hello!', <<<'LIQUID' |
| 127 | + {%- doc %}Whitespace control!{% enddoc -%} |
| 128 | + Hello! |
| 129 | + LIQUID); |
| 130 | +}); |
| 131 | + |
| 132 | +test('doc tag delimiter handling', function () { |
| 133 | + assertTemplateResult('', <<<'LIQUID' |
| 134 | + {% if true -%} |
| 135 | + {% doc %} |
| 136 | + {% docEXTRA %}wut{% enddocEXTRA %}xyz |
| 137 | + {% enddoc %} |
| 138 | + {%- endif %} |
| 139 | + LIQUID); |
| 140 | + assertMatchSyntaxError("Liquid syntax error (line 1): 'doc' tag was never closed", '{% doc %}123{% enddoc xyz %}'); |
| 141 | + assertTemplateResult('', "{% doc %}123{% enddoc\n xyz %}{% enddoc %}"); |
| 142 | +}); |
0 commit comments