public void PythonLexerNestedWhileStatementTest() { string tokenizeString = "while left:\n" + "\tmoveForward()\n" + "\trotateRight()\n" + "\twhile right:\n" + "\t\trotateRight()\n" + "\t\trotateRight()\n" + "\tmoveForward()\n" + "moveForward()\n" + "rotateRight()\n"; PythonParser p = new PythonParser (); List<ICodeBlock> block = p.ParseCode (tokenizeString); Assert.AreEqual (3, block.Count); }
public void PythonLexerSimpleStatementTest() { string tokenizeString = "moveForward()\n" + "moveForward()\n" + "rotateRight()\n" + "moveForward()\n" + "rotateRight()\n"; PythonParser p = new PythonParser (); List<ICodeBlock> block = p.ParseCode (tokenizeString); Assert.AreEqual (5, block.Count); }
public void PythonParseSimpleIF() { string tokenizeString = "if left:\n" + "\tmoveForward()\n" + "\trotateRight()\n"; PythonParser p = new PythonParser (); List<ICodeBlock> block = p.ParseCode (tokenizeString); Assert.AreEqual (1, block.Count); Assert.AreEqual (2, (block [0] as IfStatement).getChildren ().Count); Assert.IsInstanceOf<IfStatement> (block [0]); }
public void PythonParseNestedIF3() { string tokenizeString = "if left:\n" + "\tmoveForward()\n" + "\tif right:\n" + "\t\tmoveForward()\n" + "\trotateRight()\n" + "rotateRight()\n"; PythonParser p = new PythonParser (); List<ICodeBlock> block = p.ParseCode (tokenizeString); Assert.AreEqual (2, block.Count); Assert.AreEqual (3, (block [0] as IfStatement).getChildren ().Count); Assert.IsInstanceOf<IfStatement> (block [0]); Assert.IsInstanceOf<IfStatement>((block [0] as IfStatement).getChildren ().ElementAt(1)); }
public void PythonLexerTest() { string tokenizeString = "while left:\n" + "\tmoveForward()\n" + "\trotateRight()\n" + "moveForward()\n" + "moveForward()\n" + "rotateRight()\n"; //var tokens = lexer.Tokenize(tokenizeString); PythonParser p = new PythonParser (); p.ParseCode (tokenizeString); Assert.AreEqual (17,17); }
public void TestMultipleSimpleStatementsDifferentType3() { tokenize = "moveForward()\n" + "moveForward()\n" + "rotateRight()\n" + "pickUp('paprika')\n" + "moveForward()\n"; PythonParser p = new PythonParser (); response = p.ParseCode (tokenize); Assert.AreEqual (5, response.Count); Assert.IsInstanceOf<Forward> (response [0]); Assert.IsInstanceOf<Forward> (response [1]); Assert.IsInstanceOf<TurnRight> (response [2]); Assert.IsInstanceOf<PickUp> (response [3]); Assert.AreEqual ("paprika", (response [3] as PickUp).ObjectToPickUP); Assert.IsInstanceOf<Forward> (response [4]); }
public void TestMultipleSimpleStatementsDifferentType1() { tokenize = "moveForward()\n" + "rotateRight()\n"; PythonParser p = new PythonParser (); response = p.ParseCode (tokenize); Assert.AreEqual (2, response.Count); Assert.IsInstanceOf<Forward> (response [0]); Assert.IsInstanceOf<TurnRight> (response [1]); }