Пример #1
0
 public void TestConsumeUntil()
 {
     using (var buffer = StringBuffer("This is a test of the emergency broadcast system.")) {
         Assert.AreEqual((byte)'T', buffer[0]);
         AlsoAssert.AreEqual(Encoding.UTF8.GetBytes("This is a "), buffer.ConsumeUntil(Encoding.UTF8.GetBytes("test")));
     }
 }
Пример #2
0
 public void TestReadShortString()
 {
     using (var buffer = StringBuffer("This is a test.")) {
         AlsoAssert.AreEqual(Encoding.UTF8.GetBytes("is a"), buffer.Span(5, 4));
         Assert.AreEqual((byte)'T', buffer[0]);
         Assert.AreEqual((byte)'h', buffer[1]);
         AlsoAssert.AreEqual(Encoding.UTF8.GetBytes("This"), buffer.Consume(4));
         Assert.AreEqual((byte)' ', buffer[0]);
     }
 }
Пример #3
0
 public void TestConsumeWhile()
 {
     using (var buffer = StringBuffer("This is a test\nof the emergency broadcast system.")) {
         AlsoAssert.AreEqual(Encoding.UTF8.GetBytes("This is a test"),
                             buffer.ConsumeWhile(c => char.IsLetter((char)c) || c == ' '));
         Assert.AreEqual((byte)'\n', buffer[0]);
     }
     using (var buffer = StringBuffer("This is a test\nof the emergency broadcast system.")) {
         AlsoAssert.AreEqual(Encoding.UTF8.GetBytes("This is a"),
                             buffer.ConsumeWhile(c => char.IsLetter((char)c) || c == ' ', 9));
     }
 }
Пример #4
0
 public void TestEof()
 {
     using (var buffer = StringBuffer("This is a test of the emergency broadcast system.")) {
         AlsoAssert.AreEqual(Encoding.UTF8.GetBytes("This is a test"), buffer.Consume(14));
         Assert.IsFalse(buffer.Eof);
         buffer.Discard(1);
         AlsoAssert.AreEqual(Encoding.UTF8.GetBytes("of"), buffer.Consume(2));
         Assert.IsFalse(buffer.Eof);
         AlsoAssert.AreEqual(Encoding.UTF8.GetBytes(" the emergency broadcast "), buffer.Consume(25));
         Assert.IsFalse(buffer.Eof);
         AlsoAssert.AreEqual(Encoding.UTF8.GetBytes("system."), buffer.Span(7));
         Assert.IsFalse(buffer.Eof);
         AlsoAssert.AreEqual(Encoding.UTF8.GetBytes("system."), buffer.Consume(7));
         Assert.IsTrue(buffer.Eof);
     }
 }
Пример #5
0
 public void TestSpan()
 {
     using (var buffer = StringBuffer("Testing")) {
         AlsoAssert.AreEqual(Encoding.UTF8.GetBytes("stin"), buffer.Span(2, 4));
     }
 }
Пример #6
0
 public void TestConsume()
 {
     using (var buffer = StringBuffer("Testing")) {
         AlsoAssert.AreEqual(Encoding.UTF8.GetBytes("Test"), buffer.Consume(4));
     }
 }