Ejemplo n.º 1
1
 protected override void SingleSpanBlockTest(string document, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any)
 {
     SingleSpanBlockTest(document, blockType, spanType, acceptedCharacters, expectedError: null);
 }
Ejemplo n.º 2
0
 private static bool IsValidSpan(TraceSpan span, string name, ulong parentId, SpanKind kind)
 {
     return(span.SpanId != 0 &&
            kind.Convert() == span.Kind &&
            name.Equals(span.Name) &&
            span.StartTime != null &&
            parentId == span.ParentSpanId &&
            span.EndTime != null &&
            span.StartTime.ToDateTime() <= span.EndTime.ToDateTime());
 }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public ISpan StartSpan(string operationName, ISpan parent, SpanKind kind, SpanCreationOptions options)
        {
            if (parent == null)
            {
                parent = this.CurrentSpan;
            }

            return(Span.CreateFromParentSpan(operationName, parent, kind, options, this.sampler, this.tracerConfiguration,
                                             this.spanProcessor, this.LibraryResource));
        }
Ejemplo n.º 4
0
 public SpanConstructor(SpanKind kind, IEnumerable<ISymbol> symbols)
 {
     Builder = new SpanBuilder();
     Builder.Kind = kind;
     Builder.EditHandler = SpanEditHandler.CreateDefault(TestTokenizer);
     foreach (ISymbol sym in symbols)
     {
         Builder.Accept(sym);
     }
 }
Ejemplo n.º 5
0
        protected virtual void SingleSpanDocumentTest(
            string document,
            BlockType blockType,
            SpanKind spanType
            )
        {
            Block b = CreateSimpleBlockAndSpan(document, blockType, spanType);

            ParseDocumentTest(document, b);
        }
Ejemplo n.º 6
0
 public SpanConstructor(SpanKind kind, IEnumerable <ISymbol> symbols)
 {
     Builder             = new SpanBuilder();
     Builder.Kind        = kind;
     Builder.EditHandler = SpanEditHandler.CreateDefault(TestTokenizer);
     foreach (ISymbol sym in symbols)
     {
         Builder.Accept(sym);
     }
 }
Ejemplo n.º 7
0
        private static Span GenerateSpan(
            string text,
            SpanKind spanKind,
            int spanIndex,
            string spanText
            )
        {
            Span[] spans = GenerateSpans(text, spanKind, spanIndex, spanText);

            return(spans[spanIndex]);
        }
Ejemplo n.º 8
0
        private SpanConstructor CreateSymbolSpan(
            SpanKind kind,
            string content,
            Func <SourceLocation, ISymbol> ctor
            )
        {
            SourceLocation start = LocationTracker.CurrentLocation;

            LocationTracker.UpdateLocation(content);
            return(new SpanConstructor(kind, new[] { ctor(start) }));
        }
 internal static JaegerSpan CreateTestJaegerSpan(
     bool setAttributes = true,
     Dictionary <string, object> additionalAttributes = null,
     bool addEvents    = true,
     bool addLinks     = true,
     Resource resource = null,
     SpanKind kind     = SpanKind.Client)
 {
     return(JaegerSpanConverterTest.CreateTestSpan(
                setAttributes, additionalAttributes, addEvents, addLinks, resource, kind).ToJaegerSpan());
 }
Ejemplo n.º 10
0
 public static void IsSpan(
     Span tok,
     SpanKind type,
     string content,
     int actualIndex,
     int lineIndex,
     int charIndex
     )
 {
     IsSpan(tok, type, content, new SourceLocation(actualIndex, lineIndex, charIndex));
 }
Ejemplo n.º 11
0
        private Span(
            string name,
            SpanContext parentSpanContext,
            ActivityAndTracestate activityAndTracestate,
            bool ownsActivity,
            SpanKind spanKind,
            DateTimeOffset startTimestamp,
            IEnumerable <Link> links,
            TracerConfiguration tracerConfiguration,
            SpanProcessor spanProcessor,
            Resource libraryResource)
        {
            this.Name                = name;
            this.LibraryResource     = libraryResource;
            this.startTimestamp      = startTimestamp;
            this.tracerConfiguration = tracerConfiguration;
            this.spanProcessor       = spanProcessor;
            this.Kind                = spanKind;
            this.OwnsActivity        = ownsActivity;
            this.Activity            = activityAndTracestate.Activity;

            var tracestate = activityAndTracestate.Tracestate;

            this.IsRecordingEvents = MakeSamplingDecision(
                parentSpanContext,
                name,
                null,
                links, // we'll enumerate again, but double enumeration over small collection is cheaper than allocation
                this.Activity.TraceId,
                this.Activity.SpanId,
                this.tracerConfiguration);

            if (this.IsRecordingEvents)
            {
                this.Activity.ActivityTraceFlags |= ActivityTraceFlags.Recorded;

                if (links != null)
                {
                    foreach (var link in links)
                    {
                        this.AddLink(link);
                    }
                }

                this.spanProcessor.OnStart(this);
            }
            else
            {
                this.Activity.ActivityTraceFlags &= ~ActivityTraceFlags.Recorded;
            }

            this.Context = new SpanContext(this.Activity.TraceId, this.Activity.SpanId, this.Activity.ActivityTraceFlags, tracestate);
        }
Ejemplo n.º 12
0
 protected ApplicationInsightsSpan(ApplicationInsightsTracer tracer,
                                   IApplicationInsightsSpanContext typedContext,
                                   string operationName, DateTimeOffset start, SpanKind spanKind,
                                   Endpoint localEndpoint = null, Dictionary <string, string> tagsActual = null)
 {
     TypedContext  = typedContext;
     SpanKind      = spanKind;
     OperationName = operationName;
     Started       = start;
     LocalEndpoint = localEndpoint;
     Tracer        = tracer;
 }
Ejemplo n.º 13
0
        public static SpanData CreateSpanData(string name,
                                              SpanContext parentContext,
                                              SpanKind kind,
                                              DateTimeOffset startTimestamp,
                                              IEnumerable <Link> links,
                                              IDictionary <string, object> attributes,
                                              IEnumerable <Event> events,
                                              Status status,
                                              DateTimeOffset endTimestamp)
        {
            var processor = new Mock <SpanProcessor>();

            processor.Setup(p => p.OnEnd(It.IsAny <SpanData>()));

            var tracer = TracerFactory.Create(b =>
                                              b.AddProcessorPipeline(p =>
                                                                     p.AddProcessor(_ => processor.Object)))
                         .GetTracer(null);

            SpanCreationOptions spanOptions = null;

            if (links != null || attributes != null || startTimestamp != default)
            {
                spanOptions = new SpanCreationOptions
                {
                    Links          = links,
                    Attributes     = attributes,
                    StartTimestamp = startTimestamp,
                };
            }
            var span = tracer.StartSpan(name, parentContext, kind, spanOptions);

            if (events != null)
            {
                foreach (var evnt in events)
                {
                    span.AddEvent(evnt);
                }
            }

            span.Status = status.IsValid ? status : Status.Ok;

            if (endTimestamp == default)
            {
                span.End();
            }
            else
            {
                span.End(endTimestamp);
            }

            return((SpanData)processor.Invocations[0].Arguments[0]);
        }
Ejemplo n.º 14
0
        public AreaContainer getNextArea(FObj fo)
        {
            _isNewSpanArea = false;

            SpanKind span = SpanKind.NONE;

            if (fo is Block)
            {
                span = ((Block)fo).GetSpan();
            }
            else if (fo is BlockContainer)
            {
                span = ((BlockContainer)fo).GetSpan();
            }

            if (this.mainReferenceArea.getChildren().Count == 0)
            {
                if (span == SpanKind.ALL)
                {
                    return(addSpanArea(1));
                }
                else
                {
                    return(addSpanArea(columnCount));
                }
            }

            ArrayList spanAreas = this.mainReferenceArea.getChildren();
            SpanArea  spanArea  = (SpanArea)spanAreas[spanAreas.Count - 1];

            if ((span == SpanKind.ALL) && (spanArea.getColumnCount() == 1))
            {
                return(spanArea.getCurrentColumnArea());
            }
            else if ((span == SpanKind.NONE) &&
                     (spanArea.getColumnCount() == columnCount))
            {
                return(spanArea.getCurrentColumnArea());
            }
            else if (span == SpanKind.ALL)
            {
                return(addSpanArea(1));
            }
            else if (span == SpanKind.NONE)
            {
                return(addSpanArea(columnCount));
            }
            else
            {
                throw new FonetException("BodyAreaContainer::getNextArea(): Span attribute messed up");
            }
        }
Ejemplo n.º 15
0
        public SpanBuilder(ITracer tracer, string operationName, string logKey = null, SpanKind kind = SpanKind.Internal, ISpan parent = null)
        {
            EnsureArg.IsNotNull(tracer, nameof(tracer));
            EnsureArg.IsNotNullOrEmpty(operationName, nameof(operationName));

            this.tracer        = tracer;
            this.traceId       = parent?.TraceId;
            this.operationName = operationName;
            this.logKey        = logKey ?? LogKeys.Tracing;
            this.kind          = kind;
            this.parent        = parent;
            // TODO: copy baggage items from parent
        }
Ejemplo n.º 16
0
        public RequestSpan(ApplicationInsightsTracer tracer, IApplicationInsightsSpanContext typedContext,
                           string operationName, DateTimeOffset start, SpanKind spanKind, Endpoint localEndpoint = null,
                           Dictionary <string, string> tagsActual = null) : base(tracer, typedContext, operationName, start, spanKind,
                                                                                 localEndpoint, tagsActual)
        {
            var telemetry = new RequestTelemetry {
                Id = typedContext.SpanId, Name = operationName
            };

            InitializeTelemetry(typedContext, localEndpoint, tagsActual, telemetry);

            _operation = Tracer.Client.StartOperation(telemetry);
        }
Ejemplo n.º 17
0
        private void CompleteTagBlockWithSpan(IDisposable tagBlockWrapper,
                                              AcceptedCharacters acceptedCharacters,
                                              SpanKind spanKind)
        {
            Debug.Assert(tagBlockWrapper != null,
                         "Tag block wrapper should not be null when attempting to complete a block");

            Span.EditHandler.AcceptedCharacters = acceptedCharacters;
            // Write out the current span into the block before closing it.
            Output(spanKind);
            // Finish the tag block
            tagBlockWrapper.Dispose();
        }
Ejemplo n.º 18
0
        private void ExtractGenericProperties(ISpanData span, out SpanKind resultKind, out DateTimeOffset timestamp, out string name, out string resultCode, out IDictionary <string, string> props, out string traceId, out string spanId, out string parentId, out Tracestate tracestate, out bool?success, out TimeSpan duration)
        {
            resultKind = span.Kind;

            // TODO: Should this be a part of generic logic?
            if (resultKind == SpanKind.Internal)
            {
                if (span.HasRemoteParent.HasValue && span.HasRemoteParent.Value)
                {
                    resultKind = SpanKind.Server;
                }
                else
                {
                    resultKind = SpanKind.Client;
                }
            }

            // 1 tick is 100 ns
            timestamp = DateTimeOffset.FromUnixTimeSeconds(span.StartTimestamp.Seconds);
            timestamp = timestamp.Add(TimeSpan.FromTicks(span.StartTimestamp.Nanos / 100));

            name = span.Name;

            props = new Dictionary <string, string>();

            traceId  = span.Context.TraceId.ToLowerBase16();
            spanId   = span.Context.SpanId.ToLowerBase16();
            parentId = null;
            if (span.ParentSpanId != null && span.ParentSpanId.IsValid)
            {
                parentId = span.ParentSpanId.ToLowerBase16();
            }

            resultCode = null;
            success    = null;
            if (span.Status != null)
            {
                resultCode = ((int)span.Status.CanonicalCode).ToString();
                success    = span.Status.IsOk;
                if (!string.IsNullOrEmpty(span.Status.Description))
                {
                    props["statusDescription"] = span.Status.Description;
                }
            }

            tracestate = span.Context.Tracestate;

            var durationTs = span.EndTimestamp.SubtractTimestamp(span.StartTimestamp);

            duration = TimeSpan.FromTicks((durationTs.Seconds * TimeSpan.TicksPerSecond) + (durationTs.Nanos / 100));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Converts a <see cref="SpanKind"/> to a <see cref="TraceSpan.Types.SpanKind"/>.
        /// </summary>
        internal static TraceSpan.Types.SpanKind Convert(this SpanKind kind)
        {
            switch (kind)
            {
            case SpanKind.RpcClient:
                return(TraceSpan.Types.SpanKind.RpcClient);

            case SpanKind.RpcServer:
                return(TraceSpan.Types.SpanKind.RpcServer);

            default:
                return(TraceSpan.Types.SpanKind.Unspecified);
            }
        }
Ejemplo n.º 20
0
        /// <inheritdoc/>
        public ISpan StartRootSpan(string operationName, SpanKind kind, DateTimeOffset startTimestamp, IEnumerable <Link> links)
        {
            if (operationName == null)
            {
                throw new ArgumentNullException(nameof(operationName));
            }

            if (startTimestamp == default)
            {
                startTimestamp = PreciseTimestamp.GetUtcNow();
            }

            return(Span.CreateRoot(operationName, kind, startTimestamp, links, this.tracerConfiguration, this.spanProcessor, this.LibraryResource));
        }
Ejemplo n.º 21
0
 protected override void SingleSpanBlockTest(
     string document,
     BlockType blockType,
     SpanKind spanType,
     AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any
     )
 {
     SingleSpanBlockTest(
         document,
         blockType,
         spanType,
         acceptedCharacters,
         expectedError: null
         );
 }
Ejemplo n.º 22
0
 public ISpanBuilder BuildSpan(
     string operationName,
     string logKey          = null,
     SpanKind kind          = SpanKind.Internal,
     ISpan parent           = null,
     bool ignoreCurrentSpan = false)
 {
     return(new SpanBuilder(
                this,
                operationName,
                logKey ?? this.CurrentSpan.LogKey ?? LogKeys.Tracing,
                kind,
                parent == null && ignoreCurrentSpan ? null : parent ?? this.CurrentSpan)
            .WithTag(SpanTagKey.SpanKind, kind.ToString())); // pass correlationid as traceid
 }
Ejemplo n.º 23
0
        public bool isBalancingRequired(FObj fo)
        {
            if (this.mainReferenceArea.getChildren().Count == 0)
            {
                return(false);
            }

            ArrayList spanAreas = this.mainReferenceArea.getChildren();
            SpanArea  spanArea  = (SpanArea)spanAreas[spanAreas.Count - 1];

            if (spanArea.isBalanced())
            {
                return(false);
            }

            SpanKind span = SpanKind.NONE;

            if (fo is Block)
            {
                span = ((Block)fo).GetSpan();
            }
            else if (fo is BlockContainer)
            {
                span = ((BlockContainer)fo).GetSpan();
            }

            if ((span == SpanKind.ALL) && (spanArea.getColumnCount() == 1))
            {
                return(false);
            }
            else if ((span == SpanKind.NONE) &&
                     (spanArea.getColumnCount() == columnCount))
            {
                return(false);
            }
            else if (span == SpanKind.ALL)
            {
                return(true);
            }
            else if (span == SpanKind.NONE)
            {
                return(false);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 24
0
            internal int flags = 0; // bit field for timestamp and duration

            public Builder Reset()
            {
                traceId        = null;
                parentId       = null;
                id             = null;
                kind           = default(SpanKind);
                name           = null;
                timestamp      = 0L;
                duration       = 0L;
                localEndpoint  = default(Endpoint);
                remoteEndpoint = default(Endpoint);
                annotations?.Clear();
                tags?.Clear();
                flags = 0;
                return(this);
            }
Ejemplo n.º 25
0
 public static void NextSpanIs(
     IEnumerator <Span> enumerator,
     SpanKind type,
     string content,
     int actualIndex,
     int lineIndex,
     int charIndex
     )
 {
     NextSpanIs(
         enumerator,
         type,
         content,
         new SourceLocation(actualIndex, lineIndex, charIndex)
         );
 }
Ejemplo n.º 26
0
 protected override void SingleSpanBlockTest(
     string document,
     BlockType blockType,
     SpanKind spanType,
     AcceptedCharacters acceptedCharacters,
     params RazorError[] expectedError
     )
 {
     SingleSpanBlockTest(
         document,
         document,
         blockType,
         spanType,
         acceptedCharacters,
         expectedError
         );
 }
Ejemplo n.º 27
0
 protected override void SingleSpanBlockTest(
     string document,
     string spanContent,
     BlockType blockType,
     SpanKind spanType,
     params RazorError[] expectedErrors
     )
 {
     SingleSpanBlockTest(
         document,
         spanContent,
         blockType,
         spanType,
         AcceptedCharacters.Any,
         expectedErrors ?? new RazorError[0]
         );
 }
Ejemplo n.º 28
0
        public bool IsAllowedTime(SpanKind kind)
        {
            switch (kind)
            {
            case SpanKind.Unknown:
                throw new NotSupportedException();

            case SpanKind.Account:
                return(IsInRange(From, ToAccountDisable));

            case SpanKind.Shutdown:
                return(IsInRange(From, ToShutdown));

            default:
                throw new ArgumentOutOfRangeException("kind");
            }
        }
Ejemplo n.º 29
0
        private void OverwriteSpanKindFromAttribute(IAttributeValue spanKindAttr, ref SpanKind resultKind)
        {
            // override span kind with attribute named span.kind
            if (spanKindAttr != null)
            {
                var kind = spanKindAttr.Match((s) => s, null, null, null, null);

                if (kind == "server")
                {
                    resultKind = SpanKind.Server;
                }
                else
                {
                    resultKind = SpanKind.Client;
                }
            }
        }
Ejemplo n.º 30
0
        protected virtual Block CreateSimpleBlockAndSpan(
            string spanContent,
            BlockType blockType,
            SpanKind spanType,
            AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any
            )
        {
            SpanConstructor span = Factory
                                   .Span(spanType, spanContent, spanType == SpanKind.Markup)
                                   .Accepts(acceptedCharacters);
            BlockBuilder b = new BlockBuilder()
            {
                Type = blockType
            };

            return(ConfigureAndAddSpanToBlock(b, span));
        }
Ejemplo n.º 31
0
 protected virtual void SingleSpanBlockTest(
     string document,
     string spanContent,
     BlockType blockType,
     SpanKind spanType,
     AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any
     )
 {
     SingleSpanBlockTest(
         document,
         spanContent,
         blockType,
         spanType,
         acceptedCharacters,
         expectedErrors: null
         );
 }
Ejemplo n.º 32
0
        protected override void SingleSpanBlockTest(
            string document,
            string spanContent,
            BlockType blockType,
            SpanKind spanType,
            AcceptedCharacters acceptedCharacters,
            params RazorError[] expectedErrors
            )
        {
            Block b = CreateSimpleBlockAndSpan(
                spanContent,
                blockType,
                spanType,
                acceptedCharacters
                );

            ParseBlockTest(document, b, expectedErrors ?? new RazorError[0]);
        }
Ejemplo n.º 33
0
		public Span Span(SpanKind kind, params ISymbol[] symbols)
		{
			var builder = new SpanBuilder();
			builder.Kind = kind;

			foreach (var symbol in symbols)
			{
				builder.Accept(symbol);
			}

			var span = builder.Build();
			if (_last != null)
			{
				span.Previous = _last;
				_last.Next = span;
			}
			_last = span;

			return span;
		}
Ejemplo n.º 34
0
 internal virtual void SingleSpanDocumentTest(string document, BlockType blockType, SpanKind spanType) {
     ParseDocumentTest(document, new Block(blockType, new[] { new TestSimpleSpan(spanType, document) }));
 }
Ejemplo n.º 35
0
 protected virtual void SingleSpanBlockTest(string document, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters, params RazorError[] expectedError)
 {
     SingleSpanBlockTest(document, document, blockType, spanType, acceptedCharacters, expectedError);
 }
Ejemplo n.º 36
0
 protected Span(SpanKind kind, SourceLocation start, string content, bool hidden, AcceptedCharacters acceptedCharacters)
     : this(kind, content, hidden, acceptedCharacters) {
     _start = start;
 }
Ejemplo n.º 37
0
 public TestSimpleSpan(SpanKind kind, string content, AcceptedCharacters acceptedCharacters) : base(kind, content, hidden: false, acceptedCharacters: acceptedCharacters) { }
Ejemplo n.º 38
0
 protected virtual Block CreateSimpleBlockAndSpan(string spanContent, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any)
 {
     var span = Factory.Span(spanType, spanContent, spanType == SpanKind.Markup).Accepts(acceptedCharacters);
     var b = new BlockBuilder()
     {
         Type = blockType
     };
     return ConfigureAndAddSpanToBlock(b, span);
 }
Ejemplo n.º 39
0
 public TestSimpleSpan(SpanKind kind, string content) : base(kind, content) { }
Ejemplo n.º 40
0
 public SpanConstructor Span(SpanKind kind, params ISymbol[] symbols)
 {
     return new SpanConstructor(kind, symbols);
 }
Ejemplo n.º 41
0
        private static Span GenerateSpan(string text, SpanKind spanKind, int spanIndex, string spanText)
        {
            Span[] spans = GenerateSpans(text, spanKind, spanIndex, spanText);

            return spans[spanIndex];
        }
Ejemplo n.º 42
0
 public SpanConstructor Span(SpanKind kind, string content, HtmlSymbolType type)
 {
     return CreateSymbolSpan(kind, content, st => new HtmlSymbol(st, content, type));
 }
Ejemplo n.º 43
0
 protected Span(ParserContext context, SpanKind kind, bool hidden) : this(kind, context.CurrentSpanStart, context.ContentBuffer.ToString(), hidden) { }
Ejemplo n.º 44
0
        private void CompleteTagBlockWithSpan(IDisposable tagBlockWrapper,
                                              AcceptedCharacters acceptedCharacters,
                                              SpanKind spanKind)
        {
            Debug.Assert(tagBlockWrapper != null,
                "Tag block wrapper should not be null when attempting to complete a block");

            Span.EditHandler.AcceptedCharacters = acceptedCharacters;
            // Write out the current span into the block before closing it.
            Output(spanKind);
            // Finish the tag block
            tagBlockWrapper.Dispose();
        }
Ejemplo n.º 45
0
 protected override void SingleSpanBlockTest(string document, string spanContent, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters, params RazorError[] expectedErrors)
 {
     var b = CreateSimpleBlockAndSpan(spanContent, blockType, spanType, acceptedCharacters);
     ParseBlockTest(document, b, expectedErrors ?? new RazorError[0]);
 }
Ejemplo n.º 46
0
 /// <summary>
 /// Test span to simplify the generation of the actual Span in test initializer.
 /// </summary>
 /// <param name="kind">Span kind</param>
 /// <param name="start">Zero indexed start char index in the buffer.</param>
 /// <param name="end">End Column, if the text length is zero Start == End.</param>
 public TestSpan(SpanKind kind, int start, int end)
 {
     Kind = kind;
     Start = start;
     End = end;
 }
Ejemplo n.º 47
0
 public SpanConstructor Span(SpanKind kind, string[] content, bool markup)
 {
     return new SpanConstructor(kind, Tokenize(content, markup));
 }
Ejemplo n.º 48
0
 protected Span(SpanKind kind, SourceLocation start, string content, bool hidden)
     : this(kind, content, hidden) {
     _start = start;
 }
Ejemplo n.º 49
0
 private SpanConstructor CreateSymbolSpan(SpanKind kind, string content, Func<SourceLocation, ISymbol> ctor)
 {
     var start = LocationTracker.CurrentLocation;
     LocationTracker.UpdateLocation(content);
     return new SpanConstructor(kind, new[] { ctor(start) });
 }
Ejemplo n.º 50
0
 protected virtual void SingleSpanDocumentTest(string document, BlockType blockType, SpanKind spanType)
 {
     Block b = CreateSimpleBlockAndSpan(document, blockType, spanType);
     ParseDocumentTest(document, b);
 }
Ejemplo n.º 51
0
        private static Span[] GenerateSpans(string text, SpanKind spanKind, int spanIndex, string spanText)
        {
            Assert.True(spanIndex > 0);

            RazorParser parser = new RazorParser(new CSharpCodeParser(), new HtmlMarkupParser());

            Span[] spans;

            using (var reader = new StringReader(text))
            {
                ParserResults results = parser.Parse(reader);
                spans = results.Document.Flatten().ToArray();
            }

            Assert.True(spans.Length > spanIndex);
            Assert.Equal(spanKind, spans[spanIndex].Kind);
            Assert.Equal(spanText, spans[spanIndex].Content);

            return spans;
        }
Ejemplo n.º 52
0
 protected Span(ParserContext context, SpanKind kind, bool hidden, AcceptedCharacters acceptedCharacters) : this(kind, context.CurrentSpanStart, context.ContentBuffer.ToString(), hidden, acceptedCharacters) { }
Ejemplo n.º 53
0
 protected override void SingleSpanBlockTest(string document, BlockType blockType, SpanKind spanType, params RazorError[] expectedError)
 {
     SingleSpanBlockTest(document, document, blockType, spanType, expectedError);
 }
Ejemplo n.º 54
0
 protected Span(SpanKind kind, SourceLocation start, string content)
     : this(kind, content) {
     _start = start;
 }
Ejemplo n.º 55
0
 protected virtual void SingleSpanBlockTest(string document, string spanContent, BlockType blockType, SpanKind spanType, params RazorError[] expectedErrors)
 {
     SingleSpanBlockTest(document, spanContent, blockType, spanType, AcceptedCharacters.Any, expectedErrors ?? new RazorError[0]);
 }
Ejemplo n.º 56
0
 // For parser unit tests, where start point is calculated
 internal NamespaceImportSpan(SpanKind kind, string content, AcceptedCharacters acceptedCharacters, string ns, int namespaceKeywordLength)
     : base(kind, content, hidden: false, acceptedCharacters: acceptedCharacters) {
     Namespace = ns;
     NamespaceKeywordLength = namespaceKeywordLength;
 }
Ejemplo n.º 57
0
 protected virtual void SingleSpanBlockTest(string document, string spanContent, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters, params RazorError[] expectedErrors)
 {
     var builder = new BlockBuilder();
     builder.Type = blockType;
     ParseBlockTest(
         document,
         ConfigureAndAddSpanToBlock(
             builder,
             Factory.Span(spanType, spanContent, spanType == SpanKind.Markup)
                    .Accepts(acceptedCharacters)),
         expectedErrors ?? new RazorError[0]);
 }
Ejemplo n.º 58
0
 public NamespaceImportSpan(SpanKind kind, SourceLocation start, string content, AcceptedCharacters acceptedCharacters, string ns, int namespaceKeywordLength)
     : base(kind, start, content, hidden: false, acceptedCharacters: acceptedCharacters) {
     Namespace = ns;
     NamespaceKeywordLength = namespaceKeywordLength;
 }
Ejemplo n.º 59
0
 protected virtual void SingleSpanBlockTest(string document, string spanContent, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any)
 {
     SingleSpanBlockTest(document, spanContent, blockType, spanType, acceptedCharacters, expectedErrors: null);
 }
Ejemplo n.º 60
0
 public static NamespaceImportSpan Create(ParserContext context, AcceptedCharacters acceptedCharacters, SpanKind kind, string ns, int namespaceKeywordLength) {
     return new NamespaceImportSpan(kind, context.CurrentSpanStart, context.ContentBuffer.ToString(), acceptedCharacters, ns, namespaceKeywordLength);
 }