Beispiel #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]);
        }
        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 #3
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);
        }
Beispiel #4
0
        public override SymbolRule CreateSymbolRule()
        {
            SymbolRule symbolRule = base.CreateSymbolRule();

            symbolRule.AffectedAttributes = AffectedSymbolAttributes.SizeOnly;
            return(symbolRule);
        }
        public void TestManySuccessivelyChekingWithLastFailed()
        {
            // Arrange

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

            var rule1 = new SymbolRule(symbol: symbol1);
            var rule2 = new SymbolRule(symbol: symbol2);
            var rule3 = new SymbolRule(symbol: symbol3);

            var rule = new GroupRule(new List <IRule> {
                rule1, rule2, rule3
            });


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


            // Act

            var result = rule.Check(stream);


            // Assert

            Assert.IsFalse(result, message: "result is false");
        }
Beispiel #6
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 TestThatStreamCursorHasRightPositionAfterSuccessParse()
        {
            // Arrange

            var symbol1  = 'a';
            var symbol2  = 'c';
            var addition = 'e';

            var firstSymbolRule  = new SymbolRule(symbol1);
            var secondSymbolRule = new SymbolRule(symbol2);

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

            // Act

            var streamStartPosition = stream.Position;

            new RangeRule(leftArgumentRule: firstSymbolRule, rightArgumentRule: secondSymbolRule).Check(stream);


            // Assert

            Assert.AreEqual(addition, stream.CurrentSymbol());
            Assert.AreEqual(streamStartPosition + 1, stream.Position);
        }
Beispiel #8
0
        public void TestThatRuleArgumentIsCorrect()
        {
            // Arrange

            var stream  = new MemoryStream().FromString($"{this._terminateSequence}fgadcbv");
            var context = new DefaultParserContext(stream: stream);
            var parser  = this._parserFactory.GetNewParser();

            var leftArgument1 = new SymbolRule('a');
            var leftArgument2 = new SymbolRule('b');
            var leftArgument3 = new SymbolRule('c');

            context.ParsedRules.Push(leftArgument1);
            context.ParsedRules.Push(leftArgument2);
            context.ParsedRules.Push(leftArgument3);

            // Act


            var result = parser.Parse(context) as ISingleArgumentRule;

            // Assert

            Assert.AreSame(result.ArgumentRule, leftArgument3);
        }
Beispiel #9
0
        internal override SymbolRule CreateSymbolRule()
        {
            SymbolRule symbolRule = base.CreateSymbolRule();

            symbolRule.AffectedAttributes = AffectedSymbolAttributes.ColorOnly;
            return(symbolRule);
        }
Beispiel #10
0
        public void TestParseRuleSuccessWithFilledStack()
        {
            // Arrange

            var stream  = new MemoryStream().FromString($"{this._terminateSequence}fgadcbv");
            var context = new DefaultParserContext(stream: stream);
            var parser  = this._parserFactory.GetNewParser();

            var leftArgument1 = new SymbolRule('a');
            var leftArgument2 = new SymbolRule('b');
            var leftArgument3 = new SymbolRule('c');

            context.ParsedRules.Push(leftArgument1);
            context.ParsedRules.Push(leftArgument2);
            context.ParsedRules.Push(leftArgument3);

            // Act

            var streamStart = stream.Position;
            var checkResult = parser.IsCurrentRule(context);
            var result      = parser.Parse(context) as ISingleArgumentRule;

            // Assert

            Assert.IsNotNull(result);
            Assert.IsTrue(checkResult);
            Assert.AreSame(result.ArgumentRule, leftArgument3);
            Assert.AreEqual(stream.Position, streamStart + 1);
        }
Beispiel #11
0
        public void TestThatAfterSuccessParsingStreamCursorHasRightPosition()
        {
            // Arrange

            var symbol1 = 'a';
            var symbol2 = 'c';

            var additionRule = $"\'{symbol2}\'";
            var str          = $"{DisjunctionRuleParser.Symbol}\'{symbol2}\'{additionRule}";

            var stream = new MemoryStream().FromString(str);
            var parser = new DisjunctionRuleParser();

            var context      = new DefaultParserContext(stream: stream);
            var leftArgument = new SymbolRule(symbol1);

            context.ParsedRules.Push(leftArgument);
            context.LexerBuilder = new LexerBuilder(new SimpleParserInjector());

            // Act

            parser.Parse(context);

            // Assert

            Assert.AreEqual(str.Length - additionRule.Length, context.CurrentStream.Position);
        }
