Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to parse a normal text file for unit test
How to parse a normal text file for unit test [message #1779146] Wed, 03 January 2018 09:01 Go to next message
shubhankar chowdhury is currently offline shubhankar chowdhuryFriend
Messages: 3
Registered: January 2018
Junior Member
I am writing some unit test, So I want to parse the xtext file to generate some xml , basically I want to parse the file as model in unit test and use it to generate its corresponding xml?
Re: How to parse a normal text file for unit test [message #1779190 is a reply to message #1779146] Wed, 03 January 2018 17:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11892
Registered: July 2009
Senior Member
hi,

what exactly is your problem?


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: How to parse a normal text file for unit test [message #1779191 is a reply to message #1779146] Wed, 03 January 2018 17:18 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5834
Registered: July 2009
Senior Member
Hi

This happens automatically, if you just use the normal standard EMF ResourceSet.getResource API

GIT\org.eclipse.ocl\examples\org.eclipse.ocl.examples.xtext2lpg\src\org\eclipse\ocl\examples\xtext2lpg\xtext2xbnf.qvto

shiows that a *.xtext file can be the input for a QVTo transformation (again just exploiting Xtext's nice automatic parsing from grammar-defined source to equivalent token model).

Regards

Ed Willink
Re: How to parse a normal text file for unit test [message #1779234 is a reply to message #1779190] Thu, 04 January 2018 09:13 Go to previous messageGo to next message
shubhankar chowdhury is currently offline shubhankar chowdhuryFriend
Messages: 3
Registered: January 2018
Junior Member
I want to know how to parse a XXXX.myExtension file in my unit test which should generate some xml file correspond to XXXX.myExtension file .

Note: xxxx.myExtension in somewhere in some different package in same project
Re: How to parse a normal text file for unit test [message #1779242 is a reply to message #1779234] Thu, 04 January 2018 10:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11892
Registered: July 2009
Senior Member
there are may factors on how you run your unit test etc. you give zero context so its just wild wild guessing what fits for you

@RunWith(XtextRunner)
@InjectWith(MyDslInjectorProvider)
class MyDslParsingTest {
	@Inject
	Provider<ResourceSet> rsp
	
	@Test
	def void loadModel() {
		val rs = rsp.get
		// better use a file uri, but your question lacks context
		val r = rs.getResource(URI.createURI("classpath:/org/xtext/example/other/other.mydsl"), true)
		r.load(null)
		val model = r.contents.head as Model
		for (g : model.greetings) {
			println(g.name)
		}
	}
}



Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: How to parse a normal text file for unit test [message #1779243 is a reply to message #1779242] Thu, 04 January 2018 10:26 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11892
Registered: July 2009
Senior Member
or with some generator calling

@RunWith(XtextRunner)
@InjectWith(MyDslInjectorProvider)
class MyDslParsingTest {
	@Inject
	Provider<ResourceSet> rsp
	
	@Inject
	GeneratorDelegate generatorDelegate
	
	@Test
	def void loadModel() {
		val rs = rsp.get
		// better use a file uri, but your question lacks context
		val r = rs.getResource(URI.createURI("classpath:/org/xtext/example/other/other.mydsl"), true)
		r.load(null)
		val model = r.contents.head as Model
		for (g : model.greetings) {
			println(g.name)
		}
		val GeneratorContext context = new GeneratorContext();
		context.setCancelIndicator(CancelIndicator.NullImpl);
		val fsa = new InMemoryFileSystemAccess
		generatorDelegate.doGenerate(r,fsa,context)
		println(fsa.allFiles)
	}
}


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Previous Topic:Quickfix NullPointerException in PartialSerializer
Next Topic:Connecting to a non-xtext language from Eclipse: Binding ResourceDescriptionStrategy
Goto Forum:
  


Current Time: Fri Apr 20 11:06:56 GMT 2018

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

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