aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble/couscous/tests/JavaToInterpreterTests.java
blob: 763a4e75e1fc29ed5734150d8084f25f5181526b (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
41
42
43
44
45
46
47
package org.zwobble.couscous.tests;

import com.google.common.collect.ImmutableList;
import org.junit.Ignore;
import org.junit.Test;
import org.zwobble.couscous.types.ScalarType;
import org.zwobble.couscous.ast.TypeNode;
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;
import static org.zwobble.couscous.util.ExtraLists.list;

public class JavaToInterpreterTests extends CompilerTests {
    @Test
    @Ignore("WIP")
    public void genericInterfacesCanHaveMethodsWithoutGenericReturnType() throws Exception {
    }

    @Override
    protected PrimitiveValue execProgram(
        Path directory,
        ScalarType type,
        String methodName,
        List<PrimitiveValue> arguments,
        ScalarType returnType
    ) throws IOException, InterruptedException {
        JavaFrontend frontend = new JavaFrontend();
        List<TypeNode> classNodes = frontend.readSourceDirectory(list(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, returnType)
            .toPrimitiveValue().get();
    }
}