Esempio n. 1
0
        public void TestUpdateErrorLine()
        {
            var input = "a = 3\n" +
                        "achievement(\"t\", \"d\", 5, \n" +
                        "    once()\n" +
                        ")\n";
            var tokenizer = Tokenizer.CreateTokenizer(input);
            var group     = new ExpressionGroupCollection();

            group.Scope = RATools.Parser.AchievementScriptInterpreter.GetGlobalScope();
            group.Parse(tokenizer);

            var interpreter = new RATools.Parser.AchievementScriptInterpreter();

            interpreter.Run(group, null);

            Assert.That(group.HasEvaluationErrors, Is.True);
            Assert.That(group.Errors.First().Location.Start.Line, Is.EqualTo(3));

            var updatedInput = "a = 3\n" +
                               "\n" +
                               "\n" +
                               "achievement(\"t\", \"d\", 5, \n" +
                               "    once()\n" +
                               ")\n";

            group.Update(Tokenizer.CreateTokenizer(updatedInput), new int[] { 2, 3 });

            Assert.That(group.HasEvaluationErrors, Is.True);
            var error = group.Errors.First();

            Assert.That(error.Location.Start.Line, Is.EqualTo(5));
            Assert.That(error.InnermostError.Location.Start.Line, Is.EqualTo(5));

            group.Update(Tokenizer.CreateTokenizer(input), new int[] { 2, 3 });

            Assert.That(group.HasEvaluationErrors, Is.True);
            error = group.Errors.First();
            Assert.That(error.Location.Start.Line, Is.EqualTo(3));
            Assert.That(error.InnermostError.Location.Start.Line, Is.EqualTo(3));
        }
Esempio n. 2
0
        public void TestUpdateSourceLine()
        {
            var input = "a = 3\n" +
                        "achievement(\"t\", \"d\", 5, byte(0x1234) == a)\n" +
                        "leaderboard(\"t\", \"d\", byte(0x1234) == a, byte(0x1234) == a + 1, byte(0x1234) == a + 2, byte(0x2345))\n";
            var tokenizer = Tokenizer.CreateTokenizer(input);
            var group     = new ExpressionGroupCollection();

            group.Scope = RATools.Parser.AchievementScriptInterpreter.GetGlobalScope();
            group.Parse(tokenizer);

            var interpreter = new RATools.Parser.AchievementScriptInterpreter();

            interpreter.Run(group, null);

            Assert.That(group.Groups.Count, Is.EqualTo(3));
            Assert.That(group.Groups[1].GeneratedAchievements.First().SourceLine, Is.EqualTo(2));
            Assert.That(group.Groups[2].GeneratedLeaderboards.First().SourceLine, Is.EqualTo(3));

            var updatedInput = "a = 3\n" +
                               "\n" +
                               "\n" +
                               "achievement(\"t\", \"d\", 5, byte(0x1234) == a)\n" +
                               "leaderboard(\"t\", \"d\", byte(0x1234) == a, byte(0x1234) == a + 1, byte(0x1234) == a + 2, byte(0x2345))\n";

            group.Update(Tokenizer.CreateTokenizer(updatedInput), new int[] { 2, 3 });

            Assert.That(group.Groups.Count, Is.EqualTo(3));
            Assert.That(group.Groups[1].GeneratedAchievements.First().SourceLine, Is.EqualTo(4));
            Assert.That(group.Groups[2].GeneratedLeaderboards.First().SourceLine, Is.EqualTo(5));

            group.Update(Tokenizer.CreateTokenizer(input), new int[] { 2, 3 });

            Assert.That(group.Groups.Count, Is.EqualTo(3));
            Assert.That(group.Groups[1].GeneratedAchievements.First().SourceLine, Is.EqualTo(2));
            Assert.That(group.Groups[2].GeneratedLeaderboards.First().SourceLine, Is.EqualTo(3));
        }