ArrayTests.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using Jint.Runtime;
  3. using Xunit;
  4. namespace Jint.Tests.Runtime
  5. {
  6. public class ArrayTests
  7. {
  8. private readonly Engine _engine;
  9. public ArrayTests()
  10. {
  11. _engine = new Engine()
  12. .SetValue("log", new Action<object>(Console.WriteLine))
  13. .SetValue("assert", new Action<bool>(Assert.True))
  14. .SetValue("equal", new Action<object, object>(Assert.Equal));
  15. }
  16. private void RunTest(string source)
  17. {
  18. _engine.Execute(source);
  19. }
  20. [Fact]
  21. public void ArrayPrototypeToStringWithArray()
  22. {
  23. var result = _engine.Execute("Array.prototype.toString.call([1,2,3]);").GetCompletionValue().AsString();
  24. Assert.Equal("1,2,3", result);
  25. }
  26. [Fact]
  27. public void ArrayPrototypeToStringWithNumber()
  28. {
  29. var result = _engine.Execute("Array.prototype.toString.call(1);").GetCompletionValue().AsString();
  30. Assert.Equal("[object Number]", result);
  31. }
  32. [Fact]
  33. public void ArrayPrototypeToStringWithObject()
  34. {
  35. var result = _engine.Execute("Array.prototype.toString.call({});").GetCompletionValue().AsString();
  36. Assert.Equal("[object Object]", result);
  37. }
  38. }
  39. }