@@ -109,7 +109,7 @@ describe('utilities', function () {
109
109
info . value . should . equal ( obj . dimensions . units ) ;
110
110
info . name . should . equal ( 'units' ) ;
111
111
info . exists . should . be . true ;
112
- } ) ;
112
+ } ) ;
113
113
114
114
it ( 'should handle non-existent property' , function ( ) {
115
115
var info = gpi ( 'dimensions.size' , obj ) ;
@@ -118,7 +118,7 @@ describe('utilities', function () {
118
118
expect ( info . value ) . to . be . undefined ;
119
119
info . name . should . equal ( 'size' ) ;
120
120
info . exists . should . be . false ;
121
- } ) ;
121
+ } ) ;
122
122
123
123
it ( 'should handle array index' , function ( ) {
124
124
var info = gpi ( 'primes[2]' , obj ) ;
@@ -127,7 +127,7 @@ describe('utilities', function () {
127
127
info . value . should . equal ( obj . primes [ 2 ] ) ;
128
128
info . name . should . equal ( 2 ) ;
129
129
info . exists . should . be . true ;
130
- } ) ;
130
+ } ) ;
131
131
132
132
it ( 'should handle dimensional array' , function ( ) {
133
133
var info = gpi ( 'dimensions.lengths[2][1]' , obj ) ;
@@ -136,7 +136,7 @@ describe('utilities', function () {
136
136
info . value . should . equal ( obj . dimensions . lengths [ 2 ] [ 1 ] ) ;
137
137
info . name . should . equal ( 1 ) ;
138
138
info . exists . should . be . true ;
139
- } ) ;
139
+ } ) ;
140
140
141
141
it ( 'should handle out of bounds array index' , function ( ) {
142
142
var info = gpi ( 'dimensions.lengths[3]' , obj ) ;
@@ -180,13 +180,13 @@ describe('utilities', function () {
180
180
hp ( 1 , arr ) . should . be . true ;
181
181
hp ( 3 , arr ) . should . be . false ;
182
182
} ) ;
183
-
183
+
184
184
it ( 'should handle literal types' , function ( ) {
185
185
var s = 'string literal' ;
186
186
hp ( 'length' , s ) . should . be . true ;
187
187
hp ( 3 , s ) . should . be . true ;
188
188
hp ( 14 , s ) . should . be . false ;
189
-
189
+
190
190
hp ( 'foo' , 1 ) . should . be . false ;
191
191
} ) ;
192
192
@@ -342,7 +342,11 @@ describe('utilities', function () {
342
342
var obj = { } ;
343
343
_ . flag ( obj , 'message' , 'foo' ) ;
344
344
expect ( _ . getMessage ( obj , [ ] ) ) . to . contain ( 'foo' ) ;
345
+ } ) ;
346
+ } ) ;
345
347
348
+ it ( 'getMessage passed message as function' , function ( ) {
349
+ chai . use ( function ( _chai , _ ) {
346
350
var obj = { } ;
347
351
var msg = function ( ) { return "expected a to eql b" ; }
348
352
var negateMsg = function ( ) { return "expected a not to eql b" ; }
@@ -352,6 +356,67 @@ describe('utilities', function () {
352
356
} ) ;
353
357
} ) ;
354
358
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
+
355
420
it ( 'inspect with custom object-returning inspect()s' , function ( ) {
356
421
chai . use ( function ( _chai , _ ) {
357
422
var obj = {
0 commit comments