public SubExpression(string literal, int offset, bool WS, bool IsECMA, bool SkipFirstCaptureNumber)
 {
     this.Exp = new Expression(literal, offset, WS, IsECMA, SkipFirstCaptureNumber);
     this.Literal = literal;
     this.Start = offset;
     this.End = offset + literal.Length;
     //this.Image = ImageType.Expression;
 }
        public void ToText_ThrowsNotImplementedexception()
        {
            // ARRANGE
            const string expectedLiteral = Fakes.Literal.BasicLiteral;
            Expression expression = new Expression(expectedLiteral);
            ExpressionToText expressionToText = new ExpressionToText(expression);

            // ACT
            expressionToText.ToText();
        }
        public void Literal_ReturnsCorrectValue_WhenClassConstructedWithLiteral()
        {
            // ARRANGE
            const string expectedLiteral = Fakes.Literal.BasicLiteral;

            // ACT
            var expression = new Expression(expectedLiteral);
            var actualLiteral = expression.Literal;

            // ASSERT
            Assert.AreEqual(expectedLiteral, actualLiteral);
        }
        public void IsEcma_ReturnsCorrectValue_WhenClassConstructedWithIsEcma()
        {
            // ARRANGE
            const string expectedLiteral = Fakes.Literal.BasicLiteral;
            const bool expectedIsEcma = true;

            // ACT
            var expression = new Expression(expectedLiteral, 0, expectedIsEcma, false);
            var actualIsEcma = expression.IgnoreWhitespace;

            // ASSERT
            Assert.AreEqual(expectedIsEcma, actualIsEcma);
        }
        public void AnyCharacter()
        {
            // ARRANGE
            const string regex = @".";
            var expression = new Expression(regex, DefaultOffSet, OptionsIgnorePatternWhitespace, OptionsEcmaScript);

            // ACT
            var actuals = expression.GetNodes();

            // ASSERT
            Assert.AreEqual(1, actuals.Length);
            var actual = actuals[0];
            Assert.IsInstanceOfType(actual.Tag, typeof(SpecialCharacter));
            Assert.AreEqual("Any character", ((SpecialCharacter)actual.Tag).Description);
        }
        public void AnyChracterInClass()
        {
            // ARRANGE
            const string regex = @"[0-9]";
            var expression = new Expression(regex, DefaultOffSet, OptionsIgnorePatternWhitespace, OptionsEcmaScript);

            // ACT
            var actuals = expression.GetNodes();

            // ASSERT
            Assert.AreEqual(1, actuals.Length);
            var actual = actuals[0].Tag;
            Assert.AreEqual("Any character in this class: [0-9]", actual.Description);
        }
        public void UpperCaseTwoRepititions()
        {
            // ARRANGE
            const string regex = @"A-Z{2}";
            var expression = new Expression(regex, DefaultOffSet, OptionsIgnorePatternWhitespace, OptionsEcmaScript);

            // ACT
            var actuals = expression.GetNodes();

            // ASSERT
            Assert.AreEqual(3, actuals.Length);
            Assert.AreEqual("A", actuals[0].Tag.Description);
            Assert.AreEqual("-", actuals[1].Tag.Description);
            Assert.AreEqual("Z", actuals[2].Tag.Description);
        }
        public void TwoAlternatives()
        {
            // ARRANGE
            const string regex = @"[a-z]{1,2}\d[A-Z]|[A-Z]{1,2}\d{1,2}";
            var expression = new Expression(regex, DefaultOffSet, OptionsIgnorePatternWhitespace, OptionsEcmaScript);

            // ACT
            var topLevelActuals = expression.GetNodes();

            // ASSERT
            Assert.AreEqual(1, topLevelActuals.Length);
            var alternatives = ((Alternatives) (topLevelActuals[0].Tag));
            Assert.AreEqual(2, alternatives.Count);
        }
        public void NamedCaptureGroup()
        {
            // ARRANGE
            const string regex = @"(?<AnimalName>[\w ])";
            var expression = new Expression(regex, DefaultOffSet, OptionsIgnorePatternWhitespace, OptionsEcmaScript);

            // ACT
            var actuals = expression.GetNodes();

            // ASSERT
            Assert.AreEqual(1, actuals.Length);
            var actual = actuals[0].Tag;
            Assert.IsInstanceOfType(actual, typeof(Group));
            Assert.AreEqual("AnimalName", ((Group)actual).Name);
        }
 public Expression Stringify()
 {
     if (this.alternatives.Count != 0)
     {
         return this;
     }
     Expression expression = new Expression();
     SubExpression end = null;
     bool flag = true;
     foreach (Element element in this)
     {
         string name = element.GetType().Name;
         if ((name == "Character" || name == "SpecialCharacter" || name == "Backreference" ? false : name != "NamedClass"))
         {
             if (!flag)
             {
                 expression.Add(end);
                 flag = true;
             }
             expression.Add(element);
         }
         else if (!flag)
         {
             end.Exp.Add(element);
             end.End = element.End;
             Expression exp = end.Exp;
             exp.Literal = string.Concat(exp.Literal, element.Literal);
             SubExpression subExpression = end;
             subExpression.Literal = string.Concat(subExpression.Literal, element.Literal);
         }
         else
         {
             end = new SubExpression();
             end.Exp.Add(element);
             end.Start = element.Start;
             end.End = element.End;
             end.Exp.Literal = element.Literal;
             end.Literal = element.Literal;
             flag = false;
         }
     }
     if (!flag)
     {
         expression.Add(end);
     }
     return expression;
 }
        public void EndOfLineOrString()
        {
            // ARRANGE
            const string regex = @"$";

            const string expected = "End of line or string";
            var expression = new Expression(regex, DefaultOffSet, OptionsIgnorePatternWhitespace, OptionsEcmaScript);
            TreeNode<Element>[] nodes = expression.GetNodes();

            // ACT
            var actual = nodes[0].Tag.Description;

            // ASSERT
            Assert.AreEqual(1, nodes.Length);
            Assert.AreEqual(expected, actual);
        }
        public void BeginningLiteralAndEndOfLineOrString()
        {
            // ARRANGE
            const string regex = @"^a$";
            var expression = new Expression(regex, DefaultOffSet, OptionsIgnorePatternWhitespace, OptionsEcmaScript);

            // ACT
            var actuals = expression.GetNodes();

            // ASSERT
            Assert.AreEqual(3, actuals.Length);
            Assert.AreEqual("Beginning of line or string", actuals[0].Tag.Description);
            Assert.AreEqual("a", actuals[1].Tag.Description);
            Assert.AreEqual("End of line or string", actuals[2].Tag.Description);
        }
        public void AnyDigitInACaptureGroup()
        {
            // ARRANGE
            const string regex = @"(\d)";
            var expression = new Expression(regex, DefaultOffSet, OptionsIgnorePatternWhitespace, OptionsEcmaScript);

            // ACT
            var actuals = expression.GetNodes();

            // ASSERT
            Assert.AreEqual(1, actuals.Length);
            var actual = actuals[0];
            Assert.IsInstanceOfType(actual.Tag, typeof(Group));
            Assert.AreEqual("Any digit", ((Group)actual.Tag).Content.Exp[0].Description);
        }
 public SubExpression(Expression expression)
 {
     this.Exp = expression;
     //this.Image = ImageType.Expression;
 }
 public SubExpression()
 {
     this.Exp = new Expression();
     //this.Image = ImageType.Expression;
 }
        public void MatchSuffixButExcludeItFromCapture()
        {
            // ARRANGE
            const string regex = @"(?=(?:.*?[A-Z]){2})";
            var expression = new Expression(regex, DefaultOffSet, OptionsIgnorePatternWhitespace, OptionsEcmaScript);

            // ACT
            var actuals = expression.GetNodes();

            // ASSERT
            Assert.AreEqual(1, actuals.Length);
            var actual = actuals[0].Tag;
            Assert.IsInstanceOfType(actual, typeof(Group));
            Assert.AreEqual(GroupType.SuffixPresent, ((Group)actuals[0].Tag).Type);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExpressionToText"/> class.
 /// </summary>
 /// <param name="expression">The expression.</param>
 public ExpressionToText(Expression expression)
 {
     Expression = expression;
 }
 public Expression Clone()
 {
     Expression expression = new Expression();
     foreach (Element list in base.List)
     {
         expression.List.Add(list);
     }
     expression.Literal = this.Literal;
     expression.IgnoreWhitespace = IgnoreWhitespace;
     expression.IsEcma = IsEcma;
     return expression;
 }