|
@@ -2,6 +2,8 @@
|
|
|
using System.Collections.Generic;
|
|
|
using Jint.Native;
|
|
|
using Jint.Native.Object;
|
|
|
+using Jint.Tests.Runtime.Domain;
|
|
|
+using Shapes;
|
|
|
using Xunit;
|
|
|
|
|
|
namespace Jint.Tests.Runtime
|
|
@@ -12,7 +14,7 @@ namespace Jint.Tests.Runtime
|
|
|
|
|
|
public InteropTests()
|
|
|
{
|
|
|
- _engine = new Engine()
|
|
|
+ _engine = new Engine(cfg => cfg.AllowClr(typeof(Shape).Assembly))
|
|
|
.SetValue("log", new Action<object>(Console.WriteLine))
|
|
|
.SetValue("assert", new Action<bool>(Assert.True))
|
|
|
;
|
|
@@ -441,64 +443,43 @@ namespace Jint.Tests.Runtime
|
|
|
");
|
|
|
}
|
|
|
|
|
|
- public interface IPerson
|
|
|
+ [Fact]
|
|
|
+ public void ShouldUseSystemIO()
|
|
|
{
|
|
|
- string Name { get; }
|
|
|
+ RunTest(@"
|
|
|
+ var filename = System.IO.Path.GetTempFileName();
|
|
|
+ var sw = System.IO.File.CreateText(filename);
|
|
|
+ sw.Write('Hello World');
|
|
|
+ sw.Dispose();
|
|
|
+
|
|
|
+ var content = System.IO.File.ReadAllText(filename);
|
|
|
+ System.Console.WriteLine(content);
|
|
|
+
|
|
|
+ assert(content === 'Hello World');
|
|
|
+ ");
|
|
|
}
|
|
|
|
|
|
- public class Person : IPerson
|
|
|
+ [Fact]
|
|
|
+ public void ShouldImportNamespace()
|
|
|
{
|
|
|
- public string Name { get; set; }
|
|
|
- public int Age { get; set; }
|
|
|
-
|
|
|
- public override string ToString()
|
|
|
- {
|
|
|
- return Name;
|
|
|
- }
|
|
|
+ RunTest(@"
|
|
|
+ var Shapes = importNamespace('Shapes');
|
|
|
+ var circle = new Shapes.Circle();
|
|
|
+ assert(circle.Radius === 0);
|
|
|
+ assert(circle.Perimeter() === 0);
|
|
|
+ ");
|
|
|
}
|
|
|
|
|
|
- public class A
|
|
|
+ [Fact]
|
|
|
+ public void ShouldConstructWithParameters()
|
|
|
{
|
|
|
- public int Call1()
|
|
|
- {
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- public int Call1(int x)
|
|
|
- {
|
|
|
- return x;
|
|
|
- }
|
|
|
-
|
|
|
- public string Call2(string x)
|
|
|
- {
|
|
|
- return x;
|
|
|
- }
|
|
|
-
|
|
|
- public string Call3(object x)
|
|
|
- {
|
|
|
- return x.ToString();
|
|
|
- }
|
|
|
-
|
|
|
- public string Call4(IPerson x)
|
|
|
- {
|
|
|
- return x.ToString();
|
|
|
- }
|
|
|
-
|
|
|
- public string Call5(Delegate callback)
|
|
|
- {
|
|
|
- var thisArg = JsValue.Undefined;
|
|
|
- var arguments = new JsValue[] { 1, "foo" };
|
|
|
-
|
|
|
- return callback.DynamicInvoke(thisArg, arguments).ToString();
|
|
|
- }
|
|
|
-
|
|
|
- public string Call6(Func<JsValue, JsValue[], JsValue> callback)
|
|
|
- {
|
|
|
- var thisArg = new JsValue("bar");
|
|
|
- var arguments = new JsValue[] { 1, "foo" };
|
|
|
-
|
|
|
- return callback(thisArg, arguments).ToString();
|
|
|
- }
|
|
|
+ RunTest(@"
|
|
|
+ var Shapes = importNamespace('Shapes');
|
|
|
+ var circle = new Shapes.Circle(1);
|
|
|
+ assert(circle.Radius === 1);
|
|
|
+ assert(circle.Perimeter() === Math.PI);
|
|
|
+ ");
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|