public async Task StartPositionPointsToNonExistingCharachter_Backward() { StreamTextAccess buf = new StreamTextAccess( S().Add('a', 10).ToStream(Encoding.UTF8), Encoding.UTF8 ); await buf.BeginReading(11, TextAccessDirection.Backward); Assert.AreEqual(S().Add('a', 10).ToString(), buf.BufferString); int idx = buf.PositionToCharIndex(new TextStreamPosition(11)); }
public void StreamPositionToCharIndexTest_IdxFromPrevBlock() { StreamTextAccess buf = new StreamTextAccess( S().Add('a', blockSz * 3).ToStream(Encoding.UTF8), Encoding.UTF8 ); buf.BeginReading(0, TextAccessDirection.Forward); buf.Advance(100); Assert.Throws <ArgumentOutOfRangeException>(() => buf.PositionToCharIndex(new TextStreamPosition(50))); }
public async Task StartPositionPointsToNonExistingCharachter_Backward_SecondBlock() { StreamTextAccess buf = new StreamTextAccess( S().Add('a', blockSz).Add('b', blockSz).ToStream(Encoding.UTF8), Encoding.UTF8 ); await buf.BeginReading(blockSz *2, TextAccessDirection.Backward); Assert.AreEqual("", buf.BufferString); int idx = buf.PositionToCharIndex(new TextStreamPosition(blockSz * 2)); Assert.AreEqual(0, idx); }
public async Task StreamPositionToCharIndexTest_InvalidBigTextStreamPositionIsMappedToPastTheEndCharIndex() { StreamTextAccess buf = new StreamTextAccess( S().Add('a', blockSz * 3).ToStream(Encoding.Unicode), Encoding.Unicode ); await buf.BeginReading(0, TextAccessDirection.Forward); // valid Unicode text stream positions are from 0 to blockSz/2. below is invalid position. var invalidTextStreamPosition = new TextStreamPosition(blockSz - 10); Assert.AreEqual(blockSz / 2, buf.PositionToCharIndex(invalidTextStreamPosition)); }
static void TestCharPosMapping(StreamTextAccess sut, TextStreamPosition pos, int charIdx) { Assert.AreEqual(pos.Value, sut.CharIndexToPosition(charIdx).Value); Assert.AreEqual(charIdx, sut.PositionToCharIndex(pos)); }