Look up functions by name to make tests more directly analogous to user view
git-svn-id: http://google-refine.googlecode.com/svn/trunk@2252 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
e1184003df
commit
884d0ea8d4
@ -43,11 +43,17 @@ import org.testng.annotations.BeforeTest;
|
|||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.refine.expr.EvalError;
|
import com.google.refine.expr.EvalError;
|
||||||
import com.google.refine.expr.functions.strings.ToTitlecase;
|
import com.google.refine.grel.ControlFunctionRegistry;
|
||||||
import com.google.refine.grel.Function;
|
import com.google.refine.grel.Function;
|
||||||
import com.google.refine.tests.RefineTest;
|
import com.google.refine.tests.RefineTest;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for string up/low/title case functions.
|
||||||
|
* (A very brief start so far)
|
||||||
|
*
|
||||||
|
* @author Tom Morris <tfmorris@gmail.com>
|
||||||
|
*/
|
||||||
public class StringCaseTests extends RefineTest {
|
public class StringCaseTests extends RefineTest {
|
||||||
|
|
||||||
static Properties bindings;
|
static Properties bindings;
|
||||||
@ -68,23 +74,37 @@ public class StringCaseTests extends RefineTest {
|
|||||||
bindings = null;
|
bindings = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lookup a control function by name and invoke it with a variable number of args
|
||||||
|
*/
|
||||||
|
private static Object invoke(String name,Object... args) {
|
||||||
|
// registry uses static initializer, so no need to set it up
|
||||||
|
Function function = ControlFunctionRegistry.getFunction(name);
|
||||||
|
if (function == null) {
|
||||||
|
throw new IllegalArgumentException("Unknown function "+name);
|
||||||
|
}
|
||||||
|
if (args == null) {
|
||||||
|
return function.call(bindings,new Object[0]);
|
||||||
|
} else {
|
||||||
|
return function.call(bindings,args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToTitlecaseInvalidParams() {
|
public void testToTitlecaseInvalidParams() {
|
||||||
Function fut = new ToTitlecase();
|
Assert.assertTrue(invoke("toTitlecase") instanceof EvalError);
|
||||||
Assert.assertTrue(fut.call(bindings, new Object[]{}) instanceof EvalError);
|
Assert.assertTrue(invoke("toTitlecase", "one","two") instanceof EvalError);
|
||||||
Assert.assertTrue(fut.call(bindings, new Object[]{"one","two"}) instanceof EvalError);
|
Assert.assertTrue(invoke("toTitlecase", "one","two","three") instanceof EvalError);
|
||||||
Assert.assertTrue(fut.call(bindings, new Object[]{"one","two","three"}) instanceof EvalError);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToTitlecase() {
|
public void testToTitlecase() {
|
||||||
Function fut = new ToTitlecase();
|
Assert.assertEquals((String)(invoke("toTitlecase", "one")),"One");
|
||||||
Assert.assertEquals((String)(fut.call(bindings, new Object[]{"one"})),"One");
|
Assert.assertEquals((String)(invoke("toTitlecase", "ONE")),"One");
|
||||||
Assert.assertEquals((String)(fut.call(bindings, new Object[]{"ONE"})),"One");
|
Assert.assertEquals((String)(invoke("toTitlecase", "one two three")),"One Two Three");
|
||||||
Assert.assertEquals((String)(fut.call(bindings, new Object[]{"one two three"})),"One Two Three");
|
Assert.assertEquals((String)(invoke("toTitlecase", "C.R. SANDIDGE WINES, INC.")),"C.R. Sandidge Wines, Inc.");
|
||||||
Assert.assertEquals((String)(fut.call(bindings, new Object[]{"C.R. SANDIDGE WINES, INC."})),"C.R. Sandidge Wines, Inc.");
|
// Assert.assertEquals((String)(invoke("toTitlecase", "C.R. SANDIDGE WINES, INC.",",. ")),"C.R. Sandidge Wines, Inc.");
|
||||||
// Assert.assertEquals((String)(fut.call(bindings, new Object[]{"C.R. SANDIDGE WINES, INC.",",. "})),"C.R. Sandidge Wines, Inc.");
|
// Assert.assertEquals((String)(invoke("toTitlecase", "one-two-three","-")),"One-Two-Three");
|
||||||
// Assert.assertEquals((String)(fut.call(bindings, new Object[]{"one-two-three","-"})),"One-Two-Three");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user