Merge pull request #1722 from OpenRefine/json-testing

Add serialization tests for most Jsonizable classes
This commit is contained in:
Antonin Delpeuch 2018-09-10 15:35:25 +01:00 committed by GitHub
commit 5a0304f363
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
173 changed files with 3398 additions and 489 deletions

View File

@ -45,7 +45,7 @@ import com.google.refine.Jsonizable;
import edu.mit.simile.butterfly.ButterflyModuleImpl; import edu.mit.simile.butterfly.ButterflyModuleImpl;
public class DatabaseModuleImpl extends ButterflyModuleImpl implements Jsonizable { public class DatabaseModuleImpl extends ButterflyModuleImpl {
private static final Logger logger = LoggerFactory.getLogger("DatabaseModuleImpl"); private static final Logger logger = LoggerFactory.getLogger("DatabaseModuleImpl");
@ -133,12 +133,5 @@ public class DatabaseModuleImpl extends ButterflyModuleImpl implements Jsonizabl
return ps; return ps;
} }
@Override
public void write(JSONWriter writer, Properties options)
throws JSONException {
// TODO Auto-generated method stub
}
} }

View File

@ -68,7 +68,7 @@ public class ReconMatchSpecificTopicOperation extends EngineDependentMassCellOpe
JSONObject match = obj.getJSONObject("match"); JSONObject match = obj.getJSONObject("match");
JSONArray types = obj.getJSONArray("types"); JSONArray types = match.getJSONArray("types");
String[] typeIDs = new String[types.length()]; String[] typeIDs = new String[types.length()];
for (int i = 0; i < typeIDs.length; i++) { for (int i = 0; i < typeIDs.length; i++) {
typeIDs[i] = types.getString(i); typeIDs[i] = types.getString(i);

View File

@ -33,6 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.refine.util; package com.google.refine.util;
import java.io.StringWriter;
import java.io.Writer;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
@ -42,12 +44,15 @@ import java.util.Calendar;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.JSONWriter; import org.json.JSONWriter;
import com.google.refine.Jsonizable;
public class JSONUtilities { public class JSONUtilities {
static public JSONObject getObject(JSONObject obj, String key) { static public JSONObject getObject(JSONObject obj, String key) {
try { try {
@ -371,4 +376,16 @@ public class JSONUtilities {
destArray.put(srcArray.get(i)); destArray.put(srcArray.get(i));
} }
} }
static public String serialize(Jsonizable obj, Properties options) {
Writer w = new StringWriter();
JSONWriter jsonWriter = new JSONWriter(w);
obj.write(jsonWriter, options);
return w.toString();
}
static public String serialize(Jsonizable obj) {
Properties options = new Properties();
return serialize(obj, options);
}
} }

View File

@ -0,0 +1,13 @@
package com.google.refine.expr;
import org.testng.annotations.Test;
import com.google.refine.tests.util.TestUtils;
public class EvalErrorTests {
@Test
public void serializeEvalError() {
EvalError e = new EvalError("this is a critical error");
TestUtils.isSerializedTo(e, "{\"type\":\"error\",\"message\":\"This is a critical error\"}");
}
}

View File

@ -35,7 +35,6 @@ package com.google.refine.tests;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Map;
import org.apache.tools.tar.TarOutputStream; import org.apache.tools.tar.TarOutputStream;
@ -43,7 +42,6 @@ import com.google.refine.ProjectManager;
import com.google.refine.history.HistoryEntryManager; import com.google.refine.history.HistoryEntryManager;
import com.google.refine.model.Project; import com.google.refine.model.Project;
import com.google.refine.model.metadata.IMetadata; import com.google.refine.model.metadata.IMetadata;
import com.google.refine.model.metadata.MetadataFormat;
/** /**
* Stub used to make protected methods public for testing * Stub used to make protected methods public for testing

View File

@ -69,6 +69,8 @@ import com.google.refine.model.metadata.ProjectMetadata;
import com.google.refine.tests.util.TestUtils; import com.google.refine.tests.util.TestUtils;
import com.google.refine.util.JSONUtilities; import com.google.refine.util.JSONUtilities;
import edu.mit.simile.butterfly.ButterflyModule;
/** /**
* A base class containing various utilities to help testing Refine. * A base class containing various utilities to help testing Refine.
*/ */
@ -93,6 +95,8 @@ public class RefineTest {
"{\"class\":\"com.google.refine.preference.TopList\",\"top\":2147483647," + "{\"class\":\"com.google.refine.preference.TopList\",\"top\":2147483647," +
"\"list\":[]},\"scripting.expressions\":{\"class\":\"com.google.refine.preference.TopList\",\"top\":100,\"list\":[]}}}}"); "\"list\":[]},\"scripting.expressions\":{\"class\":\"com.google.refine.preference.TopList\",\"top\":100,\"list\":[]}}}}");
FileProjectManager.initialize(workspaceDir); FileProjectManager.initialize(workspaceDir);
} catch (IOException e) { } catch (IOException e) {
workspaceDir = null; workspaceDir = null;
e.printStackTrace(); e.printStackTrace();
@ -315,4 +319,10 @@ public class RefineTest {
Assert.fail("JSONException",e); Assert.fail("JSONException",e);
} }
} }
protected ButterflyModule getCoreModule() {
ButterflyModule coreModule = mock(ButterflyModule.class);
when(coreModule.getName()).thenReturn("core");
return coreModule;
}
} }

