public async Task LoadBufferTest_Reverse_StartReadingFromMiddle_BeginReached() { StreamTextAccess buf = new StreamTextAccess( S().Add('a', blockSz).Add('b', 200).ToStream(Encoding.UTF8), Encoding.UTF8 ); await buf.BeginReading(blockSz + 100, TextAccessDirection.Backward); Assert.AreEqual(S().Add('b', 100).ToString(), buf.BufferString); Assert.IsTrue(await buf.Advance(10)); Assert.AreEqual(S().Add('a', blockSz).Add('b', 90).ToString(), buf.BufferString); Assert.IsFalse(await buf.Advance(90)); }
public void AdvanceBufferTest_DetectOverflowReverse() { StreamTextAccess buf = new StreamTextAccess( new Str().Add('a', blockSz).Add('b', blockSz).Add('c', blockSz).Add('d', blockSz).Add('e', blockSz).ToStream(Encoding.UTF8), Encoding.UTF8 ); buf.BeginReading(blockSz * 4 + 123, TextAccessDirection.Backward); buf.Advance(0); buf.Advance(0); buf.Advance(0); Assert.Throws <OverflowException>(() => buf.Advance(0)); }
public async Task LoadBufferTest_EndReached() { StreamTextAccess buf = new StreamTextAccess( S().Add('a', blockSz).Add('b', 100).ToStream(Encoding.UTF8), Encoding.UTF8 ); await buf.BeginReading(0, TextAccessDirection.Forward); Assert.AreEqual(S().Add('a', blockSz).ToString(), buf.BufferString); Assert.IsTrue(await buf.Advance(20)); Assert.AreEqual(S().Add('a', blockSz - 20).Add('b', 100).ToString(), buf.BufferString); Assert.IsFalse(await buf.Advance(20)); }
public void AdvanceBufferTest_ReverseDirection_StartFromBlockBoundary() { StreamTextAccess buf = new StreamTextAccess( new Str().Add('1', blockSz).Add('2', blockSz).ToStream(Encoding.ASCII), Encoding.ASCII ); buf.BeginReading(blockSz, TextAccessDirection.Backward); Assert.AreEqual("", buf.BufferString); buf.Advance(0); Assert.AreEqual(new Str().Add('1', blockSz).ToString(), buf.BufferString); Assert.IsFalse(buf.Advance(blockSz)); }
public void AdvanceBufferTest_ReverseDirection_StreamLenIsMultipleOfAlignmentSize() { StreamTextAccess buf = new StreamTextAccess( new Str().Add('1', blockSz).Add('2', blockSz).ToStream(Encoding.ASCII), Encoding.ASCII ); buf.BeginReading(blockSz * 2, TextAccessDirection.Backward); Assert.AreEqual("", buf.BufferString); buf.Advance(0); Assert.AreEqual(new Str().Add('2', blockSz).ToString(), buf.BufferString); buf.Advance(blockSz); Assert.AreEqual(new Str().Add('1', blockSz).ToString(), buf.BufferString); }
public async Task AdvanceBufferTest_DetectOverflow() { StreamTextAccess buf = new StreamTextAccess( new Str().Add('a', blockSz).Add('b', blockSz).Add('c', blockSz).Add('d', blockSz).Add('e', blockSz).ToStream(Encoding.UTF8), Encoding.UTF8 ); await buf.BeginReading(0, TextAccessDirection.Forward); await buf.Advance(0); await buf.Advance(0); await buf.Advance(0); Assert.ThrowsAsync <OverflowException>(async() => await buf.Advance(0)); }
public void ChangeDirectionTest() { StreamTextAccess buf = new StreamTextAccess( S().Add('a', blockSz + 100).ToStream(Encoding.UTF8), Encoding.UTF8 ); buf.BeginReading(20, TextAccessDirection.Forward); buf.Advance(10); Assert.AreEqual(buf.AdvanceDirection, TextAccessDirection.Forward); buf.EndReading(); buf.BeginReading(20, TextAccessDirection.Backward); buf.Advance(10); Assert.AreEqual(buf.AdvanceDirection, TextAccessDirection.Backward); buf.EndReading(); }
public void AdvanceBufferTest_ReadSessionMustBeStartedToAdvance() { StreamTextAccess buf = new StreamTextAccess( new Str().Add('a', blockSz).ToStream(Encoding.UTF8), Encoding.UTF8 ); Assert.ThrowsAsync <InvalidOperationException>(async() => await buf.Advance(1)); }
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 void AdvanceBufferTest_ASCII() { StreamTextAccess buf = new StreamTextAccess( new Str().Add('a', blockSz).Add('b', blockSz).ToStream(Encoding.ASCII), Encoding.ASCII ); buf.BeginReading(0, TextAccessDirection.Forward); Assert.AreEqual(new Str().Add('a', blockSz).ToString(), buf.BufferString); buf.Advance(blockSz - 5); Assert.AreEqual("aaaaabbbbb", buf.BufferString.Substring(0, 10)); }
public void LoadBufferTest_Reverse_StartReadingFromBeginning() { StreamTextAccess buf = new StreamTextAccess( S().Add('a', 100).ToStream(Encoding.UTF8), Encoding.UTF8 ); buf.BeginReading(0, TextAccessDirection.Backward); Assert.AreEqual("", buf.BufferString); buf.Advance(0); Assert.AreEqual("", buf.BufferString); }
public void LoadBufferTest_UTF8CharAtBlockBoundaryBelongsToNextBlock_Reversed3() { StreamTextAccess buf = new StreamTextAccess( new Str().Add('a', blockSz - 1).Add('Θ').Add('b', blockSz).ToStream(Encoding.UTF8), Encoding.UTF8 ); buf.BeginReading(new TextStreamPosition(blockSz, 1).Value, TextAccessDirection.Backward); Assert.AreEqual("Θ", buf.BufferString); buf.Advance(1); Assert.AreEqual(new Str().Add('a', blockSz - 1).ToString(), buf.BufferString); }
public void AdvanceBufferTest_BufferEndsAtTheMiddleOfUTF8Char() { StreamTextAccess buf = new StreamTextAccess( new Str().Add('a', blockSz - 1).Add('Θ').Add('b', blockSz).ToStream(Encoding.UTF8), Encoding.UTF8 ); buf.BeginReading(0, TextAccessDirection.Forward); Assert.AreEqual(new Str().Add('a', blockSz - 1).ToString(), buf.BufferString); buf.Advance(blockSz - 5); Assert.AreEqual("aaaaΘbbbbb", buf.BufferString.Substring(0, 10)); }
public async Task CharIndexToStreamPositionTest_Reversed() { StreamTextAccess buf = new StreamTextAccess( S().Add('a', blockSz).Add('b', 200).ToStream(Encoding.UTF8), Encoding.UTF8 ); await buf.BeginReading(blockSz + 200, TextAccessDirection.Backward); TestCharPosMapping(buf, new TextStreamPosition(blockSz, 20), 20); Assert.IsTrue(await buf.Advance(10)); TestCharPosMapping(buf, new TextStreamPosition(blockSz, 20), blockSz + 20); TestCharPosMapping(buf, new TextStreamPosition(20), 20); }
public async Task AdvanceBufferTest_UTF16() { StreamTextAccess buf = new StreamTextAccess( new Str().Add('a', blockSz / 2).Add('b', blockSz / 2).ToStream(Encoding.Unicode), Encoding.Unicode ); await buf.BeginReading(0, TextAccessDirection.Forward); Assert.AreEqual(new Str().Add('a', blockSz / 2).ToString(), buf.BufferString); await buf.Advance(blockSz / 2 - 5); Assert.AreEqual("aaaaabbbbb", buf.BufferString.Substring(0, 10)); }
public async Task CharIndexToStreamPositionTest() { StreamTextAccess buf = new StreamTextAccess( S().Add('a', blockSz).Add('b', 200).ToStream(Encoding.UTF8), Encoding.UTF8 ); await buf.BeginReading(0, TextAccessDirection.Forward); TestCharPosMapping(buf, new TextStreamPosition(0, 20), 20); Assert.IsTrue(await buf.Advance(10)); Assert.AreEqual(S().Add('a', blockSz - 10).Add('b', 200).ToString(), buf.BufferString); TestCharPosMapping(buf, new TextStreamPosition(0, 20), 10); TestCharPosMapping(buf, new TextStreamPosition(blockSz, 20), blockSz + 10); }