Search in sources :

Example 1 with EFactoryValueConverter

use of org.eclipse.xtext.conversion.impl.EFactoryValueConverter in project xtext-core by eclipse.

the class EFactoryValueConverterTest method testEBigDecimalConversion.

@Test
public void testEBigDecimalConversion() throws Exception {
    EFactoryValueConverter converter = new EFactoryValueConverter(EcorePackage.Literals.EBIG_DECIMAL);
    BigDecimal value = (BigDecimal) converter.toValue(".5", null);
    assertNotNull(value);
    assertEquals(new BigDecimal("0.5"), value);
}
Also used : EFactoryValueConverter(org.eclipse.xtext.conversion.impl.EFactoryValueConverter) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 2 with EFactoryValueConverter

use of org.eclipse.xtext.conversion.impl.EFactoryValueConverter in project xtext-core by eclipse.

the class EFactoryValueConverterTest method testEmptyString.

@Test
public void testEmptyString() {
    EFactoryValueConverter eIntConverter = new EFactoryValueConverter(EcorePackage.Literals.EINT);
    try {
        eIntConverter.toValue("", null);
        fail("EInt converter should not convert empty string");
    } catch (ValueConverterException e) {
    // expected result
    }
    try {
        EFactoryValueConverter eIntegerConverter = new EFactoryValueConverter(EcorePackage.Literals.EINTEGER_OBJECT);
        eIntegerConverter.toValue("", null);
        fail("EInteger converter should not convert empty string");
    } catch (ValueConverterException e) {
        // expected result
        assertTrue(e.getCause() instanceof NumberFormatException);
    }
}
Also used : EFactoryValueConverter(org.eclipse.xtext.conversion.impl.EFactoryValueConverter) ValueConverterException(org.eclipse.xtext.conversion.ValueConverterException) Test(org.junit.Test)

Example 3 with EFactoryValueConverter

use of org.eclipse.xtext.conversion.impl.EFactoryValueConverter in project xtext-core by eclipse.

the class EFactoryValueConverterTest method testNullString.

@Test
public void testNullString() {
    EFactoryValueConverter eIntConverter = new EFactoryValueConverter(EcorePackage.Literals.EINT);
    try {
        eIntConverter.toValue(null, null);
        fail("EInt converter should not convert empty string");
    } catch (ValueConverterException e) {
    // expected result
    }
    EFactoryValueConverter eIntegerConverter = new EFactoryValueConverter(EcorePackage.Literals.EINTEGER_OBJECT);
    assertNull(eIntegerConverter.toValue(null, null));
}
Also used : EFactoryValueConverter(org.eclipse.xtext.conversion.impl.EFactoryValueConverter) ValueConverterException(org.eclipse.xtext.conversion.ValueConverterException) Test(org.junit.Test)

Example 4 with EFactoryValueConverter

use of org.eclipse.xtext.conversion.impl.EFactoryValueConverter in project xtext-core by eclipse.

the class EFactoryValueConverterTest method testEFactoryValueConverter.

@Test
public void testEFactoryValueConverter() throws Exception {
    EFactoryValueConverter eDoubleConverter = new EFactoryValueConverter(EcorePackage.Literals.EDOUBLE);
    String doubleAsString = eDoubleConverter.toString(TEST_DOUBLE_VALUE);
    assertEquals(Double.toString(TEST_DOUBLE_VALUE), doubleAsString);
    Object value = eDoubleConverter.toValue(doubleAsString, null);
    assertTrue(value instanceof Double);
    assertEquals(((Double) value).doubleValue(), TEST_DOUBLE_VALUE, 0.0001);
}
Also used : EFactoryValueConverter(org.eclipse.xtext.conversion.impl.EFactoryValueConverter) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test)

Aggregations

EFactoryValueConverter (org.eclipse.xtext.conversion.impl.EFactoryValueConverter)4 Test (org.junit.Test)4 ValueConverterException (org.eclipse.xtext.conversion.ValueConverterException)2 BigDecimal (java.math.BigDecimal)1 EObject (org.eclipse.emf.ecore.EObject)1