Skip to main content



      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 04:01 Go to next message
Eclipse UserFriend
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 12:16 Go to previous messageGo to next message
Eclipse UserFriend
hi,

what exactly is your problem?
Re: How to parse a normal text file for unit test [message #1779191 is a reply to message #1779146] Wed, 03 January 2018 12:18 Go to previous messageGo to next message
Eclipse UserFriend
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 04:13 Go to previous messageGo to next message
Eclipse UserFriend
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 05:21 Go to previous messageGo to next message
Eclipse UserFriend
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)
		}
	}
}

Re: How to parse a normal text file for unit test [message #1779243 is a reply to message #1779242] Thu, 04 January 2018 05:26 Go to previous message
Eclipse UserFriend
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)
	}
}
Previous Topic:Quickfix NullPointerException in PartialSerializer
Next Topic:Connecting to a non-xtext language from Eclipse: Binding ResourceDescriptionStrategy
Goto Forum:
  


Current Time: Wed Jul 23 16:43:59 EDT 2025

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

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

Back to the top