fix dupe name bug

This commit is contained in:
Cory Mawhorter
2018-04-07 19:36:50 +08:00
committed by Jun Yang
parent c6ff1f7911
commit aa54dad36e
3 changed files with 41 additions and 2 deletions
+3 -1
View File
@@ -36,7 +36,9 @@ module.exports = function (options) {
while ((match = valueRE.exec(argList.trim()))) {
var v = match[0]
var re = new RegExp(`${v}\\s*:`, 'g')
re.test(match.input) ? args.push(`'${v}'`) : args.push(v)
var keyMatch = re.exec(match.input)
var currentMatchIsKey = keyMatch && keyMatch.index === match.index
currentMatchIsKey ? args.push(`'${v}'`) : args.push(v)
}
this.name = name
+36
View File
@@ -54,4 +54,40 @@ describe('filter', function () {
filter.construct('foo: 33').render('foo', scope)
expect(spy).to.have.been.calledWith('foo', 33)
})
it('should support arguments as named key/values', function () {
filter.register('foo', x => x)
var f = filter.construct('foo: key1: "literal1", key2: value2');
expect(f.name).to.equal('foo')
expect(f.args).to.deep.equal([ '\'key1\'', '"literal1"', '\'key2\'', 'value2' ]);
})
it('should support arguments as named key/values with inline literals', function () {
filter.register('foo', x => x)
var f = filter.construct('foo: "test0", key1: "literal1", key2: value2');
expect(f.name).to.equal('foo')
expect(f.args).to.deep.equal([ '"test0"', '\'key1\'', '"literal1"', '\'key2\'', 'value2' ]);
})
it('should support arguments as named key/values with inline values', function () {
filter.register('foo', x => x)
var f = filter.construct('foo: test0, key1: "literal1", key2: value2');
expect(f.name).to.equal('foo')
expect(f.args).to.deep.equal([ 'test0', '\'key1\'', '"literal1"', '\'key2\'', 'value2' ]);
})
it('should support argument values named same as keys', function () {
filter.register('foo', x => x)
var f = filter.construct('foo: a: a');
expect(f.name).to.equal('foo')
expect(f.args).to.deep.equal(['\'a\'', 'a'])
})
it('should support argument literals named same as keys', function () {
filter.register('foo', x => x)
var f = filter.construct('foo: a: "a"');
expect(f.name).to.equal('foo')
expect(f.args).to.deep.equal(['\'a\'', '"a"'])
})
})
+2 -1
View File
@@ -394,6 +394,7 @@ describe('filters', function () {
liquid.registerFilter('obj_test', function () {
return Array.prototype.slice.call(arguments).join(',')
})
it('should support object', () => test('{{ "a" | obj_test: k1: "v1", k2: "v2" }}', 'a,k1,v1,k2,v2'))
it('should support object', () => test(`{{ "a" | obj_test: k1: "v1", k2: foo }}`, 'a,k1,v1,k2,bar'))
it('should support mixed object', () => test(`{{ "a" | obj_test: "something", k1: "v1", k2: foo }}`, 'a,something,k1,v1,k2,bar'))
})
})