public void TestRighSringSavedInSuccessCase()
        {
            // Arrange

            var symbol1 = 'g';
            var symbol2 = 'b';

            var rule11 = new SymbolRule(symbol: symbol1);
            var rule1  = new OneOrManyRule(rule11);
            var rule22 = new SymbolRule(symbol: symbol2);
            var rule2  = new ZeroOrManyRule(rule22);
            var rule   = new GroupRule(new List <IRule> {
                rule1, rule2
            });

            var str    = $"{symbol1}{symbol1}{symbol1}{symbol1}{symbol1}{symbol2}{symbol2}";
            var stream = new MemoryStream().FromString(str);


            // Act

            var result = rule.Check(stream);

            // Assert

            Assert.AreEqual(str, rule.ChekedString);
        }
Beispiel #2
0
        public void TestManyRuleSuccessPositioning()
        {
            //arrange

            var symbol1       = 'd';
            var symbol2       = 'g';
            var argumentRule1 = new SymbolRule(symbol: symbol1);
            var argumentRule2 = new SymbolRule(symbol: symbol2);

            var rule1 = new ZeroOrManyRule(argument: argumentRule1);
            var rule2 = new ZeroOrManyRule(argument: argumentRule2);

            var stream = new MemoryStream().FromString($"{symbol1}{symbol1}{symbol2}{symbol2}ahsdkjha");

            //act
            var streamStartPosition = stream.Position;

            var result = new List <bool> {
                rule1.Check(stream),
                rule2.Check(stream)
            };


            //assert
            Assert.AreEqual(streamStartPosition + 2 * result.Count, stream.Position);
        }
        public void TestHardRuleFailedWithoutFirstComponentString()
        {
            // Arrange

            var symbol1 = 'g';
            var symbol2 = 'b';

            var rule11 = new SymbolRule(symbol: symbol1);
            var rule1  = new OneOrManyRule(rule11);
            var rule22 = new SymbolRule(symbol: symbol2);
            var rule2  = new ZeroOrManyRule(rule22);
            var rule   = new GroupRule(new List <IRule> {
                rule1, rule2
            });


            var stream = new MemoryStream().FromString($"${symbol2}");


            // Act

            var result = rule.Check(stream);


            // Assert

            Assert.IsFalse(result, message: "result is false");
        }
Beispiel #4
0
        public void TestManyRuleSuccessAll()
        {
            //arrange

            var symbol1       = 'd';
            var symbol2       = 'g';
            var argumentRule1 = new SymbolRule(symbol: symbol1);
            var argumentRule2 = new SymbolRule(symbol: symbol2);

            var rule1 = new ZeroOrManyRule(argument: argumentRule1);
            var rule2 = new ZeroOrManyRule(argument: argumentRule2);

            var stream = new MemoryStream().FromString($"{symbol1}{symbol1}{symbol2}jahsdkjha");

            //act

            var result = new List <bool> {
                rule1.Check(stream),
                rule2.Check(stream)
            };


            //assert

            result.ForEach(Assert.IsTrue);
        }
Beispiel #5
0
        public void TestRulePriority()
        {
            var argumentRule = new SymbolRule(symbol: 'b');

            //act

            var rule = new ZeroOrManyRule(argument: argumentRule);

            //assert

            Assert.AreEqual(rule.Priority, RulePriority.RuleZeroOrMany);
        }
Beispiel #6
0
        public void TestSuccessChekingManySymbolWithSuccessArgumentRule()
        {
            //arrange

            var symbol       = 'd';
            var argumentRule = new SymbolRule(symbol: symbol);
            var rule         = new ZeroOrManyRule(argument: argumentRule);
            var stream       = new MemoryStream().FromString($"{symbol}ghsdghfsjfdjhsgdfh");

            //act

            var isCheckedSuccess = rule.Check(stream);

            //assert

            Assert.IsTrue(isCheckedSuccess);
        }
Beispiel #7
0
        public void TestThatChekingSuccessWithTwoSameSymbols()
        {
            //arrange

            var symbol       = 'd';
            var argumentRule = new SymbolRule(symbol: symbol);
            var rule         = new ZeroOrManyRule(argument: argumentRule);
            var stream       = new MemoryStream().FromString($"{symbol}{symbol}");

            //act

            var isCheckedSuccess = rule.Check(stream);

            //assert

            Assert.IsTrue(isCheckedSuccess);
        }
Beispiel #8
0
        public void TestSuccessChekingOneSymbolWithFailArgumentRule()
        {
            //arrange

            var symbol       = 'd';
            var argumentRule = new SymbolRule(symbol: symbol);
            var rule         = new ZeroOrManyRule(argument: argumentRule);
            var stream       = new MemoryStream().FromString((symbol + 1).ToString());

            //act

            var isCheckedSuccess = rule.Check(stream);

            //assert

            Assert.IsTrue(isCheckedSuccess);
        }
Beispiel #9
0
        public void TestSuccessPositionWithSuccessArgumentRule()
        {
            //arrange

            var symbol       = 'd';
            var argumentRule = new SymbolRule(symbol: symbol);
            var rule         = new ZeroOrManyRule(argument: argumentRule);
            var stream       = new MemoryStream().FromString($"{symbol}ghsdghfsjfdjhsgdfh");

            //act
            var startPos = stream.Position;

            rule.Check(stream);
            var endPos = stream.Position;

            //assert

            Assert.AreEqual(startPos + 1, endPos);
        }
Beispiel #10
0
        public void TestPositionWithFailRule()
        {
            //arrange

            var symbol       = 'd';
            var argumentRule = new SymbolRule(symbol: symbol);
            var rule         = new ZeroOrManyRule(argument: argumentRule);
            var stream       = new MemoryStream().FromString($"765765");

            //act

            var startPos = stream.Position;

            rule.Check(stream);
            var endPos = stream.Position;

            //assert

            Assert.AreEqual(startPos, endPos);
        }
        public void TestRighSringSavedInFaledCase()
        {
            var symbol1 = 'g';
            var symbol2 = 'b';

            var rule11 = new SymbolRule(symbol: symbol1);
            var rule1  = new OneOrManyRule(rule11);
            var rule22 = new SymbolRule(symbol: symbol2);
            var rule2  = new ZeroOrManyRule(rule22);
            var rule   = new GroupRule(new List <IRule> {
                rule1, rule2
            });

            var str    = $"${symbol2}";
            var stream = new MemoryStream().FromString(str);

            // Act
            rule.Check(stream);

            // Assert

            Assert.AreEqual(string.Empty, rule.ChekedString);
        }