diff --git a/package.json b/package.json index 48b6677a8..62173d857 100644 --- a/package.json +++ b/package.json @@ -32,26 +32,26 @@ "any-promise": "^1.3.0" }, "devDependencies": { - "babel-preset-es2015": "^6.14.0", + "babel-preset-es2015": "^6.24.1", "babelify": "^7.3.0", - "browserify": "^13.1.0", - "chai": "^3.5.0", - "chai-as-promised": "^6.0.0", - "coveralls": "^2.11.9", - "eslint": "^3.19.0", - "eslint-config-standard": "^10.2.0", - "eslint-plugin-import": "^2.2.0", - "eslint-plugin-mocha": "^4.9.0", - "eslint-plugin-node": "^4.2.2", + "browserify": "^14.4.0", + "chai": "^4.1.0", + "chai-as-promised": "^7.1.1", + "coveralls": "^2.13.1", + "eslint": "^4.3.0", + "eslint-config-standard": "^10.2.1", + "eslint-plugin-import": "^2.7.0", + "eslint-plugin-mocha": "^4.11.0", + "eslint-plugin-node": "^5.1.1", "eslint-plugin-promise": "^3.5.0", "eslint-plugin-standard": "^3.0.1", - "express": "^4.14.0", - "istanbul": "^0.4.3", - "mocha": "^3.0.2", - "mock-fs": "^3.9.0", - "sinon": "^1.17.4", - "sinon-chai": "^2.8.0", - "supertest": "^2.0.0", - "uglifyjs": "^2.4.10" + "express": "^4.15.3", + "istanbul": "^0.4.5", + "mocha": "^3.4.2", + "mock-fs": "^4.4.1", + "sinon": "^2.4.1", + "sinon-chai": "^2.12.0", + "supertest": "^3.0.0", + "uglifyjs": "^2.4.11" } } diff --git a/src/scope.js b/src/scope.js index 7c6a54758..77f843d3f 100644 --- a/src/scope.js +++ b/src/scope.js @@ -63,7 +63,7 @@ var Scope = { return (obj[key] = val) } if (undefined === obj[key]) obj[key] = {} - // case for readonly objects + // case for readonly objects obj = obj[key] || {} } } diff --git a/src/tag.js b/src/tag.js index 2e45d63db..a43eec3e3 100644 --- a/src/tag.js +++ b/src/tag.js @@ -27,15 +27,15 @@ module.exports = function () { return Promise.resolve('') } return Promise.resolve() - .then(() => typeof impl.render === 'function' - ? impl.render(scope, obj) : '') - .catch(function (e) { - if (_.isError(e)) { - throw e - } - var msg = `Please reject with an Error in ${impl.render}, got ${e}` - throw new Error(msg) - }) + .then(() => typeof impl.render === 'function' + ? impl.render(scope, obj) : '') + .catch(function (e) { + if (_.isError(e)) { + throw e + } + var msg = `Please reject with an Error in ${impl.render}, got ${e}` + throw new Error(msg) + }) }, parse: function (token, tokens) { this.type = 'tag' diff --git a/src/tokenizer.js b/src/tokenizer.js index cde44d1d4..e443ee0a9 100644 --- a/src/tokenizer.js +++ b/src/tokenizer.js @@ -16,7 +16,7 @@ function parse (html, filepath, options) { var parsedLinesCount = 0 while ((result = syntax.exec(html)) !== null) { - // passed html fragments + // passed html fragments if (result.index > lastMatchEnd) { htmlFragment = html.slice(lastMatchEnd, result.index) tokens.push({ @@ -49,7 +49,7 @@ function parse (html, filepath, options) { lastMatchEnd = syntax.lastIndex } - // remaining html + // remaining html if (html.length > lastMatchEnd) { htmlFragment = html.slice(lastMatchEnd, html.length) tokens.push({ diff --git a/src/util/error.js b/src/util/error.js index b29369152..cdcf85851 100644 --- a/src/util/error.js +++ b/src/util/error.js @@ -34,7 +34,7 @@ ParseError.prototype = Object.create(Error.prototype) ParseError.prototype.constructor = ParseError function RenderError (e, tpl) { - // return the original render error + // return the original render error if (e instanceof RenderError) { return e } @@ -79,14 +79,14 @@ function mkContext (input, line) { var end = Math.min(line + 3, lines.length) var context = _ - .range(begin, end + 1) - .map(l => [ - (l === line) ? '>> ' : ' ', - align(l, end), - '| ', - lines[l - 1] - ].join('')) - .join('\n') + .range(begin, end + 1) + .map(l => [ + (l === line) ? '>> ' : ' ', + align(l, end), + '| ', + lines[l - 1] + ].join('')) + .join('\n') return context } diff --git a/src/util/promise.js b/src/util/promise.js index e7df89d34..8f3c452d9 100644 --- a/src/util/promise.js +++ b/src/util/promise.js @@ -25,8 +25,8 @@ function mapSeries (iterable, iteratee) { var result = [] iterable.forEach(function (item, idx) { ret = ret - .then(() => iteratee(item, idx, iterable)) - .then(x => result.push(x)) + .then(() => iteratee(item, idx, iterable)) + .then(x => result.push(x)) }) return ret.then(() => result) } diff --git a/src/util/underscore.js b/src/util/underscore.js index 2101595b9..3870255c6 100644 --- a/src/util/underscore.js +++ b/src/util/underscore.js @@ -9,7 +9,7 @@ function isString (value) { function isError (value) { var signature = Object.prototype.toString.call(value) - // [object XXXError] + // [object XXXError] return signature.substr(-6, 5) === 'Error' || (typeof value.message === 'string' && typeof value.name === 'string') } diff --git a/test/express.js b/test/express.js index a1b8746ee..81693c6f7 100644 --- a/test/express.js +++ b/test/express.js @@ -32,8 +32,8 @@ describe('engine#express()', function () { mock({ '/views/name.html': 'My name is {{name}}.' }) app.set('views', ['/views']) request(app).get('/name') - .expect('My name is harttle.') - .expect(200, done) + .expect('My name is harttle.') + .expect(200, done) }) it('should pass error when file not found', function (done) { var view = { @@ -58,8 +58,8 @@ describe('engine#express()', function () { }) app.set('views', ['/views']) request(app).get('/include/foo') - .expect('foo') - .expect(200, done) + .expect('foo') + .expect(200, done) }) it('should respect express views (Array) when lookup', function (done) { mock({ @@ -68,8 +68,8 @@ describe('engine#express()', function () { }) app.set('views', ['/views', '/partials']) request(app).get('/include/bar') - .expect('bar') - .expect(200, done) + .expect('bar') + .expect(200, done) }) it('should respect express views (String) when lookup', function (done) { mock({ @@ -78,8 +78,8 @@ describe('engine#express()', function () { }) app.set('views', '/views') request(app).get('/include/bar') - .expect('bar') - .expect(200, done) + .expect('bar') + .expect(200, done) }) it('should respect express views (Undefined) when lookup', function (done) { var files = {} @@ -88,7 +88,7 @@ describe('engine#express()', function () { mock(files) request(app).get('/include/bar') - .expect('bar') - .expect(200, done) + .expect('bar') + .expect(200, done) }) }) diff --git a/test/filters.js b/test/filters.js index ac61caa27..ac2968acc 100644 --- a/test/filters.js +++ b/test/filters.js @@ -32,7 +32,7 @@ describe('filters', function () { describe('append', function () { it('should return "-3abc" for -3, "abc"', - () => test('{{ -3 | append: "abc" }}', '-3abc')) + () => test('{{ -3 | append: "abc" }}', '-3abc')) it('should return "abar" for "a",foo', () => test('{{ "a" | append: foo }}', 'abar')) }) @@ -72,15 +72,15 @@ describe('filters', function () { describe('downcase', function () { it('should return "parker moore" for "Parker Moore"', - () => test('{{ "Parker Moore" | downcase }}', 'parker moore')) + () => test('{{ "Parker Moore" | downcase }}', 'parker moore')) it('should return "apple" for "apple"', - () => test('{{ "apple" | downcase }}', 'apple')) + () => test('{{ "apple" | downcase }}', 'apple')) }) describe('escape', function () { it('should escape \' and &', function () { return test('{{ "Have you read \'James & the Giant Peach\'?" | escape }}', - 'Have you read 'James & the Giant Peach'?') + 'Have you read 'James & the Giant Peach'?') }) it('should escape normal string', function () { return test('{{ "Tetsuro Takara" | escape }}', 'Tetsuro Takara') @@ -92,9 +92,9 @@ describe('filters', function () { describe('escape_once', function () { it('should do escape', () => - test('{{ "1 < 2 & 3" | escape_once }}', '1 < 2 & 3')) + test('{{ "1 < 2 & 3" | escape_once }}', '1 < 2 & 3')) it('should not escape twice', - () => test('{{ "1 < 2 & 3" | escape_once }}', '1 < 2 & 3')) + () => test('{{ "1 < 2 & 3" | escape_once }}', '1 < 2 & 3')) }) it('should support split/first', function () { @@ -135,7 +135,7 @@ describe('filters', function () { it('should return "2" for 4,2', () => test('{{ 4 | minus: 2 }}', '2')) it('should return "12" for 16,4', () => test('{{ 16 | minus: 4 }}', '12')) it('should return "171.357" for 183.357,12', - () => test('{{ 183.357 | minus: 12 }}', '171.357')) + () => test('{{ 183.357 | minus: 12 }}', '171.357')) it('should convert first arg as number', () => test('{{ "4" | minus: 1 }}', '3')) it('should convert both args as number', () => test('{{ "4" | minus: "1" }}', '3')) }) @@ -144,7 +144,7 @@ describe('filters', function () { it('should return "1" for 3,2', () => test('{{ 3 | modulo: 2 }}', '1')) it('should return "3" for 24,7', () => test('{{ 24 | modulo: 7 }}', '3')) it('should return "3.357" for 183.357,12', - () => test('{{ 183.357 | modulo: 12 }}', '3.357')) + () => test('{{ 183.357 | modulo: 12 }}', '3.357')) it('should convert string', () => test('{{ "24" | modulo: "7" }}', '3')) }) @@ -164,7 +164,7 @@ describe('filters', function () { it('should return "6" for 4,2', () => test('{{ 4 | plus: 2 }}', '6')) it('should return "20" for 16,4', () => test('{{ 16 | plus: 4 }}', '20')) it('should return "195.357" for 183.357,12', - () => test('{{ 183.357 | plus: 12 }}', '195.357')) + () => test('{{ 183.357 | plus: 12 }}', '195.357')) it('should convert first arg as number', () => test('{{ "4" | plus: 2 }}', '6')) it('should convert both args as number', () => test('{{ "4" | plus: "2" }}', '6')) }) @@ -172,60 +172,60 @@ describe('filters', function () { it('should support prepend', function () { return test('{% assign url = "liquidmarkup.com" %}' + '{{ "/index.html" | prepend: url }}', - 'liquidmarkup.com/index.html') + 'liquidmarkup.com/index.html') }) it('should support remove', function () { return test('{{ "I strained to see the train through the rain" | remove: "rain" }}', - 'I sted to see the t through the ') + 'I sted to see the t through the ') }) it('should support remove_first', function () { return test('{{ "I strained to see the train through the rain" | remove_first: "rain" }}', - 'I sted to see the train through the rain') + 'I sted to see the train through the rain') }) it('should support replace', function () { return test('{{ "Take my protein pills and put my helmet on" | replace: "my", "your" }}', - 'Take your protein pills and put your helmet on') + 'Take your protein pills and put your helmet on') }) it('should support replace_first', function () { return test('{% assign my_string = "Take my protein pills and put my helmet on" %}\n' + '{{ my_string | replace_first: "my", "your" }}', - '\nTake your protein pills and put my helmet on') + '\nTake your protein pills and put my helmet on') }) it('should support reverse', function () { return test('{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }}', - '.moT rojaM ot lortnoc dnuorG') + '.moT rojaM ot lortnoc dnuorG') }) describe('round', function () { it('should return "1" for 1.2', () => test('{{1.2|round}}', '1')) it('should return "3" for 2.7', () => test('{{2.7|round}}', '3')) it('should return "183.36" for 183.357,2', - () => test('{{183.357|round: 2}}', '183.36')) + () => test('{{183.357|round: 2}}', '183.36')) it('should convert string to number', () => test('{{"2.7"|round}}', '3')) }) it('should support rstrip', function () { return test('{{ " So much room for activities! " | rstrip }}', - ' So much room for activities!') + ' So much room for activities!') }) describe('size', function () { it('should return string length', - () => test('{{ "Ground control to Major Tom." | size }}', '28')) + () => test('{{ "Ground control to Major Tom." | size }}', '28')) it('should return array size', function () { return test('{% assign my_array = "apples, oranges, peaches, plums"' + ' | split: ", " %}{{ my_array | size }}', - '4') + '4') }) it('should also be used with dot notation - string', - () => test('{% assign my_string = "Ground control to Major Tom." %}{{ my_string.size }}', '28')) + () => test('{% assign my_string = "Ground control to Major Tom." %}{{ my_string.size }}', '28')) it('should also be used with dot notation - array', - () => test('{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}{{ my_array.size }}', '4')) + () => test('{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}{{ my_array.size }}', '4')) }) describe('slice', function () { @@ -239,7 +239,7 @@ describe('filters', function () { return test('{% assign my_array = "zebra, octopus, giraffe, Sally Snake"' + ' | split: ", " %}' + '{{ my_array | sort | join: ", " }}', - 'Sally Snake, giraffe, octopus, zebra') + 'Sally Snake, giraffe, octopus, zebra') }) it('should support split', function () { @@ -247,18 +247,18 @@ describe('filters', function () { '{% for member in beatles %}' + '{{ member }} ' + '{% endfor %}', - 'John Paul George Ringo ') + 'John Paul George Ringo ') }) it('should support strip', function () { return test('{{ " So much room for activities! " | strip }}', - 'So much room for activities!') + 'So much room for activities!') }) describe('strip_html', function () { it('should strip all tags', function () { return test('{{ "Have you read Ulysses?" | strip_html }}', - 'Have you read Ulysses?') + 'Have you read Ulysses?') }) it('should strip until empty', function () { return test('{{"

