aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble/couscous/tests/JavaToInterpreterTests.java
blob: 203a0882cf00bfd23d06f2fe09b9793d62b15288 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package org.zwobble.couscous.tests;

import com.google.common.collect.ImmutableList;
import org.junit.Ignore;
import org.zwobble.couscous.ast.ClassNode;
import org.zwobble.couscous.ast.TypeName;
import org.zwobble.couscous.frontends.java.JavaFrontend;
import org.zwobble.couscous.interpreter.Interpreter;
import org.zwobble.couscous.interpreter.JavaProject;
import org.zwobble.couscous.interpreter.Project;
import org.zwobble.couscous.interpreter.values.InterpreterValue;
import org.zwobble.couscous.interpreter.values.InterpreterValues;
import org.zwobble.couscous.values.PrimitiveValue;

import java.io.IOException;
import java.nio.file.Path;
import java.util.List;

import static com.google.common.collect.Iterables.transform;

@Ignore
public class JavaToInterpreterTests extends CompilerTests {
    @Override
    protected PrimitiveValue execProgram(
        Path directory,
        TypeName type,
        String methodName,
        List<PrimitiveValue> arguments
    ) throws IOException, InterruptedException {
        JavaFrontend frontend = new JavaFrontend();
        List<ClassNode> classNodes = frontend.readSourceDirectory(directory, directory);

        Project project = JavaProject.of(classNodes);
        Interpreter interpreter = new Interpreter(project);
        List<InterpreterValue> argumentValues = ImmutableList.copyOf(transform(arguments, InterpreterValues::value));

        return interpreter.run(type, methodName, argumentValues)
            .toPrimitiveValue().get();
    }
}