ConstTests.cs 1.8 KB

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