Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET 4.5 support and more ES6 features #543

Merged
merged 6 commits into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion Jint.Benchmark/Jint.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<None Include="..\Jint.Tests.CommonScripts\Scripts\**" CopyToOutputDirectory="PreserveNewest" LinkBase="SunSpider" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.10.14" />
<PackageReference Include="BenchmarkDotNet" Version="0.11.0" />
<ProjectReference Include="..\Jint\Jint.csproj" />
<PackageReference Include="Jurassic" Version="3.0.0-alpha2" />
<PackageReference Include="NiL.JS.NetCore" Version="2.5.1200" />
Expand Down
10 changes: 5 additions & 5 deletions Jint.Tests.CommonScripts/Jint.Tests.CommonScripts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<ProjectReference Include="..\Jint\Jint.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.analyzers" Version="0.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="xunit.runner.console" Version="2.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.analyzers" Version="0.10.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="xunit.runner.console" Version="2.4.0" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
</Project>
180 changes: 142 additions & 38 deletions Jint.Tests.Ecma/EcmaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,117 @@

namespace Jint.Tests.Ecma
{
public class EcmaTest
public class Chapter6 : EcmaTest
{
[Theory(DisplayName = "Ecma Chapter 6")]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch06", false })]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch06", true }, Skip = "Skipped")]
protected void RunTest(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}
}

public class Chapter7 : EcmaTest
{
[Theory(DisplayName = "Ecma Chapter 7")]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch07", false })]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch07", true }, Skip = "Skipped")]
protected void RunTest(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}
}

public class Chapter8 : EcmaTest
{
[Theory(DisplayName = "Ecma Chapter 8")]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch08", false })]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch08", true }, Skip = "Skipped")]
protected void RunTest(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}
}

public class Chapter9 : EcmaTest
{
[Theory(DisplayName = "Ecma Chapter 9")]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch09", false })]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch09", true }, Skip = "Skipped")]
protected void RunTest(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}
}

public class Chapter10 : EcmaTest
{
[Theory(DisplayName = "Ecma Chapter 10")]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch10", false })]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch10", true }, Skip = "Skipped")]
protected void RunTest(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}
}

public class Chapter11 : EcmaTest
{
[Theory(DisplayName = "Ecma Chapter 11")]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch11", false })]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch11", true }, Skip = "Skipped")]
protected void RunTest(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}
}

public class Chapter12 : EcmaTest
{
[Theory(DisplayName = "Ecma Chapter 12")]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch12", false })]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch12", true }, Skip = "Skipped")]
protected void RunTest(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}
}

public class Chapter13 : EcmaTest
{
[Theory(DisplayName = "Ecma Chapter 13")]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch13", false })]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch13", true }, Skip = "Skipped")]
protected void RunTest(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}
}

public class Chapter14 : EcmaTest
{
[Theory(DisplayName = "Ecma Chapter 14")]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch14", false })]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch14", true }, Skip = "Skipped")]
protected void RunTest(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}
}

public class Chapter15 : EcmaTest
{
[Theory(DisplayName = "Ecma Chapter 15")]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch15", false })]
[MemberData(nameof(SourceFiles), parameters: new object[] {"ch15", true }, Skip = "Skipped")]
protected void RunTest(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}
}

public abstract class EcmaTest
{
private static string _lastError;
private static string staSource;
Expand All @@ -23,6 +133,20 @@ public EcmaTest()
BasePath = assemblyDirectory.Parent.Parent.Parent.FullName;
}

protected void RunTestInternal(SourceFile sourceFile)
{
var fullName = Path.Combine(BasePath, sourceFile.BasePath, sourceFile.Source);
if (!File.Exists(fullName))
{
throw new ArgumentException("Could not find source file: " + fullName);
}

string code = File.ReadAllText(fullName);
var negative = code.Contains("@negative");

RunTestCode(code, negative);
}

protected void RunTestCode(string code, bool negative)
{
_lastError = null;
Expand Down Expand Up @@ -73,25 +197,7 @@ protected void RunTestCode(string code, bool negative)
}
}

[Theory(DisplayName = "Ecma")]
[MemberData(nameof(SourceFiles), false)]
[MemberData(nameof(SourceFiles), true, Skip = "Skipped")]
protected void RunTest(SourceFile sourceFile)
{
var fullName = Path.Combine(BasePath, sourceFile.BasePath, sourceFile.Source);
if (!File.Exists(fullName))
{
throw new ArgumentException("Could not find source file: " + fullName);
}

string code = File.ReadAllText(fullName);
var negative = code.Contains("@negative");

RunTestCode(code, negative);

}

public static IEnumerable<object[]> SourceFiles(bool skipped)
public static IEnumerable<object[]> SourceFiles(string prefix, bool skipped)
{
var assemblyPath = new Uri(typeof(EcmaTest).GetTypeInfo().Assembly.CodeBase).LocalPath;
var assemblyDirectory = new FileInfo(assemblyPath).Directory;
Expand All @@ -100,29 +206,27 @@ public static IEnumerable<object[]> SourceFiles(bool skipped)

var fixturesPath = Path.Combine(localPath, @"TestCases\alltests.json");

try
var content = File.ReadAllText(fixturesPath);
var doc = JArray.Parse(content);
var results = new List<object[]>();
var path = Path.Combine(localPath, "TestCases");

foreach(JObject entry in doc)
{
var content = File.ReadAllText(fixturesPath);
var doc = JArray.Parse(content);
var results = new List<object[]>();
var path = Path.Combine(localPath, "TestCases");
var sourceFile = new SourceFile(entry, path);

foreach(JObject entry in doc)
if (prefix != null && !sourceFile.Source.StartsWith(prefix))
{
var sourceFile = new SourceFile(entry, path);

if (skipped == sourceFile.Skip)
{
results.Add(new object [] { sourceFile });
}
continue;
}

return results;
}
catch
{
throw;
if (skipped == sourceFile.Skip)
{
results.Add(new object [] { sourceFile });
}
}

return results;
}

public class SourceFile
Expand All @@ -145,6 +249,6 @@ public override string ToString()
return Source;
}
}

}
}
10 changes: 5 additions & 5 deletions Jint.Tests.Ecma/Jint.Tests.Ecma.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<ProjectReference Include="..\Jint\Jint.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.analyzers" Version="0.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="xunit.runner.console" Version="2.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.analyzers" Version="0.10.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="xunit.runner.console" Version="2.4.0" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
</Project>
34 changes: 34 additions & 0 deletions Jint.Tests.Ecma/SingleTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using Xunit;

namespace Jint.Tests.Ecma
{
public class RunnableInDebugOnlyAttribute : FactAttribute
{
public RunnableInDebugOnlyAttribute()
{
if (!Debugger.IsAttached)
{
Skip = "Only running in interactive mode.";
}
}
}
public class SingleTest : EcmaTest
{
// helper to test single test case
[RunnableInDebugOnly]
public void TestSingle()
{
const string Target = @"ch15/15.4/15.4.4/15.4.4.17/15.4.4.17-4-10.js";
var sourceFile = SourceFiles(Target, false)
.SelectMany(x => x)
.Cast<SourceFile>()
.Single();

var code = File.ReadAllText(Path.Combine(@"..\..\..\TestCases", sourceFile.Source));
RunTestCode(code, negative: false);
}
}
}
24 changes: 12 additions & 12 deletions Jint.Tests.Ecma/TestCases/alltests.json
Original file line number Diff line number Diff line change
Expand Up @@ -17975,8 +17975,8 @@
source: "ch15/15.1/15.1.2/15.1.2.2/S15.1.2.2_A9.1.js"
},
{
skip: false,
reason: "",
skip: true,
reason: "Function.length is configurable in ES6",
source: "ch15/15.1/15.1.2/15.1.2.2/S15.1.2.2_A9.2.js"
},
{
Expand Down Expand Up @@ -18175,8 +18175,8 @@
source: "ch15/15.1/15.1.2/15.1.2.3/S15.1.2.3_A7.1.js"
},
{
skip: false,
reason: "",
skip: true,
reason: "Function.length is configurable in ES6",
source: "ch15/15.1/15.1.2/15.1.2.3/S15.1.2.3_A7.2.js"
},
{
Expand Down Expand Up @@ -18520,8 +18520,8 @@
source: "ch15/15.1/15.1.3/15.1.3.1/S15.1.3.1_A5.1.js"
},
{
skip: false,
reason: "",
skip: true,
reason: "Function.length is configurable in ES6",
source: "ch15/15.1/15.1.3/15.1.3.1/S15.1.3.1_A5.2.js"
},
{
Expand Down Expand Up @@ -18780,8 +18780,8 @@
source: "ch15/15.1/15.1.3/15.1.3.2/S15.1.3.2_A5.1.js"
},
{
skip: false,
reason: "",
skip: true,
reason: "Function.length is configurable in ES6 ",
source: "ch15/15.1/15.1.3/15.1.3.2/S15.1.3.2_A5.2.js"
},
{
Expand Down Expand Up @@ -18920,8 +18920,8 @@
source: "ch15/15.1/15.1.3/15.1.3.3/S15.1.3.3_A5.1.js"
},
{
skip: false,
reason: "",
skip: true,
reason: "Function.length is configurable in ES6",
source: "ch15/15.1/15.1.3/15.1.3.3/S15.1.3.3_A5.2.js"
},
{
Expand Down Expand Up @@ -19060,8 +19060,8 @@
source: "ch15/15.1/15.1.3/15.1.3.4/S15.1.3.4_A5.1.js"
},
{
skip: false,
reason: "",
skip: true,
reason: "Function.length is configurable in ES6",
source: "ch15/15.1/15.1.3/15.1.3.4/S15.1.3.4_A5.2.js"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
//CHECK#
var count = 0;
var errorCount = 0;
var uspU = ["\u1680", "\u180E", "\u2000", "\u2001", "\u2002", "\u2003", "\u2004", "\u2005", "\u2006", "\u2007", "\u2008", "\u2009", "\u200A", "\u202F", "\u205F", "\u3000"];
var uspS = ["1680", "180E", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "200A", "202F", "205F", "3000"];

// \u180E commented out per https://ecmascript-daily.github.io/2016/03/28/es2016-require-unicode-8-0-0-by-littledan-pull-request-300-tc39-ecma262
var uspU = ["\u1680", /* "\u180E", */ "\u2000", "\u2001", "\u2002", "\u2003", "\u2004", "\u2005", "\u2006", "\u2007", "\u2008", "\u2009", "\u200A", "\u202F", "\u205F", "\u3000"];
var uspS = ["1680", /* "180E", */ "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "200A", "202F", "205F", "3000"];

for (var index = 0; index < uspU.length; index++) {
var result = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
//CHECK#
var count = 0;
var errorCount = 0;
var uspU = ["\u1680", "\u180E", "\u2000", "\u2001", "\u2002", "\u2003", "\u2004", "\u2005", "\u2006", "\u2007", "\u2008", "\u2009", "\u200A", "\u202F", "\u205F", "\u3000"];
var uspS = ["1680", "180E", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "200A", "202F", "205F", "3000"];

// \u180E commented out per https://ecmascript-daily.github.io/2016/03/28/es2016-require-unicode-8-0-0-by-littledan-pull-request-300-tc39-ecma262
var uspU = ["\u1680", /* "\u180E", */ "\u2000", "\u2001", "\u2002", "\u2003", "\u2004", "\u2005", "\u2006", "\u2007", "\u2008", "\u2009", "\u200A", "\u202F", "\u205F", "\u3000"];
var uspS = ["1680", /* "180E", */ "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "200A", "202F", "205F", "3000"];
for (var index = 0; index < uspU.length; index++) {
var result = true;
if (parseFloat(uspU[index] + "1.1") !== parseFloat("1.1")) {
Expand Down