View File

@ -0,0 +1,17 @@
package com.google.refine.tests.browsing;
import java.time.OffsetDateTime;
import org.testng.annotations.Test;
import com.google.refine.browsing.DecoratedValue;
import com.google.refine.tests.util.TestUtils;
public class DecoratedValueTests {
@Test
public void serializeDecoratedValue() {
OffsetDateTime date = OffsetDateTime.parse("2017-03-04T12:56:32Z");
DecoratedValue dv = new DecoratedValue(date, "[date 2017-03-04T12:56:32Z]");
TestUtils.isSerializedTo(dv, "{\"v\":\"2017-03-04T12:56:32Z\",\"l\":\"[date 2017-03-04T12:56:32Z]\"}");
}
}

View File

@ -0,0 +1,20 @@
package com.google.refine.tests.browsing;
import static org.mockito.Mockito.mock;
import org.testng.annotations.Test;
import com.google.refine.browsing.Engine;
import com.google.refine.model.Project;
import com.google.refine.tests.util.TestUtils;
// TODO Engine and engine config should be separated
// create an EngineConfig class that can be used in operations directly (to avoid manipulating JSONObject)
public class EngineTests {
@Test
public void serializeEngine() {
Project project = mock(Project.class);
Engine engine = new Engine(project);
TestUtils.isSerializedTo(engine, "{\"mode\":\"row-based\",\"facets\":[]}");
}
}

View File

@ -0,0 +1,23 @@
package com.google.refine.tests.browsing.facets;
import org.testng.annotations.Test;
import com.google.refine.browsing.DecoratedValue;
import com.google.refine.browsing.facets.NominalFacetChoice;
import com.google.refine.tests.util.TestUtils;
public class NominalFacetChoiceTests {
@Test
public void serializeNominalFacetChoice() {
DecoratedValue value = new DecoratedValue("some string", "some string");
NominalFacetChoice choice = new NominalFacetChoice(value);
choice.count = 3;
choice.selected = true;
TestUtils.isSerializedTo(choice, "{"
+ "\"v\":"
+ " {\"v\":\"some string\","
+ " \"l\":\"some string\"},"
+ "\"c\":3,"
+ "\"s\":true}");
}
}

View File

