Example #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);
        }
        public void Should_Parse_Operations(string expression, SymbolType expectedSymbolType)
        {
            var sut        = new OperationParserPart();
            var couldParse = sut.TryParse(expression, 0, out var symbol);

            Assert.True(couldParse);
            Assert.Equal(expectedSymbolType, symbol.Type);
        }
        public void Should_Fail_On_Empty_Expression()
        {
            var sut = new OperationParserPart();

            Assert.Throws <ArgumentException>(() => sut.TryParse(null, 1, out _));
            Assert.Throws <ArgumentException>(() => sut.TryParse(string.Empty, 1, out _));
            Assert.Throws <ArgumentException>(() => sut.TryParse(" ", 1, out _));
        }