Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions TUnit.Aspire/AspireFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,13 @@ private async Task WaitForResourcesWithFailFastAsync(

var sb = new StringBuilder();
sb.Append("Resources not ready: [");
sb.Append(string.Join(", ", pending.Select(n => $"'{n}'")));
sb.AppendJoin(", ", pending.Select(n => $"'{n}'"));
sb.Append(']');

if (readySet.Count > 0)
{
sb.Append(". Resources ready: [");
sb.Append(string.Join(", ", readySet.Select(n => $"'{n}'")));
sb.AppendJoin(", ", readySet.Select(n => $"'{n}'"));
sb.Append(']');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ private static void GenerateAssertConditionClassForMethod(SourceProductionContex
// Extension method - call it like an instance method
sourceBuilder.Append($" var result = actualValue.{methodName}(");
var paramList = parameters.Select(p => $"_{p.Name}").ToArray();
sourceBuilder.Append(string.Join(", ", paramList));
sourceBuilder.AppendJoin(", ", paramList);
sourceBuilder.AppendLine(");");
}
else if (attributeData.TreatAsInstance)
Expand Down Expand Up @@ -829,7 +829,7 @@ private static void GenerateAssertConditionClassForMethod(SourceProductionContex
// Instance method on the target type itself
sourceBuilder.Append($" var result = actualValue.{methodName}(");
var paramList = parameters.Select(p => $"_{p.Name}").ToArray();
sourceBuilder.Append(string.Join(", ", paramList));
sourceBuilder.AppendJoin(", ", paramList);
sourceBuilder.AppendLine(");");
}
}
Expand All @@ -854,7 +854,7 @@ private static void GenerateAssertConditionClassForMethod(SourceProductionContex
sourceBuilder.AppendLine($" var instance = new {containingType.ToDisplayString()}();");
sourceBuilder.Append($" var result = instance.{methodName}(");
var paramList = parameters.Select(p => $"_{p.Name}").ToArray();
sourceBuilder.Append(string.Join(", ", paramList));
sourceBuilder.AppendJoin(", ", paramList);
sourceBuilder.AppendLine(");");
}
}
Expand All @@ -863,7 +863,7 @@ private static void GenerateAssertConditionClassForMethod(SourceProductionContex
// Default instance method behavior
sourceBuilder.Append($" var result = actualValue.{methodName}(");
var paramList = parameters.Select(p => $"_{p.Name}").ToArray();
sourceBuilder.Append(string.Join(", ", paramList));
sourceBuilder.AppendJoin(", ", paramList);
sourceBuilder.AppendLine(");");
}
}
Expand Down
6 changes: 3 additions & 3 deletions TUnit.Core.SourceGenerator/CodeGenerationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public static string GenerateAttributeInstantiation(AttributeData attr, Immutabl
}
}

writer.Append(string.Join(", ", argStrings));
writer.AppendJoin(", ", argStrings);
}

writer.Append(")");
Expand All @@ -208,7 +208,7 @@ public static string GenerateAttributeInstantiation(AttributeData attr, Immutabl
{
writer.Append(" { ");
var namedArgs = attr.NamedArguments.Select(na => $"{na.Key} = {TypedConstantParser.GetRawTypedConstantValue(na.Value)}");
writer.Append(string.Join(", ", namedArgs));
writer.AppendJoin(", ", namedArgs);
writer.Append(" }");
}

Expand Down Expand Up @@ -311,7 +311,7 @@ public static string GenerateTestAttributes(IMethodSymbol methodSymbol)
attributeStrings.Add(GenerateAttributeInstantiation(attr));
}

writer.Append(string.Join(", ", attributeStrings));
writer.AppendJoin(", ", attributeStrings);
writer.AppendLine(" },");
}

Expand Down
11 changes: 11 additions & 0 deletions TUnit.Core.SourceGenerator/CodeWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ public ICodeWriter Append(string text)
return this;
}

public ICodeWriter AppendJoin<T>(string separator, IEnumerable<T> values)
{
if (_isNewLine)
{
_builder.Append(GetIndentation(_indentLevel));
_isNewLine = false;
}
_builder.AppendJoin(separator, values);
return this;
}

public int IndentLevel => _indentLevel;

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions TUnit.Core.SourceGenerator/ICodeWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public interface ICodeWriter : IDisposable
/// </summary>
ICodeWriter Append(string text);

/// <summary>
/// Appends the string representation of each element separated by the given separator.
/// </summary>
ICodeWriter AppendJoin<T>(string separator, IEnumerable<T> values);

/// <summary>
/// Appends multiple lines of code.
/// </summary>
Expand Down