Beispiel #1
0
        public void ReadingUnicodeWhenBufferTooSmall()
        {
            var buffer = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes("\u00E4\u00E4\u00E5"));
            var reader = new Utf8BufferTextReader();

            reader.SetBuffer(buffer);

            var chars = new char[2];
            int read  = reader.Read(chars, 0, chars.Length);

            Assert.Equal(2, read);
            Assert.Equal("\u00E4\u00E4", new string(chars, 0, read));

            read = reader.Read(chars, 0, chars.Length);

            Assert.Equal(1, read);
            Assert.Equal("\u00E5", new string(chars, 0, read));

            read = reader.Read(chars, 0, chars.Length);

            Assert.Equal(0, read);

            read = reader.Read(chars, 0, 1);

            Assert.Equal(0, read);
        }
Beispiel #2
0
        public void ReadingWhenBufferTooSmall()
        {
            var buffer = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes("Hello World"));
            var reader = new Utf8BufferTextReader();

            reader.SetBuffer(buffer);

            var chars = new char[5];
            int read  = reader.Read(chars, 0, chars.Length);

            Assert.Equal(5, read);
            Assert.Equal("Hello", new string(chars, 0, read));

            read = reader.Read(chars, 0, chars.Length);

            Assert.Equal(5, read);
            Assert.Equal(" Worl", new string(chars, 0, read));

            read = reader.Read(chars, 0, chars.Length);

            Assert.Equal(1, read);
            Assert.Equal("d", new string(chars, 0, read));

            read = reader.Read(chars, 0, chars.Length);

            Assert.Equal(0, read);

            read = reader.Read(chars, 0, 1);

            Assert.Equal(0, read);
        }
Beispiel #3
0
        public void ReadingWhenCharBufferBigEnough()
        {
            var buffer = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes("Hello World"));
            var reader = new Utf8BufferTextReader();

            reader.SetBuffer(buffer);

            var chars = new char[1024];
            int read  = reader.Read(chars, 0, chars.Length);

            Assert.Equal("Hello World", new string(chars, 0, read));
        }
        public void ReadingUnicodeWhenCharBufferBigEnough()
        {
            var buffer = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes("a\u00E4\u00E4\u00a9o"));
            var reader = new Utf8BufferTextReader();

            reader.SetBuffer(buffer);

            var chars = new char[1024];
            var read  = reader.Read(chars, 0, chars.Length);

            Assert.Equal(5, read);
            Assert.Equal("a\u00E4\u00E4\u00a9o", new string(chars, 0, read));

            read = reader.Read(chars, 0, chars.Length);

            Assert.Equal(0, read);
        }