예제 #1
0
        public void MemorySeek(string raw, string search, char expectResult, int expectIndex)
        {
            var      cursors = Factory.CreateWithContent(raw);
            Position start   = cursors.Start;
            Position end     = cursors.End;
            Position result  = default;

            var searchFor = search.ToCharArray();

            int found = -1;

            if (searchFor.Length == 1)
            {
                found = ReadOnlyBuffer.Seek(start, end, out result, (byte)searchFor[0]);
            }
            else if (searchFor.Length == 2)
            {
                found = ReadOnlyBuffer.Seek(start, end, out result, (byte)searchFor[0], (byte)searchFor[1]);
            }
            else if (searchFor.Length == 3)
            {
                found = ReadOnlyBuffer.Seek(start, end, out result, (byte)searchFor[0], (byte)searchFor[1], (byte)searchFor[2]);
            }
            else
            {
                Assert.False(true, "Invalid test sample.");
            }

            Assert.Equal(expectResult, found);
            Assert.Equal(cursors.Slice(result).ToArray(), Encoding.ASCII.GetBytes(raw.Substring(expectIndex)));
        }
예제 #2
0
        public void MemorySeek(string raw, char searchFor, int expectIndex)
        {
            var cursors = Factory.CreateWithContent(raw);
            var result  = cursors.PositionOf((byte)searchFor);

            Assert.NotNull(result);
            Assert.Equal(cursors.Slice(result.Value).ToArray(), Encoding.ASCII.GetBytes(raw.Substring(expectIndex)));
        }
예제 #3
0
        public void ToArrayIsCorrect(int length)
        {
            var data   = Enumerable.Range(0, length).Select(i => (byte)i).ToArray();
            var buffer = Factory.CreateWithContent(data);

            Assert.Equal(length, buffer.Length);
            Assert.Equal(data, buffer.ToArray());
        }