diff --git a/compile.js b/compile.js index 18a48bf..950d8a1 100644 --- a/compile.js +++ b/compile.js @@ -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 = [] diff --git a/test/compile-strong.js b/test/compile-strong.js index b0116d5..f980e43 100644 --- a/test/compile-strong.js +++ b/test/compile-strong.js @@ -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() +}) diff --git a/test/compile-weak.js b/test/compile-weak.js index 43e4cf9..cacd252 100644 --- a/test/compile-weak.js +++ b/test/compile-weak.js @@ -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") @@ -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() +}) diff --git a/test/string-template.js b/test/string-template.js index 72ba93c..d3950c5 100644 --- a/test/string-template.js +++ b/test/string-template.js @@ -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() +})