Beispiel #12
0
        public void TestThatSuccessParsingGroup()
        {
            // Arrange

            var symbol1 = 'a';
            var symbol2 = 'b';

            var stream = new MemoryStream().FromString($"{DisjunctionRuleParser.Symbol}(\'{symbol2}\'\'{symbol2}\')");
            var parser = new DisjunctionRuleParser();

            var context      = new DefaultParserContext(stream: stream);
            var leftArgument = new SymbolRule(symbol1);

            context.ParsedRules.Push(leftArgument);


            context.LexerBuilder = new LexerBuilder(new SimpleParserInjector());

            // Act

            var canParsed = parser.IsCurrentRule(context);

            // Assert

            Assert.IsTrue(canParsed);
        }
        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");
        }
        public void TestManySuccessivelyChekingl()
        {
            // Arrange

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

            var rule1 = new SymbolRule(symbol: symbol1);
            var rule2 = new SymbolRule(symbol: symbol2);
            var rule3 = new SymbolRule(symbol: symbol3);

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


            // Act

            var rule1Result = rule1.Check(stream);
            var rule2Result = rule2.Check(stream);
            var rule3Result = rule3.Check(stream);


            // Assert

            Assert.IsTrue(rule1Result, message: "rule1Result is false");
            Assert.IsTrue(rule2Result, message: "rule2Result is false");
            Assert.IsFalse(rule3Result, message: "rule4Result is false");
        }
        internal void RenderPointRule(PointTemplateMapper pointTemplateMapper, Color?color, int?size)
        {
            SymbolRule symbolRule = (SymbolRule)m_coreRule;

            SetRuleLegendProperties(symbolRule);
            SetRuleDistribution(symbolRule);
            SetSymbolRuleMarkers(symbolRule.PredefinedSymbols);
            InitializePredefinedSymbols(symbolRule.PredefinedSymbols, pointTemplateMapper, color, size);
        }
Beispiel #16
0
        public void RenderSymbolRule(PointTemplateMapper symbolTemplateMapper, Color?color, MarkerStyle?markerStyle)
        {
            SymbolRule symbolRule = (SymbolRule)base.m_coreRule;

            base.SetRuleLegendProperties(symbolRule);
            base.SetRuleDistribution(symbolRule);
            this.SetSymbolRuleSizes(symbolRule.PredefinedSymbols);
            this.InitializePredefinedSymbols(symbolRule.PredefinedSymbols, symbolTemplateMapper, color, markerStyle);
        }
        public void RenderPointRule(PointTemplateMapper pointTemplateMapper, Color?color, int?size)
        {
            SymbolRule symbolRule = (SymbolRule)base.m_coreRule;

            base.SetRuleLegendProperties(symbolRule);
            base.SetRuleDistribution(symbolRule);
            this.SetSymbolRuleMarkers(symbolRule.PredefinedSymbols);
            this.InitializePredefinedSymbols(symbolRule.PredefinedSymbols, pointTemplateMapper, color, size);
        }
Beispiel #18
0
        internal virtual SymbolRule CreateSymbolRule()
        {
            SymbolRule symbolRule = (SymbolRule)(m_coreRule = new SymbolRule());

            symbolRule.Category = m_mapVectorLayer.Name;
            symbolRule.Field    = "";
            m_coreMap.SymbolRules.Add(symbolRule);
            SetRuleFieldName();
            return(symbolRule);
        }
Beispiel #19
0
        public virtual SymbolRule CreateSymbolRule()
        {
            SymbolRule symbolRule = (SymbolRule)(this.m_coreRule = new SymbolRule());

            symbolRule.Category = this.m_mapVectorLayer.Name;
            symbolRule.Field    = "";
            this.m_coreMap.SymbolRules.Add(symbolRule);
            this.SetRuleFieldName();
            return(symbolRule);
        }
Beispiel #20
0
        public void TestRulePriority()
        {
            var argumentRule = new SymbolRule(symbol: 'b');

            //act

            var rule = new OneOrZeroRule(argument: argumentRule);

            //assert

            Assert.AreEqual(rule.Priority, RulePriority.RuleZeroOrOne);
        }
        public void TestRulePriority()
        {
            // arrage

            var symbol = 'a';

            // act

            var rule = new SymbolRule(symbol: symbol);

            // assert

            Assert.AreEqual(rule.Priority, RulePriority.RuleSymbol);
        }
        public void TestRighSringSavedInFaledCase()
        {
            // Arrange

            var symbol = 'a';
            var rule   = new SymbolRule(symbol: symbol);
            var stream = new MemoryStream().FromString($"{symbol + 1}");

            // Act
            rule.Check(stream);

            // Assert

            Assert.AreEqual(string.Empty, rule.ChekedString);
        }
        public void TestFailChekingOneSymbol()
        {
            //arrange

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

            //act

            var isCheckedSuccess = rule.Check(stream);

            //assert

            Assert.IsFalse(isCheckedSuccess);
        }
Beispiel #24
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);
        }
        public void TestStreamPositionOffsetCorrectlyWithIncorrectSymbol()
        {
            // Arrange

            var symbol        = 'g';
            var rule          = new SymbolRule(symbol: symbol);
            var stream        = new MemoryStream().FromString("example test string that so biger then needed");
            var startPosition = stream.Position;

            // Act

            rule.Check(stream);

            // Assert

            Assert.AreEqual(stream.Position, startPosition);
        }
        public void TestSuccessChekingSpecialSymbol()
        {
            // Arrange

            var symbol = '\r';
            var rule   = new SymbolRule(symbol: symbol);
            var stream = new MemoryStream().FromString("\rtnmp");

            // Act
            var startPos = stream.Position;

            rule.Check(stream);

            // Assert

            Assert.AreEqual(startPos + 1, stream.Position);
        }
Beispiel #27
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 #28
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);
        }
Beispiel #29
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);
        }
Beispiel #30
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);
        }