Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Reduce tracing #230

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/Sep.Test/Internals/InterpolatedStringHandlerRow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -28,29 +29,30 @@ public void set_Item2(string index, [InterpolatedStringHandlerArgument("")] ref
[InterpolatedStringHandler]
public ref struct TraceInterpolatedStringHandler
{
static readonly Action<string> Log = t => { };
// Storage for the built-up string
readonly StringBuilder _builder;

public TraceInterpolatedStringHandler(int literalLength, int formattedCount)
{
_builder = new StringBuilder(literalLength);
Trace.WriteLine($"\tliteral length: {literalLength}, formattedCount: {formattedCount}");
Log($"\tliteral length: {literalLength}, formattedCount: {formattedCount}");
}

public TraceInterpolatedStringHandler(int literalLength, int formattedCount, InterpolatedStringHandlerRow row)
{
Contract.Assume(row is not null);
row._stringBuilder.Clear();
_builder = row._stringBuilder;
Trace.WriteLine($"\tliteral length: {literalLength}, formattedCount: {formattedCount} REUSE");
Log($"\tliteral length: {literalLength}, formattedCount: {formattedCount} REUSE");
}

public void AppendLiteral(string s)
{
Trace.WriteLine($"\tAppendLiteral called: {{{s}}}");
Log($"\tAppendLiteral called: {{{s}}}");

_builder.Append(s);
Trace.WriteLine($"\tAppended the literal string");
Log($"\tAppended the literal string");
}

public void AppendFormatted<T>(T t)
Expand Down
6 changes: 3 additions & 3 deletions src/Sep.Test/SepParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public void SepParserTest_ParseColEnds_NewLinesOnly(object parserObject)
_chars.AsSpan(0, charsEnd).Fill('\n');
_state._currentRowColCount = 0;
var parsedRowsLength = _state._parsedRows.Length;
Trace.WriteLine($"{nameof(parsedRowsLength)} {parsedRowsLength} {nameof(charsEnd)} {charsEnd}");

var rowCount = Math.Min(charsEnd, parsedRowsLength);
var charsStart = 0;
var lineNumberOffset = 4;
Expand Down Expand Up @@ -331,7 +331,8 @@ void AssertOutput(ISepParser parser, int charsStart, int charsEnd, ExpectedOutpu
Assert.AreEqual(expectedParsingRow.ColCount, s._parsingRowColCount, nameof(s._parsingRowColCount));
}

int TraceParseState(SepReaderState s)
[Conditional("SEPREADERTRACE")]
void TraceParseState(SepReaderState s)
{
var sb = new StringBuilder();
var indent = " ";
Expand All @@ -347,7 +348,6 @@ int TraceParseState(SepReaderState s)
var colEndsParsing = _colEndsOrColInfos.AsSpan().Slice(colEndsFrom, s._parsingRowColCount + 1);
sb.AppendLine($"{indent}}}, new({nameof(ExpectedParsingRow.ColEnds)}: new[]{{ {string.Join(", ", colEndsParsing.ToArray())} }}, {nameof(ExpectedParsingRow.LineNumberTo)}: {s._parsingLineNumber}, {nameof(ExpectedParsingRow.CharsStartIndex)}: {s._parsingRowCharsStartIndex}, {nameof(ExpectedParsingRow.ColEndsStartIndex)}: {s._parsingRowColEndsOrInfosStartIndex}, {nameof(ExpectedParsingRow.ColCount)}: {s._parsingRowColCount}));");
Trace.WriteLine(sb.ToString());
return colEndsFrom;
}

static void AreEqual(ReadOnlySpan<int> expected, int[] actual, int actualFrom, int actualTo)
Expand Down
Loading