Last active
August 29, 2015 14:07
-
-
Save szarnekow/ad2369160bee7b42e619 to your computer and use it in GitHub Desktop.
Small example to show how to test multiple DSLs with Xtext
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MultiLangInjectorProvider extends MyDslInjectorProvider { | |
override protected internalCreateInjector() { | |
// trigger injector creation of other language | |
new SecondDslInjectorProvider().getInjector | |
return super.internalCreateInjector() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test def void successfulLanguageTest() { | |
val resourceSet = resourceSetProvider.get | |
// create a resource for language 'MyDsl' | |
val firstLang = resourceSet.createResource(URI.createURI("sample.mydsl")) | |
// parse some contents | |
firstLang.load(new StringInputStream(".."), emptyMap) | |
// and read the root instance | |
val root = firstLang.contents.head as MyDslRoot | |
// ensure it's not null | |
assertNotNull(root) | |
// and valid | |
validationTester.assertNoIssues(root) | |
// use the parse helper to read the model under test | |
// into the same resource set | |
val testMe = parseHelper.parse("..", resourceSet) | |
// it's not null, too | |
assertNotNull(testMe) | |
// and also valid | |
validationTester.assertNoIssues(testMe) | |
// more assertions below | |
.. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(XtextRunner) | |
@InjectWith(MyDSLInjectorProvider) | |
class MyTest { | |
// Helper to read models | |
@Inject ParseHelper<MyModel> parseHelper | |
// Helper to test all validation rules and ensure resolved links | |
@Inject ValidationTestHelper validationTester | |
@Test def void myTest() { | |
val model = parseHelper.parse('Hello World!') | |
validationTester.assertNoIssues(model) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment