Exemplo n.º 1
0
        public void TestManyRuleFileFirstAndSuccessSecond()
        {
            //arrange

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

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

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

            //act

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


            //assert
            Assert.IsFalse(result[0]);
            Assert.IsTrue(result[1]);
        }
Exemplo n.º 2
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 OneOrZeroRule(argument: argumentRule1);
            var rule2 = new OneOrZeroRule(argument: argumentRule2);

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

            //act

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


            //assert

            result.ForEach(Assert.IsTrue);
        }
Exemplo n.º 3
0
        public void TestSuccessChekingManySymbolWithFailArgumentRule()
        {
            //arrange

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

            //act

            var isCheckedSuccess = rule.Check(stream);

            //assert

            Assert.IsTrue(isCheckedSuccess);
        }
Exemplo n.º 4
0
        public void TestSuccessChekingOneSymbolWithSuccessArgumentRule()
        {
            //arrange

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

            //act

            var isCheckedSuccess = rule.Check(stream);

            //assert

            Assert.IsTrue(isCheckedSuccess);
        }
Exemplo n.º 5
0
        public void TestFailChekingOneSymbol()
        {
            //arrange

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

            //act

            var isCheckedSuccess = rule.Check(stream);

            //assert

            Assert.IsFalse(isCheckedSuccess);
        }
Exemplo n.º 6
0
        public void TestSuccessPositionWithSuccessArgumentRule()
        {
            //arrange

            var symbol       = 'd';
            var argumentRule = new SymbolRule(symbol: symbol);
            var rule         = new OneOrZeroRule(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);
        }
Exemplo n.º 7
0
        public void TestPositionWithFailRule()
        {
            //arrange

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

            //act

            var startPos = stream.Position;

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

            //assert

            Assert.AreEqual(startPos, endPos);
        }