ConstTests.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using Xunit;
  3. namespace Jint.Tests.Runtime
  4. {
  5. public class ConstTests
  6. {
  7. private readonly Engine _engine;
  8. public ConstTests()
  9. {
  10. _engine = new Engine()
  11. .SetValue("log", new Action<object>(Console.WriteLine))
  12. .SetValue("assert", new Action<bool>(Assert.True))
  13. .SetValue("equal", new Action<object, object>(Assert.Equal));
  14. }
  15. [Fact]
  16. public void ConstInsideIife()
  17. {
  18. _engine.Execute(@"
  19. (function(){
  20. const testVariable = 'test';
  21. function render() {
  22. log(testVariable);
  23. }
  24. render();
  25. })();
  26. ");
  27. }
  28. [Fact]
  29. public void ConstDestructuring()
  30. {
  31. _engine.Execute(@"
  32. let obj = {};
  33. for (var i = 0; i < 1; i++) {
  34. const { subElement } = obj;
  35. }
  36. ");
  37. }
  38. }
  39. }