package com.jedrzejewski.slisp.interpreter.specialforms;

import com.jedrzejewski.slisp.TestUtils;
import com.jedrzejewski.slisp.interpreter.Interpreter;
import com.jedrzejewski.slisp.parser.lispobjects.Num;
import org.junit.Assert;
import org.junit.Test;

public class FnFormTest {

    @Test
    public void testBindAndCall() throws Exception {
        Interpreter interpreter = new Interpreter();
        TestUtils.evalString("(set! inc (fn [n] (+ n 1)))", interpreter);
        Assert.assertEquals(
                new Num(2),
                TestUtils.evalString("(inc 1)", interpreter)
        );
    }

    // TODO: add lexical binding test
}

@@ -315,11 +315,12 @@
 Bind
-And
+Then
 Call
@@ -604,16 +604,221 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void testDefineAndCall() throws Exception %7B%0A        Assert.assertEquals(%0A                new Num(6),%0A                TestUtils.evalString(%22((fn %5Ba b%5D (* a b)) 3 2)%22)%0A        );%0A    %7D%0A%0A
     // T

Test calling just defined function