Esempio n. 1
0
        // LUCENE-3642: normalize SMP->BMP and check that offsets are correct
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testCrossPlaneNormalization() throws java.io.IOException
        public virtual void testCrossPlaneNormalization()
        {
            Analyzer analyzer = new AnalyzerAnonymousInnerClassHelper(this);
            int      num      = 1000 * RANDOM_MULTIPLIER;

            for (int i = 0; i < num; i++)
            {
                string      s  = TestUtil.randomUnicodeString(random());
                TokenStream ts = analyzer.tokenStream("foo", s);
                try
                {
                    ts.reset();
                    OffsetAttribute offsetAtt = ts.addAttribute(typeof(OffsetAttribute));
                    while (ts.incrementToken())
                    {
                        string highlightedText = StringHelperClass.SubstringSpecial(s, offsetAtt.startOffset(), offsetAtt.endOffset());
                        for (int j = 0, cp = 0; j < highlightedText.Length; j += char.charCount(cp))
                        {
                            cp = char.ConvertToUtf32(highlightedText, j);
                            assertTrue("non-letter:" + cp.ToString("x"), char.IsLetter(cp));
                        }
                    }
                    ts.end();
                }
                finally
                {
                    IOUtils.closeWhileHandlingException(ts);
                }
            }
            // just for fun
            checkRandomData(random(), analyzer, num);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testMaxPosition2() throws java.io.IOException
        public virtual void testMaxPosition2()
        {
            foreach (bool consumeAll in new bool[] { true, false })
            {
                Analyzer a = new AnalyzerAnonymousInnerClassHelper(this);

                // don't use assertAnalyzesTo here, as the end offset is not the end of the string (unless consumeAll is true, in which case its correct)!
                assertTokenStreamContents(a.tokenStream("dummy", "1  2     3  4  5"), new string[] { "1", "2" }, new int[] { 0, 3 }, new int[] { 1, 4 }, consumeAll ? 16 : null);
                assertTokenStreamContents(a.tokenStream("dummy", new StringReader("1 2 3 4 5")), new string[] { "1", "2" }, new int[] { 0, 2 }, new int[] { 1, 3 }, consumeAll ? 9 : null);

                // less than the limit, ensure we behave correctly
                assertTokenStreamContents(a.tokenStream("dummy", "1  "), new string[] { "1" }, new int[] { 0 }, new int[] { 1 }, consumeAll ? 3 : null);

                // equal to limit
                assertTokenStreamContents(a.tokenStream("dummy", "1  2  "), new string[] { "1", "2" }, new int[] { 0, 3 }, new int[] { 1, 4 }, consumeAll ? 6 : null);
            }
        }
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public void testMaxPosition2() throws java.io.IOException
        public virtual void testMaxPosition2()
        {
            foreach (bool consumeAll in new bool[]{true, false})
            {
              Analyzer a = new AnalyzerAnonymousInnerClassHelper(this);

              // don't use assertAnalyzesTo here, as the end offset is not the end of the string (unless consumeAll is true, in which case its correct)!
              assertTokenStreamContents(a.tokenStream("dummy", "1  2     3  4  5"), new string[]{"1", "2"}, new int[]{0, 3}, new int[]{1, 4}, consumeAll ? 16 : null);
              assertTokenStreamContents(a.tokenStream("dummy", new StringReader("1 2 3 4 5")), new string[]{"1", "2"}, new int[]{0, 2}, new int[]{1, 3}, consumeAll ? 9 : null);

              // less than the limit, ensure we behave correctly
              assertTokenStreamContents(a.tokenStream("dummy", "1  "), new string[]{"1"}, new int[]{0}, new int[]{1}, consumeAll ? 3 : null);

              // equal to limit
              assertTokenStreamContents(a.tokenStream("dummy", "1  2  "), new string[]{"1", "2"}, new int[]{0, 3}, new int[]{1, 4}, consumeAll ? 6 : null);
            }
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testLetterAscii() throws Exception
        public virtual void testLetterAscii()
        {
            Random   random = random();
            Analyzer left   = new MockAnalyzer(random, jvmLetter, false);
            Analyzer right  = new AnalyzerAnonymousInnerClassHelper(this);

            for (int i = 0; i < 1000; i++)
            {
                string s = TestUtil.randomSimpleString(random);
                assertEquals(s, left.tokenStream("foo", newStringReader(s)), right.tokenStream("foo", newStringReader(s)));
            }
        }
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testLetterAscii() throws Exception
 public virtual void testLetterAscii()
 {
     Random random = random();
     Analyzer left = new MockAnalyzer(random, jvmLetter, false);
     Analyzer right = new AnalyzerAnonymousInnerClassHelper(this);
     for (int i = 0; i < 1000; i++)
     {
       string s = TestUtil.randomSimpleString(random);
       assertEquals(s, left.tokenStream("foo", newStringReader(s)), right.tokenStream("foo", newStringReader(s)));
     }
 }
Esempio n. 6
0
	  // LUCENE-3642: normalize SMP->BMP and check that offsets are correct
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testCrossPlaneNormalization() throws java.io.IOException
	  public virtual void testCrossPlaneNormalization()
	  {
		Analyzer analyzer = new AnalyzerAnonymousInnerClassHelper(this);
		int num = 1000 * RANDOM_MULTIPLIER;
		for (int i = 0; i < num; i++)
		{
		  string s = TestUtil.randomUnicodeString(random());
		  TokenStream ts = analyzer.tokenStream("foo", s);
		  try
		  {
			ts.reset();
			OffsetAttribute offsetAtt = ts.addAttribute(typeof(OffsetAttribute));
			while (ts.incrementToken())
			{
			  string highlightedText = StringHelperClass.SubstringSpecial(s, offsetAtt.startOffset(), offsetAtt.endOffset());
			  for (int j = 0, cp = 0; j < highlightedText.Length; j += char.charCount(cp))
			  {
				cp = char.ConvertToUtf32(highlightedText, j);
				assertTrue("non-letter:" + cp.ToString("x"), char.IsLetter(cp));
			  }
			}
			ts.end();
		  }
		  finally
		  {
			IOUtils.closeWhileHandlingException(ts);
		  }
		}
		// just for fun
		checkRandomData(random(), analyzer, num);
	  }