SunSpiderTests.cs 2.5 KB

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