コード例 #1
0
        public void TestBalancingGroup()
        {
            Assert.ThrowsException <ArgumentNullException>(() => new BalancingGroupPattern(("group1", "group2")));
            Assert.AreEqual(new BalancingGroupPattern("group1", "abc".AsItIs()).Expression, "(?'-group1'abc)");
            Assert.AreEqual(new BalancingGroupPattern(("group1", "group2"), "abc").Expression, "(?'group2-group1'abc)");
            Assert.AreEqual(Patterns.BalancedBracketsContent('[', ']').Expression, @"^[^]\[]*(?:(?:(?'Open'\[)[^]\[]*)+(?:(?'Close-Open'])[^]\[]*)+)*(?(Open)(?!))$");

            Assert.AreEqual(Verex.ContainsBalancedBrackets(
                                "(2 + 1) * (3 + 2) - ( 1 + 4)",
                                "(", ")"), true);

            Assert.AreEqual(Verex.ContainsBalancedBrackets(
                                "(2 + 1) * ((3 + 2) - ( 1 + 4)",
                                "(", ")"), false);

            Assert.AreEqual(Verex.ContainsBalancedBrackets(
                                "=>=>x + 2<= * =>4 + 3<=<= / 2", "=>", "<="), true);

            Assert.AreEqual(Verex.ContainsBalancedBrackets(
                                "=>=>x + 2<= * =>4 + 3<= / 2", "=>", "<="), false);

            string input = "<!--<!--x+2> * <!--4+3>>/2";
            var    x     = Verex.BalancedContents(input, "<!--", ">");

            Assert.AreEqual(Join(x), @"<!--x+2> * <!--4+3>, x+2, 4+3, ");

            input = "<!--<!--x+2=> * <!--4+3=>=>/2";
            x     = Verex.BalancedContents(input, "<!--", "=>");

            Assert.AreEqual(Join(x), @"<!--x+2=> * <!--4+3=>, x+2, 4+3, ");

            input = " 'y' 'x+2' * '4+3'/2";
            x     = Verex.BalancedContents(input, "'", "'");

            Assert.AreEqual(Join(x), @"y' 'x+2' * '4+3,  'x+2' * , x+2, ");

            input = "--y-- --x+2-- * --4+3--/2";
            x     = Verex.BalancedContents(input, "--", "--");

            Assert.AreEqual(Join(x), @"y-- --x+2-- * --4+3,  --x+2-- * , x+2, ");
        }