Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// <auto-generated/>
#pragma warning disable

#nullable enable
namespace TUnit.Generated;
internal sealed class ExpectedArgumentTypeTests_TypedArguments_TestSource_GUID : global::TUnit.Core.Interfaces.SourceGenerator.ITestSource
{
public async global::System.Collections.Generic.IAsyncEnumerable<global::TUnit.Core.TestMetadata> GetTestsAsync(string testSessionId, [global::System.Runtime.CompilerServices.EnumeratorCancellation] global::System.Threading.CancellationToken cancellationToken = default)
{
var metadata = new global::TUnit.Core.TestMetadata<global::TUnit.TestProject.ExpectedArgumentTypeTests>
{
TestName = "TypedArguments",
TestClassType = typeof(global::TUnit.TestProject.ExpectedArgumentTypeTests),
TestMethodName = "TypedArguments",
Dependencies = global::System.Array.Empty<global::TUnit.Core.TestDependency>(),
AttributeFactory = () =>
[
new global::TUnit.Core.TestAttribute(),
new global::TUnit.Core.ArgumentsAttribute(0d, typeof(double)),
new global::TUnit.Core.ArgumentsAttribute(0f, typeof(float)),
new global::TUnit.Core.ArgumentsAttribute((sbyte)0, typeof(sbyte)),
new global::TUnit.Core.ArgumentsAttribute((byte)0, typeof(byte)),
new global::TUnit.Core.ArgumentsAttribute((short)0, typeof(short)),
new global::TUnit.Core.ArgumentsAttribute((ushort)0, typeof(ushort)),
new global::TUnit.Core.ArgumentsAttribute(0, typeof(int)),
new global::TUnit.Core.ArgumentsAttribute((uint)0, typeof(uint)),
new global::TUnit.Core.ArgumentsAttribute(0u, typeof(uint)),
new global::TUnit.Core.ArgumentsAttribute((long)0, typeof(long)),
new global::TUnit.Core.ArgumentsAttribute(0L, typeof(long)),
new global::TUnit.Core.ArgumentsAttribute((ulong)0, typeof(ulong)),
new global::TUnit.Core.ArgumentsAttribute(0UL, typeof(ulong)),
new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass)
],
DataSources = new global::TUnit.Core.IDataSourceAttribute[]
{
new global::TUnit.Core.ArgumentsAttribute(0d, typeof(double)),
new global::TUnit.Core.ArgumentsAttribute(0f, typeof(float)),
new global::TUnit.Core.ArgumentsAttribute((sbyte)0, typeof(sbyte)),
new global::TUnit.Core.ArgumentsAttribute((byte)0, typeof(byte)),
new global::TUnit.Core.ArgumentsAttribute((short)0, typeof(short)),
new global::TUnit.Core.ArgumentsAttribute((ushort)0, typeof(ushort)),
new global::TUnit.Core.ArgumentsAttribute(0, typeof(int)),
new global::TUnit.Core.ArgumentsAttribute(0U, typeof(uint)),
new global::TUnit.Core.ArgumentsAttribute(0U, typeof(uint)),
new global::TUnit.Core.ArgumentsAttribute(0L, typeof(long)),
new global::TUnit.Core.ArgumentsAttribute(0L, typeof(long)),
new global::TUnit.Core.ArgumentsAttribute(0UL, typeof(ulong)),
new global::TUnit.Core.ArgumentsAttribute(0UL, typeof(ulong)),
},
ClassDataSources = global::System.Array.Empty<global::TUnit.Core.IDataSourceAttribute>(),
PropertyDataSources = global::System.Array.Empty<global::TUnit.Core.PropertyDataSource>(),
PropertyInjections = global::System.Array.Empty<global::TUnit.Core.PropertyInjectionData>(),
InheritanceDepth = 0,
FilePath = @"",
LineNumber = 8,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.ExpectedArgumentTypeTests),
TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.ExpectedArgumentTypeTests, TestsBase`1"),
Name = "TypedArguments",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
Parameters = new global::TUnit.Core.ParameterMetadata[]
{
new global::TUnit.Core.ParameterMetadata(typeof(object))
{
Name = "value",
TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("object, System.Private.CoreLib"),
IsNullable = false,
ReflectionInfo = typeof(global::TUnit.TestProject.ExpectedArgumentTypeTests).GetMethod("TypedArguments", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(object), typeof(global::System.Type) }, null)!.GetParameters()[0]
},
new global::TUnit.Core.ParameterMetadata(typeof(global::System.Type))
{
Name = "expectedType",
TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Type, System.Private.CoreLib"),
IsNullable = false,
ReflectionInfo = typeof(global::TUnit.TestProject.ExpectedArgumentTypeTests).GetMethod("TypedArguments", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(object), typeof(global::System.Type) }, null)!.GetParameters()[1]
}
},
Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ExpectedArgumentTypeTests", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
{
Type = typeof(global::TUnit.TestProject.ExpectedArgumentTypeTests),
TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.ExpectedArgumentTypeTests, TestsBase`1"),
Name = "ExpectedArgumentTypeTests",
Namespace = "TUnit.TestProject",
Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
Parameters = global::System.Array.Empty<global::TUnit.Core.ParameterMetadata>(),
Properties = global::System.Array.Empty<global::TUnit.Core.PropertyMetadata>(),
Parent = null
};
foreach (var prop in classMetadata.Properties)
{
prop.ClassMetadata = classMetadata;
prop.ContainingTypeMetadata = classMetadata;
}
return classMetadata;
})
},
InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ExpectedArgumentTypeTests(),
TestInvoker = async (instance, args) =>
{
var typedInstance = (global::TUnit.TestProject.ExpectedArgumentTypeTests)instance;
switch (args.Length)
{
case 2:
await typedInstance.TypedArguments(TUnit.Core.Helpers.CastHelper.Cast<object>(args[0]), TUnit.Core.Helpers.CastHelper.Cast<global::System.Type>(args[1]));
break;
default:
throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}");
}
},
InvokeTypedTest = async (instance, args, cancellationToken) =>
{
switch (args.Length)
{
case 2:
await instance.TypedArguments(TUnit.Core.Helpers.CastHelper.Cast<object>(args[0]), TUnit.Core.Helpers.CastHelper.Cast<global::System.Type>(args[1]));
break;
default:
throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}");
}
},
};
metadata.UseRuntimeDataGeneration(testSessionId);
yield return metadata;
yield break;
}
}
internal static class ExpectedArgumentTypeTests_TypedArguments_ModuleInitializer_GUID
{
[global::System.Runtime.CompilerServices.ModuleInitializer]
public static void Initialize()
{
global::TUnit.Core.SourceRegistrar.Register(typeof(global::TUnit.TestProject.ExpectedArgumentTypeTests), new ExpectedArgumentTypeTests_TypedArguments_TestSource_GUID());
}
}
10 changes: 10 additions & 0 deletions TUnit.Core.SourceGenerator.Tests/ExpectedArgumentTypeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