< p >

" | strip_html }}', '') @@ -269,33 +269,33 @@ describe('filters', function () { return test('{% capture string_with_newlines %}\n' + 'Hello\nthere\n{% endcapture %}' + '{{ string_with_newlines | strip_newlines }}', - 'Hellothere') + 'Hellothere') }) describe('times', function () { it('should return "6" for 3,2', () => test('{{ 3 | times: 2 }}', '6')) it('should return "168" for 24,7', () => test('{{ 24 | times: 7 }}', '168')) it('should return "2200.284" for 183.357,12', - () => test('{{ 183.357 | times: 12 }}', '2200.284')) + () => test('{{ 183.357 | times: 12 }}', '2200.284')) it('should convert string to number', () => test('{{ "24" | times: "7" }}', '168')) }) describe('truncate', function () { it('should truncate when string too long', function () { return test('{{ "Ground control to Major Tom." | truncate: 20 }}', - 'Ground control to...') + 'Ground control to...') }) it('should not truncate when string not long enough', function () { return test('{{ "Ground control to Major Tom." | truncate: 80 }}', - 'Ground control to Major Tom.') + 'Ground control to Major Tom.') }) it('should truncate with custom ellipsis', function () { return test('{{ "Ground control to Major Tom." | truncate: 25,", and so on" }}', - 'Ground control, and so on') + 'Ground control, and so on') }) it('should truncate with empty custom ellipsis', function () { return test('{{ "Ground control to Major Tom." | truncate: 20, "" }}', - 'Ground control to Ma') + 'Ground control to Ma') }) it('should not truncate when short enough', function () { return test('{{ "12345" | truncate: 5 }}', '12345') @@ -305,35 +305,35 @@ describe('filters', function () { describe('truncatewords', function () { it('should truncate when too many words', function () { return test('{{ "Ground control to Major Tom." | truncatewords: 3 }}', - 'Ground control to...') + 'Ground control to...') }) it('should not truncate when not enough words', function () { return test('{{ "Ground control to Major Tom." | truncatewords: 8 }}', - 'Ground control to Major Tom.') + 'Ground control to Major Tom.') }) it('should truncate with custom ellipsis', function () { return test('{{ "Ground control to Major Tom." | truncatewords: 3, "--" }}', - 'Ground control to--') + 'Ground control to--') }) it('should truncate with empty custom ellipsis', function () { return test('{{ "Ground control to Major Tom." | truncatewords: 3, "" }}', - 'Ground control to') + 'Ground control to') }) }) it('should support uniq', function () { return test('{% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %}' + '{{ my_array | uniq | join: ", " }}', - 'ants, bugs, bees') + 'ants, bugs, bees') }) it('should support upcase', () => test('{{ "Parker Moore" | upcase }}', 'PARKER MOORE')) describe('url_encode', function () { it('should encode @', - () => test('{{ "john@liquid.com" | url_encode }}', 'john%40liquid.com')) + () => test('{{ "john@liquid.com" | url_encode }}', 'john%40liquid.com')) it('should encode ', - () => test('{{ "Tetsuro Takara" | url_encode }}', 'Tetsuro%20Takara')) + () => test('{{ "Tetsuro Takara" | url_encode }}', 'Tetsuro%20Takara')) }) describe('obj_test', function () { diff --git a/test/liquid.js b/test/liquid.js index 6fb91e09c..29dc5e0d6 100644 --- a/test/liquid.js +++ b/test/liquid.js @@ -83,11 +83,11 @@ describe('liquid', function () { describe('#renderFile()', function () { it('should render file', function () { return expect(engine.renderFile('/root/files/foo.html', ctx)) - .to.eventually.equal('foo') + .to.eventually.equal('foo') }) it('should accept relative path', function () { return expect(engine.renderFile('files/foo.html')) - .to.eventually.equal('foo') + .to.eventually.equal('foo') }) it('should resolve array as root', function () { engine = Liquid({ @@ -95,7 +95,7 @@ describe('liquid', function () { extname: '.html' }) return expect(engine.renderFile('files/foo.html')) - .to.eventually.equal('foo') + .to.eventually.equal('foo') }) it('should default root to cwd', function () { var files = {} @@ -106,7 +106,7 @@ describe('liquid', function () { extname: '.html' }) return expect(engine.renderFile('foo.html')) - .to.eventually.equal('FOO') + .to.eventually.equal('FOO') }) it('should render file with context', function () { return expect(engine.renderFile('/root/files/name.html', ctx)).to.eventually.equal('My name is harttle.') @@ -120,17 +120,17 @@ describe('liquid', function () { extname: '.html' }) return expect(engine.renderFile('/not/exist.html')).to - .be.rejectedWith(/failed to lookup \/not\/exist.html in: \/boo,\/root\//i) + .be.rejectedWith(/failed to lookup \/not\/exist.html in: \/boo,\/root\//i) }) it('should throw when file not readable', function () { return expect(engine.renderFile('/un-readable.html')).to - .be.rejectedWith(/EACCES/) + .be.rejectedWith(/EACCES/) }) }) describe('strict', function () { it('should not throw when strict_variables false (default)', function () { return expect(engine.parseAndRender('before{{notdefined}}after', ctx)).to - .eventually.equal('beforeafter') + .eventually.equal('beforeafter') }) it('should throw when strict_variables true', function () { var tpl = engine.parse('before{{notdefined}}after') @@ -138,7 +138,7 @@ describe('liquid', function () { strict_variables: true } return expect(engine.render(tpl, ctx, opts)).to - .be.rejectedWith(/undefined variable: notdefined/) + .be.rejectedWith(/undefined variable: notdefined/) }) it('should pass strict_variables to render by parseAndRender', function () { var html = 'before{{notdefined}}after' diff --git a/test/scope.js b/test/scope.js index ae9729453..de6ab3e3f 100644 --- a/test/scope.js +++ b/test/scope.js @@ -20,27 +20,27 @@ describe('scope', function () { describe('#propertyAccessSeq()', function () { it('should handle dot syntax', function () { expect(scope.propertyAccessSeq('foo.bar')) - .to.deep.equal(['foo', 'bar']) + .to.deep.equal(['foo', 'bar']) }) it('should handle [] syntax', function () { expect(scope.propertyAccessSeq('foo["bar"]')) - .to.deep.equal(['foo', 'bar']) + .to.deep.equal(['foo', 'bar']) }) it('should handle [] syntax', function () { expect(scope.propertyAccessSeq('foo[foo]')) - .to.deep.equal(['foo', 'zoo']) + .to.deep.equal(['foo', 'zoo']) }) it('should handle nested access 1', function () { expect(scope.propertyAccessSeq('foo[bar.zoo]')) - .to.deep.equal(['foo', 'coo']) + .to.deep.equal(['foo', 'coo']) }) it('should handle nested access 2', function () { expect(scope.propertyAccessSeq('foo[bar["zoo"]]')) - .to.deep.equal(['foo', 'coo']) + .to.deep.equal(['foo', 'coo']) }) it('should handle nested access 3', function () { expect(scope.propertyAccessSeq('bar["foo"].zoo')) - .to.deep.equal(['bar', 'foo', 'zoo']) + .to.deep.equal(['bar', 'foo', 'zoo']) }) }) diff --git a/test/syntax.js b/test/syntax.js index 50c7466f2..df7df233f 100644 --- a/test/syntax.js +++ b/test/syntax.js @@ -32,7 +32,7 @@ describe('expression', function () { }) describe('.isTruthy()', function () { - // Spec: https://shopify.github.io/liquid/basics/truthy-and-falsy/ + // Spec: https://shopify.github.io/liquid/basics/truthy-and-falsy/ expect(isTruthy(true)).to.be.true expect(isTruthy(false)).to.be.false expect(isTruthy(null)).to.be.false diff --git a/test/tag.js b/test/tag.js index b38def0b0..4dd5172aa 100644 --- a/test/tag.js +++ b/test/tag.js @@ -43,13 +43,13 @@ describe('tag', function () { render: spy }) return tag - .construct({ - type: 'tag', - value: 'foo', - name: 'foo' - }, []) - .render(scope, {}) - .then(() => expect(spy).to.have.been.called) + .construct({ + type: 'tag', + value: 'foo', + name: 'foo' + }, []) + .render(scope, {}) + .then(() => expect(spy).to.have.been.called) }) describe('hash', function () { @@ -68,31 +68,31 @@ describe('tag', function () { }) it('should call tag.render with scope', function () { return tag.construct(token, []).render(scope, {}) - .then(() => expect(spy).to.have.been.calledWithMatch(scope)) + .then(() => expect(spy).to.have.been.calledWithMatch(scope)) }) it('should resolve identifier hash', function () { return tag.construct(token, []).render(scope, {}) - .then(() => expect(spy).to.have.been.calledWithMatch({}, { - aa: 'bar' - })) + .then(() => expect(spy).to.have.been.calledWithMatch({}, { + aa: 'bar' + })) }) it('should accept space between key/value', function () { return tag.construct(token, []).render(scope, {}) - .then(() => expect(spy).to.have.been.calledWithMatch({}, { - bb: 2 - })) + .then(() => expect(spy).to.have.been.calledWithMatch({}, { + bb: 2 + })) }) it('should resolve number value hash', function () { return tag.construct(token, []).render(scope, {}) - .then(() => expect(spy).to.have.been.calledWithMatch(scope, { - cc: 2.3 - })) + .then(() => expect(spy).to.have.been.calledWithMatch(scope, { + cc: 2.3 + })) }) it('should resolve property access hash', function () { return tag.construct(token, []).render(scope, {}) - .then(() => expect(spy).to.have.been.calledWithMatch(scope, { - dd: 'uoo' - })) + .then(() => expect(spy).to.have.been.calledWithMatch(scope, { + dd: 'uoo' + })) }) }) }) diff --git a/test/tags/assign.js b/test/tags/assign.js index b4625c335..d93f2831f 100644 --- a/test/tags/assign.js +++ b/test/tags/assign.js @@ -14,17 +14,17 @@ describe('tags/assign', function () { it('should assign as string', function () { var src = '{% assign foo="bar" %}{{foo}}' return expect(liquid.parseAndRender(src)) - .to.eventually.equal('bar') + .to.eventually.equal('bar') }) it('should assign as array', function () { var src = '{% assign foo=(1..3) %}{{foo}}' return expect(liquid.parseAndRender(src)) - .to.eventually.equal('[1,2,3]') + .to.eventually.equal('[1,2,3]') }) it('should assign as filter result', function () { var src = '{% assign foo="a b" | capitalize | split: " " | first %}{{foo}}' return expect(liquid.parseAndRender(src)) - .to.eventually.equal('A') + .to.eventually.equal('A') }) it('should assign var-1', function () { var src = '{% assign var-1 = 5 %}{{ var-1 }}' diff --git a/test/tags/capture.js b/test/tags/capture.js index a43e7dc25..e27f26974 100644 --- a/test/tags/capture.js +++ b/test/tags/capture.js @@ -9,18 +9,18 @@ describe('tags/capture', function () { it('should support capture', function () { var src = '{% capture f %}{{"a" | capitalize}}{%endcapture%}{{f}}' return expect(liquid.parseAndRender(src)) - .to.eventually.equal('A') + .to.eventually.equal('A') }) it('should throw on invalid identifier', function () { var src = '{% capture = %}{%endcapture%}' return expect(liquid.parseAndRender(src)) - .to.be.rejectedWith(/= not valid identifier/) + .to.be.rejectedWith(/= not valid identifier/) }) it('should throw when capture not closed', function () { var src = '{%capture c%}{{c}}' return expect(liquid.parseAndRender(src)) - .to.be.rejectedWith(/tag .* not closed/) + .to.be.rejectedWith(/tag .* not closed/) }) }) diff --git a/test/tags/case.js b/test/tags/case.js index c5a8c6d4a..4476e3f24 100644 --- a/test/tags/case.js +++ b/test/tags/case.js @@ -9,14 +9,14 @@ describe('tags/case', function () { it('should support case 1', function () { var src = '{% case "foo"%}' return expect(liquid.parseAndRender(src)) - .to.be.rejectedWith(/{% case "foo"%} not closed/) + .to.be.rejectedWith(/{% case "foo"%} not closed/) }) it('should support case 2', function () { var src = '{% case "foo"%}' + '{% when "foo" %}foo{% when "bar"%}bar' + '{%endcase%}' return expect(liquid.parseAndRender(src)) - .to.eventually.equal('foo') + .to.eventually.equal('foo') }) it('should support case 3', function () { var src = '{% case empty %}' + @@ -26,20 +26,20 @@ describe('tags/case', function () { empty: '' } return expect(liquid.parseAndRender(src, ctx)) - .to.eventually.equal('bar') + .to.eventually.equal('bar') }) it('should support case 4', function () { var src = '{% case false %}' + '{% when "foo" %}foo{% when ""%}bar' + '{%endcase%}' return expect(liquid.parseAndRender(src)) - .to.eventually.equal('') + .to.eventually.equal('') }) it('should support case 5', function () { var src = '{% case "a" %}' + '{% when "b" %}b{% when "c"%}c{%else %}d' + '{%endcase%}' return expect(liquid.parseAndRender(src)) - .to.eventually.equal('d') + .to.eventually.equal('d') }) }) diff --git a/test/tags/comment.js b/test/tags/comment.js index 0f33bb42b..946d18911 100644 --- a/test/tags/comment.js +++ b/test/tags/comment.js @@ -8,16 +8,16 @@ describe('tags/comment', function () { it('should support comment 1', function () { var src = '{% comment %}{% raw%}' return expect(liquid.parseAndRender(src)) - .to.be.rejectedWith(/{% comment %} not closed/) + .to.be.rejectedWith(/{% comment %} not closed/) }) it('should support comment 2', function () { var src = 'My name is {% comment %}super{% endcomment %} Shopify.' return expect(liquid.parseAndRender(src)) - .to.eventually.equal('My name is Shopify.') + .to.eventually.equal('My name is Shopify.') }) it('should support comment 3', function () { var src = '{% comment %}\n{{ foo}} \n{% endcomment %}' return expect(liquid.parseAndRender(src)) - .to.eventually.equal('') + .to.eventually.equal('') }) }) diff --git a/test/tags/cycle.js b/test/tags/cycle.js index c2a7674a8..ac0169e13 100644 --- a/test/tags/cycle.js +++ b/test/tags/cycle.js @@ -9,12 +9,12 @@ describe('tags/cycle', function () { it('should support cycle', function () { var src = "{% cycle '1', '2', '3' %}" return expect(liquid.parseAndRender(src + src + src + src)) - .to.eventually.equal('1231') + .to.eventually.equal('1231') }) it('should throw when cycle candidates empty', function () { return expect(liquid.parseAndRender('{%cycle%}')) - .to.be.rejectedWith(/empty candidates/) + .to.be.rejectedWith(/empty candidates/) }) it('should support cycle in for block', function () { @@ -23,7 +23,7 @@ describe('tags/cycle', function () { one: 1 } return expect(liquid.parseAndRender(src, ctx)) - .to.eventually.equal('1e1e1') + .to.eventually.equal('1e1e1') }) it('should support cycle group', function () { @@ -34,6 +34,6 @@ describe('tags/cycle', function () { one: 1 } return expect(liquid.parseAndRender(src, ctx)) - .to.eventually.equal('121') + .to.eventually.equal('121') }) }) diff --git a/test/tags/decrement.js b/test/tags/decrement.js index aad25b917..5e1d44bd2 100644 --- a/test/tags/decrement.js +++ b/test/tags/decrement.js @@ -18,13 +18,13 @@ describe('tags/decrement', function () { one: 1 } return expect(liquid.parseAndRender(src, ctx)) - .to.eventually.equal('0') + .to.eventually.equal('0') }) it('should decrement undefined', function () { var src = '{% decrement empty %}{{empty}}' return expect(liquid.parseAndRender(src)) - .to.eventually.equal('-1') + .to.eventually.equal('-1') }) it('should support decrement multiple times', function () { @@ -33,6 +33,6 @@ describe('tags/decrement', function () { foo: 1 } return expect(liquid.parseAndRender(src, ctx)) - .to.eventually.equal('-1') + .to.eventually.equal('-1') }) }) diff --git a/test/tags/for.js b/test/tags/for.js index 6de383d08..6416dde40 100644 --- a/test/tags/for.js +++ b/test/tags/for.js @@ -21,7 +21,7 @@ describe('tags/for', function () { it('should support array', function () { var src = '{%for c in alpha%}{{c}}{%endfor%}' return expect(liquid.parseAndRender(src, ctx)) - .to.eventually.equal('abc') + .to.eventually.equal('abc') }) it('should support object', function () { @@ -33,7 +33,7 @@ describe('tags/for', function () { it('should throw when for not closed', function () { var src = '{%for c in alpha%}{{c}}' return expect(liquid.parseAndRender(src, ctx)) - .to.be.rejectedWith(/tag .* not closed/) + .to.be.rejectedWith(/tag .* not closed/) }) describe('else', function () { @@ -80,7 +80,7 @@ describe('tags/for', function () { 'false.2.1.false.3.2.1b\n' + 'false.3.2.true.3.1.0c\n' return expect(liquid.parseAndRender(src, ctx)) - .to.eventually.equal(dst) + .to.eventually.equal(dst) }) it('should support for with continue', function () { @@ -88,46 +88,46 @@ describe('tags/for', function () { '{{i}}{% continue %}after' + '{% endfor %}' return expect(liquid.parseAndRender(src, ctx)) - .to.eventually.equal('12345') + .to.eventually.equal('12345') }) it('should support for with break', function () { var src = '{% for i in (one..5) %}' + '{% if i == 4 %}{% break %}{% endif %}' + '{{ i }}' + '{% endfor %}' - // return liquid.parseAndRender(src, ctx).catch(e => { + // return liquid.parseAndRender(src, ctx).catch(e => { // console.log(e.stack); - // }); + // }); return expect(liquid.parseAndRender(src, ctx)) - .to.eventually.equal('123') + .to.eventually.equal('123') }) it('should support for with limit', function () { var src = '{% for i in (1..5) limit:2 %}{{ i }}{% endfor %}' return expect(liquid.parseAndRender(src, ctx)) - .to.eventually.equal('12') + .to.eventually.equal('12') }) it('should support for with limit and offset', function () { var src = '{% for i in (1..10) limit:2 offset:5%}{{ i }}{% endfor %}' return expect(liquid.parseAndRender(src, ctx)) - .to.eventually.equal('67') + .to.eventually.equal('67') }) it('should support for reversed in the last position', function () { var src = '{% for i in (1..5) limit:2 reversed %}{{ i }}{% endfor %}' return expect(liquid.parseAndRender(src, ctx)) - .to.eventually.equal('21') + .to.eventually.equal('21') }) it('should support for reversed in the first position', function () { var src = '{% for i in (1..5) reversed limit:2 %}{{ i }}{% endfor %}' return expect(liquid.parseAndRender(src, ctx)) - .to.eventually.equal('21') + .to.eventually.equal('21') }) it('should support for reversed in the middle position', function () { var src = '{% for i in (1..5) offset:2 reversed limit:4 %}{{ i }}{% endfor %}' return expect(liquid.parseAndRender(src, ctx)) - .to.eventually.equal('543') + .to.eventually.equal('543') }) }) diff --git a/test/tags/if.js b/test/tags/if.js index 067969cf3..0800f1e72 100644 --- a/test/tags/if.js +++ b/test/tags/if.js @@ -15,89 +15,89 @@ describe('tags/if', function () { it('should support if 1', function () { var src = '{% if false%}yes' return expect(liquid.parseAndRender(src, ctx)) - .to.be.rejectedWith(/tag {% if false%} not closed/) + .to.be.rejectedWith(/tag {% if false%} not closed/) }) it('should support if 2', function () { var src = '{%if emptyArray%}a{%endif%}' return expect(liquid.parseAndRender(src, ctx)) - .to.eventually.equal('a') + .to.eventually.equal('a') }) it('should support if 3', function () { var src = '{% if 2==3 %}yes{%else%}no{%endif%}' return expect(liquid.parseAndRender(src, ctx)) - .to.eventually.equal('no') + .to.eventually.equal('no') }) it('should support if 4', function () { var src = '{% if 1>=2 and one2 %} not closed/) + .to.be.rejectedWith(/tag {% unless 1>2 %} not closed/) }) it('should render unless when predicate yields false and else undefined', function () { var src = '{% unless 1>2 %}yes{%endunless%}' return expect(liquid.parseAndRender(src)) - .to.eventually.equal('yes') + .to.eventually.equal('yes') }) it('should render "" when predicate yields false and else undefined', function () { var src = '{% unless 1<2 %}yes{%endunless%}' return expect(liquid.parseAndRender(src)) - .to.eventually.equal('') + .to.eventually.equal('') }) }) diff --git a/test/util/error.js b/test/util/error.js index e09f23ff4..e964e7bfa 100644 --- a/test/util/error.js +++ b/test/util/error.js @@ -17,11 +17,11 @@ describe('error', function () { describe('TokenizationError', function () { it('should throw TokenizationError when tag illegal', function () { return expect(engine.parseAndRender('{% . a %}', {})).to.eventually - .be.rejected - .then(function (err) { - expect(err.name).to.equal('TokenizationError') - expect(err.message).to.contain('illegal tag syntax') - }) + .be.rejected + .then(function (err) { + expect(err.name).to.equal('TokenizationError') + expect(err.message).to.contain('illegal tag syntax') + }) }) it('should contain template content in err.message', function () { var html = ['1st', '2nd', 'X{% . a %} Y', '4th'] @@ -33,36 +33,36 @@ describe('error', function () { 'TokenizationError: illegal tag syntax' ] return expect(engine.parseAndRender(html.join('\n'))).to.eventually - .be.rejected - .then(function (err) { - expect(err.message).to.equal('illegal tag syntax, line:3') - expect(err.stack).to.contain(message.join('\n')) - expect(err.name).to.equal('TokenizationError') - }) + .be.rejected + .then(function (err) { + expect(err.message).to.equal('illegal tag syntax, line:3') + expect(err.stack).to.contain(message.join('\n')) + expect(err.name).to.equal('TokenizationError') + }) }) it('should contain the whole template content in err.input', function () { var html = 'bar\nfoo{% . a %}\nfoo' return expect(engine.parseAndRender(html)).to.eventually - .be.rejected - .then(function (err) { - expect(err.input).to.equal(html) - }) + .be.rejected + .then(function (err) { + expect(err.input).to.equal(html) + }) }) it('should contain line number in err.line', function () { return expect(engine.parseAndRender('1\n2\n{% . a %}\n4', {})).to.eventually - .be.rejected - .then(function (err) { - expect(err.name).to.equal('TokenizationError') - expect(err.line).to.equal(3) - }) + .be.rejected + .then(function (err) { + expect(err.name).to.equal('TokenizationError') + expect(err.line).to.equal(3) + }) }) it('should contain stack in err.stack', function () { return expect(engine.parseAndRender('{% . a %}')).to.eventually - .be.rejected - .then(function (err) { - expect(err.stack).to.contain('illegal tag syntax') - expect(err.stack).to.contain('at Object.parse') - }) + .be.rejected + .then(function (err) { + expect(err.stack).to.contain('illegal tag syntax') + expect(err.stack).to.contain('at Object.parse') + }) }) it('should contain file path in err.file', function () { var html = '\n\n\n{% . a %}\n\n' @@ -70,12 +70,12 @@ describe('error', function () { '/foo.html': html }) return expect(engine.renderFile('/foo.html')).to.eventually - .be.rejected - .then(function (err) { - mock.restore() - expect(err.name).to.equal('TokenizationError') - expect(err.file).to.equal('/foo.html') - }) + .be.rejected + .then(function (err) { + mock.restore() + expect(err.name).to.equal('TokenizationError') + expect(err.file).to.equal('/foo.html') + }) }) }) @@ -101,40 +101,40 @@ describe('error', function () { it('should throw RenderError when tag throws', function () { var src = '{%throwingTag%}' return expect(engine.parseAndRender(src)).to.eventually - .be.rejected - .then(function (err) { - expect(err.name).to.equal('RenderError') - expect(err.message).to.contain('intended render error') - }) + .be.rejected + .then(function (err) { + expect(err.name).to.equal('RenderError') + expect(err.message).to.contain('intended render error') + }) }) it('should throw RenderError when tag rejects', function () { var src = '{%rejectingTag%}' return expect(engine.parseAndRender(src)).to.eventually - .be.rejected - .then(function (err) { - expect(err.name).to.equal('RenderError') - expect(err.message).to.contain('intended render reject') - }) + .be.rejected + .then(function (err) { + expect(err.name).to.equal('RenderError') + expect(err.message).to.contain('intended render reject') + }) }) it('should throw RenderError when filter throws', function () { var src = '{{1|throwingFilter}}' return expect(engine.parseAndRender(src)).to.eventually - .be.rejected - .then(function (err) { - expect(err.name).to.equal('RenderError') - expect(err.message).to.contain('throwed by filter') - }) + .be.rejected + .then(function (err) { + expect(err.name).to.equal('RenderError') + expect(err.message).to.contain('throwed by filter') + }) }) it('should not throw when variable undefined by default', function () { return expect(engine.parseAndRender('X{{a}}Y')).to.eventually.equal('XY') }) it('should throw RenderError when variable not defined', function () { return expect(strictEngine.parseAndRender('{{a}}')).to.eventually - .be.rejected - .then(function (e) { - expect(e).to.have.property('name', 'RenderError') - expect(e.message).to.contain('undefined variable: a') - }) + .be.rejected + .then(function (e) { + expect(e).to.have.property('name', 'RenderError') + expect(e.message).to.contain('undefined variable: a') + }) }) it('should contain template context in err.stack', function () { var html = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th'] @@ -148,12 +148,12 @@ describe('error', function () { 'Error: intended render error' ] return expect(engine.parseAndRender(html.join('\n'))).to.eventually - .be.rejected - .then(function (err) { - expect(err.message).to.equal('intended render error, line:4') - expect(err.stack).to.contain(message.join('\n')) - expect(err.name).to.equal('RenderError') - }) + .be.rejected + .then(function (err) { + expect(err.message).to.equal('intended render error, line:4') + expect(err.stack).to.contain(message.join('\n')) + expect(err.name).to.equal('RenderError') + }) }) it('should contain original error info for {% layout %}', function () { mock({ @@ -178,14 +178,14 @@ describe('error', function () { 'Error: intended render error' ] return expect(engine.parseAndRender(html)).to.eventually - .be.rejected - .then(function (err) { - console.log(err.message) - console.log(err.stack) - expect(err.message).to.equal('intended render error, file:/throwing-tag.html, line:4') - expect(err.stack).to.contain(message.join('\n')) - expect(err.name).to.equal('RenderError') - }) + .be.rejected + .then(function (err) { + console.log(err.message) + console.log(err.stack) + expect(err.message).to.equal('intended render error, file:/throwing-tag.html, line:4') + expect(err.stack).to.contain(message.join('\n')) + expect(err.name).to.equal('RenderError') + }) }) it('should contain original error info for {% include %}', function () { var origin = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th'] @@ -203,38 +203,38 @@ describe('error', function () { 'Error: intended render error' ] return expect(engine.parseAndRender(html)).to.eventually - .be.rejected - .then(function (err) { - expect(err.message).to.equal('intended render error, file:/throwing-tag.html, line:4') - expect(err.stack).to.contain(message.join('\n')) - expect(err.name).to.equal('RenderError') - }) + .be.rejected + .then(function (err) { + expect(err.message).to.equal('intended render error, file:/throwing-tag.html, line:4') + expect(err.stack).to.contain(message.join('\n')) + expect(err.name).to.equal('RenderError') + }) }) it('should contain the whole template content in err.input', function () { var html = 'bar\nfoo{%throwingTag%}\nfoo' return expect(engine.parseAndRender(html)).to.eventually - .be.rejected - .then(function (err) { - expect(err.input).to.equal(html) - expect(err.name).to.equal('RenderError') - }) + .be.rejected + .then(function (err) { + expect(err.input).to.equal(html) + expect(err.name).to.equal('RenderError') + }) }) it('should contain line number in err.line', function () { var src = '1\n2\n{{1|throwingFilter}}\n4' return expect(engine.parseAndRender(src)).to.eventually - .be.rejected - .then(function (err) { - expect(err.line).to.equal(3) - expect(err.name).to.equal('RenderError') - }) + .be.rejected + .then(function (err) { + expect(err.line).to.equal(3) + expect(err.name).to.equal('RenderError') + }) }) it('should contain stack in err.stack', function () { return expect(engine.parseAndRender('{%rejectingTag%}')).to.eventually - .be.rejected - .then(function (err) { - expect(err.stack).to.contain('intended render reject') - expect(err.stack).to.match(/at .*:\d+:\d+\)/) - }) + .be.rejected + .then(function (err) { + expect(err.stack).to.contain('intended render reject') + expect(err.stack).to.match(/at .*:\d+:\d+\)/) + }) }) it('should contain file path in err.file', function () { @@ -243,12 +243,12 @@ describe('error', function () { '/foo.html': html }) return expect(engine.renderFile('/foo.html')).to.eventually - .be.rejected - .then(function (err) { - mock.restore() - expect(err.name).to.equal('RenderError') - expect(err.file).to.equal('/foo.html') - }) + .be.rejected + .then(function (err) { + mock.restore() + expect(err.name).to.equal('RenderError') + expect(err.file).to.equal('/foo.html') + }) }) }) @@ -263,46 +263,46 @@ describe('error', function () { }) it('should throw RenderError when filter not defined', function () { return expect(strictEngine.parseAndRender('{{1 | a}}')).to.eventually - .be.rejected - .then(function (e) { - expect(e).to.have.property('name', 'ParseError') - expect(e.message).to.contain('undefined filter: a') - }) + .be.rejected + .then(function (e) { + expect(e).to.have.property('name', 'ParseError') + expect(e.message).to.contain('undefined filter: a') + }) }) it('should throw ParseError when tag not closed', function () { return expect(engine.parseAndRender('{% if %}')).to.eventually - .be.rejected - .then(function (err) { - expect(err.name).to.equal('ParseError') - expect(err.message).to.contain('tag {% if %} not closed') - }) + .be.rejected + .then(function (err) { + expect(err.name).to.equal('ParseError') + expect(err.message).to.contain('tag {% if %} not closed') + }) }) it('should throw ParseError when tag parse throws', function () { var src = '{%throwsOnParse%}' return expect(engine.parseAndRender(src)).to.eventually - .be.rejected - .then(function (err) { - expect(err.name).to.equal('ParseError') - expect(err.message).to.contain('intended parse error') - }) + .be.rejected + .then(function (err) { + expect(err.name).to.equal('ParseError') + expect(err.message).to.contain('intended parse error') + }) }) it('should throw ParseError when tag not found', function () { var src = '{%if true%}\naaa{%endif%}\n{% -a %}\n3' return expect(engine.parseAndRender(src)).to.eventually - .be.rejected - .then(function (err) { - expect(err.name).to.equal('ParseError') - expect(err.message).to.contain('tag -a not found') - }) + .be.rejected + .then(function (err) { + expect(err.name).to.equal('ParseError') + expect(err.message).to.contain('tag -a not found') + }) }) it('should throw ParseError when tag not exist', function () { return expect(engine.parseAndRender('{% a %}')).to.eventually - .be.rejected - .then(function (err) { - expect(err.name).to.equal('ParseError') - expect(err.message).to.contain('tag a not found') - }) + .be.rejected + .then(function (err) { + expect(err.name).to.equal('ParseError') + expect(err.message).to.contain('tag a not found') + }) }) it('should contain template context in err.stack', function () { @@ -317,12 +317,12 @@ describe('error', function () { 'AssertionError: tag a not found' ] return expect(engine.parseAndRender(html.join('\n'))).to.eventually - .be.rejected - .then(function (err) { - expect(err.message).to.equal('tag a not found, line:4') - expect(err.stack).to.contain(message.join('\n')) - expect(err.name).to.equal('ParseError') - }) + .be.rejected + .then(function (err) { + expect(err.message).to.equal('tag a not found, line:4') + expect(err.stack).to.contain(message.join('\n')) + expect(err.name).to.equal('ParseError') + }) }) it('should handle err.message when context not enough', function () { @@ -335,38 +335,38 @@ describe('error', function () { 'AssertionError: tag a not found' ] return expect(engine.parseAndRender(html.join('\n'))).to.eventually - .be.rejected - .then(function (err) { - expect(err.message).to.equal('tag a not found, line:2') - expect(err.stack).to.contain(message.join('\n')) - }) + .be.rejected + .then(function (err) { + expect(err.message).to.equal('tag a not found, line:2') + expect(err.stack).to.contain(message.join('\n')) + }) }) it('should contain the whole template content in err.input', function () { var html = 'bar\nfoo{% a %}\nfoo' return expect(engine.parseAndRender(html)).to.eventually - .be.rejected - .then(function (err) { - expect(err.input).to.equal(html) - }) + .be.rejected + .then(function (err) { + expect(err.input).to.equal(html) + }) }) it('should contain line number in err.line', function () { var html = '\n\n\n{% raw %}\n\n' return expect(engine.parseAndRender(html)).to.eventually - .be.rejected - .then(function (err) { - expect(err.line).to.equal(4) - }) + .be.rejected + .then(function (err) { + expect(err.line).to.equal(4) + }) }) it('should contain stack in err.stack', function () { return expect(engine.parseAndRender('{% -a %}')).to.eventually - .be.rejected - .then(function (err) { - expect(err.stack).to.contain('AssertionError: tag -a not found') - expect(err.stack).to.match(/at .*:\d+:\d+\)/) - }) + .be.rejected + .then(function (err) { + expect(err.stack).to.contain('AssertionError: tag -a not found') + expect(err.stack).to.match(/at .*:\d+:\d+\)/) + }) }) it('should contain file path in err.file', function () { @@ -375,12 +375,12 @@ describe('error', function () { '/foo.html': html }) return expect(engine.renderFile('/foo.html')).to.eventually - .be.rejected - .then(function (err) { - mock.restore() - expect(err.name).to.equal('ParseError') - expect(err.file).to.equal('/foo.html') - }) + .be.rejected + .then(function (err) { + mock.restore() + expect(err.name).to.equal('ParseError') + expect(err.file).to.equal('/foo.html') + }) }) }) }) diff --git a/test/util/promise.js b/test/util/promise.js index a09e0f714..c43b9c761 100644 --- a/test/util/promise.js +++ b/test/util/promise.js @@ -13,18 +13,18 @@ describe('util/promise', function () { var spy2 = sinon.spy() return P .anySeries( - ['first', 'second'], - (item, idx) => new Promise(function (resolve, reject) { - if (idx === 0) { - setTimeout(function () { - spy1() - reject(new Error('first cb')) - }, 10) - } else { - spy2() - resolve('foo') - } - })) + ['first', 'second'], + (item, idx) => new Promise(function (resolve, reject) { + if (idx === 0) { + setTimeout(function () { + spy1() + reject(new Error('first cb')) + }, 10) + } else { + spy2() + resolve('foo') + } + })) .then(() => expect(spy2).to.have.been.calledAfter(spy1)) }) it('should reject when all rejected', function () {