@everyonesoftware/common 6.0.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -425,7 +425,26 @@ var PromiseAsyncResult = class _PromiseAsyncResult {
425
425
  }
426
426
  static create(actionOrPromise) {
427
427
  PreCondition.assertNotUndefinedAndNotNull(actionOrPromise, "action or promise");
428
- return new _PromiseAsyncResult(Promise.resolve(isPromise(actionOrPromise) ? actionOrPromise : actionOrPromise()));
428
+ let promise;
429
+ if (isPromise(actionOrPromise)) {
430
+ promise = actionOrPromise;
431
+ } else {
432
+ let actionExecutor2 = function(resolve, reject) {
433
+ try {
434
+ resolve(action());
435
+ } catch (error) {
436
+ reject(error);
437
+ }
438
+ };
439
+ var actionExecutor = actionExecutor2;
440
+ const action = actionOrPromise;
441
+ ;
442
+ promise = new Promise(actionExecutor2);
443
+ }
444
+ return new _PromiseAsyncResult(promise);
445
+ }
446
+ static empty() {
447
+ return _PromiseAsyncResult.create(Promise.resolve());
429
448
  }
430
449
  static value(value) {
431
450
  return _PromiseAsyncResult.create(Promise.resolve(value));
@@ -1685,6 +1704,118 @@ var Iterator = class _Iterator {
1685
1704
  }
1686
1705
  };
1687
1706
 
1707
+ // sources/Indexable.ts
1708
+ var Indexable = class _Indexable {
1709
+ static create(values) {
1710
+ return List.create(values);
1711
+ }
1712
+ toArray() {
1713
+ return _Indexable.toArray(this);
1714
+ }
1715
+ static toArray(indexable) {
1716
+ return Iterable.toArray(indexable);
1717
+ }
1718
+ any() {
1719
+ return _Indexable.any(this);
1720
+ }
1721
+ static any(indexable) {
1722
+ return Iterable.any(indexable);
1723
+ }
1724
+ getCount() {
1725
+ return _Indexable.getCount(this);
1726
+ }
1727
+ static getCount(indexable) {
1728
+ return Iterable.getCount(indexable);
1729
+ }
1730
+ equals(right, equalFunctions) {
1731
+ return _Indexable.equals(this, right, equalFunctions);
1732
+ }
1733
+ static equals(left, right, equalFunctions) {
1734
+ return Iterable.equals(left, right, equalFunctions);
1735
+ }
1736
+ toString(toStringFunctions) {
1737
+ return _Indexable.toString(this, toStringFunctions);
1738
+ }
1739
+ static toString(indexable, toStringFunctions) {
1740
+ return Iterable.toString(indexable, toStringFunctions);
1741
+ }
1742
+ concatenate(...toConcatenate) {
1743
+ return _Indexable.concatenate(this, ...toConcatenate);
1744
+ }
1745
+ static concatenate(indexable, ...toConcatenate) {
1746
+ return Iterable.concatenate(indexable, ...toConcatenate);
1747
+ }
1748
+ map(mapping) {
1749
+ return _Indexable.map(this, mapping);
1750
+ }
1751
+ static map(indexable, mapping) {
1752
+ return Iterable.map(indexable, mapping);
1753
+ }
1754
+ flatMap(mapping) {
1755
+ return _Indexable.flatMap(this, mapping);
1756
+ }
1757
+ static flatMap(indexable, mapping) {
1758
+ return Iterable.flatMap(indexable, mapping);
1759
+ }
1760
+ where(condition) {
1761
+ return _Indexable.where(this, condition);
1762
+ }
1763
+ static where(indexable, condition) {
1764
+ return Iterable.where(indexable, condition);
1765
+ }
1766
+ instanceOf(typeOrTypeCheck) {
1767
+ return _Indexable.instanceOf(this, typeOrTypeCheck);
1768
+ }
1769
+ static instanceOf(indexable, typeOrTypeCheck) {
1770
+ return Iterable.instanceOf(indexable, typeOrTypeCheck);
1771
+ }
1772
+ first(condition) {
1773
+ return _Indexable.first(this, condition);
1774
+ }
1775
+ static first(indexable, condition) {
1776
+ let result;
1777
+ if (condition) {
1778
+ result = Iterable.first(indexable, condition);
1779
+ } else {
1780
+ if (indexable.any().await()) {
1781
+ result = indexable.get(0);
1782
+ } else {
1783
+ result = SyncResult.error(new EmptyError());
1784
+ }
1785
+ }
1786
+ return result;
1787
+ }
1788
+ last(condition) {
1789
+ return _Indexable.last(this, condition);
1790
+ }
1791
+ static last(indexable, condition) {
1792
+ let result;
1793
+ if (condition) {
1794
+ result = Iterable.last(indexable, condition);
1795
+ } else {
1796
+ const count = indexable.getCount().await();
1797
+ if (count > 0) {
1798
+ result = indexable.get(count - 1);
1799
+ } else {
1800
+ result = SyncResult.error(new EmptyError());
1801
+ }
1802
+ }
1803
+ return result;
1804
+ }
1805
+ [Symbol.iterator]() {
1806
+ return _Indexable[Symbol.iterator](this);
1807
+ }
1808
+ static [Symbol.iterator](indexable) {
1809
+ return Iterable[Symbol.iterator](indexable);
1810
+ }
1811
+ contains(value, equalFunctions) {
1812
+ return _Indexable.contains(this, value, equalFunctions);
1813
+ }
1814
+ static contains(indexable, value, equalFunctions) {
1815
+ return Iterable.contains(indexable, value, equalFunctions);
1816
+ }
1817
+ };
1818
+
1688
1819
  // sources/javascriptArrayList.ts
1689
1820
  var JavascriptArrayList = class _JavascriptArrayList {
1690
1821
  array;
@@ -2633,85 +2764,85 @@ var List = class _List {
2633
2764
  return _List.toArray(this);
2634
2765
  }
2635
2766
  static toArray(list2) {
2636
- return Iterable.toArray(list2);
2767
+ return Indexable.toArray(list2);
2637
2768
  }
2638
2769
  any() {
2639
2770
  return _List.any(this);
2640
2771
  }
2641
2772
  static any(list2) {
2642
- return Iterable.any(list2);
2773
+ return Indexable.any(list2);
2643
2774
  }
2644
2775
  getCount() {
2645
2776
  return _List.getCount(this);
2646
2777
  }
2647
2778
  static getCount(list2) {
2648
- return Iterable.getCount(list2);
2779
+ return Indexable.getCount(list2);
2649
2780
  }
2650
2781
  equals(right, equalFunctions) {
2651
2782
  return _List.equals(this, right, equalFunctions);
2652
2783
  }
2653
2784
  static equals(left, right, equalFunctions) {
2654
- return Iterable.equals(left, right, equalFunctions);
2785
+ return Indexable.equals(left, right, equalFunctions);
2655
2786
  }
2656
2787
  toString(toStringFunctions) {
2657
2788
  return _List.toString(this, toStringFunctions);
2658
2789
  }
2659
2790
  static toString(list2, toStringFunctions) {
2660
- return Iterable.toString(list2, toStringFunctions);
2791
+ return Indexable.toString(list2, toStringFunctions);
2661
2792
  }
2662
2793
  concatenate(...toConcatenate) {
2663
2794
  return _List.concatenate(this, ...toConcatenate);
2664
2795
  }
2665
2796
  static concatenate(list2, ...toConcatenate) {
2666
- return Iterable.concatenate(list2, ...toConcatenate);
2797
+ return Indexable.concatenate(list2, ...toConcatenate);
2667
2798
  }
2668
2799
  map(mapping) {
2669
2800
  return _List.map(this, mapping);
2670
2801
  }
2671
2802
  static map(list2, mapping) {
2672
- return Iterable.map(list2, mapping);
2803
+ return Indexable.map(list2, mapping);
2673
2804
  }
2674
2805
  flatMap(mapping) {
2675
2806
  return _List.flatMap(this, mapping);
2676
2807
  }
2677
2808
  static flatMap(list2, mapping) {
2678
- return Iterable.flatMap(list2, mapping);
2809
+ return Indexable.flatMap(list2, mapping);
2679
2810
  }
2680
2811
  where(condition) {
2681
2812
  return _List.where(this, condition);
2682
2813
  }
2683
2814
  static where(list2, condition) {
2684
- return Iterable.where(list2, condition);
2815
+ return Indexable.where(list2, condition);
2685
2816
  }
2686
2817
  instanceOf(typeOrTypeCheck) {
2687
2818
  return _List.instanceOf(this, typeOrTypeCheck);
2688
2819
  }
2689
2820
  static instanceOf(list2, typeOrTypeCheck) {
2690
- return Iterable.instanceOf(list2, typeOrTypeCheck);
2821
+ return Indexable.instanceOf(list2, typeOrTypeCheck);
2691
2822
  }
2692
2823
  first(condition) {
2693
2824
  return _List.first(this, condition);
2694
2825
  }
2695
2826
  static first(list2, condition) {
2696
- return condition ? Iterable.first(list2, condition) : list2.get(0);
2827
+ return Indexable.first(list2, condition);
2697
2828
  }
2698
2829
  last(condition) {
2699
2830
  return _List.last(this, condition);
2700
2831
  }
2701
2832
  static last(list2, condition) {
2702
- return condition ? Iterable.last(list2, condition) : list2.get(list2.getCount().await() - 1);
2833
+ return Indexable.last(list2, condition);
2703
2834
  }
2704
2835
  [Symbol.iterator]() {
2705
2836
  return _List[Symbol.iterator](this);
2706
2837
  }
2707
2838
  static [Symbol.iterator](list2) {
2708
- return Iterable[Symbol.iterator](list2);
2839
+ return Indexable[Symbol.iterator](list2);
2709
2840
  }
2710
2841
  contains(value, equalFunctions) {
2711
2842
  return _List.contains(this, value, equalFunctions);
2712
2843
  }
2713
2844
  static contains(list2, value, equalFunctions) {
2714
- return Iterable.contains(list2, value, equalFunctions);
2845
+ return Indexable.contains(list2, value, equalFunctions);
2715
2846
  }
2716
2847
  };
2717
2848
 
@@ -3068,7 +3199,7 @@ var WhereIterable = class _WhereIterable {
3068
3199
  // sources/iterable.ts
3069
3200
  var Iterable = class _Iterable {
3070
3201
  static create(values) {
3071
- return List.create(values);
3202
+ return Indexable.create(values);
3072
3203
  }
3073
3204
  [Symbol.iterator]() {
3074
3205
  return _Iterable[Symbol.iterator](this);
@@ -3555,7 +3686,7 @@ var MutableCondition = class _MutableCondition {
3555
3686
  }
3556
3687
  assertNotEmpty(value, expression, message) {
3557
3688
  this.assertNotUndefinedAndNotNull(value, expression, message);
3558
- if (isString(value) && value.length === 0 || isJavascriptIterable(value) && !Iterable.create(value).any()) {
3689
+ if (isString(value) && value.length === 0 || isJavascriptIterable(value) && !Iterable.create(value).any().await()) {
3559
3690
  throw this.createError({
3560
3691
  expected: "not empty",
3561
3692
  actual: this.toValueString(value),
@@ -3921,461 +4052,208 @@ var PreCondition = class _PreCondition {
3921
4052
  }
3922
4053
  };
3923
4054
 
3924
- // tests/test.ts
3925
- var Test = class _Test {
4055
+ // sources/ANSIStyles.ts
4056
+ var ANSIStyles = class {
4057
+ constructor() {
4058
+ }
4059
+ static color(colorCode, text) {
4060
+ return `\x1B[${colorCode}m${text}\x1B[0m`;
4061
+ }
4062
+ static black(text) {
4063
+ return this.color(30, text);
4064
+ }
4065
+ static red(text) {
4066
+ return this.color(31, text);
4067
+ }
4068
+ static green(text) {
4069
+ return this.color(32, text);
4070
+ }
4071
+ static yellow(text) {
4072
+ return this.color(33, text);
4073
+ }
4074
+ static blue(text) {
4075
+ return this.color(34, text);
4076
+ }
4077
+ };
4078
+
4079
+ // sources/asyncResult.ts
4080
+ var AsyncResult = class {
4081
+ static create(actionOrPromise) {
4082
+ return PromiseAsyncResult.create(actionOrPromise);
4083
+ }
3926
4084
  /**
3927
- * Assert that the provided value is undefined;
3928
- * @param value The value to check.
4085
+ * Get an {@link AsyncResult} that is already completed and doesn't do anything.
3929
4086
  */
3930
- assertUndefined(value) {
3931
- _Test.assertUndefined(this, value);
4087
+ static empty() {
4088
+ return PromiseAsyncResult.empty();
3932
4089
  }
3933
4090
  /**
3934
- * Assert that the provided value is undefined.
3935
- * @param test The current {@link Test}.
3936
- * @param value The value to check.
4091
+ * Create a new {@link AsyncResult} that contains the provided value.
4092
+ * @param value The value to wrap in a {@link AsyncResult}.
3937
4093
  */
3938
- static assertUndefined(test2, value) {
3939
- test2.assertSame(value, void 0);
4094
+ static value(value) {
4095
+ return PromiseAsyncResult.value(value);
3940
4096
  }
3941
4097
  /**
3942
- * Assert that the provided value is not undefined;
3943
- * @param value The value to check.
4098
+ * Create a new {@link AsyncResult} that contains the provided error.
4099
+ * @param error The error to wrap in a {@link AsyncResult}.
3944
4100
  */
3945
- assertNotUndefined(value) {
3946
- _Test.assertNotUndefined(this, value);
4101
+ static error(error) {
4102
+ return PromiseAsyncResult.error(error);
4103
+ }
4104
+ static yield() {
4105
+ return PromiseAsyncResult.yield();
4106
+ }
4107
+ };
4108
+
4109
+ // sources/postConditionError.ts
4110
+ var PostConditionError = class extends Error {
4111
+ constructor(...message) {
4112
+ super(join("\n", message));
4113
+ }
4114
+ };
4115
+
4116
+ // sources/postCondition.ts
4117
+ var PostCondition = class _PostCondition {
4118
+ static condition;
4119
+ static getCondition() {
4120
+ if (_PostCondition.condition === void 0) {
4121
+ _PostCondition.condition = MutableCondition.create().setCreateErrorFunction((message) => {
4122
+ return new PostConditionError(message);
4123
+ });
4124
+ }
4125
+ return _PostCondition.condition;
3947
4126
  }
3948
4127
  /**
3949
- * Assert that the provided value is not undefined.
3950
- * @param test The current {@link Test}.
4128
+ * Assert that the provided value is undefined.
3951
4129
  * @param value The value to check.
4130
+ * @param expression The name of the expression that produced the value.
4131
+ * @param message An additional message that will be included with the error.
3952
4132
  */
3953
- static assertNotUndefined(test2, value) {
3954
- test2.assertNotSame(value, void 0);
4133
+ static assertUndefined(value, expression, message) {
4134
+ return _PostCondition.getCondition().assertUndefined(value, expression, message);
3955
4135
  }
3956
4136
  /**
3957
- * Assert that the provided value is null.
4137
+ * Assert that the provided value is not undefined and not null.
3958
4138
  * @param value The value to check.
4139
+ * @param expression The name of the expression that produced the value.
4140
+ * @param message An additional message that will be included with the error.
3959
4141
  */
3960
- assertNull(value) {
3961
- _Test.assertNull(this, value);
4142
+ static assertNotUndefined(value, expression, message) {
4143
+ return _PostCondition.getCondition().assertNotUndefined(value, expression, message);
3962
4144
  }
3963
4145
  /**
3964
- * Assert that the provided value is null.
4146
+ * Assert that the provided value is not undefined and not null.
3965
4147
  * @param value The value to check.
4148
+ * @param expression The name of the expression that produced the value.
4149
+ * @param message An additional message that will be included with the error.
3966
4150
  */
3967
- static assertNull(test2, value) {
3968
- test2.assertSame(value, null);
4151
+ static assertNotUndefinedAndNotNull(value, expression, message) {
4152
+ return _PostCondition.getCondition().assertNotUndefinedAndNotNull(value, expression, message);
3969
4153
  }
3970
4154
  /**
3971
- * Assert that the provided value is not null.
4155
+ * Assert that the provided value is true.
3972
4156
  * @param value The value to check.
4157
+ * @param expression The name of the expression that produced the value.
4158
+ * @param message An additional message that will be included with the error.
3973
4159
  */
3974
- assertNotNull(value) {
3975
- _Test.assertNull(this, value);
4160
+ static assertTrue(value, expression, message) {
4161
+ return _PostCondition.getCondition().assertTrue(value, expression, message);
3976
4162
  }
3977
4163
  /**
3978
- * Assert that the provided value is not null.
4164
+ * Assert that the provided value is false.
3979
4165
  * @param value The value to check.
4166
+ * @param expression The name of the expression that produced the value.
4167
+ * @param message An additional message that will be included with the error.
3980
4168
  */
3981
- static assertNotNull(test2, value) {
3982
- test2.assertNotSame(value, null);
4169
+ static assertFalse(value, expression, message) {
4170
+ return _PostCondition.getCondition().assertFalse(value, expression, message);
3983
4171
  }
3984
4172
  /**
3985
- * Assert that the provided value is not undefined and not null.
3986
- * @param value The value to check.
4173
+ * Assert that the provided actual value is the same as the provided expected value.
4174
+ * @param expected The expected value.
4175
+ * @param actual The actual value.
4176
+ * @param expression The expression that produced the actual value.
4177
+ * @param message An optional message that describes the scenario.
3987
4178
  */
3988
- assertNotUndefinedAndNotNull(value) {
3989
- _Test.assertNotUndefinedAndNotNull(this, value);
4179
+ static assertSame(expected, actual, expression, message) {
4180
+ return _PostCondition.getCondition().assertSame(expected, actual, expression, message);
3990
4181
  }
3991
4182
  /**
3992
- * Assert that the provided value is not undefined and not null.
3993
- * @param value The value to check.
4183
+ * Assert that the provided actual value is not the same as the provided expected value.
4184
+ * @param expected The expected value.
4185
+ * @param actual The actual value.
4186
+ * @param expression The expression that produced the actual value.
4187
+ * @param message An optional message that describes the scenario.
3994
4188
  */
3995
- static assertNotUndefinedAndNotNull(test2, value) {
3996
- test2.assertNotSame(value, null);
3997
- test2.assertNotSame(value, void 0);
4189
+ static assertNotSame(expected, actual, expression, message) {
4190
+ return _PostCondition.getCondition().assertNotSame(expected, actual, expression, message);
3998
4191
  }
3999
4192
  /**
4000
- * Assert that the provided value is false.
4001
- * @param value The value to check.
4193
+ * Assert that the provided actual value is equal to the provided expected value.
4194
+ * @param expected The expected value.
4195
+ * @param actual The actual value.
4196
+ * @param expression The expression that produced the actual value.
4197
+ * @param message An optional message that describes the scenario.
4002
4198
  */
4003
- assertFalse(value) {
4004
- _Test.assertFalse(this, value);
4199
+ static assertEqual(expected, actual, expression, message) {
4200
+ return _PostCondition.getCondition().assertEqual(expected, actual, expression, message);
4005
4201
  }
4006
4202
  /**
4007
- * Assert that the provided value is false.
4203
+ * Assert that the provided actual value is not equal to the provided expected value.
4204
+ * @param notExpected The not expected value.
4205
+ * @param actual The actual value.
4206
+ * @param expression The expression that produced the actual value.
4207
+ * @param message An optional message that describes the scenario.
4208
+ */
4209
+ static assertNotEqual(notExpected, actual, expression, message) {
4210
+ return _PostCondition.getCondition().assertNotEqual(notExpected, actual, expression, message);
4211
+ }
4212
+ /**
4213
+ * Assert that the provided value is not empty.
4008
4214
  * @param value The value to check.
4215
+ * @param expression The expression that produced the actual value.
4216
+ * @param message An optional message that describes the scenario.
4009
4217
  */
4010
- static assertFalse(test2, value) {
4011
- PreCondition.assertNotUndefinedAndNotNull(test2, "test");
4012
- test2.assertSame(value, false);
4218
+ static assertNotEmpty(value, expression, message) {
4219
+ return _PostCondition.getCondition().assertNotEmpty(value, expression, message);
4013
4220
  }
4014
4221
  /**
4015
- * Assert that the provided value is true.
4222
+ * Assert that the provided value is less than the provided upperBound.
4016
4223
  * @param value The value to check.
4224
+ * @param upperBound The upperBound that the value must be less than.
4225
+ * @param expression The expression that produced the actual value.
4226
+ * @param message An optional message that describes the scenario.
4017
4227
  */
4018
- assertTrue(value) {
4019
- _Test.assertTrue(this, value);
4228
+ static assertLessThan(value, upperBound, expression, message) {
4229
+ return _PostCondition.getCondition().assertLessThan(value, upperBound, expression, message);
4020
4230
  }
4021
4231
  /**
4022
- * Assert that the provided value is true.
4232
+ * Assert that the provided value is less than or equal to the provided upperBound.
4023
4233
  * @param value The value to check.
4234
+ * @param upperBound The upperBound that the value must be less than.
4235
+ * @param expression The expression that produced the actual value.
4236
+ * @param message An optional message that describes the scenario.
4024
4237
  */
4025
- static assertTrue(test2, value) {
4026
- PreCondition.assertNotUndefinedAndNotNull(test2, "test");
4027
- test2.assertSame(value, true);
4238
+ static assertLessThanOrEqualTo(value, upperBound, expression, message) {
4239
+ return _PostCondition.getCondition().assertLessThanOrEqualTo(value, upperBound, expression, message);
4028
4240
  }
4029
4241
  /**
4030
- * Assert that the provided value is an instance of the provided {@link Type}.
4242
+ * Assert that the provided value is greater than or equal to the provided lowerBound.
4031
4243
  * @param value The value to check.
4032
- * @param type The {@link Type} to check.
4033
- * @param expression The expression that produced the value.
4034
- * @param message An optional error message.
4244
+ * @param lowerBound The lowerBound that the value must be greater than or equal to.
4245
+ * @param expression The expression that produced the actual value.
4246
+ * @param message An optional message that describes the scenario.
4035
4247
  */
4036
- assertInstanceOf(value, type, typeCheck) {
4037
- return _Test.assertInstanceOf(this, value, type, typeCheck);
4248
+ static assertGreaterThanOrEqualTo(value, lowerBound, expression, message) {
4249
+ return _PostCondition.getCondition().assertGreaterThanOrEqualTo(value, lowerBound, expression, message);
4038
4250
  }
4039
4251
  /**
4040
- * Assert that the provided value is an instance of the provided {@link Type}.
4252
+ * Assert that the provided value is greater than the provided lowerBound.
4041
4253
  * @param value The value to check.
4042
- * @param type The {@link Type} to check.
4043
- * @param expression The expression that produced the value.
4044
- * @param message An optional error message.
4045
- */
4046
- static assertInstanceOf(test2, value, type, typeCheck) {
4047
- PreCondition.assertNotUndefinedAndNotNull(type, "type");
4048
- if (isUndefinedOrNull(typeCheck)) {
4049
- typeCheck = ((value2) => value2 instanceof type);
4050
- }
4051
- if (!typeCheck(value)) {
4052
- test2.fail(`Expected value to be of type ${type.name} but found ${value} instead.`);
4053
- }
4054
- }
4055
- };
4056
-
4057
- // tests/assertTest.ts
4058
- var AssertTest = class _AssertTest {
4059
- name;
4060
- constructor(name) {
4061
- this.name = name;
4062
- }
4063
- /**
4064
- * Create a new {@link AssertTest} object.
4065
- */
4066
- static create(name) {
4067
- return new _AssertTest(name);
4068
- }
4069
- fail(message) {
4070
- PreCondition.assertNotEmpty(message, "message");
4071
- assert.fail(message);
4072
- }
4073
- assertUndefined(value) {
4074
- Test.assertUndefined(this, value);
4075
- }
4076
- assertNotUndefined(value) {
4077
- Test.assertNotUndefined(this, value);
4078
- }
4079
- assertNull(value) {
4080
- Test.assertNull(this, value);
4081
- }
4082
- assertNotNull(value) {
4083
- Test.assertNotNull(this, value);
4084
- }
4085
- assertNotUndefinedAndNotNull(value) {
4086
- Test.assertNotUndefinedAndNotNull(this, value);
4087
- }
4088
- assertSame(left, right) {
4089
- assert.strictEqual(left, right);
4090
- }
4091
- assertNotSame(left, right) {
4092
- assert.notStrictEqual(left, right);
4093
- }
4094
- assertEqual(left, right, message) {
4095
- assert.deepStrictEqual(left, right, message);
4096
- }
4097
- assertNotEqual(left, right) {
4098
- assert.notDeepStrictEqual(left, right);
4099
- }
4100
- assertFalse(value) {
4101
- Test.assertFalse(this, value);
4102
- }
4103
- assertTrue(value) {
4104
- Test.assertTrue(this, value);
4105
- }
4106
- assertThrows(action, expectedError) {
4107
- if (!isFunction(action)) {
4108
- const syncResult = action;
4109
- action = () => {
4110
- syncResult.await();
4111
- };
4112
- }
4113
- assert.throws(action, expectedError);
4114
- }
4115
- assertThrowsAsync(action, expectedError) {
4116
- const promiseOrAsyncAction = isFunction(action) ? async () => await action() : action;
4117
- return PromiseAsyncResult.create(assert.rejects(promiseOrAsyncAction, expectedError));
4118
- }
4119
- assertInstanceOf(value, type, typeCheck) {
4120
- Test.assertInstanceOf(this, value, type, typeCheck);
4121
- }
4122
- };
4123
-
4124
- // tests/assertTestTests.ts
4125
- var import_assert = require("assert");
4126
- function test(runner) {
4127
- runner.testFile("assertTest.ts", () => {
4128
- runner.testType("AssertTest", () => {
4129
- runner.testFunction("assertThrows()", () => {
4130
- runner.test("with throwing action", (test2) => {
4131
- const at = AssertTest.create("fake-test-name");
4132
- at.assertThrows(() => {
4133
- throw new Error("abc");
4134
- }, new Error("abc"));
4135
- });
4136
- runner.test("with non-throwing action", (test2) => {
4137
- const at = AssertTest.create("fake-test-name");
4138
- test2.assertThrows(
4139
- () => at.assertThrows(() => {
4140
- }, new Error("oops")),
4141
- new import_assert.AssertionError({
4142
- message: "Missing expected exception (Error).",
4143
- operator: "throws",
4144
- expected: new Error("oops")
4145
- })
4146
- );
4147
- });
4148
- });
4149
- runner.testFunction("assertThrowsAsync()", () => {
4150
- runner.test("with throwing sync action", async (test2) => {
4151
- const at = AssertTest.create("fake-test-name");
4152
- await at.assertThrowsAsync(() => {
4153
- throw new Error("abc");
4154
- }, new Error("abc"));
4155
- });
4156
- runner.test("with throwing async action", async (test2) => {
4157
- const at = AssertTest.create("fake-test-name");
4158
- await at.assertThrowsAsync(async () => {
4159
- throw new Error("abc");
4160
- }, new Error("abc"));
4161
- });
4162
- runner.test("with rejected Promise", async (test2) => {
4163
- const at = AssertTest.create("fake-test-name");
4164
- await at.assertThrowsAsync(Promise.reject(new Error("abc")), new Error("abc"));
4165
- });
4166
- runner.test("with throwing action that returns a rejected Promise", async (test2) => {
4167
- const at = AssertTest.create("fake-test-name");
4168
- await at.assertThrowsAsync(() => Promise.reject(new Error("abc")), new Error("abc"));
4169
- });
4170
- runner.test("with non-throwing async action", async (test2) => {
4171
- const at = AssertTest.create("fake-test-name");
4172
- await test2.assertThrowsAsync(
4173
- async () => await at.assertThrowsAsync(async () => {
4174
- }, new Error("oops")),
4175
- new import_assert.AssertionError({
4176
- message: "Missing expected rejection (Error).",
4177
- operator: "rejects",
4178
- expected: new Error("oops")
4179
- })
4180
- );
4181
- });
4182
- });
4183
- });
4184
- });
4185
- }
4186
-
4187
- // tests/basicTestSkip.ts
4188
- var BasicTestSkip = class _BasicTestSkip {
4189
- shouldSkip;
4190
- message;
4191
- constructor(shouldSkip, message) {
4192
- PreCondition.assertNotUndefinedAndNotNull(message, "message");
4193
- this.shouldSkip = shouldSkip;
4194
- this.message = message;
4195
- }
4196
- /**
4197
- * Create a new {@link TestSkip} with the provided properties.
4198
- * @param shouldSkip Whether the tests associated with the new {@link TestSkip}
4199
- * should be skipped.
4200
- * @param message The message that explains why the tests associated with this {@link TestSkip}
4201
- * should be skipped.
4202
- */
4203
- static create(shouldSkip, message) {
4204
- if (shouldSkip === void 0 || shouldSkip === null) {
4205
- shouldSkip = true;
4206
- }
4207
- if (message === void 0 || message === null) {
4208
- message = "";
4209
- }
4210
- return new _BasicTestSkip(shouldSkip, message);
4211
- }
4212
- getShouldSkip() {
4213
- return this.shouldSkip;
4214
- }
4215
- getMessage() {
4216
- return this.message;
4217
- }
4218
- };
4219
-
4220
- // sources/commandLineParameters.ts
4221
- var CommandLineParameters = class _CommandLineParameters {
4222
- args;
4223
- constructor(argv) {
4224
- this.args = argv;
4225
- }
4226
- static create(args) {
4227
- return new _CommandLineParameters(args);
4228
- }
4229
- };
4230
-
4231
- // sources/postConditionError.ts
4232
- var PostConditionError = class extends Error {
4233
- constructor(...message) {
4234
- super(join("\n", message));
4235
- }
4236
- };
4237
-
4238
- // sources/postCondition.ts
4239
- var PostCondition = class _PostCondition {
4240
- static condition;
4241
- static getCondition() {
4242
- if (_PostCondition.condition === void 0) {
4243
- _PostCondition.condition = MutableCondition.create().setCreateErrorFunction((message) => {
4244
- return new PostConditionError(message);
4245
- });
4246
- }
4247
- return _PostCondition.condition;
4248
- }
4249
- /**
4250
- * Assert that the provided value is undefined.
4251
- * @param value The value to check.
4252
- * @param expression The name of the expression that produced the value.
4253
- * @param message An additional message that will be included with the error.
4254
- */
4255
- static assertUndefined(value, expression, message) {
4256
- return _PostCondition.getCondition().assertUndefined(value, expression, message);
4257
- }
4258
- /**
4259
- * Assert that the provided value is not undefined and not null.
4260
- * @param value The value to check.
4261
- * @param expression The name of the expression that produced the value.
4262
- * @param message An additional message that will be included with the error.
4263
- */
4264
- static assertNotUndefined(value, expression, message) {
4265
- return _PostCondition.getCondition().assertNotUndefined(value, expression, message);
4266
- }
4267
- /**
4268
- * Assert that the provided value is not undefined and not null.
4269
- * @param value The value to check.
4270
- * @param expression The name of the expression that produced the value.
4271
- * @param message An additional message that will be included with the error.
4272
- */
4273
- static assertNotUndefinedAndNotNull(value, expression, message) {
4274
- return _PostCondition.getCondition().assertNotUndefinedAndNotNull(value, expression, message);
4275
- }
4276
- /**
4277
- * Assert that the provided value is true.
4278
- * @param value The value to check.
4279
- * @param expression The name of the expression that produced the value.
4280
- * @param message An additional message that will be included with the error.
4281
- */
4282
- static assertTrue(value, expression, message) {
4283
- return _PostCondition.getCondition().assertTrue(value, expression, message);
4284
- }
4285
- /**
4286
- * Assert that the provided value is false.
4287
- * @param value The value to check.
4288
- * @param expression The name of the expression that produced the value.
4289
- * @param message An additional message that will be included with the error.
4290
- */
4291
- static assertFalse(value, expression, message) {
4292
- return _PostCondition.getCondition().assertFalse(value, expression, message);
4293
- }
4294
- /**
4295
- * Assert that the provided actual value is the same as the provided expected value.
4296
- * @param expected The expected value.
4297
- * @param actual The actual value.
4298
- * @param expression The expression that produced the actual value.
4299
- * @param message An optional message that describes the scenario.
4300
- */
4301
- static assertSame(expected, actual, expression, message) {
4302
- return _PostCondition.getCondition().assertSame(expected, actual, expression, message);
4303
- }
4304
- /**
4305
- * Assert that the provided actual value is not the same as the provided expected value.
4306
- * @param expected The expected value.
4307
- * @param actual The actual value.
4308
- * @param expression The expression that produced the actual value.
4309
- * @param message An optional message that describes the scenario.
4310
- */
4311
- static assertNotSame(expected, actual, expression, message) {
4312
- return _PostCondition.getCondition().assertNotSame(expected, actual, expression, message);
4313
- }
4314
- /**
4315
- * Assert that the provided actual value is equal to the provided expected value.
4316
- * @param expected The expected value.
4317
- * @param actual The actual value.
4318
- * @param expression The expression that produced the actual value.
4319
- * @param message An optional message that describes the scenario.
4320
- */
4321
- static assertEqual(expected, actual, expression, message) {
4322
- return _PostCondition.getCondition().assertEqual(expected, actual, expression, message);
4323
- }
4324
- /**
4325
- * Assert that the provided actual value is not equal to the provided expected value.
4326
- * @param notExpected The not expected value.
4327
- * @param actual The actual value.
4328
- * @param expression The expression that produced the actual value.
4329
- * @param message An optional message that describes the scenario.
4330
- */
4331
- static assertNotEqual(notExpected, actual, expression, message) {
4332
- return _PostCondition.getCondition().assertNotEqual(notExpected, actual, expression, message);
4333
- }
4334
- /**
4335
- * Assert that the provided value is not empty.
4336
- * @param value The value to check.
4337
- * @param expression The expression that produced the actual value.
4338
- * @param message An optional message that describes the scenario.
4339
- */
4340
- static assertNotEmpty(value, expression, message) {
4341
- return _PostCondition.getCondition().assertNotEmpty(value, expression, message);
4342
- }
4343
- /**
4344
- * Assert that the provided value is less than the provided upperBound.
4345
- * @param value The value to check.
4346
- * @param upperBound The upperBound that the value must be less than.
4347
- * @param expression The expression that produced the actual value.
4348
- * @param message An optional message that describes the scenario.
4349
- */
4350
- static assertLessThan(value, upperBound, expression, message) {
4351
- return _PostCondition.getCondition().assertLessThan(value, upperBound, expression, message);
4352
- }
4353
- /**
4354
- * Assert that the provided value is less than or equal to the provided upperBound.
4355
- * @param value The value to check.
4356
- * @param upperBound The upperBound that the value must be less than.
4357
- * @param expression The expression that produced the actual value.
4358
- * @param message An optional message that describes the scenario.
4359
- */
4360
- static assertLessThanOrEqualTo(value, upperBound, expression, message) {
4361
- return _PostCondition.getCondition().assertLessThanOrEqualTo(value, upperBound, expression, message);
4362
- }
4363
- /**
4364
- * Assert that the provided value is greater than or equal to the provided lowerBound.
4365
- * @param value The value to check.
4366
- * @param lowerBound The lowerBound that the value must be greater than or equal to.
4367
- * @param expression The expression that produced the actual value.
4368
- * @param message An optional message that describes the scenario.
4369
- */
4370
- static assertGreaterThanOrEqualTo(value, lowerBound, expression, message) {
4371
- return _PostCondition.getCondition().assertGreaterThanOrEqualTo(value, lowerBound, expression, message);
4372
- }
4373
- /**
4374
- * Assert that the provided value is greater than the provided lowerBound.
4375
- * @param value The value to check.
4376
- * @param lowerBound The lowerBound that the value must be greater than.
4377
- * @param expression The expression that produced the actual value.
4378
- * @param message An optional message that describes the scenario.
4254
+ * @param lowerBound The lowerBound that the value must be greater than.
4255
+ * @param expression The expression that produced the actual value.
4256
+ * @param message An optional message that describes the scenario.
4379
4257
  */
4380
4258
  static assertGreaterThan(value, lowerBound, expression, message) {
4381
4259
  return _PostCondition.getCondition().assertGreaterThan(value, lowerBound, expression, message);
@@ -4452,30 +4330,293 @@ var PostCondition = class _PostCondition {
4452
4330
  assertInstanceOf(parametersOrValue, type, typeCheck, expression, message) {
4453
4331
  return _PostCondition.getCondition().assertInstanceOf(parametersOrValue, type, typeCheck, expression, message);
4454
4332
  }
4455
- };
4456
-
4457
- // sources/characterWriteStream.ts
4458
- var CharacterWriteStream = class _CharacterWriteStream {
4333
+ };
4334
+
4335
+ // sources/characterWriteStream.ts
4336
+ var CharacterWriteStream = class _CharacterWriteStream {
4337
+ /**
4338
+ * Write the provided text (if provided) and then write a newline character sequence to this
4339
+ * {@link CharacterWriteStream}.
4340
+ * @param text The optional text to write before the newline character sequence.
4341
+ * @returns The number of characters that were written.
4342
+ */
4343
+ writeLine(text) {
4344
+ return _CharacterWriteStream.writeLine(this, text);
4345
+ }
4346
+ static writeLine(writeStream, text) {
4347
+ PreCondition.assertNotUndefinedAndNotNull(writeStream, "writeStream");
4348
+ return PromiseAsyncResult.create(async () => {
4349
+ let result = 0;
4350
+ if (text) {
4351
+ result += await writeStream.writeString(text);
4352
+ }
4353
+ result += await writeStream.writeString("\n");
4354
+ PostCondition.assertGreaterThan(result, 0, "result");
4355
+ return result;
4356
+ });
4357
+ }
4358
+ };
4359
+
4360
+ // sources/IndentedCharacterWriteStream.ts
4361
+ var IndentedCharacterWriteStream = class _IndentedCharacterWriteStream extends CharacterWriteStream {
4362
+ innerStream;
4363
+ currentIndentationList;
4364
+ currentIndentation;
4365
+ singleIndent;
4366
+ atLineStart;
4367
+ constructor(innerStream) {
4368
+ PreCondition.assertNotUndefinedAndNotNull(innerStream, "innerStream");
4369
+ super();
4370
+ this.innerStream = innerStream;
4371
+ this.currentIndentationList = List.create();
4372
+ this.currentIndentation = "";
4373
+ this.singleIndent = " ";
4374
+ this.atLineStart = true;
4375
+ }
4376
+ static create(innerStream) {
4377
+ return new _IndentedCharacterWriteStream(innerStream);
4378
+ }
4379
+ getSingleIndent() {
4380
+ return this.singleIndent;
4381
+ }
4382
+ setSingleIndent(singleIndent) {
4383
+ PreCondition.assertNotUndefinedAndNotNull(singleIndent, "singleIndent");
4384
+ this.singleIndent = singleIndent;
4385
+ return this;
4386
+ }
4387
+ getCurrentIndentationCount() {
4388
+ return this.currentIndentationList.getCount().await();
4389
+ }
4390
+ getCurrentIndentation() {
4391
+ return this.currentIndentation;
4392
+ }
4393
+ addIndentation(singleIndent) {
4394
+ if (isUndefinedOrNull(singleIndent)) {
4395
+ singleIndent = this.singleIndent;
4396
+ }
4397
+ this.currentIndentationList.add(singleIndent);
4398
+ if (singleIndent) {
4399
+ this.currentIndentation = this.currentIndentation + singleIndent;
4400
+ }
4401
+ return this;
4402
+ }
4403
+ removeIndentation() {
4404
+ PreCondition.assertGreaterThanOrEqualTo(this.getCurrentIndentationCount(), 1, "this.getCurrentIndentationCount()");
4405
+ const result = this.currentIndentationList.removeLast().await();
4406
+ if (result) {
4407
+ this.currentIndentation = this.currentIndentation.substring(0, this.currentIndentation.length - result.length);
4408
+ }
4409
+ return result;
4410
+ }
4411
+ indent(actionOrSingleIndent, action) {
4412
+ let singleIndent;
4413
+ if (isString(actionOrSingleIndent)) {
4414
+ singleIndent = actionOrSingleIndent;
4415
+ action = action;
4416
+ } else {
4417
+ action = actionOrSingleIndent;
4418
+ }
4419
+ PreCondition.assertNotUndefinedAndNotNull(action, "action");
4420
+ return AsyncResult.create(async () => {
4421
+ let result;
4422
+ this.addIndentation(singleIndent);
4423
+ try {
4424
+ result = await action();
4425
+ if (!isNumber(result)) {
4426
+ result = 0;
4427
+ }
4428
+ } finally {
4429
+ this.removeIndentation();
4430
+ }
4431
+ return result;
4432
+ });
4433
+ }
4434
+ writeString(text) {
4435
+ return AsyncResult.create(async () => {
4436
+ let result = 0;
4437
+ const textLength = text.length;
4438
+ let startIndex = 0;
4439
+ while (startIndex < textLength) {
4440
+ const newLineCharacterIndex = text.indexOf("\n", startIndex);
4441
+ const atLineStartAfterWrite = newLineCharacterIndex !== -1;
4442
+ const nextLineStartIndex = atLineStartAfterWrite ? newLineCharacterIndex + 1 : textLength;
4443
+ if (newLineCharacterIndex === startIndex || newLineCharacterIndex === startIndex + 1 && text[startIndex] === "\r") {
4444
+ result += await this.innerStream.writeString(text.substring(startIndex, nextLineStartIndex));
4445
+ startIndex = nextLineStartIndex;
4446
+ } else {
4447
+ if (this.atLineStart && this.currentIndentation) {
4448
+ result += await this.innerStream.writeString(this.currentIndentation);
4449
+ }
4450
+ result += await this.innerStream.writeString(text.substring(startIndex, nextLineStartIndex));
4451
+ startIndex = nextLineStartIndex;
4452
+ }
4453
+ this.atLineStart = atLineStartAfterWrite;
4454
+ }
4455
+ return result;
4456
+ });
4457
+ }
4458
+ };
4459
+
4460
+ // sources/english.ts
4461
+ function andList(values) {
4462
+ return list("and", values);
4463
+ }
4464
+ function orList(values) {
4465
+ return list("or", values);
4466
+ }
4467
+ function list(conjunction, values) {
4468
+ PreCondition.assertNotEmpty(conjunction, "conjunction");
4469
+ PreCondition.assertNotUndefinedAndNotNull(values, "values");
4470
+ let result = "";
4471
+ let index = 0;
4472
+ const iterator = Iterator.create(values).start().await();
4473
+ while (iterator.hasCurrent()) {
4474
+ const currentValue = iterator.takeCurrent().await();
4475
+ if (index >= 1) {
4476
+ if (iterator.hasCurrent()) {
4477
+ result += `, `;
4478
+ } else {
4479
+ if (index >= 2) {
4480
+ result += `,`;
4481
+ }
4482
+ result += ` ${conjunction} `;
4483
+ }
4484
+ }
4485
+ result += currentValue;
4486
+ index++;
4487
+ }
4488
+ return result;
4489
+ }
4490
+
4491
+ // sources/commandLineParameters.ts
4492
+ var CommandLineParameters = class _CommandLineParameters {
4493
+ args;
4494
+ parameters;
4495
+ constructor(argv) {
4496
+ PreCondition.assertNotUndefinedAndNotNull(argv, "argv");
4497
+ this.args = isIterable(argv) ? argv : Iterable.create(argv);
4498
+ this.parameters = List.create();
4499
+ }
4500
+ static create(args) {
4501
+ return new _CommandLineParameters(args);
4502
+ }
4503
+ static getArgumentName(arg) {
4504
+ return arg[0] === "-" ? arg.substring(arg[1] === "-" ? 2 : 1) : void 0;
4505
+ }
4506
+ getArguments() {
4507
+ return this.args;
4508
+ }
4509
+ /**
4510
+ * Get the value of the first argument that matches one of the provided names.
4511
+ * @param names The possible names to look for.
4512
+ */
4513
+ getNamedArgumentStringValue(nameOrNames) {
4514
+ PreCondition.assertNotEmpty(nameOrNames, "nameOrNames");
4515
+ return SyncResult.create(() => {
4516
+ let foundArgName = false;
4517
+ let result;
4518
+ if (isString(nameOrNames)) {
4519
+ nameOrNames = [nameOrNames];
4520
+ }
4521
+ const searchNames = Iterable.create(nameOrNames);
4522
+ for (const arg of this.args) {
4523
+ if (!foundArgName) {
4524
+ const argName = _CommandLineParameters.getArgumentName(arg);
4525
+ foundArgName = !!(argName && searchNames.contains(argName));
4526
+ } else {
4527
+ result = arg;
4528
+ break;
4529
+ }
4530
+ }
4531
+ if (result === void 0) {
4532
+ const toStringFunctions = ToStringFunctions.create();
4533
+ throw new NotFoundError(`No argument found that matches ${orList(searchNames.map((n) => toStringFunctions.toString(n)))}.`);
4534
+ }
4535
+ return result;
4536
+ });
4537
+ }
4538
+ nameOrAliasExists(nameOrAlias) {
4539
+ PreCondition.assertNotEmpty(nameOrAlias, "nameOrAlias");
4540
+ let result = false;
4541
+ for (const parameter of this.parameters) {
4542
+ if (parameter.getNameAndAliases().contains(nameOrAlias).await()) {
4543
+ result = true;
4544
+ break;
4545
+ }
4546
+ }
4547
+ return result;
4548
+ }
4549
+ add(name) {
4550
+ const result = CommandLineParameter.create({
4551
+ owner: this,
4552
+ name
4553
+ });
4554
+ this.parameters.add(result);
4555
+ return result;
4556
+ }
4557
+ };
4558
+
4559
+ // sources/commandLineParameter.ts
4560
+ var CommandLineParameter = class _CommandLineParameter {
4561
+ owner;
4562
+ name;
4563
+ aliases;
4564
+ description;
4565
+ constructor(owner, name) {
4566
+ PreCondition.assertNotUndefinedAndNotNull(owner, "owner");
4567
+ PreCondition.assertNotEmpty(name, "name");
4568
+ PreCondition.assertFalse(owner.nameOrAliasExists(name), "owner.nameOrAliasExists(name)");
4569
+ this.owner = owner;
4570
+ this.name = name;
4571
+ }
4572
+ static create(ownerOrProperties, name) {
4573
+ let owner;
4574
+ if (ownerOrProperties instanceof CommandLineParameters) {
4575
+ owner = ownerOrProperties;
4576
+ name = name;
4577
+ } else {
4578
+ owner = ownerOrProperties.owner;
4579
+ name = ownerOrProperties.name;
4580
+ }
4581
+ return new _CommandLineParameter(owner, name);
4582
+ }
4459
4583
  /**
4460
- * Write the provided text (if provided) and then write a newline character sequence to this
4461
- * {@link CharacterWriteStream}.
4462
- * @param text The optional text to write before the newline character sequence.
4463
- * @returns The number of characters that were written.
4584
+ * Get the name of this {@link CommandLineParameter}.
4464
4585
  */
4465
- writeLine(text) {
4466
- return _CharacterWriteStream.writeLine(this, text);
4586
+ getName() {
4587
+ return this.name;
4467
4588
  }
4468
- static writeLine(writeStream, text) {
4469
- PreCondition.assertNotUndefinedAndNotNull(writeStream, "writeStream");
4470
- return PromiseAsyncResult.create(async () => {
4471
- let result = 0;
4472
- if (text) {
4473
- result += await writeStream.writeString(text);
4474
- }
4475
- result += await writeStream.writeString("\n");
4476
- PostCondition.assertGreaterThan(result, 0, "result");
4477
- return result;
4478
- });
4589
+ getAliases() {
4590
+ return this.aliases ?? Iterable.create();
4591
+ }
4592
+ nameOrAliasExists(nameOrAlias) {
4593
+ return this.owner.nameOrAliasExists(nameOrAlias);
4594
+ }
4595
+ addAlias(alias) {
4596
+ PreCondition.assertNotEmpty(alias, "alias");
4597
+ PreCondition.assertFalse(this.nameOrAliasExists(alias), "this.nameOrAliasExists(alias)");
4598
+ if (this.aliases === void 0) {
4599
+ this.aliases = List.create();
4600
+ }
4601
+ this.aliases.add(alias);
4602
+ return this;
4603
+ }
4604
+ addAliases(aliases) {
4605
+ for (const alias of aliases) {
4606
+ this.addAlias(alias);
4607
+ }
4608
+ return this;
4609
+ }
4610
+ getNameAndAliases() {
4611
+ return List.create().add(this.getName()).addAll(this.getAliases());
4612
+ }
4613
+ getDescription() {
4614
+ return this.description ?? "";
4615
+ }
4616
+ setDescription(description) {
4617
+ PreCondition.assertNotUndefinedAndNotNull(description, "description");
4618
+ this.description = description;
4619
+ return this;
4479
4620
  }
4480
4621
  };
4481
4622
 
@@ -4723,580 +4864,953 @@ var HttpHeaders = class _HttpHeaders {
4723
4864
  getCount() {
4724
4865
  return _HttpHeaders.getCount(this);
4725
4866
  }
4726
- static getCount(headers) {
4727
- return Iterable.getCount(headers);
4867
+ static getCount(headers) {
4868
+ return Iterable.getCount(headers);
4869
+ }
4870
+ equals(right, equalFunctions) {
4871
+ return _HttpHeaders.equals(this, right, equalFunctions);
4872
+ }
4873
+ static equals(headers, right, equalFunctions) {
4874
+ return Iterable.equals(headers, right, equalFunctions);
4875
+ }
4876
+ toString(toStringFunctions) {
4877
+ return _HttpHeaders.toString(this, toStringFunctions);
4878
+ }
4879
+ static toString(headers, toStringFunctions) {
4880
+ return Iterable.toString(headers, toStringFunctions);
4881
+ }
4882
+ concatenate(...toConcatenate) {
4883
+ return _HttpHeaders.concatenate(this, ...toConcatenate);
4884
+ }
4885
+ static concatenate(headers, ...toConcatenate) {
4886
+ return Iterable.concatenate(headers, ...toConcatenate);
4887
+ }
4888
+ map(mapping) {
4889
+ return _HttpHeaders.map(this, mapping);
4890
+ }
4891
+ static map(headers, mapping) {
4892
+ return Iterable.map(headers, mapping);
4893
+ }
4894
+ flatMap(mapping) {
4895
+ return _HttpHeaders.flatMap(this, mapping);
4896
+ }
4897
+ static flatMap(headers, mapping) {
4898
+ return Iterable.flatMap(headers, mapping);
4899
+ }
4900
+ where(condition) {
4901
+ return _HttpHeaders.where(this, condition);
4902
+ }
4903
+ static where(headers, condition) {
4904
+ return Iterable.where(headers, condition);
4905
+ }
4906
+ instanceOf(typeOrTypeCheck) {
4907
+ return _HttpHeaders.instanceOf(this, typeOrTypeCheck);
4908
+ }
4909
+ static instanceOf(headers, typeOrTypeCheck) {
4910
+ return Iterable.instanceOf(headers, typeOrTypeCheck);
4911
+ }
4912
+ first(condition) {
4913
+ return _HttpHeaders.first(this, condition);
4914
+ }
4915
+ static first(headers, condition) {
4916
+ return Iterable.first(headers, condition);
4917
+ }
4918
+ last(condition) {
4919
+ return _HttpHeaders.last(this, condition);
4920
+ }
4921
+ static last(headers, condition) {
4922
+ return Iterable.last(headers, condition);
4923
+ }
4924
+ [Symbol.iterator]() {
4925
+ return _HttpHeaders[Symbol.iterator](this);
4926
+ }
4927
+ static [Symbol.iterator](headers) {
4928
+ return Iterable[Symbol.iterator](headers);
4929
+ }
4930
+ contains(value, equalFunctions) {
4931
+ return _HttpHeaders.contains(this, value, equalFunctions);
4932
+ }
4933
+ static contains(headers, value, equalFunctions) {
4934
+ return SyncResult.create(() => {
4935
+ if (!equalFunctions) {
4936
+ equalFunctions = EqualFunctions.create();
4937
+ }
4938
+ return headers.getValue(value.getName()).then((headerValue) => equalFunctions.areEqual(headerValue, value.getValue()).await()).catch(NotFoundError, () => false).await();
4939
+ });
4940
+ }
4941
+ };
4942
+
4943
+ // sources/httpIncomingResponse.ts
4944
+ var HttpIncomingResponse = class {
4945
+ };
4946
+
4947
+ // sources/fetchHttpResponse.ts
4948
+ var FetchHttpIncomingResponse = class _FetchHttpIncomingResponse extends HttpIncomingResponse {
4949
+ response;
4950
+ constructor(response) {
4951
+ PreCondition.assertNotUndefinedAndNotNull(response, "response");
4952
+ super();
4953
+ this.response = response;
4954
+ }
4955
+ static create(response) {
4956
+ return new _FetchHttpIncomingResponse(response);
4957
+ }
4958
+ getStatusCode() {
4959
+ return this.response.status;
4960
+ }
4961
+ getHeaders() {
4962
+ return SyncResult.create(() => {
4963
+ const result = HttpHeaders.create();
4964
+ for (const header of this.response.headers) {
4965
+ result.set(header[0], header[1]);
4966
+ }
4967
+ return result;
4968
+ });
4969
+ }
4970
+ getHeader(headerName) {
4971
+ PreCondition.assertNotEmpty(headerName, "headerName");
4972
+ return SyncResult.create(() => {
4973
+ let result;
4974
+ const lowerHeaderName = headerName.toLowerCase();
4975
+ for (const header of this.response.headers) {
4976
+ if (lowerHeaderName === header[0].toLowerCase()) {
4977
+ result = HttpHeader.create(header[0], header[1]);
4978
+ break;
4979
+ }
4980
+ }
4981
+ if (result === void 0) {
4982
+ throw new NotFoundError(`Could not find a header with the name ${escapeAndQuote(headerName)}.`);
4983
+ }
4984
+ return result;
4985
+ });
4986
+ }
4987
+ getHeaderValue(headerName) {
4988
+ PreCondition.assertNotEmpty(headerName, "headerName");
4989
+ return SyncResult.create(() => {
4990
+ let result;
4991
+ const lowerHeaderName = headerName.toLowerCase();
4992
+ for (const header of this.response.headers) {
4993
+ if (lowerHeaderName === header[0].toLowerCase()) {
4994
+ result = header[1];
4995
+ break;
4996
+ }
4997
+ }
4998
+ if (result === void 0) {
4999
+ throw new NotFoundError(`Could not find a header with the name ${escapeAndQuote(headerName)}.`);
5000
+ }
5001
+ return result;
5002
+ });
5003
+ }
5004
+ getBody() {
5005
+ return PromiseAsyncResult.create(this.response.text());
5006
+ }
5007
+ };
5008
+
5009
+ // sources/httpOutgoingRequest.ts
5010
+ var HttpOutgoingRequest = class _HttpOutgoingRequest {
5011
+ method;
5012
+ url;
5013
+ headers;
5014
+ body;
5015
+ constructor(method, url) {
5016
+ PreCondition.assertNotUndefinedAndNotNull(method, "method");
5017
+ PreCondition.assertNotEmpty(url, "url");
5018
+ this.method = method;
5019
+ this.url = url;
5020
+ this.headers = HttpHeaders.create();
5021
+ this.body = "";
5022
+ }
5023
+ static create(method, url) {
5024
+ return new _HttpOutgoingRequest(method, url);
5025
+ }
5026
+ /**
5027
+ * Create a new {@link HttpOutgoingRequest} with a GET {@link HttpMethod}.
5028
+ * @param url The target URL for the {@link HttpOutgoingRequest}.
5029
+ */
5030
+ static get(url) {
5031
+ return _HttpOutgoingRequest.create(0 /* GET */, url);
5032
+ }
5033
+ /**
5034
+ * Get the {@link HttpMethod} for this {@link HttpOutgoingRequest}.
5035
+ */
5036
+ getMethod() {
5037
+ return this.method;
5038
+ }
5039
+ /**
5040
+ * Set the {@link HttpMethod} for this {@link HttpOutgoingRequest}.
5041
+ * @param method The {@link HttpMethod} for this {@link HttpOutgoingRequest}.
5042
+ */
5043
+ setMethod(method) {
5044
+ PreCondition.assertNotUndefinedAndNotNull(method, "method");
5045
+ this.method = method;
5046
+ return this;
5047
+ }
5048
+ /**
5049
+ * Get this {@link HttpOutgoingRequest}'s target URL.
5050
+ */
5051
+ getURL() {
5052
+ return this.url;
5053
+ }
5054
+ /**
5055
+ * Set the URL that this request will be sent to.
5056
+ * @param url The URL to send this request to.
5057
+ */
5058
+ setURL(url) {
5059
+ PreCondition.assertNotEmpty(url, "url");
5060
+ this.url = url;
5061
+ return this;
5062
+ }
5063
+ /**
5064
+ * Get the {@link HttpHeaders} that will be sent.
5065
+ */
5066
+ getHeaders() {
5067
+ return this.headers;
5068
+ }
5069
+ getHeader(headerName) {
5070
+ return this.headers.get(headerName);
5071
+ }
5072
+ getHeaderValue(headerName) {
5073
+ return this.headers.getValue(headerName);
5074
+ }
5075
+ /**
5076
+ * Get the body that will be sent.
5077
+ */
5078
+ getBody() {
5079
+ return this.body;
5080
+ }
5081
+ setBody(body) {
5082
+ PreCondition.assertNotUndefinedAndNotNull(body, "body");
5083
+ this.body = body;
5084
+ return this;
5085
+ }
5086
+ };
5087
+
5088
+ // sources/fetchHttpClient.ts
5089
+ var FetchHttpClient = class _FetchHttpClient {
5090
+ constructor() {
5091
+ }
5092
+ static create() {
5093
+ return new _FetchHttpClient();
4728
5094
  }
4729
- equals(right, equalFunctions) {
4730
- return _HttpHeaders.equals(this, right, equalFunctions);
5095
+ sendRequest(request) {
5096
+ PreCondition.assertNotUndefinedAndNotNull(request, "request");
5097
+ return PromiseAsyncResult.create(async () => {
5098
+ const requestInit = {
5099
+ method: _FetchHttpClient.convertMethod(request.getMethod()),
5100
+ headers: request.getHeaders().map((header) => [header.getName(), header.getValue()]).toArray().await(),
5101
+ body: request.getBody() || void 0
5102
+ };
5103
+ const fetchResponse = await fetch(request.getURL(), requestInit);
5104
+ return FetchHttpIncomingResponse.create(fetchResponse);
5105
+ });
4731
5106
  }
4732
- static equals(headers, right, equalFunctions) {
4733
- return Iterable.equals(headers, right, equalFunctions);
5107
+ sendGetRequest(url) {
5108
+ return this.sendRequest(HttpOutgoingRequest.create(0 /* GET */, url));
4734
5109
  }
4735
- toString(toStringFunctions) {
4736
- return _HttpHeaders.toString(this, toStringFunctions);
5110
+ static convertMethod(method) {
5111
+ PreCondition.assertNotUndefinedAndNotNull(method, "method");
5112
+ let result;
5113
+ switch (method) {
5114
+ case 5 /* CONNECT */:
5115
+ result = "CONNECT";
5116
+ break;
5117
+ case 4 /* DELETE */:
5118
+ result = "DELETE";
5119
+ break;
5120
+ case 0 /* GET */:
5121
+ result = "GET";
5122
+ break;
5123
+ case 1 /* HEAD */:
5124
+ result = "HEAD";
5125
+ break;
5126
+ case 6 /* OPTIONS */:
5127
+ result = "OPTIONS";
5128
+ break;
5129
+ case 8 /* PATCH */:
5130
+ result = "PATCH";
5131
+ break;
5132
+ case 2 /* POST */:
5133
+ result = "POST";
5134
+ break;
5135
+ case 3 /* PUT */:
5136
+ result = "PUT";
5137
+ break;
5138
+ case 7 /* TRACE */:
5139
+ result = "TRACE";
5140
+ break;
5141
+ }
5142
+ PostCondition.assertNotEmpty(result, "result");
5143
+ return result;
4737
5144
  }
4738
- static toString(headers, toStringFunctions) {
4739
- return Iterable.toString(headers, toStringFunctions);
5145
+ };
5146
+
5147
+ // sources/network.ts
5148
+ var Network = class {
5149
+ };
5150
+
5151
+ // sources/nodeJSHttpServer.ts
5152
+ var http = __toESM(require("http"), 1);
5153
+
5154
+ // sources/httpServer.ts
5155
+ var HttpServer = class {
5156
+ };
5157
+
5158
+ // sources/httpOutgoingResponse.ts
5159
+ var HttpOutgoingResponse = class _HttpOutgoingResponse {
5160
+ statusCode;
5161
+ headers;
5162
+ body;
5163
+ constructor() {
5164
+ this.statusCode = 200;
5165
+ this.headers = MutableHttpHeaders.create();
5166
+ this.body = "";
4740
5167
  }
4741
- concatenate(...toConcatenate) {
4742
- return _HttpHeaders.concatenate(this, ...toConcatenate);
5168
+ static create() {
5169
+ return new _HttpOutgoingResponse();
4743
5170
  }
4744
- static concatenate(headers, ...toConcatenate) {
4745
- return Iterable.concatenate(headers, ...toConcatenate);
5171
+ /**
5172
+ * Get the status code of this {@link HttpOutgoingResponse}.
5173
+ */
5174
+ getStatusCode() {
5175
+ return this.statusCode;
4746
5176
  }
4747
- map(mapping) {
4748
- return _HttpHeaders.map(this, mapping);
5177
+ /**
5178
+ * Set the status code of this {@link HttpOutgoingResponse}.
5179
+ * @param statusCode The status code of this {@link HttpOutgoingResponse}.
5180
+ */
5181
+ setStatusCode(statusCode) {
5182
+ PreCondition.assertBetween(100, statusCode, 599, "statusCode");
5183
+ this.statusCode = statusCode;
5184
+ return this;
4749
5185
  }
4750
- static map(headers, mapping) {
4751
- return Iterable.map(headers, mapping);
5186
+ getHeaders() {
5187
+ return this.headers;
4752
5188
  }
4753
- flatMap(mapping) {
4754
- return _HttpHeaders.flatMap(this, mapping);
5189
+ /**
5190
+ * Get the HTTP header with the provided name or return a {@link NotFoundError} if the header
5191
+ * doesn't exist.
5192
+ * @param headerName The name of the header to get.
5193
+ */
5194
+ getHeader(headerName) {
5195
+ return this.headers.get(headerName);
4755
5196
  }
4756
- static flatMap(headers, mapping) {
4757
- return Iterable.flatMap(headers, mapping);
5197
+ /**
5198
+ * Get the value of the header with the provided name or return a {@link NotFoundError} if the
5199
+ * header doesn't exist.
5200
+ * @param headerName The name of the header value to get.
5201
+ */
5202
+ getHeaderValue(headerName) {
5203
+ return this.headers.getValue(headerName);
4758
5204
  }
4759
- where(condition) {
4760
- return _HttpHeaders.where(this, condition);
5205
+ /**
5206
+ * Set the HTTP header in this {@link HttpOutgoingResponse}.
5207
+ * @param headerName The name of the HTTP header.
5208
+ * @param headerValue The value of the HTTP header.
5209
+ */
5210
+ setHeader(headerName, headerValue) {
5211
+ this.headers.set(headerName, headerValue);
5212
+ return this;
4761
5213
  }
4762
- static where(headers, condition) {
4763
- return Iterable.where(headers, condition);
5214
+ setContentTypeHeader(contentType) {
5215
+ this.headers.setContentType(contentType);
5216
+ return this;
4764
5217
  }
4765
- instanceOf(typeOrTypeCheck) {
4766
- return _HttpHeaders.instanceOf(this, typeOrTypeCheck);
5218
+ /**
5219
+ * Get the body of this {@link HttpOutgoingResponse}.
5220
+ */
5221
+ getBody() {
5222
+ return this.body;
4767
5223
  }
4768
- static instanceOf(headers, typeOrTypeCheck) {
4769
- return Iterable.instanceOf(headers, typeOrTypeCheck);
5224
+ /**
5225
+ * Set the body of this {@link HttpOutgoingResponse}.
5226
+ * @param body The body for this {@link HttpOutgoingResponse}.
5227
+ */
5228
+ setBody(body) {
5229
+ PreCondition.assertNotUndefinedAndNotNull(body, "body");
5230
+ this.body = body;
5231
+ return this;
4770
5232
  }
4771
- first(condition) {
4772
- return _HttpHeaders.first(this, condition);
5233
+ };
5234
+
5235
+ // sources/nodeJSHttpServer.ts
5236
+ var NodeJSHttpServer = class _NodeJSHttpServer extends HttpServer {
5237
+ httpServer;
5238
+ disposed;
5239
+ constructor() {
5240
+ super();
5241
+ this.disposed = false;
4773
5242
  }
4774
- static first(headers, condition) {
4775
- return Iterable.first(headers, condition);
5243
+ static create() {
5244
+ return new _NodeJSHttpServer();
4776
5245
  }
4777
- last(condition) {
4778
- return _HttpHeaders.last(this, condition);
5246
+ dispose() {
5247
+ return PromiseAsyncResult.create(new Promise((resolve, reject) => {
5248
+ if (this.disposed) {
5249
+ resolve(false);
5250
+ } else if (!this.httpServer) {
5251
+ this.disposed = true;
5252
+ resolve(true);
5253
+ } else {
5254
+ this.httpServer.close((error) => {
5255
+ if (error) {
5256
+ reject(error);
5257
+ } else {
5258
+ this.disposed = true;
5259
+ this.httpServer = void 0;
5260
+ resolve(true);
5261
+ }
5262
+ });
5263
+ }
5264
+ }));
4779
5265
  }
4780
- static last(headers, condition) {
4781
- return Iterable.last(headers, condition);
5266
+ isDisposed() {
5267
+ return this.disposed;
4782
5268
  }
4783
- [Symbol.iterator]() {
4784
- return _HttpHeaders[Symbol.iterator](this);
5269
+ isStarted() {
5270
+ return !!this.httpServer;
4785
5271
  }
4786
- static [Symbol.iterator](headers) {
4787
- return Iterable[Symbol.iterator](headers);
5272
+ addRequestHandler(requestPath, handler) {
5273
+ throw new Error("Method not implemented.");
4788
5274
  }
4789
- contains(value, equalFunctions) {
4790
- return _HttpHeaders.contains(this, value, equalFunctions);
5275
+ setDefaultRequestHandler(handler) {
5276
+ throw new Error("Method not implemented.");
4791
5277
  }
4792
- static contains(headers, value, equalFunctions) {
4793
- return SyncResult.create(() => {
4794
- if (!equalFunctions) {
4795
- equalFunctions = EqualFunctions.create();
5278
+ start(portNumber) {
5279
+ PreCondition.assertGreaterThanOrEqualTo(portNumber, 1, "portNumber");
5280
+ PreCondition.assertFalse(this.isDisposed(), "this.isDisposed()");
5281
+ PreCondition.assertUndefined(this.httpServer, "this.httpServer");
5282
+ return PromiseAsyncResult.create(new Promise((resolve, reject) => {
5283
+ if (this.httpServer) {
5284
+ reject(new Error("Can't run a HttpServer multiple times."));
5285
+ } else {
5286
+ this.httpServer = http.createServer();
5287
+ this.httpServer.on("request", (request, response) => {
5288
+ const httpResponse = HttpOutgoingResponse.create().setStatusCode(200).setHeader("Content-Type", "text/plain").setBody("Hello world!");
5289
+ const statusCode = httpResponse.getStatusCode();
5290
+ const headers = httpResponse.getHeaders();
5291
+ const responseHeaders = {};
5292
+ for (const header of headers) {
5293
+ responseHeaders[header.getName()] = header.getValue();
5294
+ }
5295
+ response.writeHead(statusCode, responseHeaders);
5296
+ response.end(httpResponse.getBody());
5297
+ });
5298
+ this.httpServer.on("close", () => {
5299
+ resolve();
5300
+ });
5301
+ this.httpServer.on("error", (error) => {
5302
+ reject(error);
5303
+ });
5304
+ this.httpServer.listen(portNumber);
4796
5305
  }
4797
- return headers.getValue(value.getName()).then((headerValue) => equalFunctions.areEqual(headerValue, value.getValue()).await()).catch(NotFoundError, () => false).await();
4798
- });
5306
+ }));
4799
5307
  }
4800
5308
  };
4801
5309
 
4802
- // sources/httpIncomingResponse.ts
4803
- var HttpIncomingResponse = class {
4804
- };
4805
-
4806
- // sources/fetchHttpResponse.ts
4807
- var FetchHttpIncomingResponse = class _FetchHttpIncomingResponse extends HttpIncomingResponse {
4808
- response;
4809
- constructor(response) {
4810
- PreCondition.assertNotUndefinedAndNotNull(response, "response");
5310
+ // sources/realNetwork.ts
5311
+ var RealNetwork = class _RealNetwork extends Network {
5312
+ constructor() {
4811
5313
  super();
4812
- this.response = response;
4813
5314
  }
4814
- static create(response) {
4815
- return new _FetchHttpIncomingResponse(response);
5315
+ static create() {
5316
+ return new _RealNetwork();
4816
5317
  }
4817
- getStatusCode() {
4818
- return this.response.status;
5318
+ createHttpServer() {
5319
+ return NodeJSHttpServer.create();
4819
5320
  }
4820
- getHeaders() {
4821
- return SyncResult.create(() => {
4822
- const result = HttpHeaders.create();
4823
- for (const header of this.response.headers) {
4824
- result.set(header[0], header[1]);
4825
- }
4826
- return result;
4827
- });
5321
+ createHttpClient() {
5322
+ return FetchHttpClient.create();
4828
5323
  }
4829
- getHeader(headerName) {
4830
- PreCondition.assertNotEmpty(headerName, "headerName");
4831
- return SyncResult.create(() => {
4832
- let result;
4833
- const lowerHeaderName = headerName.toLowerCase();
4834
- for (const header of this.response.headers) {
4835
- if (lowerHeaderName === header[0].toLowerCase()) {
4836
- result = HttpHeader.create(header[0], header[1]);
4837
- break;
4838
- }
4839
- }
4840
- if (result === void 0) {
4841
- throw new NotFoundError(`Could not find a header with the name ${escapeAndQuote(headerName)}.`);
4842
- }
4843
- return result;
4844
- });
5324
+ };
5325
+
5326
+ // sources/currentProcess.ts
5327
+ var CurrentProcess = class _CurrentProcess {
5328
+ args;
5329
+ parameters;
5330
+ outputWriteStream;
5331
+ exitCodeProperty;
5332
+ network;
5333
+ constructor() {
4845
5334
  }
4846
- getHeaderValue(headerName) {
4847
- PreCondition.assertNotEmpty(headerName, "headerName");
4848
- return SyncResult.create(() => {
4849
- let result;
4850
- const lowerHeaderName = headerName.toLowerCase();
4851
- for (const header of this.response.headers) {
4852
- if (lowerHeaderName === header[0].toLowerCase()) {
4853
- result = header[1];
4854
- break;
4855
- }
5335
+ static create() {
5336
+ return new _CurrentProcess();
5337
+ }
5338
+ static async run(action) {
5339
+ PreCondition.assertNotUndefinedAndNotNull(action, "action");
5340
+ const currentProcess = _CurrentProcess.create();
5341
+ try {
5342
+ const result = await action(currentProcess);
5343
+ if (isNumber(result)) {
5344
+ currentProcess.setExitCode(result);
4856
5345
  }
4857
- if (result === void 0) {
4858
- throw new NotFoundError(`Could not find a header with the name ${escapeAndQuote(headerName)}.`);
5346
+ } catch (error) {
5347
+ currentProcess.setExitCode(-1);
5348
+ const writeStream = currentProcess.getOutputWriteStream();
5349
+ if (error instanceof Error && error.stack) {
5350
+ writeStream.writeLine(error.stack);
5351
+ } else {
5352
+ writeStream.writeLine(`${error}`);
4859
5353
  }
4860
- return result;
4861
- });
4862
- }
4863
- getBody() {
4864
- return PromiseAsyncResult.create(this.response.text());
5354
+ }
4865
5355
  }
4866
- };
4867
-
4868
- // sources/httpOutgoingRequest.ts
4869
- var HttpOutgoingRequest = class _HttpOutgoingRequest {
4870
- method;
4871
- url;
4872
- headers;
4873
- body;
4874
- constructor(method, url) {
4875
- PreCondition.assertNotUndefinedAndNotNull(method, "method");
4876
- PreCondition.assertNotEmpty(url, "url");
4877
- this.method = method;
4878
- this.url = url;
4879
- this.headers = HttpHeaders.create();
4880
- this.body = "";
5356
+ getArguments() {
5357
+ if (!this.args) {
5358
+ this.args = Iterable.create(process.argv);
5359
+ }
5360
+ return this.args;
4881
5361
  }
4882
- static create(method, url) {
4883
- return new _HttpOutgoingRequest(method, url);
5362
+ setArguments(args) {
5363
+ PreCondition.assertNotUndefinedAndNotNull(args, "args");
5364
+ PreCondition.assertUndefined(this.parameters, "this.parameters");
5365
+ this.args = isIterable(args) ? args : Iterable.create(args);
5366
+ return this;
4884
5367
  }
4885
- /**
4886
- * Create a new {@link HttpOutgoingRequest} with a GET {@link HttpMethod}.
4887
- * @param url The target URL for the {@link HttpOutgoingRequest}.
4888
- */
4889
- static get(url) {
4890
- return _HttpOutgoingRequest.create(0 /* GET */, url);
5368
+ getParameters() {
5369
+ if (!this.parameters) {
5370
+ this.parameters = CommandLineParameters.create(this.getArguments());
5371
+ }
5372
+ return this.parameters;
4891
5373
  }
4892
- /**
4893
- * Get the {@link HttpMethod} for this {@link HttpOutgoingRequest}.
4894
- */
4895
- getMethod() {
4896
- return this.method;
5374
+ getOutputWriteStream() {
5375
+ if (!this.outputWriteStream) {
5376
+ this.outputWriteStream = NodeJSCharacterWriteStream.create(process.stdout);
5377
+ }
5378
+ return this.outputWriteStream;
4897
5379
  }
4898
- /**
4899
- * Set the {@link HttpMethod} for this {@link HttpOutgoingRequest}.
4900
- * @param method The {@link HttpMethod} for this {@link HttpOutgoingRequest}.
4901
- */
4902
- setMethod(method) {
4903
- PreCondition.assertNotUndefinedAndNotNull(method, "method");
4904
- this.method = method;
5380
+ setOutputWriteStream(outputWriteStream) {
5381
+ PreCondition.assertNotUndefinedAndNotNull(outputWriteStream, "outputWriteStream");
5382
+ this.outputWriteStream = outputWriteStream;
4905
5383
  return this;
4906
5384
  }
4907
- /**
4908
- * Get this {@link HttpOutgoingRequest}'s target URL.
4909
- */
4910
- getURL() {
4911
- return this.url;
5385
+ getExitCode() {
5386
+ return this.getExitCodeProperty().getValue();
4912
5387
  }
4913
- /**
4914
- * Set the URL that this request will be sent to.
4915
- * @param url The URL to send this request to.
4916
- */
4917
- setURL(url) {
4918
- PreCondition.assertNotEmpty(url, "url");
4919
- this.url = url;
5388
+ setExitCode(exitCode) {
5389
+ PreCondition.assertNotUndefinedAndNotNull(exitCode, "exitCode");
5390
+ this.getExitCodeProperty().setValue(exitCode);
4920
5391
  return this;
4921
5392
  }
4922
- /**
4923
- * Get the {@link HttpHeaders} that will be sent.
4924
- */
4925
- getHeaders() {
4926
- return this.headers;
4927
- }
4928
- getHeader(headerName) {
4929
- return this.headers.get(headerName);
5393
+ getExitCodeProperty() {
5394
+ if (!this.exitCodeProperty) {
5395
+ this.exitCodeProperty = Property.create({
5396
+ getter: () => process.exitCode,
5397
+ setter: (value) => {
5398
+ process.exitCode = value;
5399
+ }
5400
+ });
5401
+ }
5402
+ return this.exitCodeProperty;
4930
5403
  }
4931
- getHeaderValue(headerName) {
4932
- return this.headers.getValue(headerName);
5404
+ setExitCodeProperty(exitCodeProperty) {
5405
+ PreCondition.assertNotUndefinedAndNotNull(exitCodeProperty, "exitCodeProperty");
5406
+ this.exitCodeProperty = exitCodeProperty;
5407
+ return this;
4933
5408
  }
4934
- /**
4935
- * Get the body that will be sent.
4936
- */
4937
- getBody() {
4938
- return this.body;
5409
+ getNetwork() {
5410
+ if (!this.network) {
5411
+ this.network = RealNetwork.create();
5412
+ }
5413
+ return this.network;
4939
5414
  }
4940
- setBody(body) {
4941
- PreCondition.assertNotUndefinedAndNotNull(body, "body");
4942
- this.body = body;
5415
+ setNetwork(network) {
5416
+ PreCondition.assertUndefined(this.network, "this.network");
5417
+ PreCondition.assertNotUndefinedAndNotNull(network, "network");
5418
+ this.network = network;
4943
5419
  return this;
4944
5420
  }
4945
5421
  };
4946
5422
 
4947
- // sources/fetchHttpClient.ts
4948
- var FetchHttpClient = class _FetchHttpClient {
4949
- constructor() {
5423
+ // sources/luxonDateTime.ts
5424
+ var luxon = __toESM(require("luxon"), 1);
5425
+
5426
+ // sources/listStack.ts
5427
+ var ListStack = class _ListStack {
5428
+ list;
5429
+ constructor(list2) {
5430
+ this.list = list2 ?? List.create();
4950
5431
  }
4951
- static create() {
4952
- return new _FetchHttpClient();
5432
+ static create(list2) {
5433
+ return new _ListStack(list2);
4953
5434
  }
4954
- sendRequest(request) {
4955
- PreCondition.assertNotUndefinedAndNotNull(request, "request");
4956
- return PromiseAsyncResult.create(async () => {
4957
- const requestInit = {
4958
- method: _FetchHttpClient.convertMethod(request.getMethod()),
4959
- headers: request.getHeaders().map((header) => [header.getName(), header.getValue()]).toArray().await(),
4960
- body: request.getBody() || void 0
4961
- };
4962
- const fetchResponse = await fetch(request.getURL(), requestInit);
4963
- return FetchHttpIncomingResponse.create(fetchResponse);
4964
- });
5435
+ any() {
5436
+ return this.list.any();
4965
5437
  }
4966
- sendGetRequest(url) {
4967
- return this.sendRequest(HttpOutgoingRequest.create(0 /* GET */, url));
5438
+ getCount() {
5439
+ return this.list.getCount();
4968
5440
  }
4969
- static convertMethod(method) {
4970
- PreCondition.assertNotUndefinedAndNotNull(method, "method");
4971
- let result;
4972
- switch (method) {
4973
- case 5 /* CONNECT */:
4974
- result = "CONNECT";
4975
- break;
4976
- case 4 /* DELETE */:
4977
- result = "DELETE";
4978
- break;
4979
- case 0 /* GET */:
4980
- result = "GET";
4981
- break;
4982
- case 1 /* HEAD */:
4983
- result = "HEAD";
4984
- break;
4985
- case 6 /* OPTIONS */:
4986
- result = "OPTIONS";
4987
- break;
4988
- case 8 /* PATCH */:
4989
- result = "PATCH";
4990
- break;
4991
- case 2 /* POST */:
4992
- result = "POST";
4993
- break;
4994
- case 3 /* PUT */:
4995
- result = "PUT";
4996
- break;
4997
- case 7 /* TRACE */:
4998
- result = "TRACE";
4999
- break;
5000
- }
5001
- PostCondition.assertNotEmpty(result, "result");
5002
- return result;
5441
+ add(value) {
5442
+ return SyncResult.create(() => {
5443
+ this.list.add(value);
5444
+ });
5445
+ }
5446
+ addAll(values) {
5447
+ PreCondition.assertNotUndefinedAndNotNull(values, "values");
5448
+ return SyncResult.create(() => {
5449
+ this.list.addAll(values);
5450
+ });
5451
+ }
5452
+ remove() {
5453
+ return SyncResult.create(() => {
5454
+ if (!this.any().await()) {
5455
+ throw new EmptyError();
5456
+ }
5457
+ return this.list.removeLast().await();
5458
+ });
5459
+ }
5460
+ contains(value, equalFunctions) {
5461
+ return this.list.contains(value, equalFunctions);
5003
5462
  }
5004
5463
  };
5005
5464
 
5006
- // sources/network.ts
5007
- var Network = class {
5465
+ // sources/stack.ts
5466
+ var Stack = class {
5467
+ /**
5468
+ * Create an instance of the default {@link Stack} implementation.
5469
+ * @returns A new {@link Stack} object.
5470
+ */
5471
+ static create() {
5472
+ return ListStack.create();
5473
+ }
5008
5474
  };
5009
5475
 
5010
- // sources/nodeJSHttpServer.ts
5011
- var http = __toESM(require("http"), 1);
5012
-
5013
- // sources/httpServer.ts
5014
- var HttpServer = class {
5476
+ // sources/wonderlandTrailClient.ts
5477
+ var WonderlandTrailDirection = class _WonderlandTrailDirection {
5478
+ value;
5479
+ constructor(value) {
5480
+ PreCondition.assertNotEmpty(value, "value");
5481
+ this.value = value;
5482
+ }
5483
+ static clockwise = new _WonderlandTrailDirection("Clockwise");
5484
+ static counterClockwise = new _WonderlandTrailDirection("CounterClockwise");
5485
+ toString() {
5486
+ return this.value;
5487
+ }
5488
+ reverse() {
5489
+ return this === _WonderlandTrailDirection.clockwise ? _WonderlandTrailDirection.counterClockwise : _WonderlandTrailDirection.clockwise;
5490
+ }
5015
5491
  };
5016
5492
 
5017
- // sources/httpOutgoingResponse.ts
5018
- var HttpOutgoingResponse = class _HttpOutgoingResponse {
5019
- statusCode;
5020
- headers;
5021
- body;
5022
- constructor() {
5023
- this.statusCode = 200;
5024
- this.headers = MutableHttpHeaders.create();
5025
- this.body = "";
5026
- }
5027
- static create() {
5028
- return new _HttpOutgoingResponse();
5493
+ // tests/test.ts
5494
+ var Test = class _Test {
5495
+ /**
5496
+ * Assert that the provided value is undefined;
5497
+ * @param value The value to check.
5498
+ */
5499
+ assertUndefined(value) {
5500
+ _Test.assertUndefined(this, value);
5029
5501
  }
5030
5502
  /**
5031
- * Get the status code of this {@link HttpOutgoingResponse}.
5503
+ * Assert that the provided value is undefined.
5504
+ * @param test The current {@link Test}.
5505
+ * @param value The value to check.
5032
5506
  */
5033
- getStatusCode() {
5034
- return this.statusCode;
5507
+ static assertUndefined(test2, value) {
5508
+ test2.assertSame(value, void 0);
5035
5509
  }
5036
5510
  /**
5037
- * Set the status code of this {@link HttpOutgoingResponse}.
5038
- * @param statusCode The status code of this {@link HttpOutgoingResponse}.
5511
+ * Assert that the provided value is not undefined;
5512
+ * @param value The value to check.
5039
5513
  */
5040
- setStatusCode(statusCode) {
5041
- PreCondition.assertBetween(100, statusCode, 599, "statusCode");
5042
- this.statusCode = statusCode;
5043
- return this;
5514
+ assertNotUndefined(value) {
5515
+ _Test.assertNotUndefined(this, value);
5044
5516
  }
5045
- getHeaders() {
5046
- return this.headers;
5517
+ /**
5518
+ * Assert that the provided value is not undefined.
5519
+ * @param test The current {@link Test}.
5520
+ * @param value The value to check.
5521
+ */
5522
+ static assertNotUndefined(test2, value) {
5523
+ test2.assertNotSame(value, void 0);
5047
5524
  }
5048
5525
  /**
5049
- * Get the HTTP header with the provided name or return a {@link NotFoundError} if the header
5050
- * doesn't exist.
5051
- * @param headerName The name of the header to get.
5526
+ * Assert that the provided value is null.
5527
+ * @param value The value to check.
5052
5528
  */
5053
- getHeader(headerName) {
5054
- return this.headers.get(headerName);
5529
+ assertNull(value) {
5530
+ _Test.assertNull(this, value);
5055
5531
  }
5056
5532
  /**
5057
- * Get the value of the header with the provided name or return a {@link NotFoundError} if the
5058
- * header doesn't exist.
5059
- * @param headerName The name of the header value to get.
5533
+ * Assert that the provided value is null.
5534
+ * @param value The value to check.
5060
5535
  */
5061
- getHeaderValue(headerName) {
5062
- return this.headers.getValue(headerName);
5536
+ static assertNull(test2, value) {
5537
+ test2.assertSame(value, null);
5063
5538
  }
5064
5539
  /**
5065
- * Set the HTTP header in this {@link HttpOutgoingResponse}.
5066
- * @param headerName The name of the HTTP header.
5067
- * @param headerValue The value of the HTTP header.
5540
+ * Assert that the provided value is not null.
5541
+ * @param value The value to check.
5068
5542
  */
5069
- setHeader(headerName, headerValue) {
5070
- this.headers.set(headerName, headerValue);
5071
- return this;
5543
+ assertNotNull(value) {
5544
+ _Test.assertNull(this, value);
5072
5545
  }
5073
- setContentTypeHeader(contentType) {
5074
- this.headers.setContentType(contentType);
5075
- return this;
5546
+ /**
5547
+ * Assert that the provided value is not null.
5548
+ * @param value The value to check.
5549
+ */
5550
+ static assertNotNull(test2, value) {
5551
+ test2.assertNotSame(value, null);
5076
5552
  }
5077
5553
  /**
5078
- * Get the body of this {@link HttpOutgoingResponse}.
5554
+ * Assert that the provided value is not undefined and not null.
5555
+ * @param value The value to check.
5079
5556
  */
5080
- getBody() {
5081
- return this.body;
5557
+ assertNotUndefinedAndNotNull(value) {
5558
+ _Test.assertNotUndefinedAndNotNull(this, value);
5082
5559
  }
5083
5560
  /**
5084
- * Set the body of this {@link HttpOutgoingResponse}.
5085
- * @param body The body for this {@link HttpOutgoingResponse}.
5561
+ * Assert that the provided value is not undefined and not null.
5562
+ * @param value The value to check.
5086
5563
  */
5087
- setBody(body) {
5088
- PreCondition.assertNotUndefinedAndNotNull(body, "body");
5089
- this.body = body;
5090
- return this;
5564
+ static assertNotUndefinedAndNotNull(test2, value) {
5565
+ test2.assertNotSame(value, null);
5566
+ test2.assertNotSame(value, void 0);
5091
5567
  }
5092
- };
5093
-
5094
- // sources/nodeJSHttpServer.ts
5095
- var NodeJSHttpServer = class _NodeJSHttpServer extends HttpServer {
5096
- httpServer;
5097
- disposed;
5098
- constructor() {
5099
- super();
5100
- this.disposed = false;
5568
+ /**
5569
+ * Assert that the provided collection is not undefined, not null, and not empty.
5570
+ * @param value The value to check.
5571
+ */
5572
+ assertNotEmpty(value) {
5573
+ _Test.assertNotEmpty(this, value);
5101
5574
  }
5102
- static create() {
5103
- return new _NodeJSHttpServer();
5575
+ static assertNotEmpty(test2, value) {
5576
+ test2.assertNotUndefinedAndNotNull(value);
5577
+ test2.assertTrue(Iterable.any(value).await());
5104
5578
  }
5105
- dispose() {
5106
- return PromiseAsyncResult.create(new Promise((resolve, reject) => {
5107
- if (this.disposed) {
5108
- resolve(false);
5109
- } else if (!this.httpServer) {
5110
- this.disposed = true;
5111
- resolve(true);
5112
- } else {
5113
- this.httpServer.close((error) => {
5114
- if (error) {
5115
- reject(error);
5116
- } else {
5117
- this.disposed = true;
5118
- this.httpServer = void 0;
5119
- resolve(true);
5120
- }
5121
- });
5122
- }
5123
- }));
5579
+ /**
5580
+ * Assert that the provided value is false.
5581
+ * @param value The value to check.
5582
+ */
5583
+ assertFalse(value) {
5584
+ _Test.assertFalse(this, value);
5124
5585
  }
5125
- isDisposed() {
5126
- return this.disposed;
5586
+ static assertFalse(test2, value) {
5587
+ PreCondition.assertNotUndefinedAndNotNull(test2, "test");
5588
+ test2.assertSame(value, false);
5127
5589
  }
5128
- isStarted() {
5129
- return !!this.httpServer;
5590
+ /**
5591
+ * Assert that the provided value is true.
5592
+ * @param value The value to check.
5593
+ */
5594
+ assertTrue(value) {
5595
+ _Test.assertTrue(this, value);
5130
5596
  }
5131
- addRequestHandler(requestPath, handler) {
5132
- throw new Error("Method not implemented.");
5597
+ /**
5598
+ * Assert that the provided value is true.
5599
+ * @param value The value to check.
5600
+ */
5601
+ static assertTrue(test2, value) {
5602
+ PreCondition.assertNotUndefinedAndNotNull(test2, "test");
5603
+ test2.assertSame(value, true);
5133
5604
  }
5134
- setDefaultRequestHandler(handler) {
5135
- throw new Error("Method not implemented.");
5605
+ /**
5606
+ * Assert that the provided value is an instance of the provided {@link Type}.
5607
+ * @param value The value to check.
5608
+ * @param type The {@link Type} to check.
5609
+ * @param expression The expression that produced the value.
5610
+ * @param message An optional error message.
5611
+ */
5612
+ assertInstanceOf(value, type, typeCheck) {
5613
+ return _Test.assertInstanceOf(this, value, type, typeCheck);
5136
5614
  }
5137
- start(portNumber) {
5138
- PreCondition.assertGreaterThanOrEqualTo(portNumber, 1, "portNumber");
5139
- PreCondition.assertFalse(this.isDisposed(), "this.isDisposed()");
5140
- PreCondition.assertUndefined(this.httpServer, "this.httpServer");
5141
- return PromiseAsyncResult.create(new Promise((resolve, reject) => {
5142
- if (this.httpServer) {
5143
- reject(new Error("Can't run a HttpServer multiple times."));
5144
- } else {
5145
- this.httpServer = http.createServer();
5146
- this.httpServer.on("request", (request, response) => {
5147
- const httpResponse = HttpOutgoingResponse.create().setStatusCode(200).setHeader("Content-Type", "text/plain").setBody("Hello world!");
5148
- const statusCode = httpResponse.getStatusCode();
5149
- const headers = httpResponse.getHeaders();
5150
- const responseHeaders = {};
5151
- for (const header of headers) {
5152
- responseHeaders[header.getName()] = header.getValue();
5153
- }
5154
- response.writeHead(statusCode, responseHeaders);
5155
- response.end(httpResponse.getBody());
5156
- });
5157
- this.httpServer.on("close", () => {
5158
- resolve();
5159
- });
5160
- this.httpServer.on("error", (error) => {
5161
- reject(error);
5162
- });
5163
- this.httpServer.listen(portNumber);
5164
- }
5165
- }));
5615
+ /**
5616
+ * Assert that the provided value is an instance of the provided {@link Type}.
5617
+ * @param value The value to check.
5618
+ * @param type The {@link Type} to check.
5619
+ * @param expression The expression that produced the value.
5620
+ * @param message An optional error message.
5621
+ */
5622
+ static assertInstanceOf(test2, value, type, typeCheck) {
5623
+ PreCondition.assertNotUndefinedAndNotNull(type, "type");
5624
+ if (isUndefinedOrNull(typeCheck)) {
5625
+ typeCheck = ((value2) => value2 instanceof type);
5626
+ }
5627
+ if (!typeCheck(value)) {
5628
+ test2.fail(`Expected value to be of type ${type.name} but found ${value} instead.`);
5629
+ }
5166
5630
  }
5167
5631
  };
5168
5632
 
5169
- // sources/realNetwork.ts
5170
- var RealNetwork = class _RealNetwork extends Network {
5171
- constructor() {
5172
- super();
5633
+ // tests/assertTest.ts
5634
+ var AssertTest = class _AssertTest {
5635
+ name;
5636
+ constructor(name) {
5637
+ this.name = name;
5638
+ }
5639
+ /**
5640
+ * Create a new {@link AssertTest} object.
5641
+ */
5642
+ static create(name) {
5643
+ return new _AssertTest(name);
5173
5644
  }
5174
- static create() {
5175
- return new _RealNetwork();
5645
+ fail(message) {
5646
+ PreCondition.assertNotEmpty(message, "message");
5647
+ assert.fail(message);
5176
5648
  }
5177
- createHttpServer() {
5178
- return NodeJSHttpServer.create();
5649
+ assertUndefined(value) {
5650
+ Test.assertUndefined(this, value);
5179
5651
  }
5180
- createHttpClient() {
5181
- return FetchHttpClient.create();
5652
+ assertNotUndefined(value) {
5653
+ Test.assertNotUndefined(this, value);
5182
5654
  }
5183
- };
5184
-
5185
- // sources/currentProcess.ts
5186
- var CurrentProcess = class _CurrentProcess {
5187
- args;
5188
- parameters;
5189
- outputWriteStream;
5190
- exitCodeProperty;
5191
- network;
5192
- constructor() {
5655
+ assertNull(value) {
5656
+ Test.assertNull(this, value);
5193
5657
  }
5194
- static create() {
5195
- return new _CurrentProcess();
5658
+ assertNotNull(value) {
5659
+ Test.assertNotNull(this, value);
5196
5660
  }
5197
- static async run(action) {
5198
- PreCondition.assertNotUndefinedAndNotNull(action, "action");
5199
- const currentProcess = _CurrentProcess.create();
5200
- try {
5201
- const result = await action(currentProcess);
5202
- if (isNumber(result)) {
5203
- currentProcess.setExitCode(result);
5204
- }
5205
- } catch (error) {
5206
- currentProcess.setExitCode(-1);
5207
- const writeStream = currentProcess.getOutputWriteStream();
5208
- if (error instanceof Error && error.stack) {
5209
- writeStream.writeLine(error.stack);
5210
- } else {
5211
- writeStream.writeLine(`${error}`);
5212
- }
5213
- }
5661
+ assertNotUndefinedAndNotNull(value) {
5662
+ Test.assertNotUndefinedAndNotNull(this, value);
5214
5663
  }
5215
- getArguments() {
5216
- if (!this.args) {
5217
- this.args = process.argv;
5218
- }
5219
- return this.args;
5664
+ assertNotEmpty(value) {
5665
+ Test.assertNotEmpty(this, value);
5220
5666
  }
5221
- setArguments(args) {
5222
- PreCondition.assertNotUndefinedAndNotNull(args, "args");
5223
- PreCondition.assertUndefined(this.parameters, "this.parameters");
5224
- this.args = args;
5225
- return this;
5667
+ assertSame(left, right) {
5668
+ assert.strictEqual(left, right);
5226
5669
  }
5227
- getParameters() {
5228
- if (!this.parameters) {
5229
- this.parameters = CommandLineParameters.create(this.getArguments());
5230
- }
5231
- return this.parameters;
5670
+ assertNotSame(left, right) {
5671
+ assert.notStrictEqual(left, right);
5232
5672
  }
5233
- getOutputWriteStream() {
5234
- if (!this.outputWriteStream) {
5235
- this.outputWriteStream = NodeJSCharacterWriteStream.create(process.stdout);
5236
- }
5237
- return this.outputWriteStream;
5673
+ assertEqual(left, right, message) {
5674
+ assert.deepStrictEqual(left, right, message);
5238
5675
  }
5239
- setOutputWriteStream(outputWriteStream) {
5240
- PreCondition.assertNotUndefinedAndNotNull(outputWriteStream, "outputWriteStream");
5241
- this.outputWriteStream = outputWriteStream;
5242
- return this;
5676
+ assertNotEqual(left, right) {
5677
+ assert.notDeepStrictEqual(left, right);
5243
5678
  }
5244
- getExitCode() {
5245
- return this.getExitCodeProperty().getValue();
5679
+ assertFalse(value) {
5680
+ Test.assertFalse(this, value);
5246
5681
  }
5247
- setExitCode(exitCode) {
5248
- PreCondition.assertNotUndefinedAndNotNull(exitCode, "exitCode");
5249
- this.getExitCodeProperty().setValue(exitCode);
5250
- return this;
5682
+ assertTrue(value) {
5683
+ Test.assertTrue(this, value);
5251
5684
  }
5252
- getExitCodeProperty() {
5253
- if (!this.exitCodeProperty) {
5254
- this.exitCodeProperty = Property.create({
5255
- getter: () => process.exitCode,
5256
- setter: (value) => {
5257
- process.exitCode = value;
5258
- }
5259
- });
5685
+ assertThrows(action, expectedError) {
5686
+ if (!isFunction(action)) {
5687
+ const syncResult = action;
5688
+ action = () => {
5689
+ syncResult.await();
5690
+ };
5260
5691
  }
5261
- return this.exitCodeProperty;
5692
+ assert.throws(action, expectedError);
5262
5693
  }
5263
- setExitCodeProperty(exitCodeProperty) {
5264
- PreCondition.assertNotUndefinedAndNotNull(exitCodeProperty, "exitCodeProperty");
5265
- this.exitCodeProperty = exitCodeProperty;
5266
- return this;
5694
+ assertThrowsAsync(action, expectedError) {
5695
+ const promiseOrAsyncAction = isFunction(action) ? async () => await action() : action;
5696
+ return PromiseAsyncResult.create(assert.rejects(promiseOrAsyncAction, expectedError));
5267
5697
  }
5268
- getNetwork() {
5269
- if (!this.network) {
5270
- this.network = RealNetwork.create();
5698
+ assertInstanceOf(value, type, typeCheck) {
5699
+ Test.assertInstanceOf(this, value, type, typeCheck);
5700
+ }
5701
+ };
5702
+
5703
+ // tests/assertTestTests.ts
5704
+ var import_assert = require("assert");
5705
+ function test(runner) {
5706
+ runner.testFile("assertTest.ts", () => {
5707
+ runner.testType("AssertTest", () => {
5708
+ runner.testFunction("assertThrows()", () => {
5709
+ runner.test("with throwing action", (test2) => {
5710
+ const at = AssertTest.create("fake-test-name");
5711
+ at.assertThrows(() => {
5712
+ throw new Error("abc");
5713
+ }, new Error("abc"));
5714
+ });
5715
+ runner.test("with non-throwing action", (test2) => {
5716
+ const at = AssertTest.create("fake-test-name");
5717
+ test2.assertThrows(
5718
+ () => at.assertThrows(() => {
5719
+ }, new Error("oops")),
5720
+ new import_assert.AssertionError({
5721
+ message: "Missing expected exception (Error).",
5722
+ operator: "throws",
5723
+ expected: new Error("oops")
5724
+ })
5725
+ );
5726
+ });
5727
+ });
5728
+ runner.testFunction("assertThrowsAsync()", () => {
5729
+ runner.test("with throwing sync action", async (test2) => {
5730
+ const at = AssertTest.create("fake-test-name");
5731
+ await at.assertThrowsAsync(() => {
5732
+ throw new Error("abc");
5733
+ }, new Error("abc"));
5734
+ });
5735
+ runner.test("with throwing async action", async (test2) => {
5736
+ const at = AssertTest.create("fake-test-name");
5737
+ await at.assertThrowsAsync(async () => {
5738
+ throw new Error("abc");
5739
+ }, new Error("abc"));
5740
+ });
5741
+ runner.test("with rejected Promise", async (test2) => {
5742
+ const at = AssertTest.create("fake-test-name");
5743
+ await at.assertThrowsAsync(Promise.reject(new Error("abc")), new Error("abc"));
5744
+ });
5745
+ runner.test("with throwing action that returns a rejected Promise", async (test2) => {
5746
+ const at = AssertTest.create("fake-test-name");
5747
+ await at.assertThrowsAsync(() => Promise.reject(new Error("abc")), new Error("abc"));
5748
+ });
5749
+ runner.test("with non-throwing async action", async (test2) => {
5750
+ const at = AssertTest.create("fake-test-name");
5751
+ await test2.assertThrowsAsync(
5752
+ async () => await at.assertThrowsAsync(async () => {
5753
+ }, new Error("oops")),
5754
+ new import_assert.AssertionError({
5755
+ message: "Missing expected rejection (Error).",
5756
+ operator: "rejects",
5757
+ expected: new Error("oops")
5758
+ })
5759
+ );
5760
+ });
5761
+ });
5762
+ });
5763
+ });
5764
+ }
5765
+
5766
+ // tests/basicTestSkip.ts
5767
+ var BasicTestSkip = class _BasicTestSkip {
5768
+ shouldSkip;
5769
+ message;
5770
+ constructor(shouldSkip, message) {
5771
+ PreCondition.assertNotUndefinedAndNotNull(message, "message");
5772
+ this.shouldSkip = shouldSkip;
5773
+ this.message = message;
5774
+ }
5775
+ /**
5776
+ * Create a new {@link TestSkip} with the provided properties.
5777
+ * @param shouldSkip Whether the tests associated with the new {@link TestSkip}
5778
+ * should be skipped.
5779
+ * @param message The message that explains why the tests associated with this {@link TestSkip}
5780
+ * should be skipped.
5781
+ */
5782
+ static create(shouldSkip, message) {
5783
+ if (shouldSkip === void 0 || shouldSkip === null) {
5784
+ shouldSkip = true;
5271
5785
  }
5272
- return this.network;
5786
+ if (message === void 0 || message === null) {
5787
+ message = "";
5788
+ }
5789
+ return new _BasicTestSkip(shouldSkip, message);
5273
5790
  }
5274
- setNetwork(network) {
5275
- PreCondition.assertUndefined(this.network, "this.network");
5276
- PreCondition.assertNotUndefinedAndNotNull(network, "network");
5277
- this.network = network;
5278
- return this;
5791
+ getShouldSkip() {
5792
+ return this.shouldSkip;
5793
+ }
5794
+ getMessage() {
5795
+ return this.message;
5279
5796
  }
5280
5797
  };
5281
5798
 
5282
5799
  // tests/failedTest.ts
5283
5800
  var FailedTest = class _FailedTest {
5284
- fullTestNameParts;
5801
+ testAction;
5285
5802
  error;
5286
- constructor(fullTestNameParts, error) {
5287
- PreCondition.assertNotEmpty(fullTestNameParts, "fullTestName");
5803
+ constructor(testAction, error) {
5804
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
5288
5805
  PreCondition.assertNotUndefinedAndNotNull(error, "error");
5289
- this.fullTestNameParts = fullTestNameParts;
5806
+ this.testAction = testAction;
5290
5807
  this.error = error;
5291
5808
  }
5292
- static create(fullTestNameParts, error) {
5293
- return new _FailedTest(fullTestNameParts, error);
5809
+ static create(testAction, error) {
5810
+ return new _FailedTest(testAction, error);
5294
5811
  }
5295
- getFullTestNameParts() {
5296
- return this.fullTestNameParts;
5297
- }
5298
- getFullTestName() {
5299
- return join(" ", this.fullTestNameParts);
5812
+ getTestAction() {
5813
+ return this.testAction;
5300
5814
  }
5301
5815
  getError() {
5302
5816
  return this.error;
@@ -5309,24 +5823,21 @@ var FailedTest = class _FailedTest {
5309
5823
  // tests/skippedTest.ts
5310
5824
  var SkippedTest = class _SkippedTest {
5311
5825
  skip;
5312
- fullTestNameParts;
5313
- constructor(skip, fullTestNameParts) {
5826
+ testAction;
5827
+ constructor(skip, testAction) {
5314
5828
  PreCondition.assertNotUndefinedAndNotNull(skip, "skip");
5315
- PreCondition.assertNotEmpty(fullTestNameParts, "fullTestNameParts");
5829
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
5316
5830
  this.skip = skip;
5317
- this.fullTestNameParts = fullTestNameParts;
5831
+ this.testAction = testAction;
5318
5832
  }
5319
- static create(skip, fullTestNameParts) {
5320
- return new _SkippedTest(skip, fullTestNameParts);
5833
+ static create(skip, testAction) {
5834
+ return new _SkippedTest(skip, testAction);
5321
5835
  }
5322
5836
  getSkipMessage() {
5323
5837
  return this.skip.getMessage();
5324
5838
  }
5325
- getFullTestNameParts() {
5326
- return this.fullTestNameParts;
5327
- }
5328
- getFullTestName() {
5329
- return join(" ", this.fullTestNameParts);
5839
+ getTestAction() {
5840
+ return this.testAction;
5330
5841
  }
5331
5842
  };
5332
5843
 
@@ -5334,18 +5845,21 @@ var SkippedTest = class _SkippedTest {
5334
5845
  var TestAction = class _TestAction {
5335
5846
  parent;
5336
5847
  name;
5848
+ type;
5337
5849
  skip;
5338
5850
  action;
5339
- constructor(parent, name, skip, action) {
5851
+ constructor(parent, name, type, skip, action) {
5340
5852
  PreCondition.assertNotUndefinedAndNotNull(name, "name");
5853
+ PreCondition.assertNotEmpty(type, "type");
5341
5854
  PreCondition.assertNotUndefinedAndNotNull(action, "action");
5342
5855
  this.parent = parent;
5343
5856
  this.name = name;
5857
+ this.type = type;
5344
5858
  this.skip = skip;
5345
5859
  this.action = action;
5346
5860
  }
5347
- static create(parent, name, skip, action) {
5348
- return new _TestAction(parent, name, skip, action);
5861
+ static create(parent, name, type, skip, action) {
5862
+ return new _TestAction(parent, name, type, skip, action);
5349
5863
  }
5350
5864
  getParent() {
5351
5865
  return this.parent;
@@ -5364,6 +5878,9 @@ var TestAction = class _TestAction {
5364
5878
  getFullName() {
5365
5879
  return join(" ", this.getFullNameParts());
5366
5880
  }
5881
+ getType() {
5882
+ return this.type;
5883
+ }
5367
5884
  getSkip() {
5368
5885
  return this.skip || this.parent?.getSkip();
5369
5886
  }
@@ -5375,36 +5892,8 @@ var TestAction = class _TestAction {
5375
5892
  }
5376
5893
  runAsync() {
5377
5894
  return this.action();
5378
- }
5379
- };
5380
-
5381
- // sources/english.ts
5382
- function andList(values) {
5383
- return list("and", values);
5384
- }
5385
- function list(conjunction, values) {
5386
- PreCondition.assertNotEmpty(conjunction, "conjunction");
5387
- PreCondition.assertNotUndefinedAndNotNull(values, "values");
5388
- let result = "";
5389
- let index = 0;
5390
- const iterator = Iterator.create(values).start().await();
5391
- while (iterator.hasCurrent()) {
5392
- const currentValue = iterator.takeCurrent().await();
5393
- if (index >= 1) {
5394
- if (iterator.hasCurrent()) {
5395
- result += `, `;
5396
- } else {
5397
- if (index >= 2) {
5398
- result += `,`;
5399
- }
5400
- result += ` ${conjunction} `;
5401
- }
5402
- }
5403
- result += currentValue;
5404
- index++;
5405
- }
5406
- return result;
5407
- }
5895
+ }
5896
+ };
5408
5897
 
5409
5898
  // tests/testSkip.ts
5410
5899
  var TestSkip = class {
@@ -5475,113 +5964,237 @@ var TestRunner = class _TestRunner {
5475
5964
  static skip(_runner, shouldSkip, message) {
5476
5965
  return TestSkip.create(shouldSkip, message);
5477
5966
  }
5478
- static runTestAction(runner, name, skip, testAction) {
5479
- if (getParameterCount(testAction) === 0) {
5480
- runner.testGroup(name, skip, testAction);
5481
- } else {
5482
- runner.test(name, skip, testAction);
5483
- }
5967
+ };
5968
+
5969
+ // tests/ConsoleTestRunnerUI.ts
5970
+ var ConsoleTestRunnerUI = class {
5971
+ writeStream;
5972
+ styles;
5973
+ constructor() {
5974
+ this.styles = Map2.create();
5484
5975
  }
5485
- testFile(fileName, skipOrTestAction, testAction) {
5486
- _TestRunner.testFile(this, fileName, skipOrTestAction, testAction);
5976
+ static flat() {
5977
+ return FlatConsoleTestRunnerUI.create();
5487
5978
  }
5488
- /**
5489
- * Create a test group that will test the provided file.
5490
- * @param runner The {@link TestRunner} that will run the tests.
5491
- * @param fileName The name of the file that is being tested.
5492
- * @param testAction The action that will run the tests.
5493
- */
5494
- static testFile(runner, fileName, skipOrTestAction, testAction) {
5495
- PreCondition.assertNotUndefinedAndNotNull(runner, "runner");
5496
- PreCondition.assertNotUndefinedAndNotNull(fileName, "fileName");
5497
- PreCondition.assertNotEmpty(fileName, "fileName");
5498
- let skip;
5499
- if (isFunction(skipOrTestAction)) {
5500
- PreCondition.assertUndefined(testAction, "testAction");
5501
- skip = void 0;
5502
- testAction = skipOrTestAction;
5503
- } else {
5504
- skip = skipOrTestAction;
5505
- }
5506
- PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
5507
- _TestRunner.runTestAction(runner, fileName, skip, testAction);
5979
+ static tree() {
5980
+ return TreeConsoleTestRunnerUI.create();
5508
5981
  }
5509
- testType(typeNameOrType, skipOrTestAction, testAction) {
5510
- _TestRunner.testType(this, typeNameOrType, skipOrTestAction, testAction);
5982
+ setWriteStream(writeStream) {
5983
+ PreCondition.assertNotUndefinedAndNotNull(writeStream, "writeStream");
5984
+ this.writeStream = IndentedCharacterWriteStream.create(writeStream);
5985
+ return this;
5511
5986
  }
5512
- /**
5513
- * Create a test group that will test the provided type.
5514
- * @param runner The {@link TestRunner} that will run the tests.
5515
- * @param type The {@link Type} or name of the type that is being tested.
5516
- * @param testAction The action that will run the tests.
5517
- */
5518
- static testType(runner, typeNameOrType, skipOrTestAction, testAction) {
5519
- PreCondition.assertNotUndefinedAndNotNull(runner, "runner");
5520
- PreCondition.assertNotUndefinedAndNotNull(typeNameOrType, "typeNameOrType");
5521
- let typeName;
5522
- if (isString(typeNameOrType)) {
5523
- typeName = typeNameOrType;
5524
- } else {
5525
- typeName = getName(typeNameOrType);
5526
- }
5527
- PreCondition.assertNotEmpty(typeName, "typeName");
5528
- let skip;
5529
- if (isFunction(skipOrTestAction)) {
5530
- PreCondition.assertUndefined(testAction, "testAction");
5531
- skip = void 0;
5532
- testAction = skipOrTestAction;
5533
- } else {
5534
- skip = skipOrTestAction;
5987
+ setStyle(style, styleFunction) {
5988
+ PreCondition.assertNotEmpty(style, "style");
5989
+ PreCondition.assertNotUndefinedAndNotNull(styleFunction, "styleFunction");
5990
+ this.styles.set(style, styleFunction);
5991
+ return this;
5992
+ }
5993
+ setStyles(styles) {
5994
+ PreCondition.assertNotUndefinedAndNotNull(styles, "styles");
5995
+ for (const entry of Object.entries(styles)) {
5996
+ this.setStyle(entry[0], entry[1]);
5535
5997
  }
5998
+ return this;
5999
+ }
6000
+ applyStyle(style, text) {
6001
+ PreCondition.assertNotEmpty(style, "style");
6002
+ PreCondition.assertNotUndefinedAndNotNull(text, "text");
6003
+ const styleFunction = this.styles.get(style).catch(NotFoundError, () => {
6004
+ return (text2) => text2;
6005
+ }).await();
6006
+ return styleFunction(text);
6007
+ }
6008
+ addIndentation() {
6009
+ this.writeStream?.addIndentation();
6010
+ }
6011
+ removeIndentation() {
6012
+ this.writeStream?.removeIndentation();
6013
+ }
6014
+ indent(action) {
6015
+ return this.writeStream?.indent(action) ?? AsyncResult.value(0);
6016
+ }
6017
+ writeString(text) {
6018
+ return this.writeStream?.writeString(text) ?? AsyncResult.value(0);
6019
+ }
6020
+ writeLine(text) {
6021
+ return this.writeStream?.writeLine(text) ?? AsyncResult.value(0);
6022
+ }
6023
+ writeTestActionName(testAction) {
6024
+ return this.writeString(this.applyStyle(testAction.getType(), testAction.getName()));
6025
+ }
6026
+ writeFullTestActionName(testAction) {
6027
+ return AsyncResult.create(async () => {
6028
+ let result = 0;
6029
+ const testActionStack = Stack.create();
6030
+ let currentTestAction = testAction;
6031
+ while (currentTestAction) {
6032
+ testActionStack.add(currentTestAction);
6033
+ currentTestAction = currentTestAction.getParent();
6034
+ }
6035
+ while (await testActionStack.any()) {
6036
+ currentTestAction = await testActionStack.remove();
6037
+ if (currentTestAction.getParent()) {
6038
+ result += await this.writeString(" ");
6039
+ }
6040
+ result += await this.writeTestActionName(currentTestAction);
6041
+ }
6042
+ return result;
6043
+ });
6044
+ }
6045
+ beforeTestGroup(testGroup) {
6046
+ PreCondition.assertNotUndefinedAndNotNull(testGroup, "testGroup");
6047
+ return AsyncResult.empty();
6048
+ }
6049
+ afterTestGroup(testGroup) {
6050
+ PreCondition.assertNotUndefinedAndNotNull(testGroup, "testGroup");
6051
+ return AsyncResult.empty();
6052
+ }
6053
+ beforeTest(testAction) {
6054
+ return AsyncResult.empty();
6055
+ }
6056
+ afterPassedTest(testAction) {
6057
+ return AsyncResult.create(async () => {
6058
+ await this.writeLine(` - ${this.applyStyle("passed", "Passed")}`);
6059
+ });
6060
+ }
6061
+ afterSkippedTest(testAction, skip) {
5536
6062
  PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
5537
- _TestRunner.runTestAction(runner, typeName, skip, testAction);
6063
+ PreCondition.assertNotUndefinedAndNotNull(skip, "skip");
6064
+ return AsyncResult.create(async () => {
6065
+ await this.writeLine(` - ${this.applyStyle("skipped", "Skipped")}`);
6066
+ });
5538
6067
  }
5539
- testFunction(functionSignature, skipOrTestAction, testAction) {
5540
- _TestRunner.testFunction(this, functionSignature, skipOrTestAction, testAction);
6068
+ afterFailedTest(currentTestAction, error) {
6069
+ PreCondition.assertNotUndefinedAndNotNull(currentTestAction, "currentTestAction");
6070
+ PreCondition.assertNotUndefinedAndNotNull(error, "error");
6071
+ return AsyncResult.create(async () => {
6072
+ await this.writeLine(` - ${this.applyStyle("failed", "Failed")}`);
6073
+ });
5541
6074
  }
5542
- /**
5543
- * Create a test group that will test the provided function.
5544
- * @param runner The {@link TestRunner} that will run the tests.
5545
- * @param functionSignature The signature of the function that is being tested.
5546
- * @param testAction The action that will run the tests.
5547
- */
5548
- static testFunction(runner, functionSignature, skipOrTestAction, testAction) {
5549
- PreCondition.assertNotUndefinedAndNotNull(runner, "runner");
5550
- PreCondition.assertNotEmpty(functionSignature, "functionSignature");
5551
- let skip;
5552
- if (isFunction(skipOrTestAction)) {
5553
- PreCondition.assertUndefined(testAction, "testAction");
5554
- skip = void 0;
5555
- testAction = skipOrTestAction;
5556
- } else {
5557
- skip = skipOrTestAction;
5558
- }
6075
+ writeSummary(passedTestCount, skippedTests, failedTests) {
6076
+ PreCondition.assertGreaterThanOrEqualTo(passedTestCount, 0, "passedTestCount");
6077
+ PreCondition.assertNotUndefinedAndNotNull(skippedTests, "skippedTests");
6078
+ PreCondition.assertNotUndefinedAndNotNull(failedTests, "failedTests");
6079
+ return AsyncResult.create(async () => {
6080
+ await this.writeLine();
6081
+ if (await skippedTests.any()) {
6082
+ await this.writeLine(`${this.applyStyle("skipped", "Skipped Tests")}:`);
6083
+ let counter = 0;
6084
+ for (const skippedTest of skippedTests) {
6085
+ await this.writeString(`${++counter}) `);
6086
+ await this.writeFullTestActionName(skippedTest.getTestAction());
6087
+ await this.writeLine();
6088
+ const skipMessage = skippedTest.getSkipMessage();
6089
+ if (skipMessage) {
6090
+ await this.indent(() => this.writeLine(skipMessage));
6091
+ }
6092
+ }
6093
+ await this.writeLine();
6094
+ }
6095
+ if (await failedTests.any()) {
6096
+ await this.writeLine(`${this.applyStyle("failed", "Failed Tests")}:`);
6097
+ let counter = 0;
6098
+ for (const failedTest of failedTests) {
6099
+ await this.writeString(`${++counter}) `);
6100
+ await this.writeFullTestActionName(failedTest.getTestAction());
6101
+ await this.writeLine();
6102
+ await this.indent(() => this.writeLine(failedTest.getErrorMessage()));
6103
+ await this.writeLine();
6104
+ }
6105
+ }
6106
+ if (passedTestCount > 0) {
6107
+ await this.writeLine(`${this.applyStyle("passed", "Passed")}: ${passedTestCount}`);
6108
+ }
6109
+ if (await skippedTests.any()) {
6110
+ await this.writeLine(`${this.applyStyle("skipped", "Skipped")}: ${skippedTests.getCount().await()}`);
6111
+ }
6112
+ if (await failedTests.any()) {
6113
+ await this.writeLine(`${this.applyStyle("failed", "Failed")}: ${failedTests.getCount().await()}`);
6114
+ }
6115
+ });
6116
+ }
6117
+ };
6118
+ var FlatConsoleTestRunnerUI = class _FlatConsoleTestRunnerUI extends ConsoleTestRunnerUI {
6119
+ constructor() {
6120
+ super();
6121
+ }
6122
+ static create() {
6123
+ return new _FlatConsoleTestRunnerUI();
6124
+ }
6125
+ beforeTest(testAction) {
6126
+ return AsyncResult.create(async () => {
6127
+ await this.writeFullTestActionName(testAction);
6128
+ });
6129
+ }
6130
+ };
6131
+ var TreeConsoleTestRunnerUI = class _TreeConsoleTestRunnerUI extends ConsoleTestRunnerUI {
6132
+ testActions;
6133
+ testActionWrittenDepth;
6134
+ constructor() {
6135
+ super();
6136
+ this.testActions = List.create();
6137
+ this.testActionWrittenDepth = 0;
6138
+ }
6139
+ static create() {
6140
+ return new _TreeConsoleTestRunnerUI();
6141
+ }
6142
+ beforeTestGroup(testGroup) {
6143
+ return AsyncResult.create(() => {
6144
+ this.testActions.add(testGroup);
6145
+ });
6146
+ }
6147
+ afterTestGroup(testGroup) {
6148
+ PreCondition.assertNotUndefinedAndNotNull(testGroup, "testGroup");
6149
+ PreCondition.assertTrue(this.testActions.any().await(), "this.testActions.any().await()");
6150
+ return AsyncResult.create(() => {
6151
+ this.testActions.removeLast().await();
6152
+ const testActionCount = this.testActions.getCount().await();
6153
+ if (this.testActionWrittenDepth > testActionCount) {
6154
+ this.testActionWrittenDepth--;
6155
+ this.removeIndentation();
6156
+ }
6157
+ });
6158
+ }
6159
+ beforeTest(testAction) {
5559
6160
  PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
5560
- _TestRunner.runTestAction(runner, functionSignature, skip, testAction);
6161
+ return AsyncResult.create(async () => {
6162
+ const testActionCount = this.testActions.getCount().await();
6163
+ while (this.testActionWrittenDepth < testActionCount) {
6164
+ const testGroup = this.testActions.get(this.testActionWrittenDepth).await();
6165
+ await this.writeTestActionName(testGroup);
6166
+ await this.writeLine();
6167
+ this.addIndentation();
6168
+ this.testActionWrittenDepth++;
6169
+ }
6170
+ await this.writeTestActionName(testAction);
6171
+ });
5561
6172
  }
5562
6173
  };
5563
6174
 
5564
6175
  // tests/consoleTestRunner.ts
5565
- var ConsoleTestRunner = class _ConsoleTestRunner extends TestRunner {
6176
+ var ConsoleTestRunner = class _ConsoleTestRunner {
5566
6177
  writeStream;
5567
- pendingActions;
5568
- pendingActionsInsertIndex;
6178
+ testActions;
6179
+ testActionInsertIndex;
5569
6180
  currentTestAction;
5570
6181
  currentTest;
5571
6182
  passedTestCount;
5572
6183
  skippedTests;
5573
6184
  testFailures;
5574
- constructor() {
5575
- super();
5576
- this.writeStream = NodeJSCharacterWriteStream.create(process.stdout);
5577
- this.pendingActions = List.create();
5578
- this.pendingActionsInsertIndex = 0;
6185
+ ui;
6186
+ constructor(ui) {
6187
+ this.writeStream = IndentedCharacterWriteStream.create(NodeJSCharacterWriteStream.create(process.stdout));
6188
+ this.testActions = List.create();
6189
+ this.testActionInsertIndex = 0;
5579
6190
  this.passedTestCount = 0;
5580
6191
  this.skippedTests = List.create();
5581
6192
  this.testFailures = List.create();
6193
+ this.ui = ui || ConsoleTestRunnerUI.tree();
6194
+ this.ui.setWriteStream(this.writeStream);
5582
6195
  }
5583
- static create() {
5584
- return new _ConsoleTestRunner();
6196
+ static create(ui) {
6197
+ return new _ConsoleTestRunner(ui);
5585
6198
  }
5586
6199
  static run(testFunctionOrTestFunctions) {
5587
6200
  let testFunction;
@@ -5602,7 +6215,15 @@ var ConsoleTestRunner = class _ConsoleTestRunner extends TestRunner {
5602
6215
  };
5603
6216
  }
5604
6217
  return CurrentProcess.run(async (currentProcess) => {
5605
- const runner = _ConsoleTestRunner.create().setWriteStream(currentProcess.getOutputWriteStream());
6218
+ const runner = _ConsoleTestRunner.create().setWriteStream(currentProcess.getOutputWriteStream()).setStyles({
6219
+ file: (t) => ANSIStyles.blue(t),
6220
+ function: (t) => ANSIStyles.blue(t),
6221
+ type: (t) => ANSIStyles.blue(t),
6222
+ group: (t) => ANSIStyles.blue(t),
6223
+ passed: (t) => ANSIStyles.green(`\u2713 ${t}`),
6224
+ skipped: (t) => ANSIStyles.yellow(`\u25CC ${t}`),
6225
+ failed: (t) => ANSIStyles.red(`\u2717 ${t}`)
6226
+ });
5606
6227
  await testFunction(runner);
5607
6228
  await runner.runAsync();
5608
6229
  await runner.printSummary();
@@ -5610,21 +6231,39 @@ var ConsoleTestRunner = class _ConsoleTestRunner extends TestRunner {
5610
6231
  }
5611
6232
  setWriteStream(writeStream) {
5612
6233
  PreCondition.assertNotUndefinedAndNotNull(writeStream, "writeStream");
5613
- this.writeStream = writeStream;
6234
+ this.writeStream = IndentedCharacterWriteStream.create(writeStream);
6235
+ this.ui.setWriteStream(this.writeStream);
6236
+ return this;
6237
+ }
6238
+ setStyle(style, styleFunction) {
6239
+ this.ui.setStyle(style, styleFunction);
6240
+ return this;
6241
+ }
6242
+ setStyles(styles) {
6243
+ this.ui.setStyles(styles);
5614
6244
  return this;
5615
6245
  }
5616
6246
  /**
5617
6247
  * Get the number of {@link TestAction}s that have yet to be executed.
5618
6248
  */
5619
- getPendingTestActionsCount() {
5620
- return this.pendingActions.getCount().await();
6249
+ getTestActionCount() {
6250
+ return this.testActions.getCount().await();
5621
6251
  }
5622
6252
  /**
5623
- * Get the index in the pending-{@link TestAction} stack that new {@link TestAction}s will be
6253
+ * Get the index in the {@link TestAction} list that new {@link TestAction}s will be
5624
6254
  * inserted at.
5625
6255
  */
5626
- getPendingTestActionsInsertIndex() {
5627
- return this.pendingActionsInsertIndex;
6256
+ getTestActionInsertIndex() {
6257
+ return this.testActionInsertIndex;
6258
+ }
6259
+ resetTestActionInsertIndex() {
6260
+ this.testActionInsertIndex = 0;
6261
+ }
6262
+ insertTestAction(testActionName, testActionType, skip, action) {
6263
+ const parentTestAction = this.getCurrentTestAction();
6264
+ const testAction = TestAction.create(parentTestAction, testActionName, testActionType, skip, action);
6265
+ this.testActions.insert(this.testActionInsertIndex, testAction);
6266
+ this.testActionInsertIndex++;
5628
6267
  }
5629
6268
  /**
5630
6269
  * Get the number of tests that have been skipped.
@@ -5658,37 +6297,103 @@ var ConsoleTestRunner = class _ConsoleTestRunner extends TestRunner {
5658
6297
  return this.currentTest;
5659
6298
  }
5660
6299
  assertNoCurrentTest() {
5661
- if (this.currentTest !== void 0) {
6300
+ if (this.currentTest) {
5662
6301
  this.currentTest.fail("Can't start a new test group or a new test while running a test.");
5663
6302
  }
5664
6303
  }
5665
- beforeTest(fullTestNameParts) {
5666
- return PromiseAsyncResult.create(async () => {
5667
- await this.writeStream.writeString(join(" ", fullTestNameParts));
5668
- });
6304
+ beforeTestGroup(testAction) {
6305
+ return this.ui.beforeTestGroup(testAction);
5669
6306
  }
5670
- afterPassedTest() {
5671
- return PromiseAsyncResult.create(async () => {
5672
- await this.writeStream.writeLine(" - Passed");
6307
+ afterTestGroup(testAction) {
6308
+ return this.ui.afterTestGroup(testAction);
6309
+ }
6310
+ beforeTest(testAction) {
6311
+ return this.ui.beforeTest(testAction);
6312
+ }
6313
+ afterPassedTest(testAction) {
6314
+ return AsyncResult.create(async () => {
6315
+ await this.ui.afterPassedTest(testAction);
5673
6316
  this.passedTestCount++;
5674
6317
  });
5675
6318
  }
5676
- afterSkippedTest(fullTestNameParts, skip) {
5677
- PreCondition.assertNotEmpty(fullTestNameParts, "fullTestNameParts");
5678
- PreCondition.assertNotUndefinedAndNotNull(skip, "skip");
5679
- return PromiseAsyncResult.create(async () => {
5680
- this.skippedTests.add(SkippedTest.create(skip, fullTestNameParts));
5681
- await this.writeStream.writeLine(" - Skipped");
6319
+ afterSkippedTest(testAction, skip) {
6320
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
6321
+ return AsyncResult.create(async () => {
6322
+ await this.ui.afterSkippedTest(testAction, skip);
6323
+ this.skippedTests.add(SkippedTest.create(skip, testAction));
5682
6324
  });
5683
6325
  }
5684
- afterFailedTest(fullTestNameParts, error) {
5685
- PreCondition.assertNotEmpty(fullTestNameParts, "fullTestNameParts");
6326
+ afterFailedTest(testAction, error) {
6327
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
5686
6328
  PreCondition.assertNotUndefinedAndNotNull(error, "error");
5687
- return PromiseAsyncResult.create(async () => {
5688
- this.testFailures.add(FailedTest.create(fullTestNameParts, error));
5689
- await this.writeStream.writeLine(" - Failed");
6329
+ return AsyncResult.create(async () => {
6330
+ await this.ui.afterFailedTest(testAction, error);
6331
+ this.testFailures.add(FailedTest.create(testAction, error));
5690
6332
  });
5691
6333
  }
6334
+ andList(values) {
6335
+ return TestRunner.andList(this, values);
6336
+ }
6337
+ toString(value) {
6338
+ return TestRunner.toString(this, value);
6339
+ }
6340
+ skip(messageOrShouldSkip, message) {
6341
+ let shouldSkip;
6342
+ if (!isBoolean(messageOrShouldSkip)) {
6343
+ shouldSkip = true;
6344
+ message = messageOrShouldSkip;
6345
+ } else {
6346
+ shouldSkip = messageOrShouldSkip;
6347
+ }
6348
+ return TestRunner.skip(this, shouldSkip, message);
6349
+ }
6350
+ testFile(fileName, skipOrTestAction, testAction) {
6351
+ PreCondition.assertNotUndefinedAndNotNull(fileName, "fileName");
6352
+ PreCondition.assertNotEmpty(fileName, "fileName");
6353
+ let skip;
6354
+ if (isFunction(skipOrTestAction)) {
6355
+ PreCondition.assertUndefined(testAction, "testAction");
6356
+ skip = void 0;
6357
+ testAction = skipOrTestAction;
6358
+ } else {
6359
+ skip = skipOrTestAction;
6360
+ }
6361
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
6362
+ this.testGroupOrTest(fileName, "file", skip, testAction);
6363
+ }
6364
+ testType(typeNameOrType, skipOrTestAction, testAction) {
6365
+ PreCondition.assertNotUndefinedAndNotNull(typeNameOrType, "typeNameOrType");
6366
+ let typeName;
6367
+ if (isString(typeNameOrType)) {
6368
+ typeName = typeNameOrType;
6369
+ } else {
6370
+ typeName = getName(typeNameOrType);
6371
+ }
6372
+ PreCondition.assertNotEmpty(typeName, "typeName");
6373
+ let skip;
6374
+ if (isFunction(skipOrTestAction)) {
6375
+ PreCondition.assertUndefined(testAction, "testAction");
6376
+ skip = void 0;
6377
+ testAction = skipOrTestAction;
6378
+ } else {
6379
+ skip = skipOrTestAction;
6380
+ }
6381
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
6382
+ this.testGroupOrTest(typeName, "type", skip, testAction);
6383
+ }
6384
+ testFunction(functionSignature, skipOrTestAction, testAction) {
6385
+ PreCondition.assertNotEmpty(functionSignature, "functionSignature");
6386
+ let skip;
6387
+ if (isFunction(skipOrTestAction)) {
6388
+ PreCondition.assertUndefined(testAction, "testAction");
6389
+ skip = void 0;
6390
+ testAction = skipOrTestAction;
6391
+ } else {
6392
+ skip = skipOrTestAction;
6393
+ }
6394
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
6395
+ this.testGroupOrTest(functionSignature, "function", skip, testAction);
6396
+ }
5692
6397
  testGroup(testGroupName, skipOrTestAction, testAction) {
5693
6398
  PreCondition.assertNotUndefinedAndNotNull(testGroupName, "testGroupName");
5694
6399
  PreCondition.assertNotEmpty(testGroupName, "testGroupName");
@@ -5701,27 +6406,7 @@ var ConsoleTestRunner = class _ConsoleTestRunner extends TestRunner {
5701
6406
  skip = skipOrTestAction;
5702
6407
  }
5703
6408
  PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
5704
- this.assertNoCurrentTest();
5705
- this.pendingActions.insert(
5706
- this.pendingActionsInsertIndex,
5707
- TestAction.create(
5708
- this.getCurrentTestAction(),
5709
- testGroupName,
5710
- skip,
5711
- async () => {
5712
- const previousTestActionInsertIndex = this.pendingActionsInsertIndex;
5713
- this.pendingActionsInsertIndex = this.pendingActions.getCount().await();
5714
- const currentTestAction = this.getCurrentTestAction();
5715
- try {
5716
- await testAction();
5717
- } catch (error) {
5718
- await this.afterFailedTest(currentTestAction.getFullNameParts(), error);
5719
- } finally {
5720
- this.pendingActionsInsertIndex = previousTestActionInsertIndex;
5721
- }
5722
- }
5723
- )
5724
- );
6409
+ this.innerTestGroup(testGroupName, "group", skip, testAction);
5725
6410
  }
5726
6411
  test(testName, skipOrTestAction, testAction) {
5727
6412
  PreCondition.assertNotUndefinedAndNotNull(testName, "testName");
@@ -5735,85 +6420,90 @@ var ConsoleTestRunner = class _ConsoleTestRunner extends TestRunner {
5735
6420
  skip = skipOrTestAction;
5736
6421
  }
5737
6422
  PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
6423
+ this.innerTest(testName, "test", skip, testAction);
6424
+ }
6425
+ innerTestGroup(testGroupName, type, skip, testGroupAction) {
6426
+ PreCondition.assertNotEmpty(testGroupName, "testGroupName");
6427
+ PreCondition.assertNotUndefinedAndNotNull(testGroupAction, "testGroupAction");
5738
6428
  this.assertNoCurrentTest();
5739
- this.pendingActions.insert(
5740
- this.pendingActionsInsertIndex,
5741
- TestAction.create(
5742
- this.getCurrentTestAction(),
5743
- testName,
5744
- skip,
5745
- async () => {
5746
- const currentTestAction = this.getCurrentTestAction();
5747
- try {
5748
- await this.beforeTest(currentTestAction.getFullNameParts());
5749
- if (currentTestAction.shouldSkip()) {
5750
- await this.afterSkippedTest(currentTestAction.getFullNameParts(), currentTestAction.getSkip());
5751
- } else {
5752
- this.currentTest = AssertTest.create(testName);
5753
- try {
5754
- await testAction(this.currentTest);
5755
- await this.afterPassedTest();
5756
- } finally {
5757
- this.currentTest = void 0;
5758
- }
6429
+ this.insertTestAction(
6430
+ testGroupName,
6431
+ type,
6432
+ skip,
6433
+ () => this.beforeTestGroup(this.getCurrentTestAction())
6434
+ );
6435
+ this.insertTestAction(
6436
+ testGroupName,
6437
+ type,
6438
+ skip,
6439
+ async () => {
6440
+ this.resetTestActionInsertIndex();
6441
+ try {
6442
+ await testGroupAction();
6443
+ } catch (error) {
6444
+ const currentTestGroupAction = this.getCurrentTestAction();
6445
+ await this.afterFailedTest(currentTestGroupAction, error);
6446
+ }
6447
+ }
6448
+ );
6449
+ this.insertTestAction(
6450
+ testGroupName,
6451
+ type,
6452
+ skip,
6453
+ () => this.afterTestGroup(this.getCurrentTestAction())
6454
+ );
6455
+ }
6456
+ innerTest(testName, testType, skip, testAction) {
6457
+ PreCondition.assertNotEmpty(testName, "testName");
6458
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
6459
+ this.assertNoCurrentTest();
6460
+ this.insertTestAction(
6461
+ testName,
6462
+ testType,
6463
+ skip,
6464
+ async () => {
6465
+ const currentTestAction = this.getCurrentTestAction();
6466
+ try {
6467
+ await this.beforeTest(currentTestAction);
6468
+ const skip2 = currentTestAction.getSkip();
6469
+ if (skip2?.getShouldSkip()) {
6470
+ await this.afterSkippedTest(currentTestAction, skip2);
6471
+ } else {
6472
+ this.currentTest = AssertTest.create(testName);
6473
+ try {
6474
+ await testAction(this.currentTest);
6475
+ } finally {
6476
+ this.currentTest = void 0;
5759
6477
  }
5760
- } catch (error) {
5761
- await this.afterFailedTest(currentTestAction.getFullNameParts(), error);
6478
+ await this.afterPassedTest(currentTestAction);
5762
6479
  }
6480
+ } catch (error) {
6481
+ await this.afterFailedTest(currentTestAction, error);
5763
6482
  }
5764
- )
6483
+ }
5765
6484
  );
5766
6485
  }
6486
+ testGroupOrTest(name, type, skip, testAction) {
6487
+ if (getParameterCount(testAction) === 0) {
6488
+ this.innerTestGroup(name, type, skip, testAction);
6489
+ } else {
6490
+ this.innerTest(name, type, skip, testAction);
6491
+ }
6492
+ }
5767
6493
  async runAsync() {
5768
- while (this.pendingActions.any().await()) {
5769
- this.currentTestAction = this.pendingActions.removeLast().await();
6494
+ while (this.testActions.any().await()) {
6495
+ this.resetTestActionInsertIndex();
6496
+ this.currentTestAction = this.testActions.removeFirst().await();
5770
6497
  try {
5771
- const result = this.currentTestAction.runAsync();
5772
- if (isPromise(result)) {
5773
- await result;
5774
- }
6498
+ await this.currentTestAction.runAsync();
5775
6499
  } finally {
5776
6500
  this.currentTestAction = void 0;
5777
6501
  }
5778
6502
  }
6503
+ this.resetTestActionInsertIndex();
5779
6504
  }
5780
6505
  printSummary() {
5781
- return PromiseAsyncResult.create(async () => {
5782
- await this.writeStream.writeLine();
5783
- const skippedTests = this.getSkippedTests();
5784
- if (await skippedTests.any()) {
5785
- await this.writeStream.writeLine(`Skipped Tests:`);
5786
- let counter = 0;
5787
- for (const skippedTest of skippedTests) {
5788
- await this.writeStream.writeLine(`${++counter}) ${skippedTest.getFullTestName()}`);
5789
- const skipMessage = skippedTest.getSkipMessage();
5790
- if (skipMessage) {
5791
- await this.writeStream.writeLine(` ${skipMessage}`);
5792
- }
5793
- }
5794
- await this.writeStream.writeLine();
5795
- }
5796
- const failedTests = this.getFailedTests();
5797
- if (await failedTests.any()) {
5798
- await this.writeStream.writeLine("Failed Tests:");
5799
- let counter = 0;
5800
- for (const failedTest of failedTests) {
5801
- await this.writeStream.writeLine(`${++counter}) ${failedTest.getFullTestName()}`);
5802
- await this.writeStream.writeLine(` ${failedTest.getErrorMessage()}`);
5803
- await this.writeStream.writeLine();
5804
- }
5805
- }
5806
- const passedTestCount = this.getPassedTestCount();
5807
- if (passedTestCount > 0) {
5808
- await this.writeStream.writeLine(`Passed: ${passedTestCount}`);
5809
- }
5810
- if (await skippedTests.any()) {
5811
- await this.writeStream.writeLine(`Skipped: ${skippedTests.getCount().await()}`);
5812
- }
5813
- if (await failedTests.any()) {
5814
- await this.writeStream.writeLine(`Failed: ${failedTests.getCount().await()}`);
5815
- }
5816
- });
6506
+ return this.ui.writeSummary(this.passedTestCount, this.getSkippedTests(), this.getFailedTests());
5817
6507
  }
5818
6508
  };
5819
6509
  // Annotate the CommonJS export names for ESM import in node: