package edu.ufl.cise.cop5555.sp12.context;

import org.junit.Test;

import edu.ufl.cise.cop5555.sp12.Parser;
import edu.ufl.cise.cop5555.sp12.TestParser;
import edu.ufl.cise.cop5555.sp12.TokenStream;
import edu.ufl.cise.cop5555.sp12.ast.AST;
/*
 * 	First Verification 17th Apr 2012
 *  Testsuite: edu.ufl.cise.cop5555.sp12.context.TestTypeChecker
 *  Tests run: 110, Failures: 3, Errors: 29, Time elapsed: 3.854 sec
 */
public class ContextCheckVisitorTest
{
    private Parser parser = null;
    private ContextCheckVisitor visitor = new ContextCheckVisitor();
    
    private void initParser(String input)
    {
        TokenStream stream = TestParser.getInitializedTokenStream(input);
        parser = new Parser(stream);
    }
    
    //Implemented looking at Logs    
    //Error testIntDecWrong3,testBooleanDecWrong3 testStringDecWrong1 testMapDec2-4 testMapDecWrong1-5 testIfElseCommandWrong1 testPairExpression1-3
    //testBinaryOp2,3,5,6,12,13 testBinaryOpWrong2-5,8-14
    
    @Test(expected=ContextException.class)
    public void testProgNameAsIdent1() throws Exception
    {
        String input = "prog myname int myname; myname =0; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testProgNameAsIdent2() throws Exception
    {
        String input = "prog myname do(true) int myname; od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testProgNameAsIdent3() throws Exception
    {
        String input = "prog myname if(true) int myname; fi; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testProgNameAsIdent4() throws Exception
    {
        String input = "prog myname if(true) myname = 4; fi; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test (expected=ContextException.class)
    public void testRepeatedDeclaration1() throws Exception
    {
        String input = "prog progname int myname; int myname; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test (expected=ContextException.class)
    public void testRepeatedDeclaration2() throws Exception
    {
        String input = "prog progname do (2<4) int myname; int myname; od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test (expected=ContextException.class)
    public void testRepeatedDeclaration3() throws Exception
    {
        String input = "prog progname if (2<4) int myname; int myname; else int x; fi; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testNestedDeclaration1() throws Exception
    {
        String input = "prog progname int myname; do (2<5) int myname; od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
        
    }
    @Test
    public void testNestedDeclaration2() throws Exception
    {
        String input = "prog progname int myname; if(2>4) int myname; fi; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testEmptyProgram() throws Exception
    {
        String input = "prog Test1 gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testIntDec() throws Exception
    {
        String input = "prog Test1 int x; x = 0; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }    
    @Test
    public void testBooleanDec() throws Exception
    {
        String input = "prog Test1 boolean x; x = true; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testStringDec() throws Exception
    {
        String input = "prog Test1 string x; x = \"abc\"; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testMapDec() throws Exception
    {
        String input = "prog Test1 map[int,string] y; y[3] = \"hello\"; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testMapDec2() throws Exception
    {
        String input = "prog Test1 map[int,string] y; y = {[3,\"hello\"], [4,\"asd\"]}; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testMapDec3() throws Exception
    {
        String input = "prog Test1 map[int,string] y; y = {}; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testMapDec4() throws Exception
    {
        String input = "prog Test1 map[int,map[int, string]] y; map[int, string] x; x = {[3,\"hello\"], [4,\"asd\"]}; y = {[2, x]}; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testIntDecWrong() throws Exception
    {
        String input = "prog Test1 int x; x = \"hello\" ; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testIntDecWrong2() throws Exception
    {
        String input = "prog Test1 int x; x = true ; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testIntDecWrong3() throws Exception
    {
        String input = "prog Test1 int x; x = {[10,10]} ; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testBooleanDecWrong1() throws Exception
    {
        String input = "prog Test1 boolean x; x = 2 ; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testBooleanDecWrong2() throws Exception
    {
        String input = "prog Test1 boolean x; x = \"hello\" ; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testBooleanDecWrong3() throws Exception
    {
        String input = "prog Test1 boolean x; x = {[true, \"rop\"]} ; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testStringDecWrong1() throws Exception
    {
        String input = "prog Test1 string x; x = {[true, \"rop\"]} ; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testStringDecWrong2() throws Exception
    {
        String input = "prog Test1 string x; x = 1 ; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testStringDecWrong3() throws Exception
    {
        String input = "prog Test1 string x; x = true ; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testMapDecWrong1() throws Exception
    {
        String input = "prog Test1 map[int,string] y; y = {[3,\"hello\"], [true,\"asd\"]}; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testMapDecWrong2() throws Exception
    {
        String input = "prog Test1 map[int,string] y; y = {[3,\"hello\"], [4,4]}; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testMapDecWrong3() throws Exception
    {
        String input = "prog Test1 map[int,map[int, string]] y; map[int, string] x; x = {[3,\"hello\"], [4,\"asd\"]}; y = {[true, x]}; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testMapDecWrong4() throws Exception
    {
        String input = "prog Test1 map[int,map[int, string]] y; map[int, string] x; x = {[3,true], [4,\"asd\"]}; y = {[2, x]}; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testMapDecWrong5() throws Exception
    {
        String input = "prog Test1 map[int,map[int, string]] y; map[int, string] x; x = {[3,\"hello\"], [\"a\",\"asd\"]}; y = {[2, x]}; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testDoCommand1() throws Exception
    {
        String input = "prog Test1 int x; int y; do(x<y) od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testDoCommand2() throws Exception
    {
        String input = "prog Test1 int x; int y; do(x<y) od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testDoCommand3() throws Exception
    {
        String input = "prog Test1 boolean x; boolean y; do(x==y) od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testDoCommand4() throws Exception
    {
        String input = "prog Test1 int x; int y; y =-x; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testDoCommand5() throws Exception
    {
        String input = "prog Test1 string x; string y; do(x==y) od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testDoCommand6() throws Exception
    {
        String input = "prog Test1 boolean x; boolean y; do(x>y) od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testDoCommand7() throws Exception
    {
        String input = "prog Test1 map[int,int] x; map[int,int] y; do(x<=y) od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testDoCommand8() throws Exception
    {
        String input = "prog Test1 map[string,map[int,string]] x; map[string,map[int,string]] y; do(x>=y) od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test//(expected=ContextException.class)
    public void testDoCommandWrong1() throws Exception
    {// what is wrong in this Do command ? // Expression type is boolean , context wise seems ok
        String input = "prog Test1 boolean x; boolean y; do(x!=y) od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testDoCommandWrong2() throws Exception
    {	//plus not defined for boolean
        String input = "prog Test1 boolean x; boolean y; do(x + y) od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testDoCommandWrong3() throws Exception
    {
        String input = "prog Test1 int x; int y; int z; do(x - 123) od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testDoCommandWrong4() throws Exception
    {
        String input = "prog Test1 int x; int y; int z; do(z + x - 123) od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testDoEachCommand1() throws Exception
    {
        String input = "prog Test1 map[int, string] x; int y; string z; do x : [y,z] od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testDoEachCommand2() throws Exception
    {
        String input = "prog Test1 map[int, map[string, string]] x; map[string, string] y; int z; do x : [z,y] od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testIfElseCommandWrong1() throws Exception
    {
        String input = "prog Test1 int x; boolean y; string z; map[string, int] m; if(3 - (4 < y)) else fi; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testPairExpression1() throws Exception
    {
        String input = "prog Test1 map [int, string] m; m ={[3+4, \"abc\"]};  gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testPairExpression2() throws Exception
    {
        String input = "prog Test1 map [int, string] m; int a; string s1; m ={[a + 3, s1 + \"abc\"]};  gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testPairExpression3() throws Exception
    {
        String input = "prog Test1 map [int, map[string, boolean]] m; map[string, boolean] m1; m1 = {[\"as\" + \"qr\", true != false]}; int a; string s1; m ={[a - a * a / a, m1 + m1]};  gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testBinaryOp2() throws Exception
    {
        String input = "prog Test1 string s; int x; string s1; s = x + s; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testBinaryOp3() throws Exception
    {
        String input = "prog Test1 string s; map [string, int] m; s = m[\"as\"] + s; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testBinaryOp5() throws Exception
    {
        String input = "prog Test1 map[int, int] s; map[int, int] s2; s = s + s2; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testBinaryOp6() throws Exception
    {
        String input = "prog Test1 map[int, int] m1; map[int, boolean] m2; string s2; s2 = s2 + m1[4] + m2[1]; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testBinaryOp12() throws Exception
    {
        String input = "prog Test1 map[int,int] x; map[int,int] y; x = x - y; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testBinaryOp13() throws Exception
    {
        String input = "prog Test1 map[int,int] x; map[int,int] y; x = x * y; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testBinaryOpWrong2() throws Exception
    {
        String input = "prog Test1 map[int, int] s; map[string, int] s2; s = s + s2; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testBinaryOpWrong3() throws Exception
    {
        String input = "prog Test1 int x; int a; boolean b; string s; map [int, int] m; x = a <= b >= a < b > s != m == s <= m; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testBinaryOpWrong4() throws Exception
    {
        String input = "prog Test1 int x; string a; boolean b; string s; map [int, int] m; x = a <= b >= a < b > s != m == s <= m; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testBinaryOpWrong5() throws Exception
    {
        String input = "prog Test1 map[string, boolean] x; string a; boolean b; string s; map [int, int] m; x = a <= b >= a < b > s != m == s <= m; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testBinaryOpWrong8() throws Exception
    {
        String input = "prog Test1 int x; boolean y; string s; map [int, string] m; x = s/m; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testBinaryOpWrong9() throws Exception
    {
        String input = "prog Test1 int x; map[int,int] y; x = x * y; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testBinaryOpWrong10() throws Exception
    {
        String input = "prog Test1 int x; map[int,int] y; y = y * x; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testBinaryOpWrong11() throws Exception
    {
        String input = "prog Test1 int x; map[int,int] y; y = y - x; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testBinaryOpWrong12() throws Exception
    {
        String input = "prog Test1 string x; map[int,int] y; y = y - x; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testBinaryOpWrong13() throws Exception
    {
        String input = "prog Test1 boolean x; map[int,int] y; y = y - x; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testBinaryOpWrong14() throws Exception
    {
        String input = "prog Test1 boolean x; map[int,int] y; y = y * x; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    
    
    //Borrowed from other guy.
    @Test
    public void testVisitProgram() throws Exception
    {
        String input = "prog Test1 gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
     @Test(expected=ContextException.class)
    public void testUniqueProgramName() throws Exception
    {
        String input = "prog Test1 int Test1; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testVisitBlock() throws Exception
    {
        String input = "prog Test1 boolean bool; bool = true; if(bool) if(true); ; ; fi; fi; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testVisitDeclaration() throws Exception
    {
        String input = "prog Test1 do (true) int x; string y; boolean z; map[int, map[int, map[int, string]]] m1; od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testVisitAssignExprCommand() throws Exception
    {
        String input = "prog Test int i; boolean b; i = b; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testVisitAssignExprCommand2() throws Exception
    {
        String input = "prog Test1 int a; a = (2*3) ; boolean b; b = (2 & 2) ; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testVisitAssignPairListCommand() throws Exception
    {
        String input = "prog Test map[int, map[string, boolean]] m;" +
                "map[string, boolean] sbmap;" +
//                      " m = {[3,[\"str\", true]]}; gorp";
                "sbmap = {[\"str\", true]}; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testVisitPrintCommand() throws Exception
    {
        String input = "prog Test1 print (true & false) ; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
     @Test(expected=ContextException.class)
    public void testVisitPrintCommand2() throws Exception
    {
        String input = "prog Test1 print (2 * \"str\") ; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testVisitPrintlnCommand() throws Exception
    {
        String input = "prog Test1 map[int, int] x; println x; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testVisitDoCommand() throws Exception
    {
        String input = "prog Test1 do (2 + 5 == 7) map [int, int] m; od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
     @Test(expected=ContextException.class)
    public void testVisitDoCommand2() throws Exception
    {
        String input = "prog Test1 boolean c; string s; do ( ( 1 + s)== 3);od ;gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testVisitDoCommand3() throws Exception
    {
        String input = "prog Test1 do (true) aa = ab; od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testVisitDoEachCommand() throws Exception
    {
        String input = "prog Test1 map[int, int] x; int x1; int x2; boolean y; map[int, map[boolean, map[string, int]]] m1; do x : [x1 , x2] println x1;  od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testVisitDoEachCommand2() throws Exception
    {
        String input = "prog Test1 map[int, int] x; int x1; string x2; do x : [x1 , x2] println x1;  od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test//(expected=ContextException.class)
    public void testVisitDoEachCommand3() throws Exception
    {
        String input = "prog Test1 map[int, int] x1; map[int, int] x2; int c1; int c2; int c4;" +
                        " do x1 : [c1 , c2] do x2 : [c1, c4] boolean znunu; boolean asfa; znunu = asfa; od; println c4;  od; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testVisitIfElseCommand() throws Exception
    {
        String input = "prog Test1 boolean x; boolean y; if ( x | y ) a = true; else y=s; fi;  gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testVisitIfElseCommand2() throws Exception
    {
        String input = "prog Test1 boolean x; boolean y; string a; if ( x | y ) boolean a;" +
                        "a = true; else boolean s; y=s; fi;  gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testVisitIfElseCommand3() throws Exception
    {
        String input = "prog Test1 boolean x; boolean y; string a; if ( x | y )" +
                "a = true; else boolean s; y=s; fi;  gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testVisitIfCommand() throws Exception
    {
        String input = "prog Test int ab; int x; if(x == 10) boolean ab; ab = true ; ; ; fi; ab = 10; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testVisitIfCommand2() throws Exception
    {
        String input = "prog Test int ab; int x; if(x == 10) boolean ab; ab = true ; ; ; fi; ab = 10;" +
                "string ab; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testVisitSimpleLValue() throws Exception
    {
        String input = "prog Test int ab; int x; if(x == 10) boolean ab; string s; ab = true ; ; ; fi; " +
                        "ab = 10; s = \"xyz\"; string ab; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testVisitExprLValue() throws Exception
    {
        String input = "prog Test map[int, map[int, string]] m; map[int, string] valType;" +
                        "int keyType; m[keyType] = valType; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testVisitPair() throws Exception
    {
        String input = "prog Test1  map[int, boolean] m; m = {[2,3], [2, false]} ;gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testVisitPair2() throws Exception
    {
        String input = "prog Test1  map[int, boolean] m; m = {[2, false]} ;gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testVisitPairList() throws Exception
    {
        String input = "prog Test1  map[int,boolean] m; m = {[2,3]} ;gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testVisitPairList2() throws Exception
    {
        String input = "prog Test1 map[int,boolean] m; m = {[2,3],[\"str\", true]} ;gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testVisitIntegerLiteralExpression() throws Exception
    {
        String input = "prog Test1 int i; i = 2/3*4/5+6-7 ;gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testVisitBooleanLiteralExpression() throws Exception
    {
        String input = "prog Test1 boolean b; b = true|false & (false|true) & false & true ;gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testVisitStringLiteralExpression() throws Exception
    {
        String input = "prog Test1 string s; s = \"waste\" + \"of\" + \"time\"; ;gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testVisitUnaryOpExpression() throws Exception
    {
        String input = "prog Test1 int i; i = -1 + -2; if(i == -3) print true; fi; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testVisitUnaryOpExpression2() throws Exception
    {
        String input = "prog Test1 boolean i; boolean j; i = !j; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testVisitBinaryOpExpression() throws Exception
    {
        String input = "prog Test1 string s; int i; i = -3; s = \"abc\" + i; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testVisitBinaryOpExpression2() throws Exception
    {
        String input = "prog Test1 string s; int i; boolean b; i = -3; s = \"abc\" + b; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test(expected=ContextException.class)
    public void testVisitBinaryOpExpression3() throws Exception
    {
        String input = "prog Test1 string s; int i; map[int, string] m; i = -3; s = \"abc\" + m; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
    @Test
    public void testManyExpressions() throws Exception
    {
        String input = "prog Test map [int , map[string, boolean]] m ;  map[string, boolean] m1; string a; boolean b; m = {[2 , m1]} ; gorp";
        this.initParser(input);
        AST ast = parser.parse();
        ast.visit(visitor, null);
    }
}
