Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » why a parser exception inside a converter is ignored by my test ?
why a parser exception inside a converter is ignored by my test ? [message #903686] Fri, 24 August 2012 21:44 Go to next message
Cristiano Gavião is currently offline Cristiano GaviãoFriend
Messages: 279
Registered: July 2009
Senior Member
Hi,

I've created a test to evaluate an informed date:

	public void configureDateFormat(Binder binder) {

		binder.bind(String.class).annotatedWith(Names.named("dateFormat"))
				.toInstance("dd/MM/YYYY");
	}


@Test
	def void testParsingLibraryAttributes() {
		val library = '''
			libraryID library.templates.core.base
				description "My description"
				creationDate "10/01/2012a"
				creator cvgaviao
				
			}
		'''.parse
		
		assertEquals("library.templates.core.base", library.getName())
		
	}


@Inject
	@Named("dateFormat")
	private String dateFormat;

@Override
protected Date internalToValue(String string, INode node)
					throws ValueConverterException {
				string = string.substring(1, string.length() - 1);

				
				try {
					
					SimpleDateFormat fmt = new SimpleDateFormat(dateFormat);
					fmt.setTimeZone(TimeZone.getTimeZone(timeZoneFormat));
					return fmt.parse(string);
				} catch (Exception e) {
					// ignore and try timestamp format
					System.err.println(e.getMessage());
					throw new ValueConverterException(
							"Not in timestamp format", node,
							new IllegalArgumentException());
				}


With some debugging I could note that the converter is failing because a Illegal pattern character 'Y'. but the test are green...

could someone help to identify I'm missing ?

thanks.

Cristiano
Re: why a parser exception inside a converter is ignored by my test ? [message #903688 is a reply to message #903686] Fri, 24 August 2012 21:51 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13468
Registered: July 2009
Senior Member
Hi

the parse helper does not give errors - you have to write a modified version (have a look at the source code)
http://www.eclipse.org/forums/index.php/mv/msg/369186/900856/#msg_900856

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:possibility to have one xtext editor for many files?
Next Topic:New Project Wizard without use XtextNewProjectWizard ?
Goto Forum:
  


Current Time: Thu May 28 05:47:40 GMT 2020

Powered by FUDForum. Page generated in 0.01796 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top