package net.yak.stalk;

import net.yak.stalk.Expr.Send;
import net.yak.stalk.Pro.Num;
import net.yak.stalk.Pro.Str;
import net.yak.stalk.Talk.Terp;
import net.yak.stalk.Talk.Terp.Frame;
import junit.framework.TestCase;

public class TalkTest extends TestCase {
	Terp t;
	Frame f;

	public TalkTest(String arg0) {
		super(arg0);
	}

	protected void setUp() throws Exception {
		super.setUp();
		t = new Terp();
		f = t.newFrame(null, null);
		f.dict.put("p", new Num(t, 23));
		f.dict.put("q", new Num(t, 42));
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public void testNumPlus() {
		Expr r = new Expr.GetLocalVar("p");
		Expr a = new Expr.GetLocalVar("q");
		Expr args[] = new Expr[] {a};
		Expr expr = new Send(r, "pl:", args);
		Num z = expr.eval(f).asNum();
		assertNotNull(z);
		assertEquals(65.0, z.num);
	}
	public void testNumClsNam() {
		Expr r = new Expr.GetLocalVar("p");
		Expr none[] = new Expr[0];
		Expr clsx = new Send(r, "cls", none);
		Expr namx = new Send(clsx, "nam", none);
		Str z = namx.eval(f).asStr();
		assertNotNull(z);
		assertEquals("Num", z.str);
	}
}
