SunSpiderTests.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System.Reflection;
  2. using Jint.Runtime;
  3. namespace Jint.Tests.CommonScripts
  4. {
  5. public class SunSpiderTests
  6. {
  7. private static void RunTest(string source)
  8. {
  9. var engine = new Engine()
  10. .SetValue("log", new Action<object>(Console.WriteLine))
  11. .SetValue("assert", new Action<bool, string>((condition, message) => Assert.True(condition, message)));
  12. try
  13. {
  14. engine.Execute(source);
  15. }
  16. catch (JavaScriptException je)
  17. {
  18. throw new Exception(je.ToString());
  19. }
  20. }
  21. [Test]
  22. [Parallelizable(ParallelScope.All)]
  23. [TestCase("3d-cube.js")]
  24. [TestCase("3d-morph.js")]
  25. [TestCase("3d-raytrace.js")]
  26. [TestCase("access-binary-trees.js")]
  27. [TestCase("access-fannkuch.js")]
  28. [TestCase("access-nbody.js")]
  29. [TestCase("access-nsieve.js")]
  30. [TestCase("bitops-3bit-bits-in-byte.js")]
  31. [TestCase("bitops-bits-in-byte.js")]
  32. [TestCase("bitops-bitwise-and.js")]
  33. [TestCase("bitops-nsieve-bits.js")]
  34. #if !DEBUG // should only be ran in release mode when inlining happens
  35. [TestCase("controlflow-recursive.js")]
  36. #endif
  37. [TestCase("crypto-aes.js")]
  38. [TestCase("crypto-md5.js")]
  39. [TestCase("crypto-sha1.js")]
  40. [TestCase("date-format-tofte.js")]
  41. [TestCase("date-format-xparb.js")]
  42. [TestCase("math-cordic.js")]
  43. [TestCase("math-partial-sums.js")]
  44. [TestCase("math-spectral-norm.js")]
  45. [TestCase("regexp-dna.js")]
  46. [TestCase("string-base64.js")]
  47. [TestCase("string-fasta.js")]
  48. [TestCase("string-tagcloud.js")]
  49. [TestCase("string-unpack-code.js")]
  50. [TestCase("string-validate-input.js")]
  51. [TestCase("babel-standalone.js")]
  52. public void Sunspider(string url)
  53. {
  54. var content = GetEmbeddedFile(url);
  55. RunTest(content);
  56. }
  57. private string GetEmbeddedFile(string filename)
  58. {
  59. const string prefix = "Jint.Tests.CommonScripts.Scripts.";
  60. var assembly = typeof(SunSpiderTests).GetTypeInfo().Assembly;
  61. var scriptPath = prefix + filename;
  62. using var stream = assembly.GetManifestResourceStream(scriptPath);
  63. using var sr = new StreamReader(stream);
  64. return sr.ReadToEnd();
  65. }
  66. }
  67. }