Skip to content

Commit

Permalink
iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
elringus committed Sep 12, 2023
1 parent 65c3fdb commit a6312e5
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 12 deletions.
41 changes: 35 additions & 6 deletions DotNet/Bootsharp.Builder.Test/ExportTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,52 @@ public class ExportTest : PrepareBootsharpTest
protected override string TestedContent => GeneratedExports;

[Fact]
public void WhenNothingInspected ()
public void WhenNothingInspectedNothingIsGenerated ()
{
Execute();
Contains(
"""
Assert.Empty(TestedContent);
}

""");
[Fact]
public void WhenNoInvokablesNothingIsGenerated ()
{
AddAssembly(With("[JSFunction] public static void Foo () {}"));
Execute();
Assert.Empty(TestedContent);
}

[Fact]
public void WhenNoCrawledExports ()
public void ExportsInvokable ()
{
AddAssembly(With("[JSInvokable] public static void Foo () { }"));
AddAssembly(With(
"""
namespace Space;

public record Info(string Foo);

public class Foo
{
[JSInvokable] public static void Void () {}
[JSInvokable] public static global::Space.Info? WithArgs (string a, global::System.Int32[] b) => default;
[JSInvokable] public static global::System.Threading.Tasks.Task Async () => default;
[JSInvokable] public static Task<Info?> AsyncWithArgs (Info i) => default;
}
""", false));
Execute();
Contains(
"""
using System.Runtime.InteropServices.JavaScript;
using static Bootsharp.Serializer;

namespace Bootsharp;

public partial class InteropExports_Space_Foo
{
[JSExport] internal static void Void () => global::Space.Foo.Void();
[JSExport] internal static global::System.String? WithArgs (global::System.String a, global::System.Int32[] b) => Serialize(global::Space.Foo.WithArgs(a, b));
[JSExport] internal static global::System.Threading.Tasks.Task Async () => global::Space.Foo.Async();
[JSExport] internal static async global::System.Threading.Tasks.Task<global::System.String?> AsyncWithArgs (global::System.String i) => Serialize(await global::Space.Foo.AsyncWithArgs(Deserialize<global::Space.Info?>(i)));
}
""");
}
}
2 changes: 1 addition & 1 deletion DotNet/Bootsharp.Builder.Test/ImportTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void WhenNothingInspected ()
[Fact]
public void WhenNoCrawledImports ()
{
AddAssembly(With("[JSFunction] public static void Foo () { }"));
AddAssembly(With("[JSInvokable] public static void Foo () { }"));
Execute();
Contains(
"""
Expand Down
4 changes: 2 additions & 2 deletions DotNet/Bootsharp.Builder/ExportGenerator/ExportGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ namespace Bootsharp.Builder;

internal sealed class ExportGenerator
{
public string Generate (AssemblyInspector inspector)
public static string Generate (AssemblyInspector inspector)
{
return "";
return new ExportTemplate().Build();
}
}
12 changes: 11 additions & 1 deletion DotNet/Bootsharp.Builder/ExportGenerator/ExportTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,15 @@ namespace Bootsharp.Builder;
internal sealed class ExportTemplate()
{
public string Build () =>
$$""" """;
$$"""
using System.Runtime.InteropServices.JavaScript;
using static Bootsharp.Serializer;

namespace Bootsharp;

public static partial class InteropExports
{

}
""";
}
4 changes: 2 additions & 2 deletions DotNet/Bootsharp.Generator.Test/Emitters/ExportTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class ExportTest
public interface IFoo
{
void Foo (string? foo);
ValueTask Bar ();
Task Bar ();
Item? Baz ();
Task<string> Nya ();
string[] Far (int[] far);
Expand All @@ -38,7 +38,7 @@ public JSFoo (global::IFoo handler)
internal static void RegisterDynamicDependencies () { }

[JSInvokable] public static void Foo (global::System.String? foo) => handler.Foo(foo);
[JSInvokable] public static global::System.Threading.Tasks.ValueTask Bar () => handler.Bar();
[JSInvokable] public static global::System.Threading.Tasks.Task Bar () => handler.Bar();
[JSInvokable] public static global::Item? Baz () => handler.Baz();
[JSInvokable] public static global::System.Threading.Tasks.Task<global::System.String> Nya () => handler.Nya();
[JSInvokable] public static global::System.String[] Far (global::System.Int32[] far) => handler.Far(far);
Expand Down

0 comments on commit a6312e5

Please sign in to comment.