Fix the true.type() == "boolean"
Fix the true.type() == "boolean" instead of java.lang.Boolean. Remove all the references to "error" result in Type(). This will be addressed in: @ToDo fix this with issue #2562
This commit is contained in:
parent
55ea09d21c
commit
0e86619d86
@ -57,8 +57,10 @@ public class Type implements Function {
|
|||||||
return "number";
|
return "number";
|
||||||
} else if (v.getClass().isArray() || v instanceof List<?>) {
|
} else if (v.getClass().isArray() || v instanceof List<?>) {
|
||||||
return "array";
|
return "array";
|
||||||
} else if (v instanceof EvalError) {
|
} else if (v instanceof Boolean) {
|
||||||
return "error";
|
return "boolean";
|
||||||
|
// } else if (v instanceof EvalError) { // @ToDo fix this with issue #2562
|
||||||
|
// return "error";
|
||||||
} else {
|
} else {
|
||||||
return v.getClass().getName();
|
return v.getClass().getName();
|
||||||
}
|
}
|
||||||
@ -70,7 +72,7 @@ public class Type implements Function {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return "Returns the type of o";
|
return "Returns the type of o as a string ('string', 'date', 'number', 'array', 'boolean' or a class name)";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,15 +26,83 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package com.google.refine.expr.functions;
|
package com.google.refine.expr.functions;
|
||||||
|
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
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 org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
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.expr.functions.Type;
|
||||||
|
import com.google.refine.grel.ControlFunctionRegistry;
|
||||||
|
import com.google.refine.grel.Function;
|
||||||
import com.google.refine.util.TestUtils;
|
import com.google.refine.util.TestUtils;
|
||||||
|
|
||||||
public class TypeTests {
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@BeforeTest
|
||||||
|
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 testTypeInvalidParams() {
|
||||||
|
Assert.assertTrue(invoke("type") instanceof EvalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testType() {
|
||||||
|
Assert.assertEquals(invoke("type", (Object) null),"undefined");
|
||||||
|
Assert.assertEquals(invoke("type", 1),"number");
|
||||||
|
Assert.assertEquals(invoke("type", true),"boolean");
|
||||||
|
Assert.assertEquals(invoke("type", "a string"),"string");
|
||||||
|
Assert.assertEquals(invoke("type", dateTimeValue), "date");
|
||||||
|
Assert.assertEquals(invoke("type", listArray), "array");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void serializeType() {
|
public void serializeType() {
|
||||||
String json = "{\"description\":\"Returns the type of o\",\"params\":\"object o\",\"returns\":\"string\"}";
|
String json = "{\"description\":\"Returns the type of o as a string ('string', 'date', 'number', 'array', 'boolean' or a class name)\",\"params\":\"object o\",\"returns\":\"string\"}";
|
||||||
TestUtils.isSerializedTo(new Type(), json);
|
TestUtils.isSerializedTo(new Type(), json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user