MathematicalFunction { private static FunctionResolver conv() { return FunctionDSL.define(BuiltinFunctionName.CONV.getName(), FunctionDSL.impl( FunctionDSL.nullMissingHandling((x, a, b) -> new ExprStringValue( Integer.toString(Integer.parseInt(x.stringValue(), a.integerValue()), b.integerValue()) )), STRING, STRING, INTEGER, INTEGER), FunctionDSL.impl( FunctionDSL.nullMissingHandling((x, a, b) -> new ExprStringValue( Integer.toString(Integer.parseInt(x.integerValue().toString(), a.integerValue()), b.integerValue()) )), STRING, INTEGER, INTEGER, INTEGER) ); }  static void register(BuiltinFunctionRepository repository);  }
@Test public void conv_null_value() { FunctionExpression conv = dsl.conv( DSL.ref(STRING_TYPE_NULL_VALUE_FILED, STRING), DSL.literal(10), DSL.literal(2)); assertEquals(STRING, conv.type()); assertTrue(conv.valueOf(valueEnv()).isNull()); conv = dsl.conv( DSL.literal("1"), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(2)); assertEquals(STRING, conv.type()); assertTrue(conv.valueOf(valueEnv()).isNull()); conv = dsl.conv( DSL.literal("1"), DSL.literal(10), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(STRING, conv.type()); assertTrue(conv.valueOf(valueEnv()).isNull()); }
@Test public void conv_missing_value() { FunctionExpression conv = dsl.conv( DSL.ref(STRING_TYPE_MISSING_VALUE_FILED, STRING), DSL.literal(10), DSL.literal(2)); assertEquals(STRING, conv.type()); assertTrue(conv.valueOf(valueEnv()).isMissing()); conv = dsl.conv( DSL.literal("1"), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(2)); assertEquals(STRING, conv.type()); assertTrue(conv.valueOf(valueEnv()).isMissing()); conv = dsl.conv( DSL.literal("1"), DSL.literal(10), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(STRING, conv.type()); assertTrue(conv.valueOf(valueEnv()).isMissing()); }
@Test public void conv_null_missing() { FunctionExpression conv = dsl.conv(DSL.ref(STRING_TYPE_MISSING_VALUE_FILED, STRING), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(2)); assertEquals(STRING, conv.type()); assertTrue(conv.valueOf(valueEnv()).isMissing()); }