Update Find and Tests
This commit is contained in:
parent
d6999de0da
commit
ac7b5a0a19
@ -46,7 +46,15 @@ public class Find implements Function {
|
|||||||
Object s = args[0];
|
Object s = args[0];
|
||||||
Object p = args[1];
|
Object p = args[1];
|
||||||
|
|
||||||
if (s != null && p != null && (p instanceof String || p instanceof Pattern)) {
|
if (s != null && p != null && p instanceof String) {
|
||||||
|
int fromIndex = 0;
|
||||||
|
while ((fromIndex = s.toString().indexOf(p.toString(), fromIndex)) != -1 ){
|
||||||
|
allMatches.add(p.toString());
|
||||||
|
fromIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s != null && p != null && p instanceof Pattern) {
|
||||||
|
|
||||||
Pattern pattern = (p instanceof String) ? Pattern.compile((String) p) : (Pattern) p;
|
Pattern pattern = (p instanceof String) ? Pattern.compile((String) p) : (Pattern) p;
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
package com.google.refine.tests.expr.functions;
|
package com.google.refine.tests.expr.functions;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
@ -82,8 +83,8 @@ public class FindFunctionTests extends RefineTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findFunctionFindAllTest2() throws Exception {
|
public void findFunctionFindRegexTest() throws Exception {
|
||||||
String[] matches = (String[]) invoke("find", "hello 123456 goodbye.", "\\d{6}|hello");
|
String[] matches = (String[]) invoke("find", "hello 123456 goodbye.", Pattern.compile("\\d{6}|hello"));
|
||||||
Assert.assertEquals(matches[0], "hello");
|
Assert.assertEquals(matches[0], "hello");
|
||||||
Assert.assertEquals(matches[1], "123456");
|
Assert.assertEquals(matches[1], "123456");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user