context-parser-handlebars
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "context-parser-handlebars", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"licenses": [ | ||
@@ -47,3 +47,3 @@ { | ||
"bluebird": "*", | ||
"expect.js": "^0.3.1", | ||
"chai": "^2.*", | ||
"grunt": "^0.4.5", | ||
@@ -50,0 +50,0 @@ "grunt-cli": "0.1.*", |
@@ -8,3 +8,3 @@ Handlebars Context Pre-compiler | ||
- This pre-compiler processes the Handlebars template file by analyzing the execution context of output markup of the Handlebars based on the WHATWG HTML5 Specification. With the knowledge of the execution context, our pre-compiler can add the correct output filters to the Handlebars template file to defense XSS automatically. | ||
- This pre-compiler processes the Handlebars template file by analyzing the execution context of output markup of the Handlebars based on the WHATWG HTML5 Specification. With the knowledge of the execution context, our pre-compiler can add the correct output filters to the Handlebars template file to defend against XSS automatically. | ||
@@ -34,3 +34,3 @@ ## Quick Start | ||
Note: the default 'h' filter in Handlebars is disable with raw {{{expression}}}. | ||
Note: the default 'h' filter in Handlebars is disabled with raw {{{expression}}}. | ||
@@ -63,11 +63,5 @@ ### Server-side (nodejs) | ||
### How to build | ||
``` | ||
npm install | ||
grunt | ||
``` | ||
### How to test | ||
``` | ||
grunt test | ||
npm test | ||
``` | ||
@@ -74,0 +68,0 @@ |
@@ -24,2 +24,5 @@ /* | ||
/* vanilla Handlebars */ | ||
var Handlebars = require("handlebars"); | ||
/** | ||
@@ -57,2 +60,3 @@ * @module ContextParserHandlebars | ||
this._lineNo = 1; | ||
this._charNo = 1; | ||
@@ -68,3 +72,3 @@ debug("_printChar:"+this._printChar); | ||
/********************************** | ||
* PRINTING FACILITY | ||
* OUTPUT FACILITY | ||
**********************************/ | ||
@@ -130,4 +134,9 @@ | ||
/* '{' 'space'* 'non-space'+ 'space'* 'non-{'* '}' */ | ||
ContextParserHandlebars.expressionRegExp = /^{\s*(\S+)\s*([^\}]*)?}/; | ||
/* '{' 'non-{,non-}'+ '}' and not follow by '}' */ | ||
ContextParserHandlebars.escapeExpressionRegExp = /^\{[^\}\{]+?\}(?!})/; | ||
/** | ||
* @function module:ContextParserHandlebars._getExpressionExtraInfo | ||
* @function module:ContextParserHandlebars._parseExpression | ||
* | ||
@@ -139,3 +148,3 @@ * @param {string} input - The input string of the HTML5 web page. | ||
* @description | ||
* <p>this method is to judge whether it is a standalone output place holder?</p> | ||
* <p>this method is to judge whether it is a standalone output expression?</p> | ||
* | ||
@@ -146,3 +155,3 @@ * reference: | ||
*/ | ||
ContextParserHandlebars.prototype._getExpressionExtraInfo = function(input, i) { | ||
ContextParserHandlebars.prototype._parseExpression = function(input, i) { | ||
@@ -152,3 +161,3 @@ var firststr = "", | ||
filter: '', | ||
isKnownFilter: false, | ||
isPrefixWithKnownFilter: false, | ||
isSingleIdentifier: false | ||
@@ -160,10 +169,9 @@ }; | ||
* Note: the expected format is "{.*}". | ||
* it is isValidExpression and !isHandlebarsReservedExpression. | ||
*/ | ||
var str = input.substring(i); | ||
var str = input.slice(i); | ||
var j = str.indexOf('}'); | ||
str = str.substring(0, j+1); | ||
str = str.slice(0, j+1); | ||
/* '{' 'space'* 'non-space'+ 'space'* 'non-{'* '}' */ | ||
var r = /^{\s*(\S+)\s*([^}]*)?}/g; | ||
var m = r.exec(str); | ||
var m = ContextParserHandlebars.expressionRegExp.exec(str); | ||
@@ -178,3 +186,3 @@ if (m !== null) { | ||
obj.isSingleIdentifier = false; | ||
obj.isKnownFilter = true; | ||
obj.isPrefixWithKnownFilter = true; | ||
return obj; | ||
@@ -193,7 +201,7 @@ } | ||
if (k !== -1) { | ||
obj.isKnownFilter = true; | ||
obj.isPrefixWithKnownFilter = true; | ||
} | ||
} | ||
} | ||
debug("_getExpressionExtraInfo:"+obj); | ||
debug("_parseExpression:"+obj); | ||
return obj; | ||
@@ -205,5 +213,5 @@ }; | ||
* | ||
* @param {integer} state - The current HTML5 state of the current character before the Handlebars markup. | ||
* @param {integer} state - The current HTML5 state of the current character before the Handlebars expression. | ||
* @param {string} input - The input string of HTML5 web page. | ||
* @param {integer} ptr - The index of the current character in the input string, it is pointing to the last brace of the open brace of the markup. | ||
* @param {integer} ptr - The index of the current character in the input string, it is pointing to the last brace of the open brace of the expression. | ||
* @param {string} extraInfo - The extra information for filters judgement. | ||
@@ -241,7 +249,7 @@ * @returns {Array} The Array of the customized filters. | ||
} else if (state === stateMachine.State.STATE_RAWTEXT) { | ||
/* we use filter.FILTER_NOT_HANDLE to warn the developers for unsafe output place holder, | ||
/* we use filter.FILTER_NOT_HANDLE to warn the developers for unsafe output expression, | ||
* and we fall back to default Handlebars 'h' filter. IT IS UNSAFE. | ||
*/ | ||
filters.push(filter.FILTER_NOT_HANDLE); | ||
msg = "[WARNING] ContextParserHandlebars: unsafe output place holder at (line:"+this._lineNo+"/position:"+ptr+")"; | ||
msg = "[WARNING] ContextParserHandlebars: Unsafe output expression. ["+this._lineNo+":"+this._charNo+"]"; | ||
handlebarsUtil.handleError(msg); | ||
@@ -251,7 +259,7 @@ return filters; | ||
} else if (state === stateMachine.State.STATE_SCRIPT_DATA) { | ||
/* we use filter.FILTER_NOT_HANDLE to warn the developers for unsafe output place holder, | ||
/* we use filter.FILTER_NOT_HANDLE to warn the developers for unsafe output expression, | ||
* and we fall back to default Handlebars 'h' filter. IT IS UNSAFE. | ||
*/ | ||
filters.push(filter.FILTER_NOT_HANDLE); | ||
msg = "[WARNING] ContextParserHandlebars: unsafe output place holder at (line:"+this._lineNo+"/position:"+ptr+")"; | ||
msg = "[WARNING] ContextParserHandlebars: Unsafe output expression. ["+this._lineNo+":"+this._charNo+"]"; | ||
handlebarsUtil.handleError(msg); | ||
@@ -264,7 +272,7 @@ return filters; | ||
} else if (state === stateMachine.State.STATE_ATTRIBUTE_NAME) { | ||
/* we use filter.FILTER_NOT_HANDLE to warn the developers for unsafe output place holder, | ||
/* we use filter.FILTER_NOT_HANDLE to warn the developers for unsafe output expression, | ||
* and we fall back to default Handlebars 'h' filter. IT IS UNSAFE. | ||
*/ | ||
filters.push(filter.FILTER_NOT_HANDLE); | ||
msg = "[WARNING] ContextParserHandlebars: unsafe output place holder at (line:"+this._lineNo+"/position:"+ptr+")"; | ||
msg = "[WARNING] ContextParserHandlebars: Unsafe output expression. ["+this._lineNo+":"+this._charNo+"]"; | ||
handlebarsUtil.handleError(msg); | ||
@@ -288,3 +296,3 @@ return filters; | ||
filters.push(filter.FILTER_NOT_HANDLE); | ||
msg = "[WARNING] ContextParserHandlebars: unsafe output place holder at (line:"+this._lineNo+"/position:"+ptr+")"; | ||
msg = "[WARNING] ContextParserHandlebars: Unsafe output expression. ["+this._lineNo+":"+this._charNo+"]"; | ||
handlebarsUtil.handleError(msg); | ||
@@ -342,7 +350,7 @@ /* this one is safe to return */ | ||
* | ||
* we use filter.FILTER_NOT_HANDLE to warn the developers for unsafe output place holder, | ||
* we use filter.FILTER_NOT_HANDLE to warn the developers for unsafe output expression, | ||
* and we fall back to default Handlebars 'h' filter. IT IS UNSAFE. | ||
*/ | ||
filters.push(filter.FILTER_NOT_HANDLE); | ||
msg = "[WARNING] ContextParserHandlebars: unsafe output place holder at (line:"+this._lineNo+"/position:"+ptr+")"; | ||
msg = "[WARNING] ContextParserHandlebars: Unsafe output expression. ["+this._lineNo+":"+this._charNo+"]"; | ||
handlebarsUtil.handleError(msg); | ||
@@ -357,7 +365,7 @@ return filters; | ||
* | ||
* we use filter.FILTER_NOT_HANDLE to warn the developers for unsafe output place holder, | ||
* we use filter.FILTER_NOT_HANDLE to warn the developers for unsafe output expression, | ||
* and we fall back to default Handlebars 'h' filter. IT IS UNSAFE. | ||
*/ | ||
filters.push(filter.FILTER_NOT_HANDLE); | ||
msg = "[WARNING] ContextParserHandlebars: unsafe output place holder at (line:"+this._lineNo+"/position:"+ptr+")"; | ||
msg = "[WARNING] ContextParserHandlebars: Unsafe output expression. ["+this._lineNo+":"+this._charNo+"]"; | ||
handlebarsUtil.handleError(msg); | ||
@@ -391,7 +399,7 @@ return filters; | ||
* please refer to tests/unit/run-states-spec.js, '{' triggers state change to 12.2.4.34 | ||
* we use filter.FILTER_NOT_HANDLE to warn the developers for unsafe output place holder, | ||
* we use filter.FILTER_NOT_HANDLE to warn the developers for unsafe output expression, | ||
* and we fall back to default Handlebars 'h' filter. IT IS UNSAFE. | ||
*/ | ||
filters.push(filter.FILTER_NOT_HANDLE); | ||
msg = "[WARNING] ContextParserHandlebars: unsafe output place holder at (line:"+this._lineNo+"/position:"+ptr+")"; | ||
msg = "[WARNING] ContextParserHandlebars: Unsafe output expression. ["+this._lineNo+":"+this._charNo+"]"; | ||
handlebarsUtil.handleError(msg); | ||
@@ -405,7 +413,7 @@ return filters; | ||
/* we use filter.FILTER_NOT_HANDLE to warn the developers for unsafe output place holder, | ||
/* we use filter.FILTER_NOT_HANDLE to warn the developers for unsafe output expression, | ||
* and we fall back to default Handlebars 'h' filter. IT IS UNSAFE. | ||
*/ | ||
filters.push(filter.FILTER_NOT_HANDLE); | ||
msg = "[WARNING] ContextParserHandlebars: unsafe output place holder at (line:"+this._lineNo+"/position:"+ptr+")"; | ||
msg = "[WARNING] ContextParserHandlebars: Unsafe output expression. ["+this._lineNo+":"+this._charNo+"]"; | ||
handlebarsUtil.handleError(msg); | ||
@@ -419,3 +427,19 @@ return filters; | ||
// TODO: the current assumption is partial keeps in/out state the same | ||
// validate the Handlebars template before analysis. | ||
ContextParserHandlebars.prototype._validateTemplate = function(template) { | ||
var msg; | ||
if (!Handlebars.VERSION.match(/^2\./)) { | ||
msg = "[ERROR] ContextParserHandlebars: We support Handlebars 2.0 ONLY!"; | ||
handlebarsUtil.handleError(msg, true); | ||
} | ||
try { | ||
Handlebars.parse(template); | ||
} catch (err) { | ||
msg = "[ERROR] ContextParserHandlebars: Handlebars validation error!"; | ||
handlebarsUtil.handleError(msg, true); | ||
} | ||
}; | ||
// TODO: the current assumption is partial keeps in/out state the same (DATA state) | ||
ContextParserHandlebars.prototype._handlePartialTemplate = function() { | ||
@@ -434,3 +458,3 @@ }; | ||
* @param {string} input - The input string of the HTML5 web page. | ||
* @param {integer} state - The current HTML5 state of the current character before the Handlebars markup. | ||
* @param {integer} state - The current HTML5 state of the current character before the Handlebars expression. | ||
* @returns {object} The feedback object to the Context Parser with advanced index and state of input string after processing. | ||
@@ -442,7 +466,7 @@ * | ||
* <p>The _handleTemplate consumes the string till the end of template start char is met. | ||
* As the Handlebars markup is in the format of either {{expression}} or {{{expression}}}, | ||
* As the Handlebars expression is in the format of either {{expression}} or {{{expression}}}, | ||
* this function return the character pointer right after the last '}' back to the contextParser.</p> | ||
* | ||
* <p>The context template parser expects to return the same index i if it is not template stream, | ||
* otherwise it returns the pointer right after the template markup char, like '}'</p> | ||
* otherwise it returns the pointer right after the template expression char, like '}'</p> | ||
* | ||
@@ -460,19 +484,15 @@ */ | ||
/* It is not the Handlebars markup, return immediately */ | ||
var NOT_EXPRESSION = 0; | ||
/* It is the Handlebars markup in the format of with prefix {{ */ | ||
var ESCAPE_EXPRESSION = 1; | ||
/* It is the Handlebars markup in the format of with prefix {{{ */ | ||
var RAW_EXPRESSION = 2; | ||
/* Handlebars markup type */ | ||
var handlebarsExpressionType = NOT_EXPRESSION; | ||
/* Handlebars expression type */ | ||
var handlebarsExpressionType = handlebarsUtil.NOT_EXPRESSION; | ||
/* Extra information of expression */ | ||
var extraExpressionInfo; | ||
/* Handlebars reserved markup */ | ||
var isHandlebarsReservedTag = false; | ||
/* Handlebars reserved expression */ | ||
var isHandlebarsReservedExpression = false; | ||
/* Handlebars template context */ | ||
var isHandlebarsContext = false; | ||
/* Handlebars {{#if}} {{else}} {{#with}} {{#each}} {{#unless}} markup */ | ||
var isBranchTags = false; | ||
/* Handlebars {{#if}} {{else}} {{#with}} {{#each}} {{#unless}} expression */ | ||
var isBranchExpressions = false; | ||
/* regular expression validation result */ | ||
var re; | ||
@@ -483,3 +503,3 @@ /* context filters */ | ||
/* Encounter a known filter, we will not add any customized filters if it is known filter */ | ||
var isKnownFilter = false; | ||
var isPrefixWithKnownFilter = false; | ||
debug("_handleTemplate:len:"+len+",i:"+i); | ||
@@ -489,3 +509,3 @@ | ||
* ---- LOGIC #1 - is handlebars template? ---- | ||
* Determine the type of Handlebars markup | ||
* Determine the type of Handlebars expression | ||
* Note: character comparison is the faster as compared with any type of string operation. | ||
@@ -495,9 +515,19 @@ */ | ||
isHandlebarsContext = true; | ||
handlebarsExpressionType = RAW_EXPRESSION; | ||
handlebarsExpressionType = handlebarsUtil.RAW_EXPRESSION; | ||
re = handlebarsUtil.isValidExpression(input, i, handlebarsUtil.RAW_EXPRESSION); | ||
if (re.result === false) { | ||
msg = "[ERROR] ContextParserHandlebars: Parsing error! Invalid expression. ["+this._lineNo+":"+this._charNo+"]"; | ||
handlebarsUtil.handleError(msg, true); | ||
} | ||
} else if (ch === '{' && i+1 < len && input[i+1] === '{') { | ||
isHandlebarsContext = true; | ||
handlebarsExpressionType = ESCAPE_EXPRESSION; | ||
handlebarsExpressionType = handlebarsUtil.ESCAPE_EXPRESSION; | ||
re = handlebarsUtil.isValidExpression(input, i, handlebarsUtil.ESCAPE_EXPRESSION); | ||
if (re.result === false) { | ||
msg = "[ERROR] ContextParserHandlebars: Parsing error! Invalid expression. ["+this._lineNo+":"+this._charNo+"]"; | ||
handlebarsUtil.handleError(msg, true); | ||
} | ||
} else { | ||
isHandlebarsContext = false; | ||
handlebarsExpressionType = NOT_EXPRESSION; | ||
handlebarsExpressionType = handlebarsUtil.NOT_EXPRESSION; | ||
/* return immediately for non template start char '{' */ | ||
@@ -510,10 +540,10 @@ return index; | ||
* ---- LOGIC #2 - OPEN BRACE ---- | ||
* Determine the type of Handlebars escape expression | ||
*/ | ||
if (handlebarsExpressionType === ESCAPE_EXPRESSION) { | ||
isBranchTags = handlebarsUtil.isBranchTags(input, i); | ||
if (handlebarsExpressionType === handlebarsUtil.ESCAPE_EXPRESSION) { | ||
isBranchExpressions = handlebarsUtil.isBranchExpressions(input, i); | ||
if (i+2<len) { | ||
isHandlebarsReservedTag = handlebarsUtil.isReservedChar(input[i+2]); | ||
isHandlebarsReservedExpression = handlebarsUtil.isReservedChar(input[i+2]); | ||
} | ||
if (!isBranchTags) { | ||
if (!isBranchExpressions) { | ||
/* Consume 2 '{' chars */ | ||
@@ -524,4 +554,3 @@ this.printChar(input[i]); | ||
} | ||
} else if (handlebarsExpressionType === RAW_EXPRESSION) { | ||
} else if (handlebarsExpressionType === handlebarsUtil.RAW_EXPRESSION) { | ||
/* consume 3 '{' chars */ | ||
@@ -534,3 +563,3 @@ this.printChar(input[i]); | ||
} | ||
debug("_handleTemplate:LOGIC#2:isBranchTags:"+isBranchTags+",isHandlebarsReservedTag:"+isHandlebarsReservedTag+",i:"+i); | ||
debug("_handleTemplate:LOGIC#2:isBranchExpressions:"+isBranchExpressions+",isHandlebarsReservedExpression:"+isHandlebarsReservedExpression+",i:"+i); | ||
@@ -540,3 +569,3 @@ /* | ||
*/ | ||
if (handlebarsExpressionType === ESCAPE_EXPRESSION && !isHandlebarsReservedTag) { | ||
if (handlebarsExpressionType === handlebarsUtil.ESCAPE_EXPRESSION && !isHandlebarsReservedExpression) { | ||
/* | ||
@@ -546,10 +575,10 @@ * Check whether there is a known filter being added, | ||
*/ | ||
extraExpressionInfo = this._getExpressionExtraInfo(input, i); | ||
isKnownFilter = extraExpressionInfo.isKnownFilter; | ||
extraExpressionInfo = this._parseExpression(input, i); | ||
isPrefixWithKnownFilter = extraExpressionInfo.isPrefixWithKnownFilter; | ||
if (!isKnownFilter) { | ||
if (!isPrefixWithKnownFilter) { | ||
/* We suppress the escapeExpression of handlebars by changing the {{expression}} into {{{expression}}} */ | ||
this.printChar('{'); | ||
/* Get the customized filter based on the current HTML5 state before the Handlebars template markup. */ | ||
/* Get the customized filter based on the current HTML5 state before the Handlebars template expression. */ | ||
var extraInfo = { | ||
@@ -578,25 +607,30 @@ 'attributeName': this.getAttributeName(), | ||
*/ | ||
if (handlebarsExpressionType === ESCAPE_EXPRESSION && isBranchTags && isHandlebarsReservedTag) { | ||
/* Extract the branching statement, and subpress non-branching markup. */ | ||
var objMaskedStmt = handlebarsUtil.extractBranchStmt(input, i, true); | ||
if (handlebarsExpressionType === handlebarsUtil.ESCAPE_EXPRESSION && isBranchExpressions && isHandlebarsReservedExpression) { | ||
try { | ||
/* Extract the branching statement, and subpress non-branching expression. */ | ||
var objMaskedStmt = handlebarsUtil.extractBranchStmt(input, i, true); | ||
/* Parse the branching statement. */ | ||
var ast = handlebarsUtil.parseBranchStmt(objMaskedStmt.stmt); | ||
/* Parse the branching statement. */ | ||
var ast = handlebarsUtil.parseBranchStmt(objMaskedStmt.stmt); | ||
/* Restore the open/close_brace_nonce with {} for analysis */ | ||
objMaskedStmt.stmt = objMaskedStmt.stmt.replace(new RegExp(objMaskedStmt.openBracePlaceHolder, 'g'), '{'); | ||
objMaskedStmt.stmt = objMaskedStmt.stmt.replace(new RegExp(objMaskedStmt.closeBracePlaceHolder, 'g'), '}'); | ||
/* Restore the open/close_brace_nonce with {} for analysis */ | ||
objMaskedStmt.stmt = objMaskedStmt.stmt.replace(new RegExp(objMaskedStmt.openBracePlaceHolder, 'g'), '{'); | ||
objMaskedStmt.stmt = objMaskedStmt.stmt.replace(new RegExp(objMaskedStmt.closeBracePlaceHolder, 'g'), '}'); | ||
var result = handlebarsUtil.parseAstTreeState(ast, state, objMaskedStmt); | ||
var result = handlebarsUtil.parseAstTreeState(ast, state, objMaskedStmt); | ||
/* echo to output */ | ||
this.printChar(result.stmt); | ||
/* echo to output */ | ||
this.printChar(result.stmt); | ||
/* Advance the index pointer i to the char after the last brace of branching markup. */ | ||
var objUnmaskedStmt = handlebarsUtil.extractBranchStmt(input, i, false); | ||
i=i+objUnmaskedStmt.stmt.length; | ||
this.state = result.lastStates[0]; | ||
/* Advance the index pointer i to the char after the last brace of branching expression. */ | ||
var objUnmaskedStmt = handlebarsUtil.extractBranchStmt(input, i, false); | ||
i=i+objUnmaskedStmt.stmt.length; | ||
this.state = result.lastStates[0]; | ||
debug("_handleTemplate:LOGIC#A:state:"+this.state+",i:"+i); | ||
return i; | ||
debug("_handleTemplate:LOGIC#A:state:"+this.state+",i:"+i); | ||
return i; | ||
} catch (err) { | ||
msg = err + " ["+this._lineNo+":"+this._charNo+"]"; | ||
handlebarsUtil.handleError(msg, true); | ||
} | ||
} | ||
@@ -606,3 +640,3 @@ | ||
* ---- LOGIC #4 - CLOSE BRACE ---- | ||
* After the customized filter is added, we simply consume the character till we meet the close braces of Handlebars markup | ||
* After the customized filter is added, we simply consume the character till we meet the close braces of Handlebars expression | ||
*/ | ||
@@ -612,4 +646,4 @@ for(var j=i+1;j<len;++j) { | ||
if (handlebarsExpressionType === ESCAPE_EXPRESSION) { | ||
/* Encounter the end of Handlebars markup close brace */ | ||
if (handlebarsExpressionType === handlebarsUtil.ESCAPE_EXPRESSION) { | ||
/* Encounter the end of Handlebars expression close brace */ | ||
if (input[j] === '}' && j+1 < len && input[j+1] === '}') { | ||
@@ -634,3 +668,3 @@ | ||
/* we suppress the escapeExpression of handlebars by changing the {{expression}} into {{{expression}}} */ | ||
if (!isHandlebarsReservedTag && !isKnownFilter) { | ||
if (!isHandlebarsReservedExpression && !isPrefixWithKnownFilter) { | ||
this.printChar('}'); | ||
@@ -640,7 +674,7 @@ } | ||
isHandlebarsContext = false; | ||
handlebarsExpressionType = NOT_EXPRESSION; | ||
handlebarsExpressionType = handlebarsUtil.NOT_EXPRESSION; | ||
i=i+1; /* Point to the char right after the last '}' */ | ||
/* update the Context Parser's state if it is not reserved tag */ | ||
if (!isHandlebarsReservedTag) { | ||
if (!isHandlebarsReservedExpression) { | ||
this.state = state; | ||
@@ -661,4 +695,4 @@ | ||
} | ||
} else if (handlebarsExpressionType === RAW_EXPRESSION) { | ||
/* Encounter the end of Handlebars markup close brace */ | ||
} else if (handlebarsExpressionType === handlebarsUtil.RAW_EXPRESSION) { | ||
/* Encounter the end of Handlebars expression close brace */ | ||
if (input[j] === '}' && j+2 < len && input[j+1] === '}' && input[j+2] === '}') { | ||
@@ -677,3 +711,3 @@ /* Print the first '}' */ | ||
isHandlebarsContext = false; | ||
handlebarsExpressionType = NOT_EXPRESSION; | ||
handlebarsExpressionType = handlebarsUtil.NOT_EXPRESSION; | ||
i=i+1; /* Point to the char right after the last '}' */ | ||
@@ -705,3 +739,3 @@ /* update the Context Parser's state if it is not reserved tag */ | ||
if (isHandlebarsContext) { | ||
msg = "[ERROR] ContextParserHandlebars: Template parsing error, cannot encounter '}}' or '}}}' close brace at (line:"+this._lineNo+"/position:"+i+")"; | ||
msg = "[ERROR] ContextParserHandlebars: Parsing error! Cannot encounter '}}' or '}}}' close brace. ["+this._lineNo+":"+this._charNo+"]"; | ||
handlebarsUtil.handleError(msg, true); | ||
@@ -720,2 +754,8 @@ } | ||
/* TODO: use vanilla Handlebars to validate the template? | ||
if (i === 0) { | ||
this._validateTemplate(input); | ||
} | ||
*/ | ||
var len = input.length, | ||
@@ -729,3 +769,3 @@ ch = input[i], | ||
* before passing to the _handleTemplate function, | ||
* we need to judge the exact state of output markup, | ||
* we need to judge the exact state of output expression, | ||
* querying the new state based on previous state this.state. | ||
@@ -745,3 +785,3 @@ */ | ||
/* update the i, it is the index right after the handlebars markup */ | ||
/* update the i, it is the index right after the handlebars expression */ | ||
i = j; | ||
@@ -770,3 +810,5 @@ | ||
++this._lineNo; | ||
this._charNo = 1; | ||
} | ||
++this._charNo; | ||
}; | ||
@@ -773,0 +815,0 @@ |
@@ -22,3 +22,3 @@ /* | ||
/* vanillia Handlebars */ | ||
/* vanilla Handlebars */ | ||
var Handlebars = require("handlebars"); | ||
@@ -49,3 +49,52 @@ | ||
/* type of expression */ | ||
HandlebarsUtils.NOT_EXPRESSION = 0; | ||
HandlebarsUtils.ESCAPE_EXPRESSION = 1; | ||
HandlebarsUtils.RAW_EXPRESSION = 2; | ||
/* RegExp to match expression */ | ||
/* '{{' 'non-{,non-}'+ '}}' and not follow by '}' */ | ||
HandlebarsUtils.escapeExpressionRegExp = /^\{\{[^\}\{]+?\}\}(?!})/; | ||
/* '{{{' 'non-{,non-}'+ '}}}' and not follow by '}' */ | ||
HandlebarsUtils.rawExpressionRegExp = /^\{\{\{[^\}\{]+?\}\}\}(?!})/; | ||
/* '{{' '# or ^' 'space'* 'non-space,non-},non-{'+ first-'space or }' */ | ||
HandlebarsUtils.branchExpressionRegExp = /^\{\{[#|\\^]\s*([^\s\}\{]+)?[\s\}]/; | ||
/* '{{' '/' 'space'* 'non-space,non-},non-{'+ first-'space or }' */ | ||
HandlebarsUtils.branchEndExpressionRegExp = /^\{\{\/\s*([^\s\}\{]+)?[\s\}]/; | ||
/* '{{' 'space'* 'else' 'space'* '}}' */ | ||
HandlebarsUtils.elseExpressionRegExp = /^\{\{\s*else\s*?\}\}/; | ||
/** | ||
* @function HandlebarsUtils.isValidExpression | ||
* | ||
* @static | ||
* | ||
* @description | ||
* <p>This function is used to look ahead to check whether it is a valid expression.</p> | ||
* | ||
*/ | ||
HandlebarsUtils.isValidExpression = function(input, i, type) { | ||
var re = {}; | ||
re.result = false; | ||
switch(type) { | ||
case HandlebarsUtils.ESCAPE_EXPRESSION: | ||
re = HandlebarsUtils.escapeExpressionRegExp.exec(input.slice(i)); | ||
break; | ||
case HandlebarsUtils.RAW_EXPRESSION: | ||
re = HandlebarsUtils.rawExpressionRegExp.exec(input.slice(i)); | ||
break; | ||
default: | ||
return re; | ||
} | ||
if (re !== null) { | ||
re.result = true; | ||
} else { | ||
re = {}; | ||
re.result = false; | ||
} | ||
return re; | ||
}; | ||
/** | ||
* @function HandlebarsUtils.isReservedChar | ||
@@ -59,4 +108,4 @@ * | ||
* @description | ||
* <p>Check whether the Handlebars markup is a reserved markup. | ||
* The reserved markup includes block expression, partial template expression etc.</p> | ||
* <p>Check whether the Handlebars expression is a reserved expression. | ||
* The reserved expression includes block expression, partial template expression etc.</p> | ||
* | ||
@@ -75,3 +124,3 @@ * <p>For reference, please check https://github.com/mustache/spec/tree/master/specs</p> | ||
/** | ||
* @function HandlebarsUtils.isBranchTag | ||
* @function HandlebarsUtils.isBranchExpression | ||
* | ||
@@ -83,10 +132,7 @@ * @static | ||
* @description | ||
* <p>Check whether the Handlebars markup is {{#\w*}} and {{^\w*}} markup.</p> | ||
* <p>Check whether the Handlebars expression is {{#\w*}} and {{^\w*}} expression.</p> | ||
* | ||
*/ | ||
HandlebarsUtils.isBranchTag = function(input, i) { | ||
// TODO: regular expression and slice is slow | ||
/* '{{' '# ot ^' 'space'* 'non-space and non-}'+ first-'space or }' */ | ||
var p = /^{{[#|\\^]\s*([^\s\}]+)?[\s\}]/g; | ||
var re = p.exec(input.slice(i)); | ||
HandlebarsUtils.isBranchExpression = function(input, i) { | ||
var re = HandlebarsUtils.branchExpressionRegExp.exec(input.slice(i)); | ||
if (re === null) { | ||
@@ -101,3 +147,3 @@ return false; | ||
/** | ||
* @function HandlebarsUtils.isBranchEndTag | ||
* @function HandlebarsUtils.isBranchEndExpression | ||
* | ||
@@ -109,11 +155,7 @@ * @static | ||
* @description | ||
* <p>Check whether the Handlebars markup is {{/\w*}} markup.</p> | ||
* <p>Check whether the Handlebars expression is {{/\w*}} expression.</p> | ||
* | ||
*/ | ||
HandlebarsUtils.isBranchEndTag = function(input, i) { | ||
// TODO: regular expression and slice is slow | ||
/* '{{' '/' 'space'* 'non-space and non-}'+ first-'space or }' */ | ||
var p = /^{{\/\s*([^\s\}]+)?[\s\}]/g; | ||
var re = p.exec(input.slice(i)); | ||
HandlebarsUtils.isBranchEndExpression = function(input, i) { | ||
var re = HandlebarsUtils.branchEndExpressionRegExp.exec(input.slice(i)); | ||
if (re === null) { | ||
@@ -128,3 +170,3 @@ return false; | ||
/** | ||
* @function HandlebarsUtils.isElseTag | ||
* @function HandlebarsUtils.isElseExpression | ||
* | ||
@@ -136,10 +178,7 @@ * @static | ||
* @description | ||
* <p>Check whether the Handlebars markup is {{else}} markup.</p> | ||
* <p>Check whether the Handlebars expression is {{else}} expression.</p> | ||
* | ||
*/ | ||
HandlebarsUtils.isElseTag = function(input, i) { | ||
// TODO: regular expression and slice is slow | ||
var p = /^{{\s*else\s*?}}/g; | ||
var re = p.exec(input.slice(i)); | ||
HandlebarsUtils.isElseExpression = function(input, i) { | ||
var re = HandlebarsUtils.elseExpressionRegExp.exec(input.slice(i)); | ||
if (re === null) { | ||
@@ -153,3 +192,3 @@ return false; | ||
/** | ||
* @function HandlebarsUtils.isBranchTags | ||
* @function HandlebarsUtils.isBranchExpressions | ||
* | ||
@@ -161,7 +200,7 @@ * @static | ||
* @description | ||
* <p>Check whether the Handlebars markup is "branching" markup.</p> | ||
* <p>Check whether the Handlebars expression is "branching" expression.</p> | ||
* | ||
*/ | ||
HandlebarsUtils.isBranchTags = function(input, i) { | ||
var r = HandlebarsUtils.isBranchTag(input, i); | ||
HandlebarsUtils.isBranchExpressions = function(input, i) { | ||
var r = HandlebarsUtils.isBranchExpression(input, i); | ||
if (r === false) { | ||
@@ -211,2 +250,8 @@ return false; | ||
HandlebarsUtils.parseBranchStmt = function(s) { | ||
if (!Handlebars.VERSION.match(/^2\./)) { | ||
var msg = "[ERROR] ContextParserHandlebars: We support Handlebars 2.0 ONLY!"; | ||
HandlebarsUtils.handleError(msg, true); | ||
} | ||
// TODO: we should build our own data structure instead of using Handlebars directly. | ||
var ast = Handlebars.parse(s); | ||
@@ -226,8 +271,8 @@ if (ast.statements !== undefined) { | ||
* @param {string} input - The template input string. | ||
* @param {int} k - The pointer to the first char of the first brace markup of Handlebars template. | ||
* @param {boolean} masked - The flag to mask the non branching statement markup. | ||
* @param {int} k - The pointer to the first char of the first brace expression of Handlebars template. | ||
* @param {boolean} masked - The flag to mask the non branching statement expression. | ||
* @returns {Object} The object with branching statement and place holder. | ||
* | ||
* @description | ||
* <p>This function extracts a branching statement with balanced markup.</p> | ||
* <p>This function extracts a branching statement with balanced expression.</p> | ||
* | ||
@@ -250,3 +295,3 @@ */ | ||
* be used for building the AST for finding all the combination of strings, | ||
* however the non-branching markup will make the AST more | ||
* however the non-branching expression will make the AST more | ||
* complicated, so this function masks out all open/close brace | ||
@@ -260,4 +305,4 @@ * with a random nonce. | ||
for(var i=0;i<l;++i) { | ||
var tag = HandlebarsUtils.isBranchTag(str, i), | ||
endTag = HandlebarsUtils.isBranchEndTag(str, i); | ||
var tag = HandlebarsUtils.isBranchExpression(str, i), | ||
endExpression = HandlebarsUtils.isBranchEndExpression(str, i); | ||
@@ -269,10 +314,10 @@ /* push the branching tokens */ | ||
/* do nothing for 'else' token */ | ||
} else if (HandlebarsUtils.isElseTag(str, i)) { | ||
} else if (HandlebarsUtils.isElseExpression(str, i)) { | ||
/* pop the branching tokens (TODO: not fast enough) */ | ||
} else if (endTag !== false) { | ||
} else if (endExpression !== false) { | ||
if (sp.length > 0) { | ||
var lastTag = sp[sp.length-1]; | ||
var lastExpression = sp[sp.length-1]; | ||
/* check for balanced branching statement */ | ||
if (lastTag === endTag) { | ||
if (lastExpression === endExpression) { | ||
sp.pop(); | ||
@@ -290,4 +335,4 @@ /* consume till the end of '}}' */ | ||
} else { | ||
/* broken template as the end markup does not match, throw exception before function returns */ | ||
msg = "[ERROR] ContextParserHandlebars: Template markup mismatch (start_tag:"+lastTag+"/endTag:"+endTag+")"; | ||
/* broken template as the end expression does not match, throw exception before function returns */ | ||
msg = "[ERROR] ContextParserHandlebars: Template expression mismatch (startExpression:"+lastExpression+"/endExpression:"+endExpression+")"; | ||
HandlebarsUtils.handleError(msg, true); | ||
@@ -297,7 +342,7 @@ } | ||
/* broken template, throw exception before function returns */ | ||
msg = "[ERROR] ContextParserHandlebars: cannot find the corresponding start markup (tag:"+endTag+")"; | ||
msg = "[ERROR] ContextParserHandlebars: Cannot find the corresponding start expression (tag:"+endExpression+")"; | ||
HandlebarsUtils.handleError(msg, true); | ||
} | ||
/* non-branching markup */ | ||
/* non-branching expression */ | ||
} else { | ||
@@ -383,3 +428,3 @@ | ||
/* throw error on the template */ | ||
msg = "[ERROR] ContextParserHandlebars: Template does not have balanced branching markup."; | ||
msg = "[ERROR] ContextParserHandlebars: Template does not have balanced branching expression."; | ||
HandlebarsUtils.handleError(msg, true); | ||
@@ -582,3 +627,3 @@ } | ||
if (r.lastStates[0] !== r.lastStates[1]) { | ||
msg = "[ERROR] ContextParserHandlebars: Template parsing error, inconsitent HTML5 state after conditional branches. Please fix your template!"; | ||
msg = "[ERROR] ContextParserHandlebars: Parsing error! Inconsitent HTML5 state after conditional branches. Please fix your template!"; | ||
HandlebarsUtils.handleError(msg, true); | ||
@@ -633,6 +678,7 @@ } | ||
filterPlaceHolders.forEach(function(filterPlaceHolder) { | ||
/* get the output markup from stmt */ | ||
var outputMarkup = new RegExp('{{' + filterPlaceHolder + '.*?}}', 'g'); | ||
/* get the output expression from masked stmt */ | ||
var outputMarkup = new RegExp('\{\{' + filterPlaceHolder + '.*?\}\}', 'g'); | ||
var m1 = outputMarkup.exec(obj.stmt); | ||
/* get the output filter expression from processed stmt */ | ||
var i = str.indexOf(filterPlaceHolder); | ||
@@ -647,3 +693,3 @@ if (i !== -1 && m1 !== null && m1[0]) { | ||
m2 !== null && m2) { | ||
/* Replace the output markup with filter markup */ | ||
/* Replace the output expression with filter expression */ | ||
obj.stmt = obj.stmt.replace(m1[0], m2); | ||
@@ -650,0 +696,0 @@ /* Replace the filterPlaceHolder with empty string */ |
@@ -12,9 +12,9 @@ /* | ||
var mocha = require("mocha"), | ||
promise = require('bluebird'), | ||
require("mocha"); | ||
var promise = require('bluebird'), | ||
fs = require('fs'), | ||
expect = require('expect.js'), | ||
expect = require('chai').expect, | ||
ContextParserHandlebars = require("../../src/context-parser-handlebars"); | ||
var NO_OF_TEMPLATE = 20, | ||
var NO_OF_TEMPLATE = 22, | ||
NO_OF_FILTER_TEMPLATE = 20; | ||
@@ -111,7 +111,28 @@ | ||
.timeout(300) | ||
.then(function(streams){ | ||
.then(function(e){ | ||
done(); | ||
}); | ||
}); | ||
/* this test will throw exception, and the vanilla handlebars will complain */ | ||
it("./bin/handlebarspc conditional/iteration mismatch template test", function(done) { | ||
var exec = promise.promisify(require("child_process").exec); | ||
exec('./bin/handlebarspc ./tests/samples/files/handlebarsjs_template_021.hbs') | ||
.timeout(300) | ||
.catch(function(e){ | ||
done(); | ||
}); | ||
}); | ||
/* this test will throw exception, and the vanilla handlebars will complain */ | ||
it("./bin/handlebarspc conditional/iteration mismatch template test", function(done) { | ||
var exec = promise.promisify(require("child_process").exec); | ||
exec('./bin/handlebarspc ./tests/samples/files/handlebarsjs_template_022.hbs') | ||
.timeout(300) | ||
.catch(function(e){ | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}()); |
@@ -12,5 +12,6 @@ /* | ||
var mocha = require("mocha"), | ||
fs = require('fs'), | ||
expect = require('expect.js'), | ||
require("mocha"); | ||
var fs = require('fs'), | ||
expect = require('chai').expect, | ||
utils = require('../utils.js'), | ||
ContextParserHandlebars = require("../../src/context-parser-handlebars"); | ||
@@ -26,3 +27,6 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{yd name}}}/); | ||
var arr = [ | ||
/{{{yd name}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -33,4 +37,6 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{yc comment}}}/); | ||
expect(data).to.match(/{{{yd name}}}/); | ||
var arr = [ | ||
/{{{yc comment}}}/, /{{{yd name}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -41,41 +47,24 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{yubl \(yavd \(yufull url11\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavs \(yufull url12\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavd \(yufull url13\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavs \(yufull url14\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavu \(yufull url15\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavu \(yufull url16\)\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yu path11\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yu path12\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yu path13\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yu path14\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yu path15\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yu path16\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yu kv11\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yu kv12\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yu kv13\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yu kv14\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yu kv15\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yu kv16\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q11\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q12\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q13\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q14\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q15\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q16\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q17\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q18\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q19\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q20\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q21\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q22\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q23\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q24\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q25\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc hash11\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc hash12\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc hash13\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc hash14\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc hash15\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc hash16\)}}}/); | ||
var arr = [ | ||
// test against double quoted, single quoted and unquoted URL in attribute href | ||
/{{{yubl \(yavd \(yufull url11\)\)}}}/, /{{{yubl \(yavs \(yufull url12\)\)}}}/, /{{{yubl \(yavd \(yufull url13\)\)}}}/, | ||
/{{{yubl \(yavs \(yufull url14\)\)}}}/, /{{{yubl \(yavu \(yufull url15\)\)}}}/, /{{{yubl \(yavu \(yufull url16\)\)}}}/, | ||
// test against double quoted, single quoted and unquoted URL Path in attribute href | ||
/{{{yavd \(yu path11\)}}}/, /{{{yavs \(yu path12\)}}}/, /{{{yavd \(yu path13\)}}}/, | ||
/{{{yavs \(yu path14\)}}}/, /{{{yavu \(yu path15\)}}}/, /{{{yavu \(yu path16\)}}}/, | ||
// test against double quoted, single quoted and unquoted after URL ? in attribute href | ||
/{{{yavd \(yu kv11\)}}}/, /{{{yavs \(yu kv12\)}}}/, /{{{yavd \(yu kv13\)}}}/, | ||
/{{{yavs \(yu kv14\)}}}/, /{{{yavu \(yu kv15\)}}}/, /{{{yavu \(yu kv16\)}}}/, | ||
// test against double quoted, single quoted and unquoted URL query string in attribute href | ||
/{{{yavd \(yuc q11\)}}}/, /{{{yavd \(yuc q12\)}}}/, /{{{yavd \(yuc q13\)}}}/, | ||
/{{{yavs \(yuc q14\)}}}/, /{{{yavs \(yuc q15\)}}}/, /{{{yavs \(yuc q16\)}}}/, | ||
/{{{yavd \(yuc q17\)}}}/, /{{{yavd \(yuc q18\)}}}/, /{{{yavs \(yuc q19\)}}}/, | ||
/{{{yavs \(yuc q20\)}}}/, /{{{yavu \(yuc q21\)}}}/, /{{{yavu \(yuc q22\)}}}/, | ||
/{{{yavu \(yuc q22\)}}}/, /{{{yavu \(yuc q23\)}}}/, /{{{yavu \(yuc q24\)}}}/, | ||
/{{{yavu \(yuc q25\)}}}/, | ||
// test against double quoted, single quoted and unquoted URL hash in attribute href | ||
/{{{yavd \(yuc hash11\)}}}/, /{{{yavs \(yuc hash12\)}}}/, /{{{yavd \(yuc hash13\)}}}/, | ||
/{{{yavs \(yuc hash14\)}}}/, /{{{yavu \(yuc hash15\)}}}/, /{{{yavu \(yuc hash16\)}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -86,41 +75,24 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{yubl \(yavd \(yufull url11\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavs \(yufull url12\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavd \(yufull url13\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavs \(yufull url14\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavu \(yufull url15\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavu \(yufull url16\)\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yu path11\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yu path12\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yu path13\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yu path14\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yu path15\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yu path16\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yu kv11\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yu kv12\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yu kv13\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yu kv14\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yu kv15\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yu kv16\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q11\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q12\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q13\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q14\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q15\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q16\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q17\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q18\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q19\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q20\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q21\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q22\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q23\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q24\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q25\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc hash11\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc hash12\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc hash13\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc hash14\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc hash15\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc hash16\)}}}/); | ||
var arr = [ | ||
// test against double quoted, single quoted and unquoted URL in attribute form's action | ||
/{{{yubl \(yavd \(yufull url11\)\)}}}/, /{{{yubl \(yavs \(yufull url12\)\)}}}/, /{{{yubl \(yavd \(yufull url13\)\)}}}/, | ||
/{{{yubl \(yavs \(yufull url14\)\)}}}/, /{{{yubl \(yavu \(yufull url15\)\)}}}/, /{{{yubl \(yavu \(yufull url16\)\)}}}/, | ||
// test against double quoted, single quoted and unquoted URL Path in attribute form's action | ||
/{{{yavd \(yu path11\)}}}/, /{{{yavs \(yu path12\)}}}/, /{{{yavd \(yu path13\)}}}/, | ||
/{{{yavs \(yu path14\)}}}/, /{{{yavu \(yu path15\)}}}/, /{{{yavu \(yu path16\)}}}/, | ||
// test against double quoted, single quoted and unquoted after URL ? in attribute form's action | ||
/{{{yavd \(yu kv11\)}}}/, /{{{yavs \(yu kv12\)}}}/, /{{{yavd \(yu kv13\)}}}/, | ||
/{{{yavs \(yu kv14\)}}}/, /{{{yavu \(yu kv15\)}}}/, /{{{yavu \(yu kv16\)}}}/, | ||
// test against double quoted, single quoted and unquoted URL query string in attribute form's action | ||
/{{{yavd \(yuc q11\)}}}/, /{{{yavd \(yuc q12\)}}}/, /{{{yavd \(yuc q13\)}}}/, | ||
/{{{yavs \(yuc q14\)}}}/, /{{{yavs \(yuc q15\)}}}/, /{{{yavs \(yuc q16\)}}}/, | ||
/{{{yavd \(yuc q17\)}}}/, /{{{yavd \(yuc q18\)}}}/, /{{{yavs \(yuc q19\)}}}/, | ||
/{{{yavs \(yuc q20\)}}}/, /{{{yavu \(yuc q21\)}}}/, /{{{yavu \(yuc q22\)}}}/, | ||
/{{{yavu \(yuc q22\)}}}/, /{{{yavu \(yuc q23\)}}}/, /{{{yavu \(yuc q24\)}}}/, | ||
/{{{yavu \(yuc q25\)}}}/, | ||
// test against double quoted, single quoted and unquoted URL hash in attribute form's action | ||
/{{{yavd \(yuc hash11\)}}}/, /{{{yavs \(yuc hash12\)}}}/, /{{{yavd \(yuc hash13\)}}}/, | ||
/{{{yavs \(yuc hash14\)}}}/, /{{{yavu \(yuc hash15\)}}}/, /{{{yavu \(yuc hash16\)}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -131,41 +103,24 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{yubl \(yavd \(yufull url11\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavs \(yufull url12\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavd \(yufull url13\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavs \(yufull url14\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavu \(yufull url15\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavu \(yufull url16\)\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yu path11\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yu path12\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yu path13\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yu path14\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yu path15\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yu path16\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yu kv11\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yu kv12\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yu kv13\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yu kv14\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yu kv15\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yu kv16\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q11\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q12\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q13\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q14\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q15\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q16\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q17\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q18\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q19\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q20\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q21\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q22\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q23\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q24\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q25\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc hash11\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc hash12\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc hash13\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc hash14\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc hash15\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc hash16\)}}}/); | ||
var arr = [ | ||
// test against double quoted, single quoted and unquoted URL in attribute img's src | ||
/{{{yubl \(yavd \(yufull url11\)\)}}}/, /{{{yubl \(yavs \(yufull url12\)\)}}}/, /{{{yubl \(yavd \(yufull url13\)\)}}}/, | ||
/{{{yubl \(yavs \(yufull url14\)\)}}}/, /{{{yubl \(yavu \(yufull url15\)\)}}}/, /{{{yubl \(yavu \(yufull url16\)\)}}}/, | ||
// test against double quoted, single quoted and unquoted URL Path in attribute img's src | ||
/{{{yavd \(yu path11\)}}}/, /{{{yavs \(yu path12\)}}}/, /{{{yavd \(yu path13\)}}}/, | ||
/{{{yavs \(yu path14\)}}}/, /{{{yavu \(yu path15\)}}}/, /{{{yavu \(yu path16\)}}}/, | ||
// test against double quoted, single quoted and unquoted after URL ? in attribute img's src | ||
/{{{yavd \(yu kv11\)}}}/, /{{{yavs \(yu kv12\)}}}/, /{{{yavd \(yu kv13\)}}}/, | ||
/{{{yavs \(yu kv14\)}}}/, /{{{yavu \(yu kv15\)}}}/, /{{{yavu \(yu kv16\)}}}/, | ||
// test against double quoted, single quoted and unquoted URL query string in attribute img's src | ||
/{{{yavd \(yuc q11\)}}}/, /{{{yavd \(yuc q12\)}}}/, /{{{yavd \(yuc q13\)}}}/, | ||
/{{{yavs \(yuc q14\)}}}/, /{{{yavs \(yuc q15\)}}}/, /{{{yavs \(yuc q16\)}}}/, | ||
/{{{yavd \(yuc q17\)}}}/, /{{{yavd \(yuc q18\)}}}/, /{{{yavs \(yuc q19\)}}}/, | ||
/{{{yavs \(yuc q20\)}}}/, /{{{yavu \(yuc q21\)}}}/, /{{{yavu \(yuc q22\)}}}/, | ||
/{{{yavu \(yuc q22\)}}}/, /{{{yavu \(yuc q23\)}}}/, /{{{yavu \(yuc q24\)}}}/, | ||
/{{{yavu \(yuc q25\)}}}/, | ||
// test against double quoted, single quoted and unquoted URL hash in attribute img's src | ||
/{{{yavd \(yuc hash11\)}}}/, /{{{yavs \(yuc hash12\)}}}/, /{{{yavd \(yuc hash13\)}}}/, | ||
/{{{yavs \(yuc hash14\)}}}/, /{{{yavu \(yuc hash15\)}}}/, /{{{yavu \(yuc hash16\)}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -176,75 +131,55 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{yubl \(yavd \(yufull url11\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavs \(yufull url12\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavd \(yufull url13\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavs \(yufull url14\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavu \(yufull url15\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavu \(yufull url16\)\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yu path11\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yu path12\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yu path13\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yu path14\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yu path15\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yu path16\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yu kv11\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yu kv12\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yu kv13\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yu kv14\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yu kv15\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yu kv16\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q11\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q12\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q13\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q14\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q15\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q16\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q17\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc q18\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q19\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc q20\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q21\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q22\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q23\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q24\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc q25\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc hash11\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc hash12\)}}}/); | ||
expect(data).to.match(/{{{yavd \(yuc hash13\)}}}/); | ||
expect(data).to.match(/{{{yavs \(yuc hash14\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc hash15\)}}}/); | ||
expect(data).to.match(/{{{yavu \(yuc hash16\)}}}/); | ||
var arr = [ | ||
// test against double quoted, single quoted and unquoted URL in attribute button's formaction | ||
/{{{yubl \(yavd \(yufull url11\)\)}}}/, /{{{yubl \(yavs \(yufull url12\)\)}}}/, /{{{yubl \(yavd \(yufull url13\)\)}}}/, | ||
/{{{yubl \(yavs \(yufull url14\)\)}}}/, /{{{yubl \(yavu \(yufull url15\)\)}}}/, /{{{yubl \(yavu \(yufull url16\)\)}}}/, | ||
// test against double quoted, single quoted and unquoted URL Path in attribute button's formaction | ||
/{{{yavd \(yu path11\)}}}/, /{{{yavs \(yu path12\)}}}/, /{{{yavd \(yu path13\)}}}/, | ||
/{{{yavs \(yu path14\)}}}/, /{{{yavu \(yu path15\)}}}/, /{{{yavu \(yu path16\)}}}/, | ||
// test against double quoted, single quoted and unquoted after URL ? in attribute button's formaction | ||
/{{{yavd \(yu kv11\)}}}/, /{{{yavs \(yu kv12\)}}}/, /{{{yavd \(yu kv13\)}}}/, | ||
/{{{yavs \(yu kv14\)}}}/, /{{{yavu \(yu kv15\)}}}/, /{{{yavu \(yu kv16\)}}}/, | ||
// test against double quoted, single quoted and unquoted URL query string in attribute button's formaction | ||
/{{{yavd \(yuc q11\)}}}/, /{{{yavd \(yuc q12\)}}}/, /{{{yavd \(yuc q13\)}}}/, | ||
/{{{yavs \(yuc q14\)}}}/, /{{{yavs \(yuc q15\)}}}/, /{{{yavs \(yuc q16\)}}}/, | ||
/{{{yavd \(yuc q17\)}}}/, /{{{yavd \(yuc q18\)}}}/, /{{{yavs \(yuc q19\)}}}/, | ||
/{{{yavs \(yuc q20\)}}}/, /{{{yavu \(yuc q21\)}}}/, /{{{yavu \(yuc q22\)}}}/, | ||
/{{{yavu \(yuc q22\)}}}/, /{{{yavu \(yuc q23\)}}}/, /{{{yavu \(yuc q24\)}}}/, | ||
/{{{yavu \(yuc q25\)}}}/, | ||
// test against double quoted, single quoted and unquoted URL hash in attribute button's formaction | ||
/{{{yavd \(yuc hash11\)}}}/, /{{{yavs \(yuc hash12\)}}}/, /{{{yavd \(yuc hash13\)}}}/, | ||
/{{{yavs \(yuc hash14\)}}}/, /{{{yavu \(yuc hash15\)}}}/, /{{{yavu \(yuc hash16\)}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
it("Filter 006 - add style filters test", function() { | ||
it("Filter 006 - add y filters to style attribute test", function() { | ||
var file = "./tests/samples/files/handlebarsjs_filter_006.hbs.precompiled"; | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{y color11}}}/); | ||
expect(data).to.match(/{{{y color12}}}/); | ||
expect(data).to.match(/{{{y color21}}}/); | ||
expect(data).to.match(/{{{y color22}}}/); | ||
expect(data).to.match(/{{{y color31}}}/); | ||
expect(data).to.match(/{{{y color32}}}/); | ||
expect(data).to.match(/{{{y color41}}}/); | ||
expect(data).to.match(/{{{y color42}}}/); | ||
expect(data).to.match(/{{{y color43}}}/); | ||
expect(data).to.match(/{{{y color5}}}/); | ||
expect(data).to.match(/{{{y color6}}}/); | ||
expect(data).to.match(/{{{y color7}}}/); | ||
expect(data).to.match(/{{{y bgcolor1}}}/); | ||
expect(data).to.match(/{{{y bgcolor2}}}/); | ||
expect(data).to.match(/{{{y bgcolor3}}}/); | ||
expect(data).to.match(/{{{y bgcolor5}}}/); | ||
expect(data).to.match(/{{{y bgcolor6}}}/); | ||
expect(data).to.match(/{{{y bgcolor7}}}/); | ||
var arr = [ | ||
// double quoted | ||
/{{{y color11}}}/, /{{{y color12}}}/, /{{{y bgcolor1}}}/, /{{{y color41}}}/, | ||
/{{{y color5}}}/, /{{{y bgcolor5}}}/, | ||
// single quoted | ||
/{{{y color21}}}/, /{{{y color22}}}/, /{{{y bgcolor2}}}/, /{{{y color42}}}/, | ||
/{{{y color6}}}/, /{{{y bgcolor6}}}/, | ||
// unquoted | ||
/{{{y color31}}}/, /{{{y color32}}}/, /{{{y bgcolor3}}}/, /{{{y color43}}}/, | ||
/{{{y color7}}}/, /{{{y bgcolor7}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
it("Filter 007 - add ycss_quoted and ycss_unquoted filters test", function() { | ||
it("Filter 007 - add y filters to style attribute test", function() { | ||
var file = "./tests/samples/files/handlebarsjs_filter_007.hbs.precompiled"; | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{y style1}}}/); | ||
expect(data).to.match(/{{{y style2}}}/); | ||
expect(data).to.match(/{{{y style3}}}/); | ||
expect(data).to.match(/{{{y style4}}}/); | ||
expect(data).to.match(/{{{y style5}}}/); | ||
expect(data).to.match(/{{{y style6}}}/); | ||
var arr = [ | ||
// double quoted | ||
/{{{y style1}}}/, /{{{y style4}}}/, | ||
// single quoted | ||
/{{{y style2}}}/, /{{{y style5}}}/, | ||
// unquoted | ||
/{{{y style3}}}/, /{{{y style6}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -255,17 +190,25 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{y arg11}}}/); | ||
expect(data).to.match(/{{{y arg12}}}/); | ||
expect(data).to.match(/{{{y arg13}}}/); | ||
var arr = [ | ||
// single quoted | ||
/{{{y arg11}}}/, | ||
// double quoted | ||
/{{{y arg12}}}/, | ||
// unquoted | ||
/{{{y arg13}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
it("Filter 009 - add yav_xxx filters test", function() { | ||
it("Filter 009 - add yavX filters to class attribute test", function() { | ||
var file = "./tests/samples/files/handlebarsjs_filter_009.hbs.precompiled"; | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{yavd class1}}}/); | ||
expect(data).to.match(/{{{yavs class2}}}/); | ||
expect(data).to.match(/{{{yavu class3}}}/); | ||
expect(data).to.match(/{{{yavd class4}}}/); | ||
expect(data).to.match(/{{{yavs class5}}}/); | ||
expect(data).to.match(/{{{yavu class6}}}/); | ||
expect(data).to.match(/{{{yavu class7}}}/); | ||
var arr = [ | ||
// double quoted | ||
/{{{yavd class1}}}/, /{{{yavd class4}}}/, | ||
// single quoted | ||
/{{{yavs class2}}}/, /{{{yavs class5}}}/, | ||
// unquoted | ||
/{{{yavu class3}}}/, /{{{yavu class6}}}/, /{{{yavu class7}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -276,3 +219,6 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{yavu border}}}/); | ||
var arr = [ | ||
/{{{yavu border}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -283,11 +229,13 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{y arg1}}}/); | ||
expect(data).to.match(/{{{y arg2}}}/); | ||
expect(data).to.match(/{{{y arg3}}}/); | ||
expect(data).to.match(/{{{y arg4}}}/); | ||
expect(data).to.match(/{{{y arg5}}}/); | ||
expect(data).to.match(/{{{y arg6}}}/); | ||
expect(data).to.match(/{{{y arg7}}}/); | ||
expect(data).to.match(/{{{y arg8}}}/); | ||
expect(data).to.match(/{{{y arg9}}}/); | ||
var arr = [ | ||
// double quoted | ||
/{{{y arg1}}}/, /{{{y arg4}}}/, | ||
// single quoted | ||
/{{{y arg2}}}/, /{{{y arg5}}}/, | ||
// unquoted | ||
/{{{y arg3}}}/, /{{{y arg6}}}/, | ||
// double/single/unqouted line break | ||
/{{{y arg7}}}/, /{{{y arg8}}}/, /{{{y arg9}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -298,29 +246,11 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{y arg1}}}/); | ||
expect(data).to.match(/{{{y arg2}}}/); | ||
expect(data).to.match(/{{{y arg3}}}/); | ||
expect(data).to.match(/{{{y arg4}}}/); | ||
expect(data).to.match(/{{{y arg5}}}/); | ||
expect(data).to.match(/{{{y arg6}}}/); | ||
expect(data).to.match(/{{{y arg7}}}/); | ||
expect(data).to.match(/{{{y arg8}}}/); | ||
expect(data).to.match(/{{{y arg9}}}/); | ||
expect(data).to.match(/{{{y arg10}}}/); | ||
expect(data).to.match(/{{{y arg11}}}/); | ||
expect(data).to.match(/{{{y arg12}}}/); | ||
expect(data).to.match(/{{{y arg13}}}/); | ||
expect(data).to.match(/{{{y arg14}}}/); | ||
expect(data).to.match(/{{{y arg15}}}/); | ||
expect(data).to.match(/{{{y arg16}}}/); | ||
expect(data).to.match(/{{{y arg17}}}/); | ||
expect(data).to.match(/{{{y arg18}}}/); | ||
expect(data).to.match(/{{{y arg19}}}/); | ||
expect(data).to.match(/{{{y arg20}}}/); | ||
expect(data).to.match(/{{{y arg21}}}/); | ||
expect(data).to.match(/{{{y arg22}}}/); | ||
expect(data).to.match(/{{{y arg23}}}/); | ||
expect(data).to.match(/{{{y arg24}}}/); | ||
expect(data).to.match(/{{{y arg25}}}/); | ||
expect(data).to.match(/{{{y arg26}}}/); | ||
expect(data).to.match(/{{{y arg27}}}/); | ||
var arr = [ | ||
// double quoted with parameter unquoted | ||
/{{{y arg1}}}/, /{{{y arg2}}}/, /{{{y arg3}}}/, /{{{y arg4}}}/, /{{{y arg5}}}/, /{{{y arg6}}}/, /{{{y arg7}}}/, /{{{y arg8}}}/, /{{{y arg9}}}/, | ||
// single quoted with parameter unquoted | ||
/{{{y arg10}}}/, /{{{y arg11}}}/, /{{{y arg12}}}/, /{{{y arg13}}}/, /{{{y arg14}}}/, /{{{y arg15}}}/, /{{{y arg16}}}/, /{{{y arg17}}}/, /{{{y arg18}}}/, | ||
// unquoted with parameter unquoted | ||
/{{{y arg19}}}/, /{{{y arg20}}}/, /{{{y arg21}}}/, /{{{y arg22}}}/, /{{{y arg23}}}/, /{{{y arg24}}}/, /{{{y arg25}}}/, /{{{y arg26}}}/, /{{{y arg27}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -331,43 +261,35 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{y arg10}}}/); | ||
expect(data).to.match(/{{{y arg11}}}/); | ||
expect(data).to.match(/{{{y arg12}}}/); | ||
expect(data).to.match(/{{{y arg13}}}/); | ||
expect(data).to.match(/{{{y arg14}}}/); | ||
expect(data).to.match(/{{{y arg15}}}/); | ||
expect(data).to.match(/{{{y arg16}}}/); | ||
expect(data).to.match(/{{{y arg17}}}/); | ||
expect(data).to.match(/{{{y arg18}}}/); | ||
expect(data).to.match(/{{{y arg19}}}/); | ||
expect(data).to.match(/{{{y arg20}}}/); | ||
expect(data).to.match(/{{{y arg21}}}/); | ||
expect(data).to.match(/{{{y arg22}}}/); | ||
expect(data).to.match(/{{{y arg23}}}/); | ||
expect(data).to.match(/{{{y arg24}}}/); | ||
expect(data).to.match(/{{{y arg25}}}/); | ||
expect(data).to.match(/{{{y arg26}}}/); | ||
expect(data).to.match(/{{{y arg27}}}/); | ||
expect(data).to.match(/{{{y arg28}}}/); | ||
expect(data).to.match(/{{{y arg29}}}/); | ||
expect(data).to.match(/{{{y arg30}}}/); | ||
expect(data).to.match(/{{{y arg31}}}/); | ||
expect(data).to.match(/{{{y arg32}}}/); | ||
expect(data).to.match(/{{{y arg33}}}/); | ||
expect(data).to.match(/{{{y arg34}}}/); | ||
expect(data).to.match(/{{{y arg35}}}/); | ||
expect(data).to.match(/{{{y arg36}}}/); | ||
expect(data).to.match(/{{{y arg37}}}/); | ||
expect(data).to.match(/{{{y arg38}}}/); | ||
expect(data).to.match(/{{{y arg39}}}/); | ||
expect(data).to.match(/{{{y arg40}}}/); | ||
expect(data).to.match(/{{{y arg41}}}/); | ||
expect(data).to.match(/{{{y arg42}}}/); | ||
expect(data).to.match(/{{{y arg43}}}/); | ||
expect(data).to.match(/{{{y arg44}}}/); | ||
expect(data).to.match(/{{{y arg45}}}/); | ||
var arr = [ | ||
// double quoted with parameter unquoted | ||
/{{{y arg10}}}/, /{{{y arg11}}}/, /{{{y arg12}}}/, | ||
// single quoted with parameter unquoted | ||
/{{{y arg13}}}/, /{{{y arg14}}}/, /{{{y arg15}}}/, | ||
// double quoted with parameter unquoted (with space) | ||
/{{{y arg16}}}/, /{{{y arg17}}}/, | ||
// single quoted with parameter unquoted (with space) | ||
/{{{y arg18}}}/, /{{{y arg19}}}/, | ||
// double quoted with parameter quoted | ||
/{{{y arg20}}}/, /{{{y arg21}}}/, /{{{y arg22}}}/, | ||
// single quoted with parameter quoted | ||
/{{{y arg23}}}/, /{{{y arg24}}}/, /{{{y arg25}}}/, | ||
// double quoted with parameter quoted (with space) | ||
/{{{y arg26}}}/, /{{{y arg27}}}/, | ||
// single quoted with parameter quoted (with space) | ||
/{{{y arg28}}}/, /{{{y arg29}}}/, | ||
// double quoted with parameter slash quoted | ||
/{{{y arg30}}}/, /{{{y arg31}}}/, /{{{y arg32}}}/, | ||
// single quoted with parameter slash quoted | ||
/{{{y arg33}}}/, /{{{y arg34}}}/, /{{{y arg35}}}/, | ||
// double quoted with parameter slash quoted (with space) | ||
/{{{y arg36}}}/, /{{{y arg37}}}/, | ||
// single quoted with parameter slash quoted (with space) | ||
/{{{y arg38}}}/, /{{{y arg39}}}/, | ||
// double quoted | ||
/{{{y arg40}}}/, /{{{y arg43}}}/, | ||
// single quoted | ||
/{{{y arg41}}}/, /{{{y arg44}}}/, | ||
// unquoted | ||
/{{{y arg42}}}/, /{{{y arg45}}}/, | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -378,15 +300,13 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{y arg10}}}/); | ||
expect(data).to.match(/{{{y arg11}}}/); | ||
expect(data).to.match(/{{{y arg12}}}/); | ||
expect(data).to.match(/{{{y arg13}}}/); | ||
expect(data).to.match(/{{{y arg14}}}/); | ||
expect(data).to.match(/{{{y arg20}}}/); | ||
expect(data).to.match(/{{{y arg21}}}/); | ||
expect(data).to.match(/{{{y arg22}}}/); | ||
expect(data).to.match(/{{{y arg23}}}/); | ||
expect(data).to.match(/{{{y arg24}}}/); | ||
expect(data).to.match(/{{{y arg25}}}/); | ||
expect(data).to.match(/{{{y arg26}}}/); | ||
var arr = [ | ||
// unquoted with parameter unquoted | ||
/{{{y arg10}}}/, /{{{y arg11}}}/, /{{{y arg12}}}/, /{{{y arg13}}}/, /{{{y arg14}}}/, | ||
// unquoted with parameter single / double quoted | ||
/{{{y arg20}}}/, /{{{y arg21}}}/, /{{{y arg22}}}/, | ||
// unquoted with parameter single quoted | ||
/{{{y arg23}}}/, /{{{y arg24}}}/, | ||
// unquoted with parameter double quoted | ||
/{{{y arg25}}}/, /{{{y arg26}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -397,5 +317,11 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{y value1}}}/); | ||
expect(data).to.match(/{{{y value2}}}/); | ||
expect(data).to.match(/{{{y value3}}}/); | ||
var arr = [ | ||
// double quoted | ||
/{{{y value1}}}/, | ||
// single quoted | ||
/{{{y value2}}}/, | ||
// unquoted | ||
/{{{y value3}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -406,3 +332,6 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{y fontsize}}}/); | ||
var arr = [ | ||
/{{{y fontsize}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -413,77 +342,59 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{y arg10}}}/); | ||
expect(data).to.match(/{{{y arg11}}}/); | ||
expect(data).to.match(/{{{y arg12}}}/); | ||
expect(data).to.match(/{{{y arg13}}}/); | ||
expect(data).to.match(/{{{y arg14}}}/); | ||
expect(data).to.match(/{{{y arg15}}}/); | ||
expect(data).to.match(/{{{y arg16}}}/); | ||
expect(data).to.match(/{{{y arg17}}}/); | ||
expect(data).to.match(/{{{y arg18}}}/); | ||
expect(data).to.match(/{{{y arg19}}}/); | ||
expect(data).to.match(/{{{y arg20}}}/); | ||
expect(data).to.match(/{{{y arg21}}}/); | ||
expect(data).to.match(/{{{y arg22}}}/); | ||
expect(data).to.match(/{{{y arg23}}}/); | ||
expect(data).to.match(/{{{y arg24}}}/); | ||
expect(data).to.match(/{{{y arg25}}}/); | ||
expect(data).to.match(/{{{y arg26}}}/); | ||
expect(data).to.match(/{{{y arg27}}}/); | ||
expect(data).to.match(/{{{y arg28}}}/); | ||
expect(data).to.match(/{{{y arg29}}}/); | ||
expect(data).to.match(/{{{y arg30}}}/); | ||
expect(data).to.match(/{{{y arg31}}}/); | ||
expect(data).to.match(/{{{y arg32}}}/); | ||
expect(data).to.match(/{{{y arg33}}}/); | ||
expect(data).to.match(/{{{y arg34}}}/); | ||
expect(data).to.match(/{{{y arg35}}}/); | ||
expect(data).to.match(/{{{y arg36}}}/); | ||
expect(data).to.match(/{{{y arg37}}}/); | ||
expect(data).to.match(/{{{y arg38}}}/); | ||
expect(data).to.match(/{{{y arg39}}}/); | ||
expect(data).to.match(/{{{y vbarg10}}}/); | ||
expect(data).to.match(/{{{y vbarg11}}}/); | ||
expect(data).to.match(/{{{y vbarg12}}}/); | ||
expect(data).to.match(/{{{y vbarg13}}}/); | ||
expect(data).to.match(/{{{y vbarg14}}}/); | ||
expect(data).to.match(/{{{y vbarg15}}}/); | ||
expect(data).to.match(/{{{y vbarg16}}}/); | ||
expect(data).to.match(/{{{y vbarg17}}}/); | ||
expect(data).to.match(/{{{y vbarg18}}}/); | ||
expect(data).to.match(/{{{y vbarg19}}}/); | ||
expect(data).to.match(/{{{y vbarg20}}}/); | ||
expect(data).to.match(/{{{y vbarg21}}}/); | ||
expect(data).to.match(/{{{y vbarg22}}}/); | ||
expect(data).to.match(/{{{y vbarg23}}}/); | ||
expect(data).to.match(/{{{y vbarg24}}}/); | ||
expect(data).to.match(/{{{y vbarg25}}}/); | ||
expect(data).to.match(/{{{y vbarg26}}}/); | ||
expect(data).to.match(/{{{y vbarg27}}}/); | ||
expect(data).to.match(/{{{y vbarg28}}}/); | ||
expect(data).to.match(/{{{y vbarg29}}}/); | ||
expect(data).to.match(/{{{y vbarg30}}}/); | ||
expect(data).to.match(/{{{y vbarg31}}}/); | ||
expect(data).to.match(/{{{y vbarg32}}}/); | ||
expect(data).to.match(/{{{y vbarg33}}}/); | ||
expect(data).to.match(/{{{y vbarg34}}}/); | ||
expect(data).to.match(/{{{y vbarg35}}}/); | ||
expect(data).to.match(/{{{y vbarg36}}}/); | ||
expect(data).to.match(/{{{y vbarg37}}}/); | ||
expect(data).to.match(/{{{y vbarg38}}}/); | ||
expect(data).to.match(/{{{y vbarg39}}}/); | ||
expect(data).to.match(/{{{yubl \(yavd \(yufull arg40\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavs \(yufull arg41\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavu \(yufull arg42\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavd \(yufull arg43\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavs \(yufull arg44\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavu \(yufull arg45\)\)}}}/); | ||
var arr = [ | ||
// double quoted with parameter unquoted | ||
/{{{y arg10}}}/, /{{{y arg11}}}/, /{{{y arg12}}}/, | ||
// single quoted with parameter unquoted | ||
/{{{y arg13}}}/, /{{{y arg14}}}/, /{{{y arg15}}}/, | ||
// double quoted with parameter unquoted (with space) | ||
/{{{y arg16}}}/, /{{{y arg17}}}/, | ||
// single quoted with parameter unquoted (with space) | ||
/{{{y arg18}}}/, /{{{y arg19}}}/, | ||
// double quoted with parameter quoted | ||
/{{{y arg20}}}/, /{{{y arg21}}}/, /{{{y arg22}}}/, | ||
// single quoted with parameter quoted | ||
/{{{y arg23}}}/, /{{{y arg24}}}/, /{{{y arg25}}}/, | ||
// double quoted with parameter quoted (with space) | ||
/{{{y arg26}}}/, /{{{y arg27}}}/, | ||
// single quoted with parameter quoted (with space) | ||
/{{{y arg28}}}/, /{{{y arg29}}}/, | ||
// double quoted with parameter slash quoted | ||
/{{{y arg30}}}/, /{{{y arg31}}}/, /{{{y arg32}}}/, | ||
// single quoted with parameter slash quoted | ||
/{{{y arg33}}}/, /{{{y arg34}}}/, /{{{y arg35}}}/, | ||
// double quoted with parameter slash quoted (with space) | ||
/{{{y arg36}}}/, /{{{y arg37}}}/, | ||
// single quoted with parameter slash quoted (with space) | ||
/{{{y arg38}}}/, /{{{y arg39}}}/, | ||
// double quoted with parameter unquoted | ||
/{{{y vbarg10}}}/, /{{{y vbarg11}}}/, /{{{y vbarg12}}}/, | ||
// single quoted with parameter unquoted | ||
/{{{y vbarg13}}}/, /{{{y vbarg14}}}/, /{{{y vbarg15}}}/, | ||
// double quoted with parameter unquoted (with space) | ||
/{{{y vbarg16}}}/, /{{{y vbarg17}}}/, | ||
// single quoted with parameter unquoted (with space) | ||
/{{{y vbarg18}}}/, /{{{y vbarg19}}}/, | ||
// double quoted with parameter quoted | ||
/{{{y vbarg20}}}/, /{{{y vbarg21}}}/, /{{{y vbarg22}}}/, | ||
// single quoted with parameter quoted | ||
/{{{y vbarg23}}}/, /{{{y vbarg24}}}/, /{{{y vbarg25}}}/, | ||
// double quoted with parameter quoted (with space) | ||
/{{{y vbarg26}}}/, /{{{y vbarg27}}}/, | ||
// single quoted with parameter quoted (with space) | ||
/{{{y vbarg28}}}/, /{{{y vbarg29}}}/, | ||
// double quoted with parameter slash quoted | ||
/{{{y vbarg30}}}/, /{{{y vbarg31}}}/, /{{{y vbarg32}}}/, | ||
// single quoted with parameter slash quoted | ||
/{{{y vbarg33}}}/, /{{{y vbarg34}}}/, /{{{y vbarg35}}}/, | ||
// double quoted with parameter slash quoted (with space) | ||
/{{{y vbarg36}}}/, /{{{y vbarg37}}}/, | ||
// single quoted with parameter slash quoted (with space) | ||
/{{{y vbarg38}}}/, /{{{y vbarg39}}}/, | ||
// double quoted | ||
/{{{yubl \(yavd \(yufull arg40\)\)}}}/, /{{{yubl \(yavd \(yufull arg43\)\)}}}/, | ||
// single quoted | ||
/{{{yubl \(yavs \(yufull arg41\)\)}}}/, /{{{yubl \(yavs \(yufull arg44\)\)}}}/, | ||
// unquoted | ||
/{{{yubl \(yavu \(yufull arg42\)\)}}}/, /{{{yubl \(yavu \(yufull arg45\)\)}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -494,29 +405,13 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{y arg10}}}/); | ||
expect(data).to.match(/{{{y arg11}}}/); | ||
expect(data).to.match(/{{{y arg12}}}/); | ||
expect(data).to.match(/{{{y arg13}}}/); | ||
expect(data).to.match(/{{{y arg14}}}/); | ||
expect(data).to.match(/{{{y arg20}}}/); | ||
expect(data).to.match(/{{{y arg21}}}/); | ||
expect(data).to.match(/{{{y arg22}}}/); | ||
expect(data).to.match(/{{{y arg23}}}/); | ||
expect(data).to.match(/{{{y arg24}}}/); | ||
expect(data).to.match(/{{{y arg25}}}/); | ||
expect(data).to.match(/{{{y arg26}}}/); | ||
expect(data).to.match(/{{{y vbarg10}}}/); | ||
expect(data).to.match(/{{{y vbarg11}}}/); | ||
expect(data).to.match(/{{{y vbarg12}}}/); | ||
expect(data).to.match(/{{{y vbarg13}}}/); | ||
expect(data).to.match(/{{{y vbarg14}}}/); | ||
expect(data).to.match(/{{{y vbarg20}}}/); | ||
expect(data).to.match(/{{{y vbarg21}}}/); | ||
expect(data).to.match(/{{{y vbarg22}}}/); | ||
expect(data).to.match(/{{{y vbarg23}}}/); | ||
expect(data).to.match(/{{{y vbarg24}}}/); | ||
expect(data).to.match(/{{{y vbarg25}}}/); | ||
expect(data).to.match(/{{{y vbarg26}}}/); | ||
var arr = [ | ||
// unquoted with parameter unquoted | ||
/{{{y arg10}}}/, /{{{y arg11}}}/, /{{{y arg12}}}/, /{{{y arg13}}}/, /{{{y arg14}}}/, | ||
// unquoted with parameter double / single unquoted | ||
/{{{y arg20}}}/, /{{{y arg21}}}/, /{{{y arg22}}}/, /{{{y arg23}}}/, /{{{y arg24}}}/, /{{{y arg25}}}/, /{{{y arg26}}}/, | ||
// unquoted with parameter unquoted (vbscript) | ||
/{{{y vbarg10}}}/, /{{{y vbarg11}}}/, /{{{y vbarg12}}}/, /{{{y vbarg13}}}/, /{{{y vbarg14}}}/, | ||
// unquoted with parameter double / single unquoted (vbscript) | ||
/{{{y vbarg20}}}/, /{{{y vbarg21}}}/, /{{{y vbarg22}}}/, /{{{y vbarg23}}}/, /{{{y vbarg24}}}/, /{{{y vbarg25}}}/, /{{{y vbarg26}}}/, | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -527,3 +422,6 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{yd title}}}/); | ||
var arr = [ | ||
/{{{yd title}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -536,3 +434,6 @@ | ||
var output = t1.getBuffer().join(''); | ||
expect(output).to.match(/{{{yd title}}}/); | ||
var arr = [ | ||
/{{{yd title}}}/ | ||
]; | ||
utils.testArrMatch(output, arr); | ||
@@ -543,6 +444,8 @@ var t2 = new ContextParserHandlebars(false); | ||
var output = t2.getBuffer().join(''); | ||
expect(output).to.match(/{{{yubl \(yavs \(yufull url\)\)}}}/); | ||
var arr = [ | ||
/{{{yubl \(yavs \(yufull url\)\)}}}/ | ||
]; | ||
utils.testArrMatch(output, arr); | ||
}); | ||
}); | ||
}()); |
@@ -12,8 +12,85 @@ /* | ||
var mocha = require("mocha"), | ||
expect = require('expect.js'), | ||
mocha = require("mocha"); | ||
var expect = require('chai').expect, | ||
handlebars = require('handlebars'); | ||
describe("Vanillia Handlebars parsing test suite", function() { | ||
describe("Vanilla Handlebars parsing test suite", function() { | ||
it("handlebars {{expression}} test", function() { | ||
[ | ||
'{{expression}}', | ||
'{{expression}} }', | ||
].forEach(function(t) { | ||
var ast = handlebars.parse(t); | ||
expect(ast.statements[0].type).to.equal('mustache'); | ||
}); | ||
[ | ||
'{ {expression}}', | ||
].forEach(function(t) { | ||
var ast = handlebars.parse(t); | ||
expect(ast.statements[0].type).to.equal('content'); | ||
}); | ||
}); | ||
it("handlebars {{expression}} subexpression with \r\n test", function() { | ||
[ | ||
'{{expression\rion}}', | ||
'{{expression\nion}}', | ||
'{{expression\r\nion}}', | ||
].forEach(function(t) { | ||
var ast = handlebars.parse(t); | ||
expect(ast.statements[0].type).to.equal('mustache'); | ||
expect(ast.statements[0].params[0].string).to.equal('ion'); | ||
expect(ast.statements[0].isHelper).to.equal(true); | ||
}); | ||
}); | ||
it("handlebars invalid {{expression}} test", function() { | ||
[ | ||
'{ {anything}}', | ||
'{{anything}', '{{anything} }', '{{anything}}}', | ||
'{{ {anything}}', '{{ }anything}}', | ||
'{{}}' | ||
].forEach(function(e) { | ||
try { | ||
var ast = handlebars.parse(e); | ||
expect(false).to.equal(true); | ||
} catch (err) { | ||
expect(true).to.equal(true); | ||
} | ||
}); | ||
}); | ||
it("handlebars {{{raw expression}}} test", function() { | ||
[ | ||
'{{{expression}}}', | ||
'{{{expression}}} }', | ||
].forEach(function(t) { | ||
var ast = handlebars.parse(t); | ||
expect(ast.statements[0].type).to.equal('mustache'); | ||
}); | ||
[ | ||
'{ { {expression}}}', | ||
].forEach(function(t) { | ||
var ast = handlebars.parse(t); | ||
expect(ast.statements[0].type).to.equal('content'); | ||
}); | ||
}); | ||
it("handlebars invalid {{{raw expression}}} test", function() { | ||
[ | ||
'{ {{anything}}}', '{{ {anything}}}', | ||
'{{{anything}', '{{{anything}}', '{{{anything}}}}', | ||
'{{{ {anything}}}', '{{{ }anything}}}', | ||
'{{{}}}' | ||
].forEach(function(e) { | ||
try { | ||
var ast = handlebars.parse(e); | ||
expect(false).to.equal(true); | ||
} catch (err) { | ||
expect(true).to.equal(true); | ||
} | ||
}); | ||
}); | ||
it("handlebars {{#if}} {{!-- comment --}} {{/if}} parsing test", function() { | ||
@@ -115,2 +192,8 @@ var t = '{{#if}}xxx{{!-- comment --}}yyy{{/if}}'; | ||
t = '{{# if }}xxx{{ else }}yyy{{/ if}}'; | ||
ast = handlebars.parse(t); | ||
expect(ast.statements[0].mustache.id.string).to.equal('if'); | ||
expect(ast.statements[0].program.statements[0].string).to.equal('xxx'); | ||
expect(ast.statements[0].inverse.statements[0].string).to.equal('yyy'); | ||
t = '{{ # if}}xxx{{else}}yyy{{ / if}}'; | ||
@@ -117,0 +200,0 @@ try { |
@@ -13,3 +13,3 @@ /* | ||
require("mocha"); | ||
var assert = require("assert"), | ||
var expect = require("chai").expect, | ||
Parser = require("context-parser").Parser; | ||
@@ -32,3 +32,3 @@ | ||
var states = p1.getStates(); | ||
assert.equal(states.toString(), '1,8,10,10,10,34,35,35,37,38,38,42,34,35'); | ||
expect(states.toString()).to.equal('1,8,10,10,10,34,35,35,37,38,38,42,34,35'); | ||
}); | ||
@@ -49,3 +49,3 @@ | ||
var states = p1.getStates(); | ||
assert.equal(states.toString(), '1,8,10,10,10,10,10,10,34,35,35,35,35,35,37,38,38,42,34,35,35,35,35,35,35,35,35,36,35'); | ||
expect(states.toString()).to.equal('1,8,10,10,10,10,10,10,34,35,35,35,35,35,37,38,38,42,34,35,35,35,35,35,35,35,35,36,35'); | ||
}); | ||
@@ -66,3 +66,3 @@ | ||
var states = p1.getStates(); | ||
assert.equal(states.toString(), '1,8,10,10,10,10,10,10,34,35,35,35,35,35,37,40'); | ||
expect(states.toString()).to.equal('1,8,10,10,10,10,10,10,34,35,35,35,35,35,37,40'); | ||
}); | ||
@@ -83,3 +83,3 @@ | ||
var states = p1.getStates(); | ||
assert.equal(states.toString(), '1,8,10,10,10,10,10,10,34,35,35,35,35,35,37,38,38'); | ||
expect(states.toString()).to.equal('1,8,10,10,10,10,10,10,34,35,35,35,35,35,37,38,38'); | ||
}); | ||
@@ -100,3 +100,3 @@ | ||
var states = p1.getStates(); | ||
assert.equal(states.toString(), '1,8,10,10,10,10,10,10,34,35,35,35,35,35,37,39,39'); | ||
expect(states.toString()).to.equal('1,8,10,10,10,10,10,10,34,35,35,35,35,35,37,39,39'); | ||
}); | ||
@@ -118,3 +118,3 @@ | ||
var states = p1.getStates(); | ||
assert.equal(states.toString(), '1,8,10,10,10,34,35,35,37,38,38,34,35'); | ||
expect(states.toString()).to.equal('1,8,10,10,10,34,35,35,37,38,38,34,35'); | ||
}); | ||
@@ -121,0 +121,0 @@ |
@@ -12,5 +12,6 @@ /* | ||
var mocha = require("mocha"), | ||
fs = require('fs'), | ||
expect = require('expect.js'); | ||
require("mocha"); | ||
var fs = require('fs'), | ||
utils = require('../utils.js'), | ||
expect = require('chai').expect; | ||
@@ -22,3 +23,6 @@ describe("Handlebars Context Parser template test suite", function() { | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{yd name}}}/); | ||
var arr = [ | ||
/{{{yd name}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -29,3 +33,6 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{name}}}/); | ||
var arr = [ | ||
/{{{name}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -36,3 +43,6 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{#list people}}{{{yd firstName}}} {{{yd lastName}}}{{\/list}}/); | ||
var arr = [ | ||
/{{#list people}}{{{yd firstName}}} {{{yd lastName}}}{{\/list}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -43,3 +53,6 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{yd name}}}/); | ||
var arr = [ | ||
/{{{yd name}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -50,3 +63,6 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{ {name}}/); | ||
var arr = [ | ||
/{ {name}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -57,6 +73,9 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{#with story}}/); | ||
expect(data).to.match(/<div class="intro">{{{yd intro}}}<\/div>/); | ||
expect(data).to.match(/<div class="body">{{{yd body}}}<\/div>/); | ||
expect(data).to.match(/{{\/with}}/); | ||
var arr = [ | ||
/{{#with story}}/, | ||
/<div class="intro">{{{yd intro}}}<\/div>/, | ||
/<div class="body">{{{yd body}}}<\/div>/, | ||
/{{\/with}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -67,6 +86,9 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{# with story}}/); | ||
expect(data).to.match(/<div class="intro">{{{yd intro}}}<\/div>/); | ||
expect(data).to.match(/<div class="body">{{{yd body}}}<\/div>/); | ||
expect(data).to.match(/{{\/with}}/); | ||
var arr = [ | ||
/{{# with story}}/, | ||
/<div class="intro">{{{yd intro}}}<\/div>/, | ||
/<div class="body">{{{yd body}}}<\/div>/, | ||
/{{\/with}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -77,5 +99,8 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{!-- comment1 --}}/); | ||
expect(data).to.match(/{{!-- comment2 }}/); | ||
expect(data).to.match(/{{! comment3 }}/); | ||
var arr = [ | ||
/{{!-- comment1 --}}/, | ||
/{{!-- comment2 }}/, | ||
/{{! comment3 }}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -86,6 +111,9 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{>html_header}}/); | ||
expect(data).to.match(/{{>header}}/); | ||
expect(data).to.match(/{{>footer}}/); | ||
expect(data).to.match(/{{>html_footer}}/); | ||
var arr = [ | ||
/{{>html_header}}/, | ||
/{{>header}}/, | ||
/{{>footer}}/, | ||
/{{>html_footer}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -96,4 +124,7 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{yd \(outer-helper1 \(inner-helper1 'abc'\) 'def'\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavd \(yufull \(outer-helper2 \(inner-helper2 'abc'\) 'def'\)\)\)}}}/); | ||
var arr = [ | ||
/{{{yd \(outer-helper1 \(inner-helper1 'abc'\) 'def'\)}}}/, | ||
/{{{yubl \(yavd \(yufull \(outer-helper2 \(inner-helper2 'abc'\) 'def'\)\)\)}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -122,3 +153,6 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{else}}/); | ||
var arr = [ | ||
/{{else}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
expect(data).to.not.match(/{{{else}}}/); | ||
@@ -130,6 +164,9 @@ }); | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{yavd classname}}}/); | ||
expect(data).to.match(/{{{yavd index_active}}}/); | ||
expect(data).to.match(/{{{yavd safejstemplating_active1}}}/); | ||
expect(data).to.match(/{{{y safejstemplating_active2}}}/); | ||
var arr = [ | ||
/{{{yavd classname}}}/, | ||
/{{{yavd index_active}}}/, | ||
/{{{yavd safejstemplating_active1}}}/, | ||
/{{{y safejstemplating_active2}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -140,19 +177,15 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{yd html}}/); | ||
expect(data).to.match(/{{{yavu SELECTED1}}}/); | ||
expect(data).to.match(/{{{yavu SELECTED21}}}/); | ||
expect(data).to.match(/{{{yavu SELECTED22}}}/); | ||
expect(data).to.match(/{{{yavd SELECTED3}}}/); | ||
expect(data).to.match(/{{{yavd SELECTED4}}}/); | ||
expect(data).to.match(/{{{yd NAME1}}}/); | ||
expect(data).to.match(/{{{yd NAME2}}}/); | ||
expect(data).to.match(/{{{yd NAME3}}}/); | ||
expect(data).to.match(/{{{yd NAME4}}}/); | ||
expect(data).to.match(/{{{yubl \(yavd \(yufull URL1\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavd \(yufull URL2\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavu \(yufull URL3\)\)}}}/); | ||
expect(data).to.match(/{{{yubl \(yavu \(yufull URL4\)\)}}}/); | ||
expect(data).to.match(/{{{yc COMMENT1}}}/); | ||
expect(data).to.match(/{{{yc COMMENT2}}}/); | ||
expect(data).to.match(/{{{y ATTR1}}}/); | ||
var arr = [ | ||
/{{{yd html}}}/, | ||
/{{{yavu SELECTED1}}}/, | ||
/{{{yavu SELECTED21}}}/, | ||
/{{{yavu SELECTED22}}}/, | ||
/{{{yavd SELECTED3}}}/, | ||
/{{{yavd SELECTED4}}}/, | ||
/{{{yd NAME1}}}/, /{{{yd NAME2}}}/, /{{{yd NAME3}}}/, /{{{yd NAME4}}}/, | ||
/{{{yubl \(yavd \(yufull URL1\)\)}}}/, /{{{yubl \(yavd \(yufull URL2\)\)}}}/, /{{{yubl \(yavu \(yufull URL3\)\)}}}/, /{{{yubl \(yavu \(yufull URL4\)\)}}}/, | ||
/{{{yc COMMENT1}}}/, /{{{yc COMMENT2}}}/, | ||
/{{{y ATTR1}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -164,2 +197,6 @@ | ||
expect(data).to.match(/{{{yd placeholder3}}}/); | ||
var arr = [ | ||
/{{{yd placeholder3}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -170,5 +207,8 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{yd placeholder1}}}/); | ||
expect(data).to.match(/{{{yd placeholder2}}}/); | ||
expect(data).to.match(/{{{yd placeholder3}}}/); | ||
var arr = [ | ||
/{{{yd placeholder1}}}/, | ||
/{{{yd placeholder2}}}/, | ||
/{{{yd placeholder3}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -179,5 +219,8 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{placeholder1}}}/); | ||
expect(data).to.match(/{{{placeholder2}}}/); | ||
expect(data).to.match(/{{{yd placeholder3}}}/); | ||
var arr = [ | ||
/{{{placeholder1}}}/, | ||
/{{{placeholder2}}}/, | ||
/{{{yd placeholder3}}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -188,26 +231,15 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{yavd valueA}}}/); | ||
expect(data).to.match(/{{{yd firstName11}}}/); | ||
expect(data).to.match(/{{{yd lastName12}}}/); | ||
expect(data).to.match(/{{{yd placeholderA}}}/); | ||
expect(data).to.match(/{{{yavd valueB}}}/); | ||
expect(data).to.match(/{{{yd firstName21}}}/); | ||
expect(data).to.match(/{{{yd lastName22}}}/); | ||
expect(data).to.match(/{{{yd placeholderB}}}/); | ||
expect(data).to.match(/{{{yavd valueC}}}/); | ||
expect(data).to.match(/{{{yd firstName31}}}/); | ||
expect(data).to.match(/{{{yd lastName32}}}/); | ||
expect(data).to.match(/{{{yd placeholderC}}}/); | ||
expect(data).to.match(/{{{yavd valueD}}}/); | ||
expect(data).to.match(/{{{yd firstName41}}}/); | ||
expect(data).to.match(/{{{yd lastName42}}}/); | ||
expect(data).to.match(/{{{yd placeholderD}}}/); | ||
expect(data).to.match(/{{{yavd valueE}}}/); | ||
expect(data).to.match(/{{{yd firstName51}}}/); | ||
expect(data).to.match(/{{{yd lastName52}}}/); | ||
expect(data).to.match(/{{{yd placeholderE}}}/); | ||
var arr = [ | ||
// {{{#list}} | ||
/{{{yavd valueA}}}/, /{{{yd firstName11}}}/, /{{{yd lastName12}}}/, /{{{yd placeholderA}}}/, | ||
// {{{#each}} | ||
/{{{yavd valueB}}}/, /{{{yd firstName21}}}/, /{{{yd lastName22}}}/, /{{{yd placeholderB}}}/, | ||
// {{{#with}} | ||
/{{{yavd valueC}}}/, /{{{yd firstName31}}}/, /{{{yd lastName32}}}/, /{{{yd placeholderC}}}/, | ||
// {{{#tag}} | ||
/{{{yavd valueD}}}/, /{{{yd firstName41}}}/, /{{{yd lastName42}}}/, /{{{yd placeholderD}}}/, | ||
// {{{#unless}} | ||
/{{{yavd valueE}}}/, /{{{yd firstName51}}}/, /{{{yd lastName52}}}/, /{{{yd placeholderE}}}/, | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -218,6 +250,9 @@ | ||
var data = fs.readFileSync(file, 'utf-8'); | ||
expect(data).to.match(/{{{yavd nomsg}}}/); | ||
expect(data).to.match(/{{{yd name}}}/); | ||
expect(data).to.match(/{{\^msg}}/); | ||
expect(data).to.match(/{{\/msg}}/); | ||
var arr = [ | ||
/{{{yavd nomsg}}}/, | ||
/{{{yd name}}}/, | ||
/{{\^msg}}/, | ||
/{{\/msg}}/ | ||
]; | ||
utils.testArrMatch(data, arr); | ||
}); | ||
@@ -224,0 +259,0 @@ |
@@ -12,713 +12,516 @@ /* | ||
var mocha = require("mocha"), | ||
fs = require('fs'), | ||
expect = require('expect.js'), | ||
util = require("../../src/handlebars-utils.js"); | ||
require("mocha"); | ||
var expect = require('chai').expect, | ||
utils = require("../utils.js"), | ||
handlebarsUtils = require("../../src/handlebars-utils.js"), | ||
ContextParserHandlebars = require("../../src/context-parser-handlebars.js"); | ||
describe("handlebars-utils test suite", function() { | ||
describe("handlebars-handlebarsUtilss test suite", function() { | ||
it("handlebars-utils#_getExpressionExtraInfo {{else}} test", function() { | ||
var ContextParserHandlebars = require("../../src/context-parser-handlebars.js"); | ||
var parser = new ContextParserHandlebars(); | ||
it("handlebars-handlebarsUtilss#generateNonce test", function() { | ||
var n1 = handlebarsUtils.generateNonce(); | ||
var n2 = handlebarsUtils.generateNonce(); | ||
expect(n1).not.to.equal(n2); | ||
}); | ||
var str = '{else}}'; | ||
var r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal(''); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
it("handlebars-handlebarsUtilss#_parseExpression invalid format test", function() { | ||
}); | ||
str = '{else }}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal(''); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
it("handlebars-handlebarsUtilss#_parseExpression {{else}} test", function() { | ||
var parser = new ContextParserHandlebars(); | ||
str = '{ else }}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal(''); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
var arr = [ | ||
// test for {{else}} | ||
{str:'{else}}', isPrefixWithKnownFilter:true, filter:'', isSingleIdentifier:false}, | ||
// test for {{else}} with space after else | ||
{str:'{else }}', isPrefixWithKnownFilter:true, filter:'', isSingleIdentifier:false}, | ||
// test for {{else}} with space before/after else | ||
{str:'{ else }}', isPrefixWithKnownFilter:true, filter:'', isSingleIdentifier:false}, | ||
// test for {{else}} with space before/after else | ||
// {str:'{{else}}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:false} | ||
]; | ||
arr.forEach(function(obj) { | ||
var r = parser._parseExpression(obj.str, 0); | ||
utils.testExpression(r, obj); | ||
}); | ||
}); | ||
it("handlebars-utils#_getExpressionExtraInfo output markup test", function() { | ||
var ContextParserHandlebars = require("../../src/context-parser-handlebars.js"); | ||
it("handlebars-handlebarsUtilss#_parseExpression basic test", function() { | ||
var parser = new ContextParserHandlebars(); | ||
var str = '{y}}'; | ||
var r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal(''); | ||
expect(r.isSingleIdentifier).to.equal(true); | ||
var arr = [ | ||
// test for single identifier with the same name as known filter {y}} | ||
{str:'{y}}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:true}, | ||
{str:'{y }}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:true}, | ||
{str:'{ y }}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:true}, | ||
str = '{h}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal(''); | ||
expect(r.isSingleIdentifier).to.equal(true); | ||
str = '{people.name}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal(''); | ||
expect(r.isSingleIdentifier).to.equal(true); | ||
str = '{../name}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal(''); | ||
expect(r.isSingleIdentifier).to.equal(true); | ||
str = '{article/title}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal(''); | ||
expect(r.isSingleIdentifier).to.equal(true); | ||
str = '{article[0]}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal(''); | ||
expect(r.isSingleIdentifier).to.equal(true); | ||
str = '{articles.[10].[#comments]}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal(''); | ||
expect(r.isSingleIdentifier).to.equal(true); | ||
str = '{y }}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal(''); | ||
expect(r.isSingleIdentifier).to.equal(true); | ||
str = '{ y }}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal(''); | ||
expect(r.isSingleIdentifier).to.equal(true); | ||
// test for single identifier with the same name as known default filter {h}} | ||
{str:'{h}}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:true}, | ||
// test for single identifier with dot notation | ||
{str:'{people.name}}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:true}, | ||
// test for single identifier with ../ | ||
{str:'{../name}}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:true}, | ||
// test for single identifier with / | ||
{str:'{article/name}}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:true}, | ||
// test for single identifier with [] | ||
{str:'{article[0]}}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:true}, | ||
// test for single identifier with [] | ||
{str:'{article.[0].[#comments]}}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:true}, | ||
// test for expression with \r and \n as separator | ||
{str:'{y\rparam}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
{str:'{y\nparam}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
{str:'{y\r\nparam}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
]; | ||
arr.forEach(function(obj) { | ||
var r = parser._parseExpression(obj.str, 0); | ||
utils.testExpression(r, obj); | ||
}); | ||
}); | ||
it("handlebars-utils#_getExpressionExtraInfo test", function() { | ||
var ContextParserHandlebars = require("../../src/context-parser-handlebars.js"); | ||
it("handlebars-handlebarsUtilss#_parseExpression test", function() { | ||
var parser = new ContextParserHandlebars(); | ||
var str = '{y output}}'; | ||
var r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
var arr = [ | ||
// test for expression with the same name as known filter {y}} | ||
{str:'{y output}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
{str:'{y output}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
{str:'{ y output}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
// test for expression with the same name as default filter {h}} | ||
{str:'{h output}}', isPrefixWithKnownFilter:false, filter:'h', isSingleIdentifier:false}, | ||
{str:'{h output}}', isPrefixWithKnownFilter:false, filter:'h', isSingleIdentifier:false}, | ||
{str:'{ h output}}', isPrefixWithKnownFilter:false, filter:'h', isSingleIdentifier:false}, | ||
str = '{h output}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal('h'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
// test for expression with dot notation filter | ||
{str:'{people.name output}}', isPrefixWithKnownFilter:false, filter:'people.name', isSingleIdentifier:false}, | ||
// test for expression with ../ filter | ||
{str:'{../name output}}', isPrefixWithKnownFilter:false, filter:'../name', isSingleIdentifier:false}, | ||
str = '{people.name output}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal('people.name'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
// test for expression with the same name as known filter {y}} and parameter in dot notation | ||
{str:'{y people.name}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
{str:'{y people.name}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
{str:'{ y people.name}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
str = '{../name output}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal('../name'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = '{y output}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = '{h output}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal('h'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = '{ y output}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = '{ h output}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal('h'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = '{y ../output}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = '{y ../output}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = '{ y ../output}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
// test for expression with the same name as known filter {y}} and parameter with ../ | ||
{str:'{y ../output}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
{str:'{y ../output}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
{str:'{ y ../output}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
]; | ||
arr.forEach(function(obj) { | ||
var r = parser._parseExpression(obj.str, 0); | ||
utils.testExpression(r, obj); | ||
}); | ||
}); | ||
it("handlebars-utils#_getExpressionExtraInfo 2 arguments test", function() { | ||
var ContextParserHandlebars = require("../../src/context-parser-handlebars.js"); | ||
it("handlebars-handlebarsUtilss#_parseExpression 2 arguments test", function() { | ||
var parser = new ContextParserHandlebars(); | ||
var str = '{y xxx zzz}}'; | ||
var r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
var arr = [ | ||
// test for expression with the same name as known filter {y}} | ||
{str:'{y xxx zzz}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
{str:'{y xxx zzz}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
{str:'{ y xxx zzz}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
str = '{y xxx zzz}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = '{ y xxx zzz}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
// test for expression with the same name as unknown filter | ||
{str:'{unknown xxx zzz}}', isPrefixWithKnownFilter:false, filter:'unknown', isSingleIdentifier:false}, | ||
{str:'{unknown xxx zzz}}', isPrefixWithKnownFilter:false, filter:'unknown', isSingleIdentifier:false}, | ||
{str:'{ unknown xxx zzz}}', isPrefixWithKnownFilter:false, filter:'unknown', isSingleIdentifier:false} | ||
]; | ||
arr.forEach(function(obj) { | ||
var r = parser._parseExpression(obj.str, 0); | ||
utils.testExpression(r, obj); | ||
}); | ||
}); | ||
it("handlebars-utils#_getExpressionExtraInfo 2 arguments (reference format) test", function() { | ||
var ContextParserHandlebars = require("../../src/context-parser-handlebars.js"); | ||
it("handlebars-handlebarsUtilss#_parseExpression 2 arguments (reference format) test", function() { | ||
var parser = new ContextParserHandlebars(); | ||
var str = '{y xxx.name zzz}}'; | ||
var r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
var arr = [ | ||
// test for expression with the same name as known filter {y}} with different parameter format | ||
{str:'{y people.name ../name}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
{str:'{y article[0] article/name}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
{str:'{y article.[0].[#comments] article/name}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
str = '{y ../xxx.name zzz}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = '{ y xxx.name zzz}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = '{ y ../xxx.name zzz}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
// test for expression with the same name as known filter {unknown}} with different parameter format | ||
{str:'{unknown people.name ../name}}', isPrefixWithKnownFilter:false, filter:'unknown', isSingleIdentifier:false}, | ||
{str:'{unknown article[0] article/name}}', isPrefixWithKnownFilter:false, filter:'unknown', isSingleIdentifier:false}, | ||
{str:'{unknown article.[0].[#comments] article/name}}', isPrefixWithKnownFilter:false, filter:'unknown', isSingleIdentifier:false} | ||
]; | ||
arr.forEach(function(obj) { | ||
var r = parser._parseExpression(obj.str, 0); | ||
utils.testExpression(r, obj); | ||
}); | ||
}); | ||
it("handlebars-utils#_getExpressionExtraInfo reserved tag test", function() { | ||
var ContextParserHandlebars = require("../../src/context-parser-handlebars.js"); | ||
it("handlebars-handlebarsUtilss#_parseExpression reserved tag test", function() { | ||
var parser = new ContextParserHandlebars(); | ||
var str = '{#y }}'; | ||
var r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal(''); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = '{# y }}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal(''); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
var arr = [ | ||
// test for reserved expression {{#.*}} | ||
{str:'{#y}}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:false}, | ||
{str:'{# y xxx}}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:false}, | ||
// test for reserved expression {{/.*}} | ||
{str:'{/y}}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:false}, | ||
{str:'{/ y }}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:false}, | ||
// test for reserved expression {{>.*}} | ||
{str:'{>partial}}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:false}, | ||
{str:'{> partial }}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:false}, | ||
// test for reserved expression {{^.*}} | ||
{str:'{^negation}}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:false}, | ||
{str:'{^ negation }}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:false}, | ||
// test for reserved expression {{!.*}} | ||
{str:'{!comment}}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:false}, | ||
{str:'{! comment }}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:false}, | ||
// test for reserved expression {{@.*}} | ||
{str:'{@var}}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:false}, | ||
{str:'{@ var }}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:false} | ||
]; | ||
arr.forEach(function(obj) { | ||
var r = parser._parseExpression(obj.str, 0); | ||
utils.testExpression(r, obj); | ||
}); | ||
}); | ||
it("handlebars-utils#_getExpressionExtraInfo subexpression test", function() { | ||
var ContextParserHandlebars = require("../../src/context-parser-handlebars.js"); | ||
it("handlebars-handlebarsUtilss#_parseExpression subexpression test", function() { | ||
var parser = new ContextParserHandlebars(); | ||
/* not a valid handlebars syntax | ||
str = '{y(output)}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
*/ | ||
str = '{y (output)}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = '{y ( output )}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = '{y (helper xxx)}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = '{y ( helper xxx )}}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = "{y (helper 'xxx')}}"; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = "{y ( helper 'xxx' )}}"; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = "{y helper2 ( helper1 'xxx' )}}"; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = "{y (outer-helper (inner-helper 'abc') 'def')}}"; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = "{y ( outer-helper (inner-helper 'abc') 'def')}}"; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
var arr = [ | ||
// not a valid handlebars syntax, no need to test | ||
// {str:'{y(output)}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
// subexpression with one chain | ||
{str:'{y (output)}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
{str:'{y ( output ) }}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
// subexpression with two chain | ||
{str:'{y (helper xxx)}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
{str:'{y ( helper xxx ) }}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
{str:'{y (helper "xxx")}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
{str:'{y ( helper "xxx" ) }}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
// subexpression with three chain | ||
{str:'{y helper2 (helper1 xxx)}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
{str:'{y helper2 ( helper1 xxx )}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
{str:'{y helper2 ( helper1 "xxx" )}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
// | ||
{str:'{y ( outer-helper (inner-helper "abc") "def")}}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false} | ||
]; | ||
arr.forEach(function(obj) { | ||
var r = parser._parseExpression(obj.str, 0); | ||
utils.testExpression(r, obj); | ||
}); | ||
}); | ||
it("handlebars-utils#_getExpressionExtraInfo greedy match test", function() { | ||
var ContextParserHandlebars = require("../../src/context-parser-handlebars.js"); | ||
it("handlebars-handlebarsUtilss#_parseExpression greedy match test", function() { | ||
var parser = new ContextParserHandlebars(); | ||
var str = '{else }}{{h zzz }}'; | ||
var r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal(''); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
var arr = [ | ||
// immediate after an expression | ||
{str:'{else}}{{h zzz }}', isPrefixWithKnownFilter:true, filter:'', isSingleIdentifier:false}, | ||
{str:'{y}}{{h zzz }}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:true}, | ||
{str:'{y param}}{{h zzz }}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false}, | ||
// not immediate after an expression | ||
{str:'{else}}xxxx{{h zzz }}', isPrefixWithKnownFilter:true, filter:'', isSingleIdentifier:false}, | ||
{str:'{y}}xxxx{{h zzz }}', isPrefixWithKnownFilter:false, filter:'', isSingleIdentifier:true}, | ||
{str:'{y param}}xxxx{{h zzz }}', isPrefixWithKnownFilter:true, filter:'y', isSingleIdentifier:false} | ||
]; | ||
arr.forEach(function(obj) { | ||
var r = parser._parseExpression(obj.str, 0); | ||
utils.testExpression(r, obj); | ||
}); | ||
}); | ||
str = '{y}}xxxxx{{h zzz }}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal(''); | ||
expect(r.isSingleIdentifier).to.equal(true); | ||
it("handlebars-handlebarsUtilss#isValidExpression escapeExpressionRegExp test", function() { | ||
var arr = [ | ||
// basic | ||
{str:'{{anything}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:true, rstr:'{{anything}}'}, | ||
{str:'{{ anything }}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:true, rstr:'{{ anything }}'}, | ||
// with \r and \n | ||
{str:'{{any\rthing}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:true, rstr:'{{any\rthing}}'}, | ||
{str:'{{any\nthing}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:true, rstr:'{{any\nthing}}'}, | ||
{str:'{{any\r\nthing}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:true, rstr:'{{any\r\nthing}}'}, | ||
str = '{y}}{{h zzz }}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal(''); | ||
expect(r.isSingleIdentifier).to.equal(true); | ||
// invalid expression | ||
{str:'{ {anything}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:false}, | ||
{str:'{{anything}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:false}, | ||
{str:'{{anything} }', type:handlebarsUtils.ESCAPE_EXPRESSION, result:false}, | ||
{str:'{{anything}}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:false}, | ||
{str:'{{ {anything}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:false}, | ||
{str:'{{ }anything}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:false}, | ||
{str:'{{}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:false} | ||
]; | ||
arr.forEach(function(obj) { | ||
var r = handlebarsUtils.isValidExpression(obj.str, 0, obj.type); | ||
utils.testIsValidExpression(r, obj); | ||
}); | ||
}); | ||
str = '{y }}{{h zzz }}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal(''); | ||
expect(r.isSingleIdentifier).to.equal(true); | ||
it("handlebars-handlebarsUtilss#isValidExpression rawExpressionRegExp test", function() { | ||
var arr = [ | ||
// basic | ||
{str:'{{{anything}}}', type:handlebarsUtils.RAW_EXPRESSION, result:true, rstr:'{{{anything}}}'}, | ||
{str:'{{{ anything }}}', type:handlebarsUtils.RAW_EXPRESSION, result:true, rstr:'{{{ anything }}}'}, | ||
// with \r and \n | ||
{str:'{{{any\rthing}}}', type:handlebarsUtils.RAW_EXPRESSION, result:true, rstr:'{{{any\rthing}}}'}, | ||
{str:'{{{any\nthing}}}', type:handlebarsUtils.RAW_EXPRESSION, result:true, rstr:'{{{any\nthing}}}'}, | ||
{str:'{{{any\r\nthing}}}', type:handlebarsUtils.RAW_EXPRESSION, result:true, rstr:'{{{any\r\nthing}}}'}, | ||
str = '{y xxx }}{{h zzz }}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = '{y ../xxx }}{{h zzz }}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = '{y xxx.name }}{{h zzz }}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = '{#y }}{{h zzz }}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(false); | ||
expect(r.filter).to.equal(''); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = '{ y ( helper xxx )}}{{h zzz }}'; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = "{ y ( helper 'xxx' )}}{{h zzz }}"; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
str = "{ y helper2 ( helper1 xxx )}}{{h zzz }}"; | ||
r = parser._getExpressionExtraInfo(str, 0); | ||
expect(r.isKnownFilter).to.equal(true); | ||
expect(r.filter).to.equal('y'); | ||
expect(r.isSingleIdentifier).to.equal(false); | ||
// invalid expression | ||
{str:'{ {{anything}}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:false}, | ||
{str:'{{ {anything}}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:false}, | ||
{str:'{{{anything}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:false}, | ||
{str:'{{{anything}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:false}, | ||
{str:'{{{anything}}}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:false}, | ||
{str:'{{{ {anything}}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:false}, | ||
{str:'{{{ }anything}}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:false}, | ||
{str:'{{{}}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:false} | ||
]; | ||
arr.forEach(function(obj) { | ||
var r = handlebarsUtils.isValidExpression(obj.str, 0, obj.type); | ||
utils.testIsValidExpression(r, obj); | ||
}); | ||
}); | ||
it("handlebars-utils#generateNonce test", function() { | ||
var n1 = util.generateNonce(); | ||
var n2 = util.generateNonce(); | ||
expect(n1).not.to.equal(n2); | ||
}); | ||
it("handlebars-handlebarsUtilss#isValidExpression greedy match test", function() { | ||
var arr = [ | ||
// basic | ||
{str:'{{anything}}{{anything}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:true, rstr:'{{anything}}'}, | ||
{str:'{{ anything }}{{anything}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:true, rstr:'{{ anything }}'}, | ||
{str:'{{anything}}xxx{{anything}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:true, rstr:'{{anything}}'}, | ||
{str:'{{ anything }}xxx{{anything}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:true, rstr:'{{ anything }}'}, | ||
it("handlebars-utils#isReservedChar test", function() { | ||
var s = "#"; | ||
var r = util.isReservedChar(s); | ||
expect(r).to.equal(true); | ||
s = "/"; | ||
r = util.isReservedChar(s); | ||
expect(r).to.equal(true); | ||
s = ">"; | ||
r = util.isReservedChar(s); | ||
expect(r).to.equal(true); | ||
s = "@"; | ||
r = util.isReservedChar(s); | ||
expect(r).to.equal(true); | ||
s = "^"; | ||
r = util.isReservedChar(s); | ||
expect(r).to.equal(true); | ||
s = "!"; | ||
r = util.isReservedChar(s); | ||
expect(r).to.equal(true); | ||
}); | ||
// with \r and \n | ||
{str:'{{any\rthing}}{{anything}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:true, rstr:'{{any\rthing}}'}, | ||
{str:'{{any\nthing}}{{anything}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:true, rstr:'{{any\nthing}}'}, | ||
{str:'{{any\r\nthing}}{{anything}}', type:handlebarsUtils.ESCAPE_EXPRESSION, result:true, rstr:'{{any\r\nthing}}'}, | ||
it("handlebars-utils#isBranchTag (if) test", function() { | ||
var s = "{{#if xxx}}"; | ||
var r = util.isBranchTag(s); | ||
expect(r).to.equal('if'); | ||
s = "{{# if xxx}}"; | ||
r = util.isBranchTag(s); | ||
expect(r).to.equal('if'); | ||
s = "{{/if}}"; | ||
r = util.isBranchEndTag(s); | ||
expect(r).to.equal('if'); | ||
s = "{{/ if }}"; | ||
r = util.isBranchEndTag(s); | ||
expect(r).to.equal('if'); | ||
}); | ||
// basic | ||
{str:'{{{anything}}}{{{anything}}}', type:handlebarsUtils.RAW_EXPRESSION, result:true, rstr:'{{{anything}}}'}, | ||
{str:'{{{ anything }}}{{{anything}}}', type:handlebarsUtils.RAW_EXPRESSION, result:true, rstr:'{{{ anything }}}'}, | ||
{str:'{{{anything}}}xxx{{{anything}}}', type:handlebarsUtils.RAW_EXPRESSION, result:true, rstr:'{{{anything}}}'}, | ||
{str:'{{{ anything }}}xxx{{{anything}}}', type:handlebarsUtils.RAW_EXPRESSION, result:true, rstr:'{{{ anything }}}'}, | ||
it("handlebars-utils#isBranchTag (with) test", function() { | ||
var s = "{{#with xxx}}"; | ||
var r = util.isBranchTag(s); | ||
expect(r).to.equal('with'); | ||
s = "{{# with xxx}}"; | ||
r = util.isBranchTag(s); | ||
expect(r).to.equal('with'); | ||
s = "{{/with}}"; | ||
r = util.isBranchEndTag(s); | ||
expect(r).to.equal('with'); | ||
s = "{{/ with }}"; | ||
r = util.isBranchEndTag(s); | ||
expect(r).to.equal('with'); | ||
// with \r and \n | ||
{str:'{{{any\rthing}}}{{{anything}}}', type:handlebarsUtils.RAW_EXPRESSION, result:true, rstr:'{{{any\rthing}}}'}, | ||
{str:'{{{any\nthing}}}{{{anything}}}', type:handlebarsUtils.RAW_EXPRESSION, result:true, rstr:'{{{any\nthing}}}'}, | ||
{str:'{{{any\r\nthing}}}{{{anything}}}', type:handlebarsUtils.RAW_EXPRESSION, result:true, rstr:'{{{any\r\nthing}}}'}, | ||
]; | ||
arr.forEach(function(obj) { | ||
var r = handlebarsUtils.isValidExpression(obj.str, 0, obj.type); | ||
utils.testIsValidExpression(r, obj); | ||
}); | ||
}); | ||
it("handlebars-utils#isBranchTag (each) test", function() { | ||
var s = "{{#each xxx}}"; | ||
var r = util.isBranchTag(s); | ||
expect(r).to.equal('each'); | ||
s = "{{# each xxx}}"; | ||
r = util.isBranchTag(s); | ||
expect(r).to.equal('each'); | ||
s = "{{/each}}"; | ||
r = util.isBranchEndTag(s); | ||
expect(r).to.equal('each'); | ||
s = "{{/ each }}"; | ||
r = util.isBranchEndTag(s); | ||
expect(r).to.equal('each'); | ||
it("handlebars-handlebarsUtilss#isReservedChar test", function() { | ||
[ | ||
'#', '/', '>', '@', '^', '!' | ||
].forEach(function(c) { | ||
var r = handlebarsUtils.isReservedChar(c); | ||
expect(r).to.equal(true); | ||
}); | ||
}); | ||
it("handlebars-utils#isBranchTag (list) test", function() { | ||
var s = "{{#list xxx}}"; | ||
var r = util.isBranchTag(s); | ||
expect(r).to.equal('list'); | ||
s = "{{# list xxx}}"; | ||
r = util.isBranchTag(s); | ||
expect(r).to.equal('list'); | ||
s = "{{/list}}"; | ||
r = util.isBranchEndTag(s); | ||
expect(r).to.equal('list'); | ||
s = "{{/ list }}"; | ||
r = util.isBranchEndTag(s); | ||
expect(r).to.equal('list'); | ||
}); | ||
it("handlebars-handlebarsUtilss#isBranchExpression test", function() { | ||
[ | ||
{str: '{{#if xxx}}', rstr: 'if'}, | ||
{str: '{{#if xxx}}{{#if xxx}}', rstr: 'if'}, | ||
{str: '{{#if xxx}}x{{#if xxx}}', rstr: 'if'}, | ||
{str: '{{#if xxx}} x {{#if xxx}}', rstr: 'if'}, | ||
{str: '{{# if xxx}}', rstr: 'if'}, | ||
it("handlebars-utils#isBranchTag (anything) test", function() { | ||
s = "{{tag}}xxx"; | ||
r = util.isBranchTag(s); | ||
expect(r).to.equal(false); | ||
{str: '{{#with xxx}}', rstr: 'with'}, | ||
{str: '{{#each xxx}}', rstr: 'each'}, | ||
{str: '{{#list xxx}}', rstr: 'list'}, | ||
{str: '{{#unless xxx}}', rstr: 'unless'}, | ||
{str: '{{#tag xxx}}', rstr: 'tag'}, | ||
{str: '{{^msg xxx}}', rstr: 'msg'}, | ||
s = "{{#tag}}xxx"; | ||
r = util.isBranchTag(s); | ||
expect(r).to.equal("tag"); | ||
s = "{{# tag}}xxx"; | ||
r = util.isBranchTag(s); | ||
expect(r).to.equal("tag"); | ||
s = "{{# tag }}xxx"; | ||
r = util.isBranchTag(s); | ||
expect(r).to.equal("tag"); | ||
s = "{{# tag xxx}}xxx"; | ||
r = util.isBranchTag(s); | ||
expect(r).to.equal("tag"); | ||
s = "{{# tag xxx }}xxx"; | ||
r = util.isBranchTag(s); | ||
expect(r).to.equal("tag"); | ||
s = "{{/tag}}xxx"; | ||
r = util.isBranchEndTag(s); | ||
expect(r).to.equal("tag"); | ||
s = "{{/ tag}}xxx"; | ||
r = util.isBranchEndTag(s); | ||
expect(r).to.equal("tag"); | ||
s = "{{/ tag }}xxx"; | ||
r = util.isBranchEndTag(s); | ||
expect(r).to.equal("tag"); | ||
// illegal handlebars format | ||
{str: '{{#t-ag xxx}}', rstr: 't-ag'} | ||
].forEach(function(obj) { | ||
var r = handlebarsUtils.isBranchExpression(obj.str); | ||
expect(r).to.equal(obj.rstr); | ||
}); | ||
}); | ||
it("handlebars-utils#isBranchTag (negation ^msg) test", function() { | ||
var s = "{{^msg}}"; | ||
var r = util.isBranchTag(s); | ||
expect(r).to.equal('msg'); | ||
s = "{{^ msg }}"; | ||
r = util.isBranchTag(s); | ||
expect(r).to.equal('msg'); | ||
s = "{{/msg}}"; | ||
r = util.isBranchEndTag(s); | ||
expect(r).to.equal('msg'); | ||
s = "{{/ msg }}"; | ||
r = util.isBranchEndTag(s); | ||
expect(r).to.equal('msg'); | ||
}); | ||
it("handlebars-handlebarsUtilss#isBranchEndExpression test", function() { | ||
[ | ||
{str: '{{/if}}', rstr: 'if'}, | ||
{str: '{{/if}}{{/if}}', rstr: 'if'}, | ||
{str: '{{/if}}x{{/if}}', rstr: 'if'}, | ||
{str: '{{/if}} x {{/if}}', rstr: 'if'}, | ||
{str: '{{/ if }}', rstr: 'if'}, | ||
it("handlebars-utils#isBranchTag (illegal tag format) test", function() { | ||
s = "{{# t-ag xxx}}xxx"; | ||
r = util.isBranchTag(s); | ||
expect(r).to.equal("t-ag"); | ||
s = "{{/ t-ag }}xxx"; | ||
r = util.isBranchEndTag(s); | ||
expect(r).to.equal("t-ag"); | ||
}); | ||
{str: '{{/with}}', rstr: 'with'}, | ||
{str: '{{/each}}', rstr: 'each'}, | ||
{str: '{{/list}}', rstr: 'list'}, | ||
{str: '{{/unless}}', rstr: 'unless'}, | ||
{str: '{{/tag}}', rstr: 'tag'}, | ||
{str: '{{/msg}}', rstr: 'msg'}, | ||
it("handlebars-utils#isBranchTag (unless) test", function() { | ||
var s = "{{#unless xxx}}"; | ||
var r = util.isBranchTag(s); | ||
expect(r).to.equal('unless'); | ||
s = "{{#unless xxx}}{{#unless xxx}}"; | ||
r = util.isBranchTag(s); | ||
expect(r).to.equal('unless'); | ||
s = "{{#unless xxx}} xxx {{#unless xxx}}"; | ||
r = util.isBranchTag(s); | ||
expect(r).to.equal('unless'); | ||
s = "{{# unless xxx}}"; | ||
r = util.isBranchTag(s); | ||
expect(r).to.equal('unless'); | ||
s = "{{/unless}}"; | ||
r = util.isBranchEndTag(s); | ||
expect(r).to.equal('unless'); | ||
s = "{{/unless}}{{/unless}}"; | ||
r = util.isBranchEndTag(s); | ||
expect(r).to.equal('unless'); | ||
s = "{{/unless}} xxx {{/unless}}"; | ||
r = util.isBranchEndTag(s); | ||
expect(r).to.equal('unless'); | ||
s = "{{/ unless }}"; | ||
r = util.isBranchEndTag(s); | ||
expect(r).to.equal('unless'); | ||
// illegal handlebars format | ||
{str: '{{/t-ag}}', rstr: 't-ag'} | ||
].forEach(function(obj) { | ||
var r = handlebarsUtils.isBranchEndExpression(obj.str); | ||
expect(r).to.equal(obj.rstr); | ||
}); | ||
}); | ||
it("handlebars-utils#isElseTag test", function() { | ||
var s = "{{else}}"; | ||
var r = util.isElseTag(s); | ||
expect(r).to.equal(true); | ||
s = "{{ else }}"; | ||
r = util.isElseTag(s); | ||
expect(r).to.equal(true); | ||
s = "{{else}}{{else}}"; | ||
r = util.isElseTag(s); | ||
expect(r).to.equal(true); | ||
s = "{{else}} xxxx {{else}}"; | ||
r = util.isElseTag(s); | ||
expect(r).to.equal(true); | ||
it("handlebars-handlebarsUtilss#isElseExpression test", function() { | ||
[ | ||
{str: '{{else}}', result:true}, | ||
{str: '{{ else }}', result:true}, | ||
{str: '{{else}}{{else}}', result:true}, | ||
{str: '{{else}}x{{else}}', result:true}, | ||
{str: '{{else}} x {{else}}', result:true} | ||
].forEach(function(obj) { | ||
var r = handlebarsUtils.isElseExpression(obj.str); | ||
expect(r).to.equal(obj.result); | ||
}); | ||
}); | ||
it("handlebars-utils#isBranchTags test", function() { | ||
var s = "{{#if xxx}}"; | ||
var r = util.isBranchTags(s); | ||
expect(r).to.equal(true); | ||
it("handlebars-handlebarsUtilss#isBranchExpressions test", function() { | ||
[ | ||
{str: '{{#if xxx}}', result:true}, | ||
{str: '{{#if xxx}}{{#if xxx}}', result:true}, | ||
{str: '{{#if xxx}}x{{#if xxx}}', result:true}, | ||
{str: '{{#if xxx}} x {{#if xxx}}', result:true}, | ||
s = "{{#with}}"; | ||
r = util.isBranchTags(s); | ||
expect(r).to.equal(true); | ||
{str: '{{#with xxx}}', result:true}, | ||
{str: '{{#each xxx}}', result:true}, | ||
{str: '{{#list xxx}}', result:true}, | ||
{str: '{{#unless xxx}}', result:true}, | ||
{str: '{{#tag xxx}}', result:true}, | ||
s = "{{#each}}"; | ||
r = util.isBranchTags(s); | ||
expect(r).to.equal(true); | ||
{str: '{{^msg xxx}}', result:true}, | ||
s = "{{#list}}"; | ||
r = util.isBranchTags(s); | ||
expect(r).to.equal(true); | ||
s = "{{#tag}}"; | ||
r = util.isBranchTags(s); | ||
expect(r).to.equal(true); | ||
s = "{{^msg}}"; | ||
r = util.isBranchTags(s); | ||
expect(r).to.equal(true); | ||
s = "{{#unless}}"; | ||
r = util.isBranchTags(s); | ||
expect(r).to.equal(true); | ||
s = "{{else}}"; | ||
r = util.isBranchTags(s); | ||
expect(r).to.equal(false); | ||
{str: '{{else}}', result:false}, | ||
{str: '{{expression}}', result:false}, | ||
{str: '{{{expression}}}', result:false}, | ||
].forEach(function(obj) { | ||
var r = handlebarsUtils.isBranchExpressions(obj.str); | ||
expect(r).to.equal(obj.result); | ||
}); | ||
}); | ||
it("handlebars-utils - extract basic Handlebars {{#if xxx}} statement test", function() { | ||
it("handlebars-handlebarsUtilss - extract basic Handlebars {{#if xxx}} statement test", function() { | ||
var s = "{{#if xxx}} a {{/if}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{#if xxx}} a {{\/if}}'); | ||
}); | ||
it("handlebars-utils - extract basic Handlebars {{#if xxx}} statement with {{else}} test", function() { | ||
it("handlebars-handlebarsUtilss - extract basic Handlebars {{#if xxx}} statement with {{else}} test", function() { | ||
var s = "{{#if xxx}} a {{else}} b {{/if}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{#if xxx}} a {{else}} b {{\/if}}'); | ||
}); | ||
it("handlebars-utils - extract nested Handlebars {{#if xxx}} statement test", function() { | ||
it("handlebars-handlebarsUtilss - extract nested Handlebars {{#if xxx}} statement test", function() { | ||
var s = "{{#if xxx}} a {{#if}} b {{else}} c {{/if}} d {{else}} e {{#if}} f {{else}} h {{/if}} i {{/if}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{#if xxx}} a {{#if}} b {{else}} c {{/if}} d {{else}} e {{#if}} f {{else}} h {{/if}} i {{/if}}'); | ||
}); | ||
it("handlebars-utils - extract basic Handlebars {{#with xxx}} statement test", function() { | ||
it("handlebars-handlebarsUtilss - extract basic Handlebars {{#with xxx}} statement test", function() { | ||
var s = "{{#with xxx}} a {{/with}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{#with xxx}} a {{\/with}}'); | ||
}); | ||
it("handlebars-utils - extract basic Handlebars {{#with xxx}} statement with {{else}} test", function() { | ||
it("handlebars-handlebarsUtilss - extract basic Handlebars {{#with xxx}} statement with {{else}} test", function() { | ||
var s = "{{#with xxx}} a {{else}} b {{/with}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{#with xxx}} a {{else}} b {{\/with}}'); | ||
}); | ||
it("handlebars-utils - extract nested Handlebars {{#with xxx}} statement test", function() { | ||
it("handlebars-handlebarsUtilss - extract nested Handlebars {{#with xxx}} statement test", function() { | ||
var s = "{{#with xxx}} a {{#with}} b {{else}} c {{/with}} d {{else}} e {{#with}} f {{else}} h {{/with}} i {{/with}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{#with xxx}} a {{#with}} b {{else}} c {{/with}} d {{else}} e {{#with}} f {{else}} h {{/with}} i {{/with}}'); | ||
}); | ||
it("handlebars-utils - extract basic Handlebars {{#each xxx}} statement test", function() { | ||
it("handlebars-handlebarsUtilss - extract basic Handlebars {{#each xxx}} statement test", function() { | ||
var s = "{{#each xxx}} a {{/each}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{#each xxx}} a {{\/each}}'); | ||
}); | ||
it("handlebars-utils - extract basic Handlebars {{#each xxx}} statement with {{else}} test", function() { | ||
it("handlebars-handlebarsUtilss - extract basic Handlebars {{#each xxx}} statement with {{else}} test", function() { | ||
var s = "{{#each xxx}} a {{else}} b {{/each}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{#each xxx}} a {{else}} b {{\/each}}'); | ||
}); | ||
it("handlebars-utils - extract nested Handlebars {{#each xxx}} statement test", function() { | ||
it("handlebars-handlebarsUtilss - extract nested Handlebars {{#each xxx}} statement test", function() { | ||
var s = "{{#each xxx}} a {{#each}} b {{else}} c {{/each}} d {{else}} e {{#each}} f {{else}} h {{/each}} i {{/each}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{#each xxx}} a {{#each}} b {{else}} c {{/each}} d {{else}} e {{#each}} f {{else}} h {{/each}} i {{/each}}'); | ||
}); | ||
it("handlebars-utils - extract basic Handlebars {{#list xxx}} statement test", function() { | ||
it("handlebars-handlebarsUtilss - extract basic Handlebars {{#list xxx}} statement test", function() { | ||
var s = "{{#list xxx}} a {{/list}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{#list xxx}} a {{\/list}}'); | ||
}); | ||
it("handlebars-utils - extract basic Handlebars {{#list xxx}} statement with {{else}} test", function() { | ||
it("handlebars-handlebarsUtilss - extract basic Handlebars {{#list xxx}} statement with {{else}} test", function() { | ||
var s = "{{#list xxx}} a {{else}} b {{/list}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{#list xxx}} a {{else}} b {{\/list}}'); | ||
}); | ||
it("handlebars-utils - extract nested Handlebars {{#list xxx}} statement test", function() { | ||
it("handlebars-handlebarsUtilss - extract nested Handlebars {{#list xxx}} statement test", function() { | ||
var s = "{{#list xxx}} a {{#list yyy}} b {{else}} c {{/list}} d {{else}} e {{#list zzz}} f {{else}} h {{/list}} i {{/list}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{#list xxx}} a {{#list yyy}} b {{else}} c {{/list}} d {{else}} e {{#list zzz}} f {{else}} h {{/list}} i {{/list}}'); | ||
}); | ||
it("handlebars-utils - extract basic Handlebars {{#tag xxx}} statement test", function() { | ||
it("handlebars-handlebarsUtilss - extract basic Handlebars {{#tag xxx}} statement test", function() { | ||
var s = "{{#tag xxx}} a {{/tag}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{#tag xxx}} a {{\/tag}}'); | ||
}); | ||
it("handlebars-utils - extract basic Handlebars {{#tag xxx}} statement with {{else}} test", function() { | ||
it("handlebars-handlebarsUtilss - extract basic Handlebars {{#tag xxx}} statement with {{else}} test", function() { | ||
var s = "{{#tag xxx}} a {{else}} b {{/tag}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{#tag xxx}} a {{else}} b {{\/tag}}'); | ||
}); | ||
it("handlebars-utils - extract nested Handlebars {{#tag xxx}} statement test", function() { | ||
it("handlebars-handlebarsUtilss - extract nested Handlebars {{#tag xxx}} statement test", function() { | ||
var s = "{{#tag xxx}} a {{#tag yyy}} b {{else}} c {{/tag}} d {{else}} e {{#tag zzz}} f {{else}} h {{/tag}} i {{/tag}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{#tag xxx}} a {{#tag yyy}} b {{else}} c {{/tag}} d {{else}} e {{#tag zzz}} f {{else}} h {{/tag}} i {{/tag}}'); | ||
}); | ||
it("handlebars-utils - extract basic Handlebars {{^msg}} statement test", function() { | ||
it("handlebars-handlebarsUtilss - extract basic Handlebars {{^msg}} statement test", function() { | ||
var s = "{{^msg}} a {{/msg}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{^msg}} a {{\/msg}}'); | ||
}); | ||
it("handlebars-utils - extract basic Handlebars {{^msg}} statement with {{else}} test", function() { | ||
it("handlebars-handlebarsUtilss - extract basic Handlebars {{^msg}} statement with {{else}} test", function() { | ||
var s = "{{^msg}} a {{else}} b {{/msg}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{^msg}} a {{else}} b {{\/msg}}'); | ||
}); | ||
it("handlebars-utils - extract nested Handlebars {{^msg}} statement test", function() { | ||
it("handlebars-handlebarsUtilss - extract nested Handlebars {{^msg}} statement test", function() { | ||
var s = "{{^msg}} a {{^msg}} b {{else}} c {{/msg}} d {{else}} e {{^msg}} f {{else}} h {{/msg}} i {{/msg}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{^msg}} a {{^msg}} b {{else}} c {{/msg}} d {{else}} e {{^msg}} f {{else}} h {{/msg}} i {{/msg}}'); | ||
}); | ||
it("handlebars-utils - extract basic Handlebars {{#unless xxx}} statement test", function() { | ||
it("handlebars-handlebarsUtilss - extract basic Handlebars {{#unless xxx}} statement test", function() { | ||
var s = "{{#unless xxx}} a {{/unless}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{#unless xxx}} a {{\/unless}}'); | ||
}); | ||
it("handlebars-utils - extract nested Handlebars {{#unless xxx}} statement test", function() { | ||
it("handlebars-handlebarsUtilss - extract nested Handlebars {{#unless xxx}} statement test", function() { | ||
var s = "{{#unless xxx}} a {{#unless xxx}} b {{/unless}} c {{/unless}} zzzzzzzz"; | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(r['stmt']).to.equal('{{#unless xxx}} a {{#unless xxx}} b {{/unless}} c {{/unless}}'); | ||
}); | ||
it("handlebars-utils - extract nested Handlebars {{#unless xxx}} statement exception test", function() { | ||
it("handlebars-handlebarsUtilss - extract nested Handlebars {{#unless xxx}} statement exception test", function() { | ||
var s = "{{#if} aaaaaaaa"; | ||
try { | ||
var r = util.extractBranchStmt(s, 0, false); | ||
var r = handlebarsUtils.extractBranchStmt(s, 0, false); | ||
expect(false).to.equal(true); | ||
@@ -730,8 +533,8 @@ } catch (err) { | ||
it("handlebars-utils - parse basic Handlebars {{#if xxx}} statement parseAstTreeState test", function() { | ||
it("handlebars-handlebarsUtilss - parse basic Handlebars {{#if xxx}} statement parseAstTreeState test", function() { | ||
var s = "<a href='{{#if xxx}} a {{/if}}'>"; | ||
var obj = util.extractBranchStmt(s, 9, true); | ||
var obj = handlebarsUtils.extractBranchStmt(s, 9, true); | ||
expect(obj.stmt).to.equal('{{#if xxx}} a {{/if}}'); | ||
var ast = util.parseBranchStmt(obj.stmt); | ||
var r = util.parseAstTreeState(ast, 39, obj); | ||
var ast = handlebarsUtils.parseBranchStmt(obj.stmt); | ||
var r = handlebarsUtils.parseAstTreeState(ast, 39, obj); | ||
// a (1st branch) | ||
@@ -743,8 +546,8 @@ // 'empty string' (2nd branch) | ||
it("handlebars-utils - parse basic Handlebars {{#if xxx}} statement with {{else}} parseAstTreeState test", function() { | ||
it("handlebars-handlebarsUtilss - parse basic Handlebars {{#if xxx}} statement with {{else}} parseAstTreeState test", function() { | ||
var s = "<a href='{{#if xxx}} a {{else}} b {{/if}}'>"; | ||
var obj = util.extractBranchStmt(s, 9, true); | ||
var obj = handlebarsUtils.extractBranchStmt(s, 9, true); | ||
expect(obj.stmt).to.equal('{{#if xxx}} a {{else}} b {{/if}}'); | ||
var ast = util.parseBranchStmt(obj.stmt); | ||
var r = util.parseAstTreeState(ast, 39, obj); | ||
var ast = handlebarsUtils.parseBranchStmt(obj.stmt); | ||
var r = handlebarsUtils.parseAstTreeState(ast, 39, obj); | ||
// a (1st branch) | ||
@@ -756,8 +559,8 @@ // b (2nd branch) | ||
it("handlebars-utils - parse nested Handlebars {{#if xxx}} statement parseAstTreeState test", function() { | ||
it("handlebars-handlebarsUtilss - parse nested Handlebars {{#if xxx}} statement parseAstTreeState test", function() { | ||
var s = "<a href='{{#if xxx}} a {{#if}} b {{/if}} c {{/if}}'>"; | ||
var obj = util.extractBranchStmt(s, 9, true); | ||
var obj = handlebarsUtils.extractBranchStmt(s, 9, true); | ||
expect(obj.stmt).to.equal('{{#if xxx}} a {{#if}} b {{/if}} c {{/if}}'); | ||
var ast = util.parseBranchStmt(obj.stmt); | ||
var r = util.parseAstTreeState(ast, 39, obj); | ||
var ast = handlebarsUtils.parseBranchStmt(obj.stmt); | ||
var r = handlebarsUtils.parseAstTreeState(ast, 39, obj); | ||
// a b c (1st branch) | ||
@@ -770,8 +573,8 @@ // a c (1st branch) | ||
it("handlebars-utils - parse nested Handlebars {{#if xxx}} statement with {{else}} parseAstTreeState test", function() { | ||
it("handlebars-handlebarsUtilss - parse nested Handlebars {{#if xxx}} statement with {{else}} parseAstTreeState test", function() { | ||
var s = "<a href='{{#if xxx}} a {{#if}} b {{else}} c {{/if}} d {{else}} e {{#if}} f {{else}} g {{/if}} h {{/if}}'>"; | ||
var obj = util.extractBranchStmt(s, 9, true); | ||
var obj = handlebarsUtils.extractBranchStmt(s, 9, true); | ||
expect(obj.stmt).to.equal('{{#if xxx}} a {{#if}} b {{else}} c {{/if}} d {{else}} e {{#if}} f {{else}} g {{/if}} h {{/if}}'); | ||
var ast = util.parseBranchStmt(obj.stmt); | ||
var r = util.parseAstTreeState(ast, 39, obj); | ||
var ast = handlebarsUtils.parseBranchStmt(obj.stmt); | ||
var r = handlebarsUtils.parseAstTreeState(ast, 39, obj); | ||
// a b d (1st branch) | ||
@@ -785,8 +588,8 @@ // a c d (1st branch) | ||
it("handlebars-utils - parse parallel Handlebars {{#if xxx}} statement parseAstTreeState test", function() { | ||
it("handlebars-handlebarsUtilss - parse parallel Handlebars {{#if xxx}} statement parseAstTreeState test", function() { | ||
var s = "<a href='{{#if xxx}} a {{#if}} b {{else}} c {{/if}} d {{#if}} b {{else}} c {{/if}} f {{else}} e {{#if xyz}} f {{else}} g {{/if}} h {{/if}}'>"; | ||
var obj = util.extractBranchStmt(s, 9, true); | ||
var obj = handlebarsUtils.extractBranchStmt(s, 9, true); | ||
expect(obj.stmt).to.equal('{{#if xxx}} a {{#if}} b {{else}} c {{/if}} d {{#if}} b {{else}} c {{/if}} f {{else}} e {{#if xyz}} f {{else}} g {{/if}} h {{/if}}'); | ||
var ast = util.parseBranchStmt(obj.stmt); | ||
var r = util.parseAstTreeState(ast, 39, obj); | ||
var ast = handlebarsUtils.parseBranchStmt(obj.stmt); | ||
var r = handlebarsUtils.parseAstTreeState(ast, 39, obj); | ||
// a b d b f (1st branch) | ||
@@ -802,8 +605,8 @@ // a c d b f (1st branch) | ||
it("handlebars-utils - parse parallel Handlebars {{#if}} statement with {{else}} parseAstTreeState test", function() { | ||
it("handlebars-handlebarsUtilss - parse parallel Handlebars {{#if}} statement with {{else}} parseAstTreeState test", function() { | ||
var s = "<a href='{{#if xxx}} a {{#if}} b {{else}} c {{/if}} d {{#if}} b {{else}} c {{/if}} f {{else}} e {{#if}} f {{else}} g {{/if}} h {{#if}} 1 {{else}} 2 {{/if}} h {{/if}}'>"; | ||
var obj = util.extractBranchStmt(s, 9, true); | ||
var obj = handlebarsUtils.extractBranchStmt(s, 9, true); | ||
expect(obj.stmt).to.equal('{{#if xxx}} a {{#if}} b {{else}} c {{/if}} d {{#if}} b {{else}} c {{/if}} f {{else}} e {{#if}} f {{else}} g {{/if}} h {{#if}} 1 {{else}} 2 {{/if}} h {{/if}}'); | ||
var ast = util.parseBranchStmt(obj.stmt); | ||
var r = util.parseAstTreeState(ast, 39, obj); | ||
var ast = handlebarsUtils.parseBranchStmt(obj.stmt); | ||
var r = handlebarsUtils.parseAstTreeState(ast, 39, obj); | ||
// a b d b f (1st branch) | ||
@@ -821,8 +624,8 @@ // a c d b f (1st branch) | ||
it("handlebars-utils - parse basic Handlebars {{^msg}} statement parseAstTreeState test", function() { | ||
it("handlebars-handlebarsUtilss - parse basic Handlebars {{^msg}} statement parseAstTreeState test", function() { | ||
var s = "<a href='{{^msg}} a {{/msg}}'>"; | ||
var obj = util.extractBranchStmt(s, 9, true); | ||
var obj = handlebarsUtils.extractBranchStmt(s, 9, true); | ||
expect(obj.stmt).to.equal('{{^msg}} a {{/msg}}'); | ||
var ast = util.parseBranchStmt(obj.stmt); | ||
var r = util.parseAstTreeState(ast, 39, obj); | ||
var ast = handlebarsUtils.parseBranchStmt(obj.stmt); | ||
var r = handlebarsUtils.parseAstTreeState(ast, 39, obj); | ||
// a (1st branch) | ||
@@ -834,8 +637,8 @@ // b (2nd branch) | ||
it("handlebars-utils - parse basic Handlebars {{^msg}} statement with {{else}} parseAstTreeState test", function() { | ||
it("handlebars-handlebarsUtilss - parse basic Handlebars {{^msg}} statement with {{else}} parseAstTreeState test", function() { | ||
var s = "<a href='{{^msg}} a {{else}} b {{/msg}}'>"; | ||
var obj = util.extractBranchStmt(s, 9, true); | ||
var obj = handlebarsUtils.extractBranchStmt(s, 9, true); | ||
expect(obj.stmt).to.equal('{{^msg}} a {{else}} b {{/msg}}'); | ||
var ast = util.parseBranchStmt(obj.stmt); | ||
var r = util.parseAstTreeState(ast, 39, obj); | ||
var ast = handlebarsUtils.parseBranchStmt(obj.stmt); | ||
var r = handlebarsUtils.parseAstTreeState(ast, 39, obj); | ||
// a (1st branch) | ||
@@ -847,8 +650,8 @@ // b (2nd branch) | ||
it("handlebars-utils - parse nested Handlebars {{^msg}} statement parseAstTreeState test", function() { | ||
it("handlebars-handlebarsUtilss - parse nested Handlebars {{^msg}} statement parseAstTreeState test", function() { | ||
var s = "<a href='{{^msg}} a {{^msg}} b {{/msg}} c {{/msg}}'>"; | ||
var obj = util.extractBranchStmt(s, 9, true); | ||
var obj = handlebarsUtils.extractBranchStmt(s, 9, true); | ||
expect(obj.stmt).to.equal('{{^msg}} a {{^msg}} b {{/msg}} c {{/msg}}'); | ||
var ast = util.parseBranchStmt(obj.stmt); | ||
var r = util.parseAstTreeState(ast, 39, obj); | ||
var ast = handlebarsUtils.parseBranchStmt(obj.stmt); | ||
var r = handlebarsUtils.parseAstTreeState(ast, 39, obj); | ||
// a b c (1st branch) | ||
@@ -861,8 +664,8 @@ // a c (1st branch) | ||
it("handlebars-utils - parse nested Handlebars {{^msg}} statement with {{else}} parseAstTreeState test", function() { | ||
it("handlebars-handlebarsUtilss - parse nested Handlebars {{^msg}} statement with {{else}} parseAstTreeState test", function() { | ||
var s = "<a href='{{^msg}} a {{^msg}} b {{else}} c {{/msg}} d {{else}} e {{^msg}} f {{else}} g {{/msg}} h {{/msg}}'>"; | ||
var obj = util.extractBranchStmt(s, 9, true); | ||
var obj = handlebarsUtils.extractBranchStmt(s, 9, true); | ||
expect(obj.stmt).to.equal('{{^msg}} a {{^msg}} b {{else}} c {{/msg}} d {{else}} e {{^msg}} f {{else}} g {{/msg}} h {{/msg}}'); | ||
var ast = util.parseBranchStmt(obj.stmt); | ||
var r = util.parseAstTreeState(ast, 39, obj); | ||
var ast = handlebarsUtils.parseBranchStmt(obj.stmt); | ||
var r = handlebarsUtils.parseAstTreeState(ast, 39, obj); | ||
// a b d (1st branch) | ||
@@ -876,8 +679,8 @@ // a c d (1st branch) | ||
it("handlebars-utils - parse parallel Handlebars {{^msg}} statement parseAstTreeState test", function() { | ||
it("handlebars-handlebarsUtilss - parse parallel Handlebars {{^msg}} statement parseAstTreeState test", function() { | ||
var s = "<a href='{{^msg}} a {{^msg}} b {{else}} c {{/msg}} d {{^msg}} b {{else}} c {{/msg}} f {{else}} e {{^msg}} f {{else}} g {{/msg}} h {{/msg}}'>"; | ||
var obj = util.extractBranchStmt(s, 9, true); | ||
var obj = handlebarsUtils.extractBranchStmt(s, 9, true); | ||
expect(obj.stmt).to.equal('{{^msg}} a {{^msg}} b {{else}} c {{/msg}} d {{^msg}} b {{else}} c {{/msg}} f {{else}} e {{^msg}} f {{else}} g {{/msg}} h {{/msg}}'); | ||
var ast = util.parseBranchStmt(obj.stmt); | ||
var r = util.parseAstTreeState(ast, 39, obj); | ||
var ast = handlebarsUtils.parseBranchStmt(obj.stmt); | ||
var r = handlebarsUtils.parseAstTreeState(ast, 39, obj); | ||
// a b d b f (1st branch) | ||
@@ -893,8 +696,8 @@ // a c d b f (1st branch) | ||
it("handlebars-utils - parse parallel Handlebars {{^msg}} statement with {{else}} parseAstTreeState test", function() { | ||
it("handlebars-handlebarsUtilss - parse parallel Handlebars {{^msg}} statement with {{else}} parseAstTreeState test", function() { | ||
var s = "<a href='{{^msg}} a {{^msg}} b {{else}} c {{/msg}} d {{^msg}} b {{else}} c {{/msg}} f {{else}} e {{^msg}} f {{else}} g {{/msg}} h {{^msg}} 1 {{else}} 2 {{/msg}} h {{/msg}}'>"; | ||
var obj = util.extractBranchStmt(s, 9, true); | ||
var obj = handlebarsUtils.extractBranchStmt(s, 9, true); | ||
expect(obj.stmt).to.equal('{{^msg}} a {{^msg}} b {{else}} c {{/msg}} d {{^msg}} b {{else}} c {{/msg}} f {{else}} e {{^msg}} f {{else}} g {{/msg}} h {{^msg}} 1 {{else}} 2 {{/msg}} h {{/msg}}'); | ||
var ast = util.parseBranchStmt(obj.stmt); | ||
var r = util.parseAstTreeState(ast, 39, obj); | ||
var ast = handlebarsUtils.parseBranchStmt(obj.stmt); | ||
var r = handlebarsUtils.parseAstTreeState(ast, 39, obj); | ||
// a b d b f (1st branch) | ||
@@ -912,8 +715,8 @@ // a c d b f (1st branch) | ||
it("handlebars-utils - parse basic Handlebars {{#if xxx}} broken statement with {{else}} parseAstTreeState exception test", function() { | ||
it("handlebars-handlebarsUtilss - parse basic Handlebars {{#if xxx}} broken statement with {{else}} parseAstTreeState exception test", function() { | ||
var s = "<a href='{{#if xxx}} a {{else}} b'> {{/if}}'>"; | ||
var obj = util.extractBranchStmt(s, 9, true); | ||
var ast = util.parseBranchStmt(obj.stmt); | ||
var obj = handlebarsUtils.extractBranchStmt(s, 9, true); | ||
var ast = handlebarsUtils.parseBranchStmt(obj.stmt); | ||
try { | ||
var r = util.parseAstTreeState(ast, 39, obj); | ||
var r = handlebarsUtils.parseAstTreeState(ast, 39, obj); | ||
expect(false).to.equal(true); | ||
@@ -920,0 +723,0 @@ } catch (err) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
221019
64
3347
5
82
6