Merge pull request #3112 from tfmorris/2997-unescape-csv-test

Add test for changed Apache unescape("csv") behavior - Fixes #2997
This commit is contained in:
Tom Morris 2020-08-23 14:58:37 -04:00 committed by GitHub
commit c8a721a10b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
186 changed files with 317 additions and 1098 deletions

View File

@ -46,7 +46,7 @@ public class Trim implements Function {
if (args.length == 1) {
Object s1 = args[0];
if (s1 != null && s1 instanceof String) {
return CharMatcher.WHITESPACE.trimFrom((String) s1);
return CharMatcher.whitespace().trimFrom((String) s1);
}
}
return new EvalError("Invalid parameters");

View File

@ -43,6 +43,7 @@ import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.apache.commons.io.FileUtils;
import org.powermock.modules.testng.PowerMockTestCase;
@ -57,6 +58,8 @@ import com.fasterxml.jackson.databind.node.BooleanNode;
import com.fasterxml.jackson.databind.node.IntNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import com.google.refine.grel.ControlFunctionRegistry;
import com.google.refine.grel.Function;
import com.google.refine.importers.SeparatorBasedImporter;
import com.google.refine.importing.ImportingJob;
import com.google.refine.importing.ImportingManager;
@ -75,6 +78,8 @@ import edu.mit.simile.butterfly.ButterflyModule;
*/
public class RefineTest extends PowerMockTestCase {
protected static Properties bindings = null;
protected Logger logger;
boolean testFailed;
@ -308,6 +313,30 @@ public class RefineTest extends PowerMockTestCase {
verify(options, times(1)).get(name);
}
/**
* Lookup a control function by name and invoke it with a variable number of args
*/
protected static Object invoke(String name, Object... args) {
// registry uses static initializer, so no need to set it up
Function function = ControlFunctionRegistry.getFunction(name);
if (bindings == null) {
bindings = new Properties();
}
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);
}
}
@AfterMethod
public void TearDown() throws Exception {
bindings = null;
}
protected ButterflyModule getCoreModule() {
ButterflyModule coreModule = mock(ButterflyModule.class);
when(coreModule.getName()).thenReturn("core");

View File

@ -38,7 +38,6 @@ import javax.servlet.http.HttpServletRequest;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.Command;
import com.google.refine.model.Project;
/**

View File

@ -1,5 +1,5 @@
package com.google.refine.commands;
import com.google.refine.commands.CommandTestBase;
import java.io.IOException;
import javax.servlet.ServletException;

View File

@ -1,6 +1,5 @@
package com.google.refine.commands;
import com.google.refine.commands.CommandTestBase;
import java.io.IOException;
import javax.servlet.ServletException;

View File

@ -18,7 +18,6 @@ import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.google.refine.browsing.facets.ScatterplotFacet;
import com.google.refine.commands.Command;
import com.google.refine.commands.browsing.GetScatterplotCommand;
import com.google.refine.util.ParsingUtilities;
public class ScatterplotDrawCommandTests {

View File

@ -8,7 +8,6 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.google.refine.commands.CommandTestBase;
import com.google.refine.commands.cell.JoinMultiValueCellsCommand;
public class JoinMultiValueCellsCommandTests extends CommandTestBase {

View File

@ -33,8 +33,6 @@ import javax.servlet.ServletException;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.google.refine.commands.expr.GetExpressionHistoryCommand;
public class GetExpressionHistoryCommandTests extends ExpressionCommandTestBase {
@BeforeMethod

View File

@ -33,8 +33,6 @@ import javax.servlet.ServletException;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.google.refine.commands.expr.GetStarredExpressionsCommand;
public class GetStarredExpressionsCommandTests extends ExpressionCommandTestBase {
@BeforeMethod

View File

@ -3,7 +3,6 @@ package com.google.refine.commands.expr;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.mock;
import com.google.refine.ProjectManager;
import com.google.refine.ProjectManagerStub;
import com.google.refine.commands.Command;
import com.google.refine.commands.CommandTestBase;
import com.google.refine.preference.PreferenceStore;

View File

@ -59,7 +59,6 @@ import com.google.refine.ProjectManager;
import com.google.refine.ProjectMetadata;
import com.google.refine.RefineTest;
import com.google.refine.commands.Command;
import com.google.refine.commands.project.SetProjectMetadataCommand;
import com.google.refine.model.Project;
import com.google.refine.util.ParsingUtilities;

View File

@ -51,7 +51,6 @@ import org.testng.annotations.Test;
import com.google.refine.RefineTest;
import com.google.refine.browsing.Engine;
import com.google.refine.exporters.CsvExporter;
import com.google.refine.model.Cell;
import com.google.refine.model.Column;
import com.google.refine.model.ModelException;

View File

@ -54,8 +54,6 @@ import com.google.refine.ProjectManagerStub;
import com.google.refine.ProjectMetadata;
import com.google.refine.RefineTest;
import com.google.refine.browsing.Engine;
import com.google.refine.exporters.HtmlTableExporter;
import com.google.refine.exporters.WriterExporter;
import com.google.refine.model.Cell;
import com.google.refine.model.Column;
import com.google.refine.model.ModelException;

View File

@ -52,8 +52,6 @@ import com.google.refine.ProjectManagerStub;
import com.google.refine.ProjectMetadata;
import com.google.refine.RefineTest;
import com.google.refine.browsing.Engine;
import com.google.refine.exporters.TemplatingExporter;
import com.google.refine.exporters.WriterExporter;
import com.google.refine.model.Cell;
import com.google.refine.model.Column;
import com.google.refine.model.ModelException;

View File

@ -51,7 +51,6 @@ import org.testng.annotations.Test;
import com.google.refine.RefineTest;
import com.google.refine.browsing.Engine;
import com.google.refine.exporters.CsvExporter;
import com.google.refine.model.Cell;
import com.google.refine.model.Column;
import com.google.refine.model.ModelException;

View File

@ -58,8 +58,6 @@ import com.google.refine.ProjectManagerStub;
import com.google.refine.ProjectMetadata;
import com.google.refine.RefineTest;
import com.google.refine.browsing.Engine;
import com.google.refine.exporters.StreamExporter;
import com.google.refine.exporters.XlsExporter;
import com.google.refine.model.Cell;
import com.google.refine.model.Column;
import com.google.refine.model.ModelException;

View File

@ -61,8 +61,6 @@ import com.google.refine.ProjectManagerStub;
import com.google.refine.ProjectMetadata;
import com.google.refine.RefineTest;
import com.google.refine.browsing.Engine;
import com.google.refine.exporters.StreamExporter;
import com.google.refine.exporters.XlsExporter;
import com.google.refine.model.Cell;
import com.google.refine.model.Column;
import com.google.refine.model.ModelException;

View File

@ -28,7 +28,6 @@ package com.google.refine.expr;
import org.testng.annotations.Test;
import com.google.refine.expr.EvalError;
import com.google.refine.util.TestUtils;
public class EvalErrorTests {

View File

@ -40,7 +40,6 @@ import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.refine.RefineTest;
import com.google.refine.expr.ExpressionUtils;
public class ExpressionUtilsTests extends RefineTest {

View File

@ -44,15 +44,11 @@ import org.testng.annotations.Test;
import com.google.refine.RefineTest;
import com.google.refine.expr.EvalError;
import com.google.refine.expr.functions.Coalesce;
import com.google.refine.grel.ControlFunctionRegistry;
import com.google.refine.grel.Function;
import com.google.refine.util.TestUtils;
public class CoalesceTests extends RefineTest {
private static Properties bindings;
private static final Integer[] ZERO_TO_TWO = new Integer[] {0, 1, 2};
@Override
@ -71,22 +67,6 @@ public class CoalesceTests extends RefineTest {
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
public void testCoalesceInvalidParams() {
Assert.assertTrue(invoke("coalesce") instanceof EvalError);

View File

@ -41,8 +41,6 @@ import com.google.refine.expr.EvalError;
import com.google.refine.expr.HasFieldsListImpl;
import com.google.refine.expr.WrappedCell;
import com.google.refine.expr.WrappedRow;
import com.google.refine.grel.ControlFunctionRegistry;
import com.google.refine.grel.Function;
import com.google.refine.model.Cell;
import com.google.refine.model.Project;
import com.google.refine.model.Row;
@ -52,7 +50,6 @@ import com.google.refine.util.TestUtils;
* Test cases for cross function.
*/
public class CrossTests extends RefineTest {
static Properties bindings;
private static OffsetDateTime dateTimeValue = OffsetDateTime.parse("2017-05-12T05:45:00+00:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME);
@Override
@ -374,22 +371,6 @@ public class CrossTests extends RefineTest {
"cross expects a cell or value, a project name to look up (optional), and a column name in that project (optional)");
}
/**
* 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
public void serializeCross() {
String json = "{\"description\":\"Looks up the given value in the target column of the target project, returns an array of matched rows. Two values match if and only if they have the same string representation. " +

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.FacetCount;
import com.google.refine.util.TestUtils;
public class FacetCountTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.Get;
import com.google.refine.util.TestUtils;
public class GetTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.HasField;
import com.google.refine.util.TestUtils;
public class HasFieldTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.Jsonize;
import com.google.refine.util.TestUtils;
public class JsonizeTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.Length;
import com.google.refine.util.TestUtils;
public class LengthTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.Slice;
import com.google.refine.util.TestUtils;
public class SliceTests {

View File

@ -26,16 +26,85 @@
******************************************************************************/
package com.google.refine.expr.functions;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.time.OffsetDateTime;
import java.util.TimeZone;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.ToDate;
import com.google.refine.RefineTest;
import com.google.refine.expr.EvalError;
import com.google.refine.expr.util.CalendarParser;
import com.google.refine.expr.util.CalendarParserException;
import com.google.refine.util.TestUtils;
public class ToDateTests {
public class ToDateTests extends RefineTest {
@Test
public void serializeToDate() {
String json = "{\"description\":\"Returns o converted to a date object, you can hint if the day or the month is listed first, or give an ordered list of possible formats using this syntax: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html\",\"params\":\"o, boolean month_first / format1, format2, ... (all optional)\",\"returns\":\"date\"}";
TestUtils.isSerializedTo(new ToDate(), json);
}
@Test
public void testToDate() throws CalendarParserException {
TimeZone originalTimeZone = TimeZone.getDefault();
try {
// Inject a fixed non-UTC timezone
TimeZone.setDefault(TimeZone.getTimeZone("JST"));
assertTrue(invoke("toDate") instanceof EvalError);
assertTrue(invoke("toDate", (Object) null) instanceof EvalError);
assertTrue(invoke("toDate", "") instanceof EvalError);
assertTrue(invoke("toDate", 1.0) instanceof EvalError);
assertTrue(invoke("toDate", "2012-03-01", "xxx") instanceof EvalError); // bad format string
assertTrue(invoke("toDate", "2012-03-01", 1L) instanceof EvalError); // non-string format arg
assertTrue(invoke("toDate", "P1M") instanceof EvalError); // Durations aren't supported
assertTrue(invoke("toDate", "2012-03-01") instanceof OffsetDateTime);
assertEquals(invoke("toDate", "2012-03-01"),CalendarParser.parseAsOffsetDateTime("2012-03-01"));
//parse as 'month first' date with and without explicit 'true' parameter
assertEquals(invoke("toDate", "01/03/2012"),CalendarParser.parseAsOffsetDateTime("2012-01-03"));
assertEquals(invoke("toDate", "01/03/2012",true),CalendarParser.parseAsOffsetDateTime("2012-01-03"));
//parse as 'month first' date with 'false' parameter
assertEquals(invoke("toDate", "01/03/2012",false),CalendarParser.parseAsOffsetDateTime("2012-03-01"));
//parse as 'month first' date without 'false' parameter but with format specified
assertEquals(invoke("toDate", "01/03/2012","dd/MM/yyyy"),CalendarParser.parseAsOffsetDateTime("2012-03-01"));
assertEquals(invoke("toDate", "2012-03-01","yyyy-MM-dd"),CalendarParser.parseAsOffsetDateTime("2012-03-01"));
//Two digit year
assertEquals(invoke("toDate", "02-02-01"),CalendarParser.parseAsOffsetDateTime("2001-02-02"));
// Multiple format strings should get tried sequentially until one succeeds or all are exhausted
assertEquals(invoke("toDate", "2012-03-01","MMM","yyyy-MM-dd"), CalendarParser.parseAsOffsetDateTime("2012-03-01"));
// Boolean argument combined with Multiple format strings
assertEquals(invoke("toDate", "01/03/2012",false, "MMM","yyyy-MM-dd","MM/dd/yyyy"), CalendarParser.parseAsOffsetDateTime("2012-03-01"));
// First string can be a locale identifier instead of a format string
assertEquals(invoke("toDate", "2013-06-01","zh"), CalendarParser.parseAsOffsetDateTime("2013-06-01"));
assertEquals(invoke("toDate", "01-六月-2013","zh","dd-MMM-yyyy"), CalendarParser.parseAsOffsetDateTime("2013-06-01"));
assertEquals(invoke("toDate", "01-六月-2013", "zh-CN", "dd-MMM-yyyy"), CalendarParser.parseAsOffsetDateTime("2013-06-01"));
assertEquals(invoke("toDate", "01-六月-2013", "zh", "MMM-dd-yyyy", "dd-MMM-yyyy"), CalendarParser.parseAsOffsetDateTime("2013-06-01"));
// If a long, convert to string
assertEquals(invoke("toDate", (long) 2012), invoke("toDate", "2012-01-01"));
// If already a date, leave it alone
assertEquals(invoke("toDate", CalendarParser.parseAsOffsetDateTime("2012-03-01")),CalendarParser.parseAsOffsetDateTime("2012-03-01"));
// FIXME: Date/times without timezone info were interpreted as local up until May 2018 at which point they switch to UTC
// assertEquals(invoke("toDate", "2013-06-01T13:12:11"), CalendarParser.parseAsOffsetDateTime("2013-06-01 13:12:11"));
// These match current behavior, but would fail with the historic (pre-2018) behavior
assertEquals(invoke("toDate", "2013-06-01T13:12:11Z"), CalendarParser.parseAsOffsetDateTime("2013-06-01 13:12:11"));
assertEquals(invoke("toDate", "2013-06-01Z"), CalendarParser.parseAsOffsetDateTime("2013-06-01"));
// TODO: more tests for datetimes with timezones and/or offsets
// assertEquals(invoke("toDate", "2013-06-01T13:12:11+06:00"), CalendarParser.parseAsOffsetDateTime("2013-06-01 13:12:11"));
} finally {
TimeZone.setDefault(originalTimeZone);
}
}
}

View File

@ -33,11 +33,12 @@ import java.util.Properties;
import org.testng.annotations.Test;
import com.google.refine.RefineTest;
import com.google.refine.expr.EvalError;
import com.google.refine.grel.Function;
import com.google.refine.util.TestUtils;
public class ToNumberTests {
public class ToNumberTests extends RefineTest {
private static final Double EPSILON = 0.000001;
static Properties bindings = new Properties();
@ -56,5 +57,20 @@ public class ToNumberTests {
assertTrue((Double)f.call(bindings, new Object[] {"12345.6789"}) - Double.valueOf(12345.6789) < EPSILON);
assertTrue(f.call(bindings, new Object[] {"abc"}) instanceof EvalError);
}
@Test
public void testToNumber() {
assertTrue(invoke("toNumber") instanceof EvalError);
assertTrue(invoke("toNumber", (Object) null) instanceof EvalError);
assertTrue(invoke("toNumber", "") instanceof EvalError);
assertTrue(invoke("toNumber", "string") instanceof EvalError);
assertEquals(invoke("toNumber", "0.0"), 0.0);
assertEquals(invoke("toNumber", "123"), Long.valueOf(123));
assertTrue(Math.abs((Double) invoke("toNumber", "123.456") - 123.456) < EPSILON);
assertTrue(Math.abs((Double) invoke("toNumber", "001.234") - 1.234) < EPSILON);
assertTrue(Math.abs((Double) invoke("toNumber", "1e2") - 100.0) < EPSILON);
assertTrue(Math.abs((Double) invoke("toNumber", Double.parseDouble("100.0")) - 100.0) < EPSILON);
}
}

View File

@ -26,16 +26,44 @@
******************************************************************************/
package com.google.refine.expr.functions;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.ToString;
import com.google.refine.RefineTest;
import com.google.refine.expr.EvalError;
import com.google.refine.expr.util.CalendarParser;
import com.google.refine.expr.util.CalendarParserException;
import com.google.refine.util.TestUtils;
public class ToStringTests {
public class ToStringTests extends RefineTest {
@Test
public void serializeToString() {
String json = "{\"description\":\"Returns o converted to a string\",\"params\":\"o, string format (optional)\",\"returns\":\"string\"}";
TestUtils.isSerializedTo(new ToString(), json);
}
@Test
public void testToString() throws CalendarParserException {
assertTrue(invoke("toString") instanceof EvalError);
assertEquals(invoke("toString", (Object) null), "");
assertEquals(invoke("toString", Long.valueOf(100)), "100");
assertEquals(invoke("toString", Double.valueOf(100.0)), "100.0");
assertEquals(invoke("toString", Double.valueOf(100.0),"%.0f"), "100");
String inputDate = "2013-06-01";
assertEquals(invoke("toString", CalendarParser.parseAsOffsetDateTime(inputDate)), "2013-06-01T00:00:00Z");
assertEquals(invoke("toString", CalendarParser.parseAsOffsetDateTime(inputDate), "yyyy-MM-dd"), "2013-06-01");
assertEquals(invoke("toString", CalendarParser.parseAsOffsetDateTime(inputDate), "yyyy/dd/MM"), "2013/01/06");
assertEquals(invoke("toString", CalendarParser.parseAsOffsetDateTime(inputDate), "yyyy-MM-dd hh:mm:ss"), "2013-06-01 12:00:00");
String inputDateTime = "2013-06-01 13:12:11";
assertEquals(invoke("toString", CalendarParser.parseAsOffsetDateTime(inputDateTime)), "2013-06-01T13:12:11Z");
assertEquals(invoke("toString", CalendarParser.parseAsOffsetDateTime(inputDateTime), "yyyy-MM-dd"), "2013-06-01");
assertEquals(invoke("toString", CalendarParser.parseAsOffsetDateTime(inputDateTime), "yyyy-MM-dd hh:mm:ss"), "2013-06-01 01:12:11");
assertEquals(invoke("toString", CalendarParser.parseAsOffsetDateTime(inputDateTime), "yyyy-MM-dd HH:mm:ss"), "2013-06-01 13:12:11");
}
}

View File

@ -42,14 +42,10 @@ import java.util.Properties;
import com.google.refine.RefineTest;
import com.google.refine.expr.EvalError;
import com.google.refine.expr.functions.Type;
import com.google.refine.grel.ControlFunctionRegistry;
import com.google.refine.grel.Function;
import com.google.refine.util.TestUtils;
public class TypeTests extends RefineTest {
private static Properties bindings;
static final List<String> listArray = Arrays.asList("v1", "v2", "v3");
private static OffsetDateTime dateTimeValue = OffsetDateTime.parse("2017-05-12T05:45:00+00:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME);
@ -69,22 +65,6 @@ public class TypeTests extends RefineTest {
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
public void testTypeInvalidParams() {
Assert.assertTrue(invoke("type") instanceof EvalError);

View File

@ -32,16 +32,11 @@ import java.util.List;
import java.util.Properties;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.refine.RefineTest;
import com.google.refine.expr.EvalError;
import com.google.refine.expr.functions.arrays.InArray;
import com.google.refine.grel.ControlFunctionRegistry;
import com.google.refine.grel.Function;
import com.google.refine.util.TestUtils;
public class InArrayTests extends RefineTest {
@ -51,16 +46,6 @@ public class InArrayTests extends RefineTest {
static final String stringArray[] = {"v1","v2","v3"};
@BeforeMethod
public void SetUp() {
bindings = new Properties();
}
@AfterMethod
public void TearDown() {
bindings = null;
}
@Test
public void serializeInArray() {
String json = "{\"description\":\"Checks if array a contains string s\",\"params\":\"array a, string s\",\"returns\":\"boolean\"}";
@ -93,18 +78,5 @@ public class InArrayTests extends RefineTest {
Assert.assertTrue((boolean) invoke("inArray", arrayNode, "v1"));
Assert.assertFalse((boolean) invoke("inArray", arrayNode, "v4"));
}
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);
}
}
}

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.arrays;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.arrays.Join;
import com.google.refine.util.TestUtils;
public class JoinTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.arrays;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.arrays.Reverse;
import com.google.refine.util.TestUtils;
public class ReverseTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.arrays;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.arrays.Sort;
import com.google.refine.util.TestUtils;
public class SortTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.arrays;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.arrays.Uniques;
import com.google.refine.util.TestUtils;
public class UniquesTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.booleans;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.booleans.And;
import com.google.refine.util.TestUtils;
public class AndTests {

View File

@ -33,24 +33,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.refine.expr.functions.booleans;
import java.io.IOException;
import java.util.Properties;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.refine.RefineTest;
import com.google.refine.expr.EvalError;
import com.google.refine.grel.ControlFunctionRegistry;
import com.google.refine.grel.Function;
import com.google.refine.model.Cell;
import com.google.refine.model.ModelException;
import com.google.refine.model.Project;
import com.google.refine.model.Row;
public class BooleanTests extends RefineTest {
@ -72,54 +61,12 @@ public class BooleanTests extends RefineTest {
{"xor","false","true","false","true"},
};
static private Properties bindings;
private Project project;
@Override
@BeforeTest
public void init() {
logger = LoggerFactory.getLogger(this.getClass());
}
@BeforeMethod
public void SetUp() throws IOException, ModelException {
bindings = new Properties();
project = createProjectWithColumns("BooleanTests", "Column A");
bindings.put("project", project);
// Five rows of a's and five of 1s
for (int i = 0; i < 10; i++) {
Row row = new Row(1);
row.setCell(0, new Cell(i < 5 ? "a":new Integer(1), null));
project.rows.add(row);
}
}
@AfterMethod
public void TearDown() {
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
public void testInvalidParams() {
for (String op : new String[] {"and","or","xor"}) {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.booleans;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.booleans.Not;
import com.google.refine.util.TestUtils;
public class NotTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.booleans;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.booleans.Or;
import com.google.refine.util.TestUtils;
public class OrTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.booleans;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.booleans.Xor;
import com.google.refine.util.TestUtils;
public class XorTests {

View File

@ -35,15 +35,10 @@ import java.util.TimeZone;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.refine.RefineTest;
import com.google.refine.expr.functions.date.DatePart;
import com.google.refine.grel.ControlFunctionRegistry;
import com.google.refine.grel.Function;
import com.google.refine.util.TestUtils;
@ -57,32 +52,6 @@ public class DatePartTests extends RefineTest {
logger = LoggerFactory.getLogger(this.getClass());
}
@BeforeMethod
public void SetUp() {
bindings = new Properties();
}
@AfterMethod
public void TearDown() {
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);
}
}
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd-HH:mm:ss.SSSSSSSSSX");
@Test

View File

@ -29,25 +29,18 @@ package com.google.refine.expr.functions.date;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Properties;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.refine.RefineTest;
import com.google.refine.expr.EvalError;
import com.google.refine.expr.functions.date.Inc;
import com.google.refine.grel.ControlFunctionRegistry;
import com.google.refine.grel.Function;
import com.google.refine.util.TestUtils;
public class IncTests extends RefineTest {
private static Properties bindings;
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd-HH:mm:ss.SSSSSSSSSX");
@Override
@ -55,33 +48,7 @@ public class IncTests extends RefineTest {
public void init() {
logger = LoggerFactory.getLogger(this.getClass());
}
@BeforeMethod
public void setUp() {
bindings = new Properties();
}
@AfterMethod
public void tearDown() {
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
public void testInc() {
OffsetDateTime source = OffsetDateTime.parse("20180510-23:55:44.000789000Z",

View File

@ -28,24 +28,17 @@ package com.google.refine.expr.functions.date;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Properties;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.refine.RefineTest;
import com.google.refine.expr.functions.date.Now;
import com.google.refine.grel.ControlFunctionRegistry;
import com.google.refine.grel.Function;
import com.google.refine.util.TestUtils;
public class NowTests extends RefineTest {
private static Properties bindings;
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd-HH:mm:ss.SSSSSSSSSX");
@Override
@ -53,33 +46,7 @@ public class NowTests extends RefineTest {
public void init() {
logger = LoggerFactory.getLogger(this.getClass());
}
@BeforeMethod
public void setUp() {
bindings = new Properties();
}
@AfterMethod
public void tearDown() {
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
public void testNow() {
// 2018-4-30 23:55:44

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.html;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.html.InnerHtml;
import com.google.refine.util.TestUtils;
public class InnerHtmlTests {

View File

@ -33,15 +33,10 @@ import java.util.Properties;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import com.google.refine.RefineTest;
import com.google.refine.expr.EvalError;
import com.google.refine.expr.functions.html.ParseHtml;
import com.google.refine.grel.ControlFunctionRegistry;
import com.google.refine.grel.Function;
import com.google.refine.util.TestUtils;
public class ParseHtmlTests extends RefineTest {
@ -65,32 +60,6 @@ public class ParseHtmlTests extends RefineTest {
logger = LoggerFactory.getLogger(this.getClass());
}
@BeforeMethod
public void SetUp() {
bindings = new Properties();
}
@AfterMethod
public void TearDown() {
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
public void serializeParseHtml() {
String json = "{\"description\":\"Parses a string as HTML\",\"params\":\"string s\",\"returns\":\"HTML object\"}";

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.ACos;
import com.google.refine.util.TestUtils;
public class ACosTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.ASin;
import com.google.refine.util.TestUtils;
public class ASinTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.ATan2;
import com.google.refine.util.TestUtils;
public class ATan2Tests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.ATan;
import com.google.refine.util.TestUtils;
public class ATanTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Abs;
import com.google.refine.util.TestUtils;
public class AbsTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Ceil;
import com.google.refine.util.TestUtils;
public class CeilTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Combin;
import com.google.refine.util.TestUtils;
public class CombinTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Cos;
import com.google.refine.util.TestUtils;
public class CosTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Cosh;
import com.google.refine.util.TestUtils;
public class CoshTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Degrees;
import com.google.refine.util.TestUtils;
public class DegreesTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Even;
import com.google.refine.util.TestUtils;
public class EvenTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Exp;
import com.google.refine.util.TestUtils;
public class ExpTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.FactN;
import com.google.refine.util.TestUtils;
public class FactNTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Fact;
import com.google.refine.util.TestUtils;
public class FactTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Floor;
import com.google.refine.util.TestUtils;
public class FloorTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.GreatestCommonDenominator;
import com.google.refine.util.TestUtils;
public class GreatestCommonDenominatorTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.LeastCommonMultiple;
import com.google.refine.util.TestUtils;
public class LeastCommonMultipleTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Ln;
import com.google.refine.util.TestUtils;
public class LnTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Log;
import com.google.refine.util.TestUtils;
public class LogTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Max;
import com.google.refine.util.TestUtils;
public class MaxTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Min;
import com.google.refine.util.TestUtils;
public class MinTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Mod;
import com.google.refine.util.TestUtils;
public class ModTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Multinomial;
import com.google.refine.util.TestUtils;
public class MultinomialTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Odd;
import com.google.refine.util.TestUtils;
public class OddTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Pow;
import com.google.refine.util.TestUtils;
public class PowTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Quotient;
import com.google.refine.util.TestUtils;
public class QuotientTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Radians;
import com.google.refine.util.TestUtils;
public class RadiansTests {

View File

@ -29,31 +29,15 @@ package com.google.refine.expr.functions.math;
import java.util.Properties;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.RandomNumber;
import com.google.refine.RefineTest;
import com.google.refine.expr.EvalError;
import com.google.refine.expr.functions.arrays.InArray;
import com.google.refine.grel.ControlFunctionRegistry;
import com.google.refine.grel.Function;
import com.google.refine.util.TestUtils;
public class RandomNumberTests extends RefineTest {
static Properties bindings;
@BeforeMethod
public void SetUp() {
bindings = new Properties();
}
@AfterMethod
public void TearDown() {
bindings = null;
}
@Test
public void serializeRandomNumber() {
String json = "{\"description\":\"Returns a pseudo-random integer between the lower and upper bound (inclusive)\",\"params\":\"number lower bound, number upper bound\",\"returns\":\"number\"}";
@ -73,18 +57,5 @@ public class RandomNumberTests extends RefineTest {
Object a = invoke("randomNumber", 1, 10);
Assert.assertTrue((int) a < 11 && (int) a > 0);
}
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);
}
}
}

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Round;
import com.google.refine.util.TestUtils;
public class RoundTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Sin;
import com.google.refine.util.TestUtils;
public class SinTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Sinh;
import com.google.refine.util.TestUtils;
public class SinhTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Sum;
import com.google.refine.util.TestUtils;
public class SumTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Tan;
import com.google.refine.util.TestUtils;
public class TanTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Tanh;
import com.google.refine.util.TestUtils;
public class TanhTests {

View File

@ -26,16 +26,29 @@
******************************************************************************/
package com.google.refine.expr.functions.strings;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.Chomp;
import com.google.refine.RefineTest;
import com.google.refine.util.TestUtils;
public class ChompTests {
public class ChompTests extends RefineTest {
@Test
public void serializeChomp() {
String json = "{\"description\":\"Removes separator from the end of str if it's there, otherwise leave it alone.\",\"params\":\"string str, string separator\",\"returns\":\"string\"}";
TestUtils.isSerializedTo(new Chomp(), json);
}
@Test
public void testChomp() {
// FIXME: These return null instead of an EvalError
// assertTrue(invoke("chomp") instanceof EvalError);
// assertTrue(invoke("chomp", "") instanceof EvalError);
// assertTrue(invoke("chomp", 1, 1) instanceof EvalError);
assertEquals(invoke("chomp", "test,", ","), "test");
assertEquals(invoke("chomp", "test,", ":"), "test,");
}
}

View File

@ -26,33 +26,20 @@
******************************************************************************/
package com.google.refine.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.Contains;
import com.google.refine.util.TestUtils;
import java.util.Properties;
import java.util.regex.Pattern;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.refine.RefineServlet;
import com.google.refine.RefineServletStub;
import com.google.refine.RefineTest;
import com.google.refine.grel.ControlFunctionRegistry;
import com.google.refine.grel.Function;
import com.google.refine.util.TestUtils;
/**
* Test cases for find function.
*/
public class ContainsTests extends RefineTest {
static Properties bindings;
@Override
@BeforeTest
@ -60,21 +47,6 @@ public class ContainsTests extends RefineTest {
logger = LoggerFactory.getLogger(this.getClass());
}
// dependencies
RefineServlet servlet;
@BeforeMethod
public void SetUp() {
bindings = new Properties();
servlet = new RefineServletStub();
}
@AfterMethod
public void TearDown() {
}
@Test
public void testContainsFunction() {
String value = "rose is a rose";
@ -84,27 +56,11 @@ public class ContainsTests extends RefineTest {
Assert.assertEquals(invoke("contains", value, "$"),false);
Assert.assertEquals(invoke("contains", value, "r.se"),false);
Assert.assertEquals(invoke("contains", value, "\\s+"),false);
// Input regex pattern in UI with : "/ /" , is intepreted as Pattern
// Input regex pattern in UI with : "/ /" , is interpreted as Pattern
Assert.assertEquals(invoke("contains", value, Pattern.compile("$")),true);
Assert.assertEquals(invoke("contains", value, Pattern.compile("\\s+")),true);
}
/**
* 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
public void serializeContains() {
String json = "{\"description\":\"Returns whether s contains frag\",\"params\":\"string s, string frag\",\"returns\":\"boolean\"}";

View File

@ -33,16 +33,11 @@ import java.util.Properties;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.refine.RefineTest;
import com.google.refine.expr.EvalError;
import com.google.refine.expr.functions.strings.Diff;
import com.google.refine.grel.ControlFunctionRegistry;
import com.google.refine.grel.Function;
import com.google.refine.util.TestUtils;
@ -73,32 +68,6 @@ public class DiffTests extends RefineTest {
odt8 = OffsetDateTime.of(1923, 4, 21, 12, 0, 0, 0, ZoneOffset.UTC);
}
@BeforeMethod
public void SetUp() {
bindings = new Properties();
}
@AfterMethod
public void TearDown() {
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
public void testDiffInvalidParams() {
Assert.assertTrue(invoke("diff") instanceof EvalError);

View File

@ -26,16 +26,25 @@
******************************************************************************/
package com.google.refine.expr.functions.strings;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.EndsWith;
import com.google.refine.RefineTest;
import com.google.refine.util.TestUtils;
public class EndsWithTests {
public class EndsWithTests extends RefineTest {
@Test
public void serializeEndsWith() {
String json = "{\"description\":\"Returns whether s ends with sub\",\"params\":\"string s, string sub\",\"returns\":\"boolean\"}";
TestUtils.isSerializedTo(new EndsWith(), json);
}
@Test
public void testStartsWith() {
assertTrue((Boolean) invoke("endsWith", "testString", "ing"));
assertFalse((Boolean) invoke("startsWith", "testString", "banana"));
}
}

View File

@ -26,16 +26,49 @@
******************************************************************************/
package com.google.refine.expr.functions.strings;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.Escape;
import com.google.refine.RefineTest;
import com.google.refine.util.TestUtils;
public class EscapeTests {
public class EscapeTests extends RefineTest {
@Test
public void serializeEscape() {
String json = "{\"description\":\"Escapes a string depending on the given escaping mode.\",\"params\":\"string s, string mode ['html','xml','csv','url','javascript']\",\"returns\":\"string\"}";
TestUtils.isSerializedTo(new Escape(), json);
}
@Test
public void testEscape() {
assertNull(invoke("escape"));
assertEquals(invoke("escape",null,"xml"), "");
assertEquals(invoke("escape", "mystring", "html"), "mystring");
assertEquals(invoke("escape", "mystring", "xml"), "mystring");
assertEquals(invoke("escape", "mystring", "csv"), "mystring");
assertEquals(invoke("escape", "mystring", "url"), "mystring");
assertEquals(invoke("escape", "mystring", "javascript"), "mystring");
assertEquals(invoke("escape", 1, "html") ,"1");
assertEquals(invoke("escape", 1, "xml"), "1");
assertEquals(invoke("escape", 1, "csv"), "1");
assertEquals(invoke("escape", 1, "url"), "1");
assertEquals(invoke("escape", 1, "javascript"), "1");
assertEquals(invoke("escape", Long.parseLong("1"), "html"), "1");
assertEquals(invoke("escape", Long.parseLong("1"), "xml"), "1");
assertEquals(invoke("escape", Long.parseLong("1"), "csv"), "1");
assertEquals(invoke("escape", Long.parseLong("1"), "url"), "1");
assertEquals(invoke("escape", Long.parseLong("1"), "javascript"), "1");
assertEquals(invoke("escape", Double.parseDouble("1.23"), "html"), "1.23");
assertEquals(invoke("escape", Double.parseDouble("1.23"), "xml"), "1.23");
assertEquals(invoke("escape", Double.parseDouble("1.23"), "csv"), "1.23");
assertEquals(invoke("escape", Double.parseDouble("1.23"), "url"), "1.23");
assertEquals(invoke("escape", Double.parseDouble("1.23"), "javascript"), "1.23");
assertEquals("\",\"", invoke("escape", ",", "csv")); // commas get quoted
assertEquals("\"\n\"", invoke("escape", "\n", "csv")); // newlines get quoted
assertEquals("\"\"\"\"", invoke("escape", "\"", "csv")); // quotes get doubled
}
}

View File

@ -31,17 +31,11 @@ import java.util.regex.Pattern;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.refine.RefineServlet;
import com.google.refine.RefineServletStub;
import com.google.refine.RefineTest;
import com.google.refine.expr.functions.strings.Find;
import com.google.refine.grel.ControlFunctionRegistry;
import com.google.refine.grel.Function;
import com.google.refine.util.TestUtils;
/**
@ -59,18 +53,6 @@ public class FindTests extends RefineTest {
// dependencies
RefineServlet servlet;
@BeforeMethod
public void SetUp() {
bindings = new Properties();
servlet = new RefineServletStub();
}
@AfterMethod
public void TearDown() {
}
@Test
public void findFunctionFindAllTest() throws Exception {
String[] matches = (String[]) invoke("find", "This is a test string for testing find.", "test");
@ -96,20 +78,4 @@ public class FindTests extends RefineTest {
String json = "{\"description\":\"Returns all the occurances of match given regular expression\",\"params\":\"string or regexp\",\"returns\":\"array of strings\"}";
TestUtils.isSerializedTo(new Find(), json);
}
/**
* 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);
}
}
}

View File

@ -35,15 +35,10 @@ import java.util.Properties;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.refine.RefineTest;
import com.google.refine.expr.functions.strings.Fingerprint;
import com.google.refine.grel.ControlFunctionRegistry;
import com.google.refine.grel.Function;
import com.google.refine.util.TestUtils;
@ -71,32 +66,6 @@ public class FingerprintTests extends RefineTest {
logger = LoggerFactory.getLogger(this.getClass());
}
@BeforeMethod
public void SetUp() {
bindings = new Properties();
}
@AfterMethod
public void TearDown() {
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
public void testInvalidParams() {
Assert.assertNull(invoke("fingerprint"));

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.IndexOf;
import com.google.refine.util.TestUtils;
public class IndexOfTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.LastIndexOf;
import com.google.refine.util.TestUtils;
public class LastIndexOfTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.MD5;
import com.google.refine.util.TestUtils;
public class MD5Tests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.Match;
import com.google.refine.util.TestUtils;
public class MatchTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.NGramFingerprint;
import com.google.refine.util.TestUtils;
public class NGramFingerprintTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.NGram;
import com.google.refine.util.TestUtils;
public class NGramTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.ParseJson;
import com.google.refine.util.TestUtils;
public class ParseJsonTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.Partition;
import com.google.refine.util.TestUtils;
public class PartitionTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.Phonetic;
import com.google.refine.util.TestUtils;
public class PhoneticTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.RPartition;
import com.google.refine.util.TestUtils;
public class RPartitionTests {

View File

@ -26,20 +26,13 @@
******************************************************************************/
package com.google.refine.expr.functions.strings;
import java.util.Properties;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.refine.RefineTest;
import com.google.refine.expr.EvalError;
import com.google.refine.expr.functions.strings.Range;
import com.google.refine.grel.ControlFunctionRegistry;
import com.google.refine.grel.Function;
import com.google.refine.util.TestUtils;
/**
@ -47,8 +40,6 @@ import com.google.refine.util.TestUtils;
*/
public class RangeTests extends RefineTest {
private static Properties bindings;
private static final Integer[] EMPTY_ARRAY = new Integer[0];
private static final Integer[] ONE_AND_THREE = new Integer[] {1, 3};
@ -67,32 +58,6 @@ public class RangeTests extends RefineTest {
logger = LoggerFactory.getLogger(this.getClass());
}
@BeforeMethod
public void setUp() {
bindings = new Properties();
}
@AfterMethod
public void tearDown() {
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
public void testRangeInvalidParams() {
// Test number of arguments

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.Reinterpret;
import com.google.refine.util.TestUtils;
public class ReinterpretTests {

View File

@ -28,7 +28,6 @@ package com.google.refine.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.ReplaceChars;
import com.google.refine.util.TestUtils;
public class ReplaceCharsTests {

Some files were not shown because too many files have changed in this diff Show More