package function.builtin;

import static testutil.TestUtilities.assertSExpressionsMatch;
import static testutil.TestUtilities.evaluateString;
import static testutil.TestUtilities.parseString;

import org.junit.Test;

import function.ArgumentValidator.TooFewArgumentsException;
import testutil.SymbolAndFunctionCleaner;

public class FUNCALLTest extends SymbolAndFunctionCleaner {

    @Test
    public void funcallWithNumbers() {
        String input = "(funcall '+ 1 2 3)";

        assertSExpressionsMatch(parseString("6"), evaluateString(input));
    }

    @Test
    public void callWithNumbers() {
        String input = "(call '+ 1 2 3)";

        assertSExpressionsMatch(parseString("6"), evaluateString(input));
    }

    @Test
    public void funcallWithUserDefinedFunction() {
        String defineUserFunction = "(defun x (n m) (+ n m))";
        String input = "(funcall 'x 2 30)";

        evaluateString(defineUserFunction);
        assertSExpressionsMatch(parseString("32"), evaluateString(input));
    }

    @Test(expected = TooFewArgumentsException.class)
    public void funcallWithTooFewArguments() {
        evaluateString("(funcall)");
    }

}
