コード例 #1
0
 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);
 }
コード例 #2
0
 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);
 }
コード例 #3
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));
 }
コード例 #4
0
 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]);
 }
コード例 #5
0
 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);
 }
コード例 #6
0
        public void ValidateCode()
        {
            try
            {
                ResetCode(true);

                CodeParser codeParser = null;
                robot.Moves = 0;

                switch (GlobalSupport.GameLanguage)
                {
                    case EGameLanguage.Python:
                        codeParser = new PythonParser();
                        break;

                    case EGameLanguage.Pascal:
                        codeParser = new PascalParser();
                        break;
                    default:
                        codeParser = new PascalParser();
                        break;
                }

                string codeToParse = txtCodeField.Text;

                codeToParse = RemoveWhiteSpaces(codeToParse);
                codeToParse += "\n";

                List<ICodeBlock> result = codeParser.ParseCode(codeToParse);

                ExecuteCommand(result, txtCodeField.Text, lblExecutedCode);
            }
            catch (RobotException excRobot)
            {
                SetErrorLabelMessage(excRobot.Message);
            }
            catch (CodeParseException excCodeParse)
            {
                SetErrorLabelMessage(excCodeParse.Message);
            }
            catch (SyntaxParseException excSyntax)
            {
                SetErrorLabelMessage(excSyntax.Message);
            }
            catch (MapException excMap)
            {
                SetErrorLabelMessage(excMap.Message);
            }
            catch (ArgumentOutOfRangeException excArgOOR)
            {
                SetErrorLabelMessage(excArgOOR.Message);
            }
            catch (RunTimeException exRunTimeException){
                SetErrorLabelMessage (exRunTimeException.Message);
            }
        }
コード例 #7
0
 public void BeforeTest()
 {
     parser = new PythonParser ();
     response = new List<ICodeBlock> ();
     tokenize = "";
 }
コード例 #8
0
 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]);
 }
コード例 #9
0
 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]);
 }