Example #1
0
        protected CodeBlockInfo ParseBlockStart(bool isTopLevel, bool captureTransition)
        {
            // Capture the transition token, if any, into a span
            Span transitionSpan = null;

            if (HaveContent && captureTransition)
            {
                transitionSpan = TransitionSpan.Create(Context, hidden: false, acceptedCharacters: AcceptedCharacters.None);
                Context.ResetBuffers();
            }

            SourceLocation start      = CurrentLocation;
            string         identifier = Context.AcceptIdentifier();

            Span initialSpan = null;

            if (isTopLevel)
            {
                initialSpan = CodeSpan.Create(Context);
                Context.ResetBuffers();
            }

            CodeBlockInfo block = new CodeBlockInfo(identifier, start, isTopLevel, transitionSpan, initialSpan);

            return(block);
        }
        public void OutputSpanSignalsNewSpanWithStartPointAndContentFromBuffersAndSpecifiedSpanType()
        {
            // Arrange
            Mock <ParserVisitor> mockListener = new Mock <ParserVisitor>();
            ParserContext        context      = SetupTestRun("phoo", mockListener.Object);
            Span actualSpan = null;

            using (context.StartBlock(BlockType.Functions, outputCurrentBufferAsTransition: true)) {
                context.ContentBuffer.Append(context.Source.ReadToEnd());

                mockListener.Setup(l => l.VisitSpan(It.IsAny <Span>()))
                .Callback <Span>(s => actualSpan = s);

                // Act
                context.OutputSpan(CodeSpan.Create(context));
            }

            // Assert
            EventAssert.IsSpan(actualSpan, SpanKind.Code, "phoo", new SourceLocation(0, 0, 0));
        }