//           11111
 // 012345678901234
 // aa  bb   cc dd
 // aa#bb dd
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void test1block1matchShorter() throws java.io.IOException
 public virtual void test1block1matchShorter()
 {
     const string BLOCK = "aa  bb   cc dd";
     CharFilter cs = new PatternReplaceCharFilter(pattern("(aa)\\s+(bb)\\s+(cc)"), "$1#$2", new StringReader(BLOCK));
     TokenStream ts = new MockTokenizer(cs, MockTokenizer.WHITESPACE, false);
     assertTokenStreamContents(ts, new string[] {"aa#bb", "dd"}, new int[] {0, 12}, new int[] {11, 14}, BLOCK.Length);
 }
 // 01234567
 //  a  a
 //  aa  aa
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void test1block2matchLonger() throws java.io.IOException
 public virtual void test1block2matchLonger()
 {
     const string BLOCK = " a  a";
     CharFilter cs = new PatternReplaceCharFilter(pattern("a"), "aa", new StringReader(BLOCK));
     TokenStream ts = new MockTokenizer(cs, MockTokenizer.WHITESPACE, false);
     assertTokenStreamContents(ts, new string[] {"aa", "aa"}, new int[] {1, 4}, new int[] {2, 5}, BLOCK.Length);
 }
예제 #3
0
        //           111111111122222222223333
        // 0123456789012345678901234567890123
        //   aa bb cc --- aa bb aa   bb   cc
        //   aa  bb  cc --- aa bb aa  bb  cc
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void test1blockMultiMatches() throws java.io.IOException
        public virtual void test1blockMultiMatches()
        {
            const string BLOCK = "  aa bb cc --- aa bb aa   bb   cc";
            CharFilter   cs    = new PatternReplaceCharFilter(pattern("(aa)\\s+(bb)\\s+(cc)"), "$1  $2  $3", new StringReader(BLOCK));
            TokenStream  ts    = new MockTokenizer(cs, MockTokenizer.WHITESPACE, false);

            assertTokenStreamContents(ts, new string[] { "aa", "bb", "cc", "---", "aa", "bb", "aa", "bb", "cc" }, new int[] { 2, 6, 9, 11, 15, 18, 21, 25, 29 }, new int[] { 4, 8, 10, 14, 17, 20, 23, 27, 33 }, BLOCK.Length);
        }
예제 #4
0
        //           11111
        // 012345678901234
        // aa  bb   cc dd
        // aa#bb dd
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void test1block1matchShorter() throws java.io.IOException
        public virtual void test1block1matchShorter()
        {
            const string BLOCK = "aa  bb   cc dd";
            CharFilter   cs    = new PatternReplaceCharFilter(pattern("(aa)\\s+(bb)\\s+(cc)"), "$1#$2", new StringReader(BLOCK));
            TokenStream  ts    = new MockTokenizer(cs, MockTokenizer.WHITESPACE, false);

            assertTokenStreamContents(ts, new string[] { "aa#bb", "dd" }, new int[] { 0, 12 }, new int[] { 11, 14 }, BLOCK.Length);
        }
예제 #5
0
        // 01234567
        //  a  a
        //  aa  aa
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void test1block2matchLonger() throws java.io.IOException
        public virtual void test1block2matchLonger()
        {
            const string BLOCK = " a  a";
            CharFilter   cs    = new PatternReplaceCharFilter(pattern("a"), "aa", new StringReader(BLOCK));
            TokenStream  ts    = new MockTokenizer(cs, MockTokenizer.WHITESPACE, false);

            assertTokenStreamContents(ts, new string[] { "aa", "aa" }, new int[] { 1, 4 }, new int[] { 2, 5 }, BLOCK.Length);
        }
예제 #6
0
        // 012345678
        // aa bb cc
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testReplaceByEmpty() throws java.io.IOException
        public virtual void testReplaceByEmpty()
        {
            const string BLOCK = "aa bb cc";
            CharFilter   cs    = new PatternReplaceCharFilter(pattern("(aa)\\s+(bb)\\s+(cc)"), "", new StringReader(BLOCK));
            TokenStream  ts    = new MockTokenizer(cs, MockTokenizer.WHITESPACE, false);

            assertTokenStreamContents(ts, new string[] {});
        }
예제 #7
0
        //           1111
        // 01234567890123
        // this is test.
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testNothingChange() throws java.io.IOException
        public virtual void testNothingChange()
        {
            const string BLOCK = "this is test.";
            CharFilter   cs    = new PatternReplaceCharFilter(pattern("(aa)\\s+(bb)\\s+(cc)"), "$1$2$3", new StringReader(BLOCK));
            TokenStream  ts    = new MockTokenizer(cs, MockTokenizer.WHITESPACE, false);

            assertTokenStreamContents(ts, new string[] { "this", "is", "test." }, new int[] { 0, 5, 8 }, new int[] { 4, 7, 13 }, BLOCK.Length);
        }
예제 #8
0
        //           11111111112222222222333333333
        // 012345678901234567890123456789012345678
        //   aa bb cc --- aa bb aa. bb aa   bb cc
        //   aa##bb cc --- aa##bb aa. bb aa##bb cc

        //   aa bb cc --- aa bbbaa. bb aa   b cc

//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void test2blocksMultiMatches() throws java.io.IOException
        public virtual void test2blocksMultiMatches()
        {
            const string BLOCK = "  aa bb cc --- aa bb aa. bb aa   bb cc";

            CharFilter  cs = new PatternReplaceCharFilter(pattern("(aa)\\s+(bb)"), "$1##$2", new StringReader(BLOCK));
            TokenStream ts = new MockTokenizer(cs, MockTokenizer.WHITESPACE, false);

            assertTokenStreamContents(ts, new string[] { "aa##bb", "cc", "---", "aa##bb", "aa.", "bb", "aa##bb", "cc" }, new int[] { 2, 8, 11, 15, 21, 25, 28, 36 }, new int[] { 7, 10, 14, 20, 24, 27, 35, 38 }, BLOCK.Length);
        }
예제 #9
0
        //           11111111112222222222333333333
        // 012345678901234567890123456789012345678
        //  a bb - ccc . --- bb a . ccc ccc bb
        //  aa b - c . --- b aa . c c b
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testChain() throws java.io.IOException
        public virtual void testChain()
        {
            const string BLOCK = " a bb - ccc . --- bb a . ccc ccc bb";
            CharFilter   cs    = new PatternReplaceCharFilter(pattern("a"), "aa", new StringReader(BLOCK));

            cs = new PatternReplaceCharFilter(pattern("bb"), "b", cs);
            cs = new PatternReplaceCharFilter(pattern("ccc"), "c", cs);
            TokenStream ts = new MockTokenizer(cs, MockTokenizer.WHITESPACE, false);

            assertTokenStreamContents(ts, new string[] { "aa", "b", "-", "c", ".", "---", "b", "aa", ".", "c", "c", "b" }, new int[] { 1, 3, 6, 8, 12, 14, 18, 21, 23, 25, 29, 33 }, new int[] { 2, 5, 7, 11, 13, 17, 20, 22, 24, 28, 32, 35 }, BLOCK.Length);
        }
예제 #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void checkOutput(String input, String pattern, String replacement, String expectedOutput, String expectedIndexMatchedOutput) throws java.io.IOException
        private void checkOutput(string input, string pattern, string replacement, string expectedOutput, string expectedIndexMatchedOutput)
        {
            CharFilter cs = new PatternReplaceCharFilter(pattern(pattern), replacement, new StringReader(input));

            StringBuilder output = new StringBuilder();

            for (int chr = cs.read(); chr > 0; chr = cs.read())
            {
                output.Append((char)chr);
            }

            StringBuilder indexMatched = new StringBuilder();

            for (int i = 0; i < output.Length; i++)
            {
                indexMatched.Append((cs.correctOffset(i) < 0 ? "-" : input[cs.correctOffset(i)]));
            }

            bool outputGood       = expectedOutput.Equals(output.ToString());
            bool indexMatchedGood = expectedIndexMatchedOutput.Equals(indexMatched.ToString());

            if (!outputGood || !indexMatchedGood || false)
            {
                Console.WriteLine("Pattern : " + pattern);
                Console.WriteLine("Replac. : " + replacement);
                Console.WriteLine("Input   : " + input);
                Console.WriteLine("Output  : " + output);
                Console.WriteLine("Expected: " + expectedOutput);
                Console.WriteLine("Output/i: " + indexMatched);
                Console.WriteLine("Expected: " + expectedIndexMatchedOutput);
                Console.WriteLine();
            }

            assertTrue("Output doesn't match.", outputGood);
            assertTrue("Index-matched output doesn't match.", indexMatchedGood);
        }
 //           111111111122222222223333
 // 0123456789012345678901234567890123
 //   aa bb cc --- aa bb aa   bb   cc
 //   aa  bb  cc --- aa bb aa  bb  cc
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void test1blockMultiMatches() throws java.io.IOException
 public virtual void test1blockMultiMatches()
 {
     const string BLOCK = "  aa bb cc --- aa bb aa   bb   cc";
     CharFilter cs = new PatternReplaceCharFilter(pattern("(aa)\\s+(bb)\\s+(cc)"), "$1  $2  $3", new StringReader(BLOCK));
     TokenStream ts = new MockTokenizer(cs, MockTokenizer.WHITESPACE, false);
     assertTokenStreamContents(ts, new string[] {"aa", "bb", "cc", "---", "aa", "bb", "aa", "bb", "cc"}, new int[] {2, 6, 9, 11, 15, 18, 21, 25, 29}, new int[] {4, 8, 10, 14, 17, 20, 23, 27, 33}, BLOCK.Length);
 }
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: private void checkOutput(String input, String pattern, String replacement, String expectedOutput, String expectedIndexMatchedOutput) throws java.io.IOException
        private void checkOutput(string input, string pattern, string replacement, string expectedOutput, string expectedIndexMatchedOutput)
        {
            CharFilter cs = new PatternReplaceCharFilter(pattern(pattern), replacement, new StringReader(input));

            StringBuilder output = new StringBuilder();
            for (int chr = cs.read(); chr > 0; chr = cs.read())
            {
              output.Append((char) chr);
            }

            StringBuilder indexMatched = new StringBuilder();
            for (int i = 0; i < output.Length; i++)
            {
              indexMatched.Append((cs.correctOffset(i) < 0 ? "-" : input[cs.correctOffset(i)]));
            }

            bool outputGood = expectedOutput.Equals(output.ToString());
            bool indexMatchedGood = expectedIndexMatchedOutput.Equals(indexMatched.ToString());

            if (!outputGood || !indexMatchedGood || false)
            {
              Console.WriteLine("Pattern : " + pattern);
              Console.WriteLine("Replac. : " + replacement);
              Console.WriteLine("Input   : " + input);
              Console.WriteLine("Output  : " + output);
              Console.WriteLine("Expected: " + expectedOutput);
              Console.WriteLine("Output/i: " + indexMatched);
              Console.WriteLine("Expected: " + expectedIndexMatchedOutput);
              Console.WriteLine();
            }

            assertTrue("Output doesn't match.", outputGood);
            assertTrue("Index-matched output doesn't match.", indexMatchedGood);
        }
 // 012345678
 // aa bb cc
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testReplaceByEmpty() throws java.io.IOException
 public virtual void testReplaceByEmpty()
 {
     const string BLOCK = "aa bb cc";
     CharFilter cs = new PatternReplaceCharFilter(pattern("(aa)\\s+(bb)\\s+(cc)"), "", new StringReader(BLOCK));
     TokenStream ts = new MockTokenizer(cs, MockTokenizer.WHITESPACE, false);
     assertTokenStreamContents(ts, new string[] {});
 }
 //           1111
 // 01234567890123
 // this is test.
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testNothingChange() throws java.io.IOException
 public virtual void testNothingChange()
 {
     const string BLOCK = "this is test.";
     CharFilter cs = new PatternReplaceCharFilter(pattern("(aa)\\s+(bb)\\s+(cc)"), "$1$2$3", new StringReader(BLOCK));
     TokenStream ts = new MockTokenizer(cs, MockTokenizer.WHITESPACE, false);
     assertTokenStreamContents(ts, new string[] {"this", "is", "test."}, new int[] {0, 5, 8}, new int[] {4, 7, 13}, BLOCK.Length);
 }
 //           11111111112222222222333333333
 // 012345678901234567890123456789012345678
 //  a bb - ccc . --- bb a . ccc ccc bb
 //  aa b - c . --- b aa . c c b
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testChain() throws java.io.IOException
 public virtual void testChain()
 {
     const string BLOCK = " a bb - ccc . --- bb a . ccc ccc bb";
     CharFilter cs = new PatternReplaceCharFilter(pattern("a"), "aa", new StringReader(BLOCK));
     cs = new PatternReplaceCharFilter(pattern("bb"), "b", cs);
     cs = new PatternReplaceCharFilter(pattern("ccc"), "c", cs);
     TokenStream ts = new MockTokenizer(cs, MockTokenizer.WHITESPACE, false);
     assertTokenStreamContents(ts, new string[] {"aa", "b", "-", "c", ".", "---", "b", "aa", ".", "c", "c", "b"}, new int[] {1, 3, 6, 8, 12, 14, 18, 21, 23, 25, 29, 33}, new int[] {2, 5, 7, 11, 13, 17, 20, 22, 24, 28, 32, 35}, BLOCK.Length);
 }
        //           11111111112222222222333333333
        // 012345678901234567890123456789012345678
        //   aa bb cc --- aa bb aa. bb aa   bb cc
        //   aa##bb cc --- aa##bb aa. bb aa##bb cc
        //   aa bb cc --- aa bbbaa. bb aa   b cc
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public void test2blocksMultiMatches() throws java.io.IOException
        public virtual void test2blocksMultiMatches()
        {
            const string BLOCK = "  aa bb cc --- aa bb aa. bb aa   bb cc";

            CharFilter cs = new PatternReplaceCharFilter(pattern("(aa)\\s+(bb)"), "$1##$2", new StringReader(BLOCK));
            TokenStream ts = new MockTokenizer(cs, MockTokenizer.WHITESPACE, false);
            assertTokenStreamContents(ts, new string[] {"aa##bb", "cc", "---", "aa##bb", "aa.", "bb", "aa##bb", "cc"}, new int[] {2, 8, 11, 15, 21, 25, 28, 36}, new int[] {7, 10, 14, 20, 24, 27, 35, 38}, BLOCK.Length);
        }