Skip to content

Commit

Permalink
Add tests for ReadOnlySpan overloads of CharBlockArray.Append and Cha…
Browse files Browse the repository at this point in the history
…rTermAttributeImpl.Append
  • Loading branch information
paulirwin committed Nov 17, 2024
1 parent 4dfc3d2 commit bbd9f76
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public virtual void TestArray()
// CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder()
// .onUnmappableCharacter(CodingErrorAction.REPLACE)
// .onMalformedInput(CodingErrorAction.REPLACE);
//
// Encoding decoder = Encoding.GetEncoding(Encoding.UTF8.CodePage,
// new EncoderReplacementFallback("?"),
//
// Encoding decoder = Encoding.GetEncoding(Encoding.UTF8.CodePage,
// new EncoderReplacementFallback("?"),
// new DecoderReplacementFallback("?"));

for (int i = 0; i < n; i++)
Expand Down Expand Up @@ -247,6 +247,11 @@ public virtual void TestAppendableInterface()
expected = t.ToString();
t.Append((char[])null); // No-op
Assert.AreEqual(expected, t.ToString());

// LUCENENET specific - test ReadOnlySpan<char> overload
t = new CharBlockArray();
t.Append("12345678".AsSpan());
Assert.AreEqual("12345678", t.ToString());
}

// LUCENENET: Borrowed this test from TestCharTermAttributeImpl
Expand Down Expand Up @@ -285,6 +290,11 @@ public virtual void TestAppendableInterfaceWithLongSequences()
const string longTestString = "012345678901234567890123456789";
t.Append(new CharSequenceAnonymousClass(longTestString));
Assert.AreEqual("4567890123456" + longTestString, t.ToString());

// LUCENENET specific - test ReadOnlySpan<char> overload
t = new CharBlockArray();
t.Append("01234567890123456789012345678901234567890123456789".AsSpan());
Assert.AreEqual("01234567890123456789012345678901234567890123456789", t.ToString());
}

private sealed class CharSequenceAnonymousClass : ICharSequence
Expand Down Expand Up @@ -319,4 +329,4 @@ public override string ToString()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ public virtual void TestAppendableInterface()
expected = t.ToString();
t.Append((char[])null); // No-op
Assert.AreEqual(expected, t.ToString());

// LUCENENET specific - test ReadOnlySpan<char> overload
t.SetEmpty().Append("12345678".AsSpan());
Assert.AreEqual("12345678", t.ToString());
}

[Test]
Expand Down Expand Up @@ -341,6 +345,10 @@ public virtual void TestAppendableInterfaceWithLongSequences()
const string longTestString = "012345678901234567890123456789";
t.Append(new CharSequenceAnonymousClass(this, longTestString));
Assert.AreEqual("4567890123456" + longTestString, t.ToString());

// LUCENENET specific - test ReadOnlySpan<char> overload
t.SetEmpty().Append("01234567890123456789012345678901234567890123456789".AsSpan());
Assert.AreEqual("01234567890123456789012345678901234567890123456789", t.ToString());
}

private sealed class CharSequenceAnonymousClass : ICharSequence
Expand Down Expand Up @@ -479,4 +487,4 @@ public void testAppendPerf() {
*/
}
}
}

0 comments on commit bbd9f76

Please sign in to comment.