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: 14661
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


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 Mar 28 16:02:45 GMT 2024

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

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

Back to the top