Skip to content

Commit

Permalink
Added functional tests for interop
Browse files Browse the repository at this point in the history
  • Loading branch information
nilproject committed Oct 9, 2016
1 parent c531f94 commit 770358a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions FunctionalTests/FunctionalTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="FunctionsToDelegateWrapping.cs" />
<Compile Include="Generated\Embedded.cs">
<DependentUpon>Embedded.tt</DependentUpon>
<AutoGen>True</AutoGen>
Expand All @@ -85,6 +86,7 @@
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="Interop.cs" />
<Compile Include="JsFunfuzz.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UglifyJs.cs" />
Expand Down
38 changes: 38 additions & 0 deletions FunctionalTests/FunctionsToDelegateWrapping.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NiL.JS.Core;

namespace FunctionalTests
{
[TestClass]
public class FunctionsToDelegateWrapping
{
[TestMethod]
public void TryToAddFunctionIntoListOfDelegates_Marshal()
{
var context = new Context();
var list = new List<Func<string, string>>();
context.DefineVariable("list").Assign(JSValue.Marshal(list));

context.Eval("list.push(x => 'hi ' + x)"); // IList marshaled as NativeList with array-like interface

Assert.AreEqual("hi Test", list[0]("Test"));
}

[TestMethod]
public void TryToAddFunctionIntoListOfDelegates_Wrap()
{
var context = new Context();
var list = new List<Func<string, string>>();
context.DefineVariable("list").Assign(JSValue.Wrap(list));

context.Eval("list.Add(x => 'hi ' + x)");

Assert.AreEqual("hi Test", list[0]("Test"));
}
}
}
26 changes: 26 additions & 0 deletions FunctionalTests/Interop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NiL.JS.BaseLibrary;
using NiL.JS.Core;

namespace FunctionalTests
{
[TestClass]
public class Interop
{
[TestMethod]
public void CreateInstanceOfGenericType()
{
var context = new Context();
context.DefineConstructor(typeof(List<>));

var result = context.Eval("new (List(Number))()").Value;

Assert.AreSame(typeof(List<Number>), result.GetType());
}
}
}

0 comments on commit 770358a

Please sign in to comment.