package org.apache.lucene.analysis.ja;

/**
 * Copyright 2004 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.IOException;

import org.apache.lucene.analysis.BaseTokenStreamTestCase;

/**
 * Simple tests for {@link JapaneseAnalyzer} 
 */
public class TestJapaneseAnalyzer extends BaseTokenStreamTestCase {
  /** This test fails with NPE when the 
   * stopwords file is missing in classpath */
  public void testResourcesAvailable() {
    new JapaneseAnalyzer(TEST_VERSION_CURRENT);
  }
  
  /**
   * An example sentence, test removal of particles, etc by POS,
   * lemmatization with the basic form, and that position increments
   * and offsets are correct.
   */
  public void testBasics() throws IOException {
    assertAnalyzesTo(new JapaneseAnalyzer(TEST_VERSION_CURRENT), "多くの学生が試験に落ちた。",
      new String[] { "多く", "学生", "試験", "落ちる" },
      new int[] { 0, 3, 6,  9 },
      new int[] { 2, 5, 8, 11 },
      new int[] { 1, 2, 2,  2 }
    );
  }
}

@@ -681,66 +681,227 @@
 on;%0A
-%0Aimport org.apache.lucene.analysis.BaseTokenStreamTestCase
+import java.io.StringReader;%0A%0Aimport org.apache.lucene.analysis.Analyzer;%0Aimport org.apache.lucene.analysis.BaseTokenStreamTestCase;%0Aimport org.apache.lucene.analysis.TokenStream;%0Aimport org.apache.lucene.util._TestUtil
 ;%0A%0A/
@@ -1668,10 +1668,544 @@
  );%0A  %7D%0A
+  %0A  /**%0A   * Analyzes random unicode strings, to ensure no exception%0A   * (results could be completely bogus, but makes sure we don't crash on some input)%0A   */%0A  public void testReliability() throws IOException %7B%0A    Analyzer analyzer = new JapaneseAnalyzer(TEST_VERSION_CURRENT);%0A    for (int i = 0; i %3C 1000; i++) %7B%0A      String s = _TestUtil.randomUnicodeString(random, 100);%0A      TokenStream ts = analyzer.reusableTokenStream(%22foo%22, new StringReader(s));%0A      ts.reset();%0A      while (ts.incrementToken()) %7B%0A      %7D%0A    %7D%0A  %7D%0A
 %7D%0A

add a random test for the analyzer too