diff --git a/src/Zomp.SyncMethodGenerator/AnalyzerReleases.Unshipped.md b/src/Zomp.SyncMethodGenerator/AnalyzerReleases.Unshipped.md index 1b8ee08..c57a9b8 100644 --- a/src/Zomp.SyncMethodGenerator/AnalyzerReleases.Unshipped.md +++ b/src/Zomp.SyncMethodGenerator/AnalyzerReleases.Unshipped.md @@ -8,3 +8,5 @@ Rule ID | Category | Severity | Notes ZSMGEN001 | Preprocessor | Error | DiagnosticMessages ZSMGEN002 | Preprocessor | Error | DiagnosticMessages ZSMGEN003 | Preprocessor | Error | DiagnosticMessages +ZSMGEN004 | Preprocessor | Error | DiagnosticMessages +ZSMGEN005 | Preprocessor | Error | DiagnosticMessages diff --git a/src/Zomp.SyncMethodGenerator/AsyncToSyncRewriter.cs b/src/Zomp.SyncMethodGenerator/AsyncToSyncRewriter.cs index d937ca8..d27ef32 100644 --- a/src/Zomp.SyncMethodGenerator/AsyncToSyncRewriter.cs +++ b/src/Zomp.SyncMethodGenerator/AsyncToSyncRewriter.cs @@ -11,7 +11,12 @@ namespace Zomp.SyncMethodGenerator; /// The semantic model. /// Instructs the source generator that nullable context should be disabled. /// Instructs the source generator to preserve parameters. -internal sealed class AsyncToSyncRewriter(SemanticModel semanticModel, bool disableNullable, bool preserveProgress) : CSharpSyntaxRewriter +/// User defined mappings for custom sync methods. +internal sealed class AsyncToSyncRewriter( + SemanticModel semanticModel, + bool disableNullable, + bool preserveProgress, + UserMappings userMappings) : CSharpSyntaxRewriter { public const string SyncOnly = "SYNC_ONLY"; @@ -70,6 +75,7 @@ internal sealed class AsyncToSyncRewriter(SemanticModel semanticModel, bool disa private readonly SemanticModel semanticModel = semanticModel; private readonly bool disableNullable = disableNullable; private readonly bool preserveProgress = preserveProgress; + private readonly UserMappings userMappings = userMappings; private readonly HashSet removedParameters = []; /// @@ -552,6 +558,15 @@ bool InitializedToMemory(SyntaxNode node) droppingAsync = prevDroppingAsync; + if (userMappings.TryGetValue(methodSymbol, out var result)) + { + var args = methodSymbol is { IsExtensionMethod: true, ReducedFrom: not null } && @base.Expression is MemberAccessExpressionSyntax member + ? ArgumentList(SeparatedList([Argument(member.Expression.WithoutTrivia()), .. @base.ArgumentList.Arguments])) + : @base.ArgumentList; + + return InvocationExpression(MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(Global(result.Namespace)), IdentifierName(result.Method)), args).WithTriviaFrom(@base); + } + // Assumption here is that if there's a method like GetMemory(), there is also method called GetSpan(). Revisit if this isn't the case. var endsWithMemory = symbol.Name.EndsWith(Memory, StringComparison.Ordinal); @@ -1623,15 +1638,6 @@ private static SyntaxTokenList StripAsyncModifier(SyntaxTokenList list) private static string RemoveAsync(string original) => Regex.Replace(original, "Async", string.Empty); - private static bool HasSyncMethod(IMethodSymbol ms) - => ms.Name.EndsWith("Async", StringComparison.Ordinal) - && ms.ContainingType is { } type - && type.GetMembers(RemoveAsync(ms.Name)) - .OfType() - .Any(m => m.Parameters.Length == ms.Parameters.Length - && m.Parameters.Zip(ms.Parameters, (p1, p2) => SymbolEqualityComparer.Default.Equals(p1, p2)) - .All(z => z)); - private static bool CanDropIf(IfStatementSyntax ifStatement) => ifStatement.Statement is BlockSyntax { Statements.Count: 0 } or null && (ifStatement.Else is null || CanDropElse(ifStatement.Else)) @@ -2019,6 +2025,17 @@ private bool ShouldRemoveType(ITypeSymbol symbol) return (IsIProgress(namedSymbol) && !preserveProgress) || IsCancellationToken(namedSymbol); } + private bool HasSyncMethod(IMethodSymbol ms) + => userMappings.TryGetValue(ms, out _) + || ( + ms.Name.EndsWith("Async", StringComparison.Ordinal) + && ms.ContainingType is { } type + && type.GetMembers(RemoveAsync(ms.Name)) + .OfType() + .Any(m => m.Parameters.Length == ms.Parameters.Length + && m.Parameters.Zip(ms.Parameters, (p1, p2) => SymbolEqualityComparer.Default.Equals(p1, p2)) + .All(z => z))); + private bool ShouldRemoveArgument(ISymbol symbol, bool isNegated = false) => symbol switch { IPropertySymbol diff --git a/src/Zomp.SyncMethodGenerator/DiagnosticMessages.cs b/src/Zomp.SyncMethodGenerator/DiagnosticMessages.cs index 271dd47..d9f864b 100644 --- a/src/Zomp.SyncMethodGenerator/DiagnosticMessages.cs +++ b/src/Zomp.SyncMethodGenerator/DiagnosticMessages.cs @@ -26,5 +26,21 @@ internal static class DiagnosticMessages DiagnosticSeverity.Error, isEnabledByDefault: true); + internal static readonly DiagnosticDescriptor DuplicateUserMapping = new( + id: "ZSMGEN004", + title: "Duplicate user mapping", + messageFormat: "User mapping '{0}' is already defined", + category: Preprocessor, + DiagnosticSeverity.Error, + isEnabledByDefault: true); + + internal static readonly DiagnosticDescriptor AttributeAndUserMappingConflict = new( + id: "ZSMGEN005", + title: "Attribute and user mapping conflict", + messageFormat: "Method '{0}' has both an attribute and a user mapping defined. The user mapping will be used.", + category: Preprocessor, + DiagnosticSeverity.Error, + isEnabledByDefault: true); + private const string Preprocessor = "Preprocessor"; } diff --git a/src/Zomp.SyncMethodGenerator/SyncMethodSourceGenerator.cs b/src/Zomp.SyncMethodGenerator/SyncMethodSourceGenerator.cs index 14cd23d..13065d9 100644 --- a/src/Zomp.SyncMethodGenerator/SyncMethodSourceGenerator.cs +++ b/src/Zomp.SyncMethodGenerator/SyncMethodSourceGenerator.cs @@ -21,6 +21,7 @@ public class SyncMethodSourceGenerator : IIncrementalGenerator internal const string OmitNullableDirective = "OmitNullableDirective"; internal const string PreserveProgress = "PreserveProgress"; + internal static readonly Regex LineRegex = new(@"([^\r\n]+)(\r\n|\r|\n)?", RegexOptions.Compiled); /// public void Initialize(IncrementalGeneratorInitializationContext context) @@ -38,6 +39,25 @@ public void Initialize(IncrementalGeneratorInitializationContext context) context.RegisterPostInitializationOutput(ctx => ctx.AddSource( $"{SkipSyncVersionAttribute}.g.cs", SourceText.From(SourceGenerationHelper.SkipSyncVersionAttributeSource, Encoding.UTF8))); + var userMappings = context.AdditionalTextsProvider + .Where(a => a.Path.Equals("SyncMethods.txt", StringComparison.OrdinalIgnoreCase) || + a.Path.EndsWith("/SyncMethods.txt", StringComparison.OrdinalIgnoreCase) || + a.Path.EndsWith(@"\SyncMethods.txt", StringComparison.OrdinalIgnoreCase)) + .Select((text, cancellationToken) => (text.Path, text.GetText(cancellationToken)?.ToString() ?? string.Empty)) + .Collect() + .Select(GetUserMappings) + .WithTrackingName("GetUserMappings"); + + context.RegisterSourceOutput( + userMappings, + static (spc, source) => + { + foreach (var diagnostic in source.Diagnostics) + { + spc.ReportDiagnostic(diagnostic); + } + }); + var disableNullable = context.CompilationProvider.Select((c, _) => { @@ -52,8 +72,13 @@ public void Initialize(IncrementalGeneratorInitializationContext context) predicate: static (s, _) => IsSyntaxTargetForGeneration(s), transform: static (ctx, ct) => TransformForGeneration(ctx, ct)) .SelectMany((list, ct) => list) + .Combine(userMappings) .Combine(disableNullable) - .Select((data, ct) => GetMethodToGenerate(data.Left.Context, data.Left.Syntax, data.Right, ct)!) + .Select((data, ct) => + { + var ((result, userMappingsValue), disableNullableValue) = data; + return GetMethodToGenerate(result.Context, result.Syntax, disableNullableValue, userMappingsValue, ct)!; + }) .WithTrackingName("GetMethodToGenerate") .Where(static s => s is not null); @@ -77,6 +102,71 @@ public void Initialize(IncrementalGeneratorInitializationContext context) }); } + private static UserMappings GetUserMappings(ImmutableArray<(string Path, string Content)> array, CancellationToken token) + { + var mappings = ImmutableArray.CreateBuilder<(string Key, string Namespace, string Method)>(); + var diagnostics = ImmutableArray.CreateBuilder(); + var keys = new HashSet(StringComparer.Ordinal); + var lineIndex = -1; + var index = 0; + + foreach (var (path, content) in array) + { + foreach (Match lineMatch in LineRegex.Matches(content)) + { + lineIndex++; + + var line = lineMatch.Groups[1].Value; + var newLineLength = lineMatch.Groups[2] is { Success: true, Value: { } val } ? val.Length : 0; + + var startIndex = index; + index += line.Length + newLineLength; + + token.ThrowIfCancellationRequested(); + + var separatorIndex = line.IndexOf('='); + + if (separatorIndex < 0) + { + // Invalid line, skip it + continue; + } + + var key = line[..separatorIndex].Trim(); + var value = line[(separatorIndex + 1)..].Trim(); + + if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value)) + { + // Invalid key or value, skip it + continue; + } + + if (!keys.Add(key)) + { + diagnostics.Add(new ReportedDiagnostic( + DuplicateUserMapping, + path, + new TextSpan(startIndex, line.Length), + new LinePositionSpan( + new LinePosition(lineIndex, 0), + new LinePosition(lineIndex, line.Length)), + key)); + + continue; + } + + var methodIndex = value.LastIndexOf('.'); + var @namespace = methodIndex < 0 ? string.Empty : value[..methodIndex].Trim(); + var methodName = methodIndex < 0 ? value.Trim() : value[(methodIndex + 1)..].Trim(); + + mappings.Add(("global::" + key, @namespace, methodName)); + } + } + + var result = new UserMappings(mappings.ToImmutable(), diagnostics.ToImmutable()); + return result; + } + private static bool IsSyntaxTargetForGeneration(SyntaxNode node) => node switch { MethodDeclarationSyntax { AttributeLists.Count: > 0 } => true, @@ -119,7 +209,7 @@ static string BuildClassName(MethodParentDeclaration c) return (m, sourcePath, source); } - private static MethodToGenerate? GetMethodToGenerate(GeneratorAttributeSyntaxContext context, MethodDeclarationSyntax methodDeclarationSyntax, bool disableNullable, CancellationToken ct) + private static MethodToGenerate? GetMethodToGenerate(GeneratorAttributeSyntaxContext context, MethodDeclarationSyntax methodDeclarationSyntax, bool disableNullable, UserMappings userMappings, CancellationToken ct) { // stop if we're asked to ct.ThrowIfCancellationRequested(); @@ -229,12 +319,26 @@ static string BuildClassName(MethodParentDeclaration c) var preserveProgress = syncMethodGeneratorAttributeData.NamedArguments.FirstOrDefault(c => c.Key == PreserveProgress) is { Value.Value: true }; - var rewriter = new AsyncToSyncRewriter(context.SemanticModel, disableNullable, preserveProgress); + var rewriter = new AsyncToSyncRewriter(context.SemanticModel, disableNullable, preserveProgress, userMappings); var sn = rewriter.Visit(methodDeclarationSyntax); var content = sn.ToFullString(); var diagnostics = rewriter.Diagnostics; + if (userMappings.TryGetValue(methodSymbol, out _)) + { + var fullName = methodSymbol.ContainingType is not null + ? $"{methodSymbol.ContainingType.ToDisplayString()}.{methodSymbol.Name}" + : methodSymbol.Name; + + diagnostics = [ + ..diagnostics, + ReportedDiagnostic.Create( + AttributeAndUserMappingConflict, + methodDeclarationSyntax.Identifier.GetLocation(), + fullName)]; + } + var hasErrors = false; foreach (var diagnostic in diagnostics) { @@ -265,7 +369,7 @@ static string BuildClassName(MethodParentDeclaration c) } } - var result = new MethodToGenerate(index, namespaces.ToImmutable(), isNamespaceFileScoped, classes.ToImmutable(), methodDeclarationSyntax.Identifier.ValueText, content, disableNullable, rewriter.Diagnostics, hasErrors); + var result = new MethodToGenerate(index, namespaces.ToImmutable(), isNamespaceFileScoped, classes.ToImmutable(), methodDeclarationSyntax.Identifier.ValueText, content, disableNullable, diagnostics, hasErrors); return result; } diff --git a/src/Zomp.SyncMethodGenerator/UserMappings.cs b/src/Zomp.SyncMethodGenerator/UserMappings.cs new file mode 100644 index 0000000..2ac2396 --- /dev/null +++ b/src/Zomp.SyncMethodGenerator/UserMappings.cs @@ -0,0 +1,38 @@ +namespace Zomp.SyncMethodGenerator; + +internal sealed class UserMappings( + EquatableArray<(string Key, string Namespace, string Method)> mappings, + EquatableArray diagnostics) : IEquatable +{ + [field: MaybeNull] + public IReadOnlyDictionary Mappings + => field ??= mappings.ToDictionary(kv => kv.Key, kv => (kv.Namespace, kv.Method)); + + public EquatableArray Diagnostics { get; } = diagnostics; + + public bool Equals(UserMappings? other) + { + return other is not null && + Mappings.Equals(other.Mappings) && + Diagnostics.Equals(other.Diagnostics); + } + + public override bool Equals(object? obj) + { + return obj is not null && (ReferenceEquals(this, obj) || (obj is UserMappings other && Equals(other))); + } + + public override int GetHashCode() => HashCode.Combine(Mappings); + + public bool TryGetValue(IMethodSymbol ms, out (string Namespace, string Method) value) + { + if (ms.ContainingType is { } containingType) + { + return Mappings.TryGetValue( + containingType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) + "." + ms.Name, + out value); + } + + return Mappings.TryGetValue(ms.Name, out value); + } +} diff --git a/tests/GenerationSandbox.Tests/EnumerableExtensions.cs b/tests/GenerationSandbox.Tests/EnumerableExtensions.cs new file mode 100644 index 0000000..c449afc --- /dev/null +++ b/tests/GenerationSandbox.Tests/EnumerableExtensions.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace GenerationSandbox.Tests; + +internal static partial class EnumerableExtensions +{ + public static Task> ToListAsync(this IEnumerable source) + { + return Task.FromResult(source.ToList()); + } + + [Zomp.SyncMethodGenerator.CreateSyncVersion] + public static Task> ReturnListAsync(IEnumerable source) + { + return ToListAsync(source); + } +} diff --git a/tests/GenerationSandbox.Tests/GenerationSandbox.Tests.csproj b/tests/GenerationSandbox.Tests/GenerationSandbox.Tests.csproj index 9fbd2dc..8d6a472 100644 --- a/tests/GenerationSandbox.Tests/GenerationSandbox.Tests.csproj +++ b/tests/GenerationSandbox.Tests/GenerationSandbox.Tests.csproj @@ -33,5 +33,9 @@ + + + + diff --git a/tests/GenerationSandbox.Tests/SyncMethods.txt b/tests/GenerationSandbox.Tests/SyncMethods.txt new file mode 100644 index 0000000..5681a8a --- /dev/null +++ b/tests/GenerationSandbox.Tests/SyncMethods.txt @@ -0,0 +1 @@ +GenerationSandbox.Tests.EnumerableExtensions.ToListAsync=System.Linq.Enumerable.ToList diff --git a/tests/GenerationSandbox.Tests/SyncTests.cs b/tests/GenerationSandbox.Tests/SyncTests.cs index c446bb2..a73350c 100644 --- a/tests/GenerationSandbox.Tests/SyncTests.cs +++ b/tests/GenerationSandbox.Tests/SyncTests.cs @@ -20,6 +20,15 @@ public void TestGeneratedAverageRoutine() public void TestStaticAsyncWithIProgress() => AsyncWithIProgress.CallWithIProgress(); + [Fact] + public void TestReturnListAsync() + { + var expected = new int[] { 1, 2, 3, 4, 5 }; + var myNumbers = new int[] { 1, 2, 3, 4, 5 }; + var result = EnumerableExtensions.ReturnList(myNumbers); + Assert.Equal(expected, result); + } + #if NET8_0_OR_GREATER [Fact] public void TestIndexOfMaxSoFar() diff --git a/tests/Generator.Tests/IncrementalGeneratorTests.cs b/tests/Generator.Tests/IncrementalGeneratorTests.cs index 69a0c54..15e97b3 100644 --- a/tests/Generator.Tests/IncrementalGeneratorTests.cs +++ b/tests/Generator.Tests/IncrementalGeneratorTests.cs @@ -106,10 +106,17 @@ public void CheckGeneratorIsIncremental( driver = driver.RunGenerators(compilation); var result = driver.GetRunResult().Results.Single(); - var sourceOutputs = - result.TrackedOutputSteps.SelectMany(outputStep => outputStep.Value).SelectMany(output => output.Outputs); - var (value, reason) = Assert.Single(sourceOutputs); - Assert.Equal(sourceStepReason, reason); + var trackedOutput = Assert.Single(result.TrackedOutputSteps); + + Assert.Equal(2, trackedOutput.Value.Length); + + // User mappings are not changed in this test case, so they should always return 'Cached' + var userMappingsOutput = trackedOutput.Value[0].Outputs; + Assert.Equal(IncrementalStepRunReason.Cached, Assert.Single(userMappingsOutput).Reason); + Assert.Equal(IncrementalStepRunReason.Cached, result.TrackedSteps["GetUserMappings"].Single().Outputs[0].Reason); + + var sourceOutputs = trackedOutput.Value[1].Outputs; + Assert.Equal(sourceStepReason, Assert.Single(sourceOutputs).Reason); Assert.Equal(executeStepReason, result.TrackedSteps["GetMethodToGenerate"].Single().Outputs[0].Reason); Assert.Equal(combineStepReason, result.TrackedSteps["GenerateSource"].Single().Outputs[0].Reason); } diff --git a/tests/Generator.Tests/MemoryAdditionalText.cs b/tests/Generator.Tests/MemoryAdditionalText.cs new file mode 100644 index 0000000..d5a1966 --- /dev/null +++ b/tests/Generator.Tests/MemoryAdditionalText.cs @@ -0,0 +1,13 @@ +using Microsoft.CodeAnalysis.Text; + +namespace Generator.Tests; + +public class MemoryAdditionalText(string path, string text) : AdditionalText +{ + public override string Path { get; } = path; + + public override SourceText GetText(CancellationToken cancellationToken = default) + { + return SourceText.From(text); + } +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=01#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=01#CallWithIProgressAsync.g.verified.cs index c2ce333..3537778 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=01#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=01#CallWithIProgressAsync.g.verified.cs @@ -1,6 +1,6 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - var progress = new global::System.Progress(); - WithIProgress(progress); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + var progress = new global::System.Progress(); + WithIProgress(progress); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=02#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=02#CallWithIProgressAsync.g.verified.cs index 9d60023..6e08f9b 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=02#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=02#CallWithIProgressAsync.g.verified.cs @@ -1,6 +1,6 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - var progress = new global::System.Progress(); - WithIProgress(progress as global::System.IProgress); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + var progress = new global::System.Progress(); + WithIProgress(progress as global::System.IProgress); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=03#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=03#CallWithIProgressAsync.g.verified.cs index 474b81a..f9e3e80 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=03#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=03#CallWithIProgressAsync.g.verified.cs @@ -1,6 +1,6 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - var progress = new global::System.Progress(); - WithIProgress(global::Test.Class.ProgressFunc(progress)); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + var progress = new global::System.Progress(); + WithIProgress(global::Test.Class.ProgressFunc(progress)); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=05#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=05#CallWithIProgressAsync.g.verified.cs index 5c20627..7541269 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=05#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=05#CallWithIProgressAsync.g.verified.cs @@ -1,6 +1,6 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - var progress = new global::System.Progress(); - WithIProgress((global::System.Progress)progress); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + var progress = new global::System.Progress(); + WithIProgress((global::System.Progress)progress); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=06#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=06#CallWithIProgressAsync.g.verified.cs index 67821ec..78c771f 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=06#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=06#CallWithIProgressAsync.g.verified.cs @@ -1,6 +1,6 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - var progress = new global::System.Progress(); - WithIProgress((progress)); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + var progress = new global::System.Progress(); + WithIProgress((progress)); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=07#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=07#CallWithIProgressAsync.g.verified.cs index 616a956..44db485 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=07#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=07#CallWithIProgressAsync.g.verified.cs @@ -1,6 +1,6 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - var progress = new global::System.Progress(); - WithIProgress(someBool ? progress : null); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + var progress = new global::System.Progress(); + WithIProgress(someBool ? progress : null); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=08#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=08#CallWithIProgressAsync.g.verified.cs index 613304e..1e953a5 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=08#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=08#CallWithIProgressAsync.g.verified.cs @@ -1,6 +1,6 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - var progress = new global::System.Progress(); - WithIProgress(someBool ? null : progress); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + var progress = new global::System.Progress(); + WithIProgress(someBool ? null : progress); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=09#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=09#CallWithIProgressAsync.g.verified.cs index 6e1dfa9..37c067b 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=09#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=09#CallWithIProgressAsync.g.verified.cs @@ -1,6 +1,6 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - var progress = new global::System.Progress(); - WithIProgress(classWithProgress.Property); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + var progress = new global::System.Progress(); + WithIProgress(classWithProgress.Property); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=10#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=10#CallWithIProgressAsync.g.verified.cs index 6cf7332..46c9870 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=10#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=10#CallWithIProgressAsync.g.verified.cs @@ -1,6 +1,6 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - var progress = new global::System.Progress(); - WithIProgress(global::Test.Class.array[0]); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + var progress = new global::System.Progress(); + WithIProgress(global::Test.Class.array[0]); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=11#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=11#CallWithIProgressAsync.g.verified.cs index edf1534..db76853 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=11#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=11#CallWithIProgressAsync.g.verified.cs @@ -1,6 +1,6 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - var progress = new global::System.Progress(); - WithIProgress(global::Test.Class.customProgress++); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + var progress = new global::System.Progress(); + WithIProgress(global::Test.Class.customProgress++); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=12#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=12#CallWithIProgressAsync.g.verified.cs index 85085ed..35a58ff 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=12#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=12#CallWithIProgressAsync.g.verified.cs @@ -1,6 +1,6 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - var progress = new global::System.Progress(); - WithIProgress(global::Test.Class.customProgress + global::Test.Class.customProgress); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + var progress = new global::System.Progress(); + WithIProgress(global::Test.Class.customProgress + global::Test.Class.customProgress); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=13#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=13#CallWithIProgressAsync.g.verified.cs index 1a96dfa..1b10d29 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=13#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=13#CallWithIProgressAsync.g.verified.cs @@ -1,6 +1,6 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - var progress = new global::System.Progress(); - WithIProgress((global::System.Progress)global::Test.Class.classWithProgress); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + var progress = new global::System.Progress(); + WithIProgress((global::System.Progress)global::Test.Class.classWithProgress); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=14#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=14#CallWithIProgressAsync.g.verified.cs index 4c7b02d..63f1305 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=14#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=14#CallWithIProgressAsync.g.verified.cs @@ -1,6 +1,6 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - var progress = new global::System.Progress(); - WithIProgress(new global::Test.Class.CustomProgress()); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + var progress = new global::System.Progress(); + WithIProgress(new global::Test.Class.CustomProgress()); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=15#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=15#CallWithIProgressAsync.g.verified.cs index 36be872..7c27f08 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=15#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressExpressionArgument_n=15#CallWithIProgressAsync.g.verified.cs @@ -1,6 +1,6 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - var progress = new global::System.Progress(); - WithIProgress(global::Test.Class.SomeMethod(progress)); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + var progress = new global::System.Progress(); + WithIProgress(global::Test.Class.SomeMethod(progress)); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=01#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=01#CallWithIProgressAsync.g.verified.cs index cc56cec..5115489 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=01#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=01#CallWithIProgressAsync.g.verified.cs @@ -1,9 +1,9 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - global::Test.Class.CustomProgress progress = new(); - - progress++; - - WithIProgress(progress); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + global::Test.Class.CustomProgress progress = new(); + + progress++; + + WithIProgress(progress); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=02#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=02#CallWithIProgressAsync.g.verified.cs index a48164a..69e8537 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=02#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=02#CallWithIProgressAsync.g.verified.cs @@ -1,9 +1,9 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - global::Test.Class.CustomProgress progress = new(); - - if (true) { progress++; } - - WithIProgress(progress); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + global::Test.Class.CustomProgress progress = new(); + + if (true) { progress++; } + + WithIProgress(progress); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=03#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=03#CallWithIProgressAsync.g.verified.cs index f6e8573..fb668ea 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=03#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=03#CallWithIProgressAsync.g.verified.cs @@ -1,9 +1,9 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - global::Test.Class.CustomProgress progress = new(); - - if (true) progress++; - - WithIProgress(progress); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + global::Test.Class.CustomProgress progress = new(); + + if (true) progress++; + + WithIProgress(progress); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=04#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=04#CallWithIProgressAsync.g.verified.cs index f0ad71a..6fc2768 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=04#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=04#CallWithIProgressAsync.g.verified.cs @@ -1,9 +1,9 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - global::Test.Class.CustomProgress progress = new(); - - if (true) { } else progress++; - - WithIProgress(progress); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + global::Test.Class.CustomProgress progress = new(); + + if (true) { } else progress++; + + WithIProgress(progress); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=05#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=05#CallWithIProgressAsync.g.verified.cs index 23a3bd0..37a4e7d 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=05#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=05#CallWithIProgressAsync.g.verified.cs @@ -1,9 +1,9 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - global::Test.Class.CustomProgress progress = new(); - - if (false) { } else if (true) progress++; - - WithIProgress(progress); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + global::Test.Class.CustomProgress progress = new(); + + if (false) { } else if (true) progress++; + + WithIProgress(progress); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=06#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=06#CallWithIProgressAsync.g.verified.cs index b2137d2..97d9e5c 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=06#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=06#CallWithIProgressAsync.g.verified.cs @@ -1,9 +1,9 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - global::Test.Class.CustomProgress progress = new(); - - if (false) { } else if (true) progress++; else { } - - WithIProgress(progress); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + global::Test.Class.CustomProgress progress = new(); + + if (false) { } else if (true) progress++; else { } + + WithIProgress(progress); +} diff --git a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=07#CallWithIProgressAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=07#CallWithIProgressAsync.g.verified.cs index 9123a4f..2bb1c9b 100644 --- a/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=07#CallWithIProgressAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/IProgressTests.PreserveIProgressStatement_n=07#CallWithIProgressAsync.g.verified.cs @@ -1,18 +1,18 @@ -//HintName: Test.Class.CallWithIProgressAsync.g.cs -public static void CallWithIProgress() -{ - global::Test.Class.CustomProgress progress = new(); - - switch (global::Test.Class.k) -{ - case 1: - progress++; - break; - default: - progress++; - progress++; - break; -} - - WithIProgress(progress); -} +//HintName: Test.Class.CallWithIProgressAsync.g.cs +public static void CallWithIProgress() +{ + global::Test.Class.CustomProgress progress = new(); + + switch (global::Test.Class.k) +{ + case 1: + progress++; + break; + default: + progress++; + progress++; + break; +} + + WithIProgress(progress); +} diff --git a/tests/Generator.Tests/Snapshots/SyncOnlyTests.InsideParameter#IsNullAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/SyncOnlyTests.InsideParameter#IsNullAsync.g.verified.cs index e1a8ed7..5f9d978 100644 --- a/tests/Generator.Tests/Snapshots/SyncOnlyTests.InsideParameter#IsNullAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/SyncOnlyTests.InsideParameter#IsNullAsync.g.verified.cs @@ -1,7 +1,7 @@ -//HintName: Test.Class.IsNullAsync.g.cs -public bool IsNull( -global::System.Data.IDataReader reader, -int i) -{ - return reader.IsDBNull(i); -} +//HintName: Test.Class.IsNullAsync.g.cs +public bool IsNull( +global::System.Data.IDataReader reader, +int i) +{ + return reader.IsDBNull(i); +} diff --git a/tests/Generator.Tests/Snapshots/SyncOnlyTests.LastParameter#IsNullAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/SyncOnlyTests.LastParameter#IsNullAsync.g.verified.cs index fe09b48..37c14d9 100644 --- a/tests/Generator.Tests/Snapshots/SyncOnlyTests.LastParameter#IsNullAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/SyncOnlyTests.LastParameter#IsNullAsync.g.verified.cs @@ -1,7 +1,7 @@ -//HintName: Test.Class.IsNullAsync.g.cs -public bool IsNull( -global::System.Data.IDataReader reader -) -{ - return reader.IsDBNull(i); -} +//HintName: Test.Class.IsNullAsync.g.cs +public bool IsNull( +global::System.Data.IDataReader reader +) +{ + return reader.IsDBNull(i); +} diff --git a/tests/Generator.Tests/Snapshots/SystemAsyncExtensionsTests.AsyncForEachDeconstruct#SumAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/SystemAsyncExtensionsTests.AsyncForEachDeconstruct#SumAsync.g.verified.cs index e2541ff..2a6abd6 100644 --- a/tests/Generator.Tests/Snapshots/SystemAsyncExtensionsTests.AsyncForEachDeconstruct#SumAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/SystemAsyncExtensionsTests.AsyncForEachDeconstruct#SumAsync.g.verified.cs @@ -1,12 +1,12 @@ -//HintName: Test.Class.SumAsync.g.cs -int Sum(global::System.Collections.Generic.IEnumerable<(int a, int b)> enumerable) -{ - int sum = 0; - - foreach (var (a, b) in enumerable) - { - sum += a + b; - } - - return sum; -} +//HintName: Test.Class.SumAsync.g.cs +int Sum(global::System.Collections.Generic.IEnumerable<(int a, int b)> enumerable) +{ + int sum = 0; + + foreach (var (a, b) in enumerable) + { + sum += a + b; + } + + return sum; +} diff --git a/tests/Generator.Tests/Snapshots/SystemAsyncExtensionsTests.AsyncForEachQualified#SumAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/SystemAsyncExtensionsTests.AsyncForEachQualified#SumAsync.g.verified.cs index c993e42..07660ff 100644 --- a/tests/Generator.Tests/Snapshots/SystemAsyncExtensionsTests.AsyncForEachQualified#SumAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/SystemAsyncExtensionsTests.AsyncForEachQualified#SumAsync.g.verified.cs @@ -1,15 +1,15 @@ -//HintName: Test.Class.SumAsync.g.cs -int Sum(global::System.Collections.Generic.IEnumerable enumerable) -{ - int sum = 0; - - foreach (int? i in enumerable) - { - if (i.HasValue) - { - sum += i.Value; - } - } - - return sum; -} +//HintName: Test.Class.SumAsync.g.cs +int Sum(global::System.Collections.Generic.IEnumerable enumerable) +{ + int sum = 0; + + foreach (int? i in enumerable) + { + if (i.HasValue) + { + sum += i.Value; + } + } + + return sum; +} diff --git a/tests/Generator.Tests/Snapshots/TargetTypeLevelTests.TargetInterface#Test.ITargetInterface.MethodAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/TargetTypeLevelTests.TargetInterface#Test.ITargetInterface.MethodAsync.g.verified.cs index 191d59b..ed29a1d 100644 --- a/tests/Generator.Tests/Snapshots/TargetTypeLevelTests.TargetInterface#Test.ITargetInterface.MethodAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/TargetTypeLevelTests.TargetInterface#Test.ITargetInterface.MethodAsync.g.verified.cs @@ -1,8 +1,8 @@ -//HintName: Test.ITargetInterface.MethodAsync.g.cs -// -#nullable enable -namespace Test; -public partial interface ITargetInterface -{ - void Method(); -} +//HintName: Test.ITargetInterface.MethodAsync.g.cs +// +#nullable enable +namespace Test; +public partial interface ITargetInterface +{ + void Method(); +} diff --git a/tests/Generator.Tests/Snapshots/TypeTests.BinaryPattern#g.verified.cs b/tests/Generator.Tests/Snapshots/TypeTests.BinaryPattern#g.verified.cs index 8fa63d4..6f2337d 100644 --- a/tests/Generator.Tests/Snapshots/TypeTests.BinaryPattern#g.verified.cs +++ b/tests/Generator.Tests/Snapshots/TypeTests.BinaryPattern#g.verified.cs @@ -1,2 +1,2 @@ -//HintName: Test.Class.MethodAsync.g.cs -_ = new object() is global::System.DBNull or global::System.IO.Stream; +//HintName: Test.Class.MethodAsync.g.cs +_ = new object() is global::System.DBNull or global::System.IO.Stream; diff --git a/tests/Generator.Tests/Snapshots/TypeTests.DeclarationExpression#g.verified.cs b/tests/Generator.Tests/Snapshots/TypeTests.DeclarationExpression#g.verified.cs index c13d1ed..eaefed3 100644 --- a/tests/Generator.Tests/Snapshots/TypeTests.DeclarationExpression#g.verified.cs +++ b/tests/Generator.Tests/Snapshots/TypeTests.DeclarationExpression#g.verified.cs @@ -1,2 +1,2 @@ -//HintName: Test.Class.MethodAsync.g.cs -new global::System.Collections.Generic.Dictionary().TryGetValue(0, out global::System.IO.Stream a); +//HintName: Test.Class.MethodAsync.g.cs +new global::System.Collections.Generic.Dictionary().TryGetValue(0, out global::System.IO.Stream a); diff --git a/tests/Generator.Tests/Snapshots/TypeTests.EnumPattern#g.verified.cs b/tests/Generator.Tests/Snapshots/TypeTests.EnumPattern#g.verified.cs index 1d96052..c5f9695 100644 --- a/tests/Generator.Tests/Snapshots/TypeTests.EnumPattern#g.verified.cs +++ b/tests/Generator.Tests/Snapshots/TypeTests.EnumPattern#g.verified.cs @@ -1,2 +1,2 @@ -//HintName: Test.Class.MethodAsync.g.cs -_ = global::System.Data.ConnectionState.Closed is global::System.Data.ConnectionState.Closed; +//HintName: Test.Class.MethodAsync.g.cs +_ = global::System.Data.ConnectionState.Closed is global::System.Data.ConnectionState.Closed; diff --git a/tests/Generator.Tests/Snapshots/TypeTests.EnumPatternName#.Class.ReturnTrueAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/TypeTests.EnumPatternName#.Class.ReturnTrueAsync.g.verified.cs index d64773f..261f374 100644 --- a/tests/Generator.Tests/Snapshots/TypeTests.EnumPatternName#.Class.ReturnTrueAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/TypeTests.EnumPatternName#.Class.ReturnTrueAsync.g.verified.cs @@ -1,10 +1,10 @@ -//HintName: .Class.ReturnTrueAsync.g.cs -// -#nullable enable -partial class Class -{ - public bool ReturnTrue() - { - return global::Test.Test is global::Test.Test; - } -} +//HintName: .Class.ReturnTrueAsync.g.cs +// +#nullable enable +partial class Class +{ + public bool ReturnTrue() + { + return global::Test.Test is global::Test.Test; + } +} diff --git a/tests/Generator.Tests/Snapshots/TypeTests.HandleNameOfGenericTuple#g.verified.cs b/tests/Generator.Tests/Snapshots/TypeTests.HandleNameOfGenericTuple#g.verified.cs index 8c3926d..8b8316a 100644 --- a/tests/Generator.Tests/Snapshots/TypeTests.HandleNameOfGenericTuple#g.verified.cs +++ b/tests/Generator.Tests/Snapshots/TypeTests.HandleNameOfGenericTuple#g.verified.cs @@ -1,2 +1,2 @@ -//HintName: Test.Class.MethodAsync.g.cs -_ = nameof(global::System.Collections.Generic.IEnumerable<(global::System.IO.Stream? S, int I)>); +//HintName: Test.Class.MethodAsync.g.cs +_ = nameof(global::System.Collections.Generic.IEnumerable<(global::System.IO.Stream? S, int I)>); diff --git a/tests/Generator.Tests/Snapshots/TypeTests.HandleNullableTuple#g.verified.cs b/tests/Generator.Tests/Snapshots/TypeTests.HandleNullableTuple#g.verified.cs index 4fd2d75..823df1e 100644 --- a/tests/Generator.Tests/Snapshots/TypeTests.HandleNullableTuple#g.verified.cs +++ b/tests/Generator.Tests/Snapshots/TypeTests.HandleNullableTuple#g.verified.cs @@ -1,2 +1,2 @@ -//HintName: Test.Class.MethodAsync.g.cs -public void Method((global::System.IO.Stream? S, int I) z) { } +//HintName: Test.Class.MethodAsync.g.cs +public void Method((global::System.IO.Stream? S, int I) z) { } diff --git a/tests/Generator.Tests/Snapshots/TypeTests.NotPattern#g.verified.cs b/tests/Generator.Tests/Snapshots/TypeTests.NotPattern#g.verified.cs index fe1035f..103ab87 100644 --- a/tests/Generator.Tests/Snapshots/TypeTests.NotPattern#g.verified.cs +++ b/tests/Generator.Tests/Snapshots/TypeTests.NotPattern#g.verified.cs @@ -1,3 +1,3 @@ -//HintName: Test.Class.MethodAsync.g.cs -_ = new object() is not global::System.DBNull; - +//HintName: Test.Class.MethodAsync.g.cs +_ = new object() is not global::System.DBNull; + diff --git a/tests/Generator.Tests/Snapshots/TypeTests.NullableDeclarationExpression#g.verified.cs b/tests/Generator.Tests/Snapshots/TypeTests.NullableDeclarationExpression#g.verified.cs index c7ab4f3..0abeaeb 100644 --- a/tests/Generator.Tests/Snapshots/TypeTests.NullableDeclarationExpression#g.verified.cs +++ b/tests/Generator.Tests/Snapshots/TypeTests.NullableDeclarationExpression#g.verified.cs @@ -1,2 +1,2 @@ -//HintName: Test.Class.MethodAsync.g.cs -new global::System.Collections.Generic.Dictionary().TryGetValue(0, out global::System.IO.Stream? a); +//HintName: Test.Class.MethodAsync.g.cs +new global::System.Collections.Generic.Dictionary().TryGetValue(0, out global::System.IO.Stream? a); diff --git a/tests/Generator.Tests/Snapshots/TypeTests.NullableForeach#g.verified.cs b/tests/Generator.Tests/Snapshots/TypeTests.NullableForeach#g.verified.cs index c2a3105..c29cfa6 100644 --- a/tests/Generator.Tests/Snapshots/TypeTests.NullableForeach#g.verified.cs +++ b/tests/Generator.Tests/Snapshots/TypeTests.NullableForeach#g.verified.cs @@ -1,4 +1,4 @@ -//HintName: Test.Class.MethodAsync.g.cs -foreach (global::System.IO.Stream? i in global::System.Array.Empty()) -{ -} +//HintName: Test.Class.MethodAsync.g.cs +foreach (global::System.IO.Stream? i in global::System.Array.Empty()) +{ +} diff --git a/tests/Generator.Tests/Snapshots/TypeTests.SemaphoreSlimWaitAndRelease#g.verified.cs b/tests/Generator.Tests/Snapshots/TypeTests.SemaphoreSlimWaitAndRelease#g.verified.cs index fc4ca05..1702a45 100644 --- a/tests/Generator.Tests/Snapshots/TypeTests.SemaphoreSlimWaitAndRelease#g.verified.cs +++ b/tests/Generator.Tests/Snapshots/TypeTests.SemaphoreSlimWaitAndRelease#g.verified.cs @@ -1,12 +1,12 @@ -//HintName: Test.Class.MethodAsync.g.cs -var semaphore = new global::System.Threading.SemaphoreSlim(1, 1); - -semaphore.Wait(); - -try -{ -} -finally -{ - semaphore.Release(); -} +//HintName: Test.Class.MethodAsync.g.cs +var semaphore = new global::System.Threading.SemaphoreSlim(1, 1); + +semaphore.Wait(); + +try +{ +} +finally +{ + semaphore.Release(); +} diff --git a/tests/Generator.Tests/Snapshots/TypeTests.VariableDeclaration#g.verified.cs b/tests/Generator.Tests/Snapshots/TypeTests.VariableDeclaration#g.verified.cs index d39a3c5..bf91622 100644 --- a/tests/Generator.Tests/Snapshots/TypeTests.VariableDeclaration#g.verified.cs +++ b/tests/Generator.Tests/Snapshots/TypeTests.VariableDeclaration#g.verified.cs @@ -1,2 +1,2 @@ -//HintName: Test.Class.MethodAsync.g.cs -global::System.IO.MemoryStream ms = new(); +//HintName: Test.Class.MethodAsync.g.cs +global::System.IO.MemoryStream ms = new(); diff --git a/tests/Generator.Tests/Snapshots/TypeTests.VariableDeclarationRedundant#g.verified.cs b/tests/Generator.Tests/Snapshots/TypeTests.VariableDeclarationRedundant#g.verified.cs index 06b808a..514990e 100644 --- a/tests/Generator.Tests/Snapshots/TypeTests.VariableDeclarationRedundant#g.verified.cs +++ b/tests/Generator.Tests/Snapshots/TypeTests.VariableDeclarationRedundant#g.verified.cs @@ -1,2 +1,2 @@ -//HintName: Test.Class.MethodAsync.g.cs -global::System.IO.MemoryStream ms = new global::System.IO.MemoryStream(); +//HintName: Test.Class.MethodAsync.g.cs +global::System.IO.MemoryStream ms = new global::System.IO.MemoryStream(); diff --git a/tests/Generator.Tests/Snapshots/UnitTests.BrokenIfStatement#g.verified.cs b/tests/Generator.Tests/Snapshots/UnitTests.BrokenIfStatement#g.verified.cs index acb751e..25fca49 100644 --- a/tests/Generator.Tests/Snapshots/UnitTests.BrokenIfStatement#g.verified.cs +++ b/tests/Generator.Tests/Snapshots/UnitTests.BrokenIfStatement#g.verified.cs @@ -1 +1 @@ -//HintName: Test.Class.MethodAsync.g.cs +//HintName: Test.Class.MethodAsync.g.cs diff --git a/tests/Generator.Tests/Snapshots/UnitTests.DeleteIfBetweenPreprocessorDirectives#g.verified.cs b/tests/Generator.Tests/Snapshots/UnitTests.DeleteIfBetweenPreprocessorDirectives#g.verified.cs index 134fad9..23c3842 100644 --- a/tests/Generator.Tests/Snapshots/UnitTests.DeleteIfBetweenPreprocessorDirectives#g.verified.cs +++ b/tests/Generator.Tests/Snapshots/UnitTests.DeleteIfBetweenPreprocessorDirectives#g.verified.cs @@ -1,7 +1,7 @@ -//HintName: Test.Class.MethodAsync.g.cs -#if MY_SPECIAL_SYMBOL -if (true) -{ -} -#else -#endif +//HintName: Test.Class.MethodAsync.g.cs +#if MY_SPECIAL_SYMBOL +if (true) +{ +} +#else +#endif diff --git a/tests/Generator.Tests/Snapshots/UnitTests.DropUnawaitedCompletedValueTask#DoSomethingAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/UnitTests.DropUnawaitedCompletedValueTask#DoSomethingAsync.g.verified.cs index e6230c5..745ecaa 100644 --- a/tests/Generator.Tests/Snapshots/UnitTests.DropUnawaitedCompletedValueTask#DoSomethingAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/UnitTests.DropUnawaitedCompletedValueTask#DoSomethingAsync.g.verified.cs @@ -1,2 +1,2 @@ -//HintName: Test.Class.DoSomethingAsync.g.cs -public static void DoSomething() { } +//HintName: Test.Class.DoSomethingAsync.g.cs +public static void DoSomething() { } diff --git a/tests/Generator.Tests/Snapshots/UnitTests.KeepDefaultValueTaskWithResult#ReturnDefault.g.verified.cs b/tests/Generator.Tests/Snapshots/UnitTests.KeepDefaultValueTaskWithResult#ReturnDefault.g.verified.cs index 78aabf8..b89d368 100644 --- a/tests/Generator.Tests/Snapshots/UnitTests.KeepDefaultValueTaskWithResult#ReturnDefault.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/UnitTests.KeepDefaultValueTaskWithResult#ReturnDefault.g.verified.cs @@ -1,2 +1,2 @@ -//HintName: Test.Class.ReturnDefault.g.cs -public static int ReturnDefault() => default; +//HintName: Test.Class.ReturnDefault.g.cs +public static int ReturnDefault() => default; diff --git a/tests/Generator.Tests/Snapshots/UnitTests.ReturnDefaultValueTask#ReturnAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/UnitTests.ReturnDefaultValueTask#ReturnAsync.g.verified.cs index 4d4d80e..50a8d04 100644 --- a/tests/Generator.Tests/Snapshots/UnitTests.ReturnDefaultValueTask#ReturnAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/UnitTests.ReturnDefaultValueTask#ReturnAsync.g.verified.cs @@ -1,9 +1,9 @@ -//HintName: Test.Class.ReturnAsync.g.cs -private void Return(bool input) -{ - if (input) - { - return; - } - global::System.Console.WriteLine("123"); -} +//HintName: Test.Class.ReturnAsync.g.cs +private void Return(bool input) +{ + if (input) + { + return; + } + global::System.Console.WriteLine("123"); +} diff --git a/tests/Generator.Tests/Snapshots/UnitTests.ReturnTask#ReturnAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/UnitTests.ReturnTask#ReturnAsync.g.verified.cs index 97079ac..deabf74 100644 --- a/tests/Generator.Tests/Snapshots/UnitTests.ReturnTask#ReturnAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/UnitTests.ReturnTask#ReturnAsync.g.verified.cs @@ -1,9 +1,9 @@ -//HintName: Test.Class.ReturnAsync.g.cs -private void Return(bool input) -{ - if (input) - { - Return(); return; - } - Return(); -} +//HintName: Test.Class.ReturnAsync.g.cs +private void Return(bool input) +{ + if (input) + { + Return(); return; + } + Return(); +} diff --git a/tests/Generator.Tests/Snapshots/UnitTests.ReturnTaskNoBody#ReturnAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/UnitTests.ReturnTaskNoBody#ReturnAsync.g.verified.cs index 7e076be..d8d84fe 100644 --- a/tests/Generator.Tests/Snapshots/UnitTests.ReturnTaskNoBody#ReturnAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/UnitTests.ReturnTaskNoBody#ReturnAsync.g.verified.cs @@ -1,6 +1,6 @@ -//HintName: Test.Class.ReturnAsync.g.cs -private void Return(bool input) -{ - if (input) { Return(); return; } - Return(); -} +//HintName: Test.Class.ReturnAsync.g.cs +private void Return(bool input) +{ + if (input) { Return(); return; } + Return(); +} diff --git a/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTask#ReturnAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTask#ReturnAsync.g.verified.cs index 97079ac..deabf74 100644 --- a/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTask#ReturnAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTask#ReturnAsync.g.verified.cs @@ -1,9 +1,9 @@ -//HintName: Test.Class.ReturnAsync.g.cs -private void Return(bool input) -{ - if (input) - { - Return(); return; - } - Return(); -} +//HintName: Test.Class.ReturnAsync.g.cs +private void Return(bool input) +{ + if (input) + { + Return(); return; + } + Return(); +} diff --git a/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskConditional#ReturnAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskConditional#ReturnAsync.g.verified.cs index 93b7316..1a61e29 100644 --- a/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskConditional#ReturnAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskConditional#ReturnAsync.g.verified.cs @@ -1,5 +1,5 @@ -//HintName: Test.Class.ReturnAsync.g.cs -private void Return(bool input) -{ - if (input) Return(); else Return(); -} +//HintName: Test.Class.ReturnAsync.g.cs +private void Return(bool input) +{ + if (input) Return(); else Return(); +} diff --git a/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskConditionalFalse#ReturnFalseAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskConditionalFalse#ReturnFalseAsync.g.verified.cs index ba0b883..0cf9792 100644 --- a/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskConditionalFalse#ReturnFalseAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskConditionalFalse#ReturnFalseAsync.g.verified.cs @@ -1,5 +1,5 @@ -//HintName: Test.Class.ReturnFalseAsync.g.cs -private void ReturnFalse(bool input) -{ - if (!input) Return(); -} +//HintName: Test.Class.ReturnFalseAsync.g.cs +private void ReturnFalse(bool input) +{ + if (!input) Return(); +} diff --git a/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskConditionalTrue#ReturnTrueAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskConditionalTrue#ReturnTrueAsync.g.verified.cs index 8220342..260e44c 100644 --- a/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskConditionalTrue#ReturnTrueAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskConditionalTrue#ReturnTrueAsync.g.verified.cs @@ -1,5 +1,5 @@ -//HintName: Test.Class.ReturnTrueAsync.g.cs -private void ReturnTrue(bool input) -{ - if (input) Return(); -} +//HintName: Test.Class.ReturnTrueAsync.g.cs +private void ReturnTrue(bool input) +{ + if (input) Return(); +} diff --git a/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskInstance#ReturnAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskInstance#ReturnAsync.g.verified.cs index 24f7972..a41b3d6 100644 --- a/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskInstance#ReturnAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskInstance#ReturnAsync.g.verified.cs @@ -1,2 +1,2 @@ -//HintName: Test.Class.ReturnAsync.g.cs -public static int Return() { return 1; } +//HintName: Test.Class.ReturnAsync.g.cs +public static int Return() { return 1; } diff --git a/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskNoBody#ReturnAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskNoBody#ReturnAsync.g.verified.cs index 7e076be..d8d84fe 100644 --- a/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskNoBody#ReturnAsync.g.verified.cs +++ b/tests/Generator.Tests/Snapshots/UnitTests.ReturnValueTaskNoBody#ReturnAsync.g.verified.cs @@ -1,6 +1,6 @@ -//HintName: Test.Class.ReturnAsync.g.cs -private void Return(bool input) -{ - if (input) { Return(); return; } - Return(); -} +//HintName: Test.Class.ReturnAsync.g.cs +private void Return(bool input) +{ + if (input) { Return(); return; } + Return(); +} diff --git a/tests/Generator.Tests/Snapshots/UnitTests.WhenDroppingStatementLeaveTrivia#g.verified.cs b/tests/Generator.Tests/Snapshots/UnitTests.WhenDroppingStatementLeaveTrivia#g.verified.cs index 7cfe074..a38cd4c 100644 --- a/tests/Generator.Tests/Snapshots/UnitTests.WhenDroppingStatementLeaveTrivia#g.verified.cs +++ b/tests/Generator.Tests/Snapshots/UnitTests.WhenDroppingStatementLeaveTrivia#g.verified.cs @@ -1,3 +1,3 @@ -//HintName: Test.Class.MethodAsync.g.cs -#if !MY_SPECIAL_SYMBOL -#endif +//HintName: Test.Class.MethodAsync.g.cs +#if !MY_SPECIAL_SYMBOL +#endif diff --git a/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.DuplicateKey.verified.txt b/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.DuplicateKey.verified.txt new file mode 100644 index 0000000..494d2fa --- /dev/null +++ b/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.DuplicateKey.verified.txt @@ -0,0 +1,17 @@ +{ + Diagnostics: [ + { + Location: SyncMethods.txt: (1,0)-(1,57), + Message: User mapping 'System.Threading.Tasks.Task.Delay' is already defined, + Severity: Error, + Descriptor: { + Id: ZSMGEN004, + Title: Duplicate user mapping, + MessageFormat: User mapping '{0}' is already defined, + Category: Preprocessor, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + } + ] +} \ No newline at end of file diff --git a/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.ErrorOnUserMapping#FooAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.ErrorOnUserMapping#FooAsync.g.verified.cs new file mode 100644 index 0000000..83fd4e8 --- /dev/null +++ b/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.ErrorOnUserMapping#FooAsync.g.verified.cs @@ -0,0 +1,5 @@ +//HintName: Test.Class.FooAsync.g.cs +public void Foo() +{ + global::System.Threading.Thread.Sleep(1000); +} diff --git a/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.ErrorOnUserMapping.verified.txt b/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.ErrorOnUserMapping.verified.txt new file mode 100644 index 0000000..5b29600 --- /dev/null +++ b/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.ErrorOnUserMapping.verified.txt @@ -0,0 +1,17 @@ +{ + Diagnostics: [ + { + Location: : (4,16)-(4,21), + Message: Method 'Test.Class.Delay' has both an attribute and a user mapping defined. The user mapping will be used., + Severity: Error, + Descriptor: { + Id: ZSMGEN005, + Title: Attribute and user mapping conflict, + MessageFormat: Method '{0}' has both an attribute and a user mapping defined. The user mapping will be used., + Category: Preprocessor, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + } + ] +} \ No newline at end of file diff --git a/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.Extension#Test.Class{T}.FooAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.Extension#Test.Class{T}.FooAsync.g.verified.cs new file mode 100644 index 0000000..5136c4f --- /dev/null +++ b/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.Extension#Test.Class{T}.FooAsync.g.verified.cs @@ -0,0 +1,11 @@ +//HintName: Test.Class{T}.FooAsync.g.cs +// +#nullable enable +namespace Test; +internal partial class Class +{ + public void Foo(global::System.Linq.IQueryable source) + { + global::System.Linq.Enumerable.ToList(source); + } +} diff --git a/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.ExtensionDirectCall#Test.Class{T}.FooAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.ExtensionDirectCall#Test.Class{T}.FooAsync.g.verified.cs new file mode 100644 index 0000000..5136c4f --- /dev/null +++ b/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.ExtensionDirectCall#Test.Class{T}.FooAsync.g.verified.cs @@ -0,0 +1,11 @@ +//HintName: Test.Class{T}.FooAsync.g.cs +// +#nullable enable +namespace Test; +internal partial class Class +{ + public void Foo(global::System.Linq.IQueryable source) + { + global::System.Linq.Enumerable.ToList(source); + } +} diff --git a/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.OverrideSpecialMethod#Test.Class{T}.FooAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.OverrideSpecialMethod#Test.Class{T}.FooAsync.g.verified.cs new file mode 100644 index 0000000..f343286 --- /dev/null +++ b/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.OverrideSpecialMethod#Test.Class{T}.FooAsync.g.verified.cs @@ -0,0 +1,11 @@ +//HintName: Test.Class{T}.FooAsync.g.cs +// +#nullable enable +namespace Test; +internal partial class Class +{ + public void Foo() + { + global::Test.CustomThread.Sleep(1000); + } +} diff --git a/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.SelfCall#FooAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.SelfCall#FooAsync.g.verified.cs new file mode 100644 index 0000000..83fd4e8 --- /dev/null +++ b/tests/Generator.Tests/Snapshots/UserDefinedMappingTests.SelfCall#FooAsync.g.verified.cs @@ -0,0 +1,5 @@ +//HintName: Test.Class.FooAsync.g.cs +public void Foo() +{ + global::System.Threading.Thread.Sleep(1000); +} diff --git a/tests/Generator.Tests/TestHelper.cs b/tests/Generator.Tests/TestHelper.cs index 43d227d..df8308d 100644 --- a/tests/Generator.Tests/TestHelper.cs +++ b/tests/Generator.Tests/TestHelper.cs @@ -56,6 +56,7 @@ internal static Task Verify( bool disableUnique = false, SourceType sourceType = SourceType.ClassBody, LanguageVersion languageVersion = LanguageVersion.Preview, + ImmutableArray? additionalTexts = null, params object?[] parameters) { var parseOptions = CSharpParseOptions.Default @@ -104,6 +105,7 @@ partial class Class typeof(Queue<>).Assembly.Location, typeof(LinkedListNode<>).Assembly.Location, typeof(XmlReader).Assembly.Location, + typeof(IQueryable).Assembly.Location, #if NET8_0_OR_GREATER typeof(AsyncEnumerable).Assembly.Location, #endif @@ -132,6 +134,11 @@ partial class Class var driver = CSharpGeneratorDriver.Create(generator).WithUpdatedParseOptions(parseOptions); + if (additionalTexts is { Length: > 0 }) + { + driver = driver.AddAdditionalTexts(additionalTexts.Value); + } + driver = driver.RunGenerators(compilation); // Ensure that at least two sources are generated diff --git a/tests/Generator.Tests/UserDefinedMappingTests.cs b/tests/Generator.Tests/UserDefinedMappingTests.cs new file mode 100644 index 0000000..2b10bf8 --- /dev/null +++ b/tests/Generator.Tests/UserDefinedMappingTests.cs @@ -0,0 +1,108 @@ +namespace Generator.Tests; + +public class UserDefinedMappingTests +{ + [Fact] + public Task Extension() => """ +using System.Linq; + +namespace Test; + +internal static class AsyncQueryable +{ + public static async Task> ToListAsync(this IQueryable source) => throw new NotImplementedException(); +} + +internal partial class Class +{ + [CreateSyncVersion] + public async Task FooAsync(IQueryable source) + { + source.ToListAsync(); + } +} +""".Verify(sourceType: SourceType.Full, additionalTexts: [ + new MemoryAdditionalText("SyncMethods.txt", "Test.AsyncQueryable.ToListAsync=System.Linq.Enumerable.ToList") +]); + + [Fact] + public Task ExtensionDirectCall() => """ +using System.Linq; + +namespace Test; + +internal static class AsyncQueryable +{ + public static async Task> ToListAsync(this IQueryable source) => throw new NotImplementedException(); +} + +internal partial class Class +{ + [CreateSyncVersion] + public async Task FooAsync(IQueryable source) + { + Test.AsyncQueryable.ToListAsync(source); + } +} +""".Verify(sourceType: SourceType.Full, additionalTexts: [ + new MemoryAdditionalText("SyncMethods.txt", "Test.AsyncQueryable.ToListAsync=System.Linq.Enumerable.ToList") +]); + + [Fact] + public Task OverrideSpecialMethod() => """ +using System.Threading.Tasks; + +namespace Test; + +internal static class CustomThread +{ + public void Sleep(int millisecondsTimeout) => throw new NotImplementedException(); +} + +internal partial class Class +{ + [CreateSyncVersion] + public async async Task FooAsync() + { + await Task.Delay(1000); + } +} +""".Verify(sourceType: SourceType.Full, additionalTexts: [ + new MemoryAdditionalText("SyncMethods.txt", "System.Threading.Tasks.Task.Delay=Test.CustomThread.Sleep") +]); + + [Fact] + public Task DuplicateKey() => string.Empty.Verify(sourceType: SourceType.Full, additionalTexts: [ + new MemoryAdditionalText("SyncMethods.txt", """ +System.Threading.Tasks.Task.Delay=Test.CustomThread.Sleep +System.Threading.Tasks.Task.Delay=Test.CustomThread.Sleep +""") +]); + + [Fact] + public Task SelfCall() => """ +public Task Delay(int millisecondsTimeout) => Task.Delay(millisecondsTimeout); + +[CreateSyncVersion] +public async async Task FooAsync() +{ + await Delay(1000); +} +""".Verify(additionalTexts: [ + new MemoryAdditionalText("SyncMethods.txt", "Test.Class.Delay=System.Threading.Thread.Sleep") +]); + + [Fact] + public Task ErrorOnUserMapping() => """ +[CreateSyncVersion] +public Task Delay(int millisecondsTimeout) => Task.Delay(millisecondsTimeout); + +[CreateSyncVersion] +public async async Task FooAsync() +{ + await Delay(1000); +} +""".Verify(additionalTexts: [ + new MemoryAdditionalText("SyncMethods.txt", "Test.Class.Delay=System.Threading.Thread.Sleep") +]); +}