Skip to content

Commit

Permalink
fix template string without arguments for compile
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Jun 6, 2015
1 parent fe0823b commit ec2e58b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion compile.js
Expand Up @@ -24,7 +24,7 @@ var argTemplate = "(result = args.hasOwnProperty(\"{0}\") ? " +
module.exports = compile

function compile(string, inline) {
var replacements = string.match(nargs)
var replacements = string.match(nargs) || []
var interleave = string.split(nargs)
var replace = []

Expand Down
7 changes: 7 additions & 0 deletions test/compile-strong.js
Expand Up @@ -277,3 +277,10 @@ test("Allow multiple references", function (assert) {
assert.equal(result3, "onetwothree\nonetwothree\nonetwothree")
assert.end()
})

test("Template string without arguments", function (assert) {
var template = compile("Hello, how are you?", true)
var result = template()
assert.equal(result, "Hello, how are you?")
assert.end()
})
8 changes: 7 additions & 1 deletion test/compile-weak.js
Expand Up @@ -118,7 +118,6 @@ test("Listed arguments are replaced", function (assert) {
assert.end()
})


test("Supports quotes", function (assert) {
var template = compile("Hello {0}, how are you?")
var result = template("\"Mark")
Expand Down Expand Up @@ -278,3 +277,10 @@ test("Allow multiple references", function (assert) {
assert.equal(result3, "onetwothree\nonetwothree\nonetwothree")
assert.end()
})

test("Template string without arguments", function (assert) {
var template = compile("Hello, how are you?")
var result = template()
assert.equal(result, "Hello, how are you?")
assert.end()
})
6 changes: 6 additions & 0 deletions test/string-template.js
Expand Up @@ -211,3 +211,9 @@ test("Allow multiple references", function (assert) {
assert.equal(result3, "onetwothree\nonetwothree\nonetwothree")
assert.end()
})

test("Template string without arguments", function (assert) {
var result = format("Hello, how are you?")
assert.equal(result, "Hello, how are you?")
assert.end()
})

0 comments on commit ec2e58b

Please sign in to comment.