Add serialization tests for GREL controls

This commit is contained in:
Antonin Delpeuch 2018-08-21 18:13:06 +02:00
parent 326fda7999
commit 802ad77ec5
14 changed files with 210 additions and 0 deletions

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.grel.controls;
import org.testng.annotations.Test;
import com.google.refine.grel.controls.Filter;
import com.google.refine.tests.util.TestUtils;
public class FilterTests {
@Test
public void serializeFilter() {
String json = "{\"description\":\"Evaluates expression a to an array. Then for each array element, binds its value to variable name v, evaluates expression test which should return a boolean. If the boolean is true, pushes v onto the result array.\",\"params\":\"expression a, variable v, expression test\",\"returns\":\"array\"}";
TestUtils.isSerializedTo(new Filter(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.grel.controls;
import org.testng.annotations.Test;
import com.google.refine.grel.controls.ForEachIndex;
import com.google.refine.tests.util.TestUtils;
public class ForEachIndexTests {
@Test
public void serializeForEachIndex() {
String json = "{\"description\":\"Evaluates expression a to an array. Then for each array element, binds its index to variable i and its value to variable name v, evaluates expression e, and pushes the result onto the result array.\",\"params\":\"expression a, variable i, variable v, expression e\",\"returns\":\"array\"}";
TestUtils.isSerializedTo(new ForEachIndex(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.grel.controls;
import org.testng.annotations.Test;
import com.google.refine.grel.controls.ForEach;
import com.google.refine.tests.util.TestUtils;
public class ForEachTests {
@Test
public void serializeForEach() {
String json = "{\"description\":\"Evaluates expression a to an array. Then for each array element, binds its value to variable name v, evaluates expression e, and pushes the result onto the result array.\",\"params\":\"expression a, variable v, expression e\",\"returns\":\"array\"}";
TestUtils.isSerializedTo(new ForEach(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.grel.controls;
import org.testng.annotations.Test;
import com.google.refine.grel.controls.ForNonBlank;
import com.google.refine.tests.util.TestUtils;
public class ForNonBlankTests {
@Test
public void serializeForNonBlank() {
String json = "{\"description\":\"Evaluates expression o. If it is non-blank, binds its value to variable name v, evaluates expression eNonBlank and returns the result. Otherwise (if o evaluates to blank), evaluates expression eBlank and returns that result instead.\",\"params\":\"expression o, variable v, expression eNonBlank, expression eBlank\",\"returns\":\"Depends on actual arguments\"}";
TestUtils.isSerializedTo(new ForNonBlank(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.grel.controls;
import org.testng.annotations.Test;
import com.google.refine.grel.controls.ForRange;
import com.google.refine.tests.util.TestUtils;
public class ForRangeTests {
@Test
public void serializeForRange() {
String json = "{\"description\":\"Iterates over the variable v starting at \\\"from\\\", incrementing by \\\"step\\\" each time while less than \\\"to\\\". At each iteration, evaluates expression e, and pushes the result onto the result array.\",\"params\":\"number from, number to, number step, variable v, expression e\",\"returns\":\"array\"}";
TestUtils.isSerializedTo(new ForRange(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.grel.controls;
import org.testng.annotations.Test;
import com.google.refine.grel.controls.If;
import com.google.refine.tests.util.TestUtils;
public class IfTests {
@Test
public void serializeIf() {
String json = "{\"description\":\"Evaluates expression o. If it is true, evaluates expression eTrue and returns the result. Otherwise, evaluates expression eFalse and returns that result instead.\",\"params\":\"expression o, expression eTrue, expression eFalse\",\"returns\":\"Depends on actual arguments\"}";
TestUtils.isSerializedTo(new If(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.grel.controls;
import org.testng.annotations.Test;
import com.google.refine.grel.controls.IsBlank;
import com.google.refine.tests.util.TestUtils;
public class IsBlankTests {
@Test
public void serializeIsBlank() {
String json = "{\"description\":\"Returns whether o is null or an empty string\",\"params\":\"expression o\",\"returns\":\"boolean\"}";
TestUtils.isSerializedTo(new IsBlank(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.grel.controls;
import org.testng.annotations.Test;
import com.google.refine.grel.controls.IsEmptyString;
import com.google.refine.tests.util.TestUtils;
public class IsEmptyStringTests {
@Test
public void serializeIsEmptyString() {
String json = "{\"description\":\"Returns whether o is an empty string\",\"params\":\"expression o\",\"returns\":\"boolean\"}";
TestUtils.isSerializedTo(new IsEmptyString(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.grel.controls;
import org.testng.annotations.Test;
import com.google.refine.grel.controls.IsError;
import com.google.refine.tests.util.TestUtils;
public class IsErrorTests {
@Test
public void serializeIsError() {
String json = "{\"description\":\"Returns whether o is an error\",\"params\":\"expression o\",\"returns\":\"boolean\"}";
TestUtils.isSerializedTo(new IsError(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.grel.controls;
import org.testng.annotations.Test;
import com.google.refine.grel.controls.IsNonBlank;
import com.google.refine.tests.util.TestUtils;
public class IsNonBlankTests {
@Test
public void serializeIsNonBlank() {
String json = "{\"description\":\"Returns whether o is not null and not an empty string\",\"params\":\"expression o\",\"returns\":\"boolean\"}";
TestUtils.isSerializedTo(new IsNonBlank(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.grel.controls;
import org.testng.annotations.Test;
import com.google.refine.grel.controls.IsNotNull;
import com.google.refine.tests.util.TestUtils;
public class IsNotNullTests {
@Test
public void serializeIsNotNull() {
String json = "{\"description\":\"Returns whether o is not null\",\"params\":\"expression o\",\"returns\":\"boolean\"}";
TestUtils.isSerializedTo(new IsNotNull(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.grel.controls;
import org.testng.annotations.Test;
import com.google.refine.grel.controls.IsNull;
import com.google.refine.tests.util.TestUtils;
public class IsNullTests {
@Test
public void serializeIsNull() {
String json = "{\"description\":\"Returns whether o is null\",\"params\":\"expression o\",\"returns\":\"boolean\"}";
TestUtils.isSerializedTo(new IsNull(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.grel.controls;
import org.testng.annotations.Test;
import com.google.refine.grel.controls.IsNumeric;
import com.google.refine.tests.util.TestUtils;
public class IsNumericTests {
@Test
public void serializeIsNumeric() {
String json = "{\"description\":\"Returns whether o can represent a number\",\"params\":\"expression o\",\"returns\":\"boolean\"}";
TestUtils.isSerializedTo(new IsNumeric(), json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.grel.controls;
import org.testng.annotations.Test;
import com.google.refine.grel.controls.With;
import com.google.refine.tests.util.TestUtils;
public class WithTests {
@Test
public void serializeWith() {
String json = "{\"description\":\"Evaluates expression o and binds its value to variable name v. Then evaluates expression e and returns that result\",\"params\":\"expression o, variable v, expression e\",\"returns\":\"Depends on actual arguments\"}";
TestUtils.isSerializedTo(new With(), json);
}
}