package function.builtin.cons;

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

import org.junit.Test;

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

public class RESTTest extends SymbolAndFunctionCleaner {

    @Test
    public void restOfNil() {
        String input = "(rest nil)";

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

    @Test
    public void restOfList() {
        String input = "(rest '(1 2 3))";

        assertSExpressionsMatch(parseString("(2 3)"), evaluateString(input));
    }

    @Test
    public void cdrOfList() {
        String input = "(cdr '(1 2 3))";

        assertSExpressionsMatch(parseString("(2 3)"), evaluateString(input));
    }

    @Test
    public void nestedRestOfList() {
        String input = "(rest (rest '(1 2 3)))";

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

    @Test(expected = BadArgumentTypeException.class)
    public void restOfSymbol() {
        evaluateString("(rest 'x)");
    }

    @Test(expected = TooManyArgumentsException.class)
    public void restWithTooManyArguments() {
        evaluateString("(rest '(1 2) '(1 2) \"oh\")");
    }

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

}
