public void Root_returns_the_outermost_parent_span() { var inner = new ContainerSpan(); var root = new ContainerSpan(new ContainerSpan(new ContainerSpan(inner))); inner.Root.Should().BeSameAs(root); }
public virtual void VisitContainerSpan(ContainerSpan containerSpan) { foreach (var span in containerSpan) { VisitInternal(span); } }
public void SpanVisitor_visits_child_spans_in_depth_first_order() { var outerContainer = new ContainerSpan( BackgroundColorSpan.Green(), new ContainerSpan( ForegroundColorSpan.Red(), new ContentSpan("the content"), ForegroundColorSpan.Reset()), BackgroundColorSpan.Reset()); var visitor = new RecordingSpanVisitor(); visitor.Visit(outerContainer); visitor.VisitedSpans .Select(s => s.GetType()) .Should() .BeEquivalentSequenceTo( typeof(ContainerSpan), typeof(BackgroundColorSpan), typeof(ContainerSpan), typeof(ForegroundColorSpan), typeof(ContentSpan), typeof(ForegroundColorSpan), typeof(BackgroundColorSpan)); }
public void RenderToRegion( Span span, Region region) { if (region == null) { throw new ArgumentNullException(nameof(region)); } if (span == null) { span = Span.Empty(); } else if (_resetAfterRender) { span = new ContainerSpan( span, ForegroundColorSpan.Reset(), BackgroundColorSpan.Reset()); } SpanVisitor visitor = null; if (_mode == OutputMode.Auto) { _mode = _terminal?.DetectOutputMode() ?? OutputMode.PlainText; } switch (_mode) { case OutputMode.NonAnsi: visitor = new NonAnsiRenderingSpanVisitor( _terminal, region); break; case OutputMode.Ansi: visitor = new AnsiRenderingSpanVisitor( _console, region); break; case OutputMode.PlainText: visitor = new FileRenderingSpanVisitor( _console.Out, new Region(region.Left, region.Top, region.Width, region.Height, false)); break; default: throw new NotSupportedException(); } visitor.Visit(span); }
public void Container_span_supports_add_string_method() { var span = new ContainerSpan(new ContentSpan("content")); span.Add(" with string"); span.ContentLength.Should().Be("content with string".Length); }
public void When_spans_are_nested_then_content_length_can_be_calculated() { var span = new ContainerSpan( ForegroundColorSpan.Red(), new ContentSpan("content"), ForegroundColorSpan.Reset()); span.ContentLength.Should().Be("content".Length); }
public void Initialize_is_only_called_once() { var span = new ContainerSpan( new ContainerSpan(new ContainerSpan()), new ContentSpan("hello") ); var visitor = new TestVisitor(); visitor.Visit(span); visitor.InitializeCount.Should().Be(1); }
public void Spans_have_a_start_relative_to_the_parent_span() { var span = new ContainerSpan( ForegroundColorSpan.Red(), new ContentSpan("first"), ForegroundColorSpan.Blue(), new ContentSpan("second"), ForegroundColorSpan.Reset()); span[0].Start.Should().Be(0); span[1].Start.Should().Be(0); span[2].Start.Should().Be("first".Length); span[3].Start.Should().Be("first".Length); span[4].Start.Should().Be("firstsecond".Length); }
public void RenderToRegion( Span span, Region region) { SpanVisitor visitor; if (span == null) { span = Span.Empty(); } else if (_resetAfterRender) { span = new ContainerSpan( span, ForegroundColorSpan.Reset(), BackgroundColorSpan.Reset()); } switch (Mode) { case OutputMode.NonAnsi: visitor = new NonAnsiRenderingSpanVisitor( _terminal, region); break; case OutputMode.Ansi: visitor = new AnsiRenderingSpanVisitor( _console, region); break; case OutputMode.File: visitor = new FileRenderingSpanVisitor( _console.Out, new Region(region.Left, region.Top, region.Width, region.Height, false)); break; default: throw new NotSupportedException(); } visitor.Visit(span); }
public async ValueTask WriteResultsFooter(FinalResults finalResults) { var stats = finalResults.ResultStatistics; var performance = stats.TotalSuccesses / (double)stats.TotalResults; var resultSpan = performance.ToString("P").StyleGrade(performance, new Interval(0, 100, Topology.Inclusive)); var finalMessage = new ContainerSpan( NewLine, "Finished.".StyleUnderline(), NewLine, "Final results:".AsTextSpan(), NewLine, FormatStat("Successes", stats.TotalSuccesses.ToString().StyleSuccess()), FormatStat("Failures", stats.TotalFailures.ToString().StyleFailure()), FormatStat("Errors", stats.TotalErrors.ToString().StyleFailure()), FormatStat("Total", resultSpan), FormatStat("Elapsed", finalResults.TimeTaken.ToString().StyleNumber()) ); console.WriteLine(finalMessage); foreach (var(suiteName, suite) in finalResults.Config.TestSuites) { console.WriteLine($"Results for suite {suiteName.StyleBold()}:".StyleUnderline()); foreach (var(toolName, _) in suite.ToolConfigs) { var processingErrors = stats.ProcessingErrors.Find(suiteName, toolName); if (processingErrors.Case is int i && i > 0) { console.WriteLine(new ContainerSpan( i.ToString().StyleFailure(), " errors were encountered while running ".AsTextSpan(), toolName.StyleValue(), NewLine )); } foreach (var type in ResultsStatistics.Keys) { var summary = stats.Stats.Find(suiteName, toolName, type); console.WriteLine(summary.Case switch { BinaryStatistics b => FormatStatistics($"Summary for {suiteName}, {toolName}, {type}-level", type, b), _ => $"No summary statistics found for {suiteName}, {toolName}, {type}-level".AsTextSpan() });
public void Span_starts_update_when_parent_is_added_to_another_parent_span() { var innerContainerSpan = new ContainerSpan( ForegroundColorSpan.Red(), new ContentSpan("second"), ForegroundColorSpan.Blue(), new ContentSpan("third"), ForegroundColorSpan.Reset() ); var outerContainer = new ContainerSpan(new ContentSpan("first"), innerContainerSpan); innerContainerSpan[0].Start.Should().Be("first".Length); innerContainerSpan[1].Start.Should().Be("first".Length); innerContainerSpan[2].Start.Should().Be("firstsecond".Length); innerContainerSpan[3].Start.Should().Be("firstsecond".Length); innerContainerSpan[4].Start.Should().Be("firstsecondthird".Length); }
public override void VisitContainerSpan(ContainerSpan span) { VisitedSpans.Add(span); base.VisitContainerSpan(span); }
internal virtual void RecalculatePositions(ContainerSpan parent, int start) { Parent = parent; _root = parent.Root; Start = start; }