increment.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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: "Increment BigInt literal",
  11. body: function () {
  12. var x = 123n;
  13. assert.isTrue(x == 123n);
  14. x++;
  15. assert.isTrue(x == 124n);
  16. ++x;
  17. assert.isTrue(x == 125n);
  18. }
  19. },
  20. {
  21. name: "Increment negative BigInt literal",
  22. body: function () {
  23. var x = -123n;
  24. assert.isTrue(x == -123n);
  25. x++;
  26. assert.isTrue(x == -122n);
  27. ++x;
  28. assert.isTrue(x == -121n);
  29. }
  30. },
  31. {
  32. name: "Increment -1n",
  33. body: function () {
  34. var x = -1n;
  35. assert.isTrue(x == -1n);
  36. x++;
  37. assert.isTrue(x == 0n);
  38. ++x;
  39. assert.isTrue(x == 1n);
  40. }
  41. },
  42. {
  43. name: "Increment to change length",
  44. body: function () {
  45. var x = 4294967295n;
  46. assert.isTrue(x == 4294967295n);
  47. x++;
  48. assert.isTrue(x == 4294967296n);
  49. ++x;
  50. assert.isTrue(x == 4294967297n);
  51. var y = -4294967297n;
  52. assert.isTrue(y == -4294967297n);
  53. y++;
  54. assert.isTrue(y == -4294967296n);
  55. ++y;
  56. assert.isTrue(y == -4294967295n);
  57. }
  58. },
  59. {
  60. name: "Increment BigInt Object",
  61. body: function () {
  62. var x = BigInt(12345678901234567890n);
  63. var y = BigInt(12345678901234567891n);
  64. assert.isTrue(x < y);
  65. ++x;
  66. assert.isTrue(x == y);
  67. x++;
  68. assert.isTrue(x >= y);
  69. }
  70. },
  71. {
  72. name: "Out of 64 bit range",
  73. body: function () {
  74. var x = 1234567890123456789012345678901234567890n;
  75. var y = BigInt(1234567890123456789012345678901234567891n);
  76. assert.isFalse(x == y);
  77. x++;
  78. ++y;
  79. assert.isTrue(x < y);
  80. ++x;
  81. assert.isTrue(x == y);
  82. }
  83. },
  84. ];
  85. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });