feat: fixed parsing several filter arguments with quotes (#98)

This commit is contained in:
Ilya Puchka
2017-04-18 23:58:42 +02:00
committed by Kyle Fuller
parent d1717df6ff
commit 5541eae818
2 changed files with 26 additions and 6 deletions

View File

@@ -22,8 +22,8 @@ func testFilter() {
try expect(result) == "Kyle Kyle"
}
$0.it("allows you to register a custom filter which accepts arguments") {
let template = Template(templateString: "{{ name|repeat:'value' }}")
$0.it("allows you to register a custom filter which accepts single argument") {
let template = Template(templateString: "{{ name|repeat:'value1, \"value2\"' }}")
let repeatExtension = Extension()
repeatExtension.registerFilter("repeat") { value, arguments in
@@ -35,7 +35,23 @@ func testFilter() {
}
let result = try template.render(Context(dictionary: context, environment: Environment(extensions: [repeatExtension])))
try expect(result) == "Kyle Kyle with args value"
try expect(result) == "Kyle Kyle with args value1, \"value2\""
}
$0.it("allows you to register a custom filter which accepts several arguments") {
let template = Template(templateString: "{{ name|repeat:'value\"1\"',\"value'2'\",'(key, value)' }}")
let repeatExtension = Extension()
repeatExtension.registerFilter("repeat") { value, arguments in
if !arguments.isEmpty {
return "\(value!) \(value!) with args 0: \(arguments[0]!), 1: \(arguments[1]!), 2: \(arguments[2]!)"
}
return nil
}
let result = try template.render(Context(dictionary: context, environment: Environment(extensions: [repeatExtension])))
try expect(result) == "Kyle Kyle with args 0: value\"1\", 1: value'2', 2: (key, value)"
}
$0.it("allows you to register a custom which throws") {