@fncts/test 0.0.31 → 0.0.33

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. package/_cjs/api.cjs +5 -5
  2. package/_cjs/api.cjs.map +1 -1
  3. package/_cjs/control/AbstractRunnableSpec.cjs +79 -5
  4. package/_cjs/control/AbstractRunnableSpec.cjs.map +1 -1
  5. package/_cjs/control/Annotations/definition.cjs +11 -3
  6. package/_cjs/control/Annotations/definition.cjs.map +1 -1
  7. package/_cjs/control/Assertion/api.cjs +6 -5
  8. package/_cjs/control/Assertion/api.cjs.map +1 -1
  9. package/_cjs/control/DefaultRunnableSpec.cjs +3 -6
  10. package/_cjs/control/DefaultRunnableSpec.cjs.map +1 -1
  11. package/_cjs/control/DefaultTestReporter/render.cjs +1 -1
  12. package/_cjs/control/DefaultTestReporter/render.cjs.map +1 -1
  13. package/_cjs/control/Gen/api.cjs +240 -81
  14. package/_cjs/control/Gen/api.cjs.map +1 -1
  15. package/_cjs/control/Live/definition.cjs +9 -8
  16. package/_cjs/control/Live/definition.cjs.map +1 -1
  17. package/_cjs/control/Sample/api.cjs +16 -16
  18. package/_cjs/control/Sample/api.cjs.map +1 -1
  19. package/_cjs/control/Spec/api.cjs +7 -7
  20. package/_cjs/control/Spec/api.cjs.map +1 -1
  21. package/_cjs/control/TestAnnotationRenderer/api.cjs +6 -5
  22. package/_cjs/control/TestAnnotationRenderer/api.cjs.map +1 -1
  23. package/_cjs/control/TestAspect/api.cjs +2 -3
  24. package/_cjs/control/TestAspect/api.cjs.map +1 -1
  25. package/_cjs/control/TestClock/definition.cjs +6 -6
  26. package/_cjs/control/TestClock/definition.cjs.map +1 -1
  27. package/_cjs/data/AssertionResult.cjs +3 -2
  28. package/_cjs/data/AssertionResult.cjs.map +1 -1
  29. package/_cjs/data/AssertionValue/definition.cjs +2 -1
  30. package/_cjs/data/AssertionValue/definition.cjs.map +1 -1
  31. package/_cjs/data/FreeBooleanAlgebra/api.cjs +5 -4
  32. package/_cjs/data/FreeBooleanAlgebra/api.cjs.map +1 -1
  33. package/_cjs/data/TestAnnotation/api.cjs +3 -2
  34. package/_cjs/data/TestAnnotation/api.cjs.map +1 -1
  35. package/_cjs/data/TestAnnotationMap.cjs.map +1 -1
  36. package/_cjs/demo.cjs +3 -1
  37. package/_cjs/demo.cjs.map +1 -1
  38. package/_mjs/api.mjs +5 -5
  39. package/_mjs/api.mjs.map +1 -1
  40. package/_mjs/control/AbstractRunnableSpec.mjs +78 -5
  41. package/_mjs/control/AbstractRunnableSpec.mjs.map +1 -1
  42. package/_mjs/control/Annotations/definition.mjs +8 -1
  43. package/_mjs/control/Annotations/definition.mjs.map +1 -1
  44. package/_mjs/control/Assertion/api.mjs +6 -5
  45. package/_mjs/control/Assertion/api.mjs.map +1 -1
  46. package/_mjs/control/DefaultRunnableSpec.mjs +3 -6
  47. package/_mjs/control/DefaultRunnableSpec.mjs.map +1 -1
  48. package/_mjs/control/DefaultTestReporter/render.mjs +1 -1
  49. package/_mjs/control/DefaultTestReporter/render.mjs.map +1 -1
  50. package/_mjs/control/Gen/api.mjs +219 -73
  51. package/_mjs/control/Gen/api.mjs.map +1 -1
  52. package/_mjs/control/Live/definition.mjs +10 -8
  53. package/_mjs/control/Live/definition.mjs.map +1 -1
  54. package/_mjs/control/Sample/api.mjs +16 -16
  55. package/_mjs/control/Sample/api.mjs.map +1 -1
  56. package/_mjs/control/Spec/api.mjs +7 -7
  57. package/_mjs/control/Spec/api.mjs.map +1 -1
  58. package/_mjs/control/TestAnnotationRenderer/api.mjs +6 -5
  59. package/_mjs/control/TestAnnotationRenderer/api.mjs.map +1 -1
  60. package/_mjs/control/TestAspect/api.mjs +2 -3
  61. package/_mjs/control/TestAspect/api.mjs.map +1 -1
  62. package/_mjs/control/TestClock/definition.mjs +6 -6
  63. package/_mjs/control/TestClock/definition.mjs.map +1 -1
  64. package/_mjs/data/AssertionResult.mjs +3 -2
  65. package/_mjs/data/AssertionResult.mjs.map +1 -1
  66. package/_mjs/data/AssertionValue/definition.mjs +2 -1
  67. package/_mjs/data/AssertionValue/definition.mjs.map +1 -1
  68. package/_mjs/data/FreeBooleanAlgebra/api.mjs +5 -4
  69. package/_mjs/data/FreeBooleanAlgebra/api.mjs.map +1 -1
  70. package/_mjs/data/TestAnnotation/api.mjs +3 -2
  71. package/_mjs/data/TestAnnotation/api.mjs.map +1 -1
  72. package/_mjs/data/TestAnnotationMap.mjs +2 -1
  73. package/_mjs/data/TestAnnotationMap.mjs.map +1 -1
  74. package/_mjs/demo.mjs +3 -1
  75. package/_mjs/demo.mjs.map +1 -1
  76. package/_src/api.ts +2 -2
  77. package/_src/control/AbstractRunnableSpec.ts +93 -11
  78. package/_src/control/Annotations/definition.ts +4 -0
  79. package/_src/control/DefaultRunnableSpec.ts +3 -7
  80. package/_src/control/Gen/api.ts +201 -7
  81. package/_src/control/Live/definition.ts +8 -9
  82. package/_src/control/TestAspect/api.ts +2 -2
  83. package/_src/demo.ts +4 -2
  84. package/api.d.ts +1 -1
  85. package/control/AbstractRunnableSpec.d.ts +22 -9
  86. package/control/Annotations/definition.d.ts +3 -0
  87. package/control/DefaultRunnableSpec.d.ts +4 -4
  88. package/control/Gen/api.d.ts +70 -1
  89. package/control/Live/definition.d.ts +6 -2
  90. package/package.json +3 -3
  91. package/_cjs/control/RunnableSpec.cjs +0 -52
  92. package/_cjs/control/RunnableSpec.cjs.map +0 -1
  93. package/_cjs/control/TestExecutor.cjs +0 -44
  94. package/_cjs/control/TestExecutor.cjs.map +0 -1
  95. package/_cjs/control/TestRunner.cjs +0 -28
  96. package/_cjs/control/TestRunner.cjs.map +0 -1
  97. package/_mjs/control/RunnableSpec.mjs +0 -42
  98. package/_mjs/control/RunnableSpec.mjs.map +0 -1
  99. package/_mjs/control/TestExecutor.mjs +0 -36
  100. package/_mjs/control/TestExecutor.mjs.map +0 -1
  101. package/_mjs/control/TestRunner.mjs +0 -19
  102. package/_mjs/control/TestRunner.mjs.map +0 -1
  103. package/_src/control/RunnableSpec.ts +0 -47
  104. package/_src/control/TestExecutor.ts +0 -52
  105. package/_src/control/TestRunner.ts +0 -31
  106. package/control/RunnableSpec.d.ts +0 -11
  107. package/control/TestExecutor.d.ts +0 -12
  108. package/control/TestRunner.d.ts +0 -17
