All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.bower_components.blueimp-tmpl.test.test.min.js Maven / Gradle / Ivy

(function(b,c,a){if(b.require===undefined){a.load=function(e){switch(e){case"template":return"{%=o.value%}"}}}var d;beforeEach(function(){d={value:"value",nullValue:null,falseValue:false,zeroValue:0,special:"<>&\"'\x00",list:[1,2,3,4,5],func:function(){return this.value},deep:{value:"value"}}});afterEach(function(){a.cache={}});describe("Template loading",function(){it("String template",function(){c(a("{%=o.value%}",d)).to.equal("value")});it("Load template by id",function(){c(a("template",d)).to.equal("value")});it("Retun function when called without data parameter",function(){c(a("{%=o.value%}")(d)).to.equal("value")});it("Cache templates loaded by id",function(){a("template");c(a.cache.template).to.be.a("function")})});describe("Interpolation",function(){it("Escape HTML special characters with {%=o.prop%}",function(){c(a("{%=o.special%}",d)).to.equal("<>&"'")});it("Allow HTML special characters with {%#o.prop%}",function(){c(a("{%#o.special%}",d)).to.equal("<>&\"'\x00")});it("Function call",function(){c(a("{%=o.func()%}",d)).to.equal("value")});it("Dot notation",function(){c(a("{%=o.deep.value%}",d)).to.equal("value")});it("Handle single quotes",function(){c(a("'single quotes'{%=\": '\"%}",d)).to.equal("'single quotes': '")});it("Handle double quotes",function(){c(a('"double quotes"{%=": \\""%}',d)).to.equal('"double quotes": "')});it("Handle backslashes",function(){c(a('\\backslashes\\{%=": \\\\"%}',d)).to.equal("\\backslashes\\: \\")});it("Interpolate escaped falsy values except undefined or null",function(){c(a("{%=o.undefinedValue%}{%=o.nullValue%}{%=o.falseValue%}{%=o.zeroValue%}",d)).to.equal("false0")});it("Interpolate unescaped falsy values except undefined or null",function(){c(a("{%#o.undefinedValue%}{%#o.nullValue%}{%#o.falseValue%}{%#o.zeroValue%}",d)).to.equal("false0")});it("Preserve whitespace",function(){c(a("\n\r\t{%=o.value%}  \n\r\t{%=o.value%}  ",d)).to.equal("\n\r\tvalue  \n\r\tvalue  ")})});describe("Evaluation",function(){it("Escape HTML special characters with print(data)",function(){c(a("{% print(o.special); %}",d)).to.equal("<>&"'")});it("Allow HTML special characters with print(data, true)",function(){c(a("{% print(o.special, true); %}",d)).to.equal("<>&\"'\x00")});it("Print out escaped falsy values except undefined or null",function(){c(a("{% print(o.undefinedValue); %}{% print(o.nullValue); %}{% print(o.falseValue); %}{% print(o.zeroValue); %}",d)).to.equal("false0")});it("Print out unescaped falsy values except undefined or null",function(){c(a("{% print(o.undefinedValue, true); %}{% print(o.nullValue, true); %}{% print(o.falseValue, true); %}{% print(o.zeroValue, true); %}",d)).to.equal("false0")});it("Include template",function(){c(a('{% include("template", {value: "value"}); %}',d)).to.equal("value")});it("If condition",function(){c(a("{% if (o.value) { %}true{% } else { %}false{% } %}",d)).to.equal("true")});it("Else condition",function(){c(a("{% if (o.undefinedValue) { %}false{% } else { %}true{% } %}",d)).to.equal("true")});it("For loop",function(){c(a("{% for (var i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy