Esempio n. 1
0
        public void Issue1197()
        {
            var baseText   = "food time";
            var text       = string.Format("{0}{1}", baseText, '\u2019');
            var encoding   = s_utf8NoBom;
            var sourceText = SourceText.From(text, encoding);

            using (var stream = new SourceTextStream(sourceText, bufferSize: text.Length * 2))
            {
                var buffer = new byte[baseText.Length + 1];
                Assert.Equal(baseText.Length, stream.Read(buffer, 0, buffer.Length));
                Assert.True(buffer.Take(baseText.Length).SequenceEqual(encoding.GetBytes(baseText)));

                Assert.Equal(3, stream.Read(buffer, 0, buffer.Length));
                Assert.True(buffer.Take(3).SequenceEqual(encoding.GetBytes(new[] { '\u2019' })));
            }
        }
Esempio n. 2
0
        public void MinimumLength()
        {
            var sourceText = SourceText.From("hello world", s_utf8NoBom);

            using (var stream = new SourceTextStream(sourceText))
            {
                var buffer = new byte[100];
                var max    = s_utf8NoBom.GetMaxByteCount(charCount: 1);
                for (int i = 0; i < max; i++)
                {
                    var local = i;
                    Assert.Throws(typeof(ArgumentException), () => stream.Read(buffer, 0, local));
                }
            }
        }