Skip to content

Commit

Permalink
refactor tests (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
elringus committed Jan 2, 2024
1 parent 3570b5e commit 12305fc
Show file tree
Hide file tree
Showing 37 changed files with 315 additions and 289 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cover.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
dotnet pack Bootsharp.Common -o .nuget
dotnet build -c Release
dotnet pack Bootsharp -o .nuget
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:ExcludeByAttribute=GeneratedCodeAttribute
cd ../js/test/cs
dotnet workload restore
dotnet publish -p:BootsharpName=embedded -p:BootsharpEmbedBinaries=true
Expand Down
30 changes: 15 additions & 15 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,34 @@ hero:
}
}

.VPButton.medium.brand {
.VPHome .VPButton.medium.brand,
.VPHome .VPButton.medium.alt {
position: relative;
display: flex;
align-items: center;
padding-top: 5px;
padding-bottom: 5px;
padding-right: 15px;
}

.VPButton.medium.brand::after {
.VPHome .VPButton.medium.brand::after {
content: "";
mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' aria-hidden='true' width='22' height='22' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M17.92 11.62a1.001 1.001 0 0 0-.21-.33l-5-5a1.003 1.003 0 1 0-1.42 1.42l3.3 3.29H7a1 1 0 0 0 0 2h7.59l-3.3 3.29a1.002 1.002 0 0 0 .325 1.639 1 1 0 0 0 1.095-.219l5-5a1 1 0 0 0 .21-.33 1 1 0 0 0 0-.76Z'%3E%3C/path%3E%3C/svg%3E") no-repeat 50% 50%;
width: 10px;
height: 10px;
mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='22' height='22' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M17.92 11.62a1.001 1.001 0 0 0-.21-.33l-5-5a1.003 1.003 0 1 0-1.42 1.42l3.3 3.29H7a1 1 0 0 0 0 2h7.59l-3.3 3.29a1.002 1.002 0 0 0 .325 1.639 1 1 0 0 0 1.095-.219l5-5a1 1 0 0 0 .21-.33 1 1 0 0 0 0-.76Z'%3E%3C/path%3E%3C/svg%3E") no-repeat 50% 50%;
/* Required to render correctly on mobile. */
display: inline-block;
width: 22px;
height: 22px;
padding-left: 30px;
background-color: var(--vp-button-brand-text);
}

.VPButton.medium.alt {
position: relative;
padding-top: 5px;
padding-bottom: 5px;
padding-right: 15px;
}

.VPButton.medium.alt::after {
.VPHome .VPButton.medium.alt::after {
content: "";
mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M19.33 10.18a1 1 0 0 1-.77 0 1 1 0 0 1-.62-.93l.01-1.83-8.2 8.2a1 1 0 0 1-1.41-1.42l8.2-8.2H14.7a1 1 0 0 1 0-2h4.25a1 1 0 0 1 1 1v4.25a1 1 0 0 1-.62.93Z'%3E%3C/path%3E%3Cpath d='M11 4a1 1 0 1 1 0 2H7a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1v-4a1 1 0 1 1 2 0v4a3 3 0 0 1-3 3H7a3 3 0 0 1-3-3V7a3 3 0 0 1 3-3h4Z'%3E%3C/path%3E%3C/svg%3E") no-repeat 50% 50%;
width: 15px;
height: 15px;
/* Required to render correctly on mobile. */
display: inline-block;
width: 20px;
height: 20px;
padding-left: 32px;
background-color: var(--vp-button-alt-text);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cs/.scripts/cover.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
try {
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:ExcludeByAttribute=GeneratedCodeAttribute
reportgenerator "-reports:*/*.xml" "-targetdir:.cover" -reporttypes:HTML
serve .cover
} finally {
Expand Down
2 changes: 1 addition & 1 deletion src/cs/Bootsharp.Common.Test/Bootsharp.Common.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

Expand Down
8 changes: 4 additions & 4 deletions src/cs/Bootsharp.Common.Test/TypesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public void Records ()
[Fact]
public void TypesAreAssigned ()
{
Assert.Equal(new[] { typeof(IBackend) }, new JSExportAttribute(typeof(IBackend)).Types);
Assert.Equal(new[] { typeof(IFrontend) }, new JSImportAttribute(typeof(IFrontend)).Types);
Assert.Equal([typeof(IBackend)], new JSExportAttribute(typeof(IBackend)).Types);
Assert.Equal([typeof(IFrontend)], new JSImportAttribute(typeof(IFrontend)).Types);
}

[Fact]
Expand All @@ -64,7 +64,7 @@ public void EventParametersAreNullByDefault () // (defaults are in generator)
[Fact]
public void ExportParametersEqualArguments ()
{
Assert.Equal(new object[] { typeof(IBackend) },
Assert.Equal([typeof(IBackend)],
(export.ConstructorArguments[0].Value as IReadOnlyCollection<CustomAttributeTypedArgument>).Select(a => a.Value));
Assert.Equal("ExportNamePattern", GetNamedValue(export.NamedArguments, nameof(JSTypeAttribute.NamePattern)));
Assert.Equal("ExportNameReplacement", GetNamedValue(export.NamedArguments, nameof(JSTypeAttribute.NameReplacement)));
Expand All @@ -75,7 +75,7 @@ public void ExportParametersEqualArguments ()
[Fact]
public void ImportParametersEqualArguments ()
{
Assert.Equal(new object[] { typeof(IFrontend) },
Assert.Equal([typeof(IFrontend)],
(import.ConstructorArguments[0].Value as IReadOnlyCollection<CustomAttributeTypedArgument>).Select(a => a.Value));
Assert.Equal("ImportNamePattern", GetNamedValue(import.NamedArguments, nameof(JSTypeAttribute.NamePattern)));
Assert.Equal("ImportNameReplacement", GetNamedValue(import.NamedArguments, nameof(JSTypeAttribute.NameReplacement)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

Expand Down
8 changes: 4 additions & 4 deletions src/cs/Bootsharp.Generate.Test/Emitters/EventTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static class EventTest
{
public static IEnumerable<object[]> Data { get; } = new[] {
// Can generate event binding without namespace and arguments.
new object[] {
[
"""
partial class Foo
{
Expand All @@ -22,9 +22,9 @@ internal static void RegisterDynamicDependencies () { }
partial void OnBar () => Get<global::System.Action>("Global.onBar")();
}
"""
},
],
// Can generate event binding with namespace and arguments.
new object[] {
[
"""
namespace Space;

Expand All @@ -46,7 +46,7 @@ internal static void RegisterDynamicDependencies () { }
public static partial void OnBar (global::System.String a, global::System.Int32 b) => Get<global::System.Action<global::System.String, global::System.Int32>>("Space.onBar")(a, b);
}
"""
},
],
// Can generate event binding with serialized parameters.
new object[] {
"""
Expand Down
8 changes: 4 additions & 4 deletions src/cs/Bootsharp.Generate.Test/Emitters/ExportTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static class ExportTest
{
public static IEnumerable<object[]> Data { get; } = new[] {
// Can export various APIs.
new object[] {
[
"""
using System.Threading.Tasks;

Expand Down Expand Up @@ -47,9 +47,9 @@ internal static void RegisterDynamicDependencies ()
[JSInvokable] public static global::System.String[] Far (global::System.Int32[] far) => handler.Far(far);
}
"""
},
],
// Can override name and invoke.
new object[] {
[
"""
[assembly:JSExport(typeof(IFoo), NamePattern="Foo", NameReplacement="Bar", InvokePattern="(.+)", InvokeReplacement="$1/**/")]

Expand Down Expand Up @@ -80,7 +80,7 @@ internal static void RegisterDynamicDependencies ()
[JSInvokable] public static void Bar (global::System.String foo) => handler.Foo(foo)/**/;
}
"""
},
],
// Can override namespace.
new object[] {
"""
Expand Down
28 changes: 14 additions & 14 deletions src/cs/Bootsharp.Generate.Test/Emitters/FunctionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static class FunctionTest
{
public static IEnumerable<object[]> Data { get; } = new[] {
// Can generate void binding under root namespace.
new object[] {
[
"""
partial class Foo
{
Expand All @@ -22,9 +22,9 @@ internal static void RegisterDynamicDependencies () { }
partial void Bar () => Get<global::System.Action>("Global.bar")();
}
"""
},
],
// Can generate void task binding under file-scoped namespace.
new object[] {
[
"""
using System.Threading.Tasks;

Expand All @@ -50,9 +50,9 @@ internal static void RegisterDynamicDependencies () { }
private static partial global::System.Threading.Tasks.Task BarAsync (global::System.String a, global::System.Int32 b) => Get<global::System.Func<global::System.String, global::System.Int32, global::System.Threading.Tasks.Task>>("File.Scoped.barAsync")(a, b);
}
"""
},
],
// Can generate value task binding.
new object[] {
[
"""
using System.Threading.Tasks;

Expand All @@ -78,9 +78,9 @@ internal static void RegisterDynamicDependencies () { }
private static partial global::System.Threading.Tasks.Task<global::System.String?> BarAsync () => Get<global::System.Func<global::System.Threading.Tasks.Task<global::System.String?>>>("File.Scoped.barAsync")();
}
"""
},
],
// Can generate under classic namespace.
new object[] {
[
"""
using System;
using System.Threading.Tasks;
Expand Down Expand Up @@ -113,9 +113,9 @@ internal static void RegisterDynamicDependencies () { }
}
}
"""
},
],
// Can override namespace.
new object[] {
[
"""
[assembly:JSNamespace(@"A\.B\.(\S+)", "$1")]

Expand All @@ -139,9 +139,9 @@ internal static void RegisterDynamicDependencies () { }
public static partial void OnFun (global::System.Boolean val) => Get<global::System.Action<global::System.Boolean>>("C.onFun")(val);
}
"""
},
],
// Can generate void binding with serialized parameters.
new object[] {
[
"""
using System.Threading.Tasks;

Expand Down Expand Up @@ -171,9 +171,9 @@ internal static void RegisterDynamicDependencies () { }
public async partial global::System.Threading.Tasks.Task<global::System.Byte[]> BazAsync () => Deserialize<global::System.Byte[]>(await Get<global::System.Func<global::System.Threading.Tasks.Task<global::System.String>>>("Global.bazAsync")());
}
"""
},
],
// Doesn't serialize types that can be transferred as-is.
new object[] {
[
"""
using System;
using System.Threading.Tasks;
Expand All @@ -200,7 +200,7 @@ internal static void RegisterDynamicDependencies () { }
public partial global::System.Threading.Tasks.Task<global::System.Exception?> Baz (global::System.Boolean? a1, global::System.Byte? a2, global::System.Char? a3, global::System.Int16? a4, global::System.Int64? a5, global::System.Int32? a6, global::System.Single? a7, global::System.Double? a8, global::System.IntPtr? a9, global::System.DateTime? a10, global::System.DateTimeOffset? a11, global::System.String? a12, global::System.Byte?[] a13, global::System.Int32?[] a14, global::System.Double?[] a15, global::System.String?[] a16) => Get<global::System.Func<global::System.Boolean?, global::System.Byte?, global::System.Char?, global::System.Int16?, global::System.Int64?, global::System.Int32?, global::System.Single?, global::System.Double?, global::System.IntPtr?, global::System.DateTime?, global::System.DateTimeOffset?, global::System.String?, global::System.Byte?[], global::System.Int32?[], global::System.Double?[], global::System.String?[], global::System.Threading.Tasks.Task<global::System.Exception?>>>("Global.baz")(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16);
}
"""
},
],
// Special corner case when UsingDirectiveSyntax.Name is null.
new object[] {
"""
Expand Down
4 changes: 2 additions & 2 deletions src/cs/Bootsharp.Generate.Test/Emitters/ImportTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static class ImportTest
{
public static IEnumerable<object[]> Data { get; } = new[] {
// Can import various APIs; also, when event parameters are set to null, event is not detected.
new object[] {
[
"""
using System.Threading.Tasks;

Expand Down Expand Up @@ -41,7 +41,7 @@ internal static void RegisterDynamicDependencies ()
global::System.Threading.Tasks.Task<global::System.String> global::IFoo.Far () => Far();
}
"""
},
],
// Detects and overrides event methods with defaults.
new object[] {
"""
Expand Down
4 changes: 2 additions & 2 deletions src/cs/Bootsharp.Generate.Test/Emitters/InvokableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static class InvokableTest
{
public static IEnumerable<object[]> Data { get; } = new[] {
// Generates dynamic dependencies registration.
new object[] {
[
"""
partial class Foo
{
Expand All @@ -20,7 +20,7 @@ partial class Foo
internal static void RegisterDynamicDependencies () { }
}
"""
},
],
// Generates dynamic dependencies registration under namespace.
new object[] {
"""
Expand Down
2 changes: 1 addition & 1 deletion src/cs/Bootsharp.Generate.Test/GeneratorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Bootsharp.Generate.Test;

public class GeneratorTest
{
private static readonly List<(string file, string content)> sourceCache = new();
private static readonly List<(string file, string content)> sourceCache = [];
private readonly Verifier<SourceGenerator> verifier = new();

[Fact]
Expand Down
6 changes: 3 additions & 3 deletions src/cs/Bootsharp.Generate/SyntaxReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace Bootsharp.Generate;

internal sealed class SyntaxReceiver
{
public List<PartialClass> InvokableClasses { get; } = new();
public List<PartialClass> FunctionClasses { get; } = new();
public List<PartialClass> EventClasses { get; } = new();
public List<PartialClass> InvokableClasses { get; } = [];
public List<PartialClass> FunctionClasses { get; } = [];
public List<PartialClass> EventClasses { get; } = [];

public void VisitNode (SyntaxNode node, Compilation compilation)
{
Expand Down
2 changes: 1 addition & 1 deletion src/cs/Bootsharp.Inject.Test/Bootsharp.Inject.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/cs/Bootsharp.Inject.Test/Mocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class JSFrontend : IFrontend;

public class JSBackend
{
public static IBackend Handler;
public static IBackend Handler { get; private set; }

public JSBackend (IBackend handler)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Bootsharp.Publish.Test;

public class PrepareTest : TaskTest
public class EmitTest : TaskTest
{
protected string GeneratedExports => ReadProjectFile(exportPath);
protected string GeneratedImports => ReadProjectFile(importPath);
Expand All @@ -12,7 +12,7 @@ public class PrepareTest : TaskTest

public override void Execute () => CreateTask().Execute();

private PrepareBootsharp CreateTask () => new() {
private BootsharpEmit CreateTask () => new() {
InspectedDirectory = Project.Root,
EntryAssemblyName = LastAddedAssemblyName ?? "System.Runtime.dll",
ExportsFilePath = exportPath,
Expand Down
Loading

0 comments on commit 12305fc

Please sign in to comment.