示例#1
0
        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)));
        }
示例#3
0
        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);
        }
示例#4
0
        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));
        }
示例#5
0
 static void TestCharPosMapping(StreamTextAccess sut, TextStreamPosition pos, int charIdx)
 {
     Assert.AreEqual(pos.Value, sut.CharIndexToPosition(charIdx).Value);
     Assert.AreEqual(charIdx, sut.PositionToCharIndex(pos));
 }