예제 #1
0
        public void ContentAppendedToTemporaryBufferIsCopiedToPreviousBufferWhenAccepted()
        {
            // Arrange
            ParserContext context = SetupTestRun("barbazbiz", b => b.Read());

            context.ContentBuffer.Append("foo");

            // Act
            using (context.StartTemporaryBuffer()) {
                context.ContentBuffer.Append("bar");
                using (context.StartTemporaryBuffer()) {
                    context.ContentBuffer.Append("baz");
                    context.AcceptTemporaryBuffer();
                }
                context.AcceptTemporaryBuffer();
                Assert.IsFalse(context.InTemporaryBuffer);
                Assert.AreEqual("foobarbaz", context.ContentBuffer.ToString());
            }
        }
예제 #2
0
        public void ContentFromAcceptedTemporaryBufferIsNotAffectedByDisposalOfTheTemporaryBuffer()
        {
            // Arrange
            ParserContext context = SetupTestRun("barbazbiz", b => b.Read());

            context.ContentBuffer.Append("foo");

            // Act
            using (context.StartTemporaryBuffer()) {
                context.ContentBuffer.Append("bar");
                context.AcceptTemporaryBuffer();
            }
            Assert.AreEqual("foobar", context.ContentBuffer.ToString());
        }
예제 #3
0
        public void CallingAcceptTemporaryBufferCausesEndOfLookaheadWithNoBacktrack()
        {
            // Arrange
            ParserContext context = SetupTestRun("barbazbiz", r => r.Read());

            // Act
            using (context.StartTemporaryBuffer()) {
                context.Source.Read();
                context.Source.Read();
                context.AcceptTemporaryBuffer();
            }

            // Assert
            Assert.AreEqual('b', context.CurrentCharacter);
        }
예제 #4
0
        public void ContentAppendedToTemporaryBufferIsLostWhenRejectedByExplicitMethod()
        {
            // Arrange
            ParserContext context = SetupTestRun("barbazbiz", b => b.Read());

            context.ContentBuffer.Append("foo");

            // Act
            using (context.StartTemporaryBuffer()) {
                context.ContentBuffer.Append("bar");
                using (context.StartTemporaryBuffer()) {
                    context.ContentBuffer.Append("baz");
                    context.RejectTemporaryBuffer();
                }
                context.AcceptTemporaryBuffer();
                Assert.IsFalse(context.InTemporaryBuffer);
                Assert.AreEqual("foobar", context.ContentBuffer.ToString());
            }
        }