Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 351719

Summary: [Testing API] Improve ParseHelper
Product: [Modeling] TMF Reporter: Christian Dietrich <christian.dietrich.opensource>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: sebastian.zarnekow
Version: 2.0.0Flags: sebastian.zarnekow: indigo+
Target Milestone: SR2   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Christian Dietrich CLA 2011-07-11 10:46:36 EDT
Build Identifier: 2.0.0

With ParserHelper i have a nice and easy way to parse model files for tests.
but the support for tests that include global scoping could be better e.g.

@InjectWith(typeof(DomainmodelInjectorProvider))
@RunWith(typeof(XtextRunner))
class ParserTest {
	@Inject
	ParseHelper<Domainmodel> parser
	
	@Inject
	Provider<XtextResourceSet> resourceSetProvider
	
	@Test
	def void parseEmptyEntity() {
		val rs = resourceSetProvider.get
		val model = parser.parse(
		getAsStream("entity MyEntity {}"), URI::createURI("a.dmodel") , null,rs)
		val model2 = parser.parse(
			getAsStream("entity MyEntity2 extends MyEntity {}"),URI::createURI("b.dmodel") ,null, rs)
		val Entity entity = model.elements.head as Entity
		assertTrue(entity.features.isEmpty)
		val Entity entity2 = model2.elements.head as Entity
		println(entity2.superType.simpleName)
	}
	
	def InputStream getAsStream(CharSequence text) {
		new StringInputStream(text.toString)
	}
}

could be much easier if ParserHelper would offer a method

public T parse(String content, String uriToUse, ResourceSet resourceSet);

or even 
public T parse(String content, String uriToUse);

with beeing a global resourceset beeing default

Reproducible: Always
Comment 1 Sebastian Zarnekow CLA 2011-09-30 04:38:43 EDT
A patch is welcome.
Comment 2 Sebastian Zarnekow CLA 2011-09-30 04:40:25 EDT
(In reply to comment #1)
> A patch is welcome.

For clarification: The patch should introduce something like

#parse(CharSequence, String uri, ResourceSet resourceSet)

I don't like the idea of a 'global' resource set and the parse helper should be stateless.
Comment 3 Christian Dietrich CLA 2011-09-30 05:15:57 EDT
this seems to be already fixed.
Comment 4 Sebastian Zarnekow CLA 2011-09-30 05:17:01 EDT
See last comment.
Comment 5 Christian Dietrich CLA 2011-09-30 05:24:00 EDT
Hi,

no i actually saw that 	

public T parse(CharSequence text, URI uriToUse, ResourceSet resourceSetToUse)
			throws Exception {
		return super.parse(getAsStream(text),uriToUse, null, resourceSetToUse);
	}

is still missing
just copy and paste add this method.

~Christian
Comment 6 Sebastian Zarnekow CLA 2011-10-12 09:27:05 EDT
Pushed to master.
Comment 7 Karsten Thoms CLA 2017-09-19 17:02:14 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 8 Karsten Thoms CLA 2017-09-19 17:13:36 EDT
Closing all bugs that were set to RESOLVED before Neon.0