Ejemplo n.º 1
0
 private static void AssertReadLines(IList <string> lines)
 {
     using (var r = new StringListReader(lines)) {
         int lineno = 0;
         foreach (var expected in lines)
         {
             lineno += 1;
             var actual = r.ReadLine();
             Assert.AreEqual(expected, actual, $"Line #{lineno}");
         }
         Assert.IsNull(r.ReadLine(), "Did not reach EOF");
     }
 }
Ejemplo n.º 2
0
        public void PeekTest()
        {
            global::System.Char[] buffer = new char[10];

            using (var r = new StringListReader(new[] { "AB", "CD", "EF" }))
            {
                Assert.AreEqual('A', r.Peek());
                Assert.AreEqual('A', r.Peek());
                Assert.AreEqual('A', r.Read());
            }

            using (var r = new StringListReader(new[] { "AB", "CD", "EF" }))
            {
                Assert.AreEqual('A', r.Peek());
                Assert.AreEqual(2, r.Read(buffer, 0, 5));
                Assert.AreEqual('A', buffer[0]);
                Assert.AreEqual('B', buffer[1]);
            }

            using (var r = new StringListReader(new[] { "AB", "CD", "EF" }))
            {
                Assert.AreEqual('A', r.Read());
                Assert.AreEqual('B', r.Peek());
                // Read after peeking the last char in a line will get us
                // the next line too.
                Assert.AreEqual(3, r.Read(buffer, 0, 5));
                Assert.AreEqual('B', buffer[0]);
                Assert.AreEqual('C', buffer[1]);
                Assert.AreEqual('D', buffer[2]);
            }

            using (var r = new StringListReader(new[] { "AB", "CD", "EF" }))
            {
                Assert.AreEqual('A', r.Read());
                Assert.AreEqual('B', r.Peek());
                // Read after peeking the last char in a line will get us
                // the next line too.
                Assert.AreEqual("BCD", r.ReadLine());
            }
        }