Skip to main content


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: 17
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: 14665
Registered: July 2009
Senior Member
hi,

what exactly is your problem?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
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: 7655
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: 17
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: 14665
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)
		}
	}
}



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
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: 14665
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)
	}
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Quickfix NullPointerException in PartialSerializer
Next Topic:Connecting to a non-xtext language from Eclipse: Binding ResourceDescriptionStrategy
Goto Forum:
  


Current Time: Thu Apr 25 09:18:40 GMT 2024

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

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

Back to the top