fix: throws on invalid arguments for prepend/append, fixes #208

This commit is contained in:
harttle
2020-03-24 23:57:26 +08:00
parent 60c14ba057
commit 479c63350a
13 changed files with 163 additions and 113 deletions
+13
View File
@@ -22,6 +22,19 @@ describe('filters/html', function () {
it('should not escape twice',
() => test('{{ "1 < 2 & 3" | escape_once }}', '1 < 2 & 3'))
})
describe('newline_to_br', function () {
it('should support string_with_newlines', function () {
const src = '{% capture string_with_newlines %}\n' +
'Hello\n' +
'there\n' +
'{% endcapture %}' +
'{{ string_with_newlines | newline_to_br }}'
const dst = '<br />' +
'Hello<br />' +
'there<br />'
return test(src, dst)
})
})
describe('strip_html', function () {
it('should strip all tags', function () {
return test('{{ "Have <em>you</em> read <cite><a href=&quot;https://en.wikipedia.org/wiki/Ulysses_(novel)&quot;>Ulysses</a></cite>?" | strip_html }}',
+16 -14
View File
@@ -1,6 +1,9 @@
import { test } from '../../../stub/render'
import { Liquid } from '../../../../src/liquid'
import { expect } from 'chai'
import { expect, use } from 'chai'
import * as chaiAsPromised from 'chai-as-promised'
use(chaiAsPromised)
describe('filters/string', function () {
let liquid: Liquid
@@ -11,14 +14,24 @@ describe('filters/string', function () {
it('should return "-3abc" for -3, "abc"',
() => test('{{ -3 | append: "abc" }}', '-3abc'))
it('should return "abar" for "a", foo', () => test('{{ "a" | append: foo }}', 'abar'))
it('should return "abc" for "abc", undefined', () => test('{{ "abc" | append: undefinedVar }}', 'abc'))
it('should throw if second argument undefined', () => {
return expect(test('{{ "abc" | append: undefinedVar }}', 'abc')).to.be.rejectedWith(/2 arguments/)
})
it('should throw if second argument not set', () => {
return expect(test('{{ "abc" | append }}', 'abc')).to.be.rejectedWith(/2 arguments/)
})
it('should return "abcfalse" for "abc", false', () => test('{{ "abc" | append: false }}', 'abcfalse'))
})
describe('prepend', function () {
it('should return "-3abc" for -3, "abc"',
() => test('{{ -3 | prepend: "abc" }}', 'abc-3'))
it('should return "abar" for "a", foo', () => test('{{ "a" | prepend: foo }}', 'bara'))
it('should return "abc" for "abc", undefined', () => test('{{ "abc" | prepend: undefinedVar }}', 'abc'))
it('should throw if second argument undefined', () => {
return expect(test('{{ "abc" | prepend: undefinedVar }}', 'abc')).to.be.rejectedWith(/2 arguments/)
})
it('should throw if second argument not set', () => {
return expect(test('{{ "abc" | prepend }}', 'abc')).to.be.rejectedWith(/2 arguments/)
})
it('should return "falseabc" for "abc", false', () => test('{{ "abc" | prepend: false }}', 'falseabc'))
})
describe('capitalize', function () {
@@ -105,17 +118,6 @@ describe('filters/string', function () {
const src = '{{ " So much room for activities! " | lstrip }}'
return test(src, 'So much room for activities! ')
})
it('should support string_with_newlines', function () {
const src = '{% capture string_with_newlines %}\n' +
'Hello\n' +
'there\n' +
'{% endcapture %}' +
'{{ string_with_newlines | newline_to_br }}'
const dst = '<br />' +
'Hello<br />' +
'there<br />'
return test(src, dst)
})
it('should support prepend', function () {
return test('{% assign url = "liquidmarkup.com" %}' +
'{{ "/index.html" | prepend: url }}',
+9
View File
@@ -7,6 +7,15 @@ const expect = chai.expect
chai.use(sinonChai)
describe('util/underscore', function () {
describe('.camel2snake()', function () {
it('should convert camelCase to snakeCase', function () {
expect(_.snakeCase('fooBarCoo')).to.equal('foo_bar_coo')
})
it('should convert empty string to empty string', function () {
expect(_.snakeCase('')).to.equal('')
})
})
describe('.isString()', function () {
it('should return true for literal string', function () {
expect(_.isString('foo')).to.be.true