JavaTXCompilerInJavaTX/test/typeinference/JavaTXCompilerTest.java

57 lines
2.2 KiB
Java
Raw Normal View History

2017-03-02 17:16:14 +00:00
package typeinference;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.parser.ClassNotFoundException;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
2017-06-28 19:10:28 +00:00
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.typeinference.ResultSet;
2017-03-02 17:16:14 +00:00
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
2017-05-31 15:10:50 +00:00
import java.util.ArrayList;
import java.util.List;
2017-03-02 17:16:14 +00:00
import static org.junit.Assert.*;
2017-06-28 19:10:28 +00:00
public class JavaTXCompilerTest extends JavaTXCompiler {
2017-03-02 17:16:14 +00:00
private static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/";
2017-05-31 15:10:50 +00:00
private static final List<File> filesToTest = new ArrayList<>();
2017-03-02 17:16:14 +00:00
@Test
public void test() throws IOException, ClassNotFoundException {
2017-06-28 15:20:26 +00:00
filesToTest.add(new File(rootDirectory+"Faculty.jav"));
//filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
2017-06-26 16:19:56 +00:00
//filesToTest.add(new File(rootDirectory+"Lambda.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda3.jav"));
2017-05-31 15:10:50 +00:00
//filesToTest.add(new File(rootDirectory+"Vector.jav"));
//filesToTest.add(new File(rootDirectory+"Generics.jav"));
//filesToTest.add(new File(rootDirectory+"MethodsEasy.jav"));
//filesToTest.add(new File(rootDirectory+"Matrix.jav"));
for(File f : filesToTest){
2017-06-28 19:10:28 +00:00
this.parse(f);
System.out.println(ASTPrinter.print(this.sourceFiles.get(sourceFiles.size()-1)));
List<TypeInsert> result = this.getTypeInserts(f);
2017-05-31 15:10:50 +00:00
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
for(TypeInsert tip : result){
2017-05-31 15:10:50 +00:00
System.out.println(tip.insert(content));
}
}
2017-05-31 15:10:50 +00:00
}
static String readFile(String path, Charset encoding)
throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
2017-03-02 17:16:14 +00:00
}
}