public void Add_HasARegexConflict_ThrowsException()
        {
            var table = new ExpressionTable();
            var expr1 = new CustomExpression
            {
                Name                = "Test",
                RegexPattern        = "[0-9]",
                ExpressionFunction  = FakeFunc,
                ReplacementFunction = FakeReplaceFunc
            };

            table.Add(expr1);

            var expr2 = new CustomExpression
            {
                Name                = "Test1",
                RegexPattern        = "[0-9]",
                ExpressionFunction  = FakeFunc,
                ReplacementFunction = FakeReplaceFunc
            };

            Action add = () => table.Add(expr2);

            add.Should().Throw <ArgumentException>();
        }
        public void Execute_MixedFunctions(string expression, int minExpected, int maxExpected)
        {
            var table = new ExpressionTable();

            table.Add(new CustomExpression
            {
                Name                = "Roll",
                RegexPattern        = @"([0-9]+)?(d|D)([0-9]+)",
                ExpressionFunction  = RollFunction,
                ReplacementFunction = ReplaceRollCall
            });
            table.Add(new CustomExpression
            {
                Name                = "Number",
                RegexPattern        = @"^?\b\w*[n|N]\w*\b$?",
                ExpressionFunction  = NumberFunction,
                ReplacementFunction = ReplaceNumberCall
            });

            var parser = new ExpressionParser(table);

            var result = parser.Execute(expression);

            result.Should().BeGreaterOrEqualTo(minExpected);
            result.Should().BeLessOrEqualTo(maxExpected);
        }
        public void Get_HasANameMatch_ReturnsValidResult()
        {
            var table = new ExpressionTable();
            var expr1 = new CustomExpression()
            {
                Name                = "Test",
                RegexPattern        = "[0-9]",
                ExpressionFunction  = FakeFunc,
                ReplacementFunction = FakeReplaceFunc
            };

            table.Add(expr1);

            table.Get("Test").Should().Be(expr1);
        }
        public void Add_HasNoConflicts()
        {
            var table = new ExpressionTable();
            var expr  = new CustomExpression
            {
                Name                = "Test",
                RegexPattern        = "[0-9]",
                ExpressionFunction  = FakeFunc,
                ReplacementFunction = FakeReplaceFunc
            };

            Action add = () => table.Add(expr);

            add.Should().NotThrow <Exception>();
        }
        public void Execute_StandardDiceFormat(string expression, int minExpected, int maxExpected)
        {
            var table = new ExpressionTable();

            table.Add(new CustomExpression
            {
                Name                = "Roll",
                RegexPattern        = @"([0-9]+)?(d|D)([0-9]+)",
                ExpressionFunction  = RollFunction,
                ReplacementFunction = ReplaceRollCall
            });

            var parser = new ExpressionParser(table);

            var result = parser.Execute(expression);

            result.Should().BeGreaterOrEqualTo(minExpected);
            result.Should().BeLessOrEqualTo(maxExpected);
        }
示例#6
0
        public static ExpressionTable GetExpressionTable()
        {
            var table = new ExpressionTable();

            table.Add(new CustomExpression
            {
                Name                = "Level",
                RegexPattern        = @"^?\b\w*[l|L]\w*\b$?",
                ExpressionFunction  = LevelFunction,
                ReplacementFunction = ReplaceLevelCall
            });
            table.Add(new CustomExpression
            {
                Name                = "Health",
                RegexPattern        = @"^?\b\w*[h|H]\w*\b$?",
                ExpressionFunction  = HealthFunction,
                ReplacementFunction = ReplaceHealthCall
            });
            table.Add(new CustomExpression
            {
                Name                = "Mana",
                RegexPattern        = @"^?\b\w*[m|M]\w*\b$?",
                ExpressionFunction  = ManaFunction,
                ReplacementFunction = ReplaceManaCall
            });
            table.Add(new CustomExpression
            {
                Name                = "Movement",
                RegexPattern        = @"^?\b\w*[v|V]\w*\b$?",
                ExpressionFunction  = MovementFunction,
                ReplacementFunction = ReplaceMovementCall
            });
            table.Add(new CustomExpression
            {
                Name                = "Strength",
                RegexPattern        = @"^?\b\w*[s|S]\w*\b$?",
                ExpressionFunction  = StrengthFunction,
                ReplacementFunction = ReplaceStrengthCall
            });
            table.Add(new CustomExpression
            {
                Name                = "Intelligence",
                RegexPattern        = @"^?\b\w*[i|I]\w*\b$?",
                ExpressionFunction  = IntelligenceFunction,
                ReplacementFunction = ReplaceIntelligenceCall
            });
            table.Add(new CustomExpression
            {
                Name                = "Wisdom",
                RegexPattern        = @"^?\b\w*[w|W]\w*\b$?",
                ExpressionFunction  = WisdomFunction,
                ReplacementFunction = ReplaceWisdomCall
            });
            table.Add(new CustomExpression
            {
                Name                = "Dexterity",
                RegexPattern        = @"^?\b\w*[x|X]\w*\b$?",
                ExpressionFunction  = DexterityFunction,
                ReplacementFunction = ReplaceDexterityCall
            });
            table.Add(new CustomExpression
            {
                Name                = "Constitution",
                RegexPattern        = @"^?\b\w*[c|C]\w*\b$?",
                ExpressionFunction  = ConstitutionFunction,
                ReplacementFunction = ReplaceConstitutionCall
            });
            table.Add(new CustomExpression
            {
                Name                = "Charisma",
                RegexPattern        = @"^?\b\w*[a|A]\w*\b$?",
                ExpressionFunction  = CharismaFunction,
                ReplacementFunction = ReplaceCharismaCall
            });
            table.Add(new CustomExpression
            {
                Name                = "Luck",
                RegexPattern        = @"^?\b\w*[u|U]\w*\b$?",
                ExpressionFunction  = LuckFunction,
                ReplacementFunction = ReplaceLuckCall
            });
            table.Add(new CustomExpression
            {
                Name                = "Age",
                RegexPattern        = @"^?\b\w*[y|Y]\w*\b$?",
                ExpressionFunction  = AgeFunction,
                ReplacementFunction = ReplaceAgeCall
            });

            return(table);
        }