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

            var searchFor = search.ToCharArray();

            int found = -1;

            if (searchFor.Length == 1)
            {
                found = ReadCursorOperations.Seek(start, end, out result, (byte)searchFor[0]);
            }
            else if (searchFor.Length == 2)
            {
                found = ReadCursorOperations.Seek(start, end, out result, (byte)searchFor[0], (byte)searchFor[1]);
            }
            else if (searchFor.Length == 3)
            {
                found = ReadCursorOperations.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 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());
        }