@@ -388,8 +388,9 @@ test("number operators", function(t){
388
388
t . end ( ) ;
389
389
} ) ;
390
390
391
- test ( "string operators" , function ( t ) {
391
+ ytest ( "string operators" , function * ( t ) {
392
392
var tf = _ . partial ( testFn , t ) ;
393
+ var ytf = mkTf ( t ) ;
393
394
394
395
tf ( "sprintf" , [ "Bob" ] , "" ) ;
395
396
tf ( "sprintf" , [ "Bob" , "Yo" ] , "Yo" ) ;
@@ -433,11 +434,34 @@ test("string operators", function(t){
433
434
tf ( "ord" , [ "bill" ] , 98 ) ;
434
435
tf ( "ord" , [ "0" ] , 48 ) ;
435
436
436
- tf ( "replace" , [ "william W." , / W / i] , "illiam W." ) ;
437
- tf ( "replace" , [ "William W." , / W / g, "B" ] , "Billiam B." ) ;
438
- tf ( "replace" , [ "Sa5m" , 5 , true ] , "Satruem" ) ;
439
- tf ( "replace" , [ [ false , void 0 ] , / (?: ) / ig] , "[Array]" ) ;
440
- tf ( "replace" , [ [ false , void 0 ] ] , [ false , void 0 ] ) ;
437
+ yield ytf ( "replace" , [ "william W." , / W / i] , "illiam W." ) ;
438
+ yield ytf ( "replace" , [ "William W." , / W / g, "B" ] , "Billiam B." ) ;
439
+ yield ytf ( "replace" , [ "Sa5m" , 5 , true ] , "Satruem" ) ;
440
+ yield ytf ( "replace" , [ [ false , void 0 ] , / (?: ) / ig] , "[Array]" ) ;
441
+ yield ytf ( "replace" , [ [ false , void 0 ] ] , [ false , void 0 ] ) ;
442
+
443
+ yield ytf ( "replace" , [ "start 1 then 2? 3-42 end" , / ( \d + ) / g, function ( match ) {
444
+ return ( parseInt ( match , 10 ) * 2 ) + "" ;
445
+ } ] , "start 2 then 4? 6-84 end" ) ;
446
+
447
+ yield ytf ( "replace" , [ "1 2 3" , / ( \d ) / g, function ( match , p1 , offset , string ) {
448
+ t . equals ( arguments . length , 4 ) ;
449
+ t . equals ( match , p1 ) ;
450
+ t . equals ( string . substring ( offset , offset + p1 . length ) , p1 ) ;
451
+ t . equals ( string , "1 2 3" ) ;
452
+ return ( parseInt ( match , 10 ) * 2 ) + "" ;
453
+ } ] , "2 4 6" ) ;
454
+
455
+ yield ytf ( "replace" , [ "000abc333???wat" , / ( [ a - z ] + ) ( \d * ) ( [ ^ \w ] * ) / , function ( match , p1 , p2 , p3 , offset , string ) {
456
+ t . equals ( arguments . length , 6 ) ;
457
+ t . equals ( match , "abc333???" ) ;
458
+ t . equals ( p1 , "abc" ) ;
459
+ t . equals ( p2 , "333" ) ;
460
+ t . equals ( p3 , "???" ) ;
461
+ t . equals ( offset , 3 ) ;
462
+ t . equals ( string , "000abc333???wat" ) ;
463
+ return "[" + p1 + " - " + p2 + " : " + p3 + "]" ;
464
+ } ] , "000[abc - 333 : ???]wat" ) ;
441
465
442
466
tf ( "split" , [ "a;b;3;4;" , / ; / ] , [ "a" , "b" , "3" , "4" , "" ] ) ;
443
467
tf ( "split" , [ "a;b;3;4;" , "" ] , [ "a" , ";" , "b" , ";" , "3" , ";" , "4" , ";" ] ) ;
@@ -458,8 +482,6 @@ test("string operators", function(t){
458
482
tf ( "substr" , [ void 0 , "Not an index" , 2 ] , "null" ) ;
459
483
460
484
tf ( "uc" , [ "loWer" ] , "LOWER" ) ;
461
-
462
- t . end ( ) ;
463
485
} ) ;
464
486
465
487
ytest ( "collection operators" , function * ( t ) {
0 commit comments