Package nodebox.function

Source Code of nodebox.function.ClojureLibraryTest

package nodebox.function;

import nodebox.node.Node;
import nodebox.node.NodeContext;
import nodebox.node.NodeLibrary;
import nodebox.node.Port;
import nodebox.util.LoadException;
import org.junit.Test;

import static nodebox.util.Assertions.assertResultsEqual;

public class ClojureLibraryTest {

    private final FunctionLibrary mathLibrary = ClojureLibrary.loadScript("src/test/clojure/math.clj");
    private final FunctionRepository functions = FunctionRepository.of(mathLibrary);
    private final NodeLibrary testLibrary = NodeLibrary.create("test", Node.ROOT, functions);
    private final NodeContext context = new NodeContext(testLibrary);

    @Test
    public void testAdd() {
        Node addNode = Node.ROOT
                .withName("add")
                .withOutputType("int")
                .withFunction("clojure-math/add");
        Iterable<?> results = context.renderNode(addNode);
        assertResultsEqual(results, 0L);
    }

    @Test
    public void testAddWithArguments() {
        Node addNode = Node.ROOT
                .withName("add")
                .withFunction("clojure-math/add")
                .withOutputType("int")
                .withInputAdded(Port.intPort("v1", 1))
                .withInputAdded(Port.intPort("v2", 2))
                .withInputAdded(Port.intPort("v3", 3));
        Iterable<?> results = context.renderNode(addNode);
        assertResultsEqual(results, 6L);
    }

    @Test(expected = LoadException.class)
    public void testNoVarAtEnd() {
        ClojureLibrary.loadScript("src/test/clojure/no-var-at-end.clj");
    }
}
TOP

Related Classes of nodebox.function.ClojureLibraryTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.