JavaTXCompilerInJavaTX/test/typeinference/JavaTXCompilerTest.java

128 lines
4.7 KiB
Java
Raw Normal View History

2017-03-02 17:16:14 +00:00
package typeinference;
import de.dhbwstuttgart.core.JavaTXCompiler;
2017-07-05 15:42:41 +00:00
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
2017-06-30 09:13:15 +00:00
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
2017-07-05 15:42:41 +00:00
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
2017-09-07 17:52:05 +00:00
import de.dhbwstuttgart.typeinference.result.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;
2017-12-18 13:43:03 +00:00
import java.util.HashSet;
import java.util.List;
2017-08-22 14:45:28 +00:00
import java.util.Set;
2017-03-02 17:16:14 +00:00
public class JavaTXCompilerTest {
2017-03-02 17:16:14 +00:00
2017-09-19 16:51:44 +00:00
public static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/";
2018-02-28 12:22:07 +00:00
@Test
public void finiteClosure() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"fc.jav"));
}
@Test
public void lambda() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Lambda.jav"));
}
@Test
public void lambda2() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Lambda2.jav"));
}
@Test
public void lambda3() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Lambda3.jav"));
}
@Test
public void mathStruc() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"mathStruc.jav"));
}
@Test
public void generics() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Generics.jav"));
}
@Test
public void faculty() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Faculty.jav"));
}
@Test
public void facultyTyped() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"FacultyTyped.jav"));
}
@Test
2018-02-28 12:22:07 +00:00
public void matrix() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Matrix.jav"));
}
@Test
public void vector() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Vector.jav"));
}
@Test
public void lambdaRunnable() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"LambdaRunnable.jav"));
2017-09-19 16:51:44 +00:00
}
2017-03-02 17:16:14 +00:00
@Test
2018-02-28 12:22:07 +00:00
public void expressions() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Expressions.jav"));
}
private static class TestResultSet{
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
2017-11-03 12:56:04 +00:00
//filesToTest.add(new File(rootDirectory+"fc.jav"));
2017-08-28 13:42:51 +00:00
//filesToTest.add(new File(rootDirectory+"Lambda.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda3.jav"));
//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"));
2017-08-28 16:36:26 +00:00
//filesToTest.add(new File(rootDirectory+"Import.jav"));
2018-02-28 12:22:07 +00:00
// //filesToTest.add(new File(rootDirectory+"Faculty.jav"));
// //filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
// //filesToTest.add(new File(rootDirectory+"test.jav"));
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
2017-12-18 13:43:03 +00:00
List<ResultSet> results = compiler.typeInference();
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
System.out.println(ASTTypePrinter.print(sf));
System.out.println(ASTPrinter.print(sf));
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
assert results.size()>0;
2017-12-18 13:43:03 +00:00
Set<String> insertedTypes = new HashSet<>();
for(ResultSet resultSet : results){
2017-09-07 17:52:05 +00:00
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet);
assert result.size()>0;
2017-09-07 17:52:05 +00:00
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
for(TypeInsert tip : result){
2017-12-18 13:43:03 +00:00
insertedTypes.add(tip.insert(content));
2017-09-07 17:52:05 +00:00
}
2017-05-31 15:10:50 +00:00
}
2017-12-18 13:43:03 +00:00
for(String s : insertedTypes){
System.out.println(s);
}
}
2018-02-28 12:22:07 +00:00
return new TestResultSet();
}
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
}
2017-06-30 09:13:15 +00:00
2017-09-19 16:51:44 +00:00
}