|
|
|
|
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 |
|
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
Day Job: https://www.everest-systems.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 |
|
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
Day Job: https://www.everest-systems.com
|
|
|
Powered by
FUDForum. Page generated in 0.04292 seconds