SunSpiderTests.cs 2.5 KB

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