@ -43,9 +43,11 @@ 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.Coalesce;
import com.google.refine.grel.ControlFunctionRegistry; 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;
import com.google.refine.tests.util.TestUtils;
public class CoalesceTests extends RefineTest { public class CoalesceTests extends RefineTest {
@ -100,4 +102,10 @@ public class CoalesceTests extends RefineTest {
Assert.assertEquals(invoke("coalesce", (Object) null, ZERO_TO_TWO),ZERO_TO_TWO); Assert.assertEquals(invoke("coalesce", (Object) null, ZERO_TO_TWO),ZERO_TO_TWO);
} }
@Test
public void serializeCoalesce() {
String json = "{\"description\":\"Returns the first non-null from a series of values\",\"params\":\"two or more objects\",\"returns\":\"object or null\"}";
TestUtils.isSerializedTo(new Coalesce(), json);
}
} }

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.Cross;
import com.google.refine.tests.util.TestUtils;
public class CrossTests {
@Test
public void serializeCross() {
String json = "{\"description\":\"join with another project by column\",\"params\":\"cell c or string value, string projectName, string columnName\",\"returns\":\"array\"}";
TestUtils.isSerializedTo(new Cross(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.FacetCount;
import com.google.refine.tests.util.TestUtils;
public class FacetCountTests {
@Test
public void serializeFacetCount() {
String json = "{\"description\":\"Returns the facet count corresponding to the given choice value\",\"params\":\"choiceValue, string facetExpression, string columnName\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new FacetCount(), json);
}
}

View File

@ -52,7 +52,6 @@ import com.google.refine.model.Cell;
import com.google.refine.model.ModelException; import com.google.refine.model.ModelException;
import com.google.refine.model.Project; import com.google.refine.model.Project;
import com.google.refine.model.Row; import com.google.refine.model.Row;
import com.google.refine.model.metadata.ProjectMetadata;
import com.google.refine.tests.RefineTest; import com.google.refine.tests.RefineTest;

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.Get;
import com.google.refine.tests.util.TestUtils;
public class GetTests {
@Test
public void serializeGet() {
String json = "{\"description\":\"If o has fields, returns the field named 'from' of o. If o is an array, returns o[from, to]. if o is a string, returns o.substring(from, to)\",\"params\":\"o, number or string from, optional number to\",\"returns\":\"Depends on actual arguments\"}";
TestUtils.isSerializedTo(new Get(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.HasField;
import com.google.refine.tests.util.TestUtils;
public class HasFieldTests {
@Test
public void serializeHasField() {
String json = "{\"description\":\"Returns whether o has field name\",\"params\":\"o, string name\",\"returns\":\"boolean\"}";
TestUtils.isSerializedTo(new HasField(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.Jsonize;
import com.google.refine.tests.util.TestUtils;
public class JsonizeTests {
@Test
public void serializeJsonize() {
String json = "{\"description\":\"Quotes a value as a JSON literal value\",\"params\":\"value\",\"returns\":\"JSON literal value\"}";
TestUtils.isSerializedTo(new Jsonize(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.Length;
import com.google.refine.tests.util.TestUtils;
public class LengthTests {
@Test
public void serializeLength() {
String json = "{\"description\":\"Returns the length of o\",\"params\":\"array or string o\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Length(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.Slice;
import com.google.refine.tests.util.TestUtils;
public class SliceTests {
@Test
public void serializeSlice() {
String json = "{\"description\":\"If o is an array, returns o[from, to]. if o is a string, returns o.substring(from, to)\",\"params\":\"o, number from, optional number to\",\"returns\":\"Depends on actual arguments\"}";
TestUtils.isSerializedTo(new Slice(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.ToDate;
import com.google.refine.tests.util.TestUtils;
public class ToDateTests {
@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);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.ToNumber;
import com.google.refine.tests.util.TestUtils;
public class ToNumberTests {
@Test
public void serializeToNumber() {
String json = "{\"description\":\"Returns o converted to a number\",\"params\":\"o\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new ToNumber(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.ToString;
import com.google.refine.tests.util.TestUtils;
public class ToStringTests {
@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);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.Type;
import com.google.refine.tests.util.TestUtils;
public class TypeTests {
@Test
public void serializeType() {
String json = "{\"description\":\"Returns the type of o\",\"params\":\"object o\",\"returns\":\"string\"}";
TestUtils.isSerializedTo(new Type(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.arrays;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.arrays.Join;
import com.google.refine.tests.util.TestUtils;
public class JoinTests {
@Test
public void serializeJoin() {
String json = "{\"description\":\"Returns the string obtained by joining the array a with the separator sep\",\"params\":\"array a, string sep\",\"returns\":\"string\"}";
TestUtils.isSerializedTo(new Join(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.arrays;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.arrays.Reverse;
import com.google.refine.tests.util.TestUtils;
public class ReverseTests {
@Test
public void serializeReverse() {
String json = "{\"description\":\"Reverses array a\",\"params\":\"array a\",\"returns\":\"array\"}";
TestUtils.isSerializedTo(new Reverse(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.arrays;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.arrays.Sort;
import com.google.refine.tests.util.TestUtils;
public class SortTests {
@Test
public void serializeSort() {
String json = "{\"description\":\"Sorts array a\",\"params\":\"array a\",\"returns\":\"array\"}";
TestUtils.isSerializedTo(new Sort(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.arrays;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.arrays.Uniques;
import com.google.refine.tests.util.TestUtils;
public class UniquesTests {
@Test
public void serializeUniques() {
String json = "{\"description\":\"Returns array a with duplicates removed\",\"params\":\"array a\",\"returns\":\"array\"}";
TestUtils.isSerializedTo(new Uniques(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.booleans;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.booleans.And;
import com.google.refine.tests.util.TestUtils;
public class AndTests {
@Test
public void serializeAnd() {
String json = "{\"description\":\"AND two or more booleans to yield a boolean\",\"params\":\"boolean a, boolean b\",\"returns\":\"boolean\"}";
TestUtils.isSerializedTo(new And(), json);
}
}

View File

@ -50,7 +50,6 @@ import com.google.refine.model.Cell;
import com.google.refine.model.ModelException; import com.google.refine.model.ModelException;
import com.google.refine.model.Project; import com.google.refine.model.Project;
import com.google.refine.model.Row; import com.google.refine.model.Row;
import com.google.refine.model.metadata.ProjectMetadata;
import com.google.refine.tests.RefineTest; import com.google.refine.tests.RefineTest;

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.booleans;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.booleans.Not;
import com.google.refine.tests.util.TestUtils;
public class NotTests {
@Test
public void serializeNot() {
String json = "{\"description\":\"Returns the opposite of b\",\"params\":\"boolean b\",\"returns\":\"boolean\"}";
TestUtils.isSerializedTo(new Not(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.booleans;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.booleans.Or;
import com.google.refine.tests.util.TestUtils;
public class OrTests {
@Test
public void serializeOr() {
String json = "{\"description\":\"OR two or more booleans to yield a boolean\",\"params\":\"boolean a, boolean b\",\"returns\":\"boolean\"}";
TestUtils.isSerializedTo(new Or(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.booleans;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.booleans.Xor;
import com.google.refine.tests.util.TestUtils;
public class XorTests {
@Test
public void serializeXor() {
String json = "{\"description\":\"XORs two or more boolean values\",\"params\":\"boolean a, boolean b\",\"returns\":\"boolean\"}";
TestUtils.isSerializedTo(new Xor(), json);
}
}

View File

@ -15,9 +15,11 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.refine.expr.functions.date.DatePart;
import com.google.refine.grel.ControlFunctionRegistry; 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;
import com.google.refine.tests.util.TestUtils;
public class DatePartTests extends RefineTest { public class DatePartTests extends RefineTest {
@ -125,4 +127,11 @@ public class DatePartTests extends RefineTest {
calendar.setTime(date); calendar.setTime(date);
return calendar; return calendar;
} }
@Test
public void serializeDatePart() {
String json = "{\"description\":\"Returns part of a date\",\"params\":\"date d, string part\",\"returns\":\"date\"}";
TestUtils.isSerializedTo(new DatePart(), json);
}
} }

View File

@ -14,9 +14,11 @@ 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.date.Inc;
import com.google.refine.grel.ControlFunctionRegistry; 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;
import com.google.refine.tests.util.TestUtils;
public class IncTests extends RefineTest { public class IncTests extends RefineTest {
@ -115,4 +117,11 @@ public class IncTests extends RefineTest {
Assert.assertTrue(invoke("inc", source, 99) instanceof EvalError); Assert.assertTrue(invoke("inc", source, 99) instanceof EvalError);
Assert.assertTrue(invoke("inc", source.toInstant().toEpochMilli(), 99, "h") instanceof EvalError); Assert.assertTrue(invoke("inc", source.toInstant().toEpochMilli(), 99, "h") instanceof EvalError);
} }
@Test
public void serializeInc() {
String json = "{\"description\":\"Returns a date changed by the given amount in the given unit of time\",\"params\":\"date d, number value, string unit (default to 'hour')\",\"returns\":\"date\"}";
TestUtils.isSerializedTo(new Inc(), json);
}
} }

View File

@ -12,9 +12,11 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.refine.expr.functions.date.Now;
import com.google.refine.grel.ControlFunctionRegistry; 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;
import com.google.refine.tests.util.TestUtils;
public class NowTests extends RefineTest { public class NowTests extends RefineTest {
@ -67,4 +69,11 @@ public class NowTests extends RefineTest {
Assert.assertTrue(invoke("now") instanceof OffsetDateTime); Assert.assertTrue(invoke("now") instanceof OffsetDateTime);
Assert.assertTrue(((OffsetDateTime)invoke("now")).isAfter(source)); Assert.assertTrue(((OffsetDateTime)invoke("now")).isAfter(source));
} }
@Test
public void serializeNow() {
String json = "{\"description\":\"Returns the current time\",\"returns\":\"date\"}";
TestUtils.isSerializedTo(new Now(), json);
}
} }

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.html;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.html.HtmlAttr;
import com.google.refine.tests.util.TestUtils;
public class HtmlAttrTests {
@Test
public void serializeHtmlAttr() {
String json = "{\"description\":\"Selects a value from an attribute on an Html Element\",\"params\":\"Element e, String s\",\"returns\":\"String attribute Value\"}";
TestUtils.isSerializedTo(new HtmlAttr(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.html;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.html.HtmlText;
import com.google.refine.tests.util.TestUtils;
public class HtmlTextTests {
@Test
public void serializeHtmlText() {
String json = "{\"description\":\"Selects the text from within an element (including all child elements)\",\"params\":\"Element e\",\"returns\":\"String text\"}";
TestUtils.isSerializedTo(new HtmlText(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.html;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.html.InnerHtml;
import com.google.refine.tests.util.TestUtils;
public class InnerHtmlTests {
@Test
public void serializeInnerHtml() {
String json = "{\"description\":\"The innerHtml of an HTML element\",\"params\":\"Element e\",\"returns\":\"String innerHtml\"}";
TestUtils.isSerializedTo(new InnerHtml(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.html;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.html.OwnText;
import com.google.refine.tests.util.TestUtils;
public class OwnTextTests {
@Test
public void serializeOwnText() {
String json = "{\"description\":\"Gets the text owned by this HTML element only; does not get the combined text of all children.\",\"params\":\"Element e\",\"returns\":\"String ownText\"}";
TestUtils.isSerializedTo(new OwnText(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.html;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.html.ParseHtml;
import com.google.refine.tests.util.TestUtils;
public class ParseHtmlTests {
@Test
public void serializeParseHtml() {
String json = "{\"description\":\"Parses a string as HTML\",\"params\":\"string s\",\"returns\":\"HTML object\"}";
TestUtils.isSerializedTo(new ParseHtml(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.html;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.html.SelectHtml;
import com.google.refine.tests.util.TestUtils;
public class SelectHtmlTests {
@Test
public void serializeSelectHtml() {
String json = "{\"description\":\"Selects an element from an HTML elementn using selector syntax\",\"params\":\"Element e, String s\",\"returns\":\"HTML Elements\"}";
TestUtils.isSerializedTo(new SelectHtml(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.ACos;
import com.google.refine.tests.util.TestUtils;
public class ACosTests {
@Test
public void serializeACos() {
String json = "{\"description\":\"Returns the arc cosine of an angle, in the range 0 through PI\",\"params\":\"number d\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new ACos(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.ASin;
import com.google.refine.tests.util.TestUtils;
public class ASinTests {
@Test
public void serializeASin() {
String json = "{\"description\":\"Returns the arc sine of an angle in the range of -PI/2 through PI/2\",\"params\":\"number d\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new ASin(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.ATan2;
import com.google.refine.tests.util.TestUtils;
public class ATan2Tests {
@Test
public void serializeATan2() {
String json = "{\"description\":\"Converts rectangular coordinates (x, y) to polar (r, theta)\",\"params\":\"number x, number y\",\"returns\":\"number theta\"}";
TestUtils.isSerializedTo(new ATan2(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.ATan;
import com.google.refine.tests.util.TestUtils;
public class ATanTests {
@Test
public void serializeATan() {
String json = "{\"description\":\"Returns the arc tangent of an angle in the range of -PI/2 through PI/2\",\"params\":\"number d\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new ATan(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Abs;
import com.google.refine.tests.util.TestUtils;
public class AbsTests {
@Test
public void serializeAbs() {
String json = "{\"description\":\"Returns the absolute value of a number\",\"params\":\"number d\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Abs(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Ceil;
import com.google.refine.tests.util.TestUtils;
public class CeilTests {
@Test
public void serializeCeil() {
String json = "{\"description\":\"Returns the ceiling of a number\",\"params\":\"number d\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Ceil(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Combin;
import com.google.refine.tests.util.TestUtils;
public class CombinTests {
@Test
public void serializeCombin() {
String json = "{\"description\":\"Returns the number of combinations for n elements as divided into k\",\"params\":\"number d\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Combin(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Cos;
import com.google.refine.tests.util.TestUtils;
public class CosTests {
@Test
public void serializeCos() {
String json = "{\"description\":\"Returns the trigonometric cosine of an angle\",\"params\":\"number d\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Cos(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Cosh;
import com.google.refine.tests.util.TestUtils;
public class CoshTests {
@Test
public void serializeCosh() {
String json = "{\"description\":\"Returns the hyperbolic cosine of a value\",\"params\":\"number d\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Cosh(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Degrees;
import com.google.refine.tests.util.TestUtils;
public class DegreesTests {
@Test
public void serializeDegrees() {
String json = "{\"description\":\"Converts an angle from radians to degrees.\",\"params\":\"number d\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Degrees(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Even;
import com.google.refine.tests.util.TestUtils;
public class EvenTests {
@Test
public void serializeEven() {
String json = "{\"description\":\"Rounds the number up to the nearest even integer\",\"params\":\"number d\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Even(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Exp;
import com.google.refine.tests.util.TestUtils;
public class ExpTests {
@Test
public void serializeExp() {
String json = "{\"description\":\"Returns e^n\",\"params\":\"number n\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Exp(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.FactN;
import com.google.refine.tests.util.TestUtils;
public class FactNTests {
@Test
public void serializeFactN() {
String json = "{\"description\":\"Returns the factorial of a number\",\"params\":\"number i\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new FactN(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Fact;
import com.google.refine.tests.util.TestUtils;
public class FactTests {
@Test
public void serializeFact() {
String json = "{\"description\":\"Returns the factorial of a number\",\"params\":\"number i\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Fact(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Floor;
import com.google.refine.tests.util.TestUtils;
public class FloorTests {
@Test
public void serializeFloor() {
String json = "{\"description\":\"Returns the floor of a number as an integer\",\"params\":\"number d\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Floor(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.GreatestCommonDenominator;
import com.google.refine.tests.util.TestUtils;
public class GreatestCommonDenominatorTests {
@Test
public void serializeGreatestCommonDenominator() {
String json = "{\"description\":\"Returns the greatest common denominator of the two numbers\",\"params\":\"number d, number e\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new GreatestCommonDenominator(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.LeastCommonMultiple;
import com.google.refine.tests.util.TestUtils;
public class LeastCommonMultipleTests {
@Test
public void serializeLeastCommonMultiple() {
String json = "{\"description\":\"Returns the greatest common denominator of the two numbers\",\"params\":\"number d, number e\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new LeastCommonMultiple(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Ln;
import com.google.refine.tests.util.TestUtils;
public class LnTests {
@Test
public void serializeLn() {
String json = "{\"description\":\"Returns the natural log of n\",\"params\":\"number n\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Ln(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Log;
import com.google.refine.tests.util.TestUtils;
public class LogTests {
@Test
public void serializeLog() {
String json = "{\"description\":\"Returns the base 10 log of n\",\"params\":\"number n\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Log(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Max;
import com.google.refine.tests.util.TestUtils;
public class MaxTests {
@Test
public void serializeMax() {
String json = "{\"description\":\"Returns the greater of two numbers\",\"params\":\"number a, number b\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Max(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Min;
import com.google.refine.tests.util.TestUtils;
public class MinTests {
@Test
public void serializeMin() {
String json = "{\"description\":\"Returns the smaller of two numbers\",\"params\":\"number a, number b\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Min(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Mod;
import com.google.refine.tests.util.TestUtils;
public class ModTests {
@Test
public void serializeMod() {
String json = "{\"description\":\"Returns a modulus b\",\"params\":\"number a, number b\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Mod(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Multinomial;
import com.google.refine.tests.util.TestUtils;
public class MultinomialTests {
@Test
public void serializeMultinomial() {
String json = "{\"description\":\"Calculates the multinomial of a series of numbers\",\"params\":\"one or more numbers\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Multinomial(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Odd;
import com.google.refine.tests.util.TestUtils;
public class OddTests {
@Test
public void serializeOdd() {
String json = "{\"description\":\"Rounds the number up to the nearest even integer\",\"params\":\"number d\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Odd(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Pow;
import com.google.refine.tests.util.TestUtils;
public class PowTests {
@Test
public void serializePow() {
String json = "{\"description\":\"Returns a^b\",\"params\":\"number a, number b\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Pow(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Quotient;
import com.google.refine.tests.util.TestUtils;
public class QuotientTests {
@Test
public void serializeQuotient() {
String json = "{\"description\":\"Returns the integer portion of a division\",\"params\":\"number numerator, number denominator\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Quotient(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Radians;
import com.google.refine.tests.util.TestUtils;
public class RadiansTests {
@Test
public void serializeRadians() {
String json = "{\"description\":\"Converts an angle in degrees to radians\",\"params\":\"number d\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Radians(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Round;
import com.google.refine.tests.util.TestUtils;
public class RoundTests {
@Test
public void serializeRound() {
String json = "{\"description\":\"Returns n rounded\",\"params\":\"number n\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Round(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Sin;
import com.google.refine.tests.util.TestUtils;
public class SinTests {
@Test
public void serializeSin() {
String json = "{\"description\":\"Returns the trigonometric sine of an angle\",\"params\":\"number d\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Sin(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Sinh;
import com.google.refine.tests.util.TestUtils;
public class SinhTests {
@Test
public void serializeSinh() {
String json = "{\"description\":\"Returns the hyperbolic sine of an angle\",\"params\":\"number d\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Sinh(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Sum;
import com.google.refine.tests.util.TestUtils;
public class SumTests {
@Test
public void serializeSum() {
String json = "{\"description\":\"Sums numbers in array a\",\"params\":\"array a\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Sum(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Tan;
import com.google.refine.tests.util.TestUtils;
public class TanTests {
@Test
public void serializeTan() {
String json = "{\"description\":\"Returns the trigonometric tangent of an angle\",\"params\":\"number d\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Tan(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.math;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.math.Tanh;
import com.google.refine.tests.util.TestUtils;
public class TanhTests {
@Test
public void serializeTanh() {
String json = "{\"description\":\"Returns the hyperbolic tangent of a value\",\"params\":\"number d\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new Tanh(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.Chomp;
import com.google.refine.tests.util.TestUtils;
public class ChompTests {
@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);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.Contains;
import com.google.refine.tests.util.TestUtils;
public class ContainsTests {
@Test
public void serializeContains() {
String json = "{\"description\":\"Returns whether s contains frag\",\"params\":\"string s, string frag\",\"returns\":\"boolean\"}";
TestUtils.isSerializedTo(new Contains(), json);
}
}

View File

@ -12,9 +12,11 @@ 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.Diff;
import com.google.refine.grel.ControlFunctionRegistry; 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;
import com.google.refine.tests.util.TestUtils;
public class DiffTests extends RefineTest { public class DiffTests extends RefineTest {
@ -80,4 +82,11 @@ public class DiffTests extends RefineTest {
Assert.assertEquals(invoke("diff",odt2,odt1,"milliseconds"),Long.valueOf(7948860000011l)); Assert.assertEquals(invoke("diff",odt2,odt1,"milliseconds"),Long.valueOf(7948860000011l));
Assert.assertEquals(invoke("diff",odt2,odt1,"nanos"),Long.valueOf(7948860000011000l)); Assert.assertEquals(invoke("diff",odt2,odt1,"nanos"),Long.valueOf(7948860000011000l));
} }
@Test
public void serializeDiff() {
String json = "{\"description\":\"For strings, returns the portion where they differ. For dates, it returns the difference in given time units\",\"params\":\"o1, o2, time unit (optional)\",\"returns\":\"string for strings, number for dates\"}";
TestUtils.isSerializedTo(new Diff(), json);
}
} }

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.EndsWith;
import com.google.refine.tests.util.TestUtils;
public class EndsWithTests {
@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);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.Escape;
import com.google.refine.tests.util.TestUtils;
public class EscapeTests {
@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);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.Find;
import com.google.refine.tests.util.TestUtils;
public class FindTests {
@Test
public void serializeFind() {
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);
}
}

View File

@ -40,9 +40,11 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.Fingerprint;
import com.google.refine.grel.ControlFunctionRegistry; 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;
import com.google.refine.tests.util.TestUtils;
public class FingerprintTests extends RefineTest { public class FingerprintTests extends RefineTest {
@ -110,4 +112,12 @@ public class FingerprintTests extends RefineTest {
"Fingerprint for string: " + ss[0] + " failed"); "Fingerprint for string: " + ss[0] + " failed");
} }
} }
@Test
public void serializeFingerprint() {
String json = "{\"description\":\"Returns the fingerprint of s, a derived string that aims to be a more canonical form of it (this is mostly useful for finding clusters of strings related to the same information).\",\"params\":\"string s\",\"returns\":\"string\"}";
TestUtils.isSerializedTo(new Fingerprint(), json);
}
} }

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.IndexOf;
import com.google.refine.tests.util.TestUtils;
public class IndexOfTests {
@Test
public void serializeIndexOf() {
String json = "{\"description\":\"Returns the index of sub first ocurring in s\",\"params\":\"string s, string sub\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new IndexOf(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.LastIndexOf;
import com.google.refine.tests.util.TestUtils;
public class LastIndexOfTests {
@Test
public void serializeLastIndexOf() {
String json = "{\"description\":\"Returns the index of sub last ocurring in s\",\"params\":\"string s, string sub\",\"returns\":\"number\"}";
TestUtils.isSerializedTo(new LastIndexOf(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.MD5;
import com.google.refine.tests.util.TestUtils;
public class MD5Tests {
@Test
public void serializeMD5() {
String json = "{\"description\":\"Returns the MD5 hash of s\",\"params\":\"string s\",\"returns\":\"string\"}";
TestUtils.isSerializedTo(new MD5(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.Match;
import com.google.refine.tests.util.TestUtils;
public class MatchTests {
@Test
public void serializeMatch() {
String json = "{\"description\":\"Returns an array of the groups matching the given regular expression\",\"params\":\"string or regexp\",\"returns\":\"array of strings\"}";
TestUtils.isSerializedTo(new Match(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.NGramFingerprint;
import com.google.refine.tests.util.TestUtils;
public class NGramFingerprintTests {
@Test
public void serializeNGramFingerprint() {
String json = "{\"description\":\"Returns the n-gram fingerprint of s\",\"params\":\"string s, number n\",\"returns\":\"string\"}";
TestUtils.isSerializedTo(new NGramFingerprint(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.NGram;
import com.google.refine.tests.util.TestUtils;
public class NGramTests {
@Test
public void serializeNGram() {
String json = "{\"description\":\"Returns an array of the word ngrams of s\",\"params\":\"string s, number n\",\"returns\":\"array of strings\"}";
TestUtils.isSerializedTo(new NGram(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.ParseJson;
import com.google.refine.tests.util.TestUtils;
public class ParseJsonTests {
@Test
public void serializeParseJson() {
String json = "{\"description\":\"Parses a string as JSON\",\"params\":\"string s\",\"returns\":\"JSON object\"}";
TestUtils.isSerializedTo(new ParseJson(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.Partition;
import com.google.refine.tests.util.TestUtils;
public class PartitionTests {
@Test
public void serializePartition() {
String json = "{\"description\":\"Returns an array of strings [a,frag,b] where a is the string part before the first occurrence of frag in s and b is what's left. If omitFragment is true, frag is not returned.\",\"params\":\"string s, string or regex frag, optional boolean omitFragment\",\"returns\":\"array\"}";
TestUtils.isSerializedTo(new Partition(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.Phonetic;
import com.google.refine.tests.util.TestUtils;
public class PhoneticTests {
@Test
public void serializePhonetic() {
String json = "{\"description\":\"Returns the a phonetic encoding of s (optionally indicating which encoding to use')\",\"params\":\"string s, string encoding (optional, defaults to 'metaphone3')\",\"returns\":\"string\"}";
TestUtils.isSerializedTo(new Phonetic(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.RPartition;
import com.google.refine.tests.util.TestUtils;
public class RPartitionTests {
@Test
public void serializeRPartition() {
String json = "{\"description\":\"Returns an array of strings [a,frag,b] where a is the string part before the last occurrence of frag in s and b is what's left. If omitFragment is true, frag is not returned.\",\"params\":\"string s, string or regex frag, optional boolean omitFragment\",\"returns\":\"array\"}";
TestUtils.isSerializedTo(new RPartition(), json);
}
}

View File

@ -10,9 +10,11 @@ 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.Range;
import com.google.refine.grel.ControlFunctionRegistry; 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;
import com.google.refine.tests.util.TestUtils;
/** /**
* Tests for the range function. * Tests for the range function.
@ -319,4 +321,11 @@ public class RangeTests extends RefineTest {
Assert.assertEquals(((Integer[]) (invoke("range", 5, "1", "-1"))), FIVE_TO_TWO); Assert.assertEquals(((Integer[]) (invoke("range", 5, "1", "-1"))), FIVE_TO_TWO);
Assert.assertEquals(((Integer[]) (invoke("range", 5, "1", "-2"))), FIVE_AND_THREE); Assert.assertEquals(((Integer[]) (invoke("range", 5, "1", "-2"))), FIVE_AND_THREE);
} }
@Test
public void serializeRange() {
String json = "{\"description\":\"Returns an array where a and b are the start and the end of the range respectively and c is the step (increment).\",\"params\":\"A single string 'a', 'a, b' or 'a, b, c' or one, two or three integers a or a, b or a, b, c\",\"returns\":\"array\"}";
TestUtils.isSerializedTo(new Range(), json);
}
} }

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.Reinterpret;
import com.google.refine.tests.util.TestUtils;
public class ReinterpretTests {
@Test
public void serializeReinterpret() {
String json = "{\"description\":\"Returns s reinterpreted thru the given encoder.\",\"params\":\"string s, string encoder\",\"returns\":\"string\"}";
TestUtils.isSerializedTo(new Reinterpret(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.ReplaceChars;
import com.google.refine.tests.util.TestUtils;
public class ReplaceCharsTests {
@Test
public void serializeReplaceChars() {
String json = "{\"description\":\"Returns the string obtained by replacing all chars in f with the char in s at that same position\",\"params\":\"string s, string f, string r\",\"returns\":\"string\"}";
TestUtils.isSerializedTo(new ReplaceChars(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.Replace;
import com.google.refine.tests.util.TestUtils;
public class ReplaceTests {
@Test
public void serializeReplace() {
String json = "{\"description\":\"Returns the string obtained by replacing f with r in s\",\"params\":\"string s, string or regex f, string r\",\"returns\":\"string\"}";
TestUtils.isSerializedTo(new Replace(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.SHA1;
import com.google.refine.tests.util.TestUtils;
public class SHA1Tests {
@Test
public void serializeSHA1() {
String json = "{\"description\":\"Returns the SHA-1 hash of s\",\"params\":\"string s\",\"returns\":\"string\"}";
TestUtils.isSerializedTo(new SHA1(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.SmartSplit;
import com.google.refine.tests.util.TestUtils;
public class SmartSplitTests {
@Test
public void serializeSmartSplit() {
String json = "{\"description\":\"Returns the array of strings obtained by splitting s with separator sep. Handles quotes properly. Guesses tab or comma separator if \\\"sep\\\" is not given.\",\"params\":\"string s, optional string sep\",\"returns\":\"array\"}";
TestUtils.isSerializedTo(new SmartSplit(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.SplitByCharType;
import com.google.refine.tests.util.TestUtils;
public class SplitByCharTypeTests {
@Test
public void serializeSplitByCharType() {
String json = "{\"description\":\"Returns an array of strings obtained by splitting s grouping consecutive chars by their unicode type\",\"params\":\"string s\",\"returns\":\"array\"}";
TestUtils.isSerializedTo(new SplitByCharType(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.SplitByLengths;
import com.google.refine.tests.util.TestUtils;
public class SplitByLengthsTests {
@Test
public void serializeSplitByLengths() {
String json = "{\"description\":\"Returns the array of strings obtained by splitting s into substrings with the given lengths\",\"params\":\"string s, number n, ...\",\"returns\":\"array\"}";
TestUtils.isSerializedTo(new SplitByLengths(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.Split;
import com.google.refine.tests.util.TestUtils;
public class SplitTests {
@Test
public void serializeSplit() {
String json = "{\"description\":\"Returns the array of strings obtained by splitting s with separator sep. If preserveAllTokens is true, then empty segments are preserved.\",\"params\":\"string s, string or regex sep, optional boolean preserveAllTokens\",\"returns\":\"array\"}";
TestUtils.isSerializedTo(new Split(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.expr.functions.strings;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.strings.StartsWith;
import com.google.refine.tests.util.TestUtils;
public class StartsWithTests {
@Test
public void serializeStartsWith() {
String json = "{\"description\":\"Returns whether s starts with sub\",\"params\":\"string s, string sub\",\"returns\":\"boolean\"}";
TestUtils.isSerializedTo(new StartsWith(), json);
}
}

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