assign_by_value.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. if (this.WScript && this.WScript.LoadScriptFile) { // Check for running in ch
  6. this.WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  7. }
  8. var tests = [
  9. {
  10. name: "Assign BigInt literal",
  11. body: function () {
  12. var x = 123n;
  13. var y = x;
  14. assert.isTrue(x == 123n);
  15. assert.isTrue(y == 123n);
  16. x++;
  17. assert.isTrue(x == 124n);
  18. assert.isTrue(y == 123n);
  19. y = x;
  20. ++x;
  21. assert.isTrue(x == 125n);
  22. assert.isTrue(y == 124n);
  23. }
  24. },
  25. {
  26. name: "Assign BigInt object",
  27. body: function () {
  28. var x = BigInt(123n);
  29. var y = x;
  30. assert.isTrue(x == 123n);
  31. assert.isTrue(y == 123n);
  32. x++;
  33. assert.isTrue(x == 124n);
  34. assert.isTrue(y == 123n);
  35. y = x;
  36. ++x;
  37. assert.isTrue(x == 125n);
  38. assert.isTrue(y == 124n);
  39. }
  40. },
  41. {
  42. name: "Value change with add and sub",
  43. body: function () {
  44. var x = BigInt(123n);
  45. var y = x;
  46. assert.isTrue(x == 123n);
  47. assert.isTrue(y == 123n);
  48. x = x + 2n;
  49. assert.isTrue(x == 125n);
  50. assert.isTrue(y == 123n);
  51. y = x;
  52. x = x - 2n;
  53. assert.isTrue(x == 123n);
  54. assert.isTrue(y == 125n);
  55. }
  56. },
  57. ];
  58. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });