SunSpiderTests.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System.Reflection;
  2. using Jint.Runtime;
  3. namespace Jint.Tests.CommonScripts;
  4. [Parallelizable(ParallelScope.All)]
  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.That(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. [TestCase("3d-cube.js")]
  23. [TestCase("3d-morph.js")]
  24. [TestCase("3d-raytrace.js")]
  25. [TestCase("access-binary-trees.js")]
  26. [TestCase("access-fannkuch.js")]
  27. [TestCase("access-nbody.js")]
  28. [TestCase("access-nsieve.js")]
  29. [TestCase("bitops-3bit-bits-in-byte.js")]
  30. [TestCase("bitops-bits-in-byte.js")]
  31. [TestCase("bitops-bitwise-and.js")]
  32. [TestCase("bitops-nsieve-bits.js")]
  33. #if !DEBUG // should only be ran in release mode when inlining happens
  34. [TestCase("controlflow-recursive.js")]
  35. #endif
  36. [TestCase("crypto-aes.js")]
  37. [TestCase("crypto-md5.js")]
  38. [TestCase("crypto-sha1.js")]
  39. [TestCase("date-format-tofte.js")]
  40. [TestCase("date-format-xparb.js")]
  41. [TestCase("math-cordic.js")]
  42. [TestCase("math-partial-sums.js")]
  43. [TestCase("math-spectral-norm.js")]
  44. [TestCase("regexp-dna.js")]
  45. [TestCase("string-base64.js")]
  46. [TestCase("string-fasta.js")]
  47. [TestCase("string-tagcloud.js")]
  48. [TestCase("string-unpack-code.js")]
  49. [TestCase("string-validate-input.js")]
  50. [TestCase("babel-standalone.js")]
  51. public void Sunspider(string url)
  52. {
  53. var content = GetEmbeddedFile(url);
  54. RunTest(content);
  55. }
  56. internal static string GetEmbeddedFile(string filename)
  57. {
  58. const string Prefix = "Jint.Tests.CommonScripts.Scripts.";
  59. var assembly = typeof(SunSpiderTests).GetTypeInfo().Assembly;
  60. var scriptPath = Prefix + filename;
  61. using var stream = assembly.GetManifestResourceStream(scriptPath);
  62. using var sr = new StreamReader(stream);
  63. return sr.ReadToEnd();
  64. }
  65. }