@@ -109,7 +109,7 @@ describe('utilities', function () {
109109 info . value . should . equal ( obj . dimensions . units ) ;
110110 info . name . should . equal ( 'units' ) ;
111111 info . exists . should . be . true ;
112- } ) ;
112+ } ) ;
113113
114114 it ( 'should handle non-existent property' , function ( ) {
115115 var info = gpi ( 'dimensions.size' , obj ) ;
@@ -118,7 +118,7 @@ describe('utilities', function () {
118118 expect ( info . value ) . to . be . undefined ;
119119 info . name . should . equal ( 'size' ) ;
120120 info . exists . should . be . false ;
121- } ) ;
121+ } ) ;
122122
123123 it ( 'should handle array index' , function ( ) {
124124 var info = gpi ( 'primes[2]' , obj ) ;
@@ -127,7 +127,7 @@ describe('utilities', function () {
127127 info . value . should . equal ( obj . primes [ 2 ] ) ;
128128 info . name . should . equal ( 2 ) ;
129129 info . exists . should . be . true ;
130- } ) ;
130+ } ) ;
131131
132132 it ( 'should handle dimensional array' , function ( ) {
133133 var info = gpi ( 'dimensions.lengths[2][1]' , obj ) ;
@@ -136,7 +136,7 @@ describe('utilities', function () {
136136 info . value . should . equal ( obj . dimensions . lengths [ 2 ] [ 1 ] ) ;
137137 info . name . should . equal ( 1 ) ;
138138 info . exists . should . be . true ;
139- } ) ;
139+ } ) ;
140140
141141 it ( 'should handle out of bounds array index' , function ( ) {
142142 var info = gpi ( 'dimensions.lengths[3]' , obj ) ;
@@ -180,13 +180,13 @@ describe('utilities', function () {
180180 hp ( 1 , arr ) . should . be . true ;
181181 hp ( 3 , arr ) . should . be . false ;
182182 } ) ;
183-
183+
184184 it ( 'should handle literal types' , function ( ) {
185185 var s = 'string literal' ;
186186 hp ( 'length' , s ) . should . be . true ;
187187 hp ( 3 , s ) . should . be . true ;
188188 hp ( 14 , s ) . should . be . false ;
189-
189+
190190 hp ( 'foo' , 1 ) . should . be . false ;
191191 } ) ;
192192
@@ -342,7 +342,11 @@ describe('utilities', function () {
342342 var obj = { } ;
343343 _ . flag ( obj , 'message' , 'foo' ) ;
344344 expect ( _ . getMessage ( obj , [ ] ) ) . to . contain ( 'foo' ) ;
345+ } ) ;
346+ } ) ;
345347
348+ it ( 'getMessage passed message as function' , function ( ) {
349+ chai . use ( function ( _chai , _ ) {
346350 var obj = { } ;
347351 var msg = function ( ) { return "expected a to eql b" ; }
348352 var negateMsg = function ( ) { return "expected a not to eql b" ; }
@@ -352,6 +356,67 @@ describe('utilities', function () {
352356 } ) ;
353357 } ) ;
354358
359+ it ( 'getMessage template tag substitution' , function ( ) {
360+ chai . use ( function ( _chai , _ ) {
361+ var objName = 'trojan horse' ;
362+ var actualValue = 'an actual value' ;
363+ var expectedValue = 'an expected value' ;
364+ [
365+ // known template tags
366+ {
367+ template : 'one #{this} two' ,
368+ expected : 'one \'' + objName + '\' two'
369+ } ,
370+ {
371+ template : 'one #{act} two' ,
372+ expected : 'one \'' + actualValue + '\' two'
373+ } ,
374+ {
375+ template : 'one #{exp} two' ,
376+ expected : 'one \'' + expectedValue + '\' two'
377+ } ,
378+ // unknown template tag
379+ {
380+ template : 'one #{unknown} two' ,
381+ expected : 'one #{unknown} two'
382+ } ,
383+ // repeated template tag
384+ {
385+ template : '#{this}#{this}' ,
386+ expected : '\'' + objName + '\'\'' + objName + '\''
387+ } ,
388+ // multiple template tags in different order
389+ {
390+ template : '#{this}#{act}#{exp}#{act}#{this}' ,
391+ expected : '\'' + objName + '\'\'' + actualValue + '\'\'' + expectedValue + '\'\'' + actualValue + '\'\'' + objName + '\''
392+ } ,
393+ // immune to string.prototype.replace() `$` substitution
394+ {
395+ objName : '-$$-' ,
396+ template : '#{this}' ,
397+ expected : '\'-$$-\''
398+ } ,
399+ {
400+ actualValue : '-$$-' ,
401+ template : '#{act}' ,
402+ expected : '\'-$$-\''
403+ } ,
404+ {
405+ expectedValue : '-$$-' ,
406+ template : '#{exp}' ,
407+ expected : '\'-$$-\''
408+ }
409+ ] . forEach ( function ( config ) {
410+ config . objName = config . objName || objName ;
411+ config . actualValue = config . actualValue || actualValue ;
412+ config . expectedValue = config . expectedValue || expectedValue ;
413+ var obj = { _obj : config . actualValue } ;
414+ _ . flag ( obj , 'object' , config . objName ) ;
415+ expect ( _ . getMessage ( obj , [ null , config . template , null , config . expectedValue ] ) ) . to . equal ( config . expected ) ;
416+ } ) ;
417+ } ) ;
418+ } ) ;
419+
355420 it ( 'inspect with custom object-returning inspect()s' , function ( ) {
356421 chai . use ( function ( _chai , _ ) {
357422 var obj = {
0 commit comments