ConstTests.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. namespace Jint.Tests.Runtime;
  2. public class ConstTests
  3. {
  4. private readonly Engine _engine;
  5. public ConstTests()
  6. {
  7. _engine = new Engine()
  8. .SetValue("log", new Action<object>(Console.WriteLine))
  9. .SetValue("assert", new Action<bool>(Assert.True))
  10. .SetValue("equal", new Action<object, object>(Assert.Equal));
  11. }
  12. [Fact]
  13. public void ConstInsideIife()
  14. {
  15. _engine.Execute(@"
  16. (function(){
  17. const testVariable = 'test';
  18. function render() {
  19. log(testVariable);
  20. }
  21. render();
  22. })();
  23. ");
  24. }
  25. [Fact]
  26. public void ConstDestructuring()
  27. {
  28. _engine.Execute(@"
  29. let obj = {};
  30. for (var i = 0; i < 1; i++) {
  31. const { subElement } = obj;
  32. }
  33. ");
  34. }
  35. [Fact]
  36. public void DestructuringWithFunctionArgReferenceInStrictMode()
  37. {
  38. _engine.Execute(@"
  39. 'use strict';
  40. function tst(a) {
  41. let [let1, let2, let3] = a;
  42. const [const1, const2, const3] = a;
  43. var [var1, var2, var3] = a;
  44. equal(1, var1);
  45. equal(2, var2);
  46. equal(undefined, var3);
  47. equal(1, const1);
  48. equal(2, const2);
  49. equal(undefined, const3);
  50. equal(1, let1);
  51. equal(2, let2);
  52. equal(undefined, let3);
  53. }
  54. tst([1,2])
  55. ");
  56. }
  57. }