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);
}
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);
}
}
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));
}
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);
}
Aggregations