private Tokens GetBlockCallTokens() { Tokens tokens = new Tokens(); tokens.AddTokens ( new string[] { "x", "=", "{", "print", "$", "[", "0", "]", "}", "x", "(", "'yay'", ")" } ); return tokens; }
public void ParseNestedBlockTest() { Tokens tokens = new Tokens (); tokens.AddTokens ( new string[] { "x", "=", "{", "if", "x", "==", "5", "{", "print", "x", "}", "}", "print", "x" } ); Parser parser = new Parser ( TestModule.GetTestKernel () ); Block block = parser.Parse ( tokens ); Assert.AreEqual ( 2, block.Count, "Should be two statements, one assign, one print"); }
public void ParseBlockAssignment() { Tokens tokens = new Tokens (); tokens.AddTokens ( new string[] { "x", "=", "{", "print", "'bong'", "}" } ); Parser parser = new Parser ( TestModule.GetTestKernel () ); parser.Parse ( tokens ); Assert.IsInstanceOfType ( typeof ( Assign ), parser.MainBlock[0] ); Assign ass = parser.MainBlock[0] as Assign; Assert.IsInstanceOfType ( typeof ( Block ), ass.Expr ); }
public void ParseBlockCall() { Tokens tokens = new Tokens (); tokens.AddTokens ( new string[] { "x", "=", "{", "print", "'bong'", "}", "x" } ); Parser parser = new Parser ( TestModule.GetTestKernel () ); parser.Parse ( tokens ); Assert.IsInstanceOfType ( typeof ( Assign ), parser.MainBlock[0] ); Assert.IsInstanceOfType ( typeof ( Variable ), parser.MainBlock[1] ); Assert.AreEqual ( "x", (parser.MainBlock[1] as Variable).Ident ); }
public void TestSetRollbackPoint() { Tokens tokens = new Tokens(); tokens.AddTokens ( new string[] { "1", "2", "3", "4", "5" } ); Assert.AreEqual ( "1", tokens.PeekToken () ); tokens.SetMark (); Assert.AreEqual ( "1", tokens.PullToken () ); Assert.AreEqual ( "2", tokens.PullToken () ); Assert.AreEqual ( "3", tokens.PullToken () ); tokens.RollbackToMark (); Assert.AreEqual ( "1", tokens.PeekToken () ); }
public void TestBlockPassesAsParameter() { Tokens tokens = new Tokens(); tokens.AddTokens(new string[] {"x", "(", "{", "print", "'yay'","}",")"}); IKernel kernel = TestModule.GetTestKernel(); Parser parser = new Parser ( kernel ); parser.Parse ( tokens ); Variable variable = parser.MainBlock[0] as Variable; ArrayExpr array = variable.Parameters; Assert.AreEqual ( 1, array.Elements.Count, "Should only be one parameter" ); Assert.IsInstanceOfType ( typeof(Block), array.Elements[0] ); }