/*
 * generated by Xtext 2.10.0
 */
package be.uantwerpen.ansymo.semanticadaptation.tests

import com.google.inject.Inject
import org.eclipse.xtext.generator.IGenerator2
import org.junit.Assert
import org.eclipse.xtext.generator.InMemoryFileSystemAccess
import org.eclipse.xtext.generator.IFileSystemAccess
import be.uantwerpen.ansymo.semanticadaptation.generator.SemanticAdaptationPythonGenerator
import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation

abstract class AbstractSemanticAdaptationGeneratorTest extends AbstractSemanticAdaptationParserTest {

	@Inject IGenerator2 generator
	
	InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess()
	
	/**
	 * Generates an output file in the file system using the DSL's code generation
	 */
	def void generateOutputFile(SemanticAdaptation root) {
		//println(root.statements)
		//println(root.imports)
		generator.doGenerate(root.eResource, this.fsa, null)
	}
	
	/**
	 * Compares the default file in memory to the given oracle file
	 */
	def void compareFiles(String oraclefilename) {
		val inmemoryfilename = IFileSystemAccess::DEFAULT_OUTPUT+SemanticAdaptationPythonGenerator::FILENAME
		compareFiles(inmemoryfilename, oraclefilename)
	}
	
	/**
	 * Compares a given file in memory to the given oracle file
	 */
	def void compareFiles(String inmemoryfilename, String oraclefilename) {
		//println(this.fsa.allFiles)
		Assert.assertTrue(inmemoryfilename + " not found", this.fsa.allFiles.containsKey(inmemoryfilename))
		val actualtext = fsa.allFiles.get(inmemoryfilename)
		val expectedtext = readFile('oracles/'+oraclefilename)
		Assert.assertEquals(expectedtext, actualtext)
	}
	
	/**
	 * Parses a given input file, generates code, and compares this to the given oracle file
	 */
	def void parseAndGenerateAndCompare(String inputfilename, String oraclefilename) {
		val root = parseInputFile(inputfilename)
		generateOutputFile(root)
		compareFiles(oraclefilename)
	}

}