@@ -1,10 +1,16 @@
1
- import type { EqConstraint, FloatConstraints, LengthConstraints, NumberConstraints } from "./constraints.js";
1
+ import type {
2
+ DateConstraints,
3
+ EqConstraint,
4
+ FloatConstraints,
5
+ LengthConstraints,
6
+ NumberConstraints,
7
+ ObjectConstraints,
8
+ } from "./constraints.js";
2
9
  import type { _A, _R } from "@fncts/base/types.js";
3
10
  import type { ArrayInt64 } from "@fncts/base/util/rand";
4
11
 
5
12
  import { SortedMap } from "@fncts/base/collection/immutable/SortedMap";
6
13
  import { IllegalArgumentError, NoSuchElementError } from "@fncts/base/data/exceptions";
7
- import { tuple } from "@fncts/base/data/function";
8
14
  import { identity } from "@fncts/base/data/function";
9
15
 
10
16
  import {
@@ -27,6 +33,89 @@ import { Gen } from "./definition.js";
27
33
 
28
34
  const gapSize = 0xdfff + 1 - 0xd800;
29
35
 
36
+ /**
37
+ * @tsplus static fncts.test.GenOps anything
38
+ */
39
+ export function anything<C extends ObjectConstraints>(
40
+ constraints: C = {} as C,
41
+ ): Gen<
42
+ ObjectConstraints extends C
43
+ ? Sized
44
+ : unknown extends C["key"]
45
+ ? Sized
46
+ : _R<C["key"]> | C["values"] extends Array<infer A>
47
+ ? _R<A>
48
+ : Sized,
49
+ unknown
50
+ > {
51
+ const key = constraints.key ?? Gen.alphaNumericString;
52
+ const maxDepth = constraints.maxDepth ?? 2;
53
+ const maxKeys = constraints.maxKeys ?? 5;
54
+ const values = constraints.values ?? [
55
+ Gen.boolean,
56
+ Gen.alphaNumericString,
57
+ Gen.double,
58
+ Gen.int,
59
+ Gen.oneOf(Gen.alphaNumericString, Gen.constant(null), Gen.constant(undefined)),
60
+ ];
61
+
62
+ function mapOf<R, K, R1, V>(key: Gen<R, K>, value: Gen<R1, V>) {
63
+ return Gen.tuple(key, value)
64
+ .uniqueConc({
65
+ eq: Eq({
66
+ equals:
67
+ ([k1]) =>
68
+ ([k]) =>
69
+ Equatable.strictEquals(k, k1),
70
+ }),
71
+ maxLength: maxKeys,
72
+ })
73
+ .map((pairs) => new Map(pairs));
74
+ }
75
+
76
+ function setOf<R, V>(value: Gen<R, V>) {
77
+ return value
78
+ .uniqueConc({ eq: Eq({ equals: (v1) => (v) => Equatable.strictEquals(v, v1) }), maxLength: maxKeys })
79
+ .map((values) => new Set(values));
80
+ }
81
+
82
+ const base = Gen.oneOf(...values);
83
+ const arrayBase = Gen.oneOf(...values.map((gen) => gen.arrayWith({ maxLength: maxKeys })));
84
+ const arrayGen = Gen.memo((n) => Gen.oneOf(arrayBase, gen(n).arrayWith({ maxLength: maxKeys })));
85
+ const objectBase = Gen.oneOf(...values.map((gen) => Gen.record(key, gen)));
86
+ const objectGen = Gen.memo((n) => Gen.oneOf(objectBase, Gen.record(key, gen(n))));
87
+ const setBase = Gen.oneOf(...values.map(setOf));
88
+ const setGen = Gen.memo((n) => Gen.oneOf(setBase, setOf(gen(n))));
89
+ const mapBase = Gen.oneOf(...values.map((value) => mapOf(key, value)));
90
+ const mapGen = Gen.memo((n) => Gen.oneOf(mapBase, mapOf(Gen.oneOf(key, gen(n)), gen(n))));
91
+
92
+ const gen: (n: number) => Gen<any, any> = Gen.memo((n) => {
93
+ if (n <= 0) return base;
94
+ return Gen.oneOf(
95
+ base,
96
+ arrayGen(),
97
+ objectGen(),
98
+ ...(constraints.withDate ? [Gen.date()] : []),
99
+ ...(constraints.withSet ? [setGen()] : []),
100
+ ...(constraints.withMap ? [mapGen()] : []),
101
+ ...(constraints.withTypedArray
102
+ ? [
103
+ Gen.oneOf(
104
+ Gen.int8Array(),
105
+ Gen.uint8Array(),
106
+ Gen.int16Array(),
107
+ Gen.uint16Array(),
108
+ Gen.int32Array(),
109
+ Gen.uint32Array(),
110
+ ),
111
+ ]
112
+ : []),
113
+ );
114
+ });
115
+
116
+ return gen(maxDepth);
117
+ }
118
+
30
119
  /**
31
120
  * @tsplus static fncts.test.GenOps size
32
121
  */
@@ -59,6 +148,7 @@ export function alphaNumericStringWith(constraints: LengthConstraints = {}): Gen
59
148
  export const alphaNumericString: Gen<Sized, string> = alphaNumericChar.string();
60
149
 
61
150
  /**
151
+ * @tsplus static fncts.test.GenOps array
62
152
  * @tsplus getter fncts.test.Gen array
63
153
  */
64
154
  export function array<R, A>(self: Gen<R, A>): Gen<R | Sized, ReadonlyArray<A>> {
@@ -183,6 +273,7 @@ export function concWith(constraints: LengthConstraints = {}) {
183
273
 
184
274
  /**
185
275
  * @tsplus getter fncts.test.Gen conc
276
+ * @tsplus static fncts.test.GenOps conc
186
277
  */
187
278
  export function conc<R, A>(self: Gen<R, A>): Gen<R | Sized, Conc<A>> {
188
279
  return self.conc();
@@ -347,6 +438,11 @@ export function floatWith(constraints: NumberConstraints & FloatConstraints = {}
347
438
  );
348
439
  }
349
440
 
441
+ /**
442
+ * @tsplus static fncts.test.GenOps float
443
+ */
444
+ export const float: Gen<never, number> = floatWith();
445
+
350
446
  /**
351
447
  * @tsplus static fncts.test.GenOps fullUnicodeChar
352
448
  */
@@ -463,6 +559,9 @@ export function oneOf<A extends ReadonlyArray<Gen<any, any>>>(...gens: A): Gen<_
463
559
  else return Gen.intWith({ min: 0, max: gens.length - 1 }).flatMap((i) => gens[i]!);
464
560
  }
465
561
 
562
+ /**
563
+ * @tsplus static fncts.test.GenOps partial
564
+ */
466
565
  export function partial<P extends Record<string, Gen<any, any>>>(
467
566
  properties: P,
468
567
  ): Gen<
@@ -540,6 +639,9 @@ export function stringN(n: number) {
540
639
  };
541
640
  }
542
641
 
642
+ /**
643
+ * @tsplus static fncts.test.GenOps struct
644
+ */
543
645
  export function struct<P extends Record<string, Gen<any, any>>>(
544
646
  properties: P,
545
647
  ): Gen<
@@ -626,10 +728,13 @@ export function unwrap<R, R1, A>(effect: URIO<R, Gen<R1, A>>): Gen<R | R1, A> {
626
728
  */
627
729
  export function weighted<R, A>(...gens: ReadonlyArray<readonly [Gen<R, A>, number]>): Gen<R, A> {
628
730
  const sum = gens.map(([, weight]) => weight).foldLeft(0, (b, a) => b + a);
629
- const [map] = gens.foldLeft(tuple(SortedMap.make<number, Gen<R, A>>(Number.Ord), 0), ([map, acc], [gen, d]) => {
630
- if ((acc + d) / sum > acc / sum) return tuple(map.set((acc + d) / sum, gen), acc + d);
631
- else return tuple(map, acc);
632
- });
731
+ const [map] = gens.foldLeft(
732
+ Function.tuple(SortedMap.make<number, Gen<R, A>>(Number.Ord), 0),
733
+ ([map, acc], [gen, d]) => {
734
+ if ((acc + d) / sum > acc / sum) return Function.tuple(map.set((acc + d) / sum, gen), acc + d);
735
+ else return Function.tuple(map, acc);
736
+ },
737
+ );
633
738
  return Gen.uniform.flatMap((n) =>
634
739
  map.getGte(n).getOrElse(() => {
635
740
  throw new NoSuchElementError("Gen.weighted");
@@ -651,10 +756,99 @@ export function zipWith<A, R1, B, C>(that: Gen<R1, B>, f: (a: A, b: B) => C) {
651
756
  */
652
757
  export function zip<R1, B>(that: Gen<R1, B>) {
653
758
  return <R, A>(self: Gen<R, A>): Gen<R | R1, readonly [A, B]> => {
654
- return self.zipWith(that, tuple);
759
+ return self.zipWith(that, Function.tuple);
655
760
  };
656
761
  }
657
762
 
763
+ /**
764
+ * @tsplus static fncts.test.GenOps tuple
765
+ */
766
+ export function tuple<A extends [...Gen<any, any>[]]>(
767
+ ...components: A
768
+ ): Gen<
769
+ { [K in keyof A]: [A[K]] extends [Gen<infer R, any>] ? R : never }[keyof A & number],
770
+ { [K in keyof A]: [A[K]] extends [Gen<any, infer A>] ? A : never }
771
+ > {
772
+ return components.foldLeft(Gen.constant<Array<any>>([]) as Gen<any, ReadonlyArray<any>>, (b, a) =>
773
+ b.zipWith(a, (vs, v) => [...vs, v]),
774
+ ) as any;
775
+ }
776
+
777
+ /**
778
+ * @tsplus static fncts.test.GenOps record
779
+ */
780
+ export function record<R, R1, A>(
781
+ key: Gen<R, string>,
782
+ value: Gen<R1, A>,
783
+ constraints?: LengthConstraints,
784
+ ): Gen<Sized | R | R1, Record<string, A>> {
785
+ return Gen.tuple(key, value)
786
+ .uniqueConc({ eq: String.Eq.contramap(([k]) => k), ...constraints })
787
+ .map((pairs) => pairs.foldLeft({} as Record<string, A>, (b, [k, v]) => ({ ...b, [k]: v })));
788
+ }
789
+
790
+ /**
791
+ * @tsplus static fncts.test.GenOps date
792
+ */
793
+ export function date(constraints: DateConstraints = {}): Gen<never, Date> {
794
+ const min = constraints.min ? constraints.min.getTime() : -8_640_000_000_000_000;
795
+ const max = constraints.max ? constraints.max.getTime() : 8_640_000_000_000_000;
796
+ return Gen.intWith({ min, max }).map((n) => new Date(n));
797
+ }
798
+
799
+ function typedArray<A>(
800
+ constraints: LengthConstraints & NumberConstraints,
801
+ minBound: number,
802
+ maxBound: number,
803
+ ctor: { new (arg: ReadonlyArray<number>): A },
804
+ ): Gen<Sized, A> {
805
+ const min = constraints.min ? clamp(constraints.min, minBound, maxBound) : minBound;
806
+ const max = constraints.max ? clamp(constraints.max, minBound, maxBound) : maxBound;
807
+ return Gen.array(Gen.intWith({ min, max })).map((n) => new ctor(n));
808
+ }
809
+
810
+ /**
811
+ * @tsplus static fncts.test.GenOps int8Array
812
+ */
813
+ export function int8Array(constraints: LengthConstraints & NumberConstraints = {}): Gen<Sized, Int8Array> {
814
+ return typedArray(constraints, -128, 127, Int8Array);
815
+ }
816
+
817
+ /**
818
+ * @tsplus static fncts.test.GenOps int16Array
819
+ */
820
+ export function int16Array(constraints: LengthConstraints & NumberConstraints = {}): Gen<Sized, Int16Array> {
821
+ return typedArray(constraints, -32768, 32767, Int16Array);
822
+ }
823
+
824
+ /**
825
+ * @tsplus static fncts.test.GenOps int32Array
826
+ */
827
+ export function int32Array(constraints: LengthConstraints & NumberConstraints = {}): Gen<Sized, Int32Array> {
828
+ return typedArray(constraints, -0x80000000, 0x7fffffff, Int32Array);
829
+ }
830
+
831
+ /**
832
+ * @tsplus static fncts.test.GenOps uint8Array
833
+ */
834
+ export function uint8Array(constraints: LengthConstraints & NumberConstraints = {}): Gen<Sized, Uint8Array> {
835
+ return typedArray(constraints, 0, 255, Uint8Array);
836
+ }
837
+
838
+ /**
839
+ * @tsplus static fncts.test.GenOps uint16Array
840
+ */
841
+ export function uint16Array(constraints: LengthConstraints & NumberConstraints = {}): Gen<Sized, Uint16Array> {
842
+ return typedArray(constraints, 0, 65535, Uint16Array);
843
+ }
844
+
845
+ /**
846
+ * @tsplus static fncts.test.GenOps uint32Array
847
+ */
848
+ export function uint32Array(constraints: LengthConstraints & NumberConstraints = {}): Gen<Sized, Uint32Array> {
849
+ return typedArray(constraints, 0, 0xffffffff, Uint32Array);
850
+ }
851
+
658
852
  function _char(min: number, max: number, mapToCode: (v: number) => number): Gen<never, string> {
659
853
  return Gen.intWith({ min, max }).map((n) => String.fromCharCode(mapToCode(n)));
660
854
  }
@@ -21,23 +21,22 @@ export abstract class Live {
21
21
  ),
22
22
  LiveTag,
23
23
  );
24
- static Live<R extends Live, E, A>(io: IO<R, E, A>): IO<R | Live, E, A> {
24
+ static live<R extends Live, E, A>(io: IO<R, E, A>): IO<R | Live, E, A> {
25
25
  return IO.serviceWithIO((live) => live.provide(io), LiveTag);
26
26
  }
27
27
  }
28
28
 
29
29
  /**
30
- * @tsplus static fncts.test.LiveOps withLive
30
+ * @tsplus static fncts.io.IOOps liveWith
31
31
  */
32
- export function withLive_<R, E, A, E1, B>(
33
- io: IO<R, E, A>,
34
- f: (_: IO<never, E, A>) => IO<IOEnv, E1, B>,
35
- ): IO<Exclude<R, Live>, E | E1, B> {
36
- // @ts-expect-error
37
- return IO.environment<R | Live>().flatMap((r) => Live.Live(f(io.provideEnvironment(r))));
32
+ export function liveWith<R, E, A>(f: (live: Live) => IO<R, E, A>): IO<R | Live, E, A> {
33
+ return IO.environmentWithIO((environment) => f(environment.get(Live.Tag)));
38
34
  }
39
35
 
36
+ /**
37
+ * @tsplus static fncts.test.LiveOps withLive
38
+ */
40
39
  export function withLive<R extends Live, E, A>(io: IO<R, E, A>) {
41
40
  return <E1, B>(f: (_: IO<R, E, A>) => IO<R, E1, B>): IO<R | Live, E1, B> =>
42
- IOEnv.services.getWith((services) => Live.Live(f(IOEnv.services.locally(services)(io))));
41
+ IOEnv.services.getWith((services) => Live.live(f(IOEnv.services.locally(services)(io))));
43
42
  }
@@ -102,14 +102,14 @@ export function timeoutWarning(duration: Duration): TestAspect<Live, any> {
102
102
 
103
103
  function warn<R, E>(labels: Vector<string>, test: IO<R, TestFailure<E>, TestSuccess>, duration: Duration) {
104
104
  return test.raceWith(
105
- Live.withLive(showWarning(labels, duration), (io) => Clock.sleep(duration) > io),
105
+ Live.withLive(showWarning(labels, duration))((io) => Clock.sleep(duration) > io),
106
106
  (result, fiber) => fiber.interrupt > IO.fromExitNow(result),
107
107
  (_, fiber) => fiber.join,
108
108
  );
109
109
  }
110
110
 
111
111
  function showWarning(labels: Vector<string>, duration: Duration) {
112
- return Live.Live(Console.print(renderWarning(labels, duration)));
112
+ return Console.print(renderWarning(labels, duration));
113
113
  }
114
114
 
115
115
  function renderWarning(labels: Vector<string>, duration: Duration) {
package/_src/demo.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  import { DefaultRunnableSpec } from "@fncts/test/control/DefaultRunnableSpec";
2
2
 
3
- import { suite, test, testIO } from "./api.js";
3
+ import { suite, test } from "./api.js";
4
4
  import { strictEqualTo } from "./control/Assertion.js";
5
+
5
6
  const ServiceATag = Tag<{
6
7
  x: number;
7
8
  }>("fncts.test.demo.ServiceA");
9
+
8
10
  class DemoSpec extends DefaultRunnableSpec {
9
11
  spec = suite(
10
12
  "TestSuite",
@@ -12,4 +14,4 @@ class DemoSpec extends DefaultRunnableSpec {
12
14
  test("Demo failure", { a: { b: { c: { d: 100 } } } }.assert(strictEqualTo({ a: { b: { c: { d: 0 } } } }))),
13
15
  );
14
16
  }
15
- new DemoSpec().main();
17
+ new DemoSpec().run().unsafeRunFiber();
package/api.d.ts CHANGED
@@ -17,7 +17,7 @@ export declare function traverseResult<A>(value: A, assertResult: AssertResult<A
17
17
  */
18
18
  export declare function assert<A>(assertion: Assertion<A>): (value: A) => TestResult;
19
19
  /**
20
- * @tsplus pipeable fncts.io.IO assert
20
+ * @tsplus pipeable global assert
21
21
  * @tsplus location "@fncts/test/api"
22
22
  */
23
23
  export declare function assertIO<A>(assertion: AssertionIO<A>): <R, E>(io: import("@fncts/io/IO.js").IO<R, E, A>) => import("@fncts/io/IO.js").IO<R, E, TestResult>;
@@ -1,13 +1,26 @@
1
- import { URIO } from "@fncts/io/IO/definition";
1
+ import { Scope } from "@fncts/io/Scope/definition";
2
+ import { Layer } from "@fncts/io/Layer";
3
+ import { UIO, IO } from "@fncts/io/IO/definition";
4
+ import { Either } from "@fncts/base/data/Either/definition";
5
+ import { ExecutionStrategy } from "@fncts/base/data/ExecutionStrategy";
6
+ import { Clock } from "@fncts/io/Clock/definition";
2
7
  import type { Spec } from "@fncts/test/control/Spec";
3
8
  import type { TestAspect } from "@fncts/test/control/TestAspect";
4
- import type { TestLogger } from "@fncts/test/control/TestLogger";
5
- import type { TestRunner } from "@fncts/test/control/TestRunner";
6
- import type { ExecutedSpec } from "@fncts/test/data/ExecutedSpec";
9
+ import { TestEnvironment } from "@fncts/test/control/TestEnvironment";
10
+ import { ExecutedSpec } from "@fncts/test/data/ExecutedSpec";
11
+ /**
12
+ * @tsplus type fncts.test.AbstractRunnableSpec
13
+ */
7
14
  export declare abstract class AbstractRunnableSpec<R, E> {
8
- abstract aspects: ReadonlyArray<TestAspect<R, any>>;
9
- abstract runner: TestRunner<R, E>;
10
- abstract spec: Spec<R, E>;
11
- get _run(): URIO<TestLogger, ExecutedSpec<E>>;
12
- runSpec(spec: Spec<R, E>): URIO<TestLogger, ExecutedSpec<E>>;
15
+ aspects: ReadonlyArray<TestAspect<R | TestEnvironment, any>>;
16
+ abstract spec: Spec<R | TestEnvironment | Scope, E>;
17
+ abstract bootstrap: Layer<never, never, R>;
18
+ runSpec(spec: Spec<R | TestEnvironment | Scope, E>, __tsplusTrace?: string): UIO<ExecutedSpec<E>>;
19
+ run(__tsplusTrace?: string): UIO<number>;
13
20
  }
21
+ /**
22
+ * @tsplus pipeable fncts.test.AbstractRunnableSpec combine
23
+ * @tsplus pipeable-operator fncts.test.AbstractRunnableSpec +
24
+ * @tsplus location "@fncts/test/control/AbstractRunnableSpec"
25
+ */
26
+ export declare function combine<R1, E1>(that: AbstractRunnableSpec<R1, E1>): <R, E>(self: AbstractRunnableSpec<R, E>) => AbstractRunnableSpec<R1 | R, E1 | E>;
@@ -3,12 +3,15 @@ import { HashSet } from "@fncts/base/collection/immutable/HashSet/definition";
3
3
  import { Fiber } from "@fncts/io/Fiber/definition";
4
4
  import type { TestAnnotation } from "../../data/TestAnnotation.js";
5
5
  import type { TestAnnotationMap } from "../../data/TestAnnotationMap.js";
6
+ export declare const AnnotationsTypeId: unique symbol;
7
+ export type AnnotationsTypeId = typeof AnnotationsTypeId;
6
8
  export type Annotated<A> = readonly [A, TestAnnotationMap];
7
9
  /**
8
10
  * @tsplus type fncts.test.Annotations
9
11
  * @tsplus companion fncts.test.AnnotationsOps
10
12
  */
11
13
  export declare abstract class Annotations {
14
+ readonly [AnnotationsTypeId]: AnnotationsTypeId;
12
15
  abstract annotate<V>(key: TestAnnotation<V>, value: V): UIO<void>;
13
16
  abstract get<V>(key: TestAnnotation<V>): UIO<V>;
14
17
  abstract withAnnotation<R, E, A>(io: IO<R, E, A>): IO<R, Annotated<E>, Annotated<A>>;
@@ -1,7 +1,7 @@
1
- import { RunnableSpec } from "@fncts/test/control/RunnableSpec";
1
+ import { Layer } from "@fncts/io/Layer";
2
+ import { AbstractRunnableSpec } from "@fncts/test/control/AbstractRunnableSpec";
2
3
  import { TestEnvironment } from "@fncts/test/control/TestEnvironment";
3
- import { TestRunner } from "@fncts/test/control/TestRunner";
4
- export declare abstract class DefaultRunnableSpec extends RunnableSpec<TestEnvironment, any> {
4
+ export declare abstract class DefaultRunnableSpec extends AbstractRunnableSpec<TestEnvironment, any> {
5
5
  aspects: import("@fncts/test/control/TestAspect").TestAspect<import("./Live").Live, any>[];
6
- runner: TestRunner<import("./Sized").Sized | import("./Annotations").Annotations | import("../data/TestConfig").TestConfig | import("@fncts/io/Clock").Clock | import("@fncts/io/Random").Random | import("@fncts/io/Console").Console | import("./Live").Live | import("./TestClock").TestClock | import("./TestConsole").TestConsole | import("./TestRandom").TestRandom, unknown>;
6
+ bootstrap: Layer<never, never, TestEnvironment>;
7
7
  }
@@ -6,12 +6,17 @@ import { IO, URIO } from "@fncts/io/IO/definition";
6
6
  import { Stream } from "@fncts/io/Stream/definition";
7
7
  import { Maybe } from "@fncts/base/data/Maybe/definition";
8
8
  import { Eq } from "@fncts/base/data/Eq/definition";
9
- import type { EqConstraint, FloatConstraints, LengthConstraints, NumberConstraints } from "./constraints.js";
9
+ import type { DateConstraints, EqConstraint, FloatConstraints, LengthConstraints, NumberConstraints, ObjectConstraints } from "./constraints.js";
10
10
  import type { _A, _R } from "@fncts/base/types.js";
11
11
  import type { ArrayInt64 } from "@fncts/base/util/rand";
12
12
  import { Sample } from "../Sample.js";
13
13
  import { Sized } from "../Sized.js";
14
14
  import { Gen } from "./definition.js";
15
+ /**
16
+ * @tsplus static fncts.test.GenOps anything
17
+ * @tsplus location "@fncts/test/control/Gen/api"
18
+ */
19
+ export declare function anything<C extends ObjectConstraints>(constraints?: C): Gen<ObjectConstraints extends C ? Sized : unknown extends C["key"] ? Sized : _R<C["key"]> | C["values"] extends Array<infer A> ? _R<A> : Sized, unknown>;
15
20
  /**
16
21
  * @tsplus static fncts.test.GenOps size
17
22
  * @tsplus location "@fncts/test/control/Gen/api"
@@ -38,6 +43,7 @@ export declare function alphaNumericStringWith(constraints?: LengthConstraints):
38
43
  */
39
44
  export declare const alphaNumericString: Gen<Sized, string>;
40
45
  /**
46
+ * @tsplus static fncts.test.GenOps array
41
47
  * @tsplus getter fncts.test.Gen array
42
48
  * @tsplus location "@fncts/test/control/Gen/api"
43
49
  */
@@ -119,6 +125,7 @@ export declare const char16: Gen<never, string>;
119
125
  export declare function concWith(constraints?: LengthConstraints): <R, A>(self: Gen<R, A>) => Gen<Sized | R, import("@fncts/base/collection/immutable/Conc.js").Conc<A>>;
120
126
  /**
121
127
  * @tsplus getter fncts.test.Gen conc
128
+ * @tsplus static fncts.test.GenOps conc
122
129
  * @tsplus location "@fncts/test/control/Gen/api"
123
130
  */
124
131
  export declare function conc<R, A>(self: Gen<R, A>): Gen<R | Sized, Conc<A>>;
@@ -193,6 +200,11 @@ export declare function fromIOSample<R, A>(effect: IO<R, never, Sample<R, A>>):
193
200
  * @tsplus location "@fncts/test/control/Gen/api"
194
201
  */
195
202
  export declare function floatWith(constraints?: NumberConstraints & FloatConstraints): Gen<never, number>;
203
+ /**
204
+ * @tsplus static fncts.test.GenOps float
205
+ * @tsplus location "@fncts/test/control/Gen/api"
206
+ */
207
+ export declare const float: Gen<never, number>;
196
208
  /**
197
209
  * @tsplus static fncts.test.GenOps fullUnicodeChar
198
210
  * @tsplus location "@fncts/test/control/Gen/api"
@@ -253,6 +265,10 @@ export declare function nat(max?: number): Gen<unknown, number>;
253
265
  * @tsplus location "@fncts/test/control/Gen/api"
254
266
  */
255
267
  export declare function oneOf<A extends ReadonlyArray<Gen<any, any>>>(...gens: A): Gen<_R<A[number]>, _A<A[number]>>;
268
+ /**
269
+ * @tsplus static fncts.test.GenOps partial
270
+ * @tsplus location "@fncts/test/control/Gen/api"
271
+ */
256
272
  export declare function partial<P extends Record<string, Gen<any, any>>>(properties: P): Gen<_R<P[keyof P]>, Partial<{
257
273
  readonly [K in keyof P]: _A<P[K]>;
258
274
  }>>;
@@ -291,6 +307,10 @@ export declare function string(constraints?: LengthConstraints): <R>(char: Gen<R
291
307
  * @tsplus location "@fncts/test/control/Gen/api"
292
308
  */
293
309
  export declare function stringN(n: number): <R>(char: Gen<R, string>) => Gen<R, string>;
310
+ /**
311
+ * @tsplus static fncts.test.GenOps struct
312
+ * @tsplus location "@fncts/test/control/Gen/api"
313
+ */
294
314
  export declare function struct<P extends Record<string, Gen<any, any>>>(properties: P): Gen<_R<P[keyof P]>, {
295
315
  readonly [K in keyof P]: _A<P[K]>;
296
316
  }>;
@@ -349,3 +369,52 @@ export declare function zipWith<A, R1, B, C>(that: Gen<R1, B>, f: (a: A, b: B) =
349
369
  * @tsplus location "@fncts/test/control/Gen/api"
350
370
  */
351
371
  export declare function zip<R1, B>(that: Gen<R1, B>): <R, A>(self: Gen<R, A>) => Gen<R1 | R, readonly [A, B]>;
372
+ /**
373
+ * @tsplus static fncts.test.GenOps tuple
374
+ * @tsplus location "@fncts/test/control/Gen/api"
375
+ */
376
+ export declare function tuple<A extends [...Gen<any, any>[]]>(...components: A): Gen<{
377
+ [K in keyof A]: [A[K]] extends [Gen<infer R, any>] ? R : never;
378
+ }[keyof A & number], {
379
+ [K in keyof A]: [A[K]] extends [Gen<any, infer A>] ? A : never;
380
+ }>;
381
+ /**
382
+ * @tsplus static fncts.test.GenOps record
383
+ * @tsplus location "@fncts/test/control/Gen/api"
384
+ */
385
+ export declare function record<R, R1, A>(key: Gen<R, string>, value: Gen<R1, A>, constraints?: LengthConstraints): Gen<Sized | R | R1, Record<string, A>>;
386
+ /**
387
+ * @tsplus static fncts.test.GenOps date
388
+ * @tsplus location "@fncts/test/control/Gen/api"
389
+ */
390
+ export declare function date(constraints?: DateConstraints): Gen<never, Date>;
391
+ /**
392
+ * @tsplus static fncts.test.GenOps int8Array
393
+ * @tsplus location "@fncts/test/control/Gen/api"
394
+ */
395
+ export declare function int8Array(constraints?: LengthConstraints & NumberConstraints): Gen<Sized, Int8Array>;
396
+ /**
397
+ * @tsplus static fncts.test.GenOps int16Array
398
+ * @tsplus location "@fncts/test/control/Gen/api"
399
+ */
400
+ export declare function int16Array(constraints?: LengthConstraints & NumberConstraints): Gen<Sized, Int16Array>;
401
+ /**
402
+ * @tsplus static fncts.test.GenOps int32Array
403
+ * @tsplus location "@fncts/test/control/Gen/api"
404
+ */
405
+ export declare function int32Array(constraints?: LengthConstraints & NumberConstraints): Gen<Sized, Int32Array>;
406
+ /**
407
+ * @tsplus static fncts.test.GenOps uint8Array
408
+ * @tsplus location "@fncts/test/control/Gen/api"
409
+ */
410
+ export declare function uint8Array(constraints?: LengthConstraints & NumberConstraints): Gen<Sized, Uint8Array>;
411
+ /**
412
+ * @tsplus static fncts.test.GenOps uint16Array
413
+ * @tsplus location "@fncts/test/control/Gen/api"
414
+ */
415
+ export declare function uint16Array(constraints?: LengthConstraints & NumberConstraints): Gen<Sized, Uint16Array>;
416
+ /**
417
+ * @tsplus static fncts.test.GenOps uint32Array
418
+ * @tsplus location "@fncts/test/control/Gen/api"
419
+ */
420
+ export declare function uint32Array(constraints?: LengthConstraints & NumberConstraints): Gen<Sized, Uint32Array>;
@@ -12,11 +12,15 @@ export declare const LiveTag: import("@fncts/base/data/Tag").Tag<Live>;
12
12
  export declare abstract class Live {
13
13
  abstract provide<R, E, A>(io: IO<R, E, A>): IO<R, E, A>;
14
14
  static Default: Layer<IOEnv, never, Live>;
15
- static Live<R extends Live, E, A>(io: IO<R, E, A>): IO<R | Live, E, A>;
15
+ static live<R extends Live, E, A>(io: IO<R, E, A>): IO<R | Live, E, A>;
16
16
  }
17
+ /**
18
+ * @tsplus static fncts.io.IOOps liveWith
19
+ * @tsplus location "@fncts/test/control/Live/definition"
20
+ */
21
+ export declare function liveWith<R, E, A>(f: (live: Live) => IO<R, E, A>): IO<R | Live, E, A>;
17
22
  /**
18
23
  * @tsplus static fncts.test.LiveOps withLive
19
24
  * @tsplus location "@fncts/test/control/Live/definition"
20
25
  */
21
- export declare function withLive_<R, E, A, E1, B>(io: IO<R, E, A>, f: (_: IO<never, E, A>) => IO<IOEnv, E1, B>): IO<Exclude<R, Live>, E | E1, B>;
22
26
  export declare function withLive<R extends Live, E, A>(io: IO<R, E, A>): <E1, B>(f: (_: IO<R, E, A>) => import("@fncts/io/IO").IO<R, E1, B>) => import("@fncts/io/IO").IO<Live | R, E1, B>;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@fncts/test",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "dependencies": {
5
- "@fncts/base": "0.0.26",
6
- "@fncts/io": "0.0.31",
5
+ "@fncts/base": "0.0.28",
6
+ "@fncts/io": "0.0.33",
7
7
  "@fncts/typelevel": "0.0.15"
8
8
  },
9
9
  "exports": {
@@ -1,52 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.RunnableSpec = void 0;
7
- exports.isRunnableSpec = isRunnableSpec;
8
- var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/test/control/TestLogger"));
9
- var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/IO/api"));
10
- var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/test/control/SummaryBuilder"));
11
- var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/data/Either/api"));
12
- var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/test/data/ExecutedSpec/api"));
13
- var tsplus_module_6 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/data/Exit/api"));
14
- var tsplus_module_7 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/IO/api/provideLayer"));
15
- var tsplus_module_8 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/IO/runtime"));
16
- var _pattern = /*#__PURE__*/require("@fncts/base/util/pattern");
17
- var _predicates = /*#__PURE__*/require("@fncts/base/util/predicates");
18
- var _AbstractRunnableSpec = /*#__PURE__*/require("@fncts/test/control/AbstractRunnableSpec");
19
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
20
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
- const fileName_1 = "(@fncts/test) src/control/RunnableSpec.ts";
22
- class RunnableSpec extends _AbstractRunnableSpec.AbstractRunnableSpec {
23
- constructor() {
24
- super(...arguments);
25
- this._tag = "RunnableSpec";
26
- }
27
- run(spec) {
28
- const self = this;
29
- return tsplus_module_2.flatMap(results => {
30
- const hasFailures = tsplus_module_5.some((0, _pattern.matchTag)({
31
- Test: ({
32
- test
33
- }) => tsplus_module_4.isLeft(test)
34
- }, () => false))(results);
35
- const summary = tsplus_module_3.buildSummary(results);
36
- return tsplus_module_2.map(() => hasFailures ? 1 : 0, fileName_1 + ":25:8")(tsplus_module_1.logLine(summary.summary));
37
- }, fileName_1 + ":15:28")(self.runSpec(spec));
38
- }
39
- main(_args) {
40
- // const filteredSpec = this.spec.filterByArgs(args);
41
- tsplus_module_8.unsafeRunAsyncWith(tsplus_module_7.provideLayer(this.runner.bootstrap, fileName_1 + ":33:20")(this.run(this.spec)), exit => {
42
- tsplus_module_6.match(() => {
43
- process.exit(1);
44
- }, code => process.exit(code))(exit);
45
- }, fileName_1 + ":34:26");
46
- }
47
- }
48
- exports.RunnableSpec = RunnableSpec;
49
- function isRunnableSpec(u) {
50
- return (0, _predicates.isObject)(u) && "_tag" in u && u["_tag"] === "RunnableSpec";
51
- }
52
- //# sourceMappingURL=RunnableSpec.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RunnableSpec.cjs","mappings":";;;;;;;;;;;;;;;AAGA;AACA;AACA;AAAgF;AAAA;;AAI1E,MAAgBA,YAAmB,SAAQC,0CAA0B;EAA3EC;;IACW,SAAI,GAAG,cAAc;EAgChC;EA/BEC,GAAG,CAACC,IAAgB;IAClB,MAAMC,IAAI,GAAG,IAAI;IACjB,+BACQC,OAAO;MACb,MAAMC,WAAW,GAAGC,qBAClB,qBAAQ,EACN;QACEC,IAAI,EAAE,CAAC;UAAEC;QAAI,CAAE,KAAKC,2BAAI;OACzB,EACD,MAAM,KAAK,CACZ,EANiBL,OAAO,CAO1B;MACD,MAAMM,OAAO,GAAGC,6BAA4BP,OAAO,CAAC;uCAE7CC,WAAW,GAAG,CAAC,GAAG,CAAC,wBADxBO,wBAAmBF,OAAO,CAACA,OAAO,CAAC;8BAVfP,IAAI,CAACU,OAAO,CAACX,IAAI,CAAC;EAa5C;EAEAY,IAAI,CAACC,KAAgB;IACnB;IACAC,gEACgB,IAAI,CAACC,MAAM,CAACC,SAAS,yBADrC,IAAI,CAACjB,GAAG,CAAC,IAAI,CAACC,IAAI,CAAC,CACmB,EACfiB,IAAI,IAAI;MAC3BC,sBACE,MAAK;QACHC,OAAO,CAACF,IAAI,CAAC,CAAC,CAAC;MACjB,CAAC,EACAG,IAAI,IAAKD,OAAO,CAACF,IAAI,CAACG,IAAI,CAAC,EAJ9BH,IAAI,CAKH;IACH,CAAC,wBAAC;EACN;;AACD;AAEK,SAAUI,cAAc,CAACC,CAAU;EACvC,OAAO,wBAAQ,EAACA,CAAC,CAAC,IAAI,MAAM,IAAIA,CAAC,IAAIA,CAAC,CAAC,MAAM,CAAC,KAAK,cAAc;AACnE","names":["RunnableSpec","AbstractRunnableSpec","constructor","run","spec","self","results","hasFailures","tsplus_module_5","Test","test","tsplus_module_4","summary","tsplus_module_3","tsplus_module_1","runSpec","main","_args","tsplus_module_8","runner","bootstrap","exit","tsplus_module_6","process","code","isRunnableSpec","u"],"sourceRoot":"","sources":["../../_src/control/RunnableSpec.ts"],"sourcesContent":[null]}