Exemple #1
0
 public ClassifiedSpanBaselineException(ClassifiedSpanInternal span, string expected, string actual, string userMessage)
     : base(Format(span, expected, actual, userMessage))
 {
     Span     = span;
     Expected = expected;
     Actual   = actual;
 }
        public static IReadOnlyList <ClassifiedSpanInternal> GetClassifiedSpans(this RazorSyntaxTree syntaxTree)
        {
            if (syntaxTree == null)
            {
                throw new ArgumentNullException(nameof(syntaxTree));
            }

            var spans = Flatten(syntaxTree);

            var result = new ClassifiedSpanInternal[spans.Count];

            for (var i = 0; i < spans.Count; i++)
            {
                var span = spans[i];
                result[i] = new ClassifiedSpanInternal(
                    new SourceSpan(
                        span.Start.FilePath ?? syntaxTree.Source.FilePath,
                        span.Start.AbsoluteIndex,
                        span.Start.LineIndex,
                        span.Start.CharacterIndex,
                        span.Length),
                    new SourceSpan(
                        span.Parent.Start.FilePath ?? syntaxTree.Source.FilePath,
                        span.Parent.Start.AbsoluteIndex,
                        span.Parent.Start.LineIndex,
                        span.Parent.Start.CharacterIndex,
                        span.Parent.Length),
                    span.Kind,
                    span.Parent.Type,
                    span.EditHandler.AcceptedCharacters);
            }

            return(result);
        }
            public override void VisitClassifiedSpan(ClassifiedSpanInternal span)
            {
                var expected = _index < _baseline.Length ? _baseline[_index++] : null;

                _writer.GetStringBuilder().Clear();
                base.VisitClassifiedSpan(span);
                var actual = _writer.GetStringBuilder().ToString();
                AssertEqual(span, expected, actual);
            }
Exemple #4
0
            private void AssertEqual(ClassifiedSpanInternal span, string expected, string actual)
            {
                if (string.Equals(expected, actual))
                {
                    return;
                }

                if (expected == null)
                {
                    var message = "The span is missing from baseline.";
                    throw new ClassifiedSpanBaselineException(span, expected, actual, message);
                }
                else
                {
                    var message = $"Contents are not equal.";
                    throw new ClassifiedSpanBaselineException(span, expected, actual, message);
                }
            }
Exemple #5
0
                private static string Format(ClassifiedSpanInternal span, string expected, string actual, string userMessage)
                {
                    var builder = new StringBuilder();

                    builder.AppendLine(userMessage);
                    builder.AppendLine();

                    if (expected != null)
                    {
                        builder.Append("Expected: ");
                        builder.AppendLine(expected);
                    }

                    if (actual != null)
                    {
                        builder.Append("Actual: ");
                        builder.AppendLine(actual);
                    }

                    return(builder.ToString());
                }
Exemple #6
0
 protected void WriteClassifiedSpan(ClassifiedSpanInternal span)
 {
     Write($"{span.SpanKind} span at {span.Span} (Accepts:{span.AcceptedCharacters})");
     WriteSeparator();
     Write($"Parent: {span.BlockKind} block at {span.BlockSpan}");
 }
Exemple #7
0
 public virtual void VisitClassifiedSpan(ClassifiedSpanInternal span)
 {
     WriteClassifiedSpan(span);
 }