示例#1
0
        public void Should_Parse_In_Combination_With_Spaces()
        {
            var constantParserPart  = new ConstantParserPart();
            var operationParserPart = new OperationParserPart();

            var sut = new Parser(new IParserPart[]
            {
                constantParserPart,
                operationParserPart
            });

            const string expression = "1 + 2 + 3";

            object[] expectedSymbols =
            {
                new Symbol(SymbolType.Constant,  0, 1, 1),
                new Symbol(SymbolType.Addition, 2),
                new Symbol(SymbolType.Constant,  4, 1, 2),
                new Symbol(SymbolType.Addition, 6),
                new Symbol(SymbolType.Constant,  8, 1, 3)
            };
            var actualSymbols = sut.Parse(expression);

            actualSymbols
            .Should()
            .BeEquivalentTo(expectedSymbols);
        }
示例#2
0
        public void Should_Fail_On_Empty_Expression()
        {
            var sut = new ConstantParserPart();

            Assert.Throws <ArgumentException>(() => sut.TryParse(null, 1, out _));
            Assert.Throws <ArgumentException>(() => sut.TryParse(string.Empty, 1, out _));
            Assert.Throws <ArgumentException>(() => sut.TryParse(" ", 1, out _));
        }
示例#3
0
        public void Should_Parse_Constants(string expression, decimal expectedValue)
        {
            var sut        = new ConstantParserPart();
            var couldParse = sut.TryParse(expression, 0, out var symbol);

            Assert.True(couldParse);

            Assert.Equal(SymbolType.Constant, symbol.Type);
            Assert.Equal(expectedValue, symbol.Value);
        }