Skip to content

Commit

Permalink
Move some interop tests to the public interface test project (#1767)
Browse files Browse the repository at this point in the history
most of those interop tests illustrate how to interact with objects from
popular libraries such as Newtonsoft.Json, System.Text.Json and dynamic
objects such as ExpandoObject.

because this can be a valuable reference for Jint users, they should not
depend on any internals (which would be off limits for callers.)
  • Loading branch information
BhaaLseN authored Jan 30, 2024
1 parent 9fbdab3 commit 24c674f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.Dynamic;
using Jint.Native;
using Jint.Native.Symbol;
using Jint.Tests.Runtime.Domain;

namespace Jint.Tests.Runtime
namespace Jint.Tests.PublicInterface
{
public partial class InteropTests
{
Expand Down Expand Up @@ -143,5 +142,11 @@ public bool ContainsKey(string key)
return _properties.ContainsKey(key);
}
}

private class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Dynamic;
using Jint.Runtime.Interop;

namespace Jint.Tests.Runtime;
namespace Jint.Tests.PublicInterface;

public partial class InteropTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Jint.Runtime;
using Newtonsoft.Json.Linq;

namespace Jint.Tests.Runtime
namespace Jint.Tests.PublicInterface
{
public partial class InteropTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Text.Json.Nodes;
using Jint.Runtime.Interop;

namespace Jint.Tests.Runtime;
namespace Jint.Tests.PublicInterface;

public partial class InteropTests
{
Expand Down Expand Up @@ -37,7 +37,7 @@ public void AccessingJsonNodeShouldWork()
var wrapped = new ObjectWrapper(e, target);
if (target is JsonArray)
{
wrapped.SetPrototypeOf(e.Realm.Intrinsics.Array.PrototypeObject);
wrapped.Prototype = e.Intrinsics.Array.PrototypeObject;
}
return wrapped;
};
Expand Down
24 changes: 24 additions & 0 deletions Jint.Tests.PublicInterface/InteropTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Reflection;

namespace Jint.Tests.PublicInterface
{
public partial class InteropTests : IDisposable
{
private readonly Engine _engine;

public InteropTests()
{
_engine = new Engine(cfg => cfg.AllowClr(
typeof(Console).GetTypeInfo().Assembly,
typeof(File).GetTypeInfo().Assembly))
.SetValue("log", new Action<object>(Console.WriteLine))
.SetValue("assert", new Action<bool>(Assert.True))
.SetValue("equal", new Action<object, object>(Assert.Equal))
;
}

void IDisposable.Dispose()
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="NodaTime" />
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" />
<PackageReference Include="System.Text.Json" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
</ItemGroup>
Expand Down

0 comments on commit 24c674f

Please sign in to comment.