|
| 1 | +import { Liquid } from '../../../../src/liquid' |
| 2 | +import { expect, use } from 'chai' |
| 3 | +import * as chaiAsPromised from 'chai-as-promised' |
| 4 | + |
| 5 | +use(chaiAsPromised) |
| 6 | + |
| 7 | +describe('tags/inline-comment', function () { |
| 8 | + const liquid = new Liquid() |
| 9 | + it('should ignore plain string', async function () { |
| 10 | + const src = 'My name is {% # super %} Shopify.' |
| 11 | + const html = await liquid.parseAndRender(src) |
| 12 | + return expect(html).to.equal('My name is Shopify.') |
| 13 | + }) |
| 14 | + it('should ignore output tokens', async function () { |
| 15 | + const src = '{% #\n{{ foo}} \n %}' |
| 16 | + const html = await liquid.parseAndRender(src) |
| 17 | + return expect(html).to.equal('') |
| 18 | + }) |
| 19 | + it('should support whitespace control', async function () { |
| 20 | + const src = '{%- # some comment \n -%}\nfoo' |
| 21 | + const html = await liquid.parseAndRender(src) |
| 22 | + return expect(html).to.equal('foo') |
| 23 | + }) |
| 24 | + it('should handle hash without trailing whitespace', async function () { |
| 25 | + const src = '{% #some comment %}' |
| 26 | + const html = await liquid.parseAndRender(src) |
| 27 | + return expect(html).to.equal('') |
| 28 | + }) |
| 29 | + it('should handle hash without leading whitespace', async function () { |
| 30 | + const src = '{%#some comment %}' |
| 31 | + const html = await liquid.parseAndRender(src) |
| 32 | + return expect(html).to.equal('') |
| 33 | + }) |
| 34 | + it('should handle empty comment', async function () { |
| 35 | + const src = '{%#%}' |
| 36 | + const html = await liquid.parseAndRender(src) |
| 37 | + return expect(html).to.equal('') |
| 38 | + }) |
| 39 | + it('should support multiple lines', async function () { |
| 40 | + const src = [ |
| 41 | + '{%-', |
| 42 | + ' # spread inline comments', |
| 43 | + ' # over multiple lines', |
| 44 | + '-%}' |
| 45 | + ].join('\n') |
| 46 | + const html = await liquid.parseAndRender(src) |
| 47 | + return expect(html).to.equal('') |
| 48 | + }) |
| 49 | + it('should enforce leading hashes', async function () { |
| 50 | + const src = [ |
| 51 | + '{%-', |
| 52 | + ' # spread inline comments', |
| 53 | + ' over multiple lines', |
| 54 | + '-%}' |
| 55 | + ].join('\n') |
| 56 | + return expect(liquid.parseAndRender(src)) |
| 57 | + .to.be.rejectedWith(/every line of an inline comment must start with a '#' character/) |
| 58 | + }) |
| 59 | + describe('sync support', function () { |
| 60 | + it('should ignore plain string', function () { |
| 61 | + const src = 'My name is {% # super %} Shopify.' |
| 62 | + const html = liquid.parseAndRenderSync(src) |
| 63 | + return expect(html).to.equal('My name is Shopify.') |
| 64 | + }) |
| 65 | + }) |
| 66 | + describe('liquid tag', function () { |
| 67 | + it('should treat lines starting with a hash as a comment', async function () { |
| 68 | + const src = [ |
| 69 | + '{% liquid ', |
| 70 | + ' # first comment line', |
| 71 | + ' # second comment line', |
| 72 | + '', |
| 73 | + ' # another comment line', |
| 74 | + ' echo \'Hello \'', |
| 75 | + '', |
| 76 | + ' # more comments', |
| 77 | + ' echo \'goodbye\'', |
| 78 | + '-%}' |
| 79 | + ].join('\n') |
| 80 | + const html = await liquid.parseAndRender(src) |
| 81 | + return expect(html).to.equal('Hello goodbye') |
| 82 | + }) |
| 83 | + it('should handle lots of hashes', async function () { |
| 84 | + const src = [ |
| 85 | + '{% liquid', |
| 86 | + ' ##########################', |
| 87 | + ' # spread inline comments #', |
| 88 | + ' ##########################', |
| 89 | + '-%}' |
| 90 | + ].join('\n') |
| 91 | + const html = await liquid.parseAndRender(src) |
| 92 | + return expect(html).to.equal('') |
| 93 | + }) |
| 94 | + }) |
| 95 | +}) |
0 commit comments