-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8abc736
commit 78ef8f6
Showing
5 changed files
with
305 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
test/SourceGeneratorTests/Baselines/MainTests/TaskOfTMethod/Pretender_g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// <auto-generated> | ||
|
||
#nullable enable annotations | ||
#nullable disable warnings | ||
|
||
// Suppress warnings about [Obsolete] member usage in generated code. | ||
#pragma warning disable CS0612, CS0618 | ||
|
||
namespace System.Runtime.CompilerServices | ||
{ | ||
using System; | ||
using System.CodeDom.Compiler; | ||
|
||
[GeneratedCode("Pretender.SourceGenerator", "1.0.0.0")] | ||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] | ||
file sealed class InterceptsLocationAttribute : Attribute | ||
{ | ||
public InterceptsLocationAttribute(string filePath, int line, int column) | ||
{ | ||
} | ||
} | ||
} | ||
|
||
namespace Pretender.SourceGeneration | ||
{ | ||
using System; | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading.Tasks; | ||
using Pretender; | ||
using Pretender.Internals; | ||
|
||
file class PretendIMyInterface : global::TaskOfTMethodNamespace.IMyInterface | ||
{ | ||
public static readonly MethodInfo MethodAsync_MethodInfo = typeof(PretendIMyInterface).GetMethod(nameof(MethodAsync))!; | ||
|
||
private readonly ICallHandler _callHandler; | ||
|
||
public PretendIMyInterface(ICallHandler callHandler) | ||
{ | ||
_callHandler = callHandler; | ||
} | ||
|
||
public global::System.Threading.Tasks.Task<string> MethodAsync(string str) | ||
{ | ||
object?[] __arguments__ = [str]; | ||
var __callInfo__ = new CallInfo(MethodAsync_MethodInfo, __arguments__); | ||
_callHandler.Handle(__callInfo__); | ||
return (global::System.Threading.Tasks.Task<string>)__callInfo__.ReturnValue; | ||
} | ||
} | ||
|
||
file static class SetupInterceptors | ||
{ | ||
[InterceptsLocation(@"MyTest.cs", 21, 17)] | ||
internal static IPretendSetup<global::TaskOfTMethodNamespace.IMyInterface, global::System.Threading.Tasks.Task<string>> Setup0(this Pretend<global::TaskOfTMethodNamespace.IMyInterface> pretend, Func<global::TaskOfTMethodNamespace.IMyInterface, global::System.Threading.Tasks.Task<string>> setupExpression) | ||
{ | ||
return pretend.GetOrCreateSetup<global::System.Threading.Tasks.Task<string>>(0, static (pretend, expr) => | ||
{ | ||
Matcher matchCall = (callInfo, setup) => | ||
{ | ||
var singleUseCallHandler = new SingleUseCallHandler(); | ||
var fake = new PretendIMyInterface(singleUseCallHandler); | ||
var listener = MatcherListener.StartListening(); | ||
setup.Method.Invoke(setup.Target, [fake]); | ||
listener.Dispose(); | ||
var capturedArguments = singleUseCallHandler.Arguments; | ||
|
||
var str_capturedMatcher = listener.Matchers[0]; | ||
var str_arg = (string)callInfo.Arguments[0]; | ||
if (!str_capturedMatcher.Matches(str_arg)) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
}; | ||
return new ReturningCompiledSetup<global::TaskOfTMethodNamespace.IMyInterface, global::System.Threading.Tasks.Task<string>>(pretend, PretendIMyInterface.MethodAsync_MethodInfo, matchCall, expr, defaultValue: default); | ||
}, setupExpression); | ||
} | ||
} | ||
|
||
file static class VerifyInterceptors | ||
{ | ||
} | ||
|
||
file static class CreateInterceptors | ||
{ | ||
} | ||
} |
169 changes: 169 additions & 0 deletions
169
test/SourceGeneratorTests/Baselines/MainTests/Test3/Pretender_g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
// <auto-generated> | ||
|
||
#nullable enable annotations | ||
#nullable disable warnings | ||
|
||
// Suppress warnings about [Obsolete] member usage in generated code. | ||
#pragma warning disable CS0612, CS0618 | ||
|
||
namespace System.Runtime.CompilerServices | ||
{ | ||
using System; | ||
using System.CodeDom.Compiler; | ||
|
||
[GeneratedCode("Pretender.SourceGenerator", "1.0.0.0")] | ||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] | ||
file sealed class InterceptsLocationAttribute : Attribute | ||
{ | ||
public InterceptsLocationAttribute(string filePath, int line, int column) | ||
{ | ||
} | ||
} | ||
} | ||
|
||
namespace Pretender.SourceGeneration | ||
{ | ||
using System; | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading.Tasks; | ||
using Pretender; | ||
using Pretender.Internals; | ||
|
||
file class PretendISimpleInterface : global::ISimpleInterface | ||
{ | ||
public static readonly MethodInfo Foo_MethodInfo = typeof(PretendISimpleInterface).GetMethod(nameof(Foo))!; | ||
public static readonly MethodInfo VoidMethod_MethodInfo = typeof(PretendISimpleInterface).GetMethod(nameof(VoidMethod))!; | ||
public static readonly MethodInfo AsyncMethod_MethodInfo = typeof(PretendISimpleInterface).GetMethod(nameof(AsyncMethod))!; | ||
public static readonly MethodInfo AsyncReturningMethod_MethodInfo = typeof(PretendISimpleInterface).GetMethod(nameof(AsyncReturningMethod))!; | ||
public static readonly MethodInfo TryParse_MethodInfo = typeof(PretendISimpleInterface).GetMethod(nameof(TryParse))!; | ||
public static readonly MethodInfo get_Bar_MethodInfo = typeof(PretendISimpleInterface).GetProperty(nameof(Bar))!.GetMethod; | ||
public static readonly MethodInfo set_Bar_MethodInfo = typeof(PretendISimpleInterface).GetProperty(nameof(Bar))!.SetMethod; | ||
|
||
private readonly ICallHandler _callHandler; | ||
|
||
public PretendISimpleInterface(ICallHandler callHandler) | ||
{ | ||
_callHandler = callHandler; | ||
} | ||
|
||
public string? Foo(string? bar, int baz) | ||
{ | ||
object?[] __arguments__ = [bar, baz]; | ||
var __callInfo__ = new CallInfo(Foo_MethodInfo, __arguments__); | ||
_callHandler.Handle(__callInfo__); | ||
return (string?)__callInfo__.ReturnValue; | ||
} | ||
|
||
public void VoidMethod(bool baz) | ||
{ | ||
object?[] __arguments__ = [baz]; | ||
var __callInfo__ = new CallInfo(VoidMethod_MethodInfo, __arguments__); | ||
_callHandler.Handle(__callInfo__); | ||
} | ||
|
||
public global::System.Threading.Tasks.Task AsyncMethod() | ||
{ | ||
object?[] __arguments__ = []; | ||
var __callInfo__ = new CallInfo(AsyncMethod_MethodInfo, __arguments__); | ||
_callHandler.Handle(__callInfo__); | ||
return (global::System.Threading.Tasks.Task)__callInfo__.ReturnValue; | ||
} | ||
|
||
public global::System.Threading.Tasks.Task<string> AsyncReturningMethod(string bar) | ||
{ | ||
object?[] __arguments__ = [bar]; | ||
var __callInfo__ = new CallInfo(AsyncReturningMethod_MethodInfo, __arguments__); | ||
_callHandler.Handle(__callInfo__); | ||
return (global::System.Threading.Tasks.Task<string>)__callInfo__.ReturnValue; | ||
} | ||
|
||
public bool TryParse(string thing, out bool myValue) | ||
{ | ||
object?[] __arguments__ = [thing, myValue]; | ||
var __callInfo__ = new CallInfo(TryParse_MethodInfo, __arguments__); | ||
_callHandler.Handle(__callInfo__); | ||
myValue = __arguments__[1]; | ||
return (bool)__callInfo__.ReturnValue; | ||
} | ||
|
||
public string Bar | ||
{ | ||
get | ||
{ | ||
object?[] __arguments__ = []; | ||
var __callInfo__ = new CallInfo(get_Bar_MethodInfo, __arguments__); | ||
_callHandler.Handle(__callInfo__); | ||
return (string)__callInfo__.ReturnValue; | ||
} | ||
set | ||
{ | ||
object?[] __arguments__ = [value]; | ||
var __callInfo__ = new CallInfo(set_Bar_MethodInfo, __arguments__); | ||
_callHandler.Handle(__callInfo__); | ||
} | ||
} | ||
} | ||
|
||
file static class SetupInterceptors | ||
{ | ||
[InterceptsLocation(@"MyTest.cs", 13, 6)] | ||
internal static IPretendSetup<global::ISimpleInterface, string?> Setup0(this Pretend<global::ISimpleInterface> pretend, Func<global::ISimpleInterface, string?> setupExpression) | ||
{ | ||
return pretend.GetOrCreateSetup<string?>(0, static (pretend, expr) => | ||
{ | ||
Matcher matchCall = (callInfo, setup) => | ||
{ | ||
var bar_arg = (string?)callInfo.Arguments[0]; | ||
if (bar_arg != "1") | ||
{ | ||
return false; | ||
} | ||
var baz_arg = (int)callInfo.Arguments[1]; | ||
if (baz_arg != (int)(1)) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
}; | ||
return new ReturningCompiledSetup<global::ISimpleInterface, string?>(pretend, PretendISimpleInterface.Foo_MethodInfo, matchCall, expr, defaultValue: default); | ||
}, setupExpression); | ||
} | ||
} | ||
|
||
file static class VerifyInterceptors | ||
{ | ||
[InterceptsLocation(@"MyTest.cs", 18, 24)] | ||
internal static void Verify0(this Pretend<global::ISimpleInterface> pretend, Func<global::ISimpleInterface, string?> setupExpression, Called called) | ||
{ | ||
var setup = pretend.GetOrCreateSetup<string?>(0, static (pretend, expr) => | ||
{ | ||
Matcher matchCall = (callInfo, setup) => | ||
{ | ||
var bar_arg = (string?)callInfo.Arguments[0]; | ||
if (bar_arg != "1") | ||
{ | ||
return false; | ||
} | ||
var baz_arg = (int)callInfo.Arguments[1]; | ||
if (baz_arg != (int)(1)) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
}; | ||
return new ReturningCompiledSetup<global::ISimpleInterface, string?>(pretend, PretendISimpleInterface.Foo_MethodInfo, matchCall, expr, defaultValue: default); | ||
}, setupExpression); | ||
setup.Verify(called); | ||
} | ||
} | ||
|
||
file static class CreateInterceptors | ||
{ | ||
[InterceptsLocation(@"MyTest.cs", 16, 38)] | ||
internal static global::ISimpleInterface Create0(this Pretend<global::ISimpleInterface> pretend) | ||
{ | ||
return new PretendISimpleInterface(pretend); | ||
} | ||
} | ||
} |
Oops, something went wrong.