var templateparser = require('./templatestring.js');
"use strict";

var tests = {
    "one-layer object":{
        str: "hi ${foo}",
        obj: {foo: "bar"},
        expect: "hi bar"
    },
    "two-layer object":{
        str: "hi ${foo.bar}",
        obj: {foo: {bar: "whack"}},
        expect: "hi whack"
    },
    "null string test":{
        str: undefined,
        obj: {foo: "bar"},
        expect: ""
    },
    "null obj test":{
        str: "foo",
        obj: undefined,
        expect: "foo"
    },
    "null property test":{
        str: "${foo}",
        obj: {},
        expect: "undefined"
    },
    "special characters":{
        str: "${a}${1}${!}${$}",
        obj: {a:"foo", 1: "bar", "!": "foobar", "$": "taco"},
        expect: "foobarfoobartaco"
    }
}

for(var key in tests) {
    str = tests[key].str;
    obj = tests[key].obj;
    expect = tests[key].expect;
    if(templateparser(str, obj) !== expect) {
        console.log("expected: " + expect);
        console.log("got: " + templateparser(str, obj));
        throw new Error(["test", key, "failed"].join(" "));
    }
}

console.log("tests pass");
@@ -302,32 +302,201 @@
 i whack%22%0A    %7D,%0A
+    %22repeated two-layer object%22:%7B%0A        str: %22hi $%7Bfoo.bar%7D, this is $%7Bfoo.bar%7D%22,%0A        obj: %7Bfoo: %7Bbar: %22whack%22%7D%7D,%0A        expect: %22hi whack, this is whack%22%0A    %7D,%0A
     %22null string
@@ -935,16 +935,449 @@
 artaco%22%0A
+    %7D, %0A    %22dangerous strings%22:%7B%0A        str: 'this has $%7Bfirst%7D, $%7Bsecond%7D, $%7Bthird%7D, $%7Bfourth%7D and $%7Bfifth%7D inside',%0A        obj: %7B%0A            first: '$',%0A            second: '$&',%0A            third: '$%60',%0A            fourth: '$%5C'',%0A            fifth: '$1'%0A        %7D,%0A        expect: 'this has $, $&, $%60, $%5C' and $1 inside'%0A        // credit to asmblah https://github.com/asmblah/template-string/blob/master/test/templateTest.js%0A
     %7D%0A%7D%0A

add tests from asmblah's template parser for more complete test coverage.