Java Code Examples for org.eclipse.xtext.conversion.ValueConverterWithValueException#getValue()

The following examples show how to use org.eclipse.xtext.conversion.ValueConverterWithValueException#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaIDValueConverterTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testInvalidUnicode() {
  final String s = "a\\u0060";
  try {
    this.valueConverterService.toValue(s, "ID", null);
  } catch (final Throwable _t) {
    if (_t instanceof ValueConverterWithValueException) {
      final ValueConverterWithValueException e = (ValueConverterWithValueException)_t;
      Object _value = e.getValue();
      final String value = ((String) _value);
      Assert.assertEquals("a", value);
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
Example 2
Source File: JavaIDValueConverterTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testUnclosedUnicode_01() {
  final String s = "a\\u006";
  try {
    this.valueConverterService.toValue(s, "ID", null);
  } catch (final Throwable _t) {
    if (_t instanceof ValueConverterWithValueException) {
      final ValueConverterWithValueException e = (ValueConverterWithValueException)_t;
      Object _value = e.getValue();
      final String value = ((String) _value);
      Assert.assertEquals("au006", value);
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
Example 3
Source File: JavaIDValueConverterTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testUnclosedUnicode_02() {
  final String s = "a\\u";
  try {
    this.valueConverterService.toValue(s, "ID", null);
  } catch (final Throwable _t) {
    if (_t instanceof ValueConverterWithValueException) {
      final ValueConverterWithValueException e = (ValueConverterWithValueException)_t;
      Object _value = e.getValue();
      final String value = ((String) _value);
      Assert.assertEquals("au", value);
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
Example 4
Source File: JavaIDValueConverterTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testTrailingBackslash() {
  final String s = "a\\";
  try {
    this.valueConverterService.toValue(s, "ID", null);
  } catch (final Throwable _t) {
    if (_t instanceof ValueConverterWithValueException) {
      final ValueConverterWithValueException e = (ValueConverterWithValueException)_t;
      Object _value = e.getValue();
      final String value = ((String) _value);
      Assert.assertEquals("a", value);
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
Example 5
Source File: IdentifierValueConverterTest.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
public void assertError(String expected, String input) {
	try {
		IdentifierValueConverter.convertFromN4JSIdentifier(input, null);
		fail("expected exception");
	} catch (ValueConverterWithValueException e) {
		String result = (String) e.getValue();
		assertEquals(expected, result);
	}
}
 
Example 6
Source File: RichTextValueConverterTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void doTestIncompleteRichString(String text, String expectation) {
	RichTextValueConverter converter = get(RichTextValueConverter.class);
	try {
		converter.toValue(text, null);
		fail("Expected ValueConverterWithValueException");
	} catch(ValueConverterWithValueException e) {
		String value = (String) e.getValue();
		assertEquals(expectation, value);
	}
}
 
Example 7
Source File: RichTextValueConverterTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void doTestIncompleteRichStringEnd(String text, String expectation) {
	RichTextEndValueConverter converter = get(RichTextEndValueConverter.class);
	try {
		converter.toValue(text, null);
		fail("Expected ValueConverterWithValueException");
	} catch(ValueConverterWithValueException e) {
		String value = (String) e.getValue();
		assertEquals(expectation, value);
	}
}
 
Example 8
Source File: STRINGConverterTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testUnicodeSequenceLength() throws Exception {
	try {
		valueConverter.toValue("'\\u123'", null);
		fail("Illegal short unicode sequence not detected");
	} catch(ValueConverterWithValueException e) {
		String s = (String) e.getValue();
		assertEquals("u123", s);
		assertTrue(e.hasRange());
		assertEquals(1, e.getOffset());
		assertEquals(2, e.getLength());
	}
	assertEquals("\u1234", valueConverter.toValue("'\\u1234'", null));
}