package yak;

import yak.Talk.Terp;
import junit.framework.TestCase;

public class ParserTest extends TestCase {
	Terp t;

	protected void setUp() throws Exception {
		super.setUp();
		t = new Terp();
	}

	public void testOmitComments() {
		assertEquals("marco polo", Parser.omitComments("marco\"coment\"polo"));
	}
	
	public void testLit888() {
		Expr e = Parser.parse(t, " 888 ");
		assertEquals(Expr.Lit.class, e.getClass());
		assertEquals(888.0, ((Expr.Lit)e).value.asNum().num);
	}
	public void testLitString() {
		Expr e = Parser.parse(t, " 'foo''bar' ");
		assertEquals(Expr.Lit.class, e.getClass());
		assertEquals("foo'bar", ((Expr.Lit)e).value.asStr().str);
	}
	public void testTwoStmts() {
		Expr e = Parser.parse(t, " . 23 . 42 . . . ");
		assertEquals(Expr.Seq.class, e.getClass());
		assertEquals(2, ((Expr.Seq)e).body.length);
	}
	public void testPlusTwoNums() {
		Expr e = Parser.parse(t, " 23 pl: 42  ");
		assertEquals(Expr.Send.class, e.getClass());
		assertEquals(1, ((Expr.Send)e).args.length);
		assertEquals("pl:", ((Expr.Send)e).msg);
	}
	public void testBlock() {
		Expr e = Parser.parse(t, " [ 23 pl: 42 . ] .  ");
		assertEquals(Expr.Block.class, e.getClass());
	}

}