namespace TUnit.Core.SourceGenerator.Tests;

internal class ExpectedArgumentTypeTests : TestsBase
{
[Test]
public Task Test() => RunTest(Path.Combine(Git.RootDirectory.FullName,
"TUnit.TestProject",
"ExpectedArgumentTypeTests.cs"), _ => Task.CompletedTask);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal sealed class NullableByteArgumentTests_Test_TestSource_GUID : global::T
],
DataSources = new global::TUnit.Core.IDataSourceAttribute[]
{
new global::TUnit.Core.ArgumentsAttribute(1),
new global::TUnit.Core.ArgumentsAttribute((byte)1),
new global::TUnit.Core.ArgumentsAttribute(),
},
ClassDataSources = global::System.Array.Empty<global::TUnit.Core.IDataSourceAttribute>(),
Expand Down Expand Up @@ -138,7 +138,7 @@ internal sealed class NullableByteArgumentTests_Test2_TestSource_GUID : global::
],
DataSources = new global::TUnit.Core.IDataSourceAttribute[]
{
new global::TUnit.Core.ArgumentsAttribute((byte)1, 1),
new global::TUnit.Core.ArgumentsAttribute((byte)1, (byte)1),
new global::TUnit.Core.ArgumentsAttribute((byte)1, null),
},
ClassDataSources = global::System.Array.Empty<global::TUnit.Core.IDataSourceAttribute>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ private static string FormatPrimitive(object? value)
return ul.ToString(System.Globalization.CultureInfo.InvariantCulture) + "UL";
case uint ui:
return ui.ToString(System.Globalization.CultureInfo.InvariantCulture) + "U";
case byte b:
return $"(byte){b.ToInvariantString()}";
case sbyte b:
return $"(sbyte){b.ToInvariantString()}";
case ushort us:
return $"(ushort){us.ToInvariantString()}";
case short s:
return $"(short){s.ToInvariantString()}";
default:
// For other numeric types, use InvariantCulture
if (value is IFormattable formattable)
Expand Down
24 changes: 24 additions & 0 deletions TUnit.TestProject/ExpectedArgumentTypeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using TUnit.TestProject.Attributes;

namespace TUnit.TestProject;

[EngineTest(ExpectedResult.Pass)]
public class ExpectedArgumentTypeTests
{
[Test]
[Arguments(0d, typeof(double))]
[Arguments(0f, typeof(float))]
[Arguments((sbyte)0, typeof(sbyte))]
[Arguments((byte)0, typeof(byte))]
[Arguments((short)0, typeof(short))]
[Arguments((ushort)0, typeof(ushort))]
[Arguments(0, typeof(int))]
[Arguments((uint)0, typeof(uint))]
[Arguments(0u, typeof(uint))]
[Arguments((long)0, typeof(long))]
[Arguments(0L, typeof(long))]
[Arguments((ulong)0, typeof(ulong))]
[Arguments(0UL, typeof(ulong))]
public async Task TypedArguments(object value, Type expectedType)
=> await Assert.That(value).IsTypeOf(expectedType);
}
Loading