Search in sources :

Example 21 with IDataTypeParser

use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.

the class SchemaDataTypeParsersTest method testDouble.

@Test
public void testDouble() throws Exception {
    IDataTypeParser dtp = XsiDefaultDataTypeParser.instance;
    // test double
    String doubleString = "-12.789438023842092304e+28";
    double dValue = dtp.parseDouble(null, doubleString);
    assertEquals("-1.2789438023842093E29", dtp.unparseDouble(null, dValue));
    doubleString = "+1267.789438023842092304928437987423982E12";
    dValue = dtp.parseDouble(null, doubleString);
    assertEquals("1.267789438023842E15", dtp.unparseDouble(null, dValue));
    doubleString = "00000000.000000";
    dValue = dtp.parseDouble(null, doubleString);
    assertEquals("0.0E0", dtp.unparseDouble(null, dValue));
    assertEquals("INF", dtp.unparseDouble(null, Double.POSITIVE_INFINITY));
    assertEquals("-INF", dtp.unparseDouble(null, Double.NEGATIVE_INFINITY));
    assertEquals("NaN", dtp.unparseDouble(null, Double.NaN));
    try {
        dtp.parseDouble(null, "123,456");
        fail();
    } catch (Exception e) {
    }
    try {
        dtp.parseDouble(null, "1000FFFF");
        fail();
    } catch (Exception e) {
    }
}
Also used : SchemaDataTypeParsers.normalizedString(org.whole.lang.xsd.parsers.SchemaDataTypeParsers.normalizedString) IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) Test(org.junit.Test)

Example 22 with IDataTypeParser

use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.

the class SchemaDataTypeParsersTest method testByte.

@Test
public void testByte() throws Exception {
    IDataTypeParser dtp = XsiDefaultDataTypeParser.instance;
    // test primitives
    assertEquals("-128", dtp.unparseByte(null, dtp.parseByte(null, "-128")));
    assertEquals("127", dtp.unparseByte(null, dtp.parseByte(null, "127")));
    try {
        dtp.parseByte(null, "128");
        fail();
    } catch (Exception e) {
    }
    try {
        dtp.parseByte(null, "-129");
        fail();
    } catch (Exception e) {
    }
}
Also used : IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) Test(org.junit.Test)

Example 23 with IDataTypeParser

use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.

the class SchemaDataTypeParsersTest method testBoolean.

@Test
public void testBoolean() throws Exception {
    IDataTypeParser dtp = XsiDefaultDataTypeParser.instance;
    // test boolean
    String boolString = "true";
    boolean bValue = dtp.parseBoolean(null, boolString);
    assertEquals("true", dtp.unparseBoolean(null, bValue));
    boolString = "1";
    bValue = dtp.parseBoolean(null, boolString);
    assertEquals("true", dtp.unparseBoolean(null, bValue));
    boolString = "false";
    bValue = dtp.parseBoolean(null, boolString);
    assertEquals("false", dtp.unparseBoolean(null, bValue));
    boolString = "0";
    bValue = dtp.parseBoolean(null, boolString);
    assertEquals("false", dtp.unparseBoolean(null, bValue));
    try {
        dtp.parseBoolean(null, "False");
        fail();
    } catch (Exception e) {
    }
    try {
        dtp.parseBoolean(null, "TRUE");
        fail();
    } catch (Exception e) {
    }
}
Also used : SchemaDataTypeParsers.normalizedString(org.whole.lang.xsd.parsers.SchemaDataTypeParsers.normalizedString) IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) Test(org.junit.Test)

Example 24 with IDataTypeParser

use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.

the class SchemaDataTypeParsersTest method testShort.

@Test
public void testShort() throws Exception {
    IDataTypeParser dtp = XsiDefaultDataTypeParser.instance;
    // test primitives
    assertEquals("-32768", dtp.unparseShort(null, dtp.parseShort(null, "-32768")));
    assertEquals("32767", dtp.unparseShort(null, dtp.parseShort(null, "32767")));
    try {
        dtp.parseShort(null, "32768");
        fail();
    } catch (Exception e) {
    }
    try {
        dtp.parseShort(null, "-32769");
        fail();
    } catch (Exception e) {
    }
}
Also used : IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) Test(org.junit.Test)

Example 25 with IDataTypeParser

use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.

the class SchemaDataTypeParsersTest method testLong.

@Test
public void testLong() throws Exception {
    IDataTypeParser dtp = XsiDefaultDataTypeParser.instance;
    // test primitives
    assertEquals("-9223372036854775808", dtp.unparseLong(null, dtp.parseLong(null, "-9223372036854775808")));
    assertEquals("9223372036854775807", dtp.unparseLong(null, dtp.parseLong(null, "9223372036854775807")));
    try {
        dtp.parseLong(null, "9223372036854775808");
        fail();
    } catch (Exception e) {
    }
    try {
        dtp.parseLong(null, "-9223372036854775809");
        fail();
    } catch (Exception e) {
    }
}
Also used : IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) Test(org.junit.Test)

Aggregations

IDataTypeParser (org.whole.lang.parsers.IDataTypeParser)32 Test (org.junit.Test)18 IEntity (org.whole.lang.model.IEntity)12 TestEntitiesEntityFactory (org.whole.lang.testentities.factories.TestEntitiesEntityFactory)10 DataKinds (org.whole.lang.reflect.DataKinds)3 ILanguageKit (org.whole.lang.reflect.ILanguageKit)3 SchemaDataTypeParsers.normalizedString (org.whole.lang.xsd.parsers.SchemaDataTypeParsers.normalizedString)3 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 DateTime (org.joda.time.DateTime)1 Grammar (org.whole.lang.grammars.model.Grammar)1 EnumValue (org.whole.lang.model.EnumValue)1 IOperation (org.whole.lang.operations.IOperation)1 ForwardEntityDescriptorStrategyDataTypeParser (org.whole.lang.parsers.ForwardEntityDescriptorStrategyDataTypeParser)1 AbstractLanguageExtensionDeployer (org.whole.lang.reflect.AbstractLanguageExtensionDeployer)1 DynamicLanguageKit (org.whole.lang.reflect.DynamicLanguageKit)1 EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)1 EntityDescriptorEnum (org.whole.lang.reflect.EntityDescriptorEnum)1