2
0

ConstTests.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. [Fact]
  39. public void DestructuringWithFunctionArgReferenceInStrictMode()
  40. {
  41. _engine.Execute(@"
  42. 'use strict';
  43. function tst(a) {
  44. let [let1, let2, let3] = a;
  45. const [const1, const2, const3] = a;
  46. var [var1, var2, var3] = a;
  47. equal(1, var1);
  48. equal(2, var2);
  49. equal(undefined, var3);
  50. equal(1, const1);
  51. equal(2, const2);
  52. equal(undefined, const3);
  53. equal(1, let1);
  54. equal(2, let2);
  55. equal(undefined, let3);
  56. }
  57. tst([1,2])
  58. ");
  59. }
  60. }
  61. }