forked from sebastienros/jint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SunSpiderTests.cs
87 lines (79 loc) · 3.09 KB
/
SunSpiderTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.IO;
using System.Reflection;
using Jint.Runtime;
using Xunit;
namespace Jint.Tests.CommonScripts
{
public class SunSpiderTests
{
private Engine RunTest(string source)
{
var engine = new Engine()
.SetValue("log", new Action<object>(Console.WriteLine))
.SetValue("assert", new Action<bool>(Assert.True))
;
try
{
engine.Execute(source);
}
catch (JavaScriptException je)
{
throw new Exception(je.ToString());
}
return engine;
}
[Theory(DisplayName = "Sunspider")]
[InlineData("3d-cube", "3d-cube.js")]
[InlineData("3d-morph", "3d-morph.js")]
[InlineData("3d-raytrace", "3d-raytrace.js")]
[InlineData("access-binary-trees", "access-binary-trees.js")]
[InlineData("access-fannkuch", "access-fannkuch.js")]
[InlineData("access-nbody", "access-nbody.js")]
[InlineData("access-nsieve", "access-nsieve.js")]
[InlineData("bitops-3bit-bits-in-byte", "bitops-3bit-bits-in-byte.js")]
[InlineData("bitops-bits-in-byte", "bitops-bits-in-byte.js")]
[InlineData("bitops-bitwise-and", "bitops-bitwise-and.js")]
[InlineData("bitops-nsieve-bits", "bitops-nsieve-bits.js")]
[InlineData("controlflow-recursive", "controlflow-recursive.js")]
[InlineData("crypto-aes", "crypto-aes.js")]
[InlineData("crypto-md5", "crypto-md5.js")]
[InlineData("crypto-sha1", "crypto-sha1.js")]
[InlineData("date-format-tofte", "date-format-tofte.js")]
[InlineData("date-format-xparb", "date-format-xparb.js")]
[InlineData("math-cordic", "math-cordic.js")]
[InlineData("math-partial-sums", "math-partial-sums.js")]
[InlineData("math-spectral-norm", "math-spectral-norm.js")]
[InlineData("regexp-dna", "regexp-dna.js")]
[InlineData("string-base64", "string-base64.js")]
[InlineData("string-fasta", "string-fasta.js")]
[InlineData("string-tagcloud", "string-tagcloud.js")]
[InlineData("string-unpack-code", "string-unpack-code.js")]
[InlineData("string-validate-input", "string-validate-input.js")]
public void RunScript(string name, string url)
{
try
{
var content = GetEmbeddedFile(url);
RunTest(content);
}
catch
{
System.Diagnostics.Debug.WriteLine("Can't run {0}", name);
}
}
private string GetEmbeddedFile(string filename)
{
const string prefix = "Jint.Tests.CommonScripts.Scripts.";
var assembly = typeof(SunSpiderTests).GetTypeInfo().Assembly;
var scriptPath = prefix + filename;
using (var stream = assembly.GetManifestResourceStream(scriptPath))
{
using (var sr = new StreamReader(stream))
{
return sr.ReadToEnd();
}
}
}
}
}