Explorar el Código

added more tests for customReplace

Nicolas Cannasse hace 13 años
padre
commit
7d907e79ff
Se han modificado 1 ficheros con 12 adiciones y 0 borrados
  1. 12 0
      tests/unit/TestEReg.hx

+ 12 - 0
tests/unit/TestEReg.hx

@@ -60,6 +60,18 @@ class TestEReg extends Test {
 		eq( block.split(test).length, 5 );
 		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+(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" );
+		
+		// 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" );
+		
+		
 		#end
 	}