You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by di...@apache.org on 2009/12/07 23:23:31 UTC
svn commit: r888160 - in /incubator/lucene.net/trunk/C#/src:
Lucene.Net/Index/ReusableStringReader.cs Test/TestSupportClass.cs
Author: digy
Date: Mon Dec 7 22:23:28 2009
New Revision: 888160
URL: http://svn.apache.org/viewvc?rev=888160&view=rev
Log:
Test for ReusableStringReader related with LUCENENET-150
Modified:
incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/ReusableStringReader.cs
incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/ReusableStringReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/ReusableStringReader.cs?rev=888160&r1=888159&r2=888160&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/ReusableStringReader.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/ReusableStringReader.cs Mon Dec 7 22:23:28 2009
@@ -24,46 +24,72 @@
/// that can be reset to a new string; we use this when
/// tokenizing the string value from a Field.
/// </summary>
- sealed class ReusableStringReader:System.IO.TextReader
- {
- internal int upto;
- internal int left;
- internal System.String s;
- internal void Init(System.String s)
- {
- this.s = s;
- left = s.Length;
- this.upto = 0;
- }
- public int Read(char[] c)
- {
- return Read(c, 0, c.Length);
- }
- public override int Read(System.Char[] c, int off, int len)
- {
- if (left > len)
- {
- SupportClass.TextSupport.GetCharsFromString(s, upto, upto + len, c, off);
- upto += len;
- left -= len;
- return len;
- }
- else if (0 == left)
- {
- return 0;
- }
- else
- {
- SupportClass.TextSupport.GetCharsFromString(s, upto, upto + left, c, off);
- int r = left;
- left = 0;
- upto = s.Length;
- return r;
- }
- }
- public override void Close()
- {
- }
-
- }
+ sealed class ReusableStringReader : System.IO.TextReader
+ {
+ internal int upto;
+ internal int left;
+ internal System.String s;
+ internal void Init(System.String s)
+ {
+ this.s = s;
+ left = s.Length;
+ this.upto = 0;
+ }
+ public int Read(char[] c)
+ {
+ return Read(c, 0, c.Length);
+ }
+ public override int Read(System.Char[] c, int off, int len)
+ {
+ if (left > len)
+ {
+ SupportClass.TextSupport.GetCharsFromString(s, upto, upto + len, c, off);
+ upto += len;
+ left -= len;
+ return len;
+ }
+ else if (0 == left)
+ {
+ return 0;
+ }
+ else
+ {
+ SupportClass.TextSupport.GetCharsFromString(s, upto, upto + left, c, off);
+ int r = left;
+ left = 0;
+ upto = s.Length;
+ return r;
+ }
+ }
+ public override void Close()
+ {
+ }
+
+
+ public override int Read()
+ {
+ throw new NotImplementedException("This method is not implemented");
+ }
+
+ public override int ReadBlock(char[] buffer, int index, int count)
+ {
+ throw new NotImplementedException("This method is not implemented");
+ }
+
+ public override string ReadLine()
+ {
+ throw new NotImplementedException("This method is not implemented");
+ }
+
+ public override int Peek()
+ {
+ throw new NotImplementedException("This method is not implemented");
+ }
+
+ public override string ReadToEnd()
+ {
+ left = 0;
+ return s;
+ }
+ }
}
\ No newline at end of file
Modified: incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/TestSupportClass.cs?rev=888160&r1=888159&r2=888160&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs Mon Dec 7 22:23:28 2009
@@ -744,6 +744,7 @@
[TestFixture]
public class TestOldPatches
{
+ //-------------------------------------------
[Test]
[Description("LUCENENET-170")]
public void Test_Lucene_Net_Util_Parameter()
@@ -766,6 +767,7 @@
Assert.AreEqual(queryPreSerialized, queryPostSerialized, "See the issue: LUCENENET-170");
}
+ //-------------------------------------------
[Test]
[Description("LUCENENET-174")]
public void Test_Lucene_Net_Store_RAMDirectory()
@@ -808,5 +810,50 @@
Assert.AreEqual(topDocs.totalHits, 2,"See the issue: LUCENENET-174");
}
+
+
+
+ //-------------------------------------------
+ [Test]
+ [Description("LUCENENET-150")]
+ public void Test_Lucene_Net_Index_ReusableStringReader()
+ {
+ Lucene.Net.Index.IndexWriter wr = new Lucene.Net.Index.IndexWriter(new Lucene.Net.Store.RAMDirectory(), new TestAnalyzer(), true);
+
+ Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
+ Lucene.Net.Documents.Field f1 = new Lucene.Net.Documents.Field("f1", TEST_STRING, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.TOKENIZED);
+ doc.Add(f1);
+ wr.AddDocument(doc);
+
+ wr.Close();
+ }
+
+ static string TEST_STRING = "Some Text and some more Text";
+
+ class TestAnalyzer : Lucene.Net.Analysis.Analyzer
+ {
+ public override Lucene.Net.Analysis.TokenStream TokenStream(string fieldName, System.IO.TextReader reader)
+ {
+ return new TestTokenizer(reader);
+ }
+ }
+
+ class TestTokenizer : Lucene.Net.Analysis.CharTokenizer
+ {
+ public TestTokenizer(System.IO.TextReader Reader)
+ : base(Reader)
+ {
+ //Caution: "Reader" is actually of type "ReusableStringReader" and some
+ //methods (for ex. "ReadToEnd", "Peek", "ReadLine") is not implemented.
+ Assert.AreEqual(TEST_STRING, Reader.ReadToEnd(), "Issue LUCENENET-150: \"ReadToEnd\" method is not implemented");
+ }
+
+ protected override bool IsTokenChar(char c)
+ {
+ return char.IsLetterOrDigit(c);
+ }
+ }
+ //-------------------------------------------
+
}
}
\ No newline at end of file