package magic.analyser;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import org.junit.Test;

import magic.expression.Constant;
import magic.expression.Expression;
import magic.lang.Context;
import magic.parser.Parser;

public class TestAnalyse {

	@SuppressWarnings("unchecked")
	public <T> Expression<T> analyse(String t) {
		return (Expression<T>) Analyser.analyse(Parser.parse(t));
	}
	
	@Test 
	public void testLookup() {
		Context c=Context.createWith("foo",Constant.create(1));
		Expression<Integer> e=analyse("foo");
		assertEquals(Integer.valueOf(1),e.compute(c));
		
		try {
			e.compute(Context.EMPTY);
			fail("Should not be able to lookup value in empty context");
		} catch (Throwable t) {
			// OK
		}
	}
}

@@ -125,16 +125,41 @@
 .Test;%0A%0A
+import magic.data.Tuple;%0A
 import m
@@ -773,13 +773,152 @@
  OK%0A%09%09%7D%0A
+%09%7D%0A%09%0A%09@Test %0A%09public void testConstant() %7B%0A%09%09Expression%3CInteger%3E e=analyse(%22%5B1%5D%22);%0A%09%09assertEquals(Tuple.of(1L),e.compute(Context.EMPTY));%0A%0A
 %09%7D%0A%7D%0A

Test constant expression analysis