AbstractSemanticAdaptationGeneratorTest.xtend 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * generated by Xtext 2.10.0
  3. */
  4. package be.uantwerpen.ansymo.semanticadaptation.tests
  5. import com.google.inject.Inject
  6. import org.eclipse.xtext.generator.IGenerator2
  7. import org.junit.Assert
  8. import org.eclipse.xtext.generator.InMemoryFileSystemAccess
  9. import org.eclipse.xtext.generator.IFileSystemAccess
  10. import be.uantwerpen.ansymo.semanticadaptation.generator.SemanticAdaptationPythonGenerator
  11. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation
  12. abstract class AbstractSemanticAdaptationGeneratorTest extends AbstractSemanticAdaptationParserTest {
  13. @Inject IGenerator2 generator
  14. InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess()
  15. /**
  16. * Generates an output file in the file system using the DSL's code generation
  17. */
  18. def void generateOutputFile(SemanticAdaptation root) {
  19. //println(root.statements)
  20. //println(root.imports)
  21. generator.doGenerate(root.eResource, this.fsa, null)
  22. }
  23. /**
  24. * Compares the default file in memory to the given oracle file
  25. */
  26. def void compareFiles(String oraclefilename) {
  27. val inmemoryfilename = IFileSystemAccess::DEFAULT_OUTPUT+SemanticAdaptationPythonGenerator::FILENAME
  28. compareFiles(inmemoryfilename, oraclefilename)
  29. }
  30. /**
  31. * Compares a given file in memory to the given oracle file
  32. */
  33. def void compareFiles(String inmemoryfilename, String oraclefilename) {
  34. //println(this.fsa.allFiles)
  35. Assert.assertTrue(inmemoryfilename + " not found", this.fsa.allFiles.containsKey(inmemoryfilename))
  36. val actualtext = fsa.allFiles.get(inmemoryfilename)
  37. val expectedtext = readFile('oracles/'+oraclefilename)
  38. Assert.assertEquals(expectedtext, actualtext)
  39. }
  40. /**
  41. * Parses a given input file, generates code, and compares this to the given oracle file
  42. */
  43. def void parseAndGenerateAndCompare(String inputfilename, String oraclefilename) {
  44. val root = parseInputFile(inputfilename)
  45. generateOutputFile(root)
  46. compareFiles(oraclefilename)
  47. }
  48. }