SunSpiderTests.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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>(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", "3d-cube.js")]
  28. [InlineData("3d-morph", "3d-morph.js")]
  29. [InlineData("3d-raytrace", "3d-raytrace.js")]
  30. [InlineData("access-binary-trees", "access-binary-trees.js")]
  31. [InlineData("access-fannkuch", "access-fannkuch.js")]
  32. [InlineData("access-nbody", "access-nbody.js")]
  33. [InlineData("access-nsieve", "access-nsieve.js")]
  34. [InlineData("bitops-3bit-bits-in-byte", "bitops-3bit-bits-in-byte.js")]
  35. [InlineData("bitops-bits-in-byte", "bitops-bits-in-byte.js")]
  36. [InlineData("bitops-bitwise-and", "bitops-bitwise-and.js")]
  37. [InlineData("bitops-nsieve-bits", "bitops-nsieve-bits.js")]
  38. [InlineData("controlflow-recursive", "controlflow-recursive.js")]
  39. [InlineData("crypto-aes", "crypto-aes.js")]
  40. [InlineData("crypto-md5", "crypto-md5.js")]
  41. [InlineData("crypto-sha1", "crypto-sha1.js")]
  42. [InlineData("date-format-tofte", "date-format-tofte.js")]
  43. [InlineData("date-format-xparb", "date-format-xparb.js")]
  44. [InlineData("math-cordic", "math-cordic.js")]
  45. [InlineData("math-partial-sums", "math-partial-sums.js")]
  46. [InlineData("math-spectral-norm", "math-spectral-norm.js")]
  47. [InlineData("regexp-dna", "regexp-dna.js")]
  48. [InlineData("string-base64", "string-base64.js")]
  49. [InlineData("string-fasta", "string-fasta.js")]
  50. [InlineData("string-tagcloud", "string-tagcloud.js")]
  51. [InlineData("string-unpack-code", "string-unpack-code.js")]
  52. [InlineData("string-validate-input", "string-validate-input.js")]
  53. public void RunScript(string name, string url)
  54. {
  55. var content = GetEmbeddedFile(url);
  56. RunTest(content);
  57. }
  58. private string GetEmbeddedFile(string filename)
  59. {
  60. const string prefix = "Jint.Tests.CommonScripts.Scripts.";
  61. var assembly = typeof(SunSpiderTests).GetTypeInfo().Assembly;
  62. var scriptPath = prefix + filename;
  63. using (var stream = assembly.GetManifestResourceStream(scriptPath))
  64. {
  65. using (var sr = new StreamReader(stream))
  66. {
  67. return sr.ReadToEnd();
  68. }
  69. }
  70. }
  71. }
  72. }