|
@@ -61,15 +61,41 @@ class TestEReg extends Test {
|
|
|
eq( '"' + block.split(test).join('","') + '"', '"","test",".blah","something:someval",""' );
|
|
|
|
|
|
// test custom replace
|
|
|
- eq( ~/a+/g.customReplace("aaabacx", function(r) return "[" + r.matched(0).substr(1) + "]") , "[aa]b[]cx" );
|
|
|
- eq( ~/a+/.customReplace("aaabacx", function(r) return "[" + r.matched(0).substr(1) + "]") , "[aa]b[]cx" ); // same without 'g'
|
|
|
+ eq( ~/a+/g.map("aaabacx", function(r) return "[" + r.matched(0).substr(1) + "]") , "[aa]b[]cx" );
|
|
|
+ eq( ~/a+/.map("aaabacx", function(r) return "[" + r.matched(0).substr(1) + "]") , "[aa]bacx" ); // same without 'g'
|
|
|
|
|
|
- eq( ~/a+(b*)/g.customReplace("aaabacx", function(r) return "[" + r.matched(1) + "]") , "[b][]cx" );
|
|
|
- eq( ~/a+/g.customReplace("aaabacx", function(r) return "[" + r.matchedRight() + "]") , "[bacx]b[cx]cx" );
|
|
|
+ eq( ~/a+(b*)/g.map("aaabacx", function(r) return "[" + r.matched(1) + "]") , "[b][]cx" );
|
|
|
+ eq( ~/a+/g.map("aaabacx", function(r) return "[" + r.matchedRight() + "]") , "[bacx]b[cx]cx" );
|
|
|
|
|
|
// we need to change our default customReplace implementation to fix that case
|
|
|
// the best is to add a matchSub(s,pos,len)
|
|
|
- eq( ~/a+/g.customReplace("aaabacx", function(r) return "[" + r.matchedLeft() + "]") , "[]b[aaab]cx" );
|
|
|
+ eq( ~/a+/g.map("aaabacx", function(r) return "[" + r.matchedLeft() + "]") , "[]b[aaab]cx" );
|
|
|
+
|
|
|
+ // subsequent tests
|
|
|
+ var r = ~/a+/g;
|
|
|
+ eq(r.map("aaabacx", function(r) return "[" + r.matchedLeft() + "]") , "[]b[aaab]cx");
|
|
|
+ eq(r.map("aaabacx", function(r) return "[" + r.matchedLeft() + "]") , "[]b[aaab]cx");
|
|
|
+
|
|
|
+ // matchSub
|
|
|
+ var r = ~/a+/;
|
|
|
+ t(r.matchSub("abab", 0));
|
|
|
+ eq(r.matchedRight(), "bab");
|
|
|
+ t(r.matchSub("abab", 1));
|
|
|
+ eq(r.matchedRight(), "b");
|
|
|
+ eq(r.matchedLeft(), "ab");
|
|
|
+ // same again to make sure state is correct
|
|
|
+ t(r.matchSub("abab", 0));
|
|
|
+ eq(r.matchedRight(), "bab");
|
|
|
+ t(r.matchSub("abab", 1));
|
|
|
+ eq(r.matchedRight(), "b");
|
|
|
+ eq(r.matchedLeft(), "ab");
|
|
|
+ // length
|
|
|
+ f(r.matchSub("bbaa", 0, 1));
|
|
|
+ f(r.matchSub("bbaa", 0, 2));
|
|
|
+ f(r.matchSub("bbaa", 1, 1));
|
|
|
+ t(r.matchSub("bbaa", 2, 1));
|
|
|
+ eq(r.matchedLeft(), "bb");
|
|
|
+ eq(r.matchedRight(), "a");
|
|
|
|
|
|
// this one creates infinite loops on too most of the platforms ! TOFIX !
|
|
|
// eq( ~/x?/g.customReplace("aaabacx", function(r) return "[" + r.matched(0)+ "]") , "[]a[]a[]a[]b[]a[]c[][x]" );
|