diff --git a/packages/effect/src/Chunk.ts b/packages/effect/src/Chunk.ts index 60ac5f071e5..500766e4a53 100644 --- a/packages/effect/src/Chunk.ts +++ b/packages/effect/src/Chunk.ts @@ -230,9 +230,8 @@ export const empty: () => Chunk = () => _empty * @category constructors * @since 2.0.0 */ -export const make = ]>( - ...as: As -): NonEmptyChunk => as.length === 1 ? of(as[0]) : unsafeFromNonEmptyArray(as) +export const make = ]>(...as: As): NonEmptyChunk => + unsafeFromNonEmptyArray(as) /** * Builds a `NonEmptyChunk` from a single element. @@ -249,7 +248,7 @@ export const of = (a: A): NonEmptyChunk => makeChunk({ _tag: "ISingleton", * @since 2.0.0 */ export const fromIterable = (self: Iterable): Chunk => - isChunk(self) ? self : makeChunk({ _tag: "IArray", array: RA.fromIterable(self) }) + isChunk(self) ? self : unsafeFromArray(RA.fromIterable(self)) const copyToArray = (self: Chunk, array: Array, initial: number): void => { switch (self.backing._tag) { @@ -384,7 +383,8 @@ export const get: { * @since 2.0.0 * @category unsafe */ -export const unsafeFromArray = (self: ReadonlyArray): Chunk => makeChunk({ _tag: "IArray", array: self }) +export const unsafeFromArray = (self: ReadonlyArray): Chunk => + self.length === 0 ? empty() : self.length === 1 ? of(self[0]) : makeChunk({ _tag: "IArray", array: self }) /** * Wraps an array into a chunk without copying, unsafe on mutable arrays @@ -1216,8 +1216,7 @@ export const zip: { ) /** - * Delete the element at the specified index, creating a new `Chunk`, - * or returning the input if the index is out of bounds. + * Delete the element at the specified index, creating a new `Chunk`. * * @since 2.0.0 */ diff --git a/packages/effect/src/ConfigProvider.ts b/packages/effect/src/ConfigProvider.ts index 001d6ac5708..a466c334412 100644 --- a/packages/effect/src/ConfigProvider.ts +++ b/packages/effect/src/ConfigProvider.ts @@ -195,6 +195,7 @@ export const fromFlat: (flat: ConfigProvider.Flat) => ConfigProvider = internal. */ export const fromJson: (json: unknown) => ConfigProvider = internal.fromJson +// TODO: use `_` for nested configs instead of `.` in next major /** * Constructs a ConfigProvider using a map and the specified delimiter string, * which determines how to split the keys in the map into path segments. diff --git a/packages/effect/src/ParseResult.ts b/packages/effect/src/ParseResult.ts index 01a1c491e78..40f55a6d3e9 100644 --- a/packages/effect/src/ParseResult.ts +++ b/packages/effect/src/ParseResult.ts @@ -3,7 +3,7 @@ */ import * as array_ from "./Array.js" -import type * as cause_ from "./Cause.js" +import * as cause_ from "./Cause.js" import { TaggedError } from "./Data.js" import * as Effect from "./Effect.js" import * as Either from "./Either.js" @@ -14,6 +14,7 @@ import * as Inspectable from "./Inspectable.js" import * as util_ from "./internal/schema/util.js" import * as Option from "./Option.js" import * as Predicate from "./Predicate.js" +import * as Runtime from "./Runtime.js" import type * as Schema from "./Schema.js" import * as AST from "./SchemaAST.js" import type { Concurrency } from "./Types.js" @@ -1649,13 +1650,19 @@ const handleForbidden = ( try { return Effect.runSync(Effect.either(effect as Effect.Effect)) } catch (e) { - return Either.left( - new Forbidden( - ast, - actual, - "cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work" - ) - ) + if (Runtime.isFiberFailure(e)) { + const cause = e[Runtime.FiberFailureCauseId] + if (cause_.isDieType(cause) && Runtime.isAsyncFiberException(cause.defect)) { + return Either.left( + new Forbidden( + ast, + actual, + "cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work" + ) + ) + } + } + return Either.left(new Forbidden(ast, actual, String(e))) } } diff --git a/packages/effect/src/internal/secret.ts b/packages/effect/src/internal/secret.ts index 3ef59924ceb..2d12b35f6cf 100644 --- a/packages/effect/src/internal/secret.ts +++ b/packages/effect/src/internal/secret.ts @@ -23,15 +23,17 @@ export const SecretTypeId: Secret.SecretTypeId = Symbol.for( */ export const isSecret = (u: unknown): u is Secret.Secret => hasProperty(u, SecretTypeId) +const SecretProto = { + ...redacted_.proto, + [SecretTypeId]: SecretTypeId +} + /** * @internal * @deprecated */ export const make = (bytes: Array): Secret.Secret => { - const secret = Object.create({ - ...redacted_.proto, - [SecretTypeId]: SecretTypeId - }) + const secret = Object.create(SecretProto) Object.defineProperty(secret, "toString", { enumerable: false, value() { diff --git a/packages/effect/test/Array.test.ts b/packages/effect/test/Array.test.ts index 22d83732f77..465a701c850 100644 --- a/packages/effect/test/Array.test.ts +++ b/packages/effect/test/Array.test.ts @@ -1,167 +1,166 @@ -import * as RA from "effect/Array" -import * as E from "effect/Either" -import * as fc from "effect/FastCheck" -import { identity, pipe } from "effect/Function" -import * as Number from "effect/Number" -import * as O from "effect/Option" -import * as Order from "effect/Order" -import type { Predicate } from "effect/Predicate" -import * as String from "effect/String" -import { deepStrictEqual, double, strictEqual } from "effect/test/util" -import * as Util from "effect/test/util" -import { assert, describe, expect, it } from "vitest" +import { + Array as Arr, + Either, + FastCheck as fc, + identity, + Number as Num, + Option, + Order, + pipe, + type Predicate, + String as Str +} from "effect" +import { assertNone, assertSome, deepStrictEqual, strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" const symA = Symbol.for("a") const symB = Symbol.for("b") const symC = Symbol.for("c") -describe("ReadonlyArray", () => { - it("exports", () => { - expect(RA.fromRecord).exist - expect(RA.getEquivalence).exist - }) +const double = (n: number) => n * 2 +describe("Array", () => { it("of", () => { - expect(RA.of(1)).toEqual([1]) + deepStrictEqual(Arr.of(1), [1]) }) it("fromIterable/Array should return the same reference if the iterable is an Array", () => { const i = [1, 2, 3] - expect(RA.fromIterable(i) === i).toEqual(true) + strictEqual(Arr.fromIterable(i), i) }) it("fromIterable/Iterable", () => { - expect(RA.fromIterable(new Set([1, 2, 3]))).toEqual([1, 2, 3]) + deepStrictEqual(Arr.fromIterable(new Set([1, 2, 3])), [1, 2, 3]) }) it("ensure", () => { - expect(RA.ensure(1)).toEqual([1]) - expect(RA.ensure(null)).toEqual([null]) - expect(RA.ensure([1])).toEqual([1]) - expect(RA.ensure([1, 2])).toEqual([1, 2]) - expect(RA.ensure(new Set([1, 2]))).toEqual([new Set([1, 2])]) + deepStrictEqual(Arr.ensure(1), [1]) + deepStrictEqual(Arr.ensure(null), [null]) + deepStrictEqual(Arr.ensure([1]), [1]) + deepStrictEqual(Arr.ensure([1, 2]), [1, 2]) + deepStrictEqual(Arr.ensure(new Set([1, 2])), [new Set([1, 2])]) }) describe("iterable inputs", () => { it("prepend", () => { - deepStrictEqual(pipe([1, 2, 3], RA.prepend(0)), [0, 1, 2, 3]) - deepStrictEqual(pipe([[2]], RA.prepend([1])), [[1], [2]]) + deepStrictEqual(pipe([1, 2, 3], Arr.prepend(0)), [0, 1, 2, 3]) + deepStrictEqual(pipe([[2]], Arr.prepend([1])), [[1], [2]]) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.prepend(0)), [0, 1, 2, 3]) - deepStrictEqual(pipe(new Set([[2]]), RA.prepend([1])), [[1], [2]]) + deepStrictEqual(pipe(new Set([1, 2, 3]), Arr.prepend(0)), [0, 1, 2, 3]) + deepStrictEqual(pipe(new Set([[2]]), Arr.prepend([1])), [[1], [2]]) }) it("prependAll", () => { - deepStrictEqual(pipe([3, 4], RA.prependAll([1, 2])), [1, 2, 3, 4]) + deepStrictEqual(pipe([3, 4], Arr.prependAll([1, 2])), [1, 2, 3, 4]) - deepStrictEqual(pipe([3, 4], RA.prependAll(new Set([1, 2]))), [1, 2, 3, 4]) - deepStrictEqual(pipe(new Set([3, 4]), RA.prependAll([1, 2])), [1, 2, 3, 4]) + deepStrictEqual(pipe([3, 4], Arr.prependAll(new Set([1, 2]))), [1, 2, 3, 4]) + deepStrictEqual(pipe(new Set([3, 4]), Arr.prependAll([1, 2])), [1, 2, 3, 4]) }) it("append", () => { - deepStrictEqual(pipe([1, 2, 3], RA.append(4)), [1, 2, 3, 4]) - deepStrictEqual(pipe([[1]], RA.append([2])), [[1], [2]]) + deepStrictEqual(pipe([1, 2, 3], Arr.append(4)), [1, 2, 3, 4]) + deepStrictEqual(pipe([[1]], Arr.append([2])), [[1], [2]]) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.append(4)), [1, 2, 3, 4]) - deepStrictEqual(pipe(new Set([[1]]), RA.append([2])), [[1], [2]]) + deepStrictEqual(pipe(new Set([1, 2, 3]), Arr.append(4)), [1, 2, 3, 4]) + deepStrictEqual(pipe(new Set([[1]]), Arr.append([2])), [[1], [2]]) }) it("appendAll", () => { - deepStrictEqual(pipe([1, 2], RA.appendAll([3, 4])), [1, 2, 3, 4]) + deepStrictEqual(pipe([1, 2], Arr.appendAll([3, 4])), [1, 2, 3, 4]) - deepStrictEqual(pipe([1, 2], RA.appendAll(new Set([3, 4]))), [1, 2, 3, 4]) - deepStrictEqual(pipe(new Set([1, 2]), RA.appendAll([3, 4])), [1, 2, 3, 4]) + deepStrictEqual(pipe([1, 2], Arr.appendAll(new Set([3, 4]))), [1, 2, 3, 4]) + deepStrictEqual(pipe(new Set([1, 2]), Arr.appendAll([3, 4])), [1, 2, 3, 4]) }) it("scan", () => { const f = (b: number, a: number) => b - a - deepStrictEqual(pipe([1, 2, 3], RA.scan(10, f)), [10, 9, 7, 4]) - deepStrictEqual(pipe([0], RA.scan(10, f)), [10, 10]) - deepStrictEqual(pipe([], RA.scan(10, f)), [10]) + deepStrictEqual(pipe([1, 2, 3], Arr.scan(10, f)), [10, 9, 7, 4]) + deepStrictEqual(pipe([0], Arr.scan(10, f)), [10, 10]) + deepStrictEqual(pipe([], Arr.scan(10, f)), [10]) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.scan(10, f)), [10, 9, 7, 4]) - deepStrictEqual(pipe(new Set([0]), RA.scan(10, f)), [10, 10]) - deepStrictEqual(pipe(new Set([]), RA.scan(10, f)), [10]) + deepStrictEqual(pipe(new Set([1, 2, 3]), Arr.scan(10, f)), [10, 9, 7, 4]) + deepStrictEqual(pipe(new Set([0]), Arr.scan(10, f)), [10, 10]) + deepStrictEqual(pipe(new Set([]), Arr.scan(10, f)), [10]) }) it("scanRight", () => { const f = (b: number, a: number) => a - b - deepStrictEqual(pipe([1, 2, 3], RA.scanRight(10, f)), [-8, 9, -7, 10]) - deepStrictEqual(pipe([0], RA.scanRight(10, f)), [-10, 10]) - deepStrictEqual(pipe([], RA.scanRight(10, f)), [10]) + deepStrictEqual(pipe([1, 2, 3], Arr.scanRight(10, f)), [-8, 9, -7, 10]) + deepStrictEqual(pipe([0], Arr.scanRight(10, f)), [-10, 10]) + deepStrictEqual(pipe([], Arr.scanRight(10, f)), [10]) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.scanRight(10, f)), [-8, 9, -7, 10]) - deepStrictEqual(pipe(new Set([0]), RA.scanRight(10, f)), [-10, 10]) - deepStrictEqual(pipe(new Set([]), RA.scanRight(10, f)), [10]) + deepStrictEqual(pipe(new Set([1, 2, 3]), Arr.scanRight(10, f)), [-8, 9, -7, 10]) + deepStrictEqual(pipe(new Set([0]), Arr.scanRight(10, f)), [-10, 10]) + deepStrictEqual(pipe(new Set([]), Arr.scanRight(10, f)), [10]) }) it("tail", () => { - deepStrictEqual(RA.tail([1, 2, 3]), O.some([2, 3])) - deepStrictEqual(RA.tail([]), O.none()) + assertSome(Arr.tail([1, 2, 3]), [2, 3]) + assertNone(Arr.tail([])) - deepStrictEqual(RA.tail(new Set([1, 2, 3])), O.some([2, 3])) - deepStrictEqual(RA.tail(new Set([])), O.none()) + assertSome(Arr.tail(new Set([1, 2, 3])), [2, 3]) + assertNone(Arr.tail(new Set([]))) }) it("init", () => { - deepStrictEqual(RA.init([1, 2, 3]), O.some([1, 2])) - deepStrictEqual(RA.init([]), O.none()) + assertSome(Arr.init([1, 2, 3]), [1, 2]) + assertNone(Arr.init([])) - deepStrictEqual(RA.init(new Set([1, 2, 3])), O.some([1, 2])) - deepStrictEqual(RA.init(new Set([])), O.none()) + assertSome(Arr.init(new Set([1, 2, 3])), [1, 2]) + assertNone(Arr.init(new Set([]))) }) it("take", () => { - expect(pipe([1, 2, 3, 4], RA.take(2))).toEqual([1, 2]) - expect(pipe([1, 2, 3, 4], RA.take(0))).toEqual([]) + deepStrictEqual(pipe([1, 2, 3, 4], Arr.take(2)), [1, 2]) + deepStrictEqual(pipe([1, 2, 3, 4], Arr.take(0)), []) // out of bounds - expect(pipe([1, 2, 3, 4], RA.take(-10))).toEqual([]) - expect(pipe([1, 2, 3, 4], RA.take(10))).toEqual([1, 2, 3, 4]) + deepStrictEqual(pipe([1, 2, 3, 4], Arr.take(-10)), []) + deepStrictEqual(pipe([1, 2, 3, 4], Arr.take(10)), [1, 2, 3, 4]) - expect(pipe(new Set([1, 2, 3, 4]), RA.take(2))).toEqual([1, 2]) - expect(pipe(new Set([1, 2, 3, 4]), RA.take(0))).toEqual([]) + deepStrictEqual(pipe(new Set([1, 2, 3, 4]), Arr.take(2)), [1, 2]) + deepStrictEqual(pipe(new Set([1, 2, 3, 4]), Arr.take(0)), []) // out of bounds - expect(pipe(new Set([1, 2, 3, 4]), RA.take(-10))).toEqual([]) - expect(pipe(new Set([1, 2, 3, 4]), RA.take(10))).toEqual([1, 2, 3, 4]) + deepStrictEqual(pipe(new Set([1, 2, 3, 4]), Arr.take(-10)), []) + deepStrictEqual(pipe(new Set([1, 2, 3, 4]), Arr.take(10)), [1, 2, 3, 4]) }) it("takeRight", () => { - deepStrictEqual(pipe(RA.empty(), RA.takeRight(0)), []) - deepStrictEqual(pipe([1, 2], RA.takeRight(0)), []) - deepStrictEqual(pipe([1, 2], RA.takeRight(1)), [2]) - deepStrictEqual(pipe([1, 2], RA.takeRight(2)), [1, 2]) + deepStrictEqual(pipe(Arr.empty(), Arr.takeRight(0)), []) + deepStrictEqual(pipe([1, 2], Arr.takeRight(0)), []) + deepStrictEqual(pipe([1, 2], Arr.takeRight(1)), [2]) + deepStrictEqual(pipe([1, 2], Arr.takeRight(2)), [1, 2]) // out of bound - deepStrictEqual(pipe(RA.empty(), RA.takeRight(1)), []) - deepStrictEqual(pipe(RA.empty(), RA.takeRight(-1)), []) - deepStrictEqual(pipe([1, 2], RA.takeRight(3)), [1, 2]) - deepStrictEqual(pipe([1, 2], RA.takeRight(-1)), []) - - deepStrictEqual(pipe(new Set(), RA.takeRight(0)), []) - deepStrictEqual(pipe(new Set([1, 2]), RA.takeRight(0)), []) - deepStrictEqual(pipe(new Set([1, 2]), RA.takeRight(1)), [2]) - deepStrictEqual(pipe(new Set([1, 2]), RA.takeRight(2)), [1, 2]) + deepStrictEqual(pipe(Arr.empty(), Arr.takeRight(1)), []) + deepStrictEqual(pipe(Arr.empty(), Arr.takeRight(-1)), []) + deepStrictEqual(pipe([1, 2], Arr.takeRight(3)), [1, 2]) + deepStrictEqual(pipe([1, 2], Arr.takeRight(-1)), []) + + deepStrictEqual(pipe(new Set(), Arr.takeRight(0)), []) + deepStrictEqual(pipe(new Set([1, 2]), Arr.takeRight(0)), []) + deepStrictEqual(pipe(new Set([1, 2]), Arr.takeRight(1)), [2]) + deepStrictEqual(pipe(new Set([1, 2]), Arr.takeRight(2)), [1, 2]) // out of bound - deepStrictEqual(pipe(new Set(), RA.takeRight(1)), []) - deepStrictEqual(pipe(new Set(), RA.takeRight(-1)), []) - deepStrictEqual(pipe(new Set([1, 2]), RA.takeRight(3)), [1, 2]) - deepStrictEqual(pipe(new Set([1, 2]), RA.takeRight(-1)), []) + deepStrictEqual(pipe(new Set(), Arr.takeRight(1)), []) + deepStrictEqual(pipe(new Set(), Arr.takeRight(-1)), []) + deepStrictEqual(pipe(new Set([1, 2]), Arr.takeRight(3)), [1, 2]) + deepStrictEqual(pipe(new Set([1, 2]), Arr.takeRight(-1)), []) }) it("takeWhile", () => { const f = (n: number) => n % 2 === 0 - deepStrictEqual(pipe([2, 4, 3, 6], RA.takeWhile(f)), [2, 4]) - deepStrictEqual(pipe(RA.empty(), RA.takeWhile(f)), []) - deepStrictEqual(pipe([1, 2, 4], RA.takeWhile(f)), []) - deepStrictEqual(pipe([2, 4], RA.takeWhile(f)), [2, 4]) - - deepStrictEqual(pipe(new Set([2, 4, 3, 6]), RA.takeWhile(f)), [2, 4]) - deepStrictEqual(pipe(new Set(), RA.takeWhile(f)), []) - deepStrictEqual(pipe(new Set([1, 2, 4]), RA.takeWhile(f)), []) - deepStrictEqual(pipe(new Set([2, 4]), RA.takeWhile(f)), [2, 4]) + deepStrictEqual(pipe([2, 4, 3, 6], Arr.takeWhile(f)), [2, 4]) + deepStrictEqual(pipe(Arr.empty(), Arr.takeWhile(f)), []) + deepStrictEqual(pipe([1, 2, 4], Arr.takeWhile(f)), []) + deepStrictEqual(pipe([2, 4], Arr.takeWhile(f)), [2, 4]) + + deepStrictEqual(pipe(new Set([2, 4, 3, 6]), Arr.takeWhile(f)), [2, 4]) + deepStrictEqual(pipe(new Set(), Arr.takeWhile(f)), []) + deepStrictEqual(pipe(new Set([1, 2, 4]), Arr.takeWhile(f)), []) + deepStrictEqual(pipe(new Set([2, 4]), Arr.takeWhile(f)), [2, 4]) }) it("span", () => { - const f = RA.span((n) => n % 2 === 1) + const f = Arr.span((n) => n % 2 === 1) const assertSpan = ( input: Iterable, expectedInit: ReadonlyArray, @@ -172,18 +171,18 @@ describe("ReadonlyArray", () => { deepStrictEqual(rest, expectedRest) } assertSpan([1, 3, 2, 4, 5], [1, 3], [2, 4, 5]) - assertSpan(RA.empty(), RA.empty(), RA.empty()) - assertSpan([1, 3], [1, 3], RA.empty()) - assertSpan([2, 4], RA.empty(), [2, 4]) + assertSpan(Arr.empty(), Arr.empty(), Arr.empty()) + assertSpan([1, 3], [1, 3], Arr.empty()) + assertSpan([2, 4], Arr.empty(), [2, 4]) assertSpan(new Set([1, 3, 2, 4, 5]), [1, 3], [2, 4, 5]) - assertSpan(new Set(), RA.empty(), RA.empty()) - assertSpan(new Set([1, 3]), [1, 3], RA.empty()) - assertSpan(new Set([2, 4]), RA.empty(), [2, 4]) + assertSpan(new Set(), Arr.empty(), Arr.empty()) + assertSpan(new Set([1, 3]), [1, 3], Arr.empty()) + assertSpan(new Set([2, 4]), Arr.empty(), [2, 4]) }) it("splitWhere", () => { - const f = RA.splitWhere((n) => n % 2 !== 1) + const f = Arr.splitWhere((n) => n % 2 !== 1) const assertSplitWhere = ( input: Iterable, expectedInit: ReadonlyArray, @@ -194,295 +193,292 @@ describe("ReadonlyArray", () => { deepStrictEqual(rest, expectedRest) } assertSplitWhere([1, 3, 2, 4, 5], [1, 3], [2, 4, 5]) - assertSplitWhere(RA.empty(), RA.empty(), RA.empty()) - assertSplitWhere([1, 3], [1, 3], RA.empty()) - assertSplitWhere([2, 4], RA.empty(), [2, 4]) + assertSplitWhere(Arr.empty(), Arr.empty(), Arr.empty()) + assertSplitWhere([1, 3], [1, 3], Arr.empty()) + assertSplitWhere([2, 4], Arr.empty(), [2, 4]) assertSplitWhere(new Set([1, 3, 2, 4, 5]), [1, 3], [2, 4, 5]) - assertSplitWhere(new Set(), RA.empty(), RA.empty()) - assertSplitWhere(new Set([1, 3]), [1, 3], RA.empty()) - assertSplitWhere(new Set([2, 4]), RA.empty(), [2, 4]) + assertSplitWhere(new Set(), Arr.empty(), Arr.empty()) + assertSplitWhere(new Set([1, 3]), [1, 3], Arr.empty()) + assertSplitWhere(new Set([2, 4]), Arr.empty(), [2, 4]) }) it("split", () => { - expect(pipe(RA.empty(), RA.split(2))).toEqual(RA.empty()) - expect(pipe(RA.make(1), RA.split(2))).toEqual( - RA.make(RA.make(1)) - ) - expect(pipe(RA.make(1, 2), RA.split(2))).toEqual( - RA.make(RA.make(1), RA.make(2)) - ) - expect(pipe(RA.make(1, 2, 3, 4, 5), RA.split(2))).toEqual( - RA.make(RA.make(1, 2, 3), RA.make(4, 5)) - ) - expect(pipe(RA.make(1, 2, 3, 4, 5), RA.split(3))).toEqual( - RA.make(RA.make(1, 2), RA.make(3, 4), RA.make(5)) + deepStrictEqual(pipe(Arr.empty(), Arr.split(2)), Arr.empty()) + deepStrictEqual(pipe(Arr.make(1), Arr.split(2)), Arr.make(Arr.make(1))) + deepStrictEqual(pipe(Arr.make(1, 2), Arr.split(2)), Arr.make(Arr.make(1), Arr.make(2))) + deepStrictEqual(pipe(Arr.make(1, 2, 3, 4, 5), Arr.split(2)), Arr.make(Arr.make(1, 2, 3), Arr.make(4, 5))) + deepStrictEqual( + pipe(Arr.make(1, 2, 3, 4, 5), Arr.split(3)), + Arr.make(Arr.make(1, 2), Arr.make(3, 4), Arr.make(5)) ) }) it("drop", () => { - deepStrictEqual(pipe(RA.empty(), RA.drop(0)), []) - deepStrictEqual(pipe([1, 2], RA.drop(0)), [1, 2]) - deepStrictEqual(pipe([1, 2], RA.drop(1)), [2]) - deepStrictEqual(pipe([1, 2], RA.drop(2)), []) + deepStrictEqual(pipe(Arr.empty(), Arr.drop(0)), []) + deepStrictEqual(pipe([1, 2], Arr.drop(0)), [1, 2]) + deepStrictEqual(pipe([1, 2], Arr.drop(1)), [2]) + deepStrictEqual(pipe([1, 2], Arr.drop(2)), []) // out of bound - deepStrictEqual(pipe(RA.empty(), RA.drop(1)), []) - deepStrictEqual(pipe(RA.empty(), RA.drop(-1)), []) - deepStrictEqual(pipe([1, 2], RA.drop(3)), []) - deepStrictEqual(pipe([1, 2], RA.drop(-1)), [1, 2]) - - deepStrictEqual(pipe(new Set(), RA.drop(0)), []) - deepStrictEqual(pipe(new Set([1, 2]), RA.drop(0)), [1, 2]) - deepStrictEqual(pipe(new Set([1, 2]), RA.drop(1)), [2]) - deepStrictEqual(pipe(new Set([1, 2]), RA.drop(2)), []) + deepStrictEqual(pipe(Arr.empty(), Arr.drop(1)), []) + deepStrictEqual(pipe(Arr.empty(), Arr.drop(-1)), []) + deepStrictEqual(pipe([1, 2], Arr.drop(3)), []) + deepStrictEqual(pipe([1, 2], Arr.drop(-1)), [1, 2]) + + deepStrictEqual(pipe(new Set(), Arr.drop(0)), []) + deepStrictEqual(pipe(new Set([1, 2]), Arr.drop(0)), [1, 2]) + deepStrictEqual(pipe(new Set([1, 2]), Arr.drop(1)), [2]) + deepStrictEqual(pipe(new Set([1, 2]), Arr.drop(2)), []) // out of bound - deepStrictEqual(pipe(new Set(), RA.drop(1)), []) - deepStrictEqual(pipe(new Set(), RA.drop(-1)), []) - deepStrictEqual(pipe(new Set([1, 2]), RA.drop(3)), []) - deepStrictEqual(pipe(new Set([1, 2]), RA.drop(-1)), [1, 2]) + deepStrictEqual(pipe(new Set(), Arr.drop(1)), []) + deepStrictEqual(pipe(new Set(), Arr.drop(-1)), []) + deepStrictEqual(pipe(new Set([1, 2]), Arr.drop(3)), []) + deepStrictEqual(pipe(new Set([1, 2]), Arr.drop(-1)), [1, 2]) }) it("dropRight", () => { - deepStrictEqual(pipe([], RA.dropRight(0)), []) - deepStrictEqual(pipe([1, 2], RA.dropRight(0)), [1, 2]) - deepStrictEqual(pipe([1, 2], RA.dropRight(1)), [1]) - deepStrictEqual(pipe([1, 2], RA.dropRight(2)), []) + deepStrictEqual(pipe([], Arr.dropRight(0)), []) + deepStrictEqual(pipe([1, 2], Arr.dropRight(0)), [1, 2]) + deepStrictEqual(pipe([1, 2], Arr.dropRight(1)), [1]) + deepStrictEqual(pipe([1, 2], Arr.dropRight(2)), []) // out of bound - deepStrictEqual(pipe([], RA.dropRight(1)), []) - deepStrictEqual(pipe([1, 2], RA.dropRight(3)), []) - deepStrictEqual(pipe([], RA.dropRight(-1)), []) - deepStrictEqual(pipe([1, 2], RA.dropRight(-1)), [1, 2]) - - deepStrictEqual(pipe(new Set(), RA.dropRight(0)), []) - deepStrictEqual(pipe(new Set([1, 2]), RA.dropRight(0)), [1, 2]) - deepStrictEqual(pipe(new Set([1, 2]), RA.dropRight(1)), [1]) - deepStrictEqual(pipe(new Set([1, 2]), RA.dropRight(2)), []) + deepStrictEqual(pipe([], Arr.dropRight(1)), []) + deepStrictEqual(pipe([1, 2], Arr.dropRight(3)), []) + deepStrictEqual(pipe([], Arr.dropRight(-1)), []) + deepStrictEqual(pipe([1, 2], Arr.dropRight(-1)), [1, 2]) + + deepStrictEqual(pipe(new Set(), Arr.dropRight(0)), []) + deepStrictEqual(pipe(new Set([1, 2]), Arr.dropRight(0)), [1, 2]) + deepStrictEqual(pipe(new Set([1, 2]), Arr.dropRight(1)), [1]) + deepStrictEqual(pipe(new Set([1, 2]), Arr.dropRight(2)), []) // out of bound - deepStrictEqual(pipe(new Set(), RA.dropRight(1)), []) - deepStrictEqual(pipe(new Set([1, 2]), RA.dropRight(3)), []) - deepStrictEqual(pipe(new Set(), RA.dropRight(-1)), []) - deepStrictEqual(pipe(new Set([1, 2]), RA.dropRight(-1)), [1, 2]) + deepStrictEqual(pipe(new Set(), Arr.dropRight(1)), []) + deepStrictEqual(pipe(new Set([1, 2]), Arr.dropRight(3)), []) + deepStrictEqual(pipe(new Set(), Arr.dropRight(-1)), []) + deepStrictEqual(pipe(new Set([1, 2]), Arr.dropRight(-1)), [1, 2]) }) it("dropWhile", () => { - const f = RA.dropWhile((n) => n > 0) + const f = Arr.dropWhile((n) => n > 0) deepStrictEqual(f([]), []) - deepStrictEqual(f([1, 2]), RA.empty()) + deepStrictEqual(f([1, 2]), Arr.empty()) deepStrictEqual(f([-1, -2]), [-1, -2]) deepStrictEqual(f([-1, 2]), [-1, 2]) deepStrictEqual(f([1, -2, 3]), [-2, 3]) deepStrictEqual(f(new Set()), []) - deepStrictEqual(f(new Set([1, 2])), RA.empty()) + deepStrictEqual(f(new Set([1, 2])), Arr.empty()) deepStrictEqual(f(new Set([-1, -2])), [-1, -2]) deepStrictEqual(f(new Set([-1, 2])), [-1, 2]) deepStrictEqual(f(new Set([1, -2, 3])), [-2, 3]) }) it("findFirstIndex", () => { - deepStrictEqual(pipe([], RA.findFirstIndex((n) => n % 2 === 0)), O.none()) - deepStrictEqual(pipe([1, 2, 3], RA.findFirstIndex((n) => n % 2 === 0)), O.some(1)) - deepStrictEqual(pipe([1, 2, 3, 1], RA.findFirstIndex((n) => n % 2 === 0)), O.some(1)) + assertNone(pipe([], Arr.findFirstIndex((n) => n % 2 === 0))) + assertSome(pipe([1, 2, 3], Arr.findFirstIndex((n) => n % 2 === 0)), 1) + assertSome(pipe([1, 2, 3, 1], Arr.findFirstIndex((n) => n % 2 === 0)), 1) - deepStrictEqual(pipe(new Set(), RA.findFirstIndex((n) => n % 2 === 0)), O.none()) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.findFirstIndex((n) => n % 2 === 0)), O.some(1)) - deepStrictEqual(pipe(new Set([1, 2, 3, 4]), RA.findFirstIndex((n) => n % 2 === 0)), O.some(1)) + assertNone(pipe(new Set(), Arr.findFirstIndex((n) => n % 2 === 0))) + assertSome(pipe(new Set([1, 2, 3]), Arr.findFirstIndex((n) => n % 2 === 0)), 1) + assertSome(pipe(new Set([1, 2, 3, 4]), Arr.findFirstIndex((n) => n % 2 === 0)), 1) }) it("findLastIndex", () => { - deepStrictEqual(pipe([], RA.findLastIndex((n) => n % 2 === 0)), O.none()) - deepStrictEqual(pipe([1, 2, 3], RA.findLastIndex((n) => n % 2 === 0)), O.some(1)) - deepStrictEqual(pipe([1, 2, 3, 4], RA.findLastIndex((n) => n % 2 === 0)), O.some(3)) + assertNone(pipe([], Arr.findLastIndex((n) => n % 2 === 0))) + assertSome(pipe([1, 2, 3], Arr.findLastIndex((n) => n % 2 === 0)), 1) + assertSome(pipe([1, 2, 3, 4], Arr.findLastIndex((n) => n % 2 === 0)), 3) - deepStrictEqual(pipe(new Set(), RA.findLastIndex((n) => n % 2 === 0)), O.none()) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.findLastIndex((n) => n % 2 === 0)), O.some(1)) - deepStrictEqual(pipe(new Set([1, 2, 3, 4]), RA.findLastIndex((n) => n % 2 === 0)), O.some(3)) + assertNone(pipe(new Set(), Arr.findLastIndex((n) => n % 2 === 0))) + assertSome(pipe(new Set([1, 2, 3]), Arr.findLastIndex((n) => n % 2 === 0)), 1) + assertSome(pipe(new Set([1, 2, 3, 4]), Arr.findLastIndex((n) => n % 2 === 0)), 3) }) describe("findFirst", () => { it("boolean-returning overloads", () => { - deepStrictEqual(pipe([], RA.findFirst((n) => n % 2 === 0)), O.none()) - deepStrictEqual(pipe([1, 2, 3], RA.findFirst((n) => n % 2 === 0)), O.some(2)) - deepStrictEqual(pipe([1, 2, 3, 4], RA.findFirst((n) => n % 2 === 0)), O.some(2)) + assertNone(pipe([], Arr.findFirst((n) => n % 2 === 0))) + assertSome(pipe([1, 2, 3], Arr.findFirst((n) => n % 2 === 0)), 2) + assertSome(pipe([1, 2, 3, 4], Arr.findFirst((n) => n % 2 === 0)), 2) - deepStrictEqual(pipe(new Set(), RA.findFirst((n) => n % 2 === 0)), O.none()) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.findFirst((n) => n % 2 === 0)), O.some(2)) - deepStrictEqual(pipe(new Set([1, 2, 3, 4]), RA.findFirst((n) => n % 2 === 0)), O.some(2)) + assertNone(pipe(new Set(), Arr.findFirst((n) => n % 2 === 0))) + assertSome(pipe(new Set([1, 2, 3]), Arr.findFirst((n) => n % 2 === 0)), 2) + assertSome(pipe(new Set([1, 2, 3, 4]), Arr.findFirst((n) => n % 2 === 0)), 2) }) it("Option-returning overloads", () => { - deepStrictEqual(pipe([], RA.findFirst((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), O.none()) - deepStrictEqual( - pipe([1, 2, 3], RA.findFirst((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.some([2, 1]) + assertNone( + pipe([], Arr.findFirst((n, i) => n % 2 === 0 ? Option.some([n, i]) : Option.none())) ) - deepStrictEqual( - pipe([1, 2, 3, 4], RA.findFirst((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.some([2, 1]) + assertSome( + pipe([1, 2, 3], Arr.findFirst((n, i) => n % 2 === 0 ? Option.some([n, i]) : Option.none())), + [2, 1] + ) + assertSome( + pipe([1, 2, 3, 4], Arr.findFirst((n, i) => n % 2 === 0 ? Option.some([n, i]) : Option.none())), + [2, 1] ) - deepStrictEqual( - pipe(new Set(), RA.findFirst((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.none() + assertNone( + pipe(new Set(), Arr.findFirst((n, i) => n % 2 === 0 ? Option.some([n, i]) : Option.none())) ) - deepStrictEqual( - pipe(new Set([1, 2, 3]), RA.findFirst((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.some([2, 1]) + assertSome( + pipe(new Set([1, 2, 3]), Arr.findFirst((n, i) => n % 2 === 0 ? Option.some([n, i]) : Option.none())), + [2, 1] ) - deepStrictEqual( - pipe(new Set([1, 2, 3, 4]), RA.findFirst((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.some([2, 1]) + assertSome( + pipe(new Set([1, 2, 3, 4]), Arr.findFirst((n, i) => n % 2 === 0 ? Option.some([n, i]) : Option.none())), + [2, 1] ) }) }) describe("findLast", () => { it("boolean-returning overloads", () => { - deepStrictEqual(pipe([], RA.findLast((n) => n % 2 === 0)), O.none()) - deepStrictEqual(pipe([1, 2, 3], RA.findLast((n) => n % 2 === 0)), O.some(2)) - deepStrictEqual(pipe([1, 2, 3, 4], RA.findLast((n) => n % 2 === 0)), O.some(4)) + assertNone(pipe([], Arr.findLast((n) => n % 2 === 0))) + assertSome(pipe([1, 2, 3], Arr.findLast((n) => n % 2 === 0)), 2) + assertSome(pipe([1, 2, 3, 4], Arr.findLast((n) => n % 2 === 0)), 4) - deepStrictEqual(pipe(new Set(), RA.findLast((n) => n % 2 === 0)), O.none()) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.findLast((n) => n % 2 === 0)), O.some(2)) - deepStrictEqual(pipe(new Set([1, 2, 3, 4]), RA.findLast((n) => n % 2 === 0)), O.some(4)) + assertNone(pipe(new Set(), Arr.findLast((n) => n % 2 === 0))) + assertSome(pipe(new Set([1, 2, 3]), Arr.findLast((n) => n % 2 === 0)), 2) + assertSome(pipe(new Set([1, 2, 3, 4]), Arr.findLast((n) => n % 2 === 0)), 4) }) it("Option-returning overloads", () => { - deepStrictEqual(pipe([], RA.findLast((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), O.none()) - deepStrictEqual( - pipe([1, 2, 3], RA.findLast((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.some([2, 1]) + assertNone( + pipe([], Arr.findLast((n, i) => n % 2 === 0 ? Option.some([n, i]) : Option.none())) + ) + assertSome( + pipe([1, 2, 3], Arr.findLast((n, i) => n % 2 === 0 ? Option.some([n, i]) : Option.none())), + [2, 1] ) - deepStrictEqual( - pipe([1, 2, 3, 4], RA.findLast((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.some([4, 3]) + assertSome( + pipe([1, 2, 3, 4], Arr.findLast((n, i) => n % 2 === 0 ? Option.some([n, i]) : Option.none())), + [4, 3] ) - deepStrictEqual( - pipe(new Set(), RA.findLast((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.none() + assertNone( + pipe(new Set(), Arr.findLast((n, i) => n % 2 === 0 ? Option.some([n, i]) : Option.none())) ) - deepStrictEqual( - pipe(new Set([1, 2, 3]), RA.findLast((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.some([2, 1]) + assertSome( + pipe(new Set([1, 2, 3]), Arr.findLast((n, i) => n % 2 === 0 ? Option.some([n, i]) : Option.none())), + [2, 1] ) - deepStrictEqual( - pipe(new Set([1, 2, 3, 4]), RA.findLast((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.some([4, 3]) + assertSome( + pipe(new Set([1, 2, 3, 4]), Arr.findLast((n, i) => n % 2 === 0 ? Option.some([n, i]) : Option.none())), + [4, 3] ) }) }) it("insertAt", () => { - deepStrictEqual(RA.insertAt(1, 1)([]), O.none()) - deepStrictEqual(RA.insertAt(0, 1)([]), O.some([1])) - deepStrictEqual(RA.insertAt(2, 5)([1, 2, 3, 4]), O.some([1, 2, 5, 3, 4])) + assertNone(Arr.insertAt(1, 1)([])) + assertSome(Arr.insertAt(0, 1)([]), [1]) + assertSome(Arr.insertAt(2, 5)([1, 2, 3, 4]), [1, 2, 5, 3, 4]) // out of bound - deepStrictEqual(RA.insertAt(-1, 5)([1, 2, 3, 4]), O.none()) - deepStrictEqual(RA.insertAt(10, 5)([1, 2, 3, 4]), O.none()) + assertNone(Arr.insertAt(-1, 5)([1, 2, 3, 4])) + assertNone(Arr.insertAt(10, 5)([1, 2, 3, 4])) - deepStrictEqual(RA.insertAt(1, 1)(new Set([])), O.none()) - deepStrictEqual(RA.insertAt(0, 1)(new Set([])), O.some([1])) - deepStrictEqual(RA.insertAt(2, 5)(new Set([1, 2, 3, 4])), O.some([1, 2, 5, 3, 4])) + assertNone(Arr.insertAt(1, 1)(new Set([]))) + assertSome(Arr.insertAt(0, 1)(new Set([])), [1]) + assertSome(Arr.insertAt(2, 5)(new Set([1, 2, 3, 4])), [1, 2, 5, 3, 4]) // out of bound - deepStrictEqual(RA.insertAt(-1, 5)(new Set([1, 2, 3, 4])), O.none()) - deepStrictEqual(RA.insertAt(10, 5)(new Set([1, 2, 3, 4])), O.none()) + assertNone(Arr.insertAt(-1, 5)(new Set([1, 2, 3, 4]))) + assertNone(Arr.insertAt(10, 5)(new Set([1, 2, 3, 4]))) }) it("replace", () => { - deepStrictEqual(pipe([1, 2, 3], RA.replace(1, "a")), [1, "a", 3]) + deepStrictEqual(pipe([1, 2, 3], Arr.replace(1, "a")), [1, "a", 3]) // out of bound - deepStrictEqual(pipe([], RA.replace(1, "a")), []) - deepStrictEqual(pipe([1, 2, 3], RA.replace(-1, "a")), [1, 2, 3]) - deepStrictEqual(pipe([1, 2, 3], RA.replace(10, "a")), [1, 2, 3]) + deepStrictEqual(pipe([], Arr.replace(1, "a")), []) + deepStrictEqual(pipe([1, 2, 3], Arr.replace(-1, "a")), [1, 2, 3]) + deepStrictEqual(pipe([1, 2, 3], Arr.replace(10, "a")), [1, 2, 3]) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.replace(1, "a")), [1, "a", 3]) + deepStrictEqual(pipe(new Set([1, 2, 3]), Arr.replace(1, "a")), [1, "a", 3]) // out of bound - deepStrictEqual(pipe(new Set([]), RA.replace(1, "a")), []) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.replace(-1, "a")), [1, 2, 3]) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.replace(10, "a")), [1, 2, 3]) + deepStrictEqual(pipe(new Set([]), Arr.replace(1, "a")), []) + deepStrictEqual(pipe(new Set([1, 2, 3]), Arr.replace(-1, "a")), [1, 2, 3]) + deepStrictEqual(pipe(new Set([1, 2, 3]), Arr.replace(10, "a")), [1, 2, 3]) }) it("replaceOption", () => { - deepStrictEqual(pipe([1, 2, 3], RA.replaceOption(1, "a")), O.some([1, "a", 3])) + assertSome(pipe([1, 2, 3], Arr.replaceOption(1, "a")), [1, "a", 3]) // out of bound - deepStrictEqual(pipe([], RA.replaceOption(1, "a")), O.none()) - deepStrictEqual(pipe([1, 2, 3], RA.replaceOption(-1, "a")), O.none()) - deepStrictEqual(pipe([1, 2, 3], RA.replaceOption(10, "a")), O.none()) + assertNone(pipe([], Arr.replaceOption(1, "a"))) + assertNone(pipe([1, 2, 3], Arr.replaceOption(-1, "a"))) + assertNone(pipe([1, 2, 3], Arr.replaceOption(10, "a"))) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.replaceOption(1, "a")), O.some([1, "a", 3])) + assertSome(pipe(new Set([1, 2, 3]), Arr.replaceOption(1, "a")), [1, "a", 3]) // out of bound - deepStrictEqual(pipe(new Set([]), RA.replaceOption(1, "a")), O.none()) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.replaceOption(-1, "a")), O.none()) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.replaceOption(10, "a")), O.none()) + assertNone(pipe(new Set([]), Arr.replaceOption(1, "a"))) + assertNone(pipe(new Set([1, 2, 3]), Arr.replaceOption(-1, "a"))) + assertNone(pipe(new Set([1, 2, 3]), Arr.replaceOption(10, "a"))) }) it("modify", () => { - deepStrictEqual(pipe([1, 2, 3], RA.modify(1, double)), [1, 4, 3]) + deepStrictEqual(pipe([1, 2, 3], Arr.modify(1, double)), [1, 4, 3]) // out of bound - deepStrictEqual(pipe([], RA.modify(1, double)), []) - deepStrictEqual(pipe([1, 2, 3], RA.modify(10, double)), [1, 2, 3]) + deepStrictEqual(pipe([], Arr.modify(1, double)), []) + deepStrictEqual(pipe([1, 2, 3], Arr.modify(10, double)), [1, 2, 3]) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.modify(1, double)), [1, 4, 3]) + deepStrictEqual(pipe(new Set([1, 2, 3]), Arr.modify(1, double)), [1, 4, 3]) // out of bound - deepStrictEqual(pipe(new Set([]), RA.modify(1, double)), []) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.modify(10, double)), [1, 2, 3]) + deepStrictEqual(pipe(new Set([]), Arr.modify(1, double)), []) + deepStrictEqual(pipe(new Set([1, 2, 3]), Arr.modify(10, double)), [1, 2, 3]) }) it("modifyOption", () => { - deepStrictEqual(pipe([1, 2, 3], RA.modifyOption(1, double)), O.some([1, 4, 3])) + assertSome(pipe([1, 2, 3], Arr.modifyOption(1, double)), [1, 4, 3]) // out of bound - deepStrictEqual(pipe([], RA.modifyOption(1, double)), O.none()) - deepStrictEqual(pipe([1, 2, 3], RA.modifyOption(10, double)), O.none()) + assertNone(pipe([], Arr.modifyOption(1, double))) + assertNone(pipe([1, 2, 3], Arr.modifyOption(10, double))) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.modifyOption(1, double)), O.some([1, 4, 3])) + assertSome(pipe(new Set([1, 2, 3]), Arr.modifyOption(1, double)), [1, 4, 3]) // out of bound - deepStrictEqual(pipe(new Set([]), RA.modifyOption(1, double)), O.none()) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.modifyOption(10, double)), O.none()) + assertNone(pipe(new Set([]), Arr.modifyOption(1, double))) + assertNone(pipe(new Set([1, 2, 3]), Arr.modifyOption(10, double))) }) it("remove", () => { - deepStrictEqual(pipe([1, 2, 3], RA.remove(0)), [2, 3]) + deepStrictEqual(pipe([1, 2, 3], Arr.remove(0)), [2, 3]) // out of bound - deepStrictEqual(pipe([], RA.remove(0)), []) - deepStrictEqual(pipe([1, 2, 3], RA.remove(-1)), [1, 2, 3]) - deepStrictEqual(pipe([1, 2, 3], RA.remove(10)), [1, 2, 3]) + deepStrictEqual(pipe([], Arr.remove(0)), []) + deepStrictEqual(pipe([1, 2, 3], Arr.remove(-1)), [1, 2, 3]) + deepStrictEqual(pipe([1, 2, 3], Arr.remove(10)), [1, 2, 3]) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.remove(0)), [2, 3]) + deepStrictEqual(pipe(new Set([1, 2, 3]), Arr.remove(0)), [2, 3]) // out of bound - deepStrictEqual(pipe(new Set([]), RA.remove(0)), []) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.remove(-1)), [1, 2, 3]) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.remove(10)), [1, 2, 3]) + deepStrictEqual(pipe(new Set([]), Arr.remove(0)), []) + deepStrictEqual(pipe(new Set([1, 2, 3]), Arr.remove(-1)), [1, 2, 3]) + deepStrictEqual(pipe(new Set([1, 2, 3]), Arr.remove(10)), [1, 2, 3]) }) it("reverse", () => { - deepStrictEqual(RA.reverse([]), []) - deepStrictEqual(RA.reverse([1]), [1]) - deepStrictEqual(RA.reverse([1, 2, 3]), [3, 2, 1]) + deepStrictEqual(Arr.reverse([]), []) + deepStrictEqual(Arr.reverse([1]), [1]) + deepStrictEqual(Arr.reverse([1, 2, 3]), [3, 2, 1]) - deepStrictEqual(RA.reverse(new Set([])), []) - deepStrictEqual(RA.reverse(new Set([1])), [1]) - deepStrictEqual(RA.reverse(new Set([1, 2, 3])), [3, 2, 1]) + deepStrictEqual(Arr.reverse(new Set([])), []) + deepStrictEqual(Arr.reverse(new Set([1])), [1]) + deepStrictEqual(Arr.reverse(new Set([1, 2, 3])), [3, 2, 1]) }) it("sort", () => { - deepStrictEqual(RA.sort(Number.Order)([]), []) - deepStrictEqual(RA.sort(Number.Order)([1, 3, 2]), [1, 2, 3]) + deepStrictEqual(Arr.sort(Num.Order)([]), []) + deepStrictEqual(Arr.sort(Num.Order)([1, 3, 2]), [1, 2, 3]) - deepStrictEqual(RA.sort(Number.Order)(new Set()), []) - deepStrictEqual(RA.sort(Number.Order)(new Set([1, 3, 2])), [1, 2, 3]) + deepStrictEqual(Arr.sort(Num.Order)(new Set()), []) + deepStrictEqual(Arr.sort(Num.Order)(new Set([1, 3, 2])), [1, 2, 3]) }) it("zip", () => { - deepStrictEqual(pipe(new Set([]), RA.zip(new Set(["a", "b", "c", "d"]))), []) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.zip(new Set([]))), []) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.zip(new Set(["a", "b", "c", "d"]))), [ + deepStrictEqual(pipe(new Set([]), Arr.zip(new Set(["a", "b", "c", "d"]))), []) + deepStrictEqual(pipe(new Set([1, 2, 3]), Arr.zip(new Set([]))), []) + deepStrictEqual(pipe(new Set([1, 2, 3]), Arr.zip(new Set(["a", "b", "c", "d"]))), [ [1, "a"], [2, "b"], [3, "c"] ]) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.zip(new Set(["a", "b", "c", "d"]))), [ + deepStrictEqual(pipe(new Set([1, 2, 3]), Arr.zip(new Set(["a", "b", "c", "d"]))), [ [1, "a"], [2, "b"], [3, "c"] @@ -491,27 +487,27 @@ describe("ReadonlyArray", () => { it("zipWith", () => { deepStrictEqual( - pipe(new Set([1, 2, 3]), RA.zipWith(new Set([]), (n, s) => s + n)), + pipe(new Set([1, 2, 3]), Arr.zipWith(new Set([]), (n, s) => s + n)), [] ) deepStrictEqual( - pipe(new Set([]), RA.zipWith(new Set(["a", "b", "c", "d"]), (n, s) => s + n)), + pipe(new Set([]), Arr.zipWith(new Set(["a", "b", "c", "d"]), (n, s) => s + n)), [] ) deepStrictEqual( - pipe(new Set([]), RA.zipWith(new Set([]), (n, s) => s + n)), + pipe(new Set([]), Arr.zipWith(new Set([]), (n, s) => s + n)), [] ) deepStrictEqual( - pipe(new Set([1, 2, 3]), RA.zipWith(new Set(["a", "b", "c", "d"]), (n, s) => s + n)), + pipe(new Set([1, 2, 3]), Arr.zipWith(new Set(["a", "b", "c", "d"]), (n, s) => s + n)), ["a1", "b2", "c3"] ) }) it("unzip", () => { - deepStrictEqual(RA.unzip(new Set([])), [[], []]) + deepStrictEqual(Arr.unzip(new Set([])), [[], []]) deepStrictEqual( - RA.unzip( + Arr.unzip( new Set( [ [1, "a"], @@ -528,43 +524,43 @@ describe("ReadonlyArray", () => { }) it("intersperse", () => { - deepStrictEqual(pipe([], RA.intersperse(0)), []) - deepStrictEqual(pipe([1], RA.intersperse(0)), [1]) - deepStrictEqual(pipe([1, 2, 3], RA.intersperse(0)), [1, 0, 2, 0, 3]) - deepStrictEqual(pipe([1, 2], RA.intersperse(0)), [1, 0, 2]) - deepStrictEqual(pipe([1, 2, 3, 4], RA.intersperse(0)), [1, 0, 2, 0, 3, 0, 4]) - - deepStrictEqual(pipe(new Set([]), RA.intersperse(0)), []) - deepStrictEqual(pipe(new Set([1]), RA.intersperse(0)), [1]) - deepStrictEqual(pipe(new Set([1, 2, 3]), RA.intersperse(0)), [1, 0, 2, 0, 3]) - deepStrictEqual(pipe(new Set([1, 2]), RA.intersperse(0)), [1, 0, 2]) - deepStrictEqual(pipe(new Set([1, 2, 3, 4]), RA.intersperse(0)), [1, 0, 2, 0, 3, 0, 4]) + deepStrictEqual(pipe([], Arr.intersperse(0)), []) + deepStrictEqual(pipe([1], Arr.intersperse(0)), [1]) + deepStrictEqual(pipe([1, 2, 3], Arr.intersperse(0)), [1, 0, 2, 0, 3]) + deepStrictEqual(pipe([1, 2], Arr.intersperse(0)), [1, 0, 2]) + deepStrictEqual(pipe([1, 2, 3, 4], Arr.intersperse(0)), [1, 0, 2, 0, 3, 0, 4]) + + deepStrictEqual(pipe(new Set([]), Arr.intersperse(0)), []) + deepStrictEqual(pipe(new Set([1]), Arr.intersperse(0)), [1]) + deepStrictEqual(pipe(new Set([1, 2, 3]), Arr.intersperse(0)), [1, 0, 2, 0, 3]) + deepStrictEqual(pipe(new Set([1, 2]), Arr.intersperse(0)), [1, 0, 2]) + deepStrictEqual(pipe(new Set([1, 2, 3, 4]), Arr.intersperse(0)), [1, 0, 2, 0, 3, 0, 4]) }) it("rotate", () => { - deepStrictEqual(RA.rotate(0)(RA.empty()), RA.empty()) - deepStrictEqual(RA.rotate(1)(RA.empty()), RA.empty()) - deepStrictEqual(RA.rotate(1)([1]), [1]) - deepStrictEqual(RA.rotate(2)([1]), [1]) - deepStrictEqual(RA.rotate(-1)([1]), [1]) - deepStrictEqual(RA.rotate(-2)([1]), [1]) - deepStrictEqual(RA.rotate(2)([1, 2]), [1, 2]) - deepStrictEqual(RA.rotate(0)([1, 2]), [1, 2]) - deepStrictEqual(RA.rotate(-2)([1, 2]), [1, 2]) - deepStrictEqual(RA.rotate(1)([1, 2]), [2, 1]) - deepStrictEqual(RA.rotate(1)(new Set([1, 2, 3, 4, 5])), [5, 1, 2, 3, 4]) - deepStrictEqual(RA.rotate(2)(new Set([1, 2, 3, 4, 5])), [4, 5, 1, 2, 3]) - deepStrictEqual(RA.rotate(-1)(new Set([1, 2, 3, 4, 5])), [2, 3, 4, 5, 1]) - deepStrictEqual(RA.rotate(-2)(new Set([1, 2, 3, 4, 5])), [3, 4, 5, 1, 2]) + deepStrictEqual(Arr.rotate(0)(Arr.empty()), Arr.empty()) + deepStrictEqual(Arr.rotate(1)(Arr.empty()), Arr.empty()) + deepStrictEqual(Arr.rotate(1)([1]), [1]) + deepStrictEqual(Arr.rotate(2)([1]), [1]) + deepStrictEqual(Arr.rotate(-1)([1]), [1]) + deepStrictEqual(Arr.rotate(-2)([1]), [1]) + deepStrictEqual(Arr.rotate(2)([1, 2]), [1, 2]) + deepStrictEqual(Arr.rotate(0)([1, 2]), [1, 2]) + deepStrictEqual(Arr.rotate(-2)([1, 2]), [1, 2]) + deepStrictEqual(Arr.rotate(1)([1, 2]), [2, 1]) + deepStrictEqual(Arr.rotate(1)(new Set([1, 2, 3, 4, 5])), [5, 1, 2, 3, 4]) + deepStrictEqual(Arr.rotate(2)(new Set([1, 2, 3, 4, 5])), [4, 5, 1, 2, 3]) + deepStrictEqual(Arr.rotate(-1)(new Set([1, 2, 3, 4, 5])), [2, 3, 4, 5, 1]) + deepStrictEqual(Arr.rotate(-2)(new Set([1, 2, 3, 4, 5])), [3, 4, 5, 1, 2]) // out of bounds - deepStrictEqual(RA.rotate(7)([1, 2, 3, 4, 5]), [4, 5, 1, 2, 3]) - deepStrictEqual(RA.rotate(-7)([1, 2, 3, 4, 5]), [3, 4, 5, 1, 2]) - deepStrictEqual(RA.rotate(2.2)([1, 2, 3, 4, 5]), [4, 5, 1, 2, 3]) - deepStrictEqual(RA.rotate(-2.2)([1, 2, 3, 4, 5]), [3, 4, 5, 1, 2]) + deepStrictEqual(Arr.rotate(7)([1, 2, 3, 4, 5]), [4, 5, 1, 2, 3]) + deepStrictEqual(Arr.rotate(-7)([1, 2, 3, 4, 5]), [3, 4, 5, 1, 2]) + deepStrictEqual(Arr.rotate(2.2)([1, 2, 3, 4, 5]), [4, 5, 1, 2, 3]) + deepStrictEqual(Arr.rotate(-2.2)([1, 2, 3, 4, 5]), [3, 4, 5, 1, 2]) }) it("containsWith", () => { - const contains = RA.containsWith(Number.Equivalence) + const contains = Arr.containsWith(Num.Equivalence) deepStrictEqual(pipe([1, 2, 3], contains(2)), true) deepStrictEqual(pipe([1, 2, 3], contains(0)), false) @@ -573,7 +569,7 @@ describe("ReadonlyArray", () => { }) it("contains", () => { - const contains = RA.contains + const contains = Arr.contains deepStrictEqual(pipe([1, 2, 3], contains(2)), true) deepStrictEqual(pipe([1, 2, 3], contains(0)), false) @@ -582,7 +578,7 @@ describe("ReadonlyArray", () => { }) it("dedupeWith", () => { - const dedupe = RA.dedupeWith(Number.Equivalence) + const dedupe = Arr.dedupeWith(Num.Equivalence) deepStrictEqual(dedupe([]), []) deepStrictEqual(dedupe([-0, -0]), [-0]) deepStrictEqual(dedupe([0, -0]), [0]) @@ -595,10 +591,10 @@ describe("ReadonlyArray", () => { }) it("dedupeAdjacentWith", () => { - const dedupeAdjacent = RA.dedupeAdjacentWith(Number.Equivalence) - expect(dedupeAdjacent([])).toEqual([]) - expect(dedupeAdjacent([1, 2, 3])).toEqual([1, 2, 3]) - expect(dedupeAdjacent([1, 2, 2, 3, 3])).toEqual([1, 2, 3]) + const dedupeAdjacent = Arr.dedupeAdjacentWith(Num.Equivalence) + deepStrictEqual(dedupeAdjacent([]), []) + deepStrictEqual(dedupeAdjacent([1, 2, 3]), [1, 2, 3]) + deepStrictEqual(dedupeAdjacent([1, 2, 2, 3, 3]), [1, 2, 3]) }) it("splitAt", () => { @@ -608,17 +604,17 @@ describe("ReadonlyArray", () => { expectedInit: ReadonlyArray, expectedRest: ReadonlyArray ) => { - const [init, rest] = RA.splitAt(index)(input) + const [init, rest] = Arr.splitAt(index)(input) deepStrictEqual(init, expectedInit) deepStrictEqual(rest, expectedRest) } - deepStrictEqual(RA.splitAt(1)([1, 2]), [[1], [2]]) + deepStrictEqual(Arr.splitAt(1)([1, 2]), [[1], [2]]) assertSplitAt([1, 2], 2, [1, 2], []) - deepStrictEqual(RA.splitAt(2)([1, 2, 3, 4, 5]), [ + deepStrictEqual(Arr.splitAt(2)([1, 2, 3, 4, 5]), [ [1, 2], [3, 4, 5] ]) - deepStrictEqual(RA.splitAt(2)(new Set([1, 2, 3, 4, 5])), [ + deepStrictEqual(Arr.splitAt(2)(new Set([1, 2, 3, 4, 5])), [ [1, 2], [3, 4, 5] ]) @@ -634,30 +630,30 @@ describe("ReadonlyArray", () => { }) it("splitNonEmptyAt", () => { - deepStrictEqual(pipe(RA.make(1, 2, 3, 4), RA.splitNonEmptyAt(2)), [[1, 2], [3, 4]]) - deepStrictEqual(pipe(RA.make(1, 2, 3, 4), RA.splitNonEmptyAt(10)), [[1, 2, 3, 4], []]) + deepStrictEqual(pipe(Arr.make(1, 2, 3, 4), Arr.splitNonEmptyAt(2)), [[1, 2], [3, 4]]) + deepStrictEqual(pipe(Arr.make(1, 2, 3, 4), Arr.splitNonEmptyAt(10)), [[1, 2, 3, 4], []]) }) describe("unsafeGet", () => { it("should throw on index out of bound", () => { - expect(() => pipe([], RA.unsafeGet(100))).toThrowError(new Error("Index 100 out of bounds")) + throws(() => pipe([], Arr.unsafeGet(100)), new Error("Index 100 out of bounds")) }) }) it("fromNullable", () => { - deepStrictEqual(RA.fromNullable(undefined), []) - deepStrictEqual(RA.fromNullable(null), []) - deepStrictEqual(RA.fromNullable(1), [1]) + deepStrictEqual(Arr.fromNullable(undefined), []) + deepStrictEqual(Arr.fromNullable(null), []) + deepStrictEqual(Arr.fromNullable(1), [1]) }) it("liftNullable", () => { - const f = RA.liftNullable((n: number) => (n > 0 ? n : null)) + const f = Arr.liftNullable((n: number) => (n > 0 ? n : null)) deepStrictEqual(f(1), [1]) deepStrictEqual(f(-1), []) }) it("flatMapNullable", () => { - const f = RA.flatMapNullable((n: number) => (n > 0 ? n : null)) + const f = Arr.flatMapNullable((n: number) => (n > 0 ? n : null)) deepStrictEqual(pipe([], f), []) deepStrictEqual(pipe([1], f), [1]) deepStrictEqual(pipe([1, 2], f), [1, 2]) @@ -667,122 +663,122 @@ describe("ReadonlyArray", () => { it("liftPredicate", () => { const p = (n: number): boolean => n > 2 - const f = RA.liftPredicate(p) + const f = Arr.liftPredicate(p) deepStrictEqual(f(1), []) deepStrictEqual(f(3), [3]) }) it("liftOption", () => { - const f = RA.liftOption((n: number) => (n > 0 ? O.some(n) : O.none())) + const f = Arr.liftOption((n: number) => (n > 0 ? Option.some(n) : Option.none())) deepStrictEqual(f(1), [1]) deepStrictEqual(f(-1), []) }) it("unprepend", () => { - deepStrictEqual(RA.unprepend([0]), [0, []]) - deepStrictEqual(RA.unprepend([1, 2, 3, 4]), [1, [2, 3, 4]]) + deepStrictEqual(Arr.unprepend([0]), [0, []]) + deepStrictEqual(Arr.unprepend([1, 2, 3, 4]), [1, [2, 3, 4]]) }) it("unappend", () => { - deepStrictEqual(RA.unappend([0]), [[], 0]) - deepStrictEqual(RA.unappend([1, 2, 3, 4]), [ - RA.make(1, 2, 3), + deepStrictEqual(Arr.unappend([0]), [[], 0]) + deepStrictEqual(Arr.unappend([1, 2, 3, 4]), [ + Arr.make(1, 2, 3), 4 ]) - deepStrictEqual(RA.unappend([0]), [[], 0]) - deepStrictEqual(RA.unappend([1, 2, 3, 4]), [ - RA.make(1, 2, 3), + deepStrictEqual(Arr.unappend([0]), [[], 0]) + deepStrictEqual(Arr.unappend([1, 2, 3, 4]), [ + Arr.make(1, 2, 3), 4 ]) }) it("modifyNonEmptyHead", () => { const f = (s: string) => s + "!" - deepStrictEqual(pipe(["a"], RA.modifyNonEmptyHead(f)), ["a!"]) - deepStrictEqual(pipe(["a", "b"], RA.modifyNonEmptyHead(f)), ["a!", "b"]) - deepStrictEqual(pipe(["a", "b", "c"], RA.modifyNonEmptyHead(f)), ["a!", "b", "c"]) + deepStrictEqual(pipe(["a"], Arr.modifyNonEmptyHead(f)), ["a!"]) + deepStrictEqual(pipe(["a", "b"], Arr.modifyNonEmptyHead(f)), ["a!", "b"]) + deepStrictEqual(pipe(["a", "b", "c"], Arr.modifyNonEmptyHead(f)), ["a!", "b", "c"]) }) it("modifyNonEmptyLast", () => { const f = (s: string) => s + "!" - deepStrictEqual(pipe(["a"], RA.modifyNonEmptyLast(f)), ["a!"]) - deepStrictEqual(pipe(["a", "b"], RA.modifyNonEmptyLast(f)), ["a", "b!"]) - deepStrictEqual(pipe(["a", "b", "c"], RA.modifyNonEmptyLast(f)), ["a", "b", "c!"]) + deepStrictEqual(pipe(["a"], Arr.modifyNonEmptyLast(f)), ["a!"]) + deepStrictEqual(pipe(["a", "b"], Arr.modifyNonEmptyLast(f)), ["a", "b!"]) + deepStrictEqual(pipe(["a", "b", "c"], Arr.modifyNonEmptyLast(f)), ["a", "b", "c!"]) }) it("setNonEmptyHead", () => { - deepStrictEqual(pipe(RA.make("a"), RA.setNonEmptyHead("d")), ["d"]) - deepStrictEqual(pipe(RA.make("a", "b"), RA.setNonEmptyHead("d")), ["d", "b"]) - deepStrictEqual(pipe(RA.make("a", "b", "c"), RA.setNonEmptyHead("d")), ["d", "b", "c"]) + deepStrictEqual(pipe(Arr.make("a"), Arr.setNonEmptyHead("d")), ["d"]) + deepStrictEqual(pipe(Arr.make("a", "b"), Arr.setNonEmptyHead("d")), ["d", "b"]) + deepStrictEqual(pipe(Arr.make("a", "b", "c"), Arr.setNonEmptyHead("d")), ["d", "b", "c"]) }) it("setNonEmptyLast", () => { - deepStrictEqual(pipe(RA.make("a"), RA.setNonEmptyLast("d")), ["d"]) - deepStrictEqual(pipe(RA.make("a", "b"), RA.setNonEmptyLast("d")), ["a", "d"]) - deepStrictEqual(pipe(RA.make("a", "b", "c"), RA.setNonEmptyLast("d")), ["a", "b", "d"]) + deepStrictEqual(pipe(Arr.make("a"), Arr.setNonEmptyLast("d")), ["d"]) + deepStrictEqual(pipe(Arr.make("a", "b"), Arr.setNonEmptyLast("d")), ["a", "d"]) + deepStrictEqual(pipe(Arr.make("a", "b", "c"), Arr.setNonEmptyLast("d")), ["a", "b", "d"]) }) it("liftEither", () => { - const f = RA.liftEither((s: string) => s.length > 2 ? E.right(s.length) : E.left("e")) + const f = Arr.liftEither((s: string) => s.length > 2 ? Either.right(s.length) : Either.left("e")) deepStrictEqual(f("a"), []) deepStrictEqual(f("aaa"), [3]) }) it("headNonEmpty", () => { - deepStrictEqual(RA.headNonEmpty(RA.make(1, 2)), 1) + deepStrictEqual(Arr.headNonEmpty(Arr.make(1, 2)), 1) }) it("tailNonEmpty", () => { - deepStrictEqual(RA.tailNonEmpty(RA.make(1, 2)), [2]) + deepStrictEqual(Arr.tailNonEmpty(Arr.make(1, 2)), [2]) }) it("lastNonEmpty", () => { - deepStrictEqual(RA.lastNonEmpty(RA.make(1, 2, 3)), 3) - deepStrictEqual(RA.lastNonEmpty([1]), 1) + deepStrictEqual(Arr.lastNonEmpty(Arr.make(1, 2, 3)), 3) + deepStrictEqual(Arr.lastNonEmpty([1]), 1) }) it("initNonEmpty", () => { deepStrictEqual( - RA.initNonEmpty(RA.make(1, 2, 3)), - RA.make(1, 2) + Arr.initNonEmpty(Arr.make(1, 2, 3)), + Arr.make(1, 2) ) - deepStrictEqual(RA.initNonEmpty([1]), []) + deepStrictEqual(Arr.initNonEmpty([1]), []) }) it("get", () => { - deepStrictEqual(pipe([1, 2, 3], RA.get(0)), O.some(1)) - deepStrictEqual(pipe([1, 2, 3], RA.get(3)), O.none()) + assertSome(pipe([1, 2, 3], Arr.get(0)), 1) + assertNone(pipe([1, 2, 3], Arr.get(3))) }) it("unfold", () => { - const as = RA.unfold(5, (n) => (n > 0 ? O.some([n, n - 1]) : O.none())) + const as = Arr.unfold(5, (n) => (n > 0 ? Option.some([n, n - 1]) : Option.none())) deepStrictEqual(as, [5, 4, 3, 2, 1]) }) it("map", () => { deepStrictEqual( - pipe([1, 2, 3], RA.map((n) => n * 2)), + pipe([1, 2, 3], Arr.map((n) => n * 2)), [2, 4, 6] ) deepStrictEqual( - pipe(["a", "b"], RA.map((s, i) => s + i)), + pipe(["a", "b"], Arr.map((s, i) => s + i)), ["a0", "b1"] ) }) it("flatMap", () => { deepStrictEqual( - pipe([1, 2, 3], RA.flatMap((n) => [n, n + 1])), + pipe([1, 2, 3], Arr.flatMap((n) => [n, n + 1])), [1, 2, 2, 3, 3, 4] ) - const f = RA.flatMap((n: number, i) => [n + i]) + const f = Arr.flatMap((n: number, i) => [n + i]) deepStrictEqual(pipe([], f), []) deepStrictEqual(pipe([1, 2, 3], f), [1, 3, 5]) }) it("extend", () => { - deepStrictEqual(pipe([1, 2, 3, 4], RA.extend(Number.sumAll)), [10, 9, 7, 4]) - deepStrictEqual(pipe([1, 2, 3, 4], RA.extend(identity)), [ + deepStrictEqual(pipe([1, 2, 3, 4], Arr.extend(Num.sumAll)), [10, 9, 7, 4]) + deepStrictEqual(pipe([1, 2, 3, 4], Arr.extend(identity)), [ [1, 2, 3, 4], [2, 3, 4], [3, 4], @@ -791,61 +787,68 @@ describe("ReadonlyArray", () => { }) it("compact", () => { - assert.deepStrictEqual(RA.getSomes([]), []) - assert.deepStrictEqual(RA.getSomes([O.some(1), O.some(2), O.some(3)]), [ + deepStrictEqual(Arr.getSomes([]), []) + deepStrictEqual(Arr.getSomes([Option.some(1), Option.some(2), Option.some(3)]), [ 1, 2, 3 ]) - assert.deepStrictEqual(RA.getSomes([O.some(1), O.none(), O.some(3)]), [ + deepStrictEqual(Arr.getSomes([Option.some(1), Option.none(), Option.some(3)]), [ 1, 3 ]) }) it("separate", () => { - expect(RA.separate([])).toEqual([[], []]) - expect(RA.separate([E.right(1), E.left("e"), E.left(2), E.right(2)])).toEqual([ + deepStrictEqual(Arr.separate([]), [[], []]) + deepStrictEqual(Arr.separate([Either.right(1), Either.left("e"), Either.left(2), Either.right(2)]), [ ["e", 2], [1, 2] ]) }) it("filter", () => { - deepStrictEqual(RA.filter([1, 2, 3], (n) => n % 2 === 1), [1, 3]) - deepStrictEqual(RA.filter([O.some(3), O.some(2), O.some(1)], O.isSome), [O.some(3), O.some(2), O.some(1)]) - deepStrictEqual(RA.filter([O.some(3), O.none(), O.some(1)], O.isSome), [O.some(3), O.some(1)]) - deepStrictEqual(RA.filter(["a", "b", "c"], (_, i) => i % 2 === 0), ["a", "c"]) + deepStrictEqual(Arr.filter([1, 2, 3], (n) => n % 2 === 1), [1, 3]) + deepStrictEqual(Arr.filter([Option.some(3), Option.some(2), Option.some(1)], Option.isSome), [ + Option.some(3), + Option.some(2), + Option.some(1) + ]) + deepStrictEqual(Arr.filter([Option.some(3), Option.none(), Option.some(1)], Option.isSome), [ + Option.some(3), + Option.some(1) + ]) + deepStrictEqual(Arr.filter(["a", "b", "c"], (_, i) => i % 2 === 0), ["a", "c"]) }) it("filterMap", () => { - const f = (n: number) => (n % 2 === 0 ? O.none() : O.some(n)) - deepStrictEqual(pipe([1, 2, 3], RA.filterMap(f)), [1, 3]) - deepStrictEqual(pipe([], RA.filterMap(f)), []) - const g = (n: number, i: number) => ((i + n) % 2 === 0 ? O.none() : O.some(n)) - deepStrictEqual(pipe([1, 2, 4], RA.filterMap(g)), [1, 2]) - deepStrictEqual(pipe([], RA.filterMap(g)), []) + const f = (n: number) => (n % 2 === 0 ? Option.none() : Option.some(n)) + deepStrictEqual(pipe([1, 2, 3], Arr.filterMap(f)), [1, 3]) + deepStrictEqual(pipe([], Arr.filterMap(f)), []) + const g = (n: number, i: number) => ((i + n) % 2 === 0 ? Option.none() : Option.some(n)) + deepStrictEqual(pipe([1, 2, 4], Arr.filterMap(g)), [1, 2]) + deepStrictEqual(pipe([], Arr.filterMap(g)), []) }) it("partitionMap", () => { - expect(RA.partitionMap([], identity)).toEqual([[], []]) - expect(RA.partitionMap([E.right(1), E.left("a"), E.right(2)], identity)).toEqual([["a"], [1, 2]]) + deepStrictEqual(Arr.partitionMap([], identity), [[], []]) + deepStrictEqual(Arr.partitionMap([Either.right(1), Either.left("a"), Either.right(2)], identity), [["a"], [1, 2]]) }) it("partition", () => { - expect(RA.partition([], (n) => n > 2)).toEqual([[], []]) - expect(RA.partition([1, 3], (n) => n > 2)).toEqual([[1], [3]]) + deepStrictEqual(Arr.partition([], (n) => n > 2), [[], []]) + deepStrictEqual(Arr.partition([1, 3], (n) => n > 2), [[1], [3]]) - expect(RA.partition([], (n, i) => n + i > 2)).toEqual([[], []]) - expect(RA.partition([1, 2], (n, i) => n + i > 2)).toEqual([[1], [2]]) + deepStrictEqual(Arr.partition([], (n, i) => n + i > 2), [[], []]) + deepStrictEqual(Arr.partition([1, 2], (n, i) => n + i > 2), [[1], [2]]) }) it("reduce", () => { - deepStrictEqual(pipe(["a", "b", "c"], RA.reduce("", (b, a) => b + a)), "abc") + deepStrictEqual(pipe(["a", "b", "c"], Arr.reduce("", (b, a) => b + a)), "abc") deepStrictEqual( pipe( ["a", "b"], - RA.reduce("", (b, a, i) => b + i + a) + Arr.reduce("", (b, a, i) => b + i + a) ), "0a1b" ) @@ -853,19 +856,19 @@ describe("ReadonlyArray", () => { it("reduceRight", () => { const f = (b: string, a: string) => b + a - deepStrictEqual(pipe(["a", "b", "c"], RA.reduceRight("", f)), "cba") - deepStrictEqual(pipe([], RA.reduceRight("", f)), "") + deepStrictEqual(pipe(["a", "b", "c"], Arr.reduceRight("", f)), "cba") + deepStrictEqual(pipe([], Arr.reduceRight("", f)), "") deepStrictEqual( pipe( ["a", "b"], - RA.reduceRight("", (b, a, i) => b + i + a) + Arr.reduceRight("", (b, a, i) => b + i + a) ), "1b0a" ) }) it("getOrder", () => { - const O = RA.getOrder(String.Order) + const O = Arr.getOrder(Str.Order) deepStrictEqual(O([], []), 0) deepStrictEqual(O(["a"], ["a"]), 0) @@ -891,106 +894,106 @@ describe("ReadonlyArray", () => { }) it("isEmptyReadonlyArray", () => { - deepStrictEqual(RA.isEmptyReadonlyArray([1, 2, 3]), false) - deepStrictEqual(RA.isEmptyReadonlyArray([]), true) + deepStrictEqual(Arr.isEmptyReadonlyArray([1, 2, 3]), false) + deepStrictEqual(Arr.isEmptyReadonlyArray([]), true) }) it("isEmptyArray", () => { - deepStrictEqual(RA.isEmptyArray([1, 2, 3]), false) - deepStrictEqual(RA.isEmptyArray([]), true) + deepStrictEqual(Arr.isEmptyArray([1, 2, 3]), false) + deepStrictEqual(Arr.isEmptyArray([]), true) }) it("isNonEmptyReadonlyArray", () => { - deepStrictEqual(RA.isNonEmptyReadonlyArray([1, 2, 3]), true) - deepStrictEqual(RA.isNonEmptyReadonlyArray([]), false) + deepStrictEqual(Arr.isNonEmptyReadonlyArray([1, 2, 3]), true) + deepStrictEqual(Arr.isNonEmptyReadonlyArray([]), false) }) it("isNonEmptyArray", () => { - deepStrictEqual(RA.isNonEmptyArray([1, 2, 3]), true) - deepStrictEqual(RA.isNonEmptyArray([]), false) + deepStrictEqual(Arr.isNonEmptyArray([1, 2, 3]), true) + deepStrictEqual(Arr.isNonEmptyArray([]), false) }) it("head", () => { const as: ReadonlyArray = [1, 2, 3] - deepStrictEqual(RA.head(as), O.some(1)) - deepStrictEqual(RA.head([]), O.none()) + assertSome(Arr.head(as), 1) + assertNone(Arr.head([])) }) it("last", () => { const as: ReadonlyArray = [1, 2, 3] - deepStrictEqual(RA.last(as), O.some(3)) - deepStrictEqual(RA.last([]), O.none()) + assertSome(Arr.last(as), 3) + assertNone(Arr.last([])) }) it("chunksOf", () => { - deepStrictEqual(RA.chunksOf(2)([1, 2, 3, 4, 5]), [ - RA.make(1, 2), + deepStrictEqual(Arr.chunksOf(2)([1, 2, 3, 4, 5]), [ + Arr.make(1, 2), [3, 4], [5] ]) - deepStrictEqual(RA.chunksOf(2)([1, 2, 3, 4, 5, 6]), [ - RA.make(1, 2), + deepStrictEqual(Arr.chunksOf(2)([1, 2, 3, 4, 5, 6]), [ + Arr.make(1, 2), [3, 4], [5, 6] ]) - deepStrictEqual(RA.chunksOf(1)([1, 2, 3, 4, 5]), [[1], [2], [3], [4], [5]]) - deepStrictEqual(RA.chunksOf(5)([1, 2, 3, 4, 5]), [[1, 2, 3, 4, 5]]) + deepStrictEqual(Arr.chunksOf(1)([1, 2, 3, 4, 5]), [[1], [2], [3], [4], [5]]) + deepStrictEqual(Arr.chunksOf(5)([1, 2, 3, 4, 5]), [[1, 2, 3, 4, 5]]) // out of bounds - deepStrictEqual(RA.chunksOf(0)([1, 2, 3, 4, 5]), [[1], [2], [3], [4], [5]]) - deepStrictEqual(RA.chunksOf(-1)([1, 2, 3, 4, 5]), [[1], [2], [3], [4], [5]]) + deepStrictEqual(Arr.chunksOf(0)([1, 2, 3, 4, 5]), [[1], [2], [3], [4], [5]]) + deepStrictEqual(Arr.chunksOf(-1)([1, 2, 3, 4, 5]), [[1], [2], [3], [4], [5]]) const assertSingleChunk = ( - input: RA.NonEmptyReadonlyArray, + input: Arr.NonEmptyReadonlyArray, n: number ) => { - const chunks = RA.chunksOf(n)(input) + const chunks = Arr.chunksOf(n)(input) strictEqual(chunks.length, 1) - deepStrictEqual(RA.headNonEmpty(chunks), input) + deepStrictEqual(Arr.headNonEmpty(chunks), input) } // n = length - assertSingleChunk(RA.make(1, 2), 2) + assertSingleChunk(Arr.make(1, 2), 2) // n out of bounds - assertSingleChunk(RA.make(1, 2), 3) + assertSingleChunk(Arr.make(1, 2), 3) }) it("min", () => { - deepStrictEqual(RA.min(Number.Order)([2, 1, 3]), 1) - deepStrictEqual(RA.min(Number.Order)([3]), 3) + deepStrictEqual(Arr.min(Num.Order)([2, 1, 3]), 1) + deepStrictEqual(Arr.min(Num.Order)([3]), 3) }) it("max", () => { deepStrictEqual( - RA.max(Number.Order)(RA.make(1, 2, 3)), + Arr.max(Num.Order)(Arr.make(1, 2, 3)), 3 ) - deepStrictEqual(RA.max(Number.Order)([1]), 1) + deepStrictEqual(Arr.max(Num.Order)([1]), 1) }) it("flatten", () => { - expect(RA.flatten([[1], [2], [3]])).toEqual([1, 2, 3]) + deepStrictEqual(Arr.flatten([[1], [2], [3]]), [1, 2, 3]) }) it("groupWith", () => { - const groupWith = RA.groupWith(Number.Equivalence) + const groupWith = Arr.groupWith(Num.Equivalence) deepStrictEqual(groupWith([1, 2, 1, 1]), [[1], [2], [1, 1]]) deepStrictEqual(groupWith([1, 2, 1, 1, 3]), [[1], [2], [1, 1], [3]]) }) it("groupBy", () => { - deepStrictEqual(RA.groupBy((_) => "")([]), {}) - deepStrictEqual(RA.groupBy((a) => `${a}`)([1]), { "1": [1] }) + deepStrictEqual(Arr.groupBy((_) => "")([]), {}) + deepStrictEqual(Arr.groupBy((a) => `${a}`)([1]), { "1": [1] }) deepStrictEqual( - RA.groupBy((s: string) => `${s.length}`)(["foo", "bar", "foobar"]), + Arr.groupBy((s: string) => `${s.length}`)(["foo", "bar", "foobar"]), { "3": ["foo", "bar"], "6": ["foobar"] } ) - expect(RA.groupBy(["a", "b"], (s) => s === "a" ? symA : s === "b" ? symB : symC)).toStrictEqual({ + deepStrictEqual(Arr.groupBy(["a", "b"], (s) => s === "a" ? symA : s === "b" ? symB : symC), { [symA]: ["a"], [symB]: ["b"] }) - expect(RA.groupBy(["a", "b", "c", "d"], (s) => s === "a" ? symA : s === "b" ? symB : symC)).toStrictEqual({ + deepStrictEqual(Arr.groupBy(["a", "b", "c", "d"], (s) => s === "a" ? symA : s === "b" ? symB : symC), { [symA]: ["a"], [symB]: ["b"], [symC]: ["c", "d"] @@ -998,7 +1001,7 @@ describe("ReadonlyArray", () => { }) it("match", () => { - const len: (as: ReadonlyArray) => number = RA.match({ + const len: (as: ReadonlyArray) => number = Arr.match({ onEmpty: () => 0, onNonEmpty: (as) => 1 + len(as.slice(1)) }) @@ -1006,7 +1009,7 @@ describe("ReadonlyArray", () => { }) it("matchLeft", () => { - const len: (as: ReadonlyArray) => number = RA.matchLeft({ + const len: (as: ReadonlyArray) => number = Arr.matchLeft({ onEmpty: () => 0, onNonEmpty: (_, tail) => 1 + len(tail) }) @@ -1014,7 +1017,7 @@ describe("ReadonlyArray", () => { }) it("matchRight", () => { - const len: (as: ReadonlyArray) => number = RA.matchRight({ + const len: (as: ReadonlyArray) => number = Arr.matchRight({ onEmpty: () => 0, onNonEmpty: (init, _) => 1 + len(init) }) @@ -1029,25 +1032,25 @@ describe("ReadonlyArray", () => { } const byName = pipe( - String.Order, + Str.Order, Order.mapInput((p: { readonly a: string; readonly b: number }) => p.a) ) const byAge = pipe( - Number.Order, + Num.Order, Order.mapInput((p: { readonly a: string; readonly b: number }) => p.b) ) - const sortByNameByAge = RA.sortBy(byName, byAge) + const sortByNameByAge = Arr.sortBy(byName, byAge) - const xs: RA.NonEmptyArray = [ + const xs: Arr.NonEmptyArray = [ { a: "a", b: 1, c: true }, { a: "b", b: 3, c: true }, { a: "c", b: 2, c: true }, { a: "b", b: 2, c: true } ] - deepStrictEqual(RA.sortBy()(xs), xs) + deepStrictEqual(Arr.sortBy()(xs), xs) deepStrictEqual(sortByNameByAge([]), []) deepStrictEqual(sortByNameByAge(xs), [ { a: "a", b: 1, c: true }, @@ -1056,7 +1059,7 @@ describe("ReadonlyArray", () => { { a: "c", b: 2, c: true } ]) - deepStrictEqual(RA.sortBy()(new Set(xs)), xs) + deepStrictEqual(Arr.sortBy()(new Set(xs)), xs) deepStrictEqual(sortByNameByAge(new Set([])), []) deepStrictEqual(sortByNameByAge(new Set(xs)), [ { a: "a", b: 1, c: true }, @@ -1065,7 +1068,7 @@ describe("ReadonlyArray", () => { { a: "c", b: 2, c: true } ]) - const sortByAgeByName = RA.sortBy(byAge, byName) + const sortByAgeByName = Arr.sortBy(byAge, byName) deepStrictEqual(sortByAgeByName(xs), [ { a: "a", b: 1, c: true }, { a: "b", b: 2, c: true }, @@ -1075,39 +1078,39 @@ describe("ReadonlyArray", () => { }) it("copy", () => { - expect(pipe([], RA.copy)).toEqual([]) - expect(pipe([1, 2, 3], RA.copy)).toEqual([1, 2, 3]) + deepStrictEqual(pipe([], Arr.copy), []) + deepStrictEqual(pipe([1, 2, 3], Arr.copy), [1, 2, 3]) }) it("chop", () => { - deepStrictEqual(pipe([], RA.chop((as) => [as[0] * 2, as.slice(1)])), []) - deepStrictEqual(pipe([1, 2, 3], RA.chop((as) => [as[0] * 2, as.slice(1)])), [2, 4, 6]) + deepStrictEqual(pipe([], Arr.chop((as) => [as[0] * 2, as.slice(1)])), []) + deepStrictEqual(pipe([1, 2, 3], Arr.chop((as) => [as[0] * 2, as.slice(1)])), [2, 4, 6]) }) it("pad", () => { - deepStrictEqual(pipe([], RA.pad(0, 0)), []) - deepStrictEqual(pipe([1, 2, 3], RA.pad(0, 0)), []) - deepStrictEqual(pipe([1, 2, 3], RA.pad(2, 0)), [1, 2]) - deepStrictEqual(pipe([1, 2, 3], RA.pad(6, 0)), [1, 2, 3, 0, 0, 0]) - deepStrictEqual(pipe([1, 2, 3], RA.pad(-2, 0)), []) + deepStrictEqual(pipe([], Arr.pad(0, 0)), []) + deepStrictEqual(pipe([1, 2, 3], Arr.pad(0, 0)), []) + deepStrictEqual(pipe([1, 2, 3], Arr.pad(2, 0)), [1, 2]) + deepStrictEqual(pipe([1, 2, 3], Arr.pad(6, 0)), [1, 2, 3, 0, 0, 0]) + deepStrictEqual(pipe([1, 2, 3], Arr.pad(-2, 0)), []) }) describe("chunksOf", () => { it("should split a `ReadonlyArray` into length-n pieces", () => { - deepStrictEqual(RA.chunksOf(2)([1, 2, 3, 4, 5]), [[1, 2], [3, 4], [5]]) - deepStrictEqual(RA.chunksOf(2)([1, 2, 3, 4, 5, 6]), [ + deepStrictEqual(Arr.chunksOf(2)([1, 2, 3, 4, 5]), [[1, 2], [3, 4], [5]]) + deepStrictEqual(Arr.chunksOf(2)([1, 2, 3, 4, 5, 6]), [ [1, 2], [3, 4], [5, 6] ]) - deepStrictEqual(RA.chunksOf(1)([1, 2, 3, 4, 5]), [[1], [2], [3], [4], [5]]) - deepStrictEqual(RA.chunksOf(5)([1, 2, 3, 4, 5]), [[1, 2, 3, 4, 5]]) + deepStrictEqual(Arr.chunksOf(1)([1, 2, 3, 4, 5]), [[1], [2], [3], [4], [5]]) + deepStrictEqual(Arr.chunksOf(5)([1, 2, 3, 4, 5]), [[1, 2, 3, 4, 5]]) // out of bounds - deepStrictEqual(RA.chunksOf(0)([1, 2, 3, 4, 5]), [[1], [2], [3], [4], [5]]) - deepStrictEqual(RA.chunksOf(-1)([1, 2, 3, 4, 5]), [[1], [2], [3], [4], [5]]) + deepStrictEqual(Arr.chunksOf(0)([1, 2, 3, 4, 5]), [[1], [2], [3], [4], [5]]) + deepStrictEqual(Arr.chunksOf(-1)([1, 2, 3, 4, 5]), [[1], [2], [3], [4], [5]]) const assertSingleChunk = (input: ReadonlyArray, n: number) => { - const chunks = RA.chunksOf(n)(input) + const chunks = Arr.chunksOf(n)(input) deepStrictEqual(chunks.length, 1) deepStrictEqual(chunks[0], input) } @@ -1119,20 +1122,20 @@ describe("ReadonlyArray", () => { it("returns an empty array if provided an empty array", () => { const empty: ReadonlyArray = [] - deepStrictEqual(RA.chunksOf(0)(empty), RA.empty()) - deepStrictEqual(RA.chunksOf(0)(RA.empty()), RA.empty()) - deepStrictEqual(RA.chunksOf(1)(empty), RA.empty()) - deepStrictEqual(RA.chunksOf(1)(RA.empty()), RA.empty()) - deepStrictEqual(RA.chunksOf(2)(empty), RA.empty()) - deepStrictEqual(RA.chunksOf(2)(RA.empty()), RA.empty()) + deepStrictEqual(Arr.chunksOf(0)(empty), Arr.empty()) + deepStrictEqual(Arr.chunksOf(0)(Arr.empty()), Arr.empty()) + deepStrictEqual(Arr.chunksOf(1)(empty), Arr.empty()) + deepStrictEqual(Arr.chunksOf(1)(Arr.empty()), Arr.empty()) + deepStrictEqual(Arr.chunksOf(2)(empty), Arr.empty()) + deepStrictEqual(Arr.chunksOf(2)(Arr.empty()), Arr.empty()) }) it("should respect the law: chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))", () => { const xs: ReadonlyArray = [] const ys: ReadonlyArray = [1, 2] deepStrictEqual( - RA.chunksOf(2)(xs).concat(RA.chunksOf(2)(ys)), - RA.chunksOf(2)(xs.concat(ys)) + Arr.chunksOf(2)(xs).concat(Arr.chunksOf(2)(ys)), + Arr.chunksOf(2)(xs.concat(ys)) ) fc.assert( fc.property( @@ -1140,8 +1143,8 @@ describe("ReadonlyArray", () => { fc.array(fc.integer()), fc.integer({ min: 1, max: 1 }).map((x) => x * 2), // Generates `n` to be even so that it evenly divides `xs` (xs, ys, n) => { - const as = RA.chunksOf(n)(xs).concat(RA.chunksOf(n)(ys)) - const bs = RA.chunksOf(n)(xs.concat(ys)) + const as = Arr.chunksOf(n)(xs).concat(Arr.chunksOf(n)(ys)) + const bs = Arr.chunksOf(n)(xs.concat(ys)) deepStrictEqual(as, bs) } ) @@ -1150,87 +1153,87 @@ describe("ReadonlyArray", () => { }) it("makeBy", () => { - deepStrictEqual(RA.makeBy(5, (n) => n * 2), [0, 2, 4, 6, 8]) - deepStrictEqual(RA.makeBy(2.2, (n) => n * 2), [0, 2]) + deepStrictEqual(Arr.makeBy(5, (n) => n * 2), [0, 2, 4, 6, 8]) + deepStrictEqual(Arr.makeBy(2.2, (n) => n * 2), [0, 2]) }) it("replicate", () => { - deepStrictEqual(RA.replicate("a", 0), ["a"]) - deepStrictEqual(RA.replicate("a", -1), ["a"]) - deepStrictEqual(RA.replicate("a", 3), ["a", "a", "a"]) - deepStrictEqual(RA.replicate("a", 2.2), ["a", "a"]) + deepStrictEqual(Arr.replicate("a", 0), ["a"]) + deepStrictEqual(Arr.replicate("a", -1), ["a"]) + deepStrictEqual(Arr.replicate("a", 3), ["a", "a", "a"]) + deepStrictEqual(Arr.replicate("a", 2.2), ["a", "a"]) }) it("range", () => { - expect(RA.range(0, 0)).toEqual([0]) - expect(RA.range(0, 1)).toEqual([0, 1]) - expect(RA.range(1, 5)).toEqual([1, 2, 3, 4, 5]) - expect(RA.range(10, 15)).toEqual([10, 11, 12, 13, 14, 15]) - expect(RA.range(-1, 0)).toEqual([-1, 0]) - expect(RA.range(-5, -1)).toEqual([-5, -4, -3, -2, -1]) + deepStrictEqual(Arr.range(0, 0), [0]) + deepStrictEqual(Arr.range(0, 1), [0, 1]) + deepStrictEqual(Arr.range(1, 5), [1, 2, 3, 4, 5]) + deepStrictEqual(Arr.range(10, 15), [10, 11, 12, 13, 14, 15]) + deepStrictEqual(Arr.range(-1, 0), [-1, 0]) + deepStrictEqual(Arr.range(-5, -1), [-5, -4, -3, -2, -1]) // out of bound - expect(RA.range(2, 1)).toEqual([2]) - expect(RA.range(-1, -2)).toEqual([-1]) + deepStrictEqual(Arr.range(2, 1), [2]) + deepStrictEqual(Arr.range(-1, -2), [-1]) }) it("unionWith", () => { const two: ReadonlyArray = [1, 2] - deepStrictEqual(pipe(two, RA.unionWith([3, 4], Number.Equivalence)), [1, 2, 3, 4]) - deepStrictEqual(pipe(two, RA.unionWith([2, 3], Number.Equivalence)), [1, 2, 3]) - deepStrictEqual(pipe(two, RA.unionWith([1, 2], Number.Equivalence)), [1, 2]) - deepStrictEqual(pipe(two, RA.unionWith(RA.empty(), Number.Equivalence)), two) - deepStrictEqual(pipe(RA.empty(), RA.unionWith(two, Number.Equivalence)), two) + deepStrictEqual(pipe(two, Arr.unionWith([3, 4], Num.Equivalence)), [1, 2, 3, 4]) + deepStrictEqual(pipe(two, Arr.unionWith([2, 3], Num.Equivalence)), [1, 2, 3]) + deepStrictEqual(pipe(two, Arr.unionWith([1, 2], Num.Equivalence)), [1, 2]) + deepStrictEqual(pipe(two, Arr.unionWith(Arr.empty(), Num.Equivalence)), two) + deepStrictEqual(pipe(Arr.empty(), Arr.unionWith(two, Num.Equivalence)), two) deepStrictEqual( - pipe(RA.empty(), RA.unionWith(RA.empty(), Number.Equivalence)), - RA.empty() + pipe(Arr.empty(), Arr.unionWith(Arr.empty(), Num.Equivalence)), + Arr.empty() ) }) it("intersectionWith", () => { - const intersectionWith = RA.intersectionWith(Number.Equivalence) + const intersectionWith = Arr.intersectionWith(Num.Equivalence) deepStrictEqual(pipe([1, 2], intersectionWith([3, 4])), []) deepStrictEqual(pipe([1, 2], intersectionWith([2, 3])), [2]) deepStrictEqual(pipe([1, 2], intersectionWith([1, 2])), [1, 2]) }) it("differenceWith", () => { - const differenceWith = RA.differenceWith(Number.Equivalence) + const differenceWith = Arr.differenceWith(Num.Equivalence) deepStrictEqual(pipe([1, 2], differenceWith([3, 4])), [1, 2]) deepStrictEqual(pipe([1, 2], differenceWith([2, 3])), [1]) deepStrictEqual(pipe([1, 2], differenceWith([1, 2])), []) }) it("empty", () => { - deepStrictEqual(RA.empty.length, 0) + deepStrictEqual(Arr.empty.length, 0) }) it("every", () => { - const isPositive: Predicate = (n) => n > 0 - expect(RA.every([1, 2, 3], isPositive)).toEqual(true) - expect(RA.every([1, 2, -3], isPositive)).toEqual(false) + const isPositive: Predicate.Predicate = (n) => n > 0 + deepStrictEqual(Arr.every([1, 2, 3], isPositive), true) + deepStrictEqual(Arr.every([1, 2, -3], isPositive), false) }) it("some", () => { - const isPositive: Predicate = (n) => n > 0 - expect(RA.some([-1, -2, 3], isPositive)).toEqual(true) - expect(RA.some([-1, -2, -3], isPositive)).toEqual(false) + const isPositive: Predicate.Predicate = (n) => n > 0 + deepStrictEqual(Arr.some([-1, -2, 3], isPositive), true) + deepStrictEqual(Arr.some([-1, -2, -3], isPositive), false) }) it("length", () => { - deepStrictEqual(RA.length(RA.empty()), 0) - deepStrictEqual(RA.length([]), 0) - deepStrictEqual(RA.length(["a"]), 1) + deepStrictEqual(Arr.length(Arr.empty()), 0) + deepStrictEqual(Arr.length([]), 0) + deepStrictEqual(Arr.length(["a"]), 1) }) it("fromOption", () => { - deepStrictEqual(RA.fromOption(O.some("hello")), ["hello"]) - deepStrictEqual(RA.fromOption(O.none()), []) + deepStrictEqual(Arr.fromOption(Option.some("hello")), ["hello"]) + deepStrictEqual(Arr.fromOption(Option.none()), []) }) it("forEach", () => { const log: Array = [] - RA.forEach(["a", "b", "c"], (a, i) => log.push(`${a}-${i}`)) - expect(log).toEqual(["a-0", "b-1", "c-2"]) + Arr.forEach(["a", "b", "c"], (a, i) => log.push(`${a}-${i}`)) + deepStrictEqual(log, ["a-0", "b-1", "c-2"]) }) it("sortWith", () => { @@ -1239,28 +1242,28 @@ describe("ReadonlyArray", () => { b: number } const arr: ReadonlyArray = [{ a: "a", b: 2 }, { a: "b", b: 1 }] - expect(RA.sortWith(arr, (x) => x.b, Order.number)).toEqual([{ a: "b", b: 1 }, { a: "a", b: 2 }]) + deepStrictEqual(Arr.sortWith(arr, (x) => x.b, Order.number), [{ a: "b", b: 1 }, { a: "a", b: 2 }]) }) it("Do notation", () => { - const _do = RA.Do - Util.deepStrictEqual(_do, RA.of({})) + const _do = Arr.Do + deepStrictEqual(_do, Arr.of({})) - const doA = RA.bind(_do, "a", () => ["a"]) - Util.deepStrictEqual(doA, RA.of({ a: "a" })) + const doA = Arr.bind(_do, "a", () => ["a"]) + deepStrictEqual(doA, Arr.of({ a: "a" })) - const doAB = RA.bind(doA, "b", (x) => ["b", x.a + "b"]) - Util.deepStrictEqual(doAB, [ + const doAB = Arr.bind(doA, "b", (x) => ["b", x.a + "b"]) + deepStrictEqual(doAB, [ { a: "a", b: "b" }, { a: "a", b: "ab" } ]) - const doABC = RA.let(doAB, "c", (x) => [x.a, x.b, x.a + x.b]) - Util.deepStrictEqual(doABC, [ + const doABC = Arr.let(doAB, "c", (x) => [x.a, x.b, x.a + x.b]) + deepStrictEqual(doABC, [ { a: "a", b: "b", c: ["a", "b", "ab"] }, { a: "a", b: "ab", c: ["a", "ab", "aab"] } ]) - const doABCD = RA.bind(doABC, "d", () => RA.empty()) - Util.deepStrictEqual(doABCD, []) + const doABCD = Arr.bind(doABC, "d", () => Arr.empty()) + deepStrictEqual(doABCD, []) }) }) diff --git a/packages/effect/test/BigDecimal.test.ts b/packages/effect/test/BigDecimal.test.ts index 191d048b7b3..41469cdefd9 100644 --- a/packages/effect/test/BigDecimal.test.ts +++ b/packages/effect/test/BigDecimal.test.ts @@ -1,83 +1,89 @@ -import * as BigDecimal from "effect/BigDecimal" -import * as Equal from "effect/Equal" -import * as fc from "effect/FastCheck" -import * as Option from "effect/Option" -import { assert, describe, expect, it } from "vitest" - -const _ = BigDecimal.unsafeFromString -const assertEquals = (a: BigDecimal.BigDecimal, b: BigDecimal.BigDecimal) => assert.isTrue(BigDecimal.equals(a, b)) +import { BigDecimal, Equal, FastCheck as fc, Option } from "effect" +import { + assertFalse, + assertNone, + assertSome, + assertTrue, + deepStrictEqual, + equals, + strictEqual, + throws +} from "effect/test/util" +import { describe, it } from "vitest" + +const $ = BigDecimal.unsafeFromString describe("BigDecimal", () => { it("isBigDecimal", () => { - assert.isTrue(BigDecimal.isBigDecimal(_("0"))) - assert.isTrue(BigDecimal.isBigDecimal(_("987"))) - assert.isTrue(BigDecimal.isBigDecimal(_("123.0"))) - assert.isTrue(BigDecimal.isBigDecimal(_("0.123"))) - assert.isTrue(BigDecimal.isBigDecimal(_("123.456"))) - assert.isFalse(BigDecimal.isBigDecimal("1")) - assert.isFalse(BigDecimal.isBigDecimal(true)) + assertTrue(BigDecimal.isBigDecimal($("0"))) + assertTrue(BigDecimal.isBigDecimal($("987"))) + assertTrue(BigDecimal.isBigDecimal($("123.0"))) + assertTrue(BigDecimal.isBigDecimal($("0.123"))) + assertTrue(BigDecimal.isBigDecimal($("123.456"))) + assertFalse(BigDecimal.isBigDecimal("1")) + assertFalse(BigDecimal.isBigDecimal(true)) }) it("sign", () => { - assert.deepStrictEqual(BigDecimal.sign(_("-5")), -1) - assert.deepStrictEqual(BigDecimal.sign(_("0")), 0) - assert.deepStrictEqual(BigDecimal.sign(_("5")), 1) - assert.deepStrictEqual(BigDecimal.sign(_("-123.456")), -1) - assert.deepStrictEqual(BigDecimal.sign(_("456.789")), 1) + deepStrictEqual(BigDecimal.sign($("-5")), -1) + deepStrictEqual(BigDecimal.sign($("0")), 0) + deepStrictEqual(BigDecimal.sign($("5")), 1) + deepStrictEqual(BigDecimal.sign($("-123.456")), -1) + deepStrictEqual(BigDecimal.sign($("456.789")), 1) }) it("equals", () => { - assert.isTrue(BigDecimal.equals(_("1"), _("1"))) - assert.isTrue(BigDecimal.equals(_("0.00012300"), _("0.000123"))) - assert.isTrue(BigDecimal.equals(_("5"), _("5.0"))) - assert.isTrue(BigDecimal.equals(_("123.0000"), _("123.00"))) - assert.isFalse(BigDecimal.equals(_("1"), _("2"))) - assert.isFalse(BigDecimal.equals(_("1"), _("1.1"))) - assert.isFalse(BigDecimal.equals(_("1"), _("0.1"))) + assertTrue(BigDecimal.equals($("1"), $("1"))) + assertTrue(BigDecimal.equals($("0.00012300"), $("0.000123"))) + assertTrue(BigDecimal.equals($("5"), $("5.0"))) + assertTrue(BigDecimal.equals($("123.0000"), $("123.00"))) + assertFalse(BigDecimal.equals($("1"), $("2"))) + assertFalse(BigDecimal.equals($("1"), $("1.1"))) + assertFalse(BigDecimal.equals($("1"), $("0.1"))) }) it("sum", () => { - assertEquals(BigDecimal.sum(_("2"), _("0")), _("2")) - assertEquals(BigDecimal.sum(_("0"), _("2")), _("2")) - assertEquals(BigDecimal.sum(_("0"), _("0")), _("0")) - assertEquals(BigDecimal.sum(_("2"), _("1")), _("3")) - assertEquals(BigDecimal.sum(_("3.00000"), _("50")), _("53")) - assertEquals(BigDecimal.sum(_("1.23"), _("0.0045678")), _("1.2345678")) - assertEquals(BigDecimal.sum(_("123.456"), _("-123.456")), _("0")) + equals(BigDecimal.sum($("2"), $("0")), $("2")) + equals(BigDecimal.sum($("0"), $("2")), $("2")) + equals(BigDecimal.sum($("0"), $("0")), $("0")) + equals(BigDecimal.sum($("2"), $("1")), $("3")) + equals(BigDecimal.sum($("3.00000"), $("50")), $("53")) + equals(BigDecimal.sum($("1.23"), $("0.0045678")), $("1.2345678")) + equals(BigDecimal.sum($("123.456"), $("-123.456")), $("0")) }) it("multiply", () => { - assertEquals(BigDecimal.multiply(_("3"), _("2")), _("6")) - assertEquals(BigDecimal.multiply(_("3"), _("0")), _("0")) - assertEquals(BigDecimal.multiply(_("3"), _("-1")), _("-3")) - assertEquals(BigDecimal.multiply(_("3"), _("0.5")), _("1.5")) - assertEquals(BigDecimal.multiply(_("3"), _("-2.5")), _("-7.5")) + equals(BigDecimal.multiply($("3"), $("2")), $("6")) + equals(BigDecimal.multiply($("3"), $("0")), $("0")) + equals(BigDecimal.multiply($("3"), $("-1")), $("-3")) + equals(BigDecimal.multiply($("3"), $("0.5")), $("1.5")) + equals(BigDecimal.multiply($("3"), $("-2.5")), $("-7.5")) }) it("subtract", () => { - assertEquals(BigDecimal.subtract(_("0"), _("1")), _("-1")) - assertEquals(BigDecimal.subtract(_("2.1"), _("1")), _("1.1")) - assertEquals(BigDecimal.subtract(_("3"), _("1")), _("2")) - assertEquals(BigDecimal.subtract(_("3"), _("0")), _("3")) - assertEquals(BigDecimal.subtract(_("3"), _("-1")), _("4")) - assertEquals(BigDecimal.subtract(_("3"), _("0.5")), _("2.5")) - assertEquals(BigDecimal.subtract(_("3"), _("-2.5")), _("5.5")) + equals(BigDecimal.subtract($("0"), $("1")), $("-1")) + equals(BigDecimal.subtract($("2.1"), $("1")), $("1.1")) + equals(BigDecimal.subtract($("3"), $("1")), $("2")) + equals(BigDecimal.subtract($("3"), $("0")), $("3")) + equals(BigDecimal.subtract($("3"), $("-1")), $("4")) + equals(BigDecimal.subtract($("3"), $("0.5")), $("2.5")) + equals(BigDecimal.subtract($("3"), $("-2.5")), $("5.5")) }) it("roundTerminal", () => { - expect(BigDecimal.roundTerminal(0n)).toStrictEqual(0n) - expect(BigDecimal.roundTerminal(4n)).toStrictEqual(0n) - expect(BigDecimal.roundTerminal(5n)).toStrictEqual(1n) - expect(BigDecimal.roundTerminal(9n)).toStrictEqual(1n) - expect(BigDecimal.roundTerminal(49n)).toStrictEqual(0n) - expect(BigDecimal.roundTerminal(59n)).toStrictEqual(1n) - expect(BigDecimal.roundTerminal(99n)).toStrictEqual(1n) - expect(BigDecimal.roundTerminal(-4n)).toStrictEqual(0n) - expect(BigDecimal.roundTerminal(-5n)).toStrictEqual(1n) - expect(BigDecimal.roundTerminal(-9n)).toStrictEqual(1n) - expect(BigDecimal.roundTerminal(-49n)).toStrictEqual(0n) - expect(BigDecimal.roundTerminal(-59n)).toStrictEqual(1n) - expect(BigDecimal.roundTerminal(-99n)).toStrictEqual(1n) + strictEqual(BigDecimal.roundTerminal(0n), 0n) + strictEqual(BigDecimal.roundTerminal(4n), 0n) + strictEqual(BigDecimal.roundTerminal(5n), 1n) + strictEqual(BigDecimal.roundTerminal(9n), 1n) + strictEqual(BigDecimal.roundTerminal(49n), 0n) + strictEqual(BigDecimal.roundTerminal(59n), 1n) + strictEqual(BigDecimal.roundTerminal(99n), 1n) + strictEqual(BigDecimal.roundTerminal(-4n), 0n) + strictEqual(BigDecimal.roundTerminal(-5n), 1n) + strictEqual(BigDecimal.roundTerminal(-9n), 1n) + strictEqual(BigDecimal.roundTerminal(-49n), 0n) + strictEqual(BigDecimal.roundTerminal(-59n), 1n) + strictEqual(BigDecimal.roundTerminal(-99n), 1n) }) it("divide", () => { @@ -126,234 +132,234 @@ describe("BigDecimal", () => { ] for (const [x, y, z] of cases) { - assertEquals(BigDecimal.divide(_(x), _(y)).pipe(Option.getOrThrow), _(z)) - assertEquals(BigDecimal.unsafeDivide(_(x), _(y)), _(z)) + equals(BigDecimal.divide($(x), $(y)).pipe(Option.getOrThrow), $(z)) + equals(BigDecimal.unsafeDivide($(x), $(y)), $(z)) } - assert.isTrue(Option.isNone(BigDecimal.divide(_("5"), _("0")))) - assert.throws(() => BigDecimal.unsafeDivide(_("5"), _("0")), "Division by zero") + assertTrue(Option.isNone(BigDecimal.divide($("5"), $("0")))) + throws(() => BigDecimal.unsafeDivide($("5"), $("0")), new RangeError("Division by zero")) }) it("Equivalence", () => { - assert.isTrue(BigDecimal.Equivalence(_("1"), _("1"))) - assert.isTrue(BigDecimal.Equivalence(_("0.00012300"), _("0.000123"))) - assert.isTrue(BigDecimal.Equivalence(_("5"), _("5.00"))) - assert.isFalse(BigDecimal.Equivalence(_("1"), _("2"))) - assert.isFalse(BigDecimal.Equivalence(_("1"), _("1.1"))) + assertTrue(BigDecimal.Equivalence($("1"), $("1"))) + assertTrue(BigDecimal.Equivalence($("0.00012300"), $("0.000123"))) + assertTrue(BigDecimal.Equivalence($("5"), $("5.00"))) + assertFalse(BigDecimal.Equivalence($("1"), $("2"))) + assertFalse(BigDecimal.Equivalence($("1"), $("1.1"))) }) it("Order", () => { - assert.deepStrictEqual(BigDecimal.Order(_("1"), _("2")), -1) - assert.deepStrictEqual(BigDecimal.Order(_("2"), _("1")), 1) - assert.deepStrictEqual(BigDecimal.Order(_("2"), _("2")), 0) - assert.deepStrictEqual(BigDecimal.Order(_("1"), _("1.1")), -1) - assert.deepStrictEqual(BigDecimal.Order(_("1.1"), _("1")), 1) - assert.deepStrictEqual(BigDecimal.Order(_("0.00012300"), _("0.000123")), 0) - assert.deepStrictEqual(BigDecimal.Order(_("5"), _("5.000")), 0) - assert.deepStrictEqual(BigDecimal.Order(_("5"), _("0.500")), 1) - assert.deepStrictEqual(BigDecimal.Order(_("5"), _("50.00")), -1) + deepStrictEqual(BigDecimal.Order($("1"), $("2")), -1) + deepStrictEqual(BigDecimal.Order($("2"), $("1")), 1) + deepStrictEqual(BigDecimal.Order($("2"), $("2")), 0) + deepStrictEqual(BigDecimal.Order($("1"), $("1.1")), -1) + deepStrictEqual(BigDecimal.Order($("1.1"), $("1")), 1) + deepStrictEqual(BigDecimal.Order($("0.00012300"), $("0.000123")), 0) + deepStrictEqual(BigDecimal.Order($("5"), $("5.000")), 0) + deepStrictEqual(BigDecimal.Order($("5"), $("0.500")), 1) + deepStrictEqual(BigDecimal.Order($("5"), $("50.00")), -1) }) it("lessThan", () => { - assert.isTrue(BigDecimal.lessThan(_("2"), _("3"))) - assert.isFalse(BigDecimal.lessThan(_("3"), _("3"))) - assert.isFalse(BigDecimal.lessThan(_("4"), _("3"))) + assertTrue(BigDecimal.lessThan($("2"), $("3"))) + assertFalse(BigDecimal.lessThan($("3"), $("3"))) + assertFalse(BigDecimal.lessThan($("4"), $("3"))) }) it("lessThanOrEqualTo", () => { - assert.isTrue(BigDecimal.lessThanOrEqualTo(_("2"), _("3"))) - assert.isTrue(BigDecimal.lessThanOrEqualTo(_("3"), _("3"))) - assert.isFalse(BigDecimal.lessThanOrEqualTo(_("4"), _("3"))) + assertTrue(BigDecimal.lessThanOrEqualTo($("2"), $("3"))) + assertTrue(BigDecimal.lessThanOrEqualTo($("3"), $("3"))) + assertFalse(BigDecimal.lessThanOrEqualTo($("4"), $("3"))) }) it("greaterThan", () => { - assert.isFalse(BigDecimal.greaterThan(_("2"), _("3"))) - assert.isFalse(BigDecimal.greaterThan(_("3"), _("3"))) - assert.isTrue(BigDecimal.greaterThan(_("4"), _("3"))) + assertFalse(BigDecimal.greaterThan($("2"), $("3"))) + assertFalse(BigDecimal.greaterThan($("3"), $("3"))) + assertTrue(BigDecimal.greaterThan($("4"), $("3"))) }) it("greaterThanOrEqualTo", () => { - assert.deepStrictEqual(BigDecimal.greaterThanOrEqualTo(_("2"), _("3")), false) - assert.deepStrictEqual(BigDecimal.greaterThanOrEqualTo(_("3"), _("3")), true) - assert.deepStrictEqual(BigDecimal.greaterThanOrEqualTo(_("4"), _("3")), true) + deepStrictEqual(BigDecimal.greaterThanOrEqualTo($("2"), $("3")), false) + deepStrictEqual(BigDecimal.greaterThanOrEqualTo($("3"), $("3")), true) + deepStrictEqual(BigDecimal.greaterThanOrEqualTo($("4"), $("3")), true) }) it("between", () => { - assert.deepStrictEqual(BigDecimal.between({ minimum: _("0"), maximum: _("5") })(_("3")), true) - assert.deepStrictEqual(BigDecimal.between({ minimum: _("0"), maximum: _("5") })(_("-1")), false) - assert.deepStrictEqual(BigDecimal.between({ minimum: _("0"), maximum: _("5") })(_("6")), false) - assert.deepStrictEqual(BigDecimal.between({ minimum: _("0.02"), maximum: _("5") })(_("0.0123")), false) - assert.deepStrictEqual(BigDecimal.between({ minimum: _("0.02"), maximum: _("5") })(_("0.05")), true) + deepStrictEqual(BigDecimal.between({ minimum: $("0"), maximum: $("5") })($("3")), true) + deepStrictEqual(BigDecimal.between({ minimum: $("0"), maximum: $("5") })($("-1")), false) + deepStrictEqual(BigDecimal.between({ minimum: $("0"), maximum: $("5") })($("6")), false) + deepStrictEqual(BigDecimal.between({ minimum: $("0.02"), maximum: $("5") })($("0.0123")), false) + deepStrictEqual(BigDecimal.between({ minimum: $("0.02"), maximum: $("5") })($("0.05")), true) - assert.deepStrictEqual(BigDecimal.between(_("3"), { minimum: _("0"), maximum: _("5") }), true) + deepStrictEqual(BigDecimal.between($("3"), { minimum: $("0"), maximum: $("5") }), true) }) it("clamp", () => { - assertEquals(BigDecimal.clamp({ minimum: _("0"), maximum: _("5") })(_("3")), _("3")) - assertEquals(BigDecimal.clamp({ minimum: _("0"), maximum: _("5") })(_("-1")), _("0")) - assertEquals(BigDecimal.clamp({ minimum: _("0"), maximum: _("5") })(_("6")), _("5")) - assertEquals(BigDecimal.clamp({ minimum: _("0.02"), maximum: _("5") })(_("0.0123")), _("0.02")) + equals(BigDecimal.clamp({ minimum: $("0"), maximum: $("5") })($("3")), $("3")) + equals(BigDecimal.clamp({ minimum: $("0"), maximum: $("5") })($("-1")), $("0")) + equals(BigDecimal.clamp({ minimum: $("0"), maximum: $("5") })($("6")), $("5")) + equals(BigDecimal.clamp({ minimum: $("0.02"), maximum: $("5") })($("0.0123")), $("0.02")) - assertEquals(BigDecimal.clamp(_("3"), { minimum: _("0"), maximum: _("5") }), _("3")) + equals(BigDecimal.clamp($("3"), { minimum: $("0"), maximum: $("5") }), $("3")) }) it("min", () => { - assertEquals(BigDecimal.min(_("2"), _("3")), _("2")) - assertEquals(BigDecimal.min(_("5"), _("0.1")), _("0.1")) - assertEquals(BigDecimal.min(_("0.005"), _("3")), _("0.005")) - assertEquals(BigDecimal.min(_("123.456"), _("1.2")), _("1.2")) + equals(BigDecimal.min($("2"), $("3")), $("2")) + equals(BigDecimal.min($("5"), $("0.1")), $("0.1")) + equals(BigDecimal.min($("0.005"), $("3")), $("0.005")) + equals(BigDecimal.min($("123.456"), $("1.2")), $("1.2")) }) it("max", () => { - assertEquals(BigDecimal.max(_("2"), _("3")), _("3")) - assertEquals(BigDecimal.max(_("5"), _("0.1")), _("5")) - assertEquals(BigDecimal.max(_("0.005"), _("3")), _("3")) - assertEquals(BigDecimal.max(_("123.456"), _("1.2")), _("123.456")) + equals(BigDecimal.max($("2"), $("3")), $("3")) + equals(BigDecimal.max($("5"), $("0.1")), $("5")) + equals(BigDecimal.max($("0.005"), $("3")), $("3")) + equals(BigDecimal.max($("123.456"), $("1.2")), $("123.456")) }) it("abs", () => { - assertEquals(BigDecimal.abs(_("2")), _("2")) - assertEquals(BigDecimal.abs(_("-3")), _("3")) - assertEquals(BigDecimal.abs(_("0.000456")), _("0.000456")) - assertEquals(BigDecimal.abs(_("-0.123")), _("0.123")) + equals(BigDecimal.abs($("2")), $("2")) + equals(BigDecimal.abs($("-3")), $("3")) + equals(BigDecimal.abs($("0.000456")), $("0.000456")) + equals(BigDecimal.abs($("-0.123")), $("0.123")) }) it("negate", () => { - assertEquals(BigDecimal.negate(_("2")), _("-2")) - assertEquals(BigDecimal.negate(_("-3")), _("3")) - assertEquals(BigDecimal.negate(_("0.000456")), _("-0.000456")) - assertEquals(BigDecimal.negate(_("-0.123")), _("0.123")) + equals(BigDecimal.negate($("2")), $("-2")) + equals(BigDecimal.negate($("-3")), $("3")) + equals(BigDecimal.negate($("0.000456")), $("-0.000456")) + equals(BigDecimal.negate($("-0.123")), $("0.123")) }) it("remainder", () => { - assertEquals(BigDecimal.remainder(_("5"), _("2")).pipe(Option.getOrThrow), _("1")) - assertEquals(BigDecimal.remainder(_("4"), _("2")).pipe(Option.getOrThrow), _("0")) - assertEquals(BigDecimal.remainder(_("123.456"), _("0.2")).pipe(Option.getOrThrow), _("0.056")) - assert.isTrue(Option.isNone(BigDecimal.remainder(_("5"), _("0")))) + equals(BigDecimal.remainder($("5"), $("2")).pipe(Option.getOrThrow), $("1")) + equals(BigDecimal.remainder($("4"), $("2")).pipe(Option.getOrThrow), $("0")) + equals(BigDecimal.remainder($("123.456"), $("0.2")).pipe(Option.getOrThrow), $("0.056")) + assertTrue(Option.isNone(BigDecimal.remainder($("5"), $("0")))) }) it("unsafeRemainder", () => { - assertEquals(BigDecimal.unsafeRemainder(_("5"), _("2")), _("1")) - assertEquals(BigDecimal.unsafeRemainder(_("4"), _("2")), _("0")) - assertEquals(BigDecimal.unsafeRemainder(_("123.456"), _("0.2")), _("0.056")) - assert.throws(() => BigDecimal.unsafeRemainder(_("5"), _("0")), "Division by zero") + equals(BigDecimal.unsafeRemainder($("5"), $("2")), $("1")) + equals(BigDecimal.unsafeRemainder($("4"), $("2")), $("0")) + equals(BigDecimal.unsafeRemainder($("123.456"), $("0.2")), $("0.056")) + throws(() => BigDecimal.unsafeRemainder($("5"), $("0")), new RangeError("Division by zero")) }) it("normalize", () => { - assert.deepStrictEqual(BigDecimal.normalize(_("0")), BigDecimal.unsafeMakeNormalized(0n, 0)) - assert.deepStrictEqual(BigDecimal.normalize(_("0.123000")), BigDecimal.unsafeMakeNormalized(123n, 3)) - assert.deepStrictEqual(BigDecimal.normalize(_("123.000")), BigDecimal.unsafeMakeNormalized(123n, 0)) - assert.deepStrictEqual(BigDecimal.normalize(_("-0.000123000")), BigDecimal.unsafeMakeNormalized(-123n, 6)) - assert.deepStrictEqual(BigDecimal.normalize(_("-123.000")), BigDecimal.unsafeMakeNormalized(-123n, 0)) - assert.deepStrictEqual(BigDecimal.normalize(_("12300000")), BigDecimal.unsafeMakeNormalized(123n, -5)) + deepStrictEqual(BigDecimal.normalize($("0")), BigDecimal.unsafeMakeNormalized(0n, 0)) + deepStrictEqual(BigDecimal.normalize($("0.123000")), BigDecimal.unsafeMakeNormalized(123n, 3)) + deepStrictEqual(BigDecimal.normalize($("123.000")), BigDecimal.unsafeMakeNormalized(123n, 0)) + deepStrictEqual(BigDecimal.normalize($("-0.000123000")), BigDecimal.unsafeMakeNormalized(-123n, 6)) + deepStrictEqual(BigDecimal.normalize($("-123.000")), BigDecimal.unsafeMakeNormalized(-123n, 0)) + deepStrictEqual(BigDecimal.normalize($("12300000")), BigDecimal.unsafeMakeNormalized(123n, -5)) }) it("fromString", () => { - assert.deepStrictEqual(BigDecimal.fromString("2"), Option.some(BigDecimal.make(2n, 0))) - assert.deepStrictEqual(BigDecimal.fromString("-2"), Option.some(BigDecimal.make(-2n, 0))) - assert.deepStrictEqual(BigDecimal.fromString("0.123"), Option.some(BigDecimal.make(123n, 3))) - assert.deepStrictEqual(BigDecimal.fromString("200"), Option.some(BigDecimal.make(200n, 0))) - assert.deepStrictEqual(BigDecimal.fromString("20000000"), Option.some(BigDecimal.make(20000000n, 0))) - assert.deepStrictEqual(BigDecimal.fromString("-20000000"), Option.some(BigDecimal.make(-20000000n, 0))) - assert.deepStrictEqual(BigDecimal.fromString("2.00"), Option.some(BigDecimal.make(200n, 2))) - assert.deepStrictEqual(BigDecimal.fromString("0.0000200"), Option.some(BigDecimal.make(200n, 7))) - assert.deepStrictEqual(BigDecimal.fromString(""), Option.some(BigDecimal.normalize(BigDecimal.make(0n, 0)))) - assert.deepStrictEqual(BigDecimal.fromString("1e5"), Option.some(BigDecimal.make(1n, -5))) - assert.deepStrictEqual(BigDecimal.fromString("1E15"), Option.some(BigDecimal.make(1n, -15))) - assert.deepStrictEqual(BigDecimal.fromString("1e+5"), Option.some(BigDecimal.make(1n, -5))) - assert.deepStrictEqual(BigDecimal.fromString("1E+15"), Option.some(BigDecimal.make(1n, -15))) - assert.deepStrictEqual(BigDecimal.fromString("-1.5E3"), Option.some(BigDecimal.make(-15n, -2))) - assert.deepStrictEqual(BigDecimal.fromString("-1.5e3"), Option.some(BigDecimal.make(-15n, -2))) - assert.deepStrictEqual(BigDecimal.fromString("-.5e3"), Option.some(BigDecimal.make(-5n, -2))) - assert.deepStrictEqual(BigDecimal.fromString("-5e3"), Option.some(BigDecimal.make(-5n, -3))) - assert.deepStrictEqual(BigDecimal.fromString("-5e-3"), Option.some(BigDecimal.make(-5n, 3))) - assert.deepStrictEqual(BigDecimal.fromString("15e-3"), Option.some(BigDecimal.make(15n, 3))) - assert.deepStrictEqual(BigDecimal.fromString("0.00002e5"), Option.some(BigDecimal.make(2n, 0))) - assert.deepStrictEqual(BigDecimal.fromString("0.00002e-5"), Option.some(BigDecimal.make(2n, 10))) - assert.isTrue(Option.isNone(BigDecimal.fromString("0.0000e2e1"))) - assert.isTrue(Option.isNone(BigDecimal.fromString("0.1.2"))) + assertSome(BigDecimal.fromString("2"), BigDecimal.make(2n, 0)) + assertSome(BigDecimal.fromString("-2"), BigDecimal.make(-2n, 0)) + assertSome(BigDecimal.fromString("0.123"), BigDecimal.make(123n, 3)) + assertSome(BigDecimal.fromString("200"), BigDecimal.make(200n, 0)) + assertSome(BigDecimal.fromString("20000000"), BigDecimal.make(20000000n, 0)) + assertSome(BigDecimal.fromString("-20000000"), BigDecimal.make(-20000000n, 0)) + assertSome(BigDecimal.fromString("2.00"), BigDecimal.make(200n, 2)) + assertSome(BigDecimal.fromString("0.0000200"), BigDecimal.make(200n, 7)) + assertSome(BigDecimal.fromString(""), BigDecimal.normalize(BigDecimal.make(0n, 0))) + assertSome(BigDecimal.fromString("1e5"), BigDecimal.make(1n, -5)) + assertSome(BigDecimal.fromString("1E15"), BigDecimal.make(1n, -15)) + assertSome(BigDecimal.fromString("1e+5"), BigDecimal.make(1n, -5)) + assertSome(BigDecimal.fromString("1E+15"), BigDecimal.make(1n, -15)) + assertSome(BigDecimal.fromString("-1.5E3"), BigDecimal.make(-15n, -2)) + assertSome(BigDecimal.fromString("-1.5e3"), BigDecimal.make(-15n, -2)) + assertSome(BigDecimal.fromString("-.5e3"), BigDecimal.make(-5n, -2)) + assertSome(BigDecimal.fromString("-5e3"), BigDecimal.make(-5n, -3)) + assertSome(BigDecimal.fromString("-5e-3"), BigDecimal.make(-5n, 3)) + assertSome(BigDecimal.fromString("15e-3"), BigDecimal.make(15n, 3)) + assertSome(BigDecimal.fromString("0.00002e5"), BigDecimal.make(2n, 0)) + assertSome(BigDecimal.fromString("0.00002e-5"), BigDecimal.make(2n, 10)) + assertNone(BigDecimal.fromString("0.0000e2e1")) + assertNone(BigDecimal.fromString("0.1.2")) }) it("format", () => { - assert.strictEqual(BigDecimal.format(_("2")), "2") - assert.strictEqual(BigDecimal.format(_("-2")), "-2") - assert.strictEqual(BigDecimal.format(_("0.123")), "0.123") - assert.strictEqual(BigDecimal.format(_("200")), "200") - assert.strictEqual(BigDecimal.format(_("20000000")), "20000000") - assert.strictEqual(BigDecimal.format(_("-20000000")), "-20000000") - assert.strictEqual(BigDecimal.format(_("2.00")), "2") - assert.strictEqual(BigDecimal.format(_("0.200")), "0.2") - assert.strictEqual(BigDecimal.format(_("0.123000")), "0.123") - assert.strictEqual(BigDecimal.format(_("-456.123")), "-456.123") - assert.strictEqual(BigDecimal.format(BigDecimal.make(10n, -1)), "100") - assert.strictEqual(BigDecimal.format(BigDecimal.make(1n, -25)), "1e+25") - assert.strictEqual(BigDecimal.format(BigDecimal.make(12345n, -25)), "1.2345e+29") - assert.strictEqual(BigDecimal.format(BigDecimal.make(12345n, 25)), "1.2345e-21") - assert.strictEqual(BigDecimal.format(BigDecimal.make(-12345n, 20)), "-1.2345e-16") + strictEqual(BigDecimal.format($("2")), "2") + strictEqual(BigDecimal.format($("-2")), "-2") + strictEqual(BigDecimal.format($("0.123")), "0.123") + strictEqual(BigDecimal.format($("200")), "200") + strictEqual(BigDecimal.format($("20000000")), "20000000") + strictEqual(BigDecimal.format($("-20000000")), "-20000000") + strictEqual(BigDecimal.format($("2.00")), "2") + strictEqual(BigDecimal.format($("0.200")), "0.2") + strictEqual(BigDecimal.format($("0.123000")), "0.123") + strictEqual(BigDecimal.format($("-456.123")), "-456.123") + strictEqual(BigDecimal.format(BigDecimal.make(10n, -1)), "100") + strictEqual(BigDecimal.format(BigDecimal.make(1n, -25)), "1e+25") + strictEqual(BigDecimal.format(BigDecimal.make(12345n, -25)), "1.2345e+29") + strictEqual(BigDecimal.format(BigDecimal.make(12345n, 25)), "1.2345e-21") + strictEqual(BigDecimal.format(BigDecimal.make(-12345n, 20)), "-1.2345e-16") }) it("toJSON()", () => { - assert.deepStrictEqual(JSON.stringify(_("2")), JSON.stringify({ _id: "BigDecimal", value: "2", scale: 0 })) + deepStrictEqual(JSON.stringify($("2")), JSON.stringify({ _id: "BigDecimal", value: "2", scale: 0 })) }) it("inspect", () => { if (typeof window === "undefined") { // eslint-disable-next-line @typescript-eslint/no-var-requires const { inspect } = require("node:util") - expect(inspect(_("2"))).toEqual(inspect({ _id: "BigDecimal", value: "2", scale: 0 })) + deepStrictEqual(inspect($("2")), inspect({ _id: "BigDecimal", value: "2", scale: 0 })) } }) it("toString()", () => { - assert.strictEqual(String(_("2")), "BigDecimal(2)") + strictEqual(String($("2")), "BigDecimal(2)") }) it("Equal.symbol", () => { - expect(Equal.equals(_("2"), _("2"))).toBe(true) + assertTrue(Equal.equals($("2"), $("2"))) }) it("pipe()", () => { - expect(_("2").pipe(BigDecimal.multiply(_("3")))).toEqual(_("6")) + deepStrictEqual($("2").pipe(BigDecimal.multiply($("3"))), $("6")) }) it("scale", () => { - expect(BigDecimal.scale(_("3.0005"), 3)).toStrictEqual(_("3.000")) + deepStrictEqual(BigDecimal.scale($("3.0005"), 3), $("3.000")) }) it("fromBigInt", () => { - expect(BigDecimal.fromBigInt(1n)).toStrictEqual(BigDecimal.make(1n, 0)) + deepStrictEqual(BigDecimal.fromBigInt(1n), BigDecimal.make(1n, 0)) }) it("fromNumber", () => { - expect(BigDecimal.fromNumber(123)).toStrictEqual(BigDecimal.make(123n, 0)) - expect(BigDecimal.fromNumber(123.456)).toStrictEqual(BigDecimal.make(123456n, 3)) + deepStrictEqual(BigDecimal.fromNumber(123), BigDecimal.make(123n, 0)) + deepStrictEqual(BigDecimal.fromNumber(123.456), BigDecimal.make(123456n, 3)) }) it("unsafeToNumber", () => { - assert.strictEqual(BigDecimal.unsafeToNumber(_("123.456")), 123.456) + strictEqual(BigDecimal.unsafeToNumber($("123.456")), 123.456) }) it("isInteger", () => { - assert.isTrue(BigDecimal.isInteger(_("0"))) - assert.isTrue(BigDecimal.isInteger(_("1"))) - assert.isFalse(BigDecimal.isInteger(_("1.1"))) + assertTrue(BigDecimal.isInteger($("0"))) + assertTrue(BigDecimal.isInteger($("1"))) + assertFalse(BigDecimal.isInteger($("1.1"))) }) it("isZero", () => { - assert.isTrue(BigDecimal.isZero(_("0"))) - assert.isFalse(BigDecimal.isZero(_("1"))) + assertTrue(BigDecimal.isZero($("0"))) + assertFalse(BigDecimal.isZero($("1"))) }) it("isNegative", () => { - assert.isTrue(BigDecimal.isNegative(_("-1"))) - assert.isFalse(BigDecimal.isNegative(_("0"))) - assert.isFalse(BigDecimal.isNegative(_("1"))) + assertTrue(BigDecimal.isNegative($("-1"))) + assertFalse(BigDecimal.isNegative($("0"))) + assertFalse(BigDecimal.isNegative($("1"))) }) it("isPositive", () => { - assert.isFalse(BigDecimal.isPositive(_("-1"))) - assert.isFalse(BigDecimal.isPositive(_("0"))) - assert.isTrue(BigDecimal.isPositive(_("1"))) + assertFalse(BigDecimal.isPositive($("-1"))) + assertFalse(BigDecimal.isPositive($("0"))) + assertTrue(BigDecimal.isPositive($("1"))) }) }) diff --git a/packages/effect/test/BigInt.test.ts b/packages/effect/test/BigInt.test.ts index 7b40e37d2b5..0eee411d1a9 100644 --- a/packages/effect/test/BigInt.test.ts +++ b/packages/effect/test/BigInt.test.ts @@ -1,21 +1,19 @@ -import * as BigInt_ from "effect/BigInt" -import { pipe } from "effect/Function" -import * as Option from "effect/Option" -import { deepStrictEqual } from "effect/test/util" -import { assert, describe, expect, it } from "vitest" +import { BigInt as BigInt_, pipe } from "effect" +import { assertFalse, assertNone, assertSome, assertTrue, deepStrictEqual, strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" describe("BigInt", () => { it("sign", () => { - assert.deepStrictEqual(BigInt_.sign(-5n), -1) - assert.deepStrictEqual(BigInt_.sign(0n), 0) - assert.deepStrictEqual(BigInt_.sign(5n), 1) + strictEqual(BigInt_.sign(-5n), -1) + strictEqual(BigInt_.sign(0n), 0) + strictEqual(BigInt_.sign(5n), 1) }) it("isBigInt", () => { - expect(BigInt_.isBigInt(1n)).toEqual(true) - expect(BigInt_.isBigInt(1)).toEqual(false) - expect(BigInt_.isBigInt("a")).toEqual(false) - expect(BigInt_.isBigInt(true)).toEqual(false) + assertTrue(BigInt_.isBigInt(1n)) + assertFalse(BigInt_.isBigInt(1)) + assertFalse(BigInt_.isBigInt("a")) + assertFalse(BigInt_.isBigInt(true)) }) it("sum", () => { @@ -31,8 +29,8 @@ describe("BigInt", () => { }) it("divide", () => { - deepStrictEqual(pipe(6n, BigInt_.divide(2n)), Option.some(3n)) - deepStrictEqual(pipe(6n, BigInt_.divide(0n)), Option.none()) + assertSome(pipe(6n, BigInt_.divide(2n)), 3n) + assertNone(pipe(6n, BigInt_.divide(0n))) }) it("unsafeDivide", () => { @@ -48,8 +46,8 @@ describe("BigInt", () => { }) it("Equivalence", () => { - expect(BigInt_.Equivalence(1n, 1n)).toBe(true) - expect(BigInt_.Equivalence(1n, 2n)).toBe(false) + assertTrue(BigInt_.Equivalence(1n, 1n)) + assertFalse(BigInt_.Equivalence(1n, 2n)) }) it("Order", () => { @@ -59,126 +57,126 @@ describe("BigInt", () => { }) it("lessThan", () => { - assert.deepStrictEqual(BigInt_.lessThan(2n, 3n), true) - assert.deepStrictEqual(BigInt_.lessThan(3n, 3n), false) - assert.deepStrictEqual(BigInt_.lessThan(4n, 3n), false) + deepStrictEqual(BigInt_.lessThan(2n, 3n), true) + deepStrictEqual(BigInt_.lessThan(3n, 3n), false) + deepStrictEqual(BigInt_.lessThan(4n, 3n), false) }) it("lessThanOrEqualTo", () => { - assert.deepStrictEqual(BigInt_.lessThanOrEqualTo(2n, 3n), true) - assert.deepStrictEqual(BigInt_.lessThanOrEqualTo(3n, 3n), true) - assert.deepStrictEqual(BigInt_.lessThanOrEqualTo(4n, 3n), false) + deepStrictEqual(BigInt_.lessThanOrEqualTo(2n, 3n), true) + deepStrictEqual(BigInt_.lessThanOrEqualTo(3n, 3n), true) + deepStrictEqual(BigInt_.lessThanOrEqualTo(4n, 3n), false) }) it("greaterThan", () => { - assert.deepStrictEqual(BigInt_.greaterThan(2n, 3n), false) - assert.deepStrictEqual(BigInt_.greaterThan(3n, 3n), false) - assert.deepStrictEqual(BigInt_.greaterThan(4n, 3n), true) + deepStrictEqual(BigInt_.greaterThan(2n, 3n), false) + deepStrictEqual(BigInt_.greaterThan(3n, 3n), false) + deepStrictEqual(BigInt_.greaterThan(4n, 3n), true) }) it("greaterThanOrEqualTo", () => { - assert.deepStrictEqual(BigInt_.greaterThanOrEqualTo(2n, 3n), false) - assert.deepStrictEqual(BigInt_.greaterThanOrEqualTo(3n, 3n), true) - assert.deepStrictEqual(BigInt_.greaterThanOrEqualTo(4n, 3n), true) + deepStrictEqual(BigInt_.greaterThanOrEqualTo(2n, 3n), false) + deepStrictEqual(BigInt_.greaterThanOrEqualTo(3n, 3n), true) + deepStrictEqual(BigInt_.greaterThanOrEqualTo(4n, 3n), true) }) it("between", () => { - assert.deepStrictEqual(BigInt_.between({ minimum: 0n, maximum: 5n })(3n), true) - assert.deepStrictEqual(BigInt_.between({ minimum: 0n, maximum: 5n })(-1n), false) - assert.deepStrictEqual(BigInt_.between({ minimum: 0n, maximum: 5n })(6n), false) + deepStrictEqual(BigInt_.between({ minimum: 0n, maximum: 5n })(3n), true) + deepStrictEqual(BigInt_.between({ minimum: 0n, maximum: 5n })(-1n), false) + deepStrictEqual(BigInt_.between({ minimum: 0n, maximum: 5n })(6n), false) - assert.deepStrictEqual(BigInt_.between(3n, { minimum: 0n, maximum: 5n }), true) + deepStrictEqual(BigInt_.between(3n, { minimum: 0n, maximum: 5n }), true) }) it("clamp", () => { - assert.deepStrictEqual(BigInt_.clamp({ minimum: 0n, maximum: 5n })(3n), 3n) - assert.deepStrictEqual(BigInt_.clamp({ minimum: 0n, maximum: 5n })(-1n), 0n) - assert.deepStrictEqual(BigInt_.clamp({ minimum: 0n, maximum: 5n })(6n), 5n) + deepStrictEqual(BigInt_.clamp({ minimum: 0n, maximum: 5n })(3n), 3n) + deepStrictEqual(BigInt_.clamp({ minimum: 0n, maximum: 5n })(-1n), 0n) + deepStrictEqual(BigInt_.clamp({ minimum: 0n, maximum: 5n })(6n), 5n) - assert.deepStrictEqual(BigInt_.clamp(3n, { minimum: 0n, maximum: 5n }), 3n) + deepStrictEqual(BigInt_.clamp(3n, { minimum: 0n, maximum: 5n }), 3n) }) it("min", () => { - assert.deepStrictEqual(BigInt_.min(2n, 3n), 2n) + deepStrictEqual(BigInt_.min(2n, 3n), 2n) }) it("max", () => { - assert.deepStrictEqual(BigInt_.max(2n, 3n), 3n) + deepStrictEqual(BigInt_.max(2n, 3n), 3n) }) it("sumAll", () => { - assert.deepStrictEqual(BigInt_.sumAll([2n, 3n, 4n]), 9n) + deepStrictEqual(BigInt_.sumAll([2n, 3n, 4n]), 9n) }) it("multiplyAll", () => { - assert.deepStrictEqual(BigInt_.multiplyAll([2n, 0n, 4n]), 0n) - assert.deepStrictEqual(BigInt_.multiplyAll([2n, 3n, 4n]), 24n) + deepStrictEqual(BigInt_.multiplyAll([2n, 0n, 4n]), 0n) + deepStrictEqual(BigInt_.multiplyAll([2n, 3n, 4n]), 24n) }) it("abs", () => { - assert.deepStrictEqual(BigInt_.abs(2n), 2n) - assert.deepStrictEqual(BigInt_.abs(-3n), 3n) + deepStrictEqual(BigInt_.abs(2n), 2n) + deepStrictEqual(BigInt_.abs(-3n), 3n) }) it("gcd", () => { - assert.deepStrictEqual(BigInt_.gcd(2n, 4n), 2n) - assert.deepStrictEqual(BigInt_.gcd(3n, 4n), 1n) + deepStrictEqual(BigInt_.gcd(2n, 4n), 2n) + deepStrictEqual(BigInt_.gcd(3n, 4n), 1n) }) it("lcm", () => { - assert.deepStrictEqual(BigInt_.lcm(2n, 4n), 4n) - assert.deepStrictEqual(BigInt_.lcm(3n, 4n), 12n) + deepStrictEqual(BigInt_.lcm(2n, 4n), 4n) + deepStrictEqual(BigInt_.lcm(3n, 4n), 12n) }) it("sqrt", () => { - assert.deepStrictEqual(BigInt_.sqrt(1n), Option.some(1n)) - assert.deepStrictEqual(BigInt_.sqrt(16n), Option.some(4n)) - assert.deepStrictEqual(BigInt_.sqrt(81n), Option.some(9n)) - assert.deepStrictEqual(BigInt_.sqrt(-123n), Option.none()) + assertSome(BigInt_.sqrt(1n), 1n) + assertSome(BigInt_.sqrt(16n), 4n) + assertSome(BigInt_.sqrt(81n), 9n) + assertNone(BigInt_.sqrt(-123n)) }) it("sqrt", () => { - expect(() => BigInt_.unsafeSqrt(-1n)).toThrow(new Error("Cannot take the square root of a negative number")) + throws(() => BigInt_.unsafeSqrt(-1n), new RangeError("Cannot take the square root of a negative number")) }) it("toNumber", () => { - assert.deepStrictEqual(BigInt_.toNumber(BigInt(Number.MAX_SAFE_INTEGER)), Option.some(Number.MAX_SAFE_INTEGER)) - assert.deepStrictEqual(BigInt_.toNumber(BigInt(Number.MAX_SAFE_INTEGER) + BigInt(1)), Option.none()) - assert.deepStrictEqual(BigInt_.toNumber(BigInt(Number.MIN_SAFE_INTEGER)), Option.some(Number.MIN_SAFE_INTEGER)) - assert.deepStrictEqual(BigInt_.toNumber(BigInt(Number.MIN_SAFE_INTEGER) - BigInt(1)), Option.none()) - assert.deepStrictEqual(BigInt_.toNumber(BigInt(0)), Option.some(0)) - assert.deepStrictEqual(BigInt_.toNumber(BigInt(42)), Option.some(42)) - assert.deepStrictEqual(BigInt_.toNumber(BigInt(-42)), Option.some(-42)) + assertSome(BigInt_.toNumber(BigInt(Number.MAX_SAFE_INTEGER)), Number.MAX_SAFE_INTEGER) + assertNone(BigInt_.toNumber(BigInt(Number.MAX_SAFE_INTEGER) + BigInt(1))) + assertSome(BigInt_.toNumber(BigInt(Number.MIN_SAFE_INTEGER)), Number.MIN_SAFE_INTEGER) + assertNone(BigInt_.toNumber(BigInt(Number.MIN_SAFE_INTEGER) - BigInt(1))) + assertSome(BigInt_.toNumber(BigInt(0)), 0) + assertSome(BigInt_.toNumber(BigInt(42)), 42) + assertSome(BigInt_.toNumber(BigInt(-42)), -42) }) it("fromString", () => { - assert.deepStrictEqual(BigInt_.fromString("NaN"), Option.none()) - assert.deepStrictEqual(BigInt_.fromString("Infinity"), Option.none()) - assert.deepStrictEqual(BigInt_.fromString("-Infinity"), Option.none()) - assert.deepStrictEqual(BigInt_.fromString("3.14"), Option.none()) - assert.deepStrictEqual(BigInt_.fromString("-3.14"), Option.none()) - assert.deepStrictEqual(BigInt_.fromString("1e3"), Option.none()) - assert.deepStrictEqual(BigInt_.fromString("1e-3"), Option.none()) - assert.deepStrictEqual(BigInt_.fromString(""), Option.none()) - assert.deepStrictEqual(BigInt_.fromString("a"), Option.none()) - assert.deepStrictEqual(BigInt_.fromString("42"), Option.some(BigInt(42))) - assert.deepStrictEqual(BigInt_.fromString("\n\r\t 42 \n\r\t"), Option.some(BigInt(42))) + assertNone(BigInt_.fromString("NaN")) + assertNone(BigInt_.fromString("Infinity")) + assertNone(BigInt_.fromString("-Infinity")) + assertNone(BigInt_.fromString("3.14")) + assertNone(BigInt_.fromString("-3.14")) + assertNone(BigInt_.fromString("1e3")) + assertNone(BigInt_.fromString("1e-3")) + assertNone(BigInt_.fromString("")) + assertNone(BigInt_.fromString("a")) + assertSome(BigInt_.fromString("42"), BigInt(42)) + assertSome(BigInt_.fromString("\n\r\t 42 \n\r\t"), BigInt(42)) }) it("fromNumber", () => { - assert.deepStrictEqual(BigInt_.fromNumber(Number.MAX_SAFE_INTEGER), Option.some(BigInt(Number.MAX_SAFE_INTEGER))) - assert.deepStrictEqual(BigInt_.fromNumber(Number.MAX_SAFE_INTEGER + 1), Option.none()) - assert.deepStrictEqual(BigInt_.fromNumber(Number.MIN_SAFE_INTEGER), Option.some(BigInt(Number.MIN_SAFE_INTEGER))) - assert.deepStrictEqual(BigInt_.fromNumber(Number.MIN_SAFE_INTEGER - 1), Option.none()) - assert.deepStrictEqual(BigInt_.fromNumber(Infinity), Option.none()) - assert.deepStrictEqual(BigInt_.fromNumber(-Infinity), Option.none()) - assert.deepStrictEqual(BigInt_.fromNumber(NaN), Option.none()) - assert.deepStrictEqual(BigInt_.fromNumber(1e100), Option.none()) - assert.deepStrictEqual(BigInt_.fromNumber(-1e100), Option.none()) - assert.deepStrictEqual(BigInt_.fromNumber(3.14), Option.none()) - assert.deepStrictEqual(BigInt_.fromNumber(-3.14), Option.none()) - assert.deepStrictEqual(BigInt_.fromNumber(0), Option.some(BigInt(0))) - assert.deepStrictEqual(BigInt_.fromNumber(42), Option.some(BigInt(42))) - assert.deepStrictEqual(BigInt_.fromNumber(-42), Option.some(BigInt(-42))) + assertSome(BigInt_.fromNumber(Number.MAX_SAFE_INTEGER), BigInt(Number.MAX_SAFE_INTEGER)) + assertNone(BigInt_.fromNumber(Number.MAX_SAFE_INTEGER + 1)) + assertSome(BigInt_.fromNumber(Number.MIN_SAFE_INTEGER), BigInt(Number.MIN_SAFE_INTEGER)) + assertNone(BigInt_.fromNumber(Number.MIN_SAFE_INTEGER - 1)) + assertNone(BigInt_.fromNumber(Infinity)) + assertNone(BigInt_.fromNumber(-Infinity)) + assertNone(BigInt_.fromNumber(NaN)) + assertNone(BigInt_.fromNumber(1e100)) + assertNone(BigInt_.fromNumber(-1e100)) + assertNone(BigInt_.fromNumber(3.14)) + assertNone(BigInt_.fromNumber(-3.14)) + assertSome(BigInt_.fromNumber(0), BigInt(0)) + assertSome(BigInt_.fromNumber(42), BigInt(42)) + assertSome(BigInt_.fromNumber(-42), BigInt(-42)) }) }) diff --git a/packages/effect/test/Boolean.test.ts b/packages/effect/test/Boolean.test.ts index 36cbe2860bf..933b3e40b4e 100644 --- a/packages/effect/test/Boolean.test.ts +++ b/packages/effect/test/Boolean.test.ts @@ -1,68 +1,67 @@ -import * as Boolean from "effect/Boolean" -import { pipe } from "effect/Function" -import { deepStrictEqual } from "effect/test/util" -import { assert, describe, expect, it } from "vitest" +import { Boolean, pipe } from "effect" +import { assertFalse, assertTrue, deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Boolean", () => { it("isBoolean", () => { - expect(Boolean.isBoolean(true)).toEqual(true) - expect(Boolean.isBoolean(false)).toEqual(true) - expect(Boolean.isBoolean("a")).toEqual(false) - expect(Boolean.isBoolean(1)).toEqual(false) + assertTrue(Boolean.isBoolean(true)) + assertTrue(Boolean.isBoolean(false)) + assertFalse(Boolean.isBoolean("a")) + assertFalse(Boolean.isBoolean(1)) }) it("and", () => { - deepStrictEqual(pipe(true, Boolean.and(true)), true) - deepStrictEqual(pipe(true, Boolean.and(false)), false) - deepStrictEqual(pipe(false, Boolean.and(true)), false) - deepStrictEqual(pipe(false, Boolean.and(false)), false) + assertTrue(pipe(true, Boolean.and(true))) + assertFalse(pipe(true, Boolean.and(false))) + assertFalse(pipe(false, Boolean.and(true))) + assertFalse(pipe(false, Boolean.and(false))) }) it("nand", () => { - deepStrictEqual(pipe(true, Boolean.nand(true)), false) - deepStrictEqual(pipe(true, Boolean.nand(false)), true) - deepStrictEqual(pipe(false, Boolean.nand(true)), true) - deepStrictEqual(pipe(false, Boolean.nand(false)), true) + assertFalse(pipe(true, Boolean.nand(true))) + assertTrue(pipe(true, Boolean.nand(false))) + assertTrue(pipe(false, Boolean.nand(true))) + assertTrue(pipe(false, Boolean.nand(false))) }) it("or", () => { - deepStrictEqual(pipe(true, Boolean.or(true)), true) - deepStrictEqual(pipe(true, Boolean.or(false)), true) - deepStrictEqual(pipe(false, Boolean.or(true)), true) - deepStrictEqual(pipe(false, Boolean.or(false)), false) + assertTrue(pipe(true, Boolean.or(true))) + assertTrue(pipe(true, Boolean.or(false))) + assertTrue(pipe(false, Boolean.or(true))) + assertFalse(pipe(false, Boolean.or(false))) }) it("nor", () => { - deepStrictEqual(pipe(true, Boolean.nor(true)), false) - deepStrictEqual(pipe(true, Boolean.nor(false)), false) - deepStrictEqual(pipe(false, Boolean.nor(true)), false) - deepStrictEqual(pipe(false, Boolean.nor(false)), true) + assertFalse(pipe(true, Boolean.nor(true))) + assertFalse(pipe(true, Boolean.nor(false))) + assertFalse(pipe(false, Boolean.nor(true))) + assertTrue(pipe(false, Boolean.nor(false))) }) it("xor", () => { - deepStrictEqual(pipe(true, Boolean.xor(true)), false) - deepStrictEqual(pipe(true, Boolean.xor(false)), true) - deepStrictEqual(pipe(false, Boolean.xor(true)), true) - deepStrictEqual(pipe(false, Boolean.xor(false)), false) + assertFalse(pipe(true, Boolean.xor(true))) + assertTrue(pipe(true, Boolean.xor(false))) + assertTrue(pipe(false, Boolean.xor(true))) + assertFalse(pipe(false, Boolean.xor(false))) }) it("eqv", () => { - deepStrictEqual(pipe(true, Boolean.eqv(true)), true) - deepStrictEqual(pipe(true, Boolean.eqv(false)), false) - deepStrictEqual(pipe(false, Boolean.eqv(true)), false) - deepStrictEqual(pipe(false, Boolean.eqv(false)), true) + assertTrue(pipe(true, Boolean.eqv(true))) + assertFalse(pipe(true, Boolean.eqv(false))) + assertFalse(pipe(false, Boolean.eqv(true))) + assertTrue(pipe(false, Boolean.eqv(false))) }) it("implies", () => { - deepStrictEqual(pipe(true, Boolean.implies(true)), true) - deepStrictEqual(pipe(true, Boolean.implies(false)), false) - deepStrictEqual(pipe(false, Boolean.implies(true)), true) - deepStrictEqual(pipe(false, Boolean.implies(false)), true) + assertTrue(pipe(true, Boolean.implies(true))) + assertFalse(pipe(true, Boolean.implies(false))) + assertTrue(pipe(false, Boolean.implies(true))) + assertTrue(pipe(false, Boolean.implies(false))) }) it("not", () => { - deepStrictEqual(pipe(true, Boolean.not), false) - deepStrictEqual(pipe(false, Boolean.not), true) + assertFalse(pipe(true, Boolean.not)) + assertTrue(pipe(false, Boolean.not)) }) it("match", () => { @@ -75,10 +74,10 @@ describe("Boolean", () => { }) it("Equivalence", () => { - expect(Boolean.Equivalence(true, true)).toBe(true) - expect(Boolean.Equivalence(false, false)).toBe(true) - expect(Boolean.Equivalence(true, false)).toBe(false) - expect(Boolean.Equivalence(false, true)).toBe(false) + assertTrue(Boolean.Equivalence(true, true)) + assertTrue(Boolean.Equivalence(false, false)) + assertFalse(Boolean.Equivalence(true, false)) + assertFalse(Boolean.Equivalence(false, true)) }) it("Order", () => { @@ -88,12 +87,12 @@ describe("Boolean", () => { }) it("every", () => { - assert.deepStrictEqual(Boolean.every([true, true, true]), true) - assert.deepStrictEqual(Boolean.every([true, false, true]), false) + assertTrue(Boolean.every([true, true, true])) + assertFalse(Boolean.every([true, false, true])) }) it("some", () => { - assert.deepStrictEqual(Boolean.some([true, false, true]), true) - assert.deepStrictEqual(Boolean.some([false, false, false]), false) + assertTrue(Boolean.some([true, false, true])) + assertFalse(Boolean.some([false, false, false])) }) }) diff --git a/packages/effect/test/Brand.test.ts b/packages/effect/test/Brand.test.ts index b9f03a08236..0568e82f6de 100644 --- a/packages/effect/test/Brand.test.ts +++ b/packages/effect/test/Brand.test.ts @@ -1,7 +1,15 @@ -import * as Brand from "effect/Brand" -import * as Either from "effect/Either" -import * as Option from "effect/Option" -import { assert, describe, expect, it } from "vitest" +import { Brand, Option } from "effect" +import { + assertFalse, + assertLeft, + assertNone, + assertRight, + assertSome, + assertTrue, + strictEqual, + throws +} from "effect/test/util" +import { describe, it } from "vitest" declare const IntTypeId: unique symbol type Int = number & Brand.Brand @@ -23,62 +31,52 @@ describe("Brand", () => { it("nominal", () => { type MyNumber = number & Brand.Brand<"MyNumber"> const MyNumber = Brand.nominal() - assert.strictEqual(MyNumber(1), 1) - assert.strictEqual(MyNumber(1.1), 1.1) - assert.isTrue(MyNumber.is(1)) - assert.isTrue(MyNumber.is(1.1)) + strictEqual(MyNumber(1), 1) + strictEqual(MyNumber(1.1), 1.1) + assertTrue(MyNumber.is(1)) + assertTrue(MyNumber.is(1.1)) }) it("refined (predicate overload)", () => { - assert.strictEqual(Int(1), 1) - assert.throws(() => Int(1.1)) - assert.deepStrictEqual(Int.option(1), Option.some(1)) - assert.deepStrictEqual(Int.option(1.1), Option.none()) - assert.deepStrictEqual(Int.either(1), Either.right(1 as Int)) - assert.deepStrictEqual( + strictEqual(Int(1), 1) + throws(() => Int(1.1)) + assertSome(Int.option(1), 1 as Int) + assertNone(Int.option(1.1)) + assertRight(Int.either(1), 1 as Int) + assertLeft( Int.either(1.1), - Either.left(Brand.error("Expected 1.1 to be an integer")) + Brand.error("Expected 1.1 to be an integer") ) - assert.isTrue(Int.is(1)) - assert.isFalse(Int.is(1.1)) - try { - Int(1.1) - assert.fail("expected `Int(1.1)` to throw an error") - } catch (e) { - expect(e).toStrictEqual(Brand.error("Expected 1.1 to be an integer")) - } + assertTrue(Int.is(1)) + assertFalse(Int.is(1.1)) + throws(() => Int(1.1), Brand.error("Expected 1.1 to be an integer")) }) it("refined (Option overload)", () => { const Int = Brand.refined( (n) => Number.isInteger(n) ? Option.none() : Option.some(Brand.error(`Expected ${n} to be an integer`)) ) - try { - Int(1.1) - assert.fail("expected `Int(1.1)` to throw an error") - } catch (e) { - expect(e).toStrictEqual(Brand.error("Expected 1.1 to be an integer")) - } + throws(() => Int(1.1), Brand.error("Expected 1.1 to be an integer")) }) it("composition", () => { - assert.strictEqual(PositiveInt(1), 1) - assert.throws(() => PositiveInt(1.1)) - assert.deepStrictEqual(PositiveInt.option(1), Option.some(1)) - assert.deepStrictEqual(PositiveInt.option(1.1), Option.none()) - assert.deepStrictEqual(PositiveInt.either(1), Either.right(1 as PositiveInt)) - assert.deepStrictEqual( + strictEqual(PositiveInt(1), 1) + throws(() => PositiveInt(1.1)) + assertSome(PositiveInt.option(1), 1 as PositiveInt) + assertNone(PositiveInt.option(1.1)) + assertRight(PositiveInt.either(1), 1 as PositiveInt) + assertLeft( PositiveInt.either(1.1), - Either.left(Brand.error("Expected 1.1 to be an integer")) + Brand.error("Expected 1.1 to be an integer") ) - assert.deepStrictEqual( + assertLeft( PositiveInt.either(-1.1), - Either.left(Brand.errors( + Brand.errors( Brand.error("Expected -1.1 to be an integer"), Brand.error("Expected -1.1 to be positive") - )) + ) ) - assert.isTrue(PositiveInt.is(1)) - assert.isFalse(PositiveInt.is(1.1)) + assertTrue(PositiveInt.is(1)) + assertFalse(PositiveInt.is(1.1)) }) }) diff --git a/packages/effect/test/Cache.test.ts b/packages/effect/test/Cache.test.ts index e859ac74560..45b4781e74a 100644 --- a/packages/effect/test/Cache.test.ts +++ b/packages/effect/test/Cache.test.ts @@ -1,22 +1,22 @@ -import * as Cache from "effect/Cache" -import * as Effect from "effect/Effect" +import { Cache, Effect } from "effect" +import { strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { describe, expect } from "vitest" +import { describe } from "vitest" describe("Cache", () => { it.effect("should not increment cache hits on expired entries", () => - Effect.gen(function*(_) { - const cache = yield* _(Cache.make({ + Effect.gen(function*() { + const cache = yield* Cache.make({ capacity: 100, timeToLive: "1 seconds", lookup: (n: number): Effect.Effect => Effect.succeed(n) - })) - yield* _(cache.get(42)) - yield* _(TestClock.adjust("2 seconds")) - yield* _(cache.get(42)) - const { hits, misses } = yield* _(cache.cacheStats) - expect(hits).toBe(0) - expect(misses).toBe(2) + }) + yield* cache.get(42) + yield* TestClock.adjust("2 seconds") + yield* cache.get(42) + const { hits, misses } = yield* cache.cacheStats + strictEqual(hits, 0) + strictEqual(misses, 2) })) }) diff --git a/packages/effect/test/Cause.test.ts b/packages/effect/test/Cause.test.ts index b0aa26eca70..a5d66fbcff9 100644 --- a/packages/effect/test/Cause.test.ts +++ b/packages/effect/test/Cause.test.ts @@ -1,10 +1,18 @@ -import * as assert from "assert" -import { Array as Arr, Cause, Effect, Either, Equal, FiberId, Hash, Option, Predicate } from "effect" -import * as fc from "effect/FastCheck" +import { Array as Arr, Cause, Effect, Equal, FastCheck as fc, FiberId, Hash, Option, Predicate } from "effect" import { NodeInspectSymbol } from "effect/Inspectable" import * as internal from "effect/internal/cause" +import { + assertFalse, + assertLeft, + assertNone, + assertRight, + assertSome, + assertTrue, + deepStrictEqual, + strictEqual +} from "effect/test/util" import { causes, equalCauses, errorCauseFunctions, errors } from "effect/test/utils/cause" -import { describe, expect, it } from "vitest" +import { describe, it } from "vitest" describe("Cause", () => { const empty = Cause.empty @@ -18,42 +26,38 @@ describe("Cause", () => { it("correctly implements toString() and the NodeInspectSymbol", () => { // Referenced line to be included in the string output const ex = new Cause.InterruptedException("my message") - expect(ex.toString()).include("InterruptedException: my message") + assertTrue(ex.toString().includes("InterruptedException: my message")) // In Node.js environments, ensure the 'inspect' method includes line information if (typeof window === "undefined") { // eslint-disable-next-line @typescript-eslint/no-var-requires const { inspect } = require("node:util") - expect(inspect(ex)).include("Cause.test.ts:20") // <= reference to the line above + assertTrue(inspect(ex).includes("Cause.test.ts:28")) // <= reference to the line above } }) }) describe("UnknownException", () => { it("exposes its `error` property", () => { - const err1 = new Cause.UnknownException("my message") - expect(err1.error).toBe("my message") - const err2 = new Cause.UnknownException(new Error("my error")) - expect(err2.error).toBeInstanceOf(Error) - expect((err2.error as Error).message).toBe("my error") + strictEqual(new Cause.UnknownException("my message").error, "my message") + const { error } = new Cause.UnknownException(new Error("my error")) + assertTrue(Predicate.isError(error)) + strictEqual(error.message, "my error") }) it("exposes its `cause` property", () => { - const err1 = new Cause.UnknownException("my message") - expect(err1.cause).toBe("my message") + strictEqual(new Cause.UnknownException("my message").cause, "my message") const err2 = new Cause.UnknownException(new Error("my error")) - expect(err2.cause).toBeInstanceOf(Error) - expect((err2.cause as Error).message).toBe("my error") + assertTrue(Predicate.isError(err2.cause)) + strictEqual(err2.cause.message, "my error") }) it("uses a default message when none is provided", () => { - const err1 = new Cause.UnknownException("my message") - expect(err1.message).toBe("An unknown error occurred") + strictEqual(new Cause.UnknownException("my message").message, "An unknown error occurred") }) it("accepts a custom override message", () => { - const err1 = new Cause.UnknownException(new Error("my error"), "my message") - expect(err1.message).toBe("my message") + strictEqual(new Cause.UnknownException(new Error("my error"), "my message").message, "my message") }) }) @@ -61,25 +65,24 @@ describe("Cause", () => { class Error1 { readonly _tag = "WithTag" } - expect(internal.prettyErrorMessage(new Error1())).toBe(`{"_tag":"WithTag"}`) + strictEqual(internal.prettyErrorMessage(new Error1()), `{"_tag":"WithTag"}`) class Error2 { readonly _tag = "WithMessage" readonly message = "my message" } - expect(internal.prettyErrorMessage(new Error2())).toBe(`{"_tag":"WithMessage","message":"my message"}`) + strictEqual(internal.prettyErrorMessage(new Error2()), `{"_tag":"WithMessage","message":"my message"}`) class Error3 { readonly _tag = "WithName" readonly name = "my name" } - expect(internal.prettyErrorMessage(new Error3())).toBe( - `{"_tag":"WithName","name":"my name"}` - ) + strictEqual(internal.prettyErrorMessage(new Error3()), `{"_tag":"WithName","name":"my name"}`) class Error4 { readonly _tag = "WithName" readonly name = "my name" readonly message = "my message" } - expect(internal.prettyErrorMessage(new Error4())).toBe( + strictEqual( + internal.prettyErrorMessage(new Error4()), `{"_tag":"WithName","name":"my name","message":"my message"}` ) class Error5 { @@ -88,16 +91,14 @@ describe("Cause", () => { return "Error: my string" } } - expect(internal.prettyErrorMessage(new Error5())).toBe( - `Error: my string` - ) + strictEqual(internal.prettyErrorMessage(new Error5()), `Error: my string`) }) describe("Cause prototype", () => { describe("toJSON / [NodeInspectSymbol]", () => { const expectJSON = (cause: Cause.Cause, expected: unknown) => { - assert.deepStrictEqual(cause.toJSON(), expected) - assert.deepStrictEqual(cause[NodeInspectSymbol](), expected) + deepStrictEqual(cause.toJSON(), expected) + deepStrictEqual(cause[NodeInspectSymbol](), expected) } it("Empty", () => { @@ -207,59 +208,62 @@ describe("Cause", () => { describe("toString", () => { it("Empty", () => { - expect(String(Cause.empty)).toBe(`All fibers interrupted without errors.`) + strictEqual(String(Cause.empty), `All fibers interrupted without errors.`) }) it("Fail", () => { - expect(String(Cause.fail("my failure"))).toBe(`Error: my failure`) - expect(String(Cause.fail(new Error("my failure")))).includes(`Error: my failure`) + strictEqual(String(Cause.fail("my failure")), `Error: my failure`) + assertTrue(String(Cause.fail(new Error("my failure"))).includes(`Error: my failure`)) }) it("Die", () => { - expect(String(Cause.die("die message"))).toBe(`Error: die message`) - expect(String(Cause.die(new Error("die message")))).includes(`Error: die message`) + strictEqual(String(Cause.die("die message")), `Error: die message`) + assertTrue(String(Cause.die(new Error("die message"))).includes(`Error: die message`)) }) it("Interrupt", () => { - expect(String(Cause.interrupt(FiberId.none))).toBe(`All fibers interrupted without errors.`) - expect(String(Cause.interrupt(FiberId.runtime(1, 0)))).toBe(`All fibers interrupted without errors.`) - expect(String(Cause.interrupt(FiberId.composite(FiberId.none, FiberId.runtime(1, 0))))).toBe( + strictEqual(String(Cause.interrupt(FiberId.none)), `All fibers interrupted without errors.`) + strictEqual(String(Cause.interrupt(FiberId.runtime(1, 0))), `All fibers interrupted without errors.`) + strictEqual( + String(Cause.interrupt(FiberId.composite(FiberId.none, FiberId.runtime(1, 0)))), `All fibers interrupted without errors.` ) }) it("Sequential", () => { - expect(String(Cause.sequential(Cause.fail("failure 1"), Cause.fail("failure 2")))).toBe( + strictEqual( + String(Cause.sequential(Cause.fail("failure 1"), Cause.fail("failure 2"))), `Error: failure 1\nError: failure 2` ) const actual = String(Cause.sequential(Cause.fail(new Error("failure 1")), Cause.fail(new Error("failure 2")))) - expect(actual).includes("Error: failure 1") - expect(actual).includes("Error: failure 2") + assertTrue(actual.includes("Error: failure 1")) + assertTrue(actual.includes("Error: failure 2")) }) it("Parallel", () => { - expect(String(Cause.parallel(Cause.fail("failure 1"), Cause.fail("failure 2")))).toBe( + strictEqual( + String(Cause.parallel(Cause.fail("failure 1"), Cause.fail("failure 2"))), `Error: failure 1\nError: failure 2` ) const actual = String( String(Cause.parallel(Cause.fail(new Error("failure 1")), Cause.fail(new Error("failure 2")))) ) - expect(actual).includes("Error: failure 1") - expect(actual).includes("Error: failure 2") + assertTrue(actual.includes("Error: failure 1")) + assertTrue(actual.includes("Error: failure 2")) }) }) describe("Equal.symbol implementation", () => { it("compares causes by value", () => { - assert.ok(Equal.equals(Cause.fail(0), Cause.fail(0))) - assert.ok(Equal.equals(Cause.die(0), Cause.die(0))) - assert.ok(!Equal.equals(Cause.fail(0), Cause.fail(1))) - assert.ok(!Equal.equals(Cause.die(0), Cause.die(1))) + assertTrue(Equal.equals(Cause.fail(0), Cause.fail(0))) + assertTrue(Equal.equals(Cause.die(0), Cause.die(0))) + assertFalse(Equal.equals(Cause.fail(0), Cause.fail(1))) + assertFalse(Equal.equals(Cause.die(0), Cause.die(1))) }) it("is symmetric", () => { fc.assert(fc.property(causes, causes, (causeA, causeB) => { - assert.strictEqual( + strictEqual( Equal.equals(causeA, causeB), Equal.equals(causeB, causeA) ) @@ -268,164 +272,164 @@ describe("Cause", () => { it("generates identical hashes for equal causes", () => { fc.assert(fc.property(equalCauses, ([causeA, causeB]) => { - assert.strictEqual(Hash.hash(causeA), Hash.hash(causeB)) + strictEqual(Hash.hash(causeA), Hash.hash(causeB)) })) }) it("distinguishes different failure types", () => { - expect(Equal.equals(Cause.die(0), Cause.fail(0))).toBe(false) - expect( + assertFalse(Equal.equals(Cause.die(0), Cause.fail(0))) + assertFalse( Equal.equals( Cause.parallel(Cause.fail("fail1"), Cause.die("fail2")), Cause.parallel(Cause.fail("fail2"), Cause.die("fail1")) ) - ).toBe(false) - expect( + ) + assertFalse( Equal.equals( Cause.sequential(Cause.fail("fail1"), Cause.die("fail2")), Cause.parallel(Cause.fail("fail1"), Cause.die("fail2")) ) - ).toBe(false) + ) }) }) }) describe("Guards", () => { it("isCause", () => { - expect(Cause.isCause(empty)).toBe(true) - expect(Cause.isCause(failure)).toBe(true) - expect(Cause.isCause(defect)).toBe(true) - expect(Cause.isCause(interruption)).toBe(true) - expect(Cause.isCause(sequential)).toBe(true) - expect(Cause.isCause(parallel)).toBe(true) - - expect(Cause.isCause({})).toBe(false) + assertTrue(Cause.isCause(empty)) + assertTrue(Cause.isCause(failure)) + assertTrue(Cause.isCause(defect)) + assertTrue(Cause.isCause(interruption)) + assertTrue(Cause.isCause(sequential)) + assertTrue(Cause.isCause(parallel)) + + assertFalse(Cause.isCause({})) }) it("isEmptyType", () => { - expect(Cause.isEmptyType(empty)).toBe(true) - expect(Cause.isEmptyType(failure)).toBe(false) - expect(Cause.isEmptyType(defect)).toBe(false) - expect(Cause.isEmptyType(interruption)).toBe(false) - expect(Cause.isEmptyType(sequential)).toBe(false) - expect(Cause.isEmptyType(parallel)).toBe(false) + assertTrue(Cause.isEmptyType(empty)) + assertFalse(Cause.isEmptyType(failure)) + assertFalse(Cause.isEmptyType(defect)) + assertFalse(Cause.isEmptyType(interruption)) + assertFalse(Cause.isEmptyType(sequential)) + assertFalse(Cause.isEmptyType(parallel)) }) it("isFailType", () => { - expect(Cause.isFailType(empty)).toBe(false) - expect(Cause.isFailType(failure)).toBe(true) - expect(Cause.isFailType(defect)).toBe(false) - expect(Cause.isFailType(interruption)).toBe(false) - expect(Cause.isFailType(sequential)).toBe(false) - expect(Cause.isFailType(parallel)).toBe(false) + assertFalse(Cause.isFailType(empty)) + assertTrue(Cause.isFailType(failure)) + assertFalse(Cause.isFailType(defect)) + assertFalse(Cause.isFailType(interruption)) + assertFalse(Cause.isFailType(sequential)) + assertFalse(Cause.isFailType(parallel)) }) it("isDieType", () => { - expect(Cause.isDieType(empty)).toBe(false) - expect(Cause.isDieType(failure)).toBe(false) - expect(Cause.isDieType(defect)).toBe(true) - expect(Cause.isDieType(interruption)).toBe(false) - expect(Cause.isDieType(sequential)).toBe(false) - expect(Cause.isDieType(parallel)).toBe(false) + assertFalse(Cause.isDieType(empty)) + assertFalse(Cause.isDieType(failure)) + assertTrue(Cause.isDieType(defect)) + assertFalse(Cause.isDieType(interruption)) + assertFalse(Cause.isDieType(sequential)) + assertFalse(Cause.isDieType(parallel)) }) it("isInterruptType", () => { - expect(Cause.isInterruptType(empty)).toBe(false) - expect(Cause.isInterruptType(failure)).toBe(false) - expect(Cause.isInterruptType(defect)).toBe(false) - expect(Cause.isInterruptType(interruption)).toBe(true) - expect(Cause.isInterruptType(sequential)).toBe(false) - expect(Cause.isInterruptType(parallel)).toBe(false) + assertFalse(Cause.isInterruptType(empty)) + assertFalse(Cause.isInterruptType(failure)) + assertFalse(Cause.isInterruptType(defect)) + assertTrue(Cause.isInterruptType(interruption)) + assertFalse(Cause.isInterruptType(sequential)) + assertFalse(Cause.isInterruptType(parallel)) }) it("isSequentialType", () => { - expect(Cause.isSequentialType(empty)).toBe(false) - expect(Cause.isSequentialType(failure)).toBe(false) - expect(Cause.isSequentialType(defect)).toBe(false) - expect(Cause.isSequentialType(interruption)).toBe(false) - expect(Cause.isSequentialType(sequential)).toBe(true) - expect(Cause.isSequentialType(parallel)).toBe(false) + assertFalse(Cause.isSequentialType(empty)) + assertFalse(Cause.isSequentialType(failure)) + assertFalse(Cause.isSequentialType(defect)) + assertFalse(Cause.isSequentialType(interruption)) + assertTrue(Cause.isSequentialType(sequential)) + assertFalse(Cause.isSequentialType(parallel)) }) it("isParallelType", () => { - expect(Cause.isParallelType(empty)).toBe(false) - expect(Cause.isParallelType(failure)).toBe(false) - expect(Cause.isParallelType(defect)).toBe(false) - expect(Cause.isParallelType(interruption)).toBe(false) - expect(Cause.isParallelType(sequential)).toBe(false) - expect(Cause.isParallelType(parallel)).toBe(true) + assertFalse(Cause.isParallelType(empty)) + assertFalse(Cause.isParallelType(failure)) + assertFalse(Cause.isParallelType(defect)) + assertFalse(Cause.isParallelType(interruption)) + assertFalse(Cause.isParallelType(sequential)) + assertTrue(Cause.isParallelType(parallel)) }) }) describe("Getters", () => { it("isEmpty", () => { - expect(Cause.isEmpty(empty)).toBe(true) - expect(Cause.isEmpty(Cause.sequential(empty, empty))).toBe(true) - expect(Cause.isEmpty(Cause.parallel(empty, empty))).toBe(true) - expect(Cause.isEmpty(Cause.parallel(empty, Cause.sequential(empty, empty)))).toBe(true) - expect(Cause.isEmpty(Cause.sequential(empty, Cause.parallel(empty, empty)))).toBe(true) - - expect(Cause.isEmpty(defect)).toBe(false) - expect(Cause.isEmpty(Cause.sequential(empty, failure))).toBe(false) - expect(Cause.isEmpty(Cause.parallel(empty, failure))).toBe(false) - expect(Cause.isEmpty(Cause.parallel(empty, Cause.sequential(empty, failure)))).toBe(false) - expect(Cause.isEmpty(Cause.sequential(empty, Cause.parallel(empty, failure)))).toBe(false) + assertTrue(Cause.isEmpty(empty)) + assertTrue(Cause.isEmpty(Cause.sequential(empty, empty))) + assertTrue(Cause.isEmpty(Cause.parallel(empty, empty))) + assertTrue(Cause.isEmpty(Cause.parallel(empty, Cause.sequential(empty, empty)))) + assertTrue(Cause.isEmpty(Cause.sequential(empty, Cause.parallel(empty, empty)))) + + assertFalse(Cause.isEmpty(defect)) + assertFalse(Cause.isEmpty(Cause.sequential(empty, failure))) + assertFalse(Cause.isEmpty(Cause.parallel(empty, failure))) + assertFalse(Cause.isEmpty(Cause.parallel(empty, Cause.sequential(empty, failure)))) + assertFalse(Cause.isEmpty(Cause.sequential(empty, Cause.parallel(empty, failure)))) }) it("isFailure", () => { - expect(Cause.isFailure(failure)).toBe(true) - expect(Cause.isFailure(Cause.sequential(empty, failure))).toBe(true) - expect(Cause.isFailure(Cause.parallel(empty, failure))).toBe(true) - expect(Cause.isFailure(Cause.parallel(empty, Cause.sequential(empty, failure)))).toBe(true) - expect(Cause.isFailure(Cause.sequential(empty, Cause.parallel(empty, failure)))).toBe(true) + assertTrue(Cause.isFailure(failure)) + assertTrue(Cause.isFailure(Cause.sequential(empty, failure))) + assertTrue(Cause.isFailure(Cause.parallel(empty, failure))) + assertTrue(Cause.isFailure(Cause.parallel(empty, Cause.sequential(empty, failure)))) + assertTrue(Cause.isFailure(Cause.sequential(empty, Cause.parallel(empty, failure)))) - expect(Cause.isFailure(Cause.sequential(empty, Cause.parallel(empty, empty)))).toBe(false) + assertFalse(Cause.isFailure(Cause.sequential(empty, Cause.parallel(empty, empty)))) }) it("isDie", () => { - expect(Cause.isDie(defect)).toBe(true) - expect(Cause.isDie(Cause.sequential(empty, defect))).toBe(true) - expect(Cause.isDie(Cause.parallel(empty, defect))).toBe(true) - expect(Cause.isDie(Cause.parallel(empty, Cause.sequential(empty, defect)))).toBe(true) - expect(Cause.isDie(Cause.sequential(empty, Cause.parallel(empty, defect)))).toBe(true) + assertTrue(Cause.isDie(defect)) + assertTrue(Cause.isDie(Cause.sequential(empty, defect))) + assertTrue(Cause.isDie(Cause.parallel(empty, defect))) + assertTrue(Cause.isDie(Cause.parallel(empty, Cause.sequential(empty, defect)))) + assertTrue(Cause.isDie(Cause.sequential(empty, Cause.parallel(empty, defect)))) - expect(Cause.isDie(Cause.sequential(empty, Cause.parallel(empty, empty)))).toBe(false) + assertFalse(Cause.isDie(Cause.sequential(empty, Cause.parallel(empty, empty)))) }) it("isInterrupted", () => { - expect(Cause.isInterrupted(interruption)).toBe(true) - expect(Cause.isInterrupted(Cause.sequential(empty, interruption))).toBe(true) - expect(Cause.isInterrupted(Cause.parallel(empty, interruption))).toBe(true) - expect(Cause.isInterrupted(Cause.parallel(empty, Cause.sequential(empty, interruption)))).toBe(true) - expect(Cause.isInterrupted(Cause.sequential(empty, Cause.parallel(empty, interruption)))).toBe(true) - - expect(Cause.isInterrupted(Cause.sequential(failure, interruption))).toBe(true) - expect(Cause.isInterrupted(Cause.parallel(failure, interruption))).toBe(true) - expect(Cause.isInterrupted(Cause.parallel(failure, Cause.sequential(empty, interruption)))).toBe(true) - expect(Cause.isInterrupted(Cause.sequential(failure, Cause.parallel(empty, interruption)))).toBe(true) - - expect(Cause.isInterrupted(Cause.sequential(empty, Cause.parallel(empty, empty)))).toBe(false) + assertTrue(Cause.isInterrupted(interruption)) + assertTrue(Cause.isInterrupted(Cause.sequential(empty, interruption))) + assertTrue(Cause.isInterrupted(Cause.parallel(empty, interruption))) + assertTrue(Cause.isInterrupted(Cause.parallel(empty, Cause.sequential(empty, interruption)))) + assertTrue(Cause.isInterrupted(Cause.sequential(empty, Cause.parallel(empty, interruption)))) + + assertTrue(Cause.isInterrupted(Cause.sequential(failure, interruption))) + assertTrue(Cause.isInterrupted(Cause.parallel(failure, interruption))) + assertTrue(Cause.isInterrupted(Cause.parallel(failure, Cause.sequential(empty, interruption)))) + assertTrue(Cause.isInterrupted(Cause.sequential(failure, Cause.parallel(empty, interruption)))) + + assertFalse(Cause.isInterrupted(Cause.sequential(empty, Cause.parallel(empty, empty)))) }) it("isInterruptedOnly", () => { - expect(Cause.isInterruptedOnly(interruption)).toBe(true) - expect(Cause.isInterruptedOnly(Cause.sequential(empty, interruption))).toBe(true) - expect(Cause.isInterruptedOnly(Cause.parallel(empty, interruption))).toBe(true) - expect(Cause.isInterruptedOnly(Cause.parallel(empty, Cause.sequential(empty, interruption)))).toBe(true) - expect(Cause.isInterruptedOnly(Cause.sequential(empty, Cause.parallel(empty, interruption)))).toBe(true) + assertTrue(Cause.isInterruptedOnly(interruption)) + assertTrue(Cause.isInterruptedOnly(Cause.sequential(empty, interruption))) + assertTrue(Cause.isInterruptedOnly(Cause.parallel(empty, interruption))) + assertTrue(Cause.isInterruptedOnly(Cause.parallel(empty, Cause.sequential(empty, interruption)))) + assertTrue(Cause.isInterruptedOnly(Cause.sequential(empty, Cause.parallel(empty, interruption)))) // Cause.empty is considered a valid candidate - expect(Cause.isInterruptedOnly(Cause.sequential(empty, Cause.parallel(empty, empty)))).toBe(true) + assertTrue(Cause.isInterruptedOnly(Cause.sequential(empty, Cause.parallel(empty, empty)))) - expect(Cause.isInterruptedOnly(Cause.sequential(failure, interruption))).toBe(false) - expect(Cause.isInterruptedOnly(Cause.parallel(failure, interruption))).toBe(false) - expect(Cause.isInterruptedOnly(Cause.parallel(failure, Cause.sequential(empty, interruption)))).toBe(false) - expect(Cause.isInterruptedOnly(Cause.sequential(failure, Cause.parallel(empty, interruption)))).toBe(false) + assertFalse(Cause.isInterruptedOnly(Cause.sequential(failure, interruption))) + assertFalse(Cause.isInterruptedOnly(Cause.parallel(failure, interruption))) + assertFalse(Cause.isInterruptedOnly(Cause.parallel(failure, Cause.sequential(empty, interruption)))) + assertFalse(Cause.isInterruptedOnly(Cause.sequential(failure, Cause.parallel(empty, interruption)))) }) describe("failures", () => { it("should return a Chunk of all recoverable errors", () => { const expectFailures = (cause: Cause.Cause, expected: Array) => { - assert.deepStrictEqual([...Cause.failures(cause)], expected) + deepStrictEqual([...Cause.failures(cause)], expected) } expectFailures(empty, []) expectFailures(failure, ["error"]) @@ -440,13 +444,13 @@ describe("Cause", () => { const n = 10_000 const cause = Array.from({ length: n - 1 }, () => Cause.fail("fail")).reduce(Cause.parallel, Cause.fail("fail")) const result = Cause.failures(cause) - assert.strictEqual(Array.from(result).length, n) + strictEqual(Array.from(result).length, n) }) }) it("defects", () => { const expectDefects = (cause: Cause.Cause, expected: Array) => { - assert.deepStrictEqual([...Cause.defects(cause)], expected) + deepStrictEqual([...Cause.defects(cause)], expected) } expectDefects(empty, []) expectDefects(defect, ["defect"]) @@ -459,7 +463,7 @@ describe("Cause", () => { it("interruptors", () => { const expectInterruptors = (cause: Cause.Cause, expected: Array) => { - assert.deepStrictEqual([...Cause.interruptors(cause)], expected) + deepStrictEqual([...Cause.interruptors(cause)], expected) } expectInterruptors(empty, []) expectInterruptors(interruption, [FiberId.runtime(1, 0)]) @@ -473,20 +477,20 @@ describe("Cause", () => { }) it("size", () => { - expect(Cause.size(empty)).toBe(0) - expect(Cause.size(failure)).toBe(1) - expect(Cause.size(defect)).toBe(1) - expect(Cause.size(Cause.parallel(Cause.fail("error1"), Cause.fail("error2")))).toBe(2) - expect(Cause.size(Cause.sequential(Cause.fail("error1"), Cause.fail("error2")))).toBe(2) - expect(Cause.size(Cause.parallel(failure, defect))).toBe(2) - expect(Cause.size(Cause.sequential(failure, defect))).toBe(2) - expect(Cause.size(Cause.sequential(interruption, Cause.parallel(empty, failure)))).toBe(2) - expect(Cause.size(Cause.sequential(interruption, Cause.parallel(defect, failure)))).toBe(3) + strictEqual(Cause.size(empty), 0) + strictEqual(Cause.size(failure), 1) + strictEqual(Cause.size(defect), 1) + strictEqual(Cause.size(Cause.parallel(Cause.fail("error1"), Cause.fail("error2"))), 2) + strictEqual(Cause.size(Cause.sequential(Cause.fail("error1"), Cause.fail("error2"))), 2) + strictEqual(Cause.size(Cause.parallel(failure, defect)), 2) + strictEqual(Cause.size(Cause.sequential(failure, defect)), 2) + strictEqual(Cause.size(Cause.sequential(interruption, Cause.parallel(empty, failure))), 2) + strictEqual(Cause.size(Cause.sequential(interruption, Cause.parallel(defect, failure))), 3) }) it("failureOption", () => { const expectFailureOption = (cause: Cause.Cause, expected: Option.Option) => { - assert.deepStrictEqual(Cause.failureOption(cause), expected) + deepStrictEqual(Cause.failureOption(cause), expected) } expectFailureOption(empty, Option.none()) expectFailureOption(failure, Option.some("error")) @@ -499,10 +503,10 @@ describe("Cause", () => { it("failureOrCause", () => { const expectLeft = (cause: Cause.Cause, expected: E) => { - assert.deepStrictEqual(Cause.failureOrCause(cause), Either.left(expected)) + assertLeft(Cause.failureOrCause(cause), expected) } const expectRight = (cause: Cause.Cause) => { - assert.deepStrictEqual(Cause.failureOrCause(cause), Either.right(cause)) + assertRight(Cause.failureOrCause(cause), cause) } expectLeft(failure, "error") @@ -517,50 +521,48 @@ describe("Cause", () => { }) it("flipCauseOption", () => { - assert.deepStrictEqual(Cause.flipCauseOption(empty), Option.some(empty)) - assert.deepStrictEqual(Cause.flipCauseOption(defect), Option.some(defect)) - assert.deepStrictEqual(Cause.flipCauseOption(interruption), Option.some(interruption)) - assert.deepStrictEqual(Cause.flipCauseOption(Cause.fail(Option.none())), Option.none()) - assert.deepStrictEqual(Cause.flipCauseOption(Cause.fail(Option.some("error"))), Option.some(Cause.fail("error"))) + assertSome(Cause.flipCauseOption(empty), empty) + assertSome(Cause.flipCauseOption(defect), defect) + assertSome(Cause.flipCauseOption(interruption), interruption) + assertNone(Cause.flipCauseOption(Cause.fail(Option.none()))) + assertSome(Cause.flipCauseOption(Cause.fail(Option.some("error"))), Cause.fail("error")) // sequential - assert.deepStrictEqual( + assertSome( Cause.flipCauseOption(Cause.sequential(Cause.fail(Option.some("error1")), Cause.fail(Option.some("error2")))), - Option.some(Cause.sequential(Cause.fail("error1"), Cause.fail("error2"))) + Cause.sequential(Cause.fail("error1"), Cause.fail("error2")) ) - assert.deepStrictEqual( + assertSome( Cause.flipCauseOption(Cause.sequential(Cause.fail(Option.some("error1")), Cause.fail(Option.none()))), - Option.some(Cause.fail("error1")) + Cause.fail("error1") ) - assert.deepStrictEqual( + assertSome( Cause.flipCauseOption(Cause.sequential(Cause.fail(Option.none()), Cause.fail(Option.some("error2")))), - Option.some(Cause.fail("error2")) + Cause.fail("error2") ) - assert.deepStrictEqual( - Cause.flipCauseOption(Cause.sequential(Cause.fail(Option.none()), Cause.fail(Option.none()))), - Option.none() + assertNone( + Cause.flipCauseOption(Cause.sequential(Cause.fail(Option.none()), Cause.fail(Option.none()))) ) // parallel - assert.deepStrictEqual( + assertSome( Cause.flipCauseOption(Cause.parallel(Cause.fail(Option.some("error1")), Cause.fail(Option.some("error2")))), - Option.some(Cause.parallel(Cause.fail("error1"), Cause.fail("error2"))) + Cause.parallel(Cause.fail("error1"), Cause.fail("error2")) ) - assert.deepStrictEqual( + assertSome( Cause.flipCauseOption(Cause.parallel(Cause.fail(Option.some("error1")), Cause.fail(Option.none()))), - Option.some(Cause.fail("error1")) + Cause.fail("error1") ) - assert.deepStrictEqual( + assertSome( Cause.flipCauseOption(Cause.parallel(Cause.fail(Option.none()), Cause.fail(Option.some("error2")))), - Option.some(Cause.fail("error2")) + Cause.fail("error2") ) - assert.deepStrictEqual( - Cause.flipCauseOption(Cause.parallel(Cause.fail(Option.none()), Cause.fail(Option.none()))), - Option.none() + assertNone( + Cause.flipCauseOption(Cause.parallel(Cause.fail(Option.none()), Cause.fail(Option.none()))) ) }) it("dieOption", () => { const expectDieOption = (cause: Cause.Cause, expected: Option.Option) => { - assert.deepStrictEqual(Cause.dieOption(cause), expected) + deepStrictEqual(Cause.dieOption(cause), expected) } expectDieOption(empty, Option.none()) expectDieOption(defect, Option.some("defect")) @@ -573,7 +575,7 @@ describe("Cause", () => { it("interruptOption", () => { const expectInterruptOption = (cause: Cause.Cause, expected: Option.Option) => { - assert.deepStrictEqual(Cause.interruptOption(cause), expected) + deepStrictEqual(Cause.interruptOption(cause), expected) } expectInterruptOption(empty, Option.none()) expectInterruptOption(interruption, Option.some(FiberId.runtime(1, 0))) @@ -587,32 +589,32 @@ describe("Cause", () => { }) it("keepDefects", () => { - assert.deepStrictEqual(Cause.keepDefects(empty), Option.none()) - assert.deepStrictEqual(Cause.keepDefects(failure), Option.none()) - assert.deepStrictEqual(Cause.keepDefects(defect), Option.some(defect)) - assert.deepStrictEqual( + assertNone(Cause.keepDefects(empty)) + assertNone(Cause.keepDefects(failure)) + assertSome(Cause.keepDefects(defect), defect) + assertSome( Cause.keepDefects(Cause.sequential(Cause.die("defect1"), Cause.die("defect2"))), - Option.some(Cause.sequential(Cause.die("defect1"), Cause.die("defect2"))) + Cause.sequential(Cause.die("defect1"), Cause.die("defect2")) ) - assert.deepStrictEqual(Cause.keepDefects(Cause.sequential(empty, empty)), Option.none()) - assert.deepStrictEqual(Cause.keepDefects(Cause.sequential(defect, failure)), Option.some(defect)) - assert.deepStrictEqual(Cause.keepDefects(Cause.parallel(empty, empty)), Option.none()) - assert.deepStrictEqual(Cause.keepDefects(Cause.parallel(defect, failure)), Option.some(defect)) - assert.deepStrictEqual( + assertNone(Cause.keepDefects(Cause.sequential(empty, empty))) + assertSome(Cause.keepDefects(Cause.sequential(defect, failure)), defect) + assertNone(Cause.keepDefects(Cause.parallel(empty, empty))) + assertSome(Cause.keepDefects(Cause.parallel(defect, failure)), defect) + assertSome( Cause.keepDefects(Cause.parallel(Cause.die("defect1"), Cause.die("defect2"))), - Option.some(Cause.parallel(Cause.die("defect1"), Cause.die("defect2"))) + Cause.parallel(Cause.die("defect1"), Cause.die("defect2")) ) - assert.deepStrictEqual( + assertSome( Cause.keepDefects( Cause.sequential(failure, Cause.parallel(Cause.die("defect1"), Cause.die("defect2"))) ), - Option.some(Cause.parallel(Cause.die("defect1"), Cause.die("defect2"))) + Cause.parallel(Cause.die("defect1"), Cause.die("defect2")) ) - assert.deepStrictEqual( + assertSome( Cause.keepDefects( Cause.sequential(Cause.die("defect1"), Cause.parallel(failure, Cause.die("defect2"))) ), - Option.some(Cause.sequential(Cause.die("defect1"), Cause.die("defect2"))) + Cause.sequential(Cause.die("defect1"), Cause.die("defect2")) ) }) @@ -630,7 +632,7 @@ describe("Cause", () => { // TODO: what's the point of this API? it("linearize", () => { const expectLinearize = (cause: Cause.Cause, expected: Array>) => { - assert.deepStrictEqual([...Cause.linearize(cause)], expected) + deepStrictEqual([...Cause.linearize(cause)], expected) } expectLinearize(empty, []) expectLinearize(failure, [failure]) @@ -672,7 +674,7 @@ describe("Cause", () => { it("stripFailures", () => { const expectStripFailures = (cause: Cause.Cause, expected: Cause.Cause) => { - assert.deepStrictEqual(Cause.stripFailures(cause), expected) + deepStrictEqual(Cause.stripFailures(cause), expected) } expectStripFailures(empty, empty) expectStripFailures(failure, empty) @@ -697,31 +699,31 @@ describe("Cause", () => { ? Option.some(defect) : Option.none() ) - assert.deepStrictEqual(stripNumberFormatException(empty), Option.some(empty)) - assert.deepStrictEqual(stripNumberFormatException(failure), Option.some(failure)) - assert.deepStrictEqual(stripNumberFormatException(interruption), Option.some(interruption)) - assert.deepStrictEqual(stripNumberFormatException(cause1), Option.none()) - assert.deepStrictEqual(stripNumberFormatException(Cause.sequential(cause1, cause1)), Option.none()) - assert.deepStrictEqual(stripNumberFormatException(Cause.sequential(cause1, cause2)), Option.some(cause2)) - assert.deepStrictEqual(stripNumberFormatException(Cause.sequential(cause2, cause1)), Option.some(cause2)) - assert.deepStrictEqual( + assertSome(stripNumberFormatException(empty), empty) + assertSome(stripNumberFormatException(failure), failure) + assertSome(stripNumberFormatException(interruption), interruption) + assertNone(stripNumberFormatException(cause1)) + assertNone(stripNumberFormatException(Cause.sequential(cause1, cause1))) + assertSome(stripNumberFormatException(Cause.sequential(cause1, cause2)), cause2) + assertSome(stripNumberFormatException(Cause.sequential(cause2, cause1)), cause2) + assertSome( stripNumberFormatException(Cause.sequential(cause2, cause2)), - Option.some(Cause.sequential(cause2, cause2)) + Cause.sequential(cause2, cause2) ) - assert.deepStrictEqual(stripNumberFormatException(Cause.parallel(cause1, cause1)), Option.none()) - assert.deepStrictEqual(stripNumberFormatException(Cause.parallel(cause1, cause2)), Option.some(cause2)) - assert.deepStrictEqual(stripNumberFormatException(Cause.parallel(cause2, cause1)), Option.some(cause2)) - assert.deepStrictEqual( + assertNone(stripNumberFormatException(Cause.parallel(cause1, cause1))) + assertSome(stripNumberFormatException(Cause.parallel(cause1, cause2)), cause2) + assertSome(stripNumberFormatException(Cause.parallel(cause2, cause1)), cause2) + assertSome( stripNumberFormatException(Cause.parallel(cause2, cause2)), - Option.some(Cause.parallel(cause2, cause2)) + Cause.parallel(cause2, cause2) ) }) }) describe("Mapping", () => { it("as", () => { - const expectAs = (cause: Cause.Cause, expected: Cause.Cause) => { - assert.deepStrictEqual(Cause.as(cause, 2), expected) + const expectAs = (cause: Cause.Cause, expected: Cause.Cause) => { + deepStrictEqual(Cause.as(cause, 2), expected) } expectAs(empty, empty) expectAs(failure, Cause.fail(2)) @@ -732,8 +734,8 @@ describe("Cause", () => { }) it("map", () => { - const expectMap = (cause: Cause.Cause, expected: Cause.Cause) => { - assert.deepStrictEqual(Cause.map(cause, () => 2), expected) + const expectMap = (cause: Cause.Cause, expected: Cause.Cause) => { + deepStrictEqual(Cause.map(cause, () => 2), expected) } expectMap(empty, empty) expectMap(failure, Cause.fail(2)) @@ -750,7 +752,7 @@ describe("Cause", () => { fc.assert(fc.property(causes, (cause) => { const left = cause.pipe(Cause.flatMap(Cause.fail)) const right = cause - assert.ok(Equal.equals(left, right)) + assertTrue(Equal.equals(left, right)) })) }) @@ -758,7 +760,7 @@ describe("Cause", () => { fc.assert(fc.property(errors, errorCauseFunctions, (error, f) => { const left = Cause.fail(error).pipe(Cause.flatMap(f)) const right = f(error) - assert.ok(Equal.equals(left, right)) + assertTrue(Equal.equals(left, right)) })) }) @@ -766,7 +768,7 @@ describe("Cause", () => { fc.assert(fc.property(causes, errorCauseFunctions, errorCauseFunctions, (cause, f, g) => { const left = cause.pipe(Cause.flatMap(f), Cause.flatMap(g)) const right = cause.pipe(Cause.flatMap((error) => f(error).pipe(Cause.flatMap(g)))) - assert.ok(Equal.equals(left, right)) + assertTrue(Equal.equals(left, right)) })) }) }) @@ -774,15 +776,15 @@ describe("Cause", () => { it("andThen returns the second cause if the first one is failing", () => { const err1 = Cause.fail("err1") const err2 = Cause.fail("err2") - assert.deepStrictEqual(err1.pipe(Cause.andThen(() => err2)), err2) - assert.deepStrictEqual(err1.pipe(Cause.andThen(err2)), err2) - assert.deepStrictEqual(Cause.andThen(err1, () => err2), err2) - assert.deepStrictEqual(Cause.andThen(err1, err2), err2) + deepStrictEqual(err1.pipe(Cause.andThen(() => err2)), err2) + deepStrictEqual(err1.pipe(Cause.andThen(err2)), err2) + deepStrictEqual(Cause.andThen(err1, () => err2), err2) + deepStrictEqual(Cause.andThen(err1, err2), err2) }) it("flatten", () => { const expectFlatten = (cause: Cause.Cause>, expected: Cause.Cause) => { - assert.deepStrictEqual(Cause.flatten(cause), expected) + deepStrictEqual(Cause.flatten(cause), expected) } expectFlatten(Cause.fail(empty), empty) expectFlatten(Cause.fail(failure), failure) @@ -796,7 +798,7 @@ describe("Cause", () => { describe("Elements", () => { it("contains", () => { const expectContains = (cause: Cause.Cause, expected: Cause.Cause) => { - assert.ok(Cause.contains(cause, expected)) + assertTrue(Cause.contains(cause, expected)) } expectContains(empty, empty) @@ -813,7 +815,7 @@ describe("Cause", () => { it("find", () => { const expectFind = (cause: Cause.Cause, expected: Option.Option) => { - assert.deepStrictEqual( + deepStrictEqual( Cause.find( cause, (cause) => @@ -835,7 +837,7 @@ describe("Cause", () => { describe("Destructors", () => { it("squash", () => { const expectSquash = (cause: Cause.Cause, expected: unknown) => { - assert.deepStrictEqual(Cause.squash(cause), expected) + deepStrictEqual(Cause.squash(cause), expected) } expectSquash(empty, new Cause.InterruptedException("Interrupted by fibers: ")) @@ -855,7 +857,7 @@ describe("Cause", () => { describe("Filtering", () => { it("filter", () => { const expectFilter = (cause: Cause.Cause, expected: Cause.Cause) => { - assert.deepStrictEqual( + deepStrictEqual( Cause.filter( cause, (cause) => Cause.isFailType(cause) && Predicate.isString(cause.error) && cause.error === "error" @@ -882,7 +884,7 @@ describe("Cause", () => { describe("Matching", () => { it("match", () => { const expectMatch = (cause: Cause.Cause, expected: string) => { - assert.strictEqual( + strictEqual( Cause.match(cause, { onEmpty: "Empty", onFail: () => "Fail", @@ -913,15 +915,15 @@ describe("Cause", () => { describe("Formatting", () => { it("prettyErrors", () => { - assert.deepStrictEqual(Cause.prettyErrors(empty), []) - assert.deepStrictEqual(Cause.prettyErrors(failure), [new internal.PrettyError("error")]) - assert.deepStrictEqual(Cause.prettyErrors(defect), [new internal.PrettyError("defect")]) - assert.deepStrictEqual(Cause.prettyErrors(interruption), []) - assert.deepStrictEqual(Cause.prettyErrors(sequential), [ + deepStrictEqual(Cause.prettyErrors(empty), []) + deepStrictEqual(Cause.prettyErrors(failure), [new internal.PrettyError("error")]) + deepStrictEqual(Cause.prettyErrors(defect), [new internal.PrettyError("defect")]) + deepStrictEqual(Cause.prettyErrors(interruption), []) + deepStrictEqual(Cause.prettyErrors(sequential), [ new internal.PrettyError("error"), new internal.PrettyError("defect") ]) - assert.deepStrictEqual(Cause.prettyErrors(parallel), [ + deepStrictEqual(Cause.prettyErrors(parallel), [ new internal.PrettyError("error"), new internal.PrettyError("defect") ]) @@ -946,8 +948,8 @@ describe("Cause", () => { describe("renderErrorCause: false", () => { const expectPretty = (cause: Cause.Cause, expected: string | undefined) => { - assert.deepStrictEqual(Cause.pretty(cause), expected) - assert.deepStrictEqual(Cause.pretty(cause, { renderErrorCause: false }), expected) + deepStrictEqual(Cause.pretty(cause), expected) + deepStrictEqual(Cause.pretty(cause, { renderErrorCause: false }), expected) } it("handles array-based errors without throwing", () => { @@ -992,11 +994,10 @@ describe("Cause", () => { }) it("Interrupt", () => { - expect(Cause.pretty(Cause.interrupt(FiberId.none))).toBe("All fibers interrupted without errors.") - expect(Cause.pretty(Cause.interrupt(FiberId.runtime(1, 0)))).toBe( - "All fibers interrupted without errors." - ) - expect(Cause.pretty(Cause.interrupt(FiberId.composite(FiberId.none, FiberId.runtime(1, 0))))).toBe( + strictEqual(Cause.pretty(Cause.interrupt(FiberId.none)), "All fibers interrupted without errors.") + strictEqual(Cause.pretty(Cause.interrupt(FiberId.runtime(1, 0))), "All fibers interrupted without errors.") + strictEqual( + Cause.pretty(Cause.interrupt(FiberId.composite(FiberId.none, FiberId.runtime(1, 0)))), "All fibers interrupted without errors." ) }) @@ -1010,7 +1011,7 @@ describe("Cause", () => { ) const cause = exit.cause const pretty = Cause.pretty(cause) - assert.deepStrictEqual(simplifyStackTrace(pretty), [`Error: my message`, "at [myspan]"]) + deepStrictEqual(simplifyStackTrace(pretty), [`Error: my message`, "at [myspan]"]) }) }) }) @@ -1019,21 +1020,21 @@ describe("Cause", () => { describe("Fail", () => { it("no cause", () => { const pretty = Cause.pretty(Cause.fail(new Error("my message")), { renderErrorCause: true }) - assert.deepStrictEqual(simplifyStackTrace(pretty), ["Error: my message"]) + deepStrictEqual(simplifyStackTrace(pretty), ["Error: my message"]) }) it("string cause", () => { const pretty = Cause.pretty(Cause.fail(new Error("my message", { cause: "my cause" })), { renderErrorCause: true }) - assert.deepStrictEqual(simplifyStackTrace(pretty), ["Error: my message", "[cause]: Error: my cause"]) + deepStrictEqual(simplifyStackTrace(pretty), ["Error: my message", "[cause]: Error: my cause"]) }) it("error cause", () => { const pretty = Cause.pretty(Cause.fail(new Error("my message", { cause: new Error("my cause") })), { renderErrorCause: true }) - assert.deepStrictEqual(simplifyStackTrace(pretty), ["Error: my message", "[cause]: Error: my cause"]) + deepStrictEqual(simplifyStackTrace(pretty), ["Error: my message", "[cause]: Error: my cause"]) }) it("error cause with nested cause", () => { @@ -1043,7 +1044,7 @@ describe("Cause", () => { renderErrorCause: true } ) - assert.deepStrictEqual(simplifyStackTrace(pretty), [ + deepStrictEqual(simplifyStackTrace(pretty), [ "Error: my message", "[cause]: Error: my cause", "[cause]: Error: nested cause" @@ -1060,7 +1061,7 @@ describe("Cause", () => { ) const cause = exit.cause const pretty = Cause.pretty(cause, { renderErrorCause: true }) - assert.deepStrictEqual(simplifyStackTrace(pretty), [ + deepStrictEqual(simplifyStackTrace(pretty), [ `Error: my message`, "at [myspan]", "[cause]: Error: my cause" diff --git a/packages/effect/test/Channel/constructors.test.ts b/packages/effect/test/Channel/constructors.test.ts index e2b00774dea..bfddeb20536 100644 --- a/packages/effect/test/Channel/constructors.test.ts +++ b/packages/effect/test/Channel/constructors.test.ts @@ -2,20 +2,21 @@ import * as Channel from "effect/Channel" import * as Chunk from "effect/Chunk" import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Channel", () => { it.effect("succeed", () => Effect.gen(function*($) { const [chunk, value] = yield* $(Channel.runCollect(Channel.succeed(1))) - assert.isTrue(Chunk.isEmpty(chunk)) - assert.strictEqual(value, 1) + assertTrue(Chunk.isEmpty(chunk)) + strictEqual(value, 1) })) it.effect("fail", () => Effect.gen(function*($) { const result = yield* $(Effect.exit(Channel.runCollect(Channel.fail("uh oh")))) - assert.deepStrictEqual(result, Exit.fail("uh oh")) + deepStrictEqual(result, Exit.fail("uh oh")) })) }) diff --git a/packages/effect/test/Channel/environment.test.ts b/packages/effect/test/Channel/environment.test.ts index e3de0fda2e7..0fb34136ddb 100644 --- a/packages/effect/test/Channel/environment.test.ts +++ b/packages/effect/test/Channel/environment.test.ts @@ -4,8 +4,9 @@ import * as Effect from "effect/Effect" import * as Equal from "effect/Equal" import { pipe } from "effect/Function" import * as Hash from "effect/Hash" +import { deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" const NumberServiceSymbolKey = "effect/test/NumberService" @@ -49,7 +50,7 @@ describe("Channel", () => { Channel.provideService(NumberService, new NumberServiceImpl(100)), Channel.run ) - assert.deepStrictEqual(result, new NumberServiceImpl(100)) + deepStrictEqual(result, new NumberServiceImpl(100)) })) it.effect("provide -> zip -> provide", () => @@ -65,7 +66,7 @@ describe("Channel", () => { ), Channel.run ) - assert.deepStrictEqual(result, [new NumberServiceImpl(100), new NumberServiceImpl(200)]) + deepStrictEqual(result, [new NumberServiceImpl(100), new NumberServiceImpl(200)]) })) it.effect("concatMap(provide).provide", () => @@ -85,8 +86,8 @@ describe("Channel", () => { Channel.provideService(NumberService, new NumberServiceImpl(100)), Channel.runCollect ) - assert.deepStrictEqual(Array.from(chunk), [[new NumberServiceImpl(100), new NumberServiceImpl(200)] as const]) - assert.isUndefined(value) + deepStrictEqual(Array.from(chunk), [[new NumberServiceImpl(100), new NumberServiceImpl(200)] as const]) + strictEqual(value, undefined) })) it.effect("provide is modular", () => @@ -105,8 +106,8 @@ describe("Channel", () => { Channel.runDrain, Effect.provideService(NumberService, new NumberServiceImpl(4)) ) - assert.deepStrictEqual(result1, new NumberServiceImpl(4)) - assert.deepStrictEqual(result2, new NumberServiceImpl(2)) - assert.deepStrictEqual(result3, new NumberServiceImpl(4)) + deepStrictEqual(result1, new NumberServiceImpl(4)) + deepStrictEqual(result2, new NumberServiceImpl(2)) + deepStrictEqual(result3, new NumberServiceImpl(4)) })) }) diff --git a/packages/effect/test/Channel/error-handling.test.ts b/packages/effect/test/Channel/error-handling.test.ts index c2cea2fb1b7..5457ed3d414 100644 --- a/packages/effect/test/Channel/error-handling.test.ts +++ b/packages/effect/test/Channel/error-handling.test.ts @@ -4,8 +4,9 @@ import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" import { pipe } from "effect/Function" import * as Ref from "effect/Ref" +import { assertTrue, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Channel", () => { it.effect("catchAll - structure confusion", () => @@ -21,7 +22,7 @@ describe("Channel", () => { Channel.concatMap(() => Channel.fail("error2")) ) const result = yield* $(Effect.exit(Channel.runCollect(channel))) - assert.deepStrictEqual(result, Exit.fail("error2")) + deepStrictEqual(result, Exit.fail("error2")) })) it.effect("error cause is propagated on channel interruption", () => @@ -43,13 +44,13 @@ describe("Channel", () => { ) yield* $(Deferred.await(finished)) // Note: interruption in race is now done in the background const result = yield* $(Ref.get(ref)) - assert.isTrue(Exit.isInterrupted(result)) + assertTrue(Exit.isInterrupted(result)) })) it.effect("scoped failures", () => Effect.gen(function*($) { const channel = Channel.scoped(Effect.fail("error")) const result = yield* $(Channel.runCollect(channel), Effect.exit) - assert.deepStrictEqual(result, Exit.fail("error")) + deepStrictEqual(result, Exit.fail("error")) })) }) diff --git a/packages/effect/test/Channel/finalization.test.ts b/packages/effect/test/Channel/finalization.test.ts index 4f3fc0da9a0..355e32eff87 100644 --- a/packages/effect/test/Channel/finalization.test.ts +++ b/packages/effect/test/Channel/finalization.test.ts @@ -3,8 +3,9 @@ import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" import { pipe } from "effect/Function" import * as Ref from "effect/Ref" +import { assertTrue, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" interface First { readonly _tag: "First" @@ -37,7 +38,7 @@ describe("Channel", () => { ) ) const result = yield* $(Channel.runDrain(channel), Effect.zipRight(Ref.get(ref))) - assert.deepStrictEqual(result, [ + deepStrictEqual(result, [ "Acquire1", "Release11", "Release12", @@ -70,13 +71,13 @@ describe("Channel", () => { Effect.scoped, Effect.zip(Ref.get(ref)) ) - assert.deepStrictEqual(eventsInScope, [ + deepStrictEqual(eventsInScope, [ "Acquire1", "Release11", "Release12", "Acquire2" ]) - assert.deepStrictEqual(eventsOutsideScope, [ + deepStrictEqual(eventsOutsideScope, [ "Acquire1", "Release11", "Release12", @@ -112,7 +113,7 @@ describe("Channel", () => { Channel.runCollect(channel), Effect.zip(Ref.get(ref)) ) - assert.deepStrictEqual(events, [ + deepStrictEqual(events, [ "Second write", "First write", "Second write", @@ -123,7 +124,7 @@ describe("Channel", () => { "First concatMap", "Second concatMap" ]) - assert.deepStrictEqual(Array.from(elements), [ + deepStrictEqual(Array.from(elements), [ Second(First(1)), Second(First(2)), Second(First(3)) @@ -146,7 +147,7 @@ describe("Channel", () => { ) yield* $(Channel.runDrain(channel)) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [ + deepStrictEqual(Array.from(result), [ "pulled 1", "close 1", "pulled 2", @@ -163,6 +164,6 @@ describe("Channel", () => { Channel.runDrain, Effect.exit ) - assert.isTrue(Exit.isFailure(result)) + assertTrue(Exit.isFailure(result)) })) }) diff --git a/packages/effect/test/Channel/foreign.test.ts b/packages/effect/test/Channel/foreign.test.ts index 6f85e385b30..fc153aa6726 100644 --- a/packages/effect/test/Channel/foreign.test.ts +++ b/packages/effect/test/Channel/foreign.test.ts @@ -5,16 +5,17 @@ import * as Either from "effect/Either" import * as Exit from "effect/Exit" import * as Option from "effect/Option" import * as Random from "effect/Random" +import { strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import { unify } from "effect/Unify" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Channel.Foreign", () => { it.effect("Tag", () => Effect.gen(function*($) { const tag = Context.GenericTag("number") const result = yield* $(tag, Channel.run, Effect.provideService(tag, 10)) - assert.deepEqual(result, 10) + strictEqual(result, 10) })) it.effect("Unify", () => @@ -23,9 +24,9 @@ describe("Channel.Foreign", () => { const unifiedExit = unify((yield* $(Random.nextInt)) > 1 ? Exit.succeed(0) : Exit.fail(1)) const unifiedEither = unify((yield* $(Random.nextInt)) > 1 ? Either.right(0) : Either.left(1)) const unifiedOption = unify((yield* $(Random.nextInt)) > 1 ? Option.some(0) : Option.none()) - assert.deepEqual(yield* $(Channel.run(unifiedEffect)), 0) - assert.deepEqual(yield* $(Channel.run(unifiedExit)), 0) - assert.deepEqual(yield* $(Channel.run(unifiedEither)), 0) - assert.deepEqual(yield* $(Channel.run(unifiedOption)), 0) + strictEqual(yield* $(Channel.run(unifiedEffect)), 0) + strictEqual(yield* $(Channel.run(unifiedExit)), 0) + strictEqual(yield* $(Channel.run(unifiedEither)), 0) + strictEqual(yield* $(Channel.run(unifiedOption)), 0) })) }) diff --git a/packages/effect/test/Channel/interruption.test.ts b/packages/effect/test/Channel/interruption.test.ts index 78057fc2021..de46217ff9d 100644 --- a/packages/effect/test/Channel/interruption.test.ts +++ b/packages/effect/test/Channel/interruption.test.ts @@ -1,12 +1,12 @@ import * as Channel from "effect/Channel" import * as Deferred from "effect/Deferred" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import * as Fiber from "effect/Fiber" import { pipe } from "effect/Function" import * as Ref from "effect/Ref" +import { assertLeft, assertTrue, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Channel", () => { it.effect("interruptWhen - interrupts the current element", () => @@ -29,7 +29,7 @@ describe("Channel", () => { ) yield* $(Fiber.await(fiber)) const result = yield* $(Ref.get(interrupted)) - assert.isTrue(result) + assertTrue(result) })) it.effect("interruptWhen - propagates errors", () => @@ -41,7 +41,7 @@ describe("Channel", () => { ) yield* $(Deferred.fail(deferred, "fail")) const result = yield* $(Effect.either(Channel.runDrain(channel))) - assert.deepStrictEqual(result, Either.left("fail")) + assertLeft(result, "fail") })) it.effect("interruptWhenDeferred - interrupts the current element", () => @@ -64,7 +64,7 @@ describe("Channel", () => { ) yield* $(Fiber.await(fiber)) const result = yield* $(Ref.get(interrupted)) - assert.isTrue(result) + assertTrue(result) })) it.effect("interruptWhenDeferred - propagates errors", () => @@ -76,12 +76,12 @@ describe("Channel", () => { ) yield* $(Deferred.fail(deferred, "fail")) const result = yield* $(Effect.either(Channel.runDrain(channel))) - assert.deepStrictEqual(result, Either.left("fail")) + assertLeft(result, "fail") })) it.effect("runScoped - in uninterruptible region", () => Effect.gen(function*(_) { const result = yield* _(Effect.uninterruptible(Channel.run(Channel.void))) - assert.isUndefined(result) + strictEqual(result, undefined) })) }) diff --git a/packages/effect/test/Channel/mapping.test.ts b/packages/effect/test/Channel/mapping.test.ts index c6b55877221..d6c971ff288 100644 --- a/packages/effect/test/Channel/mapping.test.ts +++ b/packages/effect/test/Channel/mapping.test.ts @@ -7,10 +7,11 @@ import * as Exit from "effect/Exit" import { constVoid, pipe } from "effect/Function" import * as Option from "effect/Option" import * as Ref from "effect/Ref" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as UpstreamPullRequest from "effect/UpstreamPullRequest" import * as UpstreamPullStrategy from "effect/UpstreamPullStrategy" -import { assert, describe } from "vitest" +import { describe } from "vitest" interface First { readonly _tag: "First" @@ -34,8 +35,8 @@ describe("Channel", () => { Channel.map((n) => n + 1), Channel.runCollect ) - assert.isTrue(Chunk.isEmpty(chunk)) - assert.strictEqual(value, 2) + assertTrue(Chunk.isEmpty(chunk)) + strictEqual(value, 2) })) it.effect("mapError - structure confusion", () => @@ -46,7 +47,7 @@ describe("Channel", () => { Channel.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(1)) + deepStrictEqual(result, Exit.fail(1)) })) it.effect("mapOut - simple", () => @@ -56,8 +57,8 @@ describe("Channel", () => { Channel.mapOut((n) => n + 1), Channel.runCollect ) - assert.deepStrictEqual(Chunk.toReadonlyArray(chunk), [2, 3, 4]) - assert.isUndefined(value) + deepStrictEqual(Chunk.toReadonlyArray(chunk), [2, 3, 4]) + strictEqual(value, undefined) })) it.effect("mapOut - mixed with flatMap", () => @@ -68,8 +69,8 @@ describe("Channel", () => { Channel.flatMap(() => Channel.write("x")), Channel.runCollect ) - assert.deepStrictEqual(Chunk.toReadonlyArray(chunk), ["1", "x"]) - assert.isUndefined(value) + deepStrictEqual(Chunk.toReadonlyArray(chunk), ["1", "x"]) + strictEqual(value, undefined) })) it.effect("concatMap - plain", () => @@ -79,7 +80,7 @@ describe("Channel", () => { Channel.concatMap((i) => Channel.writeAll(i, i)), Channel.runCollect ) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [1, 1, 2, 2, 3, 3]) + deepStrictEqual(Chunk.toReadonlyArray(result), [1, 1, 2, 2, 3, 3]) })) it.effect("concatMap - complex", () => @@ -92,7 +93,7 @@ describe("Channel", () => { Channel.mapOut(Second), Channel.runCollect ) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [ + deepStrictEqual(Chunk.toReadonlyArray(result), [ Second(First(1)), Second(First(1)), Second(First(1)), @@ -120,7 +121,7 @@ describe("Channel", () => { Channel.pipeTo(readers), Channel.runCollect ) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [1, 2, 3, 4]) + deepStrictEqual(Chunk.toReadonlyArray(result), [1, 2, 3, 4]) })) it.effect("concatMap - downstream failure", () => @@ -131,7 +132,7 @@ describe("Channel", () => { Channel.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail("error")) + deepStrictEqual(result, Exit.fail("error")) })) it.effect("concatMap - upstream acquireReleaseOut + downstream failure", () => @@ -145,8 +146,8 @@ describe("Channel", () => { Effect.exit ) const [exit, events] = yield* $(effect, Effect.zip(Ref.get(ref))) - assert.deepStrictEqual(exit, Exit.fail("error")) - assert.deepStrictEqual(events, ["Acquired", "Released"]) + deepStrictEqual(exit, Exit.fail("error")) + deepStrictEqual(events, ["Acquired", "Released"]) })) it.effect("concatMap - multiple concatMaps with failure in first", () => @@ -158,7 +159,7 @@ describe("Channel", () => { Channel.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail("error")) + deepStrictEqual(result, Exit.fail("error")) })) it.effect("concatMap - with failure then flatMap", () => @@ -170,7 +171,7 @@ describe("Channel", () => { Channel.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail("error")) + deepStrictEqual(result, Exit.fail("error")) })) it.effect("concatMap - multiple concatMaps with failure in first and catchAll in second", () => @@ -182,7 +183,7 @@ describe("Channel", () => { Channel.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail("error2")) + deepStrictEqual(result, Exit.fail("error2")) })) it.effect("concatMap - done value combination", () => @@ -197,9 +198,9 @@ describe("Channel", () => { ), Channel.runCollect ) - assert.deepStrictEqual(Chunk.toReadonlyArray(chunk), [1, 2, 3]) - assert.deepStrictEqual(array1, ["Inner-1", "Inner-2", "Inner-3"]) - assert.deepStrictEqual(array2, ["Outer-0"]) + deepStrictEqual(Chunk.toReadonlyArray(chunk), [1, 2, 3]) + deepStrictEqual(array1, ["Inner-1", "Inner-2", "Inner-3"]) + deepStrictEqual(array2, ["Outer-0"]) })) it.effect("concatMap - custom 1", () => @@ -231,7 +232,7 @@ describe("Channel", () => { Channel.runCollect, Effect.map(([chunk]) => pipe(Chunk.toReadonlyArray(chunk), Array.getSomes)) ) - assert.deepStrictEqual(result, [ + deepStrictEqual(result, [ [1, 1] as const, [2, 1] as const, [3, 1] as const, @@ -277,7 +278,7 @@ describe("Channel", () => { Channel.runCollect, Effect.map(([chunk]) => pipe(Chunk.toReadonlyArray(chunk), Array.getSomes)) ) - assert.deepStrictEqual(result, [ + deepStrictEqual(result, [ [1, 1] as const, [2, 1] as const, [1, 2] as const, diff --git a/packages/effect/test/Channel/merging.test.ts b/packages/effect/test/Channel/merging.test.ts index da17dbf6122..de75937e2aa 100644 --- a/packages/effect/test/Channel/merging.test.ts +++ b/packages/effect/test/Channel/merging.test.ts @@ -6,8 +6,9 @@ import * as Exit from "effect/Exit" import { constTrue, pipe } from "effect/Function" import * as MergeDecision from "effect/MergeDecision" import * as Ref from "effect/Ref" +import { deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Channel", () => { it.effect("mergeWith - simple merge", () => @@ -22,8 +23,8 @@ describe("Channel", () => { }), Channel.runCollect ) - assert.deepStrictEqual(Array.from(chunk), [1, 2, 3, 4, 5, 6]) - assert.isUndefined(value) + deepStrictEqual(Array.from(chunk), [1, 2, 3, 4, 5, 6]) + strictEqual(value, undefined) })) it.effect("mergeWith - merge with different types", () => @@ -68,8 +69,8 @@ describe("Channel", () => { }), Channel.runCollect ) - assert.deepStrictEqual(Array.from(chunk), [1, 2]) - assert.deepStrictEqual(value, ["whatever", true]) + deepStrictEqual(Array.from(chunk), [1, 2]) + deepStrictEqual(value, ["whatever", true]) })) it.effect("mergeWith - handles polymorphic failures", () => @@ -112,7 +113,7 @@ describe("Channel", () => { Channel.runDrain, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail<[string, boolean]>(["boom", true])) + deepStrictEqual(result, Exit.fail<[string, boolean]>(["boom", true])) })) it.effect("mergeWith - interrupts losing side", () => @@ -143,6 +144,6 @@ describe("Channel", () => { )) }) const result = yield* $(Effect.exit(Channel.runDrain(merged))) - assert.deepStrictEqual(result, Exit.succeed(void 0)) + deepStrictEqual(result, Exit.succeed(void 0)) })) }) diff --git a/packages/effect/test/Channel/reading.test.ts b/packages/effect/test/Channel/reading.test.ts index 30cd414bc63..a30a752da36 100644 --- a/packages/effect/test/Channel/reading.test.ts +++ b/packages/effect/test/Channel/reading.test.ts @@ -10,8 +10,9 @@ import * as MergeDecision from "effect/MergeDecision" import * as Option from "effect/Option" import * as Random from "effect/Random" import * as Ref from "effect/Ref" +import { deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" export const mapper = ( f: (a: A) => B @@ -91,13 +92,13 @@ describe("Channel", () => { ) const result = yield* $(Channel.runCollect(channel)) const [chunk, value] = result - assert.deepStrictEqual(Chunk.toReadonlyArray(chunk), [ + deepStrictEqual(Chunk.toReadonlyArray(chunk), [ new Whatever(1), new Whatever(2), new Whatever(3), new Whatever(4) ]) - assert.isUndefined(value) + strictEqual(value, undefined) })) it.effect("read pipelining", () => @@ -131,8 +132,8 @@ describe("Channel", () => { Channel.pipeTo(innerChannel) ) const [chunk, list] = yield* $(Channel.runCollect(channel)) - assert.deepStrictEqual(Chunk.toReadonlyArray(chunk), [1, 1, 2, 2]) - assert.deepStrictEqual(list, [1, 1, 2, 2]) + deepStrictEqual(Chunk.toReadonlyArray(chunk), [1, 1, 2, 2]) + deepStrictEqual(list, [1, 1, 2, 2]) })) it.effect("read pipelining 2", () => @@ -178,7 +179,7 @@ describe("Channel", () => { ) ) const result = yield* $(Channel.run(channel), Effect.zipRight(Ref.get(ref))) - assert.deepStrictEqual(result, [3, 7]) + deepStrictEqual(result, [3, 7]) })) it.effect("reading with resources", () => @@ -215,7 +216,7 @@ describe("Channel", () => { ) const channel = pipe(left, Channel.pipeTo(right)) const result = yield* $(Channel.runDrain(channel), Effect.zipRight(Ref.get(ref))) - assert.deepStrictEqual(result, [ + deepStrictEqual(result, [ "Acquire outer", "Acquire 1", "Read 1", @@ -259,8 +260,8 @@ describe("Channel", () => { }) ) - assert.strictEqual(HashSet.size(missing), 0) - assert.strictEqual(HashSet.size(surplus), 0) + strictEqual(HashSet.size(missing), 0) + strictEqual(HashSet.size(surplus), 0) })) it.effect("nested concurrent reads", () => @@ -297,7 +298,7 @@ describe("Channel", () => { return [missing, surplus] as const }) ) - assert.strictEqual(HashSet.size(missing), 0) - assert.strictEqual(HashSet.size(surplus), 0) + strictEqual(HashSet.size(missing), 0) + strictEqual(HashSet.size(surplus), 0) })) }) diff --git a/packages/effect/test/Channel/scoping.test.ts b/packages/effect/test/Channel/scoping.test.ts index 74b7ac35632..87accb70e9a 100644 --- a/packages/effect/test/Channel/scoping.test.ts +++ b/packages/effect/test/Channel/scoping.test.ts @@ -2,13 +2,13 @@ import * as Cause from "effect/Cause" import * as Channel from "effect/Channel" import * as Deferred from "effect/Deferred" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import * as Fiber from "effect/Fiber" import * as FiberId from "effect/FiberId" import { pipe } from "effect/Function" import * as Ref from "effect/Ref" +import { assertLeft, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Channel", () => { it.it("acquireUseReleaseOut - acquire is executed uninterruptibly", async () => { @@ -29,7 +29,7 @@ describe("Channel", () => { }) const result = await Effect.runPromise(program) await Effect.runPromise(Deferred.succeed(latch, void 0)) - assert.strictEqual(result, 0) + strictEqual(result, 0) }, 35_000) it.it("scoped closes the scope", async () => { @@ -50,7 +50,7 @@ describe("Channel", () => { }) const result = await Effect.runPromise(program) await Effect.runPromise(Deferred.succeed(latch, void 0)) - assert.strictEqual(result, 0) + strictEqual(result, 0) }, 35_000) it.effect("finalizer failure is propagated", () => @@ -64,6 +64,6 @@ describe("Channel", () => { Effect.either ) - assert.deepEqual(exit, Either.left(Cause.die("ok"))) + assertLeft(exit, Cause.die("ok")) })) }) diff --git a/packages/effect/test/Channel/sequencing.test.ts b/packages/effect/test/Channel/sequencing.test.ts index e171a9deac3..efa4747a7b8 100644 --- a/packages/effect/test/Channel/sequencing.test.ts +++ b/packages/effect/test/Channel/sequencing.test.ts @@ -3,8 +3,9 @@ import * as Chunk from "effect/Chunk" import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" import { pipe } from "effect/Function" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Channel", () => { it.effect("flatMap - simple", () => @@ -24,8 +25,8 @@ describe("Channel", () => { ) ) const [chunk, value] = yield* $(Channel.runCollect(channel)) - assert.isTrue(Chunk.isEmpty(chunk)) - assert.strictEqual(value, 6) + assertTrue(Chunk.isEmpty(chunk)) + strictEqual(value, 6) })) it.effect("flatMap - structure confusion", () => @@ -36,6 +37,6 @@ describe("Channel", () => { Channel.zipRight(Channel.fail("hello")) ) const result = yield* $(Effect.exit(Channel.runDrain(channel))) - assert.deepStrictEqual(result, Exit.fail("hello")) + deepStrictEqual(result, Exit.fail("hello")) })) }) diff --git a/packages/effect/test/Channel/stack-safety.test.ts b/packages/effect/test/Channel/stack-safety.test.ts index 754f845d525..4acae6a573f 100644 --- a/packages/effect/test/Channel/stack-safety.test.ts +++ b/packages/effect/test/Channel/stack-safety.test.ts @@ -2,8 +2,9 @@ import * as Channel from "effect/Channel" import * as Chunk from "effect/Chunk" import * as Effect from "effect/Effect" import { pipe } from "effect/Function" +import { deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Channel", () => { it.effect("mapOut is stack safe", () => @@ -21,8 +22,8 @@ describe("Channel", () => { Chunk.range(1, N), Chunk.reduce(1, (x, y) => x + y) ) - assert.strictEqual(Chunk.unsafeHead(chunk), expected) - assert.isUndefined(value) + strictEqual(Chunk.unsafeHead(chunk), expected) + strictEqual(value, undefined) }), 20_000) it.effect("concatMap is stack safe", () => @@ -41,8 +42,8 @@ describe("Channel", () => { ), Channel.runCollect ) - assert.strictEqual(Chunk.unsafeHead(chunk), N) - assert.isUndefined(value) + strictEqual(Chunk.unsafeHead(chunk), N) + strictEqual(value, undefined) }), 20_000) it.effect("flatMap is stack safe", () => @@ -56,7 +57,7 @@ describe("Channel", () => { ), Channel.runCollect ) - assert.deepStrictEqual(Array.from(chunk), Array.from(Chunk.range(0, N))) - assert.isUndefined(value) + deepStrictEqual(Array.from(chunk), Array.from(Chunk.range(0, N))) + strictEqual(value, undefined) }), 20_000) }) diff --git a/packages/effect/test/Chunk.test.ts b/packages/effect/test/Chunk.test.ts index cf6225942e4..eba37fa0929 100644 --- a/packages/effect/test/Chunk.test.ts +++ b/packages/effect/test/Chunk.test.ts @@ -1,45 +1,62 @@ -import * as RA from "effect/Array" -import * as Chunk from "effect/Chunk" -import * as Duration from "effect/Duration" -import * as E from "effect/Either" -import * as Equal from "effect/Equal" -import { identity, pipe } from "effect/Function" -import * as N from "effect/Number" -import * as Option from "effect/Option" -import * as Order from "effect/Order" -import type { Predicate } from "effect/Predicate" -import * as Util from "effect/test/util" -import * as fc from "fast-check" -import { assert, describe, expect, it } from "vitest" +import { + Array as RA, + Chunk, + Either, + Equal, + FastCheck as fc, + identity, + Number as N, + Option, + Order, + pipe, + type Predicate +} from "effect" +import { + assertFalse, + assertNone, + assertSome, + assertTrue, + deepStrictEqual, + doesNotThrow, + equals, + strictEqual, + throws +} from "effect/test/util" +import { describe, it } from "vitest" + +const assertTuple = ( + actual: [Chunk.Chunk, Chunk.Chunk], + expected: [Chunk.Chunk, Chunk.Chunk] +) => { + equals(actual[0], expected[0]) + equals(actual[1], expected[1]) +} describe("Chunk", () => { - it("exports", () => { - expect(Chunk.unsafeFromNonEmptyArray).exist - expect(Chunk.contains).exist - expect(Chunk.containsWith).exist - expect(Chunk.difference).exist - expect(Chunk.differenceWith).exist - expect(Chunk.findFirst).exist - expect(Chunk.findFirstIndex).exist - expect(Chunk.findLast).exist - expect(Chunk.findLastIndex).exist - expect(Chunk.every).exist - expect(Chunk.join).exist - expect(Chunk.reduce).exist - expect(Chunk.reduceRight).exist - expect(Chunk.some).exist + it("Equal.equals", () => { + assertTrue(Equal.equals(Chunk.make(0), Chunk.make(0))) + assertTrue(Equal.equals(Chunk.make(1, 2, 3), Chunk.make(1, 2, 3))) + assertFalse(Equal.equals(Chunk.make(1, 2, 3), Chunk.make(1, 2))) + assertFalse(Equal.equals(Chunk.make(1, 2), Chunk.make(1, 2, 3))) + assertFalse(Equal.equals(Chunk.make(1, 2, 3), Chunk.make(1, "a", 3))) + assertFalse(Equal.equals(Chunk.make(0), [0])) }) it("toString", () => { - expect(String(Chunk.make(0, 1, 2))).toEqual(`{ + strictEqual( + String(Chunk.make(0, 1, 2)), + `{ "_id": "Chunk", "values": [ 0, 1, 2 ] -}`) - expect(String(Chunk.make(Chunk.make(1, 2, 3)))).toEqual(`{ +}` + ) + strictEqual( + String(Chunk.make(Chunk.make(1, 2, 3))), + `{ "_id": "Chunk", "values": [ { @@ -51,96 +68,92 @@ describe("Chunk", () => { ] } ] -}`) - }) - - it("toJSON", () => { - expect(Chunk.make(0, 1, 2).toJSON()).toEqual( - { _id: "Chunk", values: [0, 1, 2] } - ) - expect(Chunk.make(Chunk.make(1, 2, 3)).toJSON()).toEqual( - { _id: "Chunk", values: [{ _id: "Chunk", values: [1, 2, 3] }] } +}` ) }) - it("equals", () => { - expect(Equal.equals(Chunk.make(0), Chunk.make(0))).toBe(true) - expect(Equal.equals(Chunk.make(1, 2, 3), Chunk.make(1, 2, 3))).toBe(true) - expect(Equal.equals(Chunk.make(0), Duration.millis(1))).toBe(false) + it("toJSON", () => { + deepStrictEqual(Chunk.make(0, 1, 2).toJSON(), { _id: "Chunk", values: [0, 1, 2] }) + deepStrictEqual(Chunk.make(Chunk.make(1, 2, 3)).toJSON(), { + _id: "Chunk", + values: [{ _id: "Chunk", values: [1, 2, 3] }] + }) }) it("inspect", () => { if (typeof window === "undefined") { // eslint-disable-next-line @typescript-eslint/no-var-requires const { inspect } = require("node:util") - expect(inspect(Chunk.make(0, 1, 2))).toEqual(inspect({ _id: "Chunk", values: [0, 1, 2] })) + equals(inspect(Chunk.make(0, 1, 2)), inspect({ _id: "Chunk", values: [0, 1, 2] })) } }) it("modifyOption", () => { - expect(pipe(Chunk.empty(), Chunk.modifyOption(0, (n: number) => n * 2))).toEqual(Option.none()) - expect(pipe(Chunk.make(1, 2, 3), Chunk.modifyOption(0, (n: number) => n * 2))).toEqual( - Option.some(Chunk.make(2, 2, 3)) + assertNone(pipe(Chunk.empty(), Chunk.modifyOption(0, (n: number) => n * 2))) + assertSome( + pipe(Chunk.make(1, 2, 3), Chunk.modifyOption(0, (n: number) => n * 2)), + Chunk.make(2, 2, 3) ) }) it("modify", () => { - expect(pipe(Chunk.empty(), Chunk.modify(0, (n: number) => n * 2))).toEqual(Chunk.empty()) - expect(pipe(Chunk.make(1, 2, 3), Chunk.modify(0, (n: number) => n * 2))).toEqual(Chunk.make(2, 2, 3)) + equals(pipe(Chunk.empty(), Chunk.modify(0, (n: number) => n * 2)), Chunk.empty()) + equals(pipe(Chunk.make(1, 2, 3), Chunk.modify(0, (n: number) => n * 2)), Chunk.make(2, 2, 3)) }) it("replaceOption", () => { - expect(pipe(Chunk.empty(), Chunk.replaceOption(0, 2))).toEqual(Option.none()) - expect(pipe(Chunk.make(1, 2, 3), Chunk.replaceOption(0, 2))).toEqual(Option.some(Chunk.make(2, 2, 3))) + assertNone(pipe(Chunk.empty(), Chunk.replaceOption(0, 2))) + assertSome(pipe(Chunk.make(1, 2, 3), Chunk.replaceOption(0, 2)), Chunk.make(2, 2, 3)) }) it("replace", () => { - expect(pipe(Chunk.empty(), Chunk.replace(0, 2))).toEqual(Chunk.empty()) - expect(pipe(Chunk.make(1, 2, 3), Chunk.replace(0, 2))).toEqual(Chunk.make(2, 2, 3)) + equals(pipe(Chunk.empty(), Chunk.replace(0, 2)), Chunk.empty()) + equals(pipe(Chunk.make(1, 2, 3), Chunk.replace(0, 2)), Chunk.make(2, 2, 3)) }) it("remove", () => { - expect(pipe(Chunk.empty(), Chunk.remove(0))).toEqual(Chunk.empty()) - expect(pipe(Chunk.make(1, 2, 3), Chunk.remove(0))).toEqual(Chunk.make(2, 3)) + equals(pipe(Chunk.empty(), Chunk.remove(0)), Chunk.empty()) + equals(pipe(Chunk.make(1, 2, 3), Chunk.remove(0)), Chunk.make(2, 3)) }) it("chunksOf", () => { - expect(pipe(Chunk.empty(), Chunk.chunksOf(2))).toEqual(Chunk.empty()) - expect(pipe(Chunk.make(1, 2, 3, 4, 5), Chunk.chunksOf(2))).toEqual( + equals(pipe(Chunk.empty(), Chunk.chunksOf(2)), Chunk.empty()) + equals( + pipe(Chunk.make(1, 2, 3, 4, 5), Chunk.chunksOf(2)), Chunk.make(Chunk.make(1, 2), Chunk.make(3, 4), Chunk.make(5)) ) - expect(pipe(Chunk.make(1, 2, 3, 4, 5, 6), Chunk.chunksOf(2))).toEqual( + equals( + pipe(Chunk.make(1, 2, 3, 4, 5, 6), Chunk.chunksOf(2)), Chunk.make(Chunk.make(1, 2), Chunk.make(3, 4), Chunk.make(5, 6)) ) - expect(pipe(Chunk.make(1, 2, 3, 4, 5), Chunk.chunksOf(1))).toEqual( + equals( + pipe(Chunk.make(1, 2, 3, 4, 5), Chunk.chunksOf(1)), Chunk.make(Chunk.make(1), Chunk.make(2), Chunk.make(3), Chunk.make(4), Chunk.make(5)) ) - expect(pipe(Chunk.make(1, 2, 3, 4, 5), Chunk.chunksOf(5))).toEqual( - Chunk.make(Chunk.make(1, 2, 3, 4, 5)) - ) + equals(pipe(Chunk.make(1, 2, 3, 4, 5), Chunk.chunksOf(5)), Chunk.make(Chunk.make(1, 2, 3, 4, 5))) // out of bounds - expect(pipe(Chunk.make(1, 2, 3, 4, 5), Chunk.chunksOf(0))).toEqual( + equals( + pipe(Chunk.make(1, 2, 3, 4, 5), Chunk.chunksOf(0)), Chunk.make(Chunk.make(1), Chunk.make(2), Chunk.make(3), Chunk.make(4), Chunk.make(5)) ) - expect(pipe(Chunk.make(1, 2, 3, 4, 5), Chunk.chunksOf(-1))).toEqual( + equals( + pipe(Chunk.make(1, 2, 3, 4, 5), Chunk.chunksOf(-1)), Chunk.make(Chunk.make(1), Chunk.make(2), Chunk.make(3), Chunk.make(4), Chunk.make(5)) ) - expect(pipe(Chunk.make(1, 2, 3, 4, 5), Chunk.chunksOf(10))).toEqual( - Chunk.make(Chunk.make(1, 2, 3, 4, 5)) - ) + equals(pipe(Chunk.make(1, 2, 3, 4, 5), Chunk.chunksOf(10)), Chunk.make(Chunk.make(1, 2, 3, 4, 5))) }) - it(".pipe", () => { - expect(Chunk.empty().pipe(Chunk.append(1))).toEqual(Chunk.make(1)) + it(".pipe() method", () => { + equals(Chunk.empty().pipe(Chunk.append(1)), Chunk.make(1)) }) describe("toArray", () => { it("should return an empty array for an empty chunk", () => { - expect(Chunk.toArray(Chunk.empty())).toEqual([]) + deepStrictEqual(Chunk.toArray(Chunk.empty()), []) }) it("should return an array with the elements of the chunk", () => { - expect(Chunk.toArray(Chunk.make(1, 2, 3))).toEqual([1, 2, 3]) + deepStrictEqual(Chunk.toArray(Chunk.make(1, 2, 3)), [1, 2, 3]) }) it("should not affect the original chunk when the array is mutated", () => { @@ -149,7 +162,7 @@ describe("Chunk", () => { // mutate the array arr[1] = 4 // the chunk should not be affected - expect(Chunk.toArray(chunk)).toStrictEqual([1, 2, 3]) + deepStrictEqual(Chunk.toArray(chunk), [1, 2, 3]) }) }) @@ -157,7 +170,7 @@ describe("Chunk", () => { describe("Given an empty Chunk", () => { const chunk = Chunk.empty() it("should give back an empty readonly array", () => { - expect(Chunk.toReadonlyArray(chunk)).toEqual([]) + deepStrictEqual(Chunk.toReadonlyArray(chunk), []) }) }) @@ -167,8 +180,8 @@ describe("Chunk", () => { for (let i = 0; i < len; i++) chunk = Chunk.appendAll(Chunk.of(i), chunk) it("gives back a readonly array", () => { - expect(() => Chunk.toReadonlyArray(chunk)).not.toThrow() - expect(Chunk.toReadonlyArray(chunk)).toEqual(RA.reverse(RA.range(0, len - 1))) + doesNotThrow(() => Chunk.toReadonlyArray(chunk)) + deepStrictEqual(Chunk.toReadonlyArray(chunk), RA.reverse(RA.range(0, len - 1))) }) }) @@ -181,10 +194,8 @@ describe("Chunk", () => { lchunk = Chunk.appendAll(lchunk, Chunk.of(i)) } it("should have depth of +/- 3", () => { - expect(rchunk.depth) - .toBeGreaterThanOrEqual(lchunk.depth - 3) - expect(rchunk.depth) - .toBeLessThanOrEqual(lchunk.depth + 3) + assertTrue(rchunk.depth >= lchunk.depth - 3) + assertTrue(rchunk.depth <= lchunk.depth + 3) }) }) }) @@ -193,13 +204,13 @@ describe("Chunk", () => { describe("Given a chunk", () => { const chunk = Chunk.make(0, 1) it("should be true", () => { - expect(Chunk.isChunk(chunk)).toBe(true) + assertTrue(Chunk.isChunk(chunk)) }) }) describe("Given an object", () => { const object = {} it("should be false", () => { - expect(Chunk.isChunk(object)).toBe(false) + assertFalse(Chunk.isChunk(object)) }) }) }) @@ -220,14 +231,14 @@ describe("Chunk", () => { } it("should process it", () => { - expect(Chunk.fromIterable(myIterable)).toEqual(Chunk.unsafeFromArray([1, 2, 3, 4, 5])) + equals(Chunk.fromIterable(myIterable), Chunk.unsafeFromArray([1, 2, 3, 4, 5])) }) }) it("should return the same reference if the input is a Chunk", () => { const expected = Chunk.make(1, 2, 3) const actual = Chunk.fromIterable(expected) - expect(actual === expected).toEqual(true) + assertTrue(actual === expected) }) }) @@ -237,10 +248,7 @@ describe("Chunk", () => { const index = 0 it("should a Some with the value", () => { - expect(pipe( - chunk, - Chunk.get(index) - )).toEqual(Option.some(1)) + deepStrictEqual(pipe(chunk, Chunk.get(index)), Option.some(1)) }) }) @@ -248,7 +256,7 @@ describe("Chunk", () => { const chunk = Chunk.unsafeFromArray([1, 2, 3]) it("should return a None", () => { - expect(pipe(chunk, Chunk.get(4))).toEqual(Option.none()) + assertNone(pipe(chunk, Chunk.get(4))) }) }) }) @@ -259,7 +267,7 @@ describe("Chunk", () => { const index = 4 it("should throw", () => { - expect(() => pipe(chunk, Chunk.unsafeGet(index))).toThrow() + throws(() => pipe(chunk, Chunk.unsafeGet(index))) }) }) @@ -268,14 +276,14 @@ describe("Chunk", () => { const index = 4 it("should throw", () => { - expect(() => pipe(chunk, Chunk.unsafeGet(index))).toThrow() + throws(() => pipe(chunk, Chunk.unsafeGet(index))) }) }) describe("Given an appended Chunk and an index in bounds", () => { it("should return the value", () => { const chunk = pipe(Chunk.make(0, 1, 2), Chunk.append(3)) - expect(Chunk.unsafeGet(1)(chunk)).toEqual(1) + strictEqual(Chunk.unsafeGet(1)(chunk), 1) }) }) @@ -286,7 +294,7 @@ describe("Chunk", () => { array.forEach((e) => { chunk = pipe(chunk, Chunk.prepend(e)) }) - expect(() => pipe(chunk, Chunk.unsafeGet(array.length))).toThrow() + throws(() => pipe(chunk, Chunk.unsafeGet(array.length))) })) }) }) @@ -294,7 +302,7 @@ describe("Chunk", () => { describe("Given a prepended Chunk and an index in bounds", () => { it("should return the value", () => { const chunk = pipe(Chunk.make(0, 1, 2), Chunk.prepend(3)) - expect(Chunk.unsafeGet(1)(chunk)).toEqual(0) + strictEqual(Chunk.unsafeGet(1)(chunk), 0) }) }) @@ -303,7 +311,7 @@ describe("Chunk", () => { const index = 4 it("should throw", () => { - expect(() => pipe(chunk, Chunk.unsafeGet(index))).toThrow() + throws(() => pipe(chunk, Chunk.unsafeGet(index))) }) }) @@ -312,7 +320,7 @@ describe("Chunk", () => { const index = 4 it("should throw", () => { - expect(() => pipe(chunk, Chunk.unsafeGet(index))).toThrow() + throws(() => pipe(chunk, Chunk.unsafeGet(index))) }) }) @@ -320,7 +328,7 @@ describe("Chunk", () => { it("should throw", () => { fc.assert(fc.property(fc.array(fc.anything()), fc.array(fc.anything()), (arr1, arr2) => { const chunk: Chunk.Chunk = Chunk.appendAll(Chunk.fromIterable(arr2))(Chunk.unsafeFromArray(arr1)) - expect(() => pipe(chunk, Chunk.unsafeGet(arr1.length + arr2.length))).toThrow() + throws(() => pipe(chunk, Chunk.unsafeGet(arr1.length + arr2.length))) })) }) }) @@ -330,7 +338,7 @@ describe("Chunk", () => { const index = 1 it("should return the value", () => { - expect(pipe(chunk, Chunk.unsafeGet(index))).toEqual(2) + strictEqual(pipe(chunk, Chunk.unsafeGet(index)), 2) }) }) @@ -339,7 +347,7 @@ describe("Chunk", () => { const index = 1 it("should return the value", () => { - expect(pipe(chunk, Chunk.unsafeGet(index))).toEqual(2) + strictEqual(pipe(chunk, Chunk.unsafeGet(index)), 2) }) }) @@ -348,7 +356,7 @@ describe("Chunk", () => { const index = 0 it("should return the value", () => { - expect(pipe(chunk, Chunk.unsafeGet(index))).toEqual(1) + strictEqual(pipe(chunk, Chunk.unsafeGet(index)), 1) }) }) @@ -357,7 +365,7 @@ describe("Chunk", () => { const index = 1 it("should return the value", () => { - expect(pipe(chunk, Chunk.unsafeGet(index))).toEqual(2) + strictEqual(pipe(chunk, Chunk.unsafeGet(index)), 2) }) }) @@ -367,7 +375,7 @@ describe("Chunk", () => { const c = [...a, ...b] const d = Chunk.appendAll(Chunk.unsafeFromArray(b))(Chunk.unsafeFromArray(a)) for (let i = 0; i < c.length; i++) { - expect(Chunk.unsafeGet(i)(d)).toEqual(c[i]) + deepStrictEqual(Chunk.unsafeGet(i)(d), c[i]) } })) }) @@ -384,21 +392,21 @@ describe("Chunk", () => { b.forEach((e) => { chunk = Chunk.append(e)(chunk) }) - expect(Chunk.toReadonlyArray(chunk)).toEqual([...a, ...b]) + deepStrictEqual(Chunk.toReadonlyArray(chunk), [...a, ...b]) } ) ) }) it("prependAll", () => { - expect(pipe(Chunk.empty(), Chunk.prependAll(Chunk.make(1)))).toEqual(Chunk.make(1)) - expect(pipe(Chunk.make(1), Chunk.prependAll(Chunk.empty()))).toEqual(Chunk.make(1)) + equals(pipe(Chunk.empty(), Chunk.prependAll(Chunk.make(1))), Chunk.make(1)) + equals(pipe(Chunk.make(1), Chunk.prependAll(Chunk.empty())), Chunk.make(1)) - expect(pipe(Chunk.empty(), Chunk.prependAll(Chunk.make(1, 2)))).toEqual(Chunk.make(1, 2)) - expect(pipe(Chunk.make(1, 2), Chunk.prependAll(Chunk.empty()))).toEqual(Chunk.make(1, 2)) + equals(pipe(Chunk.empty(), Chunk.prependAll(Chunk.make(1, 2))), Chunk.make(1, 2)) + equals(pipe(Chunk.make(1, 2), Chunk.prependAll(Chunk.empty())), Chunk.make(1, 2)) - expect(pipe(Chunk.make(2, 3), Chunk.prependAll(Chunk.make(1)))).toEqual(Chunk.make(1, 2, 3)) - expect(pipe(Chunk.make(3), Chunk.prependAll(Chunk.make(1, 2)))).toEqual(Chunk.make(1, 2, 3)) + equals(pipe(Chunk.make(2, 3), Chunk.prependAll(Chunk.make(1))), Chunk.make(1, 2, 3)) + equals(pipe(Chunk.make(3), Chunk.prependAll(Chunk.make(1, 2))), Chunk.make(1, 2, 3)) }) it("prepend", () => { @@ -411,7 +419,7 @@ describe("Chunk", () => { for (let i = b.length - 1; i >= 0; i--) { chunk = Chunk.prepend(b[i])(chunk) } - expect(Chunk.toReadonlyArray(chunk)).toEqual([...b, ...a]) + deepStrictEqual(Chunk.toReadonlyArray(chunk), [...b, ...a]) } ) ) @@ -420,8 +428,7 @@ describe("Chunk", () => { describe("take", () => { describe("Given a Chunk with more elements than the amount taken", () => { it("should return the subset", () => { - expect(pipe(Chunk.unsafeFromArray([1, 2, 3]), Chunk.take(2))) - .toEqual(Chunk.unsafeFromArray([1, 2])) + equals(pipe(Chunk.unsafeFromArray([1, 2, 3]), Chunk.take(2)), Chunk.unsafeFromArray([1, 2])) }) }) @@ -430,11 +437,7 @@ describe("Chunk", () => { const amount = 5 it("should return the available subset", () => { - expect(pipe(chunk, Chunk.take(amount))).toEqual(Chunk.unsafeFromArray([ - 1, - 2, - 3 - ])) + equals(pipe(chunk, Chunk.take(amount)), Chunk.unsafeFromArray([1, 2, 3])) }) }) @@ -443,11 +446,7 @@ describe("Chunk", () => { const amount = 3 it("should return the available subset", () => { - expect(pipe(chunk, Chunk.take(amount))).toEqual(Chunk.unsafeFromArray([ - 1, - 2, - 3 - ])) + equals(pipe(chunk, Chunk.take(amount)), Chunk.unsafeFromArray([1, 2, 3])) }) }) @@ -456,9 +455,7 @@ describe("Chunk", () => { const amount = 2 it("should return the available subset", () => { - expect(pipe(chunk, Chunk.take(amount))).toEqual(Chunk.unsafeFromArray([ - 1 - ])) + equals(pipe(chunk, Chunk.take(amount)), Chunk.unsafeFromArray([1])) }) }) @@ -467,46 +464,46 @@ describe("Chunk", () => { const amount = 2 it("should return the available subset", () => { - expect(pipe(chunk, Chunk.take(amount), Chunk.toReadonlyArray)).toEqual([1, 2]) + deepStrictEqual(pipe(chunk, Chunk.take(amount), Chunk.toReadonlyArray), [1, 2]) }) }) describe("Given a concatenated Chunk and an amount <= self.left", () => { it("should return the available subset", () => { const chunk = Chunk.appendAll(Chunk.make(2, 3, 4), Chunk.of(1)) - expect(pipe(chunk, Chunk.take(2), Chunk.toReadonlyArray)).toEqual([2, 3]) - expect(pipe(chunk, Chunk.take(3), Chunk.toReadonlyArray)).toEqual([2, 3, 4]) + deepStrictEqual(pipe(chunk, Chunk.take(2), Chunk.toReadonlyArray), [2, 3]) + deepStrictEqual(pipe(chunk, Chunk.take(3), Chunk.toReadonlyArray), [2, 3, 4]) }) }) }) describe("make", () => { it("should return a NonEmptyChunk", () => { - expect(Chunk.make(0, 1).length).toStrictEqual(2) + strictEqual(Chunk.make(0, 1).length, 2) }) }) describe("singleton", () => { it("should return a NonEmptyChunk", () => { - expect(Chunk.of(1).length).toStrictEqual(1) + strictEqual(Chunk.of(1).length, 1) }) it("should return a ISingleton", () => { - expect(Chunk.of(1).backing._tag).toEqual("ISingleton") + strictEqual(Chunk.of(1).backing._tag, "ISingleton") }) }) describe("drop", () => { it("should return self on 0", () => { const self = Chunk.make(0, 1) - expect(Chunk.drop(0)(self)).toStrictEqual(self) + strictEqual(Chunk.drop(0)(self), self) }) it("should drop twice", () => { const self = Chunk.make(0, 1, 2, 3) - expect(Chunk.toReadonlyArray(Chunk.drop(1)(Chunk.drop(1)(self)))).toEqual([2, 3]) + deepStrictEqual(Chunk.toReadonlyArray(Chunk.drop(1)(Chunk.drop(1)(self))), [2, 3]) }) it("should handle concatenated chunks", () => { const self = pipe(Chunk.make(1), Chunk.appendAll(Chunk.make(2, 3, 4))) - expect(pipe(self, Chunk.drop(2), Chunk.toReadonlyArray)).toEqual([3, 4]) + deepStrictEqual(pipe(self, Chunk.drop(2), Chunk.toReadonlyArray), [3, 4]) }) }) @@ -516,7 +513,7 @@ describe("Chunk", () => { const toDrop = 1 it("should remove the given amount of items", () => { - expect(pipe(chunk, Chunk.dropRight(toDrop))).toEqual(Chunk.unsafeFromArray([1, 2])) + equals(pipe(chunk, Chunk.dropRight(toDrop)), Chunk.unsafeFromArray([1, 2])) }) }) @@ -525,7 +522,7 @@ describe("Chunk", () => { const toDrop = 3 it("should return an empty chunk", () => { - expect(pipe(chunk, Chunk.dropRight(toDrop))).toEqual(Chunk.unsafeFromArray([])) + equals(pipe(chunk, Chunk.dropRight(toDrop)), Chunk.unsafeFromArray([])) }) }) }) @@ -536,7 +533,7 @@ describe("Chunk", () => { const criteria = (n: number) => n < 3 it("should return the subset that doesn't pass the criteria", () => { - expect(pipe(chunk, Chunk.dropWhile(criteria))).toEqual(Chunk.unsafeFromArray([3])) + equals(pipe(chunk, Chunk.dropWhile(criteria)), Chunk.unsafeFromArray([3])) }) }) @@ -545,7 +542,7 @@ describe("Chunk", () => { const criteria = (n: number) => n < 4 it("should return an empty chunk", () => { - expect(pipe(chunk, Chunk.dropWhile(criteria))).toEqual(Chunk.unsafeFromArray([])) + equals(pipe(chunk, Chunk.dropWhile(criteria)), Chunk.unsafeFromArray([])) }) }) }) @@ -556,7 +553,7 @@ describe("Chunk", () => { const chunk2 = Chunk.unsafeFromArray([2, 3]) it("should concatenate them following order", () => { - expect(pipe(chunk1, Chunk.appendAll(chunk2))).toEqual(Chunk.unsafeFromArray([0, 1, 2, 3])) + equals(pipe(chunk1, Chunk.appendAll(chunk2)), Chunk.unsafeFromArray([0, 1, 2, 3])) }) }) @@ -565,7 +562,7 @@ describe("Chunk", () => { const chunk2 = Chunk.unsafeFromArray([3]) it("should concatenate them following order", () => { - expect(pipe(chunk1, Chunk.appendAll(chunk2))).toEqual(Chunk.unsafeFromArray([1, 2, 3])) + equals(pipe(chunk1, Chunk.appendAll(chunk2)), Chunk.unsafeFromArray([1, 2, 3])) }) }) @@ -574,7 +571,7 @@ describe("Chunk", () => { const chunk2 = Chunk.unsafeFromArray([2, 3, 4]) it("should concatenate them following order", () => { - expect(pipe(chunk1, Chunk.appendAll(chunk2))).toEqual(Chunk.unsafeFromArray([1, 2, 3, 4])) + equals(pipe(chunk1, Chunk.appendAll(chunk2)), Chunk.unsafeFromArray([1, 2, 3, 4])) }) }) @@ -586,7 +583,7 @@ describe("Chunk", () => { const chunk2 = Chunk.unsafeFromArray([2, 3, 4]) it("should concatenate them following order", () => { - expect(pipe(chunk1, Chunk.appendAll(chunk2))).toEqual(Chunk.unsafeFromArray([1, 2, 3, 4])) + equals(pipe(chunk1, Chunk.appendAll(chunk2)), Chunk.unsafeFromArray([1, 2, 3, 4])) }) }) @@ -598,7 +595,7 @@ describe("Chunk", () => { ) it("should concatenate them following order", () => { - expect(pipe(chunk1, Chunk.appendAll(chunk2))).toEqual(Chunk.unsafeFromArray([1, 2])) + equals(pipe(chunk1, Chunk.appendAll(chunk2)), Chunk.unsafeFromArray([1, 2])) }) }) @@ -607,7 +604,7 @@ describe("Chunk", () => { const chunk2 = Chunk.unsafeFromArray([1, 2]) it("should concatenate them following order", () => { - expect(pipe(chunk1, Chunk.appendAll(chunk2))).toEqual(Chunk.unsafeFromArray([1, 2])) + equals(pipe(chunk1, Chunk.appendAll(chunk2)), Chunk.unsafeFromArray([1, 2])) }) }) @@ -616,7 +613,7 @@ describe("Chunk", () => { const chunk2 = Chunk.empty() it("should concatenate them following order", () => { - expect(pipe(chunk1, Chunk.appendAll(chunk2))).toEqual(Chunk.unsafeFromArray([1, 2])) + equals(pipe(chunk1, Chunk.appendAll(chunk2)), Chunk.unsafeFromArray([1, 2])) }) }) @@ -628,45 +625,26 @@ describe("Chunk", () => { const chunk5 = Chunk.unsafeFromArray([5, 6]) it("should concatenate them following order", () => { - expect( + equals( pipe( chunk1, Chunk.appendAll(chunk2), Chunk.appendAll(chunk3), Chunk.appendAll(chunk4), Chunk.appendAll(chunk5) - ) + ), + Chunk.unsafeFromArray([1, 2, 3, 4, 5, 6]) ) - .toEqual(Chunk.unsafeFromArray([1, 2, 3, 4, 5, 6])) }) }) // TODO add tests for 100% coverage: left & right diff depths & depth > 0 }) it("zip", () => { - pipe( - Chunk.empty(), - Chunk.zip(Chunk.empty()), - Equal.equals(Chunk.unsafeFromArray([])), - assert.isTrue - ) - pipe( - Chunk.empty(), - Chunk.zip(Chunk.of(1)), - Equal.equals(Chunk.unsafeFromArray([])), - assert.isTrue - ) - pipe( - Chunk.of(1), - Chunk.zip(Chunk.empty()), - Equal.equals(Chunk.unsafeFromArray([])), - assert.isTrue - ) - expect(pipe( - Chunk.of(1), - Chunk.zip(Chunk.of(2)), - Chunk.toReadonlyArray - )).toEqual([[1, 2]]) + equals(Chunk.zip(Chunk.empty(), Chunk.empty()), Chunk.empty()) + equals(Chunk.zip(Chunk.make(1), Chunk.empty()), Chunk.empty()) + equals(Chunk.zip(Chunk.empty(), Chunk.make(1)), Chunk.empty()) + deepStrictEqual(Chunk.toArray(Chunk.zip(Chunk.make(1), Chunk.make(2))), [[1, 2]]) }) describe("Given two non-materialized chunks of different sizes", () => { @@ -675,203 +653,197 @@ describe("Chunk", () => { const left = pipe(Chunk.make(-1, 0, 1), Chunk.drop(1)) const right = pipe(Chunk.make(1, 0, 0, 1), Chunk.drop(1)) const zipped = pipe(left, Chunk.zipWith(pipe(right, Chunk.take(left.length)), (a, b) => [a, b])) - expect(Array.from(zipped)).toEqual([[0, 0], [1, 0]]) + deepStrictEqual(Array.from(zipped), [[0, 0], [1, 0]]) }) }) it("last", () => { - expect(Chunk.last(Chunk.empty())).toEqual(Option.none()) - expect(Chunk.last(Chunk.make(1, 2, 3))).toEqual(Option.some(3)) + assertNone(Chunk.last(Chunk.empty())) + assertSome(Chunk.last(Chunk.make(1, 2, 3)), 3) }) it("map", () => { - expect(Chunk.map(Chunk.empty(), (n) => n + 1)).toEqual(Chunk.empty()) - expect(Chunk.map(Chunk.of(1), (n) => n + 1)).toEqual(Chunk.of(2)) - expect(Chunk.map(Chunk.make(1, 2, 3), (n) => n + 1)).toEqual(Chunk.make(2, 3, 4)) - expect(Chunk.map(Chunk.make(1, 2, 3), (n, i) => n + i)).toEqual(Chunk.make(1, 3, 5)) + equals(Chunk.map(Chunk.empty(), (n) => n + 1), Chunk.empty()) + equals(Chunk.map(Chunk.of(1), (n) => n + 1), Chunk.of(2)) + equals(Chunk.map(Chunk.make(1, 2, 3), (n) => n + 1), Chunk.make(2, 3, 4)) + equals(Chunk.map(Chunk.make(1, 2, 3), (n, i) => n + i), Chunk.make(1, 3, 5)) }) it("mapAccum", () => { - expect(Chunk.mapAccum(Chunk.make(1, 2, 3), "-", (s, a) => [s + a, a + 1])).toEqual(["-123", Chunk.make(2, 3, 4)]) + deepStrictEqual(Chunk.mapAccum(Chunk.make(1, 2, 3), "-", (s, a) => [s + a, a + 1]), ["-123", Chunk.make(2, 3, 4)]) }) it("partition", () => { - expect(Chunk.partition(Chunk.empty(), (n) => n > 2)).toEqual([Chunk.empty(), Chunk.empty()]) - expect(Chunk.partition(Chunk.make(1, 3), (n) => n > 2)).toEqual([Chunk.make(1), Chunk.make(3)]) + assertTuple(Chunk.partition(Chunk.empty(), (n) => n > 2), [Chunk.empty(), Chunk.empty()]) + assertTuple(Chunk.partition(Chunk.make(1, 3), (n) => n > 2), [Chunk.make(1), Chunk.make(3)]) - expect(Chunk.partition(Chunk.empty(), (n, i) => n + i > 2)).toEqual([Chunk.empty(), Chunk.empty()]) - expect(Chunk.partition(Chunk.make(1, 2), (n, i) => n + i > 2)).toEqual([Chunk.make(1), Chunk.make(2)]) + assertTuple(Chunk.partition(Chunk.empty(), (n, i) => n + i > 2), [Chunk.empty(), Chunk.empty()]) + assertTuple(Chunk.partition(Chunk.make(1, 2), (n, i) => n + i > 2), [Chunk.make(1), Chunk.make(2)]) }) it("partitionMap", () => { - expect(Chunk.partitionMap(Chunk.empty(), identity)).toEqual([Chunk.empty(), Chunk.empty()]) - expect(Chunk.partitionMap(Chunk.make(E.right(1), E.left("a"), E.right(2)), identity)).toEqual([ + assertTuple(Chunk.partitionMap(Chunk.empty(), identity), [Chunk.empty(), Chunk.empty()]) + assertTuple(Chunk.partitionMap(Chunk.make(Either.right(1), Either.left("a"), Either.right(2)), identity), [ Chunk.make("a"), Chunk.make(1, 2) ]) }) it("separate", () => { - expect(Chunk.separate(Chunk.empty())).toEqual([Chunk.empty(), Chunk.empty()]) - expect(Chunk.separate(Chunk.make(E.right(1), E.left("e"), E.right(2)))).toEqual([ + assertTuple(Chunk.separate(Chunk.empty()), [Chunk.empty(), Chunk.empty()]) + assertTuple(Chunk.separate(Chunk.make(Either.right(1), Either.left("e"), Either.right(2))), [ Chunk.make("e"), Chunk.make(1, 2) ]) }) it("size", () => { - expect(Chunk.size(Chunk.empty())).toEqual(0) - expect(Chunk.size(Chunk.make(1, 2, 3))).toEqual(3) + strictEqual(Chunk.size(Chunk.empty()), 0) + strictEqual(Chunk.size(Chunk.make(1, 2, 3)), 3) }) it("split", () => { - expect(pipe(Chunk.empty(), Chunk.split(2))).toEqual(Chunk.empty()) - expect(pipe(Chunk.make(1), Chunk.split(2))).toEqual( - Chunk.make(Chunk.make(1)) - ) - expect(pipe(Chunk.make(1, 2), Chunk.split(2))).toEqual( - Chunk.make(Chunk.make(1), Chunk.make(2)) - ) - expect(pipe(Chunk.make(1, 2, 3, 4, 5), Chunk.split(2))).toEqual( - Chunk.make(Chunk.make(1, 2, 3), Chunk.make(4, 5)) - ) - expect(pipe(Chunk.make(1, 2, 3, 4, 5), Chunk.split(3))).toEqual( + equals(pipe(Chunk.empty(), Chunk.split(2)), Chunk.empty()) + equals(pipe(Chunk.make(1), Chunk.split(2)), Chunk.make(Chunk.make(1))) + equals(pipe(Chunk.make(1, 2), Chunk.split(2)), Chunk.make(Chunk.make(1), Chunk.make(2))) + equals(pipe(Chunk.make(1, 2, 3, 4, 5), Chunk.split(2)), Chunk.make(Chunk.make(1, 2, 3), Chunk.make(4, 5))) + equals( + pipe(Chunk.make(1, 2, 3, 4, 5), Chunk.split(3)), Chunk.make(Chunk.make(1, 2), Chunk.make(3, 4), Chunk.make(5)) ) }) it("tail", () => { - expect(Chunk.tail(Chunk.empty())).toEqual(Option.none()) - expect(Chunk.tail(Chunk.make(1, 2, 3))).toEqual(Option.some(Chunk.make(2, 3))) + assertNone(Chunk.tail(Chunk.empty())) + // TODO: use assertSome? + equals(Chunk.tail(Chunk.make(1, 2, 3)), Option.some(Chunk.make(2, 3))) }) it("filter", () => { - Util.deepStrictEqual(Chunk.filter(Chunk.make(1, 2, 3), (n) => n % 2 === 1), Chunk.make(1, 3)) - assert.deepStrictEqual( + equals(Chunk.filter(Chunk.make(1, 2, 3), (n) => n % 2 === 1), Chunk.make(1, 3)) + equals( Chunk.filter(Chunk.make(Option.some(3), Option.some(2), Option.some(1)), Option.isSome), Chunk.make(Option.some(3), Option.some(2), Option.some(1)) as any ) - assert.deepStrictEqual( + equals( Chunk.filter(Chunk.make(Option.some(3), Option.none(), Option.some(1)), Option.isSome), Chunk.make(Option.some(3), Option.some(1)) as any ) }) it("filterMapWhile", () => { - expect(Chunk.filterMapWhile(Chunk.make(1, 3, 4, 5), (n) => n % 2 === 1 ? Option.some(n) : Option.none())).toEqual( + equals( + Chunk.filterMapWhile(Chunk.make(1, 3, 4, 5), (n) => n % 2 === 1 ? Option.some(n) : Option.none()), Chunk.make(1, 3) ) }) it("compact", () => { - expect(Chunk.compact(Chunk.empty())).toEqual(Chunk.empty()) - expect(Chunk.compact(Chunk.make(Option.some(1), Option.some(2), Option.some(3)))).toEqual(Chunk.make(1, 2, 3)) - expect(Chunk.compact(Chunk.make(Option.some(1), Option.none(), Option.some(3)))).toEqual(Chunk.make(1, 3)) + equals(Chunk.compact(Chunk.empty()), Chunk.empty()) + equals(Chunk.compact(Chunk.make(Option.some(1), Option.some(2), Option.some(3))), Chunk.make(1, 2, 3)) + equals(Chunk.compact(Chunk.make(Option.some(1), Option.none(), Option.some(3))), Chunk.make(1, 3)) }) it("dedupeAdjacent", () => { - expect(Chunk.dedupeAdjacent(Chunk.empty())).toEqual(Chunk.empty()) - expect(Chunk.dedupeAdjacent(Chunk.make(1, 2, 3))).toEqual(Chunk.make(1, 2, 3)) - expect(Chunk.dedupeAdjacent(Chunk.make(1, 2, 2, 3, 3))).toEqual(Chunk.make(1, 2, 3)) + equals(Chunk.dedupeAdjacent(Chunk.empty()), Chunk.empty()) + equals(Chunk.dedupeAdjacent(Chunk.make(1, 2, 3)), Chunk.make(1, 2, 3)) + equals(Chunk.dedupeAdjacent(Chunk.make(1, 2, 2, 3, 3)), Chunk.make(1, 2, 3)) }) it("flatMap", () => { - expect(Chunk.flatMap(Chunk.make(1), (n) => Chunk.make(n, n + 1))).toEqual(Chunk.make(1, 2)) - expect(Chunk.flatMap(Chunk.make(1, 2, 3), (n) => Chunk.make(n, n + 1))).toEqual(Chunk.make(1, 2, 2, 3, 3, 4)) + equals(Chunk.flatMap(Chunk.make(1), (n) => Chunk.make(n, n + 1)), Chunk.make(1, 2)) + equals(Chunk.flatMap(Chunk.make(1, 2, 3), (n) => Chunk.make(n, n + 1)), Chunk.make(1, 2, 2, 3, 3, 4)) }) it("union", () => { - expect(Chunk.union(Chunk.make(1, 2, 3), Chunk.empty())).toEqual(Chunk.make(1, 2, 3)) - expect(Chunk.union(Chunk.empty(), Chunk.make(1, 2, 3))).toEqual(Chunk.make(1, 2, 3)) - expect(Chunk.union(Chunk.make(1, 2, 3), Chunk.make(2, 3, 4))).toEqual(Chunk.make(1, 2, 3, 4)) + equals(Chunk.union(Chunk.make(1, 2, 3), Chunk.empty()), Chunk.make(1, 2, 3)) + equals(Chunk.union(Chunk.empty(), Chunk.make(1, 2, 3)), Chunk.make(1, 2, 3)) + equals(Chunk.union(Chunk.make(1, 2, 3), Chunk.make(2, 3, 4)), Chunk.make(1, 2, 3, 4)) }) it("intersection", () => { - expect(Chunk.intersection(Chunk.make(1, 2, 3), Chunk.empty())).toEqual(Chunk.empty()) - expect(Chunk.intersection(Chunk.empty(), Chunk.make(2, 3, 4))).toEqual(Chunk.empty()) - expect(Chunk.intersection(Chunk.make(1, 2, 3), Chunk.make(2, 3, 4))).toEqual(Chunk.make(2, 3)) + equals(Chunk.intersection(Chunk.make(1, 2, 3), Chunk.empty()), Chunk.empty()) + equals(Chunk.intersection(Chunk.empty(), Chunk.make(2, 3, 4)), Chunk.empty()) + equals(Chunk.intersection(Chunk.make(1, 2, 3), Chunk.make(2, 3, 4)), Chunk.make(2, 3)) }) it("isEmpty", () => { - expect(Chunk.isEmpty(Chunk.empty())).toEqual(true) - expect(Chunk.isEmpty(Chunk.make(1))).toEqual(false) + assertTrue(Chunk.isEmpty(Chunk.empty())) + assertFalse(Chunk.isEmpty(Chunk.make(1))) }) it("unsafeLast", () => { - expect(Chunk.unsafeLast(Chunk.make(1))).toEqual(1) - expect(Chunk.unsafeLast(Chunk.make(1, 2, 3))).toEqual(3) - expect(() => Chunk.unsafeLast(Chunk.empty())).toThrow(new Error("Index out of bounds")) + strictEqual(Chunk.unsafeLast(Chunk.make(1)), 1) + strictEqual(Chunk.unsafeLast(Chunk.make(1, 2, 3)), 3) + throws(() => Chunk.unsafeLast(Chunk.empty()), new Error("Index out of bounds")) }) it("splitNonEmptyAt", () => { - expect(pipe(Chunk.make(1, 2, 3, 4), Chunk.splitNonEmptyAt(2))).toStrictEqual([Chunk.make(1, 2), Chunk.make(3, 4)]) - expect(pipe(Chunk.make(1, 2, 3, 4), Chunk.splitNonEmptyAt(10))).toStrictEqual([ - Chunk.make(1, 2, 3, 4), - Chunk.empty() - ]) + assertTuple(Chunk.splitNonEmptyAt(Chunk.make(1, 2, 3, 4), 2), [Chunk.make(1, 2), Chunk.make(3, 4)]) + assertTuple(Chunk.splitNonEmptyAt(Chunk.make(1, 2, 3, 4), 10), [Chunk.make(1, 2, 3, 4), Chunk.empty()]) }) it("splitWhere", () => { - expect(Chunk.splitWhere(Chunk.empty(), (n) => n > 1)).toEqual([Chunk.empty(), Chunk.empty()]) - expect(Chunk.splitWhere(Chunk.make(1, 2, 3), (n) => n > 1)).toEqual([Chunk.make(1), Chunk.make(2, 3)]) + assertTuple(Chunk.splitWhere(Chunk.empty(), (n) => n > 1), [Chunk.empty(), Chunk.empty()]) + assertTuple(Chunk.splitWhere(Chunk.make(1, 2, 3), (n) => n > 1), [Chunk.make(1), Chunk.make(2, 3)]) }) it("takeWhile", () => { - expect(Chunk.takeWhile(Chunk.empty(), (n) => n <= 2)).toEqual(Chunk.empty()) - expect(Chunk.takeWhile(Chunk.make(1, 2, 3), (n) => n <= 2)).toEqual(Chunk.make(1, 2)) + equals(Chunk.takeWhile(Chunk.empty(), (n) => n <= 2), Chunk.empty()) + equals(Chunk.takeWhile(Chunk.make(1, 2, 3), (n) => n <= 2), Chunk.make(1, 2)) }) it("dedupe", () => { - expect(Chunk.dedupe(Chunk.empty())).toEqual(Chunk.empty()) - expect(Chunk.dedupe(Chunk.make(1, 2, 3))).toEqual(Chunk.make(1, 2, 3)) - expect(Chunk.dedupe(Chunk.make(1, 2, 3, 2, 1, 3))).toEqual(Chunk.make(1, 2, 3)) + equals(Chunk.dedupe(Chunk.empty()), Chunk.empty()) + equals(Chunk.dedupe(Chunk.make(1, 2, 3)), Chunk.make(1, 2, 3)) + equals(Chunk.dedupe(Chunk.make(1, 2, 3, 2, 1, 3)), Chunk.make(1, 2, 3)) }) it("unzip", () => { - expect(Chunk.unzip(Chunk.empty())).toEqual([Chunk.empty(), Chunk.empty()]) - expect(Chunk.unzip(Chunk.make(["a", 1] as const, ["b", 2] as const))).toEqual([ + assertTuple(Chunk.unzip(Chunk.empty()), [Chunk.empty(), Chunk.empty()]) + assertTuple(Chunk.unzip(Chunk.make(["a", 1] as const, ["b", 2] as const)), [ Chunk.make("a", "b"), Chunk.make(1, 2) ]) }) it("reverse", () => { - expect(Chunk.reverse(Chunk.empty())).toEqual(Chunk.empty()) - expect(Chunk.reverse(Chunk.make(1, 2, 3))).toEqual(Chunk.make(3, 2, 1)) - expect(Chunk.reverse(Chunk.take(Chunk.make(1, 2, 3, 4), 3))).toEqual(Chunk.make(3, 2, 1)) + equals(Chunk.reverse(Chunk.empty()), Chunk.empty()) + equals(Chunk.reverse(Chunk.make(1, 2, 3)), Chunk.make(3, 2, 1)) + equals(Chunk.reverse(Chunk.take(Chunk.make(1, 2, 3, 4), 3)), Chunk.make(3, 2, 1)) }) it("flatten", () => { - expect(Chunk.flatten(Chunk.make(Chunk.make(1), Chunk.make(2), Chunk.make(3)))).toEqual(Chunk.make(1, 2, 3)) + equals(Chunk.flatten(Chunk.make(Chunk.make(1), Chunk.make(2), Chunk.make(3))), Chunk.make(1, 2, 3)) }) it("makeBy", () => { - expect(Chunk.makeBy(5, (n) => n * 2)).toEqual(Chunk.make(0, 2, 4, 6, 8)) - expect(Chunk.makeBy(2.2, (n) => n * 2)).toEqual(Chunk.make(0, 2)) + equals(Chunk.makeBy(5, (n) => n * 2), Chunk.make(0, 2, 4, 6, 8)) + equals(Chunk.makeBy(2.2, (n) => n * 2), Chunk.make(0, 2)) }) it("range", () => { - expect(Chunk.range(0, 0)).toEqual(Chunk.make(0)) - expect(Chunk.range(0, 1)).toEqual(Chunk.make(0, 1)) - expect(Chunk.range(1, 5)).toEqual(Chunk.make(1, 2, 3, 4, 5)) - expect(Chunk.range(10, 15)).toEqual(Chunk.make(10, 11, 12, 13, 14, 15)) - expect(Chunk.range(-1, 0)).toEqual(Chunk.make(-1, 0)) - expect(Chunk.range(-5, -1)).toEqual(Chunk.make(-5, -4, -3, -2, -1)) + equals(Chunk.range(0, 0), Chunk.make(0)) + equals(Chunk.range(0, 1), Chunk.make(0, 1)) + equals(Chunk.range(1, 5), Chunk.make(1, 2, 3, 4, 5)) + equals(Chunk.range(10, 15), Chunk.make(10, 11, 12, 13, 14, 15)) + equals(Chunk.range(-1, 0), Chunk.make(-1, 0)) + equals(Chunk.range(-5, -1), Chunk.make(-5, -4, -3, -2, -1)) // out of bound - expect(Chunk.range(2, 1)).toEqual(Chunk.make(2)) - expect(Chunk.range(-1, -2)).toEqual(Chunk.make(-1)) + equals(Chunk.range(2, 1), Chunk.make(2)) + equals(Chunk.range(-1, -2), Chunk.make(-1)) }) it("some", () => { - const isPositive: Predicate = (n) => n > 0 - expect(Chunk.some(Chunk.make(-1, -2, 3), isPositive)).toEqual(true) - expect(Chunk.some(Chunk.make(-1, -2, -3), isPositive)).toEqual(false) + const isPositive: Predicate.Predicate = (n) => n > 0 + assertTrue(Chunk.some(Chunk.make(-1, -2, 3), isPositive)) + assertFalse(Chunk.some(Chunk.make(-1, -2, -3), isPositive)) }) it("forEach", () => { const as: Array = [] Chunk.forEach(Chunk.make(1, 2, 3, 4), (n) => as.push(n)) - expect(as).toEqual([1, 2, 3, 4]) + deepStrictEqual(as, [1, 2, 3, 4]) }) it("sortWith", () => { @@ -880,35 +852,35 @@ describe("Chunk", () => { b: number } const chunk: Chunk.Chunk = Chunk.make({ a: "a", b: 2 }, { a: "b", b: 1 }) - expect(Chunk.sortWith(chunk, (x) => x.b, Order.number)).toEqual(Chunk.make({ a: "b", b: 1 }, { a: "a", b: 2 })) + deepStrictEqual(Chunk.sortWith(chunk, (x) => x.b, Order.number), Chunk.make({ a: "b", b: 1 }, { a: "a", b: 2 })) }) it("getEquivalence", () => { const equivalence = Chunk.getEquivalence(N.Equivalence) - expect(equivalence(Chunk.empty(), Chunk.empty())).toBe(true) - expect(equivalence(Chunk.make(1, 2, 3), Chunk.make(1, 2, 3))).toBe(true) - expect(equivalence(Chunk.make(1, 2, 3), Chunk.make(1, 2))).toBe(false) - expect(equivalence(Chunk.make(1, 2, 3), Chunk.make(1, 2, 4))).toBe(false) + assertTrue(equivalence(Chunk.empty(), Chunk.empty())) + assertTrue(equivalence(Chunk.make(1, 2, 3), Chunk.make(1, 2, 3))) + assertFalse(equivalence(Chunk.make(1, 2, 3), Chunk.make(1, 2))) + assertFalse(equivalence(Chunk.make(1, 2, 3), Chunk.make(1, 2, 4))) }) it("differenceWith", () => { const eq = (a: E, b: E) => a.id === b.id - const diffW = pipe(eq, Chunk.differenceWith) + const differenceWith = pipe(eq, Chunk.differenceWith) - const curr = Chunk.make({ id: 1 }, { id: 2 }, { id: 3 }) + const chunk = Chunk.make({ id: 1 }, { id: 2 }, { id: 3 }) - expect(diffW(Chunk.make({ id: 1 }, { id: 2 }), curr)).toEqual(Chunk.make({ id: 3 })) - expect(diffW(Chunk.empty(), curr)).toEqual(curr) - expect(diffW(curr, Chunk.empty())).toEqual(Chunk.empty()) - expect(diffW(curr, curr)).toEqual(Chunk.empty()) + deepStrictEqual(differenceWith(Chunk.make({ id: 1 }, { id: 2 }), chunk), Chunk.make({ id: 3 })) + equals(differenceWith(Chunk.empty(), chunk), chunk) + equals(differenceWith(chunk, Chunk.empty()), Chunk.empty()) + equals(differenceWith(chunk, chunk), Chunk.empty()) }) it("difference", () => { const curr = Chunk.make(1, 3, 5, 7, 9) - expect(Chunk.difference(Chunk.make(1, 2, 3, 4, 5), curr)).toEqual(Chunk.make(7, 9)) - expect(Chunk.difference(Chunk.empty(), curr)).toEqual(curr) - expect(Chunk.difference(curr, Chunk.empty())).toEqual(Chunk.empty()) - expect(Chunk.difference(curr, curr)).toEqual(Chunk.empty()) + equals(Chunk.difference(Chunk.make(1, 2, 3, 4, 5), curr), Chunk.make(7, 9)) + equals(Chunk.difference(Chunk.empty(), curr), curr) + equals(Chunk.difference(curr, Chunk.empty()), Chunk.empty()) + equals(Chunk.difference(curr, curr), Chunk.empty()) }) }) diff --git a/packages/effect/test/Config.test.ts b/packages/effect/test/Config.test.ts index 0b01bc82509..008b58e4b27 100644 --- a/packages/effect/test/Config.test.ts +++ b/packages/effect/test/Config.test.ts @@ -1,55 +1,48 @@ -import * as Chunk from "effect/Chunk" -import * as Config from "effect/Config" -import * as ConfigError from "effect/ConfigError" -import * as ConfigProvider from "effect/ConfigProvider" -import * as Duration from "effect/Duration" -import * as Effect from "effect/Effect" -import * as Equal from "effect/Equal" -import * as Exit from "effect/Exit" -import { pipe } from "effect/Function" -import * as HashSet from "effect/HashSet" -import * as LogLevel from "effect/LogLevel" -import * as Option from "effect/Option" -import * as Redacted from "effect/Redacted" -import * as Secret from "effect/Secret" -import { assert, describe, expect, it } from "vitest" - -const assertFailure = ( +import { + Cause, + Chunk, + Config, + ConfigError, + ConfigProvider, + Duration, + Effect, + Equal, + HashSet, + LogLevel, + Option, + pipe, + Redacted, + Secret +} from "effect" +import { assertFailure, assertSuccess, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" + +const assertConfigError = ( config: Config.Config, map: ReadonlyArray, error: ConfigError.ConfigError ) => { const configProvider = ConfigProvider.fromMap(new Map(map)) - const result = Effect.runSync(Effect.exit(configProvider.load(config))) - expect(result).toStrictEqual(Exit.fail(error)) + const result = Effect.runSyncExit(configProvider.load(config)) + assertFailure(result, Cause.fail(error)) } -const assertSuccess = ( +const assertConfig = ( config: Config.Config, map: ReadonlyArray, a: A ) => { const configProvider = ConfigProvider.fromMap(new Map(map)) - const result = Effect.runSync(Effect.exit(configProvider.load(config))) - expect(result).toStrictEqual(Exit.succeed(a)) -} - -const assertEqualSuccess = ( - config: Config.Config, - map: ReadonlyArray, - a: A -) => { - const configProvider = ConfigProvider.fromMap(new Map(map)) - const result = Effect.runSync(Effect.exit(configProvider.load(config))) - expect(Equal.equals(Exit.succeed(a), result)).toBe(true) + const result = Effect.runSyncExit(configProvider.load(config)) + assertSuccess(result, a) } describe("Config", () => { describe("boolean", () => { it("name = undefined", () => { const config = Config.array(Config.boolean(), "ITEMS") - assertSuccess(config, [["ITEMS", "true"]], [true]) - assertFailure( + assertConfig(config, [["ITEMS", "true"]], [true]) + assertConfigError( config, [["ITEMS", "value"]], ConfigError.InvalidData(["ITEMS"], "Expected a boolean value but received value") @@ -58,17 +51,17 @@ describe("Config", () => { it("name != undefined", () => { const config = Config.boolean("BOOL") - assertSuccess(config, [["BOOL", "true"]], true) - assertSuccess(config, [["BOOL", "yes"]], true) - assertSuccess(config, [["BOOL", "on"]], true) - assertSuccess(config, [["BOOL", "1"]], true) - assertSuccess(config, [["BOOL", "false"]], false) - assertSuccess(config, [["BOOL", "no"]], false) - assertSuccess(config, [["BOOL", "off"]], false) - assertSuccess(config, [["BOOL", "0"]], false) - - assertFailure(config, [], ConfigError.MissingData(["BOOL"], "Expected BOOL to exist in the provided map")) - assertFailure( + assertConfig(config, [["BOOL", "true"]], true) + assertConfig(config, [["BOOL", "yes"]], true) + assertConfig(config, [["BOOL", "on"]], true) + assertConfig(config, [["BOOL", "1"]], true) + assertConfig(config, [["BOOL", "false"]], false) + assertConfig(config, [["BOOL", "no"]], false) + assertConfig(config, [["BOOL", "off"]], false) + assertConfig(config, [["BOOL", "0"]], false) + + assertConfigError(config, [], ConfigError.MissingData(["BOOL"], "Expected BOOL to exist in the provided map")) + assertConfigError( config, [["BOOL", "value"]], ConfigError.InvalidData(["BOOL"], "Expected a boolean value but received value") @@ -79,17 +72,17 @@ describe("Config", () => { describe("url", () => { it("name != undefined", () => { const config = Config.url("WEBSITE_URL") - assertSuccess( + assertConfig( config, [["WEBSITE_URL", "https://effect.website/docs/introduction#what-is-effect"]], new URL("https://effect.website/docs/introduction#what-is-effect") ) - assertFailure( + assertConfigError( config, [["WEBSITE_URL", "abra-kadabra"]], ConfigError.InvalidData(["WEBSITE_URL"], "Expected an URL value but received abra-kadabra") ) - assertFailure( + assertConfigError( config, [], ConfigError.MissingData(["WEBSITE_URL"], "Expected WEBSITE_URL to exist in the provided map") @@ -100,15 +93,15 @@ describe("Config", () => { describe("nonEmptyString", () => { it("name = undefined", () => { const config = Config.array(Config.nonEmptyString(), "ITEMS") - assertSuccess(config, [["ITEMS", "foo"]], ["foo"]) - assertFailure(config, [["ITEMS", ""]], ConfigError.MissingData(["ITEMS"], "Expected a non-empty string")) + assertConfig(config, [["ITEMS", "foo"]], ["foo"]) + assertConfigError(config, [["ITEMS", ""]], ConfigError.MissingData(["ITEMS"], "Expected a non-empty string")) }) it("name != undefined", () => { const config = Config.nonEmptyString("NON_EMPTY_STRING") - assertSuccess(config, [["NON_EMPTY_STRING", "foo"]], "foo") - assertSuccess(config, [["NON_EMPTY_STRING", " "]], " ") - assertFailure( + assertConfig(config, [["NON_EMPTY_STRING", "foo"]], "foo") + assertConfig(config, [["NON_EMPTY_STRING", " "]], " ") + assertConfigError( config, [["NON_EMPTY_STRING", ""]], ConfigError.MissingData(["NON_EMPTY_STRING"], "Expected a non-empty string") @@ -119,13 +112,13 @@ describe("Config", () => { describe("number", () => { it("name = undefined", () => { const config = Config.array(Config.number(), "ITEMS") - assertSuccess(config, [["ITEMS", "1"]], [1]) - assertFailure( + assertConfig(config, [["ITEMS", "1"]], [1]) + assertConfigError( config, [["ITEMS", "123qq"]], ConfigError.InvalidData(["ITEMS"], "Expected a number value but received 123qq") ) - assertFailure( + assertConfigError( config, [["ITEMS", "value"]], ConfigError.InvalidData(["ITEMS"], "Expected a number value but received value") @@ -134,15 +127,15 @@ describe("Config", () => { it("name != undefined", () => { const config = Config.number("NUMBER") - assertSuccess(config, [["NUMBER", "1"]], 1) - assertSuccess(config, [["NUMBER", "1.2"]], 1.2) - assertSuccess(config, [["NUMBER", "-1"]], -1) - assertSuccess(config, [["NUMBER", "-1.2"]], -1.2) - assertSuccess(config, [["NUMBER", "0"]], 0) - assertSuccess(config, [["NUMBER", "-0"]], -0) - - assertFailure(config, [], ConfigError.MissingData(["NUMBER"], "Expected NUMBER to exist in the provided map")) - assertFailure( + assertConfig(config, [["NUMBER", "1"]], 1) + assertConfig(config, [["NUMBER", "1.2"]], 1.2) + assertConfig(config, [["NUMBER", "-1"]], -1) + assertConfig(config, [["NUMBER", "-1.2"]], -1.2) + assertConfig(config, [["NUMBER", "0"]], 0) + assertConfig(config, [["NUMBER", "-0"]], -0) + + assertConfigError(config, [], ConfigError.MissingData(["NUMBER"], "Expected NUMBER to exist in the provided map")) + assertConfigError( config, [["NUMBER", "value"]], ConfigError.InvalidData(["NUMBER"], "Expected a number value but received value") @@ -153,8 +146,8 @@ describe("Config", () => { describe("literal", () => { it("name = undefined", () => { const config = Config.array(Config.literal("a", "b")(), "ITEMS") - assertSuccess(config, [["ITEMS", "a"]], ["a"]) - assertFailure( + assertConfig(config, [["ITEMS", "a"]], ["a"]) + assertConfigError( config, [["ITEMS", "value"]], ConfigError.InvalidData(["ITEMS"], "Expected one of (a, b) but received value") @@ -163,15 +156,19 @@ describe("Config", () => { it("name != undefined", () => { const config = Config.literal("a", 0, -0.3, BigInt(5), false, null)("LITERAL") - assertSuccess(config, [["LITERAL", "a"]], "a") - assertSuccess(config, [["LITERAL", "0"]], 0) - assertSuccess(config, [["LITERAL", "-0.3"]], -0.3) - assertSuccess(config, [["LITERAL", "5"]], BigInt(5)) - assertSuccess(config, [["LITERAL", "false"]], false) - assertSuccess(config, [["LITERAL", "null"]], null) - - assertFailure(config, [], ConfigError.MissingData(["LITERAL"], "Expected LITERAL to exist in the provided map")) - assertFailure( + assertConfig(config, [["LITERAL", "a"]], "a") + assertConfig(config, [["LITERAL", "0"]], 0) + assertConfig(config, [["LITERAL", "-0.3"]], -0.3) + assertConfig(config, [["LITERAL", "5"]], BigInt(5)) + assertConfig(config, [["LITERAL", "false"]], false) + assertConfig(config, [["LITERAL", "null"]], null) + + assertConfigError( + config, + [], + ConfigError.MissingData(["LITERAL"], "Expected LITERAL to exist in the provided map") + ) + assertConfigError( config, [["LITERAL", "value"]], ConfigError.InvalidData(["LITERAL"], "Expected one of (a, 0, -0.3, 5, false, null) but received value") @@ -182,8 +179,8 @@ describe("Config", () => { describe("date", () => { it("name = undefined", () => { const config = Config.date() - assertSuccess(config, [["", "0"]], new Date(Date.parse("0"))) - assertFailure( + assertConfig(config, [["", "0"]], new Date(Date.parse("0"))) + assertConfigError( config, [["", "value"]], ConfigError.InvalidData([], "Expected a Date value but received value") @@ -192,10 +189,10 @@ describe("Config", () => { it("name != undefined", () => { const config = Config.date("DATE") - assertSuccess(config, [["DATE", "0"]], new Date(Date.parse("0"))) + assertConfig(config, [["DATE", "0"]], new Date(Date.parse("0"))) - assertFailure(config, [], ConfigError.MissingData(["DATE"], "Expected DATE to exist in the provided map")) - assertFailure( + assertConfigError(config, [], ConfigError.MissingData(["DATE"], "Expected DATE to exist in the provided map")) + assertConfigError( config, [["DATE", "value"]], ConfigError.InvalidData(["DATE"], "Expected a Date value but received value") @@ -205,7 +202,7 @@ describe("Config", () => { it("fail", () => { const config = Config.fail("failure message") - assertFailure(config, [], ConfigError.MissingData([], "failure message")) + assertConfigError(config, [], ConfigError.MissingData([], "failure message")) }) it("mapAttempt", () => { @@ -219,33 +216,33 @@ describe("Config", () => { } return n })) - assertSuccess(config, [["STRING", "1"]], 1) - assertFailure( + assertConfig(config, [["STRING", "1"]], 1) + assertConfigError( config, [["STRING", "value"]], ConfigError.InvalidData(["STRING"], "invalid number") ) - assertFailure( + assertConfigError( config, [["STRING", "-1"]], ConfigError.InvalidData(["STRING"], "invalid negative number") ) - assertFailure(config, [], ConfigError.MissingData(["STRING"], "Expected STRING to exist in the provided map")) + assertConfigError(config, [], ConfigError.MissingData(["STRING"], "Expected STRING to exist in the provided map")) }) describe("logLevel", () => { it("name = undefined", () => { const config = Config.logLevel() - assertSuccess(config, [["", "DEBUG"]], LogLevel.Debug) + assertConfig(config, [["", "DEBUG"]], LogLevel.Debug) - assertFailure(config, [["", "-"]], ConfigError.InvalidData([], "Expected a log level but received -")) + assertConfigError(config, [["", "-"]], ConfigError.InvalidData([], "Expected a log level but received -")) }) it("name != undefined", () => { const config = Config.logLevel("LOG_LEVEL") - assertSuccess(config, [["LOG_LEVEL", "DEBUG"]], LogLevel.Debug) + assertConfig(config, [["LOG_LEVEL", "DEBUG"]], LogLevel.Debug) - assertFailure( + assertConfigError( config, [["LOG_LEVEL", "-"]], ConfigError.InvalidData(["LOG_LEVEL"], "Expected a log level but received -") @@ -256,16 +253,16 @@ describe("Config", () => { describe("duration", () => { it("name = undefined", () => { const config = Config.duration() - assertSuccess(config, [["", "10 seconds"]], Duration.decode("10 seconds")) + assertConfig(config, [["", "10 seconds"]], Duration.decode("10 seconds")) - assertFailure(config, [["", "-"]], ConfigError.InvalidData([], "Expected a duration but received -")) + assertConfigError(config, [["", "-"]], ConfigError.InvalidData([], "Expected a duration but received -")) }) it("name != undefined", () => { const config = Config.duration("DURATION") - assertSuccess(config, [["DURATION", "10 seconds"]], Duration.decode("10 seconds")) + assertConfig(config, [["DURATION", "10 seconds"]], Duration.decode("10 seconds")) - assertFailure( + assertConfigError( config, [["DURATION", "-"]], ConfigError.InvalidData(["DURATION"], "Expected a duration but received -") @@ -281,9 +278,9 @@ describe("Config", () => { validation: (n) => n >= 0 }) ) - assertSuccess(flat, [["NUMBER", "1"]], 1) - assertSuccess(flat, [["NUMBER", "1.2"]], 1.2) - assertFailure( + assertConfig(flat, [["NUMBER", "1"]], 1) + assertConfig(flat, [["NUMBER", "1.2"]], 1.2) + assertConfigError( flat, [["NUMBER", "-1"]], ConfigError.InvalidData(["NUMBER"], "a positive number") @@ -292,18 +289,18 @@ describe("Config", () => { const nested = flat.pipe( Config.nested("NESTED1") ) - assertSuccess(nested, [["NESTED1.NUMBER", "1"]], 1) - assertSuccess(nested, [["NESTED1.NUMBER", "1.2"]], 1.2) - assertFailure( + assertConfig(nested, [["NESTED1.NUMBER", "1"]], 1) + assertConfig(nested, [["NESTED1.NUMBER", "1.2"]], 1.2) + assertConfigError( nested, [["NESTED1.NUMBER", "-1"]], ConfigError.InvalidData(["NESTED1", "NUMBER"], "a positive number") ) const doubleNested = nested.pipe(Config.nested("NESTED2")) - assertSuccess(doubleNested, [["NESTED2.NESTED1.NUMBER", "1"]], 1) - assertSuccess(doubleNested, [["NESTED2.NESTED1.NUMBER", "1.2"]], 1.2) - assertFailure( + assertConfig(doubleNested, [["NESTED2.NESTED1.NUMBER", "1"]], 1) + assertConfig(doubleNested, [["NESTED2.NESTED1.NUMBER", "1.2"]], 1.2) + assertConfigError( doubleNested, [["NESTED2.NESTED1.NUMBER", "-1"]], ConfigError.InvalidData(["NESTED2", "NESTED1", "NUMBER"], "a positive number") @@ -318,9 +315,9 @@ describe("Config", () => { Config.withDefault(0) ) // available data - assertSuccess(config, [["key", "1"]], 1) + assertConfig(config, [["key", "1"]], 1) // missing data - assertSuccess(config, [], 0) + assertConfig(config, [], 0) }) it("does not recover from other errors", () => { @@ -328,14 +325,14 @@ describe("Config", () => { Config.integer("key"), Config.withDefault(0) ) - assertSuccess(config, [["key", "1"]], 1) - assertFailure( + assertConfig(config, [["key", "1"]], 1) + assertConfigError( config, [["key", "1.2"]], // available data but not an integer ConfigError.InvalidData(["key"], "Expected an integer value but received 1.2") ) - assertFailure( + assertConfigError( config, [["key", "value"]], // available data but not an integer @@ -349,9 +346,9 @@ describe("Config", () => { Config.zip(Config.integer("key2")), Config.withDefault([0, 0]) ) - assertSuccess(config, [], [0, 0]) - assertSuccess(config, [["key1", "1"], ["key2", "2"]], [1, 2]) - assertFailure( + assertConfig(config, [], [0, 0]) + assertConfig(config, [["key1", "1"], ["key2", "2"]], [1, 2]) + assertConfigError( config, [["key2", "value"]], ConfigError.And( @@ -367,10 +364,10 @@ describe("Config", () => { Config.orElse(() => Config.integer("key2")), Config.withDefault(0) ) - assertSuccess(config, [], 0) - assertSuccess(config, [["key1", "1"]], 1) - assertSuccess(config, [["key2", "2"]], 2) - assertFailure( + assertConfig(config, [], 0) + assertConfig(config, [["key1", "1"]], 1) + assertConfig(config, [["key2", "2"]], 2) + assertConfigError( config, [["key2", "value"]], ConfigError.Or( @@ -384,13 +381,13 @@ describe("Config", () => { describe("option", () => { it("recovers from missing data error", () => { const config = Config.option(Config.integer("key")) - assertSuccess(config, [], Option.none()) - assertSuccess(config, [["key", "1"]], Option.some(1)) + assertConfig(config, [], Option.none()) + assertConfig(config, [["key", "1"]], Option.some(1)) }) it("does not recover from other errors", () => { const config = Config.option(Config.integer("key")) - assertFailure( + assertConfigError( config, [["key", "value"]], ConfigError.InvalidData(["key"], "Expected an integer value but received value") @@ -403,8 +400,8 @@ describe("Config", () => { Config.zip(Config.integer("key2")), Config.option ) - assertSuccess(config, [["key1", "1"], ["key2", "2"]], Option.some([1, 2])) - assertFailure( + assertConfig(config, [["key1", "1"], ["key2", "2"]], Option.some([1, 2])) + assertConfigError( config, [["key1", "value"]], ConfigError.And( @@ -412,7 +409,7 @@ describe("Config", () => { ConfigError.MissingData(["key2"], "Expected key2 to exist in the provided map") ) ) - assertFailure( + assertConfigError( config, [["key2", "value"]], ConfigError.And( @@ -428,9 +425,9 @@ describe("Config", () => { Config.orElse(() => Config.integer("key2")), Config.option ) - assertSuccess(config, [["key1", "1"]], Option.some(1)) - assertSuccess(config, [["key1", "value"], ["key2", "2"]], Option.some(2)) - assertFailure( + assertConfig(config, [["key1", "1"]], Option.some(1)) + assertConfig(config, [["key1", "value"], ["key2", "2"]], Option.some(2)) + assertConfigError( config, [["key2", "value"]], ConfigError.Or( @@ -466,7 +463,7 @@ describe("Config", () => { key2: Config.string("key2") } }) - assertSuccess(config, [["key1", "123"], ["items", "1,2,3"], ["option", "123"], ["secret", "sauce"], [ + assertConfig(config, [["key1", "123"], ["items", "1,2,3"], ["option", "123"], ["secret", "sauce"], [ "key2", "value" ]], { @@ -478,7 +475,7 @@ describe("Config", () => { key2: "value" } }) - assertFailure( + assertConfigError( config, [["key1", "123"], ["items", "1,value,3"], ["option", "123"], ["secret", "sauce"], ["key2", "value"]], ConfigError.InvalidData(["items"], "Expected an integer value but received value") @@ -488,30 +485,30 @@ describe("Config", () => { it("sync", () => { const config = Config.sync(() => 1) - assertSuccess(config, [], 1) + assertConfig(config, [], 1) }) describe("all", () => { describe("tuple", () => { it("length = 0", () => { const config = Config.all([]) - assertSuccess(config, [], []) + assertConfig(config, [], []) }) it("length = 1", () => { const config = Config.all([Config.number("NUMBER")]) - assertSuccess(config, [["NUMBER", "1"]], [1]) + assertConfig(config, [["NUMBER", "1"]], [1]) }) it("length > 1", () => { const config = Config.all([Config.number("NUMBER"), Config.boolean("BOOL")]) - assertSuccess(config, [["NUMBER", "1"], ["BOOL", "true"]], [1, true]) - assertFailure( + assertConfig(config, [["NUMBER", "1"], ["BOOL", "true"]], [1, true]) + assertConfigError( config, [["NUMBER", "value"], ["BOOL", "true"]], ConfigError.InvalidData(["NUMBER"], "Expected a number value but received value") ) - assertFailure( + assertConfigError( config, [["NUMBER", "1"], ["BOOL", "value"]], ConfigError.InvalidData(["BOOL"], "Expected a boolean value but received value") @@ -522,13 +519,13 @@ describe("Config", () => { it("iterable", () => { const set = new Set([Config.number("NUMBER"), Config.boolean("BOOL")]) const config = Config.all(set) - assertSuccess(config, [["NUMBER", "1"], ["BOOL", "true"]], [1, true]) - assertFailure( + assertConfig(config, [["NUMBER", "1"], ["BOOL", "true"]], [1, true]) + assertConfigError( config, [["NUMBER", "value"], ["BOOL", "true"]], ConfigError.InvalidData(["NUMBER"], "Expected a number value but received value") ) - assertFailure( + assertConfigError( config, [["NUMBER", "1"], ["BOOL", "value"]], ConfigError.InvalidData(["BOOL"], "Expected a boolean value but received value") @@ -539,17 +536,17 @@ describe("Config", () => { describe("Config.redacted", () => { it("name = undefined", () => { const config = Config.array(Config.redacted(), "ITEMS") - assertSuccess(config, [["ITEMS", "a"]], [Redacted.make("a")]) + assertConfig(config, [["ITEMS", "a"]], [Redacted.make("a")]) }) it("name != undefined", () => { const config = Config.redacted("SECRET") - assertEqualSuccess(config, [["SECRET", "a"]], Redacted.make("a")) + assertConfig(config, [["SECRET", "a"]], Redacted.make("a")) }) it("can wrap generic Config", () => { const config = Config.redacted(Config.integer("NUM")) - assertEqualSuccess(config, [["NUM", "2"]], Redacted.make(2)) + assertConfig(config, [["NUM", "2"]], Redacted.make(2)) }) }) @@ -557,40 +554,40 @@ describe("Config", () => { describe("Config.secret", () => { it("name = undefined", () => { const config = Config.array(Config.secret(), "ITEMS") - assertSuccess(config, [["ITEMS", "a"]], [Secret.fromString("a")]) + assertConfig(config, [["ITEMS", "a"]], [Secret.fromString("a")]) }) it("name != undefined", () => { const config = Config.secret("SECRET") - assertEqualSuccess(config, [["SECRET", "a"]], Secret.fromString("a")) + assertConfig(config, [["SECRET", "a"]], Secret.fromString("a")) }) }) it("chunk constructor", () => { const secret = Secret.fromIterable(Chunk.fromIterable("secret".split(""))) - assert.isTrue(Equal.equals(secret, Secret.fromString("secret"))) + assertTrue(Equal.equals(secret, Secret.fromString("secret"))) }) it("value", () => { const secret = Secret.fromIterable(Chunk.fromIterable("secret".split(""))) const value = Secret.value(secret) - assert.strictEqual(value, "secret") + strictEqual(value, "secret") }) it("toString", () => { const secret = Secret.fromString("secret") - assert.strictEqual(`${secret}`, "Secret()") + strictEqual(`${secret}`, "Secret()") }) it("toJSON", () => { const secret = Secret.fromString("secret") - assert.strictEqual(JSON.stringify(secret), "\"\"") + strictEqual(JSON.stringify(secret), "\"\"") }) it("wipe", () => { const secret = Secret.fromString("secret") Secret.unsafeWipe(secret) - assert.isTrue( + assertTrue( Equal.equals( Secret.value(secret), Array.from({ length: "secret".length }, () => String.fromCharCode(0)).join("") @@ -601,18 +598,18 @@ describe("Config", () => { it("withDescription", () => { const config = Config.number("NUMBER").pipe(Config.withDescription("my description")) - expect("description" in config).toBe(true) + assertTrue("description" in config) }) describe("hashSet", () => { it("name = undefined", () => { const config = Config.array(Config.hashSet(Config.string()), "ITEMS") - assertSuccess(config, [["ITEMS", "a,b,c"]], [HashSet.make("a", "b", "c")]) + assertConfig(config, [["ITEMS", "a,b,c"]], [HashSet.make("a", "b", "c")]) }) it("name != undefined", () => { const config = Config.hashSet(Config.string(), "HASH_SET") - assertSuccess(config, [["HASH_SET", "a,b,c"]], HashSet.make("a", "b", "c")) + assertConfig(config, [["HASH_SET", "a,b,c"]], HashSet.make("a", "b", "c")) }) }) @@ -621,7 +618,7 @@ describe("Config", () => { Config.string("STRING"), ConfigProvider.fromMap(new Map([["STRING", "value"]])) )) - assert.strictEqual(result, "value") + strictEqual(result, "value") }) it("array nested", () => { @@ -633,6 +630,6 @@ describe("Config", () => { ), Effect.runSync ) - assert.deepStrictEqual(result, [1, 2, 3]) + deepStrictEqual(result, [1, 2, 3]) }) }) diff --git a/packages/effect/test/ConfigProvider.test.ts b/packages/effect/test/ConfigProvider.test.ts index d8ba6d66ff2..5c0dac4b434 100644 --- a/packages/effect/test/ConfigProvider.test.ts +++ b/packages/effect/test/ConfigProvider.test.ts @@ -1,19 +1,22 @@ -import * as Cause from "effect/Cause" -import * as Chunk from "effect/Chunk" -import * as Config from "effect/Config" -import * as ConfigError from "effect/ConfigError" -import * as ConfigProvider from "effect/ConfigProvider" -import * as Effect from "effect/Effect" -import * as Either from "effect/Either" -import * as Equal from "effect/Equal" -import * as Exit from "effect/Exit" -import * as HashMap from "effect/HashMap" -import * as HashSet from "effect/HashSet" -import * as LogLevel from "effect/LogLevel" -import * as Option from "effect/Option" -import * as Secret from "effect/Secret" +import { + Cause, + Chunk, + Config, + ConfigError, + ConfigProvider, + Effect, + Either, + Equal, + Exit, + HashMap, + HashSet, + LogLevel, + Option, + Secret +} from "effect" +import { assertNone, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe, expect } from "vitest" +import { describe } from "vitest" interface HostPort { readonly host: string @@ -89,24 +92,24 @@ const provider = (map: Map): ConfigProvider.ConfigProvider => { describe("ConfigProvider", () => { it.effect("flat atoms", () => - Effect.gen(function*($) { + Effect.gen(function*() { const map = new Map([["host", "localhost"], ["port", "8080"]]) - const result = yield* $(provider(map).load(hostPortConfig)) - assert.deepStrictEqual(result, { + const result = yield* provider(map).load(hostPortConfig) + deepStrictEqual(result, { host: "localhost", port: 8080 }) })) it.effect("nested atoms", () => - Effect.gen(function*($) { + Effect.gen(function*() { const map = new Map([ ["hostPort.host", "localhost"], ["hostPort.port", "8080"], ["timeout", "1000"] ]) - const result = yield* $(provider(map).load(serviceConfigConfig)) - assert.deepStrictEqual(result, { + const result = yield* provider(map).load(serviceConfigConfig) + deepStrictEqual(result, { hostPort: { host: "localhost", port: 8080 @@ -116,32 +119,32 @@ describe("ConfigProvider", () => { })) it.effect("top-level list with same number of elements per key", () => - Effect.gen(function*($) { + Effect.gen(function*() { const map = new Map([ ["hostPorts.host", "localhost,localhost,localhost"], ["hostPorts.port", "8080,8080,8080"] ]) - const result = yield* $(provider(map).load(hostPortsConfig)) - assert.deepStrictEqual(result, { + const result = yield* provider(map).load(hostPortsConfig) + deepStrictEqual(result, { hostPorts: Array.from({ length: 3 }, () => ({ host: "localhost", port: 8080 })) }) })) it.effect("top-level missing list", () => - Effect.gen(function*($) { + Effect.gen(function*() { const map = new Map() - const result = yield* $(Effect.exit(provider(map).load(hostPortsConfig))) - assert.isTrue(Exit.isFailure(result)) + const result = yield* Effect.exit(provider(map).load(hostPortsConfig)) + assertTrue(Exit.isFailure(result)) })) it.effect("simple map", () => - Effect.gen(function*($) { + Effect.gen(function*() { const map = new Map([ ["name", "Sherlock Holmes"], ["address", "221B Baker Street"] ]) - const result = yield* $(provider(map).load(Config.hashMap(Config.string()))) - assert.deepStrictEqual( + const result = yield* provider(map).load(Config.hashMap(Config.string())) + deepStrictEqual( result, HashMap.make( ["name", "Sherlock Holmes"], @@ -151,49 +154,49 @@ describe("ConfigProvider", () => { })) it.effect("top-level lists with multi-character sequence delimiters", () => - Effect.gen(function*($) { + Effect.gen(function*() { const map = new Map([ ["hostPorts.host", "localhost///localhost///localhost"], ["hostPorts.port", "8080///8080///8080"] ]) - const result = yield* $(ConfigProvider.fromMap(map, { seqDelim: "///" }).load(hostPortsConfig)) - assert.deepStrictEqual(result, { + const result = yield* ConfigProvider.fromMap(map, { seqDelim: "///" }).load(hostPortsConfig) + deepStrictEqual(result, { hostPorts: Array.from({ length: 3 }, () => ({ host: "localhost", port: 8080 })) }) })) it.effect("top-level lists with special regex multi-character sequence delimiter", () => - Effect.gen(function*($) { + Effect.gen(function*() { const map = new Map([ ["hostPorts.host", "localhost|||localhost|||localhost"], ["hostPorts.port", "8080|||8080|||8080"] ]) - const result = yield* $(ConfigProvider.fromMap(map, { seqDelim: "|||" }).load(hostPortsConfig)) - assert.deepStrictEqual(result, { + const result = yield* ConfigProvider.fromMap(map, { seqDelim: "|||" }).load(hostPortsConfig) + deepStrictEqual(result, { hostPorts: Array.from({ length: 3 }, () => ({ host: "localhost", port: 8080 })) }) })) it.effect("top-level lists with special regex character sequence delimiter", () => - Effect.gen(function*($) { + Effect.gen(function*() { const map = new Map([ ["hostPorts.host", "localhost*localhost*localhost"], ["hostPorts.port", "8080*8080*8080"] ]) - const result = yield* $(ConfigProvider.fromMap(map, { seqDelim: "*" }).load(hostPortsConfig)) - assert.deepStrictEqual(result, { + const result = yield* ConfigProvider.fromMap(map, { seqDelim: "*" }).load(hostPortsConfig) + deepStrictEqual(result, { hostPorts: Array.from({ length: 3 }, () => ({ host: "localhost", port: 8080 })) }) })) it.effect("top-level list with different number of elements per key fails", () => - Effect.gen(function*($) { + Effect.gen(function*() { const map = new Map([ ["hostPorts.host", "localhost"], ["hostPorts.port", "8080,8080,8080"] ]) - const result = yield* $(Effect.exit(provider(map).load(hostPortsConfig))) - assert.deepStrictEqual( + const result = yield* Effect.exit(provider(map).load(hostPortsConfig)) + deepStrictEqual( result, Exit.fail( ConfigError.MissingData( @@ -205,7 +208,7 @@ describe("ConfigProvider", () => { })) it.effect("flat atoms of different types", () => - Effect.gen(function*($) { + Effect.gen(function*() { const map = new Map([ ["date", "2022-10-28"], ["open", "98.8"], @@ -214,8 +217,8 @@ describe("ConfigProvider", () => { ["high", "151.5"], ["volume", "100091990"] ]) - const result = yield* $(provider(map).load(stockDayConfig)) - assert.deepStrictEqual(result, { + const result = yield* provider(map).load(stockDayConfig) + deepStrictEqual(result, { date: new Date("2022-10-28"), open: 98.8, close: 150.0, @@ -226,7 +229,7 @@ describe("ConfigProvider", () => { })) it.effect("tables", () => - Effect.gen(function*($) { + Effect.gen(function*() { const map = new Map([ ["Effect.date", "2022-10-28"], ["Effect.open", "98.8"], @@ -235,8 +238,8 @@ describe("ConfigProvider", () => { ["Effect.high", "151.5"], ["Effect.volume", "100091990"] ]) - const result = yield* $(provider(map).load(snp500Config)) - assert.deepStrictEqual(result, { + const result = yield* provider(map).load(snp500Config) + deepStrictEqual(result, { stockDays: HashMap.make([ "Effect", { @@ -252,57 +255,57 @@ describe("ConfigProvider", () => { })) it.effect("empty tables", () => - Effect.gen(function*($) { - const result = yield* $(provider(new Map()).load(snp500Config)) - assert.deepStrictEqual(result, { stockDays: HashMap.empty() }) + Effect.gen(function*() { + const result = yield* provider(new Map()).load(snp500Config) + deepStrictEqual(result, { stockDays: HashMap.empty() }) })) it.effect("collection of atoms", () => - Effect.gen(function*($) { + Effect.gen(function*() { const map = new Map([ ["targets", "https://effect.website,https://github.com/Effect-TS"] ]) - const result = yield* $(provider(map).load(webScrapingTargetsConfig)) - assert.deepStrictEqual(result, { + const result = yield* provider(map).load(webScrapingTargetsConfig) + deepStrictEqual(result, { targets: HashSet.make("https://effect.website", "https://github.com/Effect-TS") }) })) it.effect("collection of atoms falls back to default", () => - Effect.gen(function*($) { + Effect.gen(function*() { const map = new Map() - const result = yield* $(provider(map).load(webScrapingTargetsConfigWithDefault)) - assert.deepStrictEqual(result, { + const result = yield* provider(map).load(webScrapingTargetsConfigWithDefault) + deepStrictEqual(result, { targets: Chunk.make("https://effect.website2", "https://github.com/Effect-TS2") }) })) it.effect("indexed - simple", () => - Effect.gen(function*($) { + Effect.gen(function*() { const config = Config.array(Config.integer(), "id") const map = new Map([ ["id[0]", "1"], ["id[1]", "2"], ["id[2]", "3"] ]) - const result = yield* $(ConfigProvider.fromMap(map).load(config)) - expect(result).toEqual([1, 2, 3]) + const result = yield* ConfigProvider.fromMap(map).load(config) + deepStrictEqual(result, [1, 2, 3]) })) it.effect("indexed sequence - simple with list values", () => - Effect.gen(function*($) { + Effect.gen(function*() { const config = Config.array(Config.array(Config.integer()), "id") const map = new Map([ ["id[0]", "1, 2"], ["id[1]", "3, 4"], ["id[2]", "5, 6"] ]) - const result = yield* $(ConfigProvider.fromMap(map).load(config)) - expect(result).toEqual([[1, 2], [3, 4], [5, 6]]) + const result = yield* ConfigProvider.fromMap(map).load(config) + deepStrictEqual(result, [[1, 2], [3, 4], [5, 6]]) })) it.effect("indexed sequence - one product type", () => - Effect.gen(function*($) { + Effect.gen(function*() { const config = Config.array( Config.all({ age: Config.integer("age"), @@ -314,12 +317,12 @@ describe("ConfigProvider", () => { ["employees[0].age", "1"], ["employees[0].id", "1"] ]) - const result = yield* $(ConfigProvider.fromMap(map).load(config)) - expect(result).toEqual([{ age: 1, id: 1 }]) + const result = yield* ConfigProvider.fromMap(map).load(config) + deepStrictEqual(result, [{ age: 1, id: 1 }]) })) it.effect("indexed sequence - multiple product types", () => - Effect.gen(function*($) { + Effect.gen(function*() { const config = Config.array( Config.all({ age: Config.integer("age"), @@ -333,12 +336,12 @@ describe("ConfigProvider", () => { ["employees[1].age", "3"], ["employees[1].id", "4"] ]) - const result = yield* $(ConfigProvider.fromMap(map).load(config)) - expect(result).toEqual([{ age: 1, id: 2 }, { age: 3, id: 4 }]) + const result = yield* ConfigProvider.fromMap(map).load(config) + deepStrictEqual(result, [{ age: 1, id: 2 }, { age: 3, id: 4 }]) })) it.effect("indexed sequence - multiple product types with missing fields", () => - Effect.gen(function*($) { + Effect.gen(function*() { const config = Config.array( Config.all({ age: Config.integer("age"), @@ -352,10 +355,8 @@ describe("ConfigProvider", () => { ["employees[1].age", "3"], ["employees[1]", "4"] ]) - const result = yield* $( - Effect.exit(ConfigProvider.fromMap(map).load(config)) - ) - assert.isTrue( + const result = yield* Effect.exit(ConfigProvider.fromMap(map).load(config)) + assertTrue( Exit.isFailure(result) && Cause.isFailType(result.effect_instruction_i0) && ConfigError.isMissingData(result.effect_instruction_i0.error) && @@ -369,7 +370,7 @@ describe("ConfigProvider", () => { })) it.effect("indexed sequence - multiple product types with optional fields", () => - Effect.gen(function*($) { + Effect.gen(function*() { const config = Config.array( Config.all({ age: Config.option(Config.integer("age")), @@ -382,12 +383,12 @@ describe("ConfigProvider", () => { ["employees[0].id", "2"], ["employees[1].id", "4"] ]) - const result = yield* $(ConfigProvider.fromMap(map).load(config)) - expect(result).toEqual([{ age: Option.some(1), id: 2 }, { age: Option.none(), id: 4 }]) + const result = yield* ConfigProvider.fromMap(map).load(config) + deepStrictEqual(result, [{ age: Option.some(1), id: 2 }, { age: Option.none(), id: 4 }]) })) it.effect("indexed sequence - multiple product types with sequence fields", () => - Effect.gen(function*($) { + Effect.gen(function*() { const config = Config.array( Config.all({ refunds: Config.array(Config.integer(), "refunds"), @@ -401,12 +402,12 @@ describe("ConfigProvider", () => { ["employees[1].id", "1"], ["employees[1].refunds", "4,5,6"] ]) - const result = yield* $(ConfigProvider.fromMap(map).load(config)) - expect(result).toEqual([{ refunds: [1, 2, 3], id: 0 }, { refunds: [4, 5, 6], id: 1 }]) + const result = yield* ConfigProvider.fromMap(map).load(config) + deepStrictEqual(result, [{ refunds: [1, 2, 3], id: 0 }, { refunds: [4, 5, 6], id: 1 }]) })) it.effect("indexed sequence - product type of indexed sequences with reusable config", () => - Effect.gen(function*($) { + Effect.gen(function*() { const idAndAge = Config.all({ id: Config.integer("id"), age: Config.integer("age") @@ -425,15 +426,15 @@ describe("ConfigProvider", () => { ["students[0].age", "2"], ["students[1].age", "3"] ]) - const result = yield* $(ConfigProvider.fromMap(map).load(config)) - expect(result).toEqual({ + const result = yield* ConfigProvider.fromMap(map).load(config) + deepStrictEqual(result, { employees: [{ id: 0, age: 10 }, { id: 1, age: 11 }], students: [{ id: 20, age: 2 }, { id: 30, age: 3 }] }) })) it.effect("indexed sequence - map of indexed sequences", () => - Effect.gen(function*($) { + Effect.gen(function*() { const employee = Config.all({ age: Config.integer("age"), id: Config.integer("id") @@ -449,16 +450,16 @@ describe("ConfigProvider", () => { ["departments.department2.employees[1].age", "20"], ["departments.department2.employees[1].id", "1"] ]) - const result = yield* $(ConfigProvider.fromMap(map).load(config)) + const result = yield* ConfigProvider.fromMap(map).load(config) const expectedEmployees = [{ age: 10, id: 0 }, { age: 20, id: 1 }] - expect(Array.from(result)).toEqual([ + deepStrictEqual(Array.from(result), [ ["department1", expectedEmployees], ["department2", expectedEmployees] ]) })) it.effect("indexed sequence - map", () => - Effect.gen(function*($) { + Effect.gen(function*() { const employee = Config.hashMap(Config.integer(), "details") const config = Config.array(employee, "employees") const map = new Map([ @@ -467,15 +468,15 @@ describe("ConfigProvider", () => { ["employees[1].details.age", "20"], ["employees[1].details.id", "1"] ]) - const result = yield* $(ConfigProvider.fromMap(map).load(config)) - expect(result.map((table) => Array.from(table))).toEqual([ + const result = yield* ConfigProvider.fromMap(map).load(config) + deepStrictEqual(result.map((table) => Array.from(table)), [ [["age", 10], ["id", 0]], [["age", 20], ["id", 1]] ]) })) it.effect("indexed sequence - indexed sequences", () => - Effect.gen(function*($) { + Effect.gen(function*() { const employee = Config.all({ age: Config.integer("age"), id: Config.integer("id") @@ -492,13 +493,13 @@ describe("ConfigProvider", () => { ["departments[1].employees[1].age", "20"], ["departments[1].employees[1].id", "1"] ]) - const result = yield* $(ConfigProvider.fromMap(map).load(config)) + const result = yield* ConfigProvider.fromMap(map).load(config) const expectedEmployees = [{ age: 10, id: 0 }, { age: 20, id: 1 }] - expect(result).toEqual([expectedEmployees, expectedEmployees]) + deepStrictEqual(result, [expectedEmployees, expectedEmployees]) })) it.effect("indexed sequence - multiple product types nested", () => - Effect.gen(function*($) { + Effect.gen(function*() { const employee = Config.all({ age: Config.integer("age"), id: Config.integer("id") @@ -514,12 +515,12 @@ describe("ConfigProvider", () => { ConfigProvider.nested("child"), ConfigProvider.nested("parent") ) - const result = yield* $(provider.load(config)) - expect(result).toEqual([{ age: 1, id: 2 }, { age: 3, id: 4 }]) + const result = yield* provider.load(config) + deepStrictEqual(result, [{ age: 1, id: 2 }, { age: 3, id: 4 }]) })) it.effect("indexed sequence - multiple product types unnested", () => - Effect.gen(function*($) { + Effect.gen(function*() { const employee = Config.all({ age: Config.integer("age"), id: Config.integer("id") @@ -538,28 +539,28 @@ describe("ConfigProvider", () => { ConfigProvider.unnested("parent"), ConfigProvider.unnested("child") ) - const result = yield* $(provider.load(config)) - expect(result).toEqual([{ age: 1, id: 2 }, { age: 3, id: 4 }]) + const result = yield* provider.load(config) + deepStrictEqual(result, [{ age: 1, id: 2 }, { age: 3, id: 4 }]) })) it.effect("logLevel", () => - Effect.gen(function*($) { + Effect.gen(function*() { const config = Config.logLevel("level") const map = new Map([["level", "ERROR"]]) - const result = yield* $(ConfigProvider.fromMap(map).load(config)) - expect(result).toEqual(LogLevel.Error) + const result = yield* ConfigProvider.fromMap(map).load(config) + strictEqual(result, LogLevel.Error) })) it.effect("accessing a non-existent key fails", () => - Effect.gen(function*($) { + Effect.gen(function*() { const map = new Map([ ["k1.k3", "v"] ]) const config = Config.string("k2").pipe( Config.nested("k1") ) - const result = yield* $(Effect.exit(provider(map).load(config))) - assert.deepStrictEqual( + const result = yield* Effect.exit(provider(map).load(config)) + deepStrictEqual( result, Exit.fail( ConfigError.MissingData( @@ -571,64 +572,64 @@ describe("ConfigProvider", () => { })) it.effect("values are not split unless a sequence is expected", () => - Effect.gen(function*($) { + Effect.gen(function*() { const configProvider = ConfigProvider.fromMap(new Map([["greeting", "Hello, World!"]])) - const result = yield* $(configProvider.load(Config.string("greeting"))) - assert.strictEqual(result, "Hello, World!") + const result = yield* configProvider.load(Config.string("greeting")) + strictEqual(result, "Hello, World!") })) it.effect("constantCase", () => - Effect.gen(function*($) { + Effect.gen(function*() { const configProvider = ConfigProvider.fromMap(new Map([["CONSTANT_CASE", "value"]])).pipe( ConfigProvider.constantCase ) - const result = yield* $(configProvider.load(Config.string("constant.case"))) - assert.strictEqual(result, "value") + const result = yield* configProvider.load(Config.string("constant.case")) + strictEqual(result, "value") })) it.effect("mapInputPath", () => - Effect.gen(function*($) { + Effect.gen(function*() { const configProvider = ConfigProvider.fromMap(new Map([["KEY", "VALUE"]])).pipe( ConfigProvider.mapInputPath((path) => path.toUpperCase()) ) - const result = yield* $(configProvider.load(Config.string("key"))) - assert.strictEqual(result, "VALUE") + const result = yield* configProvider.load(Config.string("key")) + strictEqual(result, "VALUE") })) it.effect("kebabCase", () => - Effect.gen(function*($) { + Effect.gen(function*() { const configProvider = ConfigProvider.fromMap(new Map([["kebab-case", "value"]])).pipe( ConfigProvider.kebabCase ) - const result = yield* $(configProvider.load(Config.string("kebabCase"))) - assert.strictEqual(result, "value") + const result = yield* configProvider.load(Config.string("kebabCase")) + strictEqual(result, "value") })) it.effect("lowerCase", () => - Effect.gen(function*($) { + Effect.gen(function*() { const configProvider = ConfigProvider.fromMap(new Map([["lowercase", "value"]])).pipe( ConfigProvider.lowerCase ) - const result = yield* $(configProvider.load(Config.string("lowerCase"))) - assert.strictEqual(result, "value") + const result = yield* configProvider.load(Config.string("lowerCase")) + strictEqual(result, "value") })) it.effect("nested", () => - Effect.gen(function*($) { + Effect.gen(function*() { const configProvider1 = ConfigProvider.fromMap(new Map([["nested.key", "value"]])) const config1 = Config.string("key").pipe(Config.nested("nested")) const configProvider2 = ConfigProvider.fromMap(new Map([["nested.key", "value"]])).pipe( ConfigProvider.nested("nested") ) const config2 = Config.string("key") - const result1 = yield* $(configProvider1.load(config1)) - const result2 = yield* $(configProvider2.load(config2)) - assert.strictEqual(result1, "value") - assert.strictEqual(result2, "value") + const result1 = yield* configProvider1.load(config1) + const result2 = yield* configProvider2.load(config2) + strictEqual(result1, "value") + strictEqual(result2, "value") })) it.effect("nested - multiple layers of nesting", () => - Effect.gen(function*($) { + Effect.gen(function*() { const configProvider1 = ConfigProvider.fromMap(new Map([["parent.child.key", "value"]])) const config1 = Config.string("key").pipe( Config.nested("child"), @@ -639,14 +640,14 @@ describe("ConfigProvider", () => { ConfigProvider.nested("parent") ) const config2 = Config.string("key") - const result1 = yield* $(configProvider1.load(config1)) - const result2 = yield* $(configProvider2.load(config2)) - assert.strictEqual(result1, "value") - assert.strictEqual(result2, "value") + const result1 = yield* configProvider1.load(config1) + const result2 = yield* configProvider2.load(config2) + strictEqual(result1, "value") + strictEqual(result2, "value") })) it.effect("orElse - with flat data", () => - Effect.gen(function*($) { + Effect.gen(function*() { const configProvider = ConfigProvider.fromMap( new Map([ ["key1", "value1"], @@ -662,24 +663,27 @@ describe("ConfigProvider", () => { ) ) ) - const result1 = yield* $(configProvider.load(Config.string("key1"))) - const result2 = yield* $(configProvider.load(Config.string("key2"))) - const result31 = yield* $(configProvider.load(Config.option(Config.string("key3")))) - const result32 = yield* $(Effect.either(configProvider.load(Config.string("key3")))) - const result4 = yield* $(configProvider.load(Config.string("key4"))) + const result1 = yield* configProvider.load(Config.string("key1")) + const result2 = yield* configProvider.load(Config.string("key2")) + const result31 = yield* configProvider.load(Config.option(Config.string("key3"))) + const result32 = yield* Effect.either(configProvider.load(Config.string("key3"))) + const result4 = yield* configProvider.load(Config.string("key4")) - expect(result1).toBe("value1") - expect(result2).toBe("value2") - expect(result31).toEqual(Option.none()) - expect(result32).toEqual(Either.left(ConfigError.Or( - ConfigError.MissingData(["key3"], "Expected key3 to exist in the provided map"), - ConfigError.MissingData(["key3"], "Expected key3 to exist in the provided map") - ))) - expect(result4).toBe("value41") + strictEqual(result1, "value1") + strictEqual(result2, "value2") + assertNone(result31) + deepStrictEqual( + result32, + Either.left(ConfigError.Or( + ConfigError.MissingData(["key3"], "Expected key3 to exist in the provided map"), + ConfigError.MissingData(["key3"], "Expected key3 to exist in the provided map") + )) + ) + strictEqual(result4, "value41") })) it.effect("orElse - with indexed sequences", () => - Effect.gen(function*($) { + Effect.gen(function*() { const configProvider = ConfigProvider.fromMap( new Map([ ["parent1.child.employees[0].age", "1"], @@ -707,15 +711,15 @@ describe("ConfigProvider", () => { const config1 = arrayConfig.pipe(Config.nested("child"), Config.nested("parent1")) const config2 = arrayConfig.pipe(Config.nested("child"), Config.nested("parent2")) - const result1 = yield* $(configProvider.load(config1)) - const result2 = yield* $(configProvider.load(config2)) + const result1 = yield* configProvider.load(config1) + const result2 = yield* configProvider.load(config2) - expect(result1).toEqual([[1, 2], [3, 4], [5, 6]]) - expect(result2).toEqual([[11, 21], [31, 41]]) + deepStrictEqual(result1, [[1, 2], [3, 4], [5, 6]]) + deepStrictEqual(result2, [[11, 21], [31, 41]]) })) it.effect("orElse - with indexed sequences and each provider unnested", () => - Effect.gen(function*(_) { + Effect.gen(function*() { const configProvider = ConfigProvider.fromMap( new Map([ ["employees[0].age", "1"], @@ -747,26 +751,29 @@ describe("ConfigProvider", () => { const config2 = arrayConfig.pipe(Config.nested("child"), Config.nested("parent2")) const config3 = arrayConfig.pipe(Config.nested("child"), Config.nested("parent3")) - const result1 = yield* _(configProvider.load(config1)) - const result2 = yield* _(configProvider.load(config2)) - const result3 = yield* _(Effect.either(configProvider.load(config3))) + const result1 = yield* configProvider.load(config1) + const result2 = yield* configProvider.load(config2) + const result3 = yield* Effect.either(configProvider.load(config3)) - expect(result1).toEqual([[1, 2], [3, 4]]) - expect(result2).toEqual([[11, 21], [31, 41]]) - expect(result3).toEqual(Either.left(ConfigError.And( - ConfigError.MissingData( - ["parent3", "child", "employees"], - "Expected parent1 to be in path in ConfigProvider#unnested" - ), - ConfigError.MissingData( - ["parent3", "child", "employees"], - "Expected parent2 to be in path in ConfigProvider#unnested" - ) - ))) + deepStrictEqual(result1, [[1, 2], [3, 4]]) + deepStrictEqual(result2, [[11, 21], [31, 41]]) + deepStrictEqual( + result3, + Either.left(ConfigError.And( + ConfigError.MissingData( + ["parent3", "child", "employees"], + "Expected parent1 to be in path in ConfigProvider#unnested" + ), + ConfigError.MissingData( + ["parent3", "child", "employees"], + "Expected parent2 to be in path in ConfigProvider#unnested" + ) + )) + ) })) it.effect("orElse - with index sequences and combined provider unnested", () => - Effect.gen(function*(_) { + Effect.gen(function*() { const configProvider = ConfigProvider.fromMap( new Map([ ["employees[0].age", "1"], @@ -789,44 +796,44 @@ describe("ConfigProvider", () => { const arrayConfig = Config.array(product, "employees") const config = arrayConfig.pipe(Config.nested("child"), Config.nested("parent1")) - const result = yield* _(configProvider.load(config)) + const result = yield* configProvider.load(config) - expect(result).toEqual([[1, 2], [3, 4]]) + deepStrictEqual(result, [[1, 2], [3, 4]]) })) it.effect("secret", () => - Effect.gen(function*($) { + Effect.gen(function*() { const value = "Hello, World!" const configProvider = ConfigProvider.fromMap(new Map([["greeting", value]])) - const result = yield* $(configProvider.load(Config.secret("greeting"))) - assert.deepStrictEqual(result, Secret.make(value.split("").map((c) => c.charCodeAt(0)))) + const result = yield* configProvider.load(Config.secret("greeting")) + deepStrictEqual(result, Secret.make(value.split("").map((c) => c.charCodeAt(0)))) })) it.effect("snakeCase", () => - Effect.gen(function*($) { + Effect.gen(function*() { const configProvider = ConfigProvider.fromMap(new Map([["snake_case", "value"]])).pipe( ConfigProvider.snakeCase ) - const result = yield* $(configProvider.load(Config.string("snakeCase"))) - assert.strictEqual(result, "value") + const result = yield* configProvider.load(Config.string("snakeCase")) + strictEqual(result, "value") })) it.effect("unnested", () => - Effect.gen(function*($) { + Effect.gen(function*() { const configProvider1 = ConfigProvider.fromMap(new Map([["key", "value"]])) const config1 = Config.string("key") const configProvider2 = ConfigProvider.fromMap(new Map([["key", "value"]])).pipe( ConfigProvider.unnested("nested") ) const config2 = Config.string("key").pipe(Config.nested("nested")) - const result1 = yield* $(configProvider1.load(config1)) - const result2 = yield* $(configProvider2.load(config2)) - assert.strictEqual(result1, "value") - assert.strictEqual(result2, "value") + const result1 = yield* configProvider1.load(config1) + const result2 = yield* configProvider2.load(config2) + strictEqual(result1, "value") + strictEqual(result2, "value") })) it.effect("unnested - multiple layers of nesting", () => - Effect.gen(function*($) { + Effect.gen(function*() { const configProvider1 = ConfigProvider.fromMap(new Map([["key", "value"]])) const config1 = Config.string("key") const configProvider2 = ConfigProvider.fromMap(new Map([["key", "value"]])).pipe( @@ -837,37 +844,37 @@ describe("ConfigProvider", () => { Config.nested("child"), Config.nested("parent") ) - const result1 = yield* $(configProvider1.load(config1)) - const result2 = yield* $(configProvider2.load(config2)) - assert.strictEqual(result1, "value") - assert.strictEqual(result2, "value") + const result1 = yield* configProvider1.load(config1) + const result2 = yield* configProvider2.load(config2) + strictEqual(result1, "value") + strictEqual(result2, "value") })) it.effect("unnested - failure", () => - Effect.gen(function*($) { + Effect.gen(function*() { const configProvider = ConfigProvider.fromMap(new Map([["key", "value"]])).pipe( ConfigProvider.unnested("nested") ) const config = Config.string("key") - const result = yield* $(Effect.exit(configProvider.load(config))) + const result = yield* Effect.exit(configProvider.load(config)) const error = ConfigError.MissingData( ["key"], "Expected nested to be in path in ConfigProvider#unnested" ) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) it.effect("upperCase", () => - Effect.gen(function*($) { + Effect.gen(function*() { const configProvider = ConfigProvider.fromMap(new Map([["UPPERCASE", "value"]])).pipe( ConfigProvider.upperCase ) - const result = yield* $(configProvider.load(Config.string("upperCase"))) - assert.strictEqual(result, "value") + const result = yield* configProvider.load(Config.string("upperCase")) + strictEqual(result, "value") })) it.effect("within", () => - Effect.gen(function*($) { + Effect.gen(function*() { const configProvider = ConfigProvider.fromMap(new Map([["nesting1.key1", "value1"], ["nesting2.KEY2", "value2"]])) .pipe( ConfigProvider.within(["nesting2"], ConfigProvider.mapInputPath((s) => s.toUpperCase())) @@ -880,12 +887,12 @@ describe("ConfigProvider", () => { ) ) ) - const result = yield* $(configProvider.load(config)) - assert.deepStrictEqual(result, ["value1", "value2"]) + const result = yield* configProvider.load(config) + deepStrictEqual(result, ["value1", "value2"]) })) it.effect("within - multiple layers of nesting", () => - Effect.gen(function*($) { + Effect.gen(function*() { const configProvider = ConfigProvider.fromMap( new Map([["nesting1.key1", "value1"], ["nesting2.nesting3.KEY2", "value2"]]) ).pipe( @@ -900,41 +907,37 @@ describe("ConfigProvider", () => { ) ) ) - const result = yield* $(configProvider.load(config)) - assert.deepStrictEqual(result, ["value1", "value2"]) + const result = yield* configProvider.load(config) + deepStrictEqual(result, ["value1", "value2"]) })) it.effect("fromJson - should load configs from flat JSON", () => - Effect.gen(function*($) { - const result = yield* $( - ConfigProvider.fromJson({ - host: "localhost", - port: 8080 - }).load(hostPortConfig) - ) - assert.deepStrictEqual(result, { + Effect.gen(function*() { + const result = yield* ConfigProvider.fromJson({ + host: "localhost", + port: 8080 + }).load(hostPortConfig) + deepStrictEqual(result, { host: "localhost", port: 8080 }) })) it.effect("fromJson - should load configs from nested JSON", () => - Effect.gen(function*($) { - const result = yield* $( - ConfigProvider.fromJson({ - hostPorts: [{ - host: "localhost", - port: 8080 - }, { - host: "localhost", - port: 8080 - }, { - host: "localhost", - port: 8080 - }] - }).load(hostPortsConfig) - ) - assert.deepStrictEqual(result, { + Effect.gen(function*() { + const result = yield* ConfigProvider.fromJson({ + hostPorts: [{ + host: "localhost", + port: 8080 + }, { + host: "localhost", + port: 8080 + }, { + host: "localhost", + port: 8080 + }] + }).load(hostPortsConfig) + deepStrictEqual(result, { hostPorts: Array.from({ length: 3 }, () => ({ host: "localhost", port: 8080 })) }) })) diff --git a/packages/effect/test/Context.test.ts b/packages/effect/test/Context.test.ts index 4641921879e..54ee7f98d30 100644 --- a/packages/effect/test/Context.test.ts +++ b/packages/effect/test/Context.test.ts @@ -1,8 +1,6 @@ -import * as Context from "effect/Context" -import * as Differ from "effect/Differ" -import { pipe } from "effect/Function" -import * as O from "effect/Option" -import { assert, describe, expect, it } from "vitest" +import { Context, Differ, Option, pipe } from "effect" +import { assertFalse, assertNone, assertSome, assertTrue, deepStrictEqual, strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" interface A { a: number @@ -26,24 +24,59 @@ class E extends Context.Reference()("E", { }) {} describe("Context", () => { + it("error messages", () => { + throws(() => { + Context.unsafeGet(Context.empty(), A) + }, (e) => e instanceof Error && e.message.includes("Service not found: A")) + throws(() => { + Context.get(Context.empty(), A as never) + }, (e) => e instanceof Error && e.message.includes("Service not found: A")) + throws(() => { + Context.unsafeGet(Context.empty(), C) + }, (e) => e instanceof Error && e.message.includes("Service not found: C")) + throws(() => { + Context.get(Context.empty(), C as never) + }, (e) => e instanceof Error && e.message.includes("Service not found: C")) + if (typeof window === "undefined") { + throws( + () => { + Context.get(Context.empty(), C as never) + }, + (e) => { + return e instanceof Error && + new RegExp(/Service not found: C \(defined at (.*)Context.test.ts:18:19\)/).test(e.message) + } + ) + throws( + () => { + Context.get(Context.empty(), D as never) + }, + (e) => { + return e instanceof Error && + new RegExp(/Service not found: D \(defined at (.*)Context.test.ts:20:32\)/).test(e.message) + } + ) + } + }) + it("Tag.toJson()", () => { const json: any = A.toJSON() - expect(json["_id"]).toEqual("Tag") - expect(json["key"]).toEqual("A") - expect(typeof json["stack"]).toEqual("string") + strictEqual(json["_id"], "Tag") + strictEqual(json["key"], "A") + strictEqual(typeof json["stack"], "string") }) it("TagClass.toJson()", () => { const json: any = D.toJSON() - expect(json["_id"]).toEqual("Tag") - expect(json["key"]).toEqual("D") - expect(typeof json["stack"]).toEqual("string") + strictEqual(json["_id"], "Tag") + strictEqual(json["key"], "D") + strictEqual(typeof json["stack"], "string") }) it("Context.toJson()", () => { const json: any = Context.empty().toJSON() - expect(json["_id"]).toEqual("Context") - expect(json["services"]).toEqual([]) + strictEqual(json["_id"], "Context") + deepStrictEqual(json["services"], []) }) it("aliased tags", () => { @@ -58,7 +91,7 @@ describe("Context", () => { } const Service = Context.GenericTag("FooBar") const context = Context.make(Service, { _tag: "Foo" }) - expect(Context.get(context, Service)).toStrictEqual({ _tag: "Foo" }) + deepStrictEqual(Context.get(context, Service), { _tag: "Foo" }) }) it("adds and retrieve services", () => { @@ -68,34 +101,18 @@ describe("Context", () => { Context.add(D, { d: 2 }) ) - expect(Context.get(Services, A)).toEqual({ a: 0 }) - - expect(pipe( - Services, - Context.getOption(B) - )).toEqual(O.some({ b: 1 })) - - expect(pipe( - Services, - Context.get(D) - )).toEqual({ d: 2 }) + deepStrictEqual(Context.get(Services, A), { a: 0 }) + assertSome(pipe(Services, Context.getOption(B)), { b: 1 }) + deepStrictEqual(pipe(Services, Context.get(D)), { d: 2 }) + assertNone(pipe(Services, Context.getOption(C))) + deepStrictEqual(pipe(Services, Context.get(E)), { e: 0 }) - expect(pipe( - Services, - Context.getOption(C) - )).toEqual(O.none()) - - expect(pipe( - Services, - Context.get(E) - )).toEqual({ e: 0 }) - - assert.throw(() => { + throws(() => { pipe( Services, Context.unsafeGet(C) ) - }, "Service not found: C") + }, (e) => e instanceof Error && e.message.includes("Service not found: C")) }) it("picks services in env and merges", () => { @@ -114,25 +131,10 @@ describe("Context", () => { Context.pick(A, B) ) - expect(pipe( - pruned, - Context.get(A) - )).toEqual({ a: 0 }) - - expect(pipe( - pruned, - Context.getOption(B) - )).toEqual(O.some({ b: 1 })) - - expect(pipe( - pruned, - Context.getOption(C) - )).toEqual(O.none()) - - expect(pipe( - env, - Context.getOption(C) - )).toEqual(O.some({ c: 2 })) + deepStrictEqual(pipe(pruned, Context.get(A)), { a: 0 }) + assertSome(pipe(pruned, Context.getOption(B)), { b: 1 }) + assertNone(pipe(pruned, Context.getOption(C))) + assertSome(pipe(env, Context.getOption(C)), { c: 2 }) }) it("omits services from env", () => { @@ -151,15 +153,8 @@ describe("Context", () => { Context.omit(A, B) ) - expect(pipe( - pruned, - Context.getOption(A) - )).toEqual(O.none()) - - expect(pipe( - env, - Context.get(C) - )).toEqual({ c: 2 }) + assertNone(pipe(pruned, Context.getOption(A))) + deepStrictEqual(pipe(env, Context.get(C)), { c: 2 }) }) it("applies a patch to the environment", () => { @@ -181,10 +176,10 @@ describe("Context", () => { const patch = differ.diff(oldEnv, newEnv) const result = differ.patch(patch, oldEnv) - assert.isTrue(O.isSome(Context.getOption(A)(result))) - assert.isTrue(O.isSome(Context.getOption(B)(result))) - assert.isTrue(O.isNone(Context.getOption(C)(result))) - assert.strictEqual(pipe(result, Context.get(B)).b, 3) + assertTrue(Option.isSome(Context.getOption(A)(result))) + assertTrue(Option.isSome(Context.getOption(B)(result))) + assertTrue(Option.isNone(Context.getOption(C)(result))) + strictEqual(pipe(result, Context.get(B)).b, 3) }) it("creates a proper diff", () => { @@ -203,57 +198,24 @@ describe("Context", () => { Context.add(B, { b: 3 }) ) as Context.Context const differ = Differ.environment() - const result = differ.diff(oldEnv, newEnv) + const result: any = differ.diff(oldEnv, newEnv) - assert.deepNestedPropertyVal(result, "first._tag", "AndThen") - assert.deepNestedPropertyVal(result, "first.first._tag", "Empty") - assert.deepNestedPropertyVal(result, "first.second._tag", "UpdateService") - assert.deepNestedPropertyVal(result, "first.second.key", B.key) - assert.deepNestedPropertyVal(result, "second._tag", "RemoveService") - assert.deepNestedPropertyVal(result, "second.key", C.key) - }) - - it("error messages", () => { - assert.throw(() => { - Context.unsafeGet(Context.empty(), A) - }, "Service not found") - assert.throw(() => { - Context.get(Context.empty(), A as never) - }, "Service not found") - assert.throw(() => { - Context.unsafeGet(Context.empty(), C) - }, "Service not found: C") - assert.throw(() => { - Context.get(Context.empty(), C as never) - }, "Service not found: C") - if (typeof window === "undefined") { - try { - Context.get(Context.empty(), C as never) - } catch (e) { - assert.match( - String(e), - new RegExp(/Error: Service not found: C \(defined at (.*)Context.test.ts:20:19\)/) - ) - } - try { - Context.get(Context.empty(), D as never) - } catch (e) { - assert.match( - String(e), - new RegExp(/Error: Service not found: D \(defined at (.*)Context.test.ts:22:32\)/) - ) - } - } + strictEqual(result.first._tag, "AndThen") + strictEqual(result.first.first._tag, "Empty") + strictEqual(result.first.second._tag, "UpdateService") + strictEqual(result.first.second.key, B.key) + strictEqual(result.second._tag, "RemoveService") + strictEqual(result.second.key, C.key) }) it("pipe()", () => { const result = Context.empty().pipe(Context.add(A, { a: 0 })) - expect(result.pipe(Context.get(A))).toEqual({ a: 0 }) + deepStrictEqual(result.pipe(Context.get(A)), { a: 0 }) }) it("tag pipe", () => { const result = A.pipe((tag) => Context.make(tag, { a: 0 })) - expect(result.pipe(Context.get(A))).toEqual({ a: 0 }) + deepStrictEqual(result.pipe(Context.get(A)), { a: 0 }) }) it("mergeAll", () => { @@ -268,39 +230,24 @@ describe("Context", () => { Context.pick(A, B) ) - expect(pipe( - pruned, - Context.get(A) - )).toEqual({ a: 0 }) - - expect(pipe( - pruned, - Context.getOption(B) - )).toEqual(O.some({ b: 1 })) - - expect(pipe( - pruned, - Context.getOption(C) - )).toEqual(O.none()) - - expect(pipe( - env, - Context.getOption(C) - )).toEqual(O.some({ c: 2 })) + deepStrictEqual(pipe(pruned, Context.get(A)), { a: 0 }) + assertSome(pipe(pruned, Context.getOption(B)), { b: 1 }) + assertNone(pipe(pruned, Context.getOption(C))) + assertSome(pipe(env, Context.getOption(C)), { c: 2 }) }) it("isContext", () => { - expect(Context.isContext(Context.empty())).toEqual(true) - expect(Context.isContext(null)).toEqual(false) + assertTrue(Context.isContext(Context.empty())) + assertFalse(Context.isContext(null)) }) it("isTag", () => { - expect(Context.isTag(Context.GenericTag("Demo"))).toEqual(true) - expect(Context.isContext(null)).toEqual(false) + assertTrue(Context.isTag(Context.GenericTag("Demo"))) + assertFalse(Context.isContext(null)) }) it("isReference", () => { - expect(Context.isTag(E)).toEqual(true) - expect(Context.isReference(E)).toEqual(true) + assertTrue(Context.isTag(E)) + assertTrue(Context.isReference(E)) }) }) diff --git a/packages/effect/test/Cron.test.ts b/packages/effect/test/Cron.test.ts index 7ee935b644d..2e4e3bd3f79 100644 --- a/packages/effect/test/Cron.test.ts +++ b/packages/effect/test/Cron.test.ts @@ -1,17 +1,12 @@ -import * as Cron from "effect/Cron" -import * as DateTime from "effect/DateTime" -import * as Either from "effect/Either" -import * as Equal from "effect/Equal" -import { identity } from "effect/Function" -import * as Option from "effect/Option" -import { assertFalse, assertTrue, deepStrictEqual } from "effect/test/util" -import { describe, expect, it } from "vitest" - -const parse = (input: string, tz?: DateTime.TimeZone | string) => Either.getOrThrowWith(Cron.parse(input, tz), identity) +import { Cron, DateTime, Either, Equal, Option } from "effect" +import { assertFalse, assertTrue, deepStrictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" + const match = (input: Cron.Cron | string, date: DateTime.DateTime.Input) => - Cron.match(Cron.isCron(input) ? input : parse(input), date) + Cron.match(Cron.isCron(input) ? input : Cron.unsafeParse(input), date) + const next = (input: Cron.Cron | string, after?: DateTime.DateTime.Input) => - Cron.next(Cron.isCron(input) ? input : parse(input), after) + Cron.next(Cron.isCron(input) ? input : Cron.unsafeParse(input), after) describe("Cron", () => { it("parse", () => { @@ -51,8 +46,14 @@ describe("Cron", () => { }) it("unsafeParse", () => { - expect(() => Cron.unsafeParse("")).toThrow(new Error("Invalid number of segments in cron expression")) - expect(() => Cron.unsafeParse("0 0 4 8-14 * *", "")).toThrow(new Error("Invalid time zone in cron expression")) + throws( + () => Cron.unsafeParse(""), + new Cron.ParseError({ message: "Invalid number of segments in cron expression", input: "" }) + ) + throws( + () => Cron.unsafeParse("0 0 4 8-14 * *", ""), + new Cron.ParseError({ message: "Invalid time zone in cron expression", input: "" }) + ) }) it("match", () => { @@ -96,8 +97,8 @@ describe("Cron", () => { adjustForTimeZone: true }) - assertTrue(match(parse("15 14 1 * *", london), londonTime)) - assertTrue(match(parse("15 14 1 * *", london), amsterdamTime)) + assertTrue(match(Cron.unsafeParse("15 14 1 * *", london), londonTime)) + assertTrue(match(Cron.unsafeParse("15 14 1 * *", london), amsterdamTime)) }) it("next", () => { @@ -121,13 +122,13 @@ describe("Cron", () => { adjustForTimeZone: true }) - deepStrictEqual(next(parse("5 0 8 2 *", london), after), DateTime.toDateUtc(londonTime)) - deepStrictEqual(next(parse("5 0 8 2 *", london), after), DateTime.toDateUtc(amsterdamTime)) + deepStrictEqual(next(Cron.unsafeParse("5 0 8 2 *", london), after), DateTime.toDateUtc(londonTime)) + deepStrictEqual(next(Cron.unsafeParse("5 0 8 2 *", london), after), DateTime.toDateUtc(amsterdamTime)) }) it("sequence", () => { const start = new Date("2024-01-01 00:00:00") - const generator = Cron.sequence(parse("23 0-20/2 * * 0"), start) + const generator = Cron.sequence(Cron.unsafeParse("23 0-20/2 * * 0"), start) deepStrictEqual(generator.next().value, new Date("2024-01-07 00:23:00")) deepStrictEqual(generator.next().value, new Date("2024-01-07 02:23:00")) deepStrictEqual(generator.next().value, new Date("2024-01-07 04:23:00")) @@ -136,12 +137,12 @@ describe("Cron", () => { }) it("equal", () => { - const cron = parse("23 0-20/2 * * 0") + const cron = Cron.unsafeParse("23 0-20/2 * * 0") assertTrue(Equal.equals(cron, cron)) - assertTrue(Equal.equals(cron, parse("23 0-20/2 * * 0"))) - assertFalse(Equal.equals(cron, parse("23 0-20/2 * * 1"))) - assertFalse(Equal.equals(cron, parse("23 0-20/2 * * 0-6"))) - assertFalse(Equal.equals(cron, parse("23 0-20/2 1 * 0"))) + assertTrue(Equal.equals(cron, Cron.unsafeParse("23 0-20/2 * * 0"))) + assertFalse(Equal.equals(cron, Cron.unsafeParse("23 0-20/2 * * 1"))) + assertFalse(Equal.equals(cron, Cron.unsafeParse("23 0-20/2 * * 0-6"))) + assertFalse(Equal.equals(cron, Cron.unsafeParse("23 0-20/2 1 * 0"))) }) it("handles leap years", () => { @@ -158,7 +159,7 @@ describe("Cron", () => { it("handles transition into daylight savings time", () => { const make = (date: string) => DateTime.makeZonedFromString(date).pipe(Option.getOrThrow) const sequence = Cron.sequence( - parse("30 * * * *", "Europe/Berlin"), + Cron.unsafeParse("30 * * * *", "Europe/Berlin"), make("2024-03-31T00:00:00.000+01:00[Europe/Berlin]") ) const next = (): DateTime.Zoned => DateTime.unsafeMakeZoned(sequence.next().value, { timeZone: "Europe/Berlin" }) @@ -177,7 +178,7 @@ describe("Cron", () => { it("handles transition out of daylight savings time", () => { const make = (date: string) => DateTime.makeZonedFromString(date).pipe(Option.getOrThrow) const sequence = Cron.sequence( - parse("30 * * * *", "Europe/Berlin"), + Cron.unsafeParse("30 * * * *", "Europe/Berlin"), make("2024-10-27T00:00:00.000+02:00[Europe/Berlin]") ) const next = (): DateTime.Zoned => DateTime.unsafeMakeZoned(sequence.next().value, { timeZone: "Europe/Berlin" }) @@ -197,7 +198,7 @@ describe("Cron", () => { it("handles utc timezone", () => { const utc = DateTime.zoneUnsafeMakeNamed("UTC") const make = (date: string) => DateTime.makeZonedFromString(date).pipe(Option.getOrThrow) - const sequence = Cron.sequence(parse("30 * * * *", utc), make("2024-10-27T00:00:00.000+00:00[UTC]")) + const sequence = Cron.sequence(Cron.unsafeParse("30 * * * *", utc), make("2024-10-27T00:00:00.000+00:00[UTC]")) const next = (): DateTime.Zoned => DateTime.unsafeMakeZoned(sequence.next().value, { timeZone: utc }) const a = make("2024-10-27T00:30:00.000+00:00[UTC]") diff --git a/packages/effect/test/Data.test.ts b/packages/effect/test/Data.test.ts index 7fab66478ed..f2fe35d6ddf 100644 --- a/packages/effect/test/Data.test.ts +++ b/packages/effect/test/Data.test.ts @@ -1,59 +1,58 @@ -import * as Data from "effect/Data" -import * as Equal from "effect/Equal" -import { pipe } from "effect/Function" -import { assert, describe, expect, it } from "vitest" +import { Data, Equal, pipe } from "effect" +import { assertFalse, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Data", () => { it("struct", () => { const x = Data.struct({ a: 0, b: 1, c: 2 }) const y = Data.struct({ a: 0, b: 1, c: 2 }) const { a, b, c } = x - expect(a).toBe(0) - expect(b).toBe(1) - expect(c).toBe(2) - expect(Equal.equals(x, y)).toBe(true) - expect(Equal.equals(x, Data.struct({ a: 0 }))).toBe(false) + strictEqual(a, 0) + strictEqual(b, 1) + strictEqual(c, 2) + assertTrue(Equal.equals(x, y)) + assertFalse(Equal.equals(x, Data.struct({ a: 0 }))) // different keys length - expect(Equal.equals(Data.struct({ a: 0, b: 1 }), Data.struct({ a: 0 }))).toBe(false) + assertFalse(Equal.equals(Data.struct({ a: 0, b: 1 }), Data.struct({ a: 0 }))) // same length but different keys - expect(Equal.equals(Data.struct({ a: 0 }), Data.struct({ b: 1 }))).toBe(false) + assertFalse(Equal.equals(Data.struct({ a: 0 }), Data.struct({ b: 1 }))) }) it("unsafeStruct", () => { const x = Data.unsafeStruct({ a: 0, b: 1, c: 2 }) const y = Data.unsafeStruct({ a: 0, b: 1, c: 2 }) const { a, b, c } = x - expect(a).toBe(0) - expect(b).toBe(1) - expect(c).toBe(2) - expect(Equal.equals(x, y)).toBe(true) + strictEqual(a, 0) + strictEqual(b, 1) + strictEqual(c, 2) + assertTrue(Equal.equals(x, y)) }) it("tuple", () => { const x = Data.tuple(0, 1, 2) const y = Data.tuple(0, 1, 2) const [a, b, c] = x - expect(a).toBe(0) - expect(b).toBe(1) - expect(c).toBe(2) - expect(Equal.equals(x, y)).toBe(true) - expect(Equal.equals(x, Data.tuple(0, 1))).toBe(false) + strictEqual(a, 0) + strictEqual(b, 1) + strictEqual(c, 2) + assertTrue(Equal.equals(x, y)) + assertFalse(Equal.equals(x, Data.tuple(0, 1))) }) it("array", () => { const x = Data.array([0, 1, 2]) const y = Data.array([0, 1, 2]) const [a, b, c] = x - expect(a).toBe(0) - expect(b).toBe(1) - expect(c).toBe(2) - expect(Equal.equals(x, y)).toBe(true) - expect(Equal.equals(x, Data.tuple(0, 1, 2))).toBe(true) - expect(Equal.equals(x, Data.array([0, 1]))).toBe(false) + strictEqual(a, 0) + strictEqual(b, 1) + strictEqual(c, 2) + assertTrue(Equal.equals(x, y)) + assertTrue(Equal.equals(x, Data.tuple(0, 1, 2))) + assertFalse(Equal.equals(x, Data.array([0, 1]))) // different length - expect(Equal.equals(Data.array([0, 1, 2]), Data.array([0, 1]))).toBe(false) + assertFalse(Equal.equals(Data.array([0, 1, 2]), Data.array([0, 1]))) }) it("case", () => { @@ -67,14 +66,14 @@ describe("Data", () => { const b = Person({ name: "Mike" }) const c = Person({ name: "Foo" }) - expect(a.name).toBe("Mike") - expect(b.name).toBe("Mike") - expect(c.name).toBe("Foo") - expect(Equal.equals(a, b)).toBe(true) - expect(Equal.equals(a, c)).toBe(false) + strictEqual(a.name, "Mike") + strictEqual(b.name, "Mike") + strictEqual(c.name, "Foo") + assertTrue(Equal.equals(a, b)) + assertFalse(Equal.equals(a, c)) const Empty = Data.case() - expect(Equal.equals(Empty(), Empty())).toBe(true) + assertTrue(Equal.equals(Empty(), Empty())) }) it("tagged", () => { @@ -89,12 +88,12 @@ describe("Data", () => { const b = Person({ name: "Mike" }) const c = Person({ name: "Foo" }) - expect(a._tag).toBe("Person") - expect(a.name).toBe("Mike") - expect(b.name).toBe("Mike") - expect(c.name).toBe("Foo") - expect(Equal.equals(a, b)).toBe(true) - expect(Equal.equals(a, c)).toBe(false) + strictEqual(a._tag, "Person") + strictEqual(a.name, "Mike") + strictEqual(b.name, "Mike") + strictEqual(c.name, "Foo") + assertTrue(Equal.equals(a, b)) + assertFalse(Equal.equals(a, c)) }) it("case class", () => { @@ -103,20 +102,20 @@ describe("Data", () => { const b = new Person({ name: "Mike" }) const c = new Person({ name: "Foo" }) - expect(a.name).toBe("Mike") - expect(b.name).toBe("Mike") - expect(c.name).toBe("Foo") - expect(Equal.equals(a, b)).toBe(true) - expect(Equal.equals(a, c)).toBe(false) + strictEqual(a.name, "Mike") + strictEqual(b.name, "Mike") + strictEqual(c.name, "Foo") + assertTrue(Equal.equals(a, b)) + assertFalse(Equal.equals(a, c)) // different keys length class D extends Data.Class<{ d: string; e: string }> {} const d = new D({ d: "d", e: "e" }) - expect(Equal.equals(a, d)).toBe(false) + assertFalse(Equal.equals(a, d)) // same length but different keys class E extends Data.Class<{ e: string }> {} const e = new E({ e: "e" }) - expect(Equal.equals(a, e)).toBe(false) + assertFalse(Equal.equals(a, e)) }) it("date compares by value", () => { @@ -124,7 +123,7 @@ describe("Data", () => { const a = Data.struct({ date: new Date(date.toISOString()) }) const b = Data.struct({ date: new Date(date.toISOString()) }) - expect(Equal.equals(a, b)).toBe(true) + assertTrue(Equal.equals(a, b)) }) it("tagged class", () => { @@ -133,12 +132,12 @@ describe("Data", () => { const b = new Person({ name: "Mike" }) const c = new Person({ name: "Foo" }) - expect(a._tag).toBe("Person") - expect(a.name).toBe("Mike") - expect(b.name).toBe("Mike") - expect(c.name).toBe("Foo") - expect(Equal.equals(a, b)).toBe(true) - expect(Equal.equals(a, c)).toBe(false) + strictEqual(a._tag, "Person") + strictEqual(a.name, "Mike") + strictEqual(b.name, "Mike") + strictEqual(c.name, "Foo") + assertTrue(Equal.equals(a, b)) + assertFalse(Equal.equals(a, c)) }) it("tagged - empty", () => { @@ -151,7 +150,7 @@ describe("Data", () => { const a = Person() const b = Person() - expect(Equal.equals(a, b)).toBe(true) + assertTrue(Equal.equals(a, b)) }) it("TaggedClass - empty", () => { @@ -160,7 +159,7 @@ describe("Data", () => { const a = new Person() const b = new Person() - expect(Equal.equals(a, b)).toBe(true) + assertTrue(Equal.equals(a, b)) }) it("tagged - don't override tag", () => { @@ -178,7 +177,7 @@ describe("Data", () => { const foo = Foo({ value: "test" }) const bar = Bar({ ...foo, value: 10 }) - expect(bar._tag).toStrictEqual("Bar") + strictEqual(bar._tag, "Bar") }) it("taggedEnum", () => { @@ -197,23 +196,23 @@ describe("Data", () => { const b = InternalServerError({ reason: "test" }) const c = InternalServerError({ reason: "test" }) - expect(a._tag).toBe("NotFound") - expect(b._tag).toBe("InternalServerError") + strictEqual(a._tag, "NotFound") + strictEqual(b._tag, "InternalServerError") - expect(b.reason).toBe("test") - expect(c.reason).toBe("test") + strictEqual(b.reason, "test") + strictEqual(c.reason, "test") - expect(Equal.equals(a, b)).toBe(false) - expect(Equal.equals(b, c)).toBe(true) + assertFalse(Equal.equals(a, b)) + assertTrue(Equal.equals(b, c)) - expect($is("NotFound")(a)).toBe(true) - expect($is("InternalServerError")(a)).toBe(false) + assertTrue($is("NotFound")(a)) + assertFalse($is("InternalServerError")(a)) const matcher = $match({ NotFound: () => 0, InternalServerError: () => 1 }) - expect(matcher(a)).toEqual(0) - expect(matcher(b)).toEqual(1) + strictEqual(matcher(a), 0) + strictEqual(matcher(b), 1) }) it("taggedEnum - generics", () => { @@ -233,20 +232,20 @@ describe("Data", () => { const b = Failure({ error: "test" }) satisfies Result const c = Success({ value: 1 }) satisfies Result - expect(a._tag).toBe("Success") - expect(b._tag).toBe("Failure") - expect(c._tag).toBe("Success") + strictEqual(a._tag, "Success") + strictEqual(b._tag, "Failure") + strictEqual(c._tag, "Success") - expect(a.value).toBe(1) - expect(b.error).toBe("test") + strictEqual(a.value, 1) + strictEqual(b.error, "test") - expect(Equal.equals(a, b)).toBe(false) - expect(Equal.equals(a, c)).toBe(true) + assertFalse(Equal.equals(a, b)) + assertTrue(Equal.equals(a, c)) const aResult = Success({ value: 1 }) as Result const bResult = Failure({ error: "boom" }) as Result - assert.strictEqual( + strictEqual( $match(aResult, { Success: (_) => 1, Failure: (_) => 2 @@ -261,29 +260,29 @@ describe("Data", () => { }) ) result satisfies string | number - assert.strictEqual(result, "boom") + strictEqual(result, "boom") - assert($is("Success")(aResult)) + assertTrue($is("Success")(aResult)) aResult satisfies { readonly _tag: "Success"; readonly value: number } - assert.strictEqual(aResult.value, 1) + strictEqual(aResult.value, 1) - assert($is("Failure")(bResult)) + assertTrue($is("Failure")(bResult)) bResult satisfies { readonly _tag: "Failure"; readonly error: string } - assert.strictEqual(bResult.error, "boom") + strictEqual(bResult.error, "boom") }) describe("Error", () => { it("should support a message field", () => { class MyError extends Data.Error<{ message: string; a: number }> {} const e = new MyError({ message: "Oh no!", a: 1 }) - expect(e.message).toStrictEqual("Oh no!") - expect(e.a).toStrictEqual(1) + strictEqual(e.message, "Oh no!") + strictEqual(e.a, 1) }) it("toJSON includes all args", () => { class MyError extends Data.Error<{ message: string; a: number; cause: string }> {} const e = new MyError({ message: "Oh no!", a: 1, cause: "Boom" }) - assert.deepStrictEqual(e.toJSON(), { message: "Oh no!", a: 1, cause: "Boom" }) + deepStrictEqual(e.toJSON(), { message: "Oh no!", a: 1, cause: "Boom" }) }) }) @@ -291,7 +290,7 @@ describe("Data", () => { it("toJSON includes all args", () => { class MyError extends Data.TaggedError("MyError")<{ message: string; a: number; cause: string }> {} const e = new MyError({ message: "Oh no!", a: 1, cause: "Boom" }) - assert.deepStrictEqual(e.toJSON(), { + deepStrictEqual(e.toJSON(), { _tag: "MyError", message: "Oh no!", a: 1, diff --git a/packages/effect/test/DateTime.test.ts b/packages/effect/test/DateTime.test.ts index ff01753b558..90999a5c84f 100644 --- a/packages/effect/test/DateTime.test.ts +++ b/packages/effect/test/DateTime.test.ts @@ -1,5 +1,6 @@ -import { DateTime, Duration, Effect, Either, Option, TestClock } from "effect" -import { assert, describe, it } from "./utils/extend.js" +import { DateTime, Duration, Effect, Option, TestClock } from "effect" +import { assertRight, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "./utils/extend.js" const setTo2024NZ = TestClock.setTime(new Date("2023-12-31T11:00:00.000Z").getTime()) @@ -12,7 +13,7 @@ describe("DateTime", () => { date.setUTCDate(date.getUTCDate() + 1) }) const diff = DateTime.distanceDurationEither(now, tomorrow) - assert.deepStrictEqual(diff, Either.right(Duration.decode("1 day"))) + assertRight(diff, Duration.decode("1 day")) })) it.effect("correctly preserves the time zone", () => @@ -24,13 +25,13 @@ describe("DateTime", () => { const future = DateTime.mutate(now, (date) => { date.setUTCMonth(date.getUTCMonth() + 6) }) - assert.strictEqual(DateTime.toDateUtc(future).toISOString(), "2024-06-30T12:00:00.000Z") - assert.strictEqual(DateTime.toDate(future).toISOString(), "2024-07-01T00:00:00.000Z") + strictEqual(DateTime.toDateUtc(future).toISOString(), "2024-06-30T12:00:00.000Z") + strictEqual(DateTime.toDate(future).toISOString(), "2024-07-01T00:00:00.000Z") const plusOne = DateTime.mutate(future, (date) => { date.setUTCDate(date.getUTCDate() + 1) }) - assert.strictEqual(DateTime.toDateUtc(plusOne).toISOString(), "2024-07-01T12:00:00.000Z") - assert.strictEqual(DateTime.toDate(plusOne).toISOString(), "2024-07-02T00:00:00.000Z") + strictEqual(DateTime.toDateUtc(plusOne).toISOString(), "2024-07-01T12:00:00.000Z") + strictEqual(DateTime.toDate(plusOne).toISOString(), "2024-07-02T00:00:00.000Z") })) }) @@ -40,17 +41,17 @@ describe("DateTime", () => { const now = yield* DateTime.now const tomorrow = DateTime.add(now, { days: 1 }) const diff = DateTime.distanceDurationEither(now, tomorrow) - assert.deepStrictEqual(diff, Either.right(Duration.decode("1 day"))) + assertRight(diff, Duration.decode("1 day")) })) it("to month with less days", () => { const jan = DateTime.unsafeMake({ year: 2023, month: 1, day: 31 }) let feb = DateTime.add(jan, { months: 1 }) - assert.strictEqual(feb.toJSON(), "2023-02-28T00:00:00.000Z") + strictEqual(feb.toJSON(), "2023-02-28T00:00:00.000Z") const mar = DateTime.unsafeMake({ year: 2023, month: 3, day: 31 }) feb = DateTime.subtract(mar, { months: 1 }) - assert.strictEqual(feb.toJSON(), "2023-02-28T00:00:00.000Z") + strictEqual(feb.toJSON(), "2023-02-28T00:00:00.000Z") }) it.effect("correctly preserves the time zone", () => @@ -60,14 +61,14 @@ describe("DateTime", () => { DateTime.withCurrentZoneNamed("Pacific/Auckland") ) const future = DateTime.add(now, { months: 6 }) - assert.strictEqual(DateTime.toDateUtc(future).toISOString(), "2024-06-30T12:00:00.000Z") - assert.strictEqual(DateTime.toDate(future).toISOString(), "2024-07-01T00:00:00.000Z") + strictEqual(DateTime.toDateUtc(future).toISOString(), "2024-06-30T12:00:00.000Z") + strictEqual(DateTime.toDate(future).toISOString(), "2024-07-01T00:00:00.000Z") const plusOne = DateTime.add(future, { days: 1 }) - assert.strictEqual(DateTime.toDateUtc(plusOne).toISOString(), "2024-07-01T12:00:00.000Z") - assert.strictEqual(DateTime.toDate(plusOne).toISOString(), "2024-07-02T00:00:00.000Z") + strictEqual(DateTime.toDateUtc(plusOne).toISOString(), "2024-07-01T12:00:00.000Z") + strictEqual(DateTime.toDate(plusOne).toISOString(), "2024-07-02T00:00:00.000Z") const minusOne = DateTime.subtract(plusOne, { days: 1 }) - assert.strictEqual(DateTime.toDateUtc(minusOne).toISOString(), "2024-06-30T12:00:00.000Z") - assert.strictEqual(DateTime.toDate(minusOne).toISOString(), "2024-07-01T00:00:00.000Z") + strictEqual(DateTime.toDateUtc(minusOne).toISOString(), "2024-06-30T12:00:00.000Z") + strictEqual(DateTime.toDate(minusOne).toISOString(), "2024-07-01T00:00:00.000Z") })) it.effect("leap years", () => @@ -75,7 +76,7 @@ describe("DateTime", () => { yield* setTo2024NZ const now = yield* DateTime.make({ year: 2024, month: 2, day: 29 }) const future = DateTime.add(now, { years: 1 }) - assert.strictEqual(DateTime.formatIso(future), "2025-02-28T00:00:00.000Z") + strictEqual(DateTime.formatIso(future), "2025-02-28T00:00:00.000Z") })) }) @@ -83,26 +84,26 @@ describe("DateTime", () => { it("month", () => { const mar = DateTime.unsafeMake("2024-03-15T12:00:00.000Z") const end = DateTime.endOf(mar, "month") - assert.strictEqual(end.toJSON(), "2024-03-31T23:59:59.999Z") + strictEqual(end.toJSON(), "2024-03-31T23:59:59.999Z") }) it("feb leap year", () => { const feb = DateTime.unsafeMake("2024-02-15T12:00:00.000Z") const end = DateTime.endOf(feb, "month") - assert.strictEqual(end.toJSON(), "2024-02-29T23:59:59.999Z") + strictEqual(end.toJSON(), "2024-02-29T23:59:59.999Z") }) it("week", () => { const start = DateTime.unsafeMake("2024-03-15T12:00:00.000Z") const end = DateTime.endOf(start, "week") - assert.strictEqual(end.toJSON(), "2024-03-16T23:59:59.999Z") - assert.strictEqual(DateTime.getPartUtc(end, "weekDay"), 6) + strictEqual(end.toJSON(), "2024-03-16T23:59:59.999Z") + strictEqual(DateTime.getPartUtc(end, "weekDay"), 6) }) it("week last day", () => { const start = DateTime.unsafeMake("2024-03-16T12:00:00.000Z") const end = DateTime.endOf(start, "week") - assert.strictEqual(end.toJSON(), "2024-03-16T23:59:59.999Z") + strictEqual(end.toJSON(), "2024-03-16T23:59:59.999Z") }) it("week with options", () => { @@ -110,7 +111,7 @@ describe("DateTime", () => { const end = DateTime.endOf(start, "week", { weekStartsOn: 1 }) - assert.strictEqual(end.toJSON(), "2024-03-17T23:59:59.999Z") + strictEqual(end.toJSON(), "2024-03-17T23:59:59.999Z") }) it.effect("correctly preserves the time zone", () => @@ -120,8 +121,8 @@ describe("DateTime", () => { DateTime.withCurrentZoneNamed("Pacific/Auckland") ) const future = DateTime.endOf(now, "month") - assert.strictEqual(DateTime.toDateUtc(future).toISOString(), "2024-01-31T10:59:59.999Z") - assert.strictEqual(DateTime.toDate(future).toISOString(), "2024-01-31T23:59:59.999Z") + strictEqual(DateTime.toDateUtc(future).toISOString(), "2024-01-31T10:59:59.999Z") + strictEqual(DateTime.toDate(future).toISOString(), "2024-01-31T23:59:59.999Z") })) }) @@ -129,7 +130,7 @@ describe("DateTime", () => { it("month", () => { const mar = DateTime.unsafeMake("2024-03-15T12:00:00.000Z") const end = DateTime.startOf(mar, "month") - assert.strictEqual(end.toJSON(), "2024-03-01T00:00:00.000Z") + strictEqual(end.toJSON(), "2024-03-01T00:00:00.000Z") }) it("month duplicated", () => { @@ -137,26 +138,26 @@ describe("DateTime", () => { const end = DateTime.startOf(mar, "month").pipe( DateTime.startOf("month") ) - assert.strictEqual(end.toJSON(), "2024-03-01T00:00:00.000Z") + strictEqual(end.toJSON(), "2024-03-01T00:00:00.000Z") }) it("feb leap year", () => { const feb = DateTime.unsafeMake("2024-02-15T12:00:00.000Z") const end = DateTime.startOf(feb, "month") - assert.strictEqual(end.toJSON(), "2024-02-01T00:00:00.000Z") + strictEqual(end.toJSON(), "2024-02-01T00:00:00.000Z") }) it("week", () => { const start = DateTime.unsafeMake("2024-03-15T12:00:00.000Z") const end = DateTime.startOf(start, "week") - assert.strictEqual(end.toJSON(), "2024-03-10T00:00:00.000Z") - assert.strictEqual(DateTime.getPartUtc(end, "weekDay"), 0) + strictEqual(end.toJSON(), "2024-03-10T00:00:00.000Z") + strictEqual(DateTime.getPartUtc(end, "weekDay"), 0) }) it("week first day", () => { const start = DateTime.unsafeMake("2024-03-10T12:00:00.000Z") const end = DateTime.startOf(start, "week") - assert.strictEqual(end.toJSON(), "2024-03-10T00:00:00.000Z") + strictEqual(end.toJSON(), "2024-03-10T00:00:00.000Z") }) it("week with options", () => { @@ -164,7 +165,7 @@ describe("DateTime", () => { const end = DateTime.startOf(start, "week", { weekStartsOn: 1 }) - assert.strictEqual(end.toJSON(), "2024-03-11T00:00:00.000Z") + strictEqual(end.toJSON(), "2024-03-11T00:00:00.000Z") }) }) @@ -172,25 +173,25 @@ describe("DateTime", () => { it("month up", () => { const mar = DateTime.unsafeMake("2024-03-16T12:00:00.000Z") const end = DateTime.nearest(mar, "month") - assert.strictEqual(end.toJSON(), "2024-04-01T00:00:00.000Z") + strictEqual(end.toJSON(), "2024-04-01T00:00:00.000Z") }) it("month down", () => { const mar = DateTime.unsafeMake("2024-03-16T11:00:00.000Z") const end = DateTime.nearest(mar, "month") - assert.strictEqual(end.toJSON(), "2024-03-01T00:00:00.000Z") + strictEqual(end.toJSON(), "2024-03-01T00:00:00.000Z") }) it("second up", () => { const mar = DateTime.unsafeMake("2024-03-20T12:00:00.500Z") const end = DateTime.nearest(mar, "second") - assert.strictEqual(end.toJSON(), "2024-03-20T12:00:01.000Z") + strictEqual(end.toJSON(), "2024-03-20T12:00:01.000Z") }) it("second down", () => { const mar = DateTime.unsafeMake("2024-03-20T12:00:00.400Z") const end = DateTime.nearest(mar, "second") - assert.strictEqual(end.toJSON(), "2024-03-20T12:00:00.000Z") + strictEqual(end.toJSON(), "2024-03-20T12:00:00.000Z") }) }) @@ -198,7 +199,7 @@ describe("DateTime", () => { it.effect("full", () => Effect.gen(function*() { const now = yield* DateTime.now - assert.strictEqual( + strictEqual( DateTime.format(now, { locale: "en-US", dateStyle: "full", @@ -213,7 +214,7 @@ describe("DateTime", () => { it.effect("full", () => Effect.gen(function*() { const now = yield* DateTime.now - assert.strictEqual( + strictEqual( DateTime.formatUtc(now, { locale: "en-US", dateStyle: "full", @@ -230,7 +231,7 @@ describe("DateTime", () => { const now = yield* DateTime.nowInCurrentZone.pipe( DateTime.withCurrentZoneNamed("Pacific/Auckland") ) - assert.strictEqual( + strictEqual( DateTime.format(now, { locale: "en-US", dateStyle: "full", @@ -251,7 +252,7 @@ describe("DateTime", () => { timeStyle: "short" }) ) - assert.strictEqual(formatted, "January 1, 1970 at 10:00 AM") + strictEqual(formatted, "January 1, 1970 at 10:00 AM") })) }) @@ -262,12 +263,12 @@ describe("DateTime", () => { month: 12, day: 25 }) - assert.strictEqual(date.toJSON(), "2024-12-25T00:00:00.000Z") + strictEqual(date.toJSON(), "2024-12-25T00:00:00.000Z") }) it("month is set correctly", () => { const date = DateTime.unsafeMake({ year: 2024 }) - assert.strictEqual(date.toJSON(), "2024-01-01T00:00:00.000Z") + strictEqual(date.toJSON(), "2024-01-01T00:00:00.000Z") }) }) @@ -278,13 +279,13 @@ describe("DateTime", () => { month: 12, day: 25 }) - assert.strictEqual(date.toJSON(), "2024-12-25T00:00:00.000Z") + strictEqual(date.toJSON(), "2024-12-25T00:00:00.000Z") const updated = DateTime.setPartsUtc(date, { year: 2023, month: 1 }) - assert.strictEqual(updated.toJSON(), "2023-01-25T00:00:00.000Z") + strictEqual(updated.toJSON(), "2023-01-25T00:00:00.000Z") }) it("ignores time zones", () => { @@ -293,13 +294,13 @@ describe("DateTime", () => { month: 12, day: 25 }).pipe(DateTime.unsafeSetZoneNamed("Pacific/Auckland")) - assert.strictEqual(date.toJSON(), "2024-12-25T00:00:00.000Z") + strictEqual(date.toJSON(), "2024-12-25T00:00:00.000Z") const updated = DateTime.setPartsUtc(date, { year: 2023, month: 1 }) - assert.strictEqual(updated.toJSON(), "2023-01-25T00:00:00.000Z") + strictEqual(updated.toJSON(), "2023-01-25T00:00:00.000Z") }) }) @@ -310,13 +311,13 @@ describe("DateTime", () => { month: 12, day: 25 }) - assert.strictEqual(date.toJSON(), "2024-12-25T00:00:00.000Z") + strictEqual(date.toJSON(), "2024-12-25T00:00:00.000Z") const updated = DateTime.setParts(date, { year: 2023, month: 1 }) - assert.strictEqual(updated.toJSON(), "2023-01-25T00:00:00.000Z") + strictEqual(updated.toJSON(), "2023-01-25T00:00:00.000Z") }) it("accounts for time zone", () => { @@ -325,21 +326,21 @@ describe("DateTime", () => { month: 12, day: 25 }).pipe(DateTime.unsafeSetZoneNamed("Pacific/Auckland")) - assert.strictEqual(date.toJSON(), "2024-12-25T00:00:00.000Z") + strictEqual(date.toJSON(), "2024-12-25T00:00:00.000Z") const updated = DateTime.setParts(date, { year: 2023, month: 6, hours: 12 }) - assert.strictEqual(updated.toJSON(), "2023-06-25T00:00:00.000Z") + strictEqual(updated.toJSON(), "2023-06-25T00:00:00.000Z") }) }) describe("formatIso", () => { it("full", () => { const now = DateTime.unsafeMake("2024-03-15T12:00:00.000Z") - assert.strictEqual(DateTime.formatIso(now), "2024-03-15T12:00:00.000Z") + strictEqual(DateTime.formatIso(now), "2024-03-15T12:00:00.000Z") }) }) @@ -349,7 +350,7 @@ describe("DateTime", () => { const now = yield* DateTime.nowInCurrentZone.pipe( DateTime.withCurrentZoneNamed("Pacific/Auckland") ) - assert.strictEqual(DateTime.formatIsoOffset(now), "1970-01-01T12:00:00.000+12:00") + strictEqual(DateTime.formatIsoOffset(now), "1970-01-01T12:00:00.000+12:00") })) }) @@ -357,7 +358,7 @@ describe("DateTime", () => { it.effect("correctly adds offset", () => Effect.gen(function*() { const now = yield* DateTime.nowInCurrentZone - assert.strictEqual(DateTime.formatIsoOffset(now), "1970-01-01T12:00:00.000+12:00") + strictEqual(DateTime.formatIsoOffset(now), "1970-01-01T12:00:00.000+12:00") }).pipe( Effect.provide(DateTime.layerCurrentZoneNamed("Pacific/Auckland")) )) @@ -369,7 +370,7 @@ describe("DateTime", () => { timeZone: "Pacific/Auckland", adjustForTimeZone: true }).pipe(DateTime.removeTime) - assert.strictEqual(dt.toJSON(), "2024-01-01T00:00:00.000Z") + strictEqual(dt.toJSON(), "2024-01-01T00:00:00.000Z") }) }) @@ -377,21 +378,21 @@ describe("DateTime", () => { it.effect("parses time + zone", () => Effect.gen(function*() { const dt = yield* DateTime.makeZonedFromString("2024-07-21T20:12:34.112546348+12:00[Pacific/Auckland]") - assert.strictEqual(dt.toJSON(), "2024-07-21T08:12:34.112Z") + strictEqual(dt.toJSON(), "2024-07-21T08:12:34.112Z") })) it.effect("only offset", () => Effect.gen(function*() { const dt = yield* DateTime.makeZonedFromString("2024-07-21T20:12:34.112546348+12:00") - assert.strictEqual(dt.zone._tag, "Offset") - assert.strictEqual(dt.toJSON(), "2024-07-21T08:12:34.112Z") + strictEqual(dt.zone._tag, "Offset") + strictEqual(dt.toJSON(), "2024-07-21T08:12:34.112Z") })) it.effect("only offset with 00:00", () => Effect.gen(function*() { const dt = yield* DateTime.makeZonedFromString("2024-07-21T20:12:34.112546348+00:00") - assert.strictEqual(dt.zone._tag, "Offset") - assert.strictEqual(dt.toJSON(), "2024-07-21T20:12:34.112Z") + strictEqual(dt.zone._tag, "Offset") + strictEqual(dt.toJSON(), "2024-07-21T20:12:34.112Z") })) it.effect("roundtrip", () => @@ -400,17 +401,17 @@ describe("DateTime", () => { Option.map(DateTime.formatIsoZoned), Option.flatMap(DateTime.makeZonedFromString) ) - assert.deepStrictEqual(dt.zone, DateTime.zoneUnsafeMakeNamed("Pacific/Auckland")) - assert.strictEqual(dt.toJSON(), "2024-07-21T08:12:34.112Z") + deepStrictEqual(dt.zone, DateTime.zoneUnsafeMakeNamed("Pacific/Auckland")) + strictEqual(dt.toJSON(), "2024-07-21T08:12:34.112Z") })) }) it("parts equality", () => { const d1 = DateTime.unsafeMake("2025-01-01") const d2 = DateTime.unsafeMake("2025-01-01") - assert.deepStrictEqual(d1, d2) + deepStrictEqual(d1, d2) DateTime.toPartsUtc(d2) - assert.deepStrictEqual(d1, d2) + deepStrictEqual(d1, d2) }) // doesnt work in CI @@ -418,6 +419,6 @@ describe("DateTime", () => { const date = new Date("2024-07-21T20:12:34.112Z") ;(date as any).getTimezoneOffset = () => -60 const dt = DateTime.unsafeMakeZoned(date) - assert.deepStrictEqual(dt.zone, DateTime.zoneMakeOffset(60 * 60 * 1000)) + deepStrictEqual(dt.zone, DateTime.zoneMakeOffset(60 * 60 * 1000)) }) }) diff --git a/packages/effect/test/Deferred.test.ts b/packages/effect/test/Deferred.test.ts index 2862b4afb2b..9076dad0908 100644 --- a/packages/effect/test/Deferred.test.ts +++ b/packages/effect/test/Deferred.test.ts @@ -1,10 +1,7 @@ -import * as Deferred from "effect/Deferred" -import * as Effect from "effect/Effect" -import * as Exit from "effect/Exit" -import * as Option from "effect/Option" -import * as Ref from "effect/Ref" +import { Deferred, Effect, Exit, Option, Ref } from "effect" +import { assertFalse, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Deferred", () => { it.effect("complete a deferred using succeed", () => @@ -12,8 +9,8 @@ describe("Deferred", () => { const deferred = yield* $(Deferred.make()) const success = yield* $(Deferred.succeed(deferred, 32)) const result = yield* $(Deferred.await(deferred)) - assert.isTrue(success) - assert.strictEqual(result, 32) + assertTrue(success) + strictEqual(result, 32) })) it.effect("complete a deferred using complete", () => Effect.gen(function*($) { @@ -22,8 +19,8 @@ describe("Deferred", () => { yield* $(Deferred.complete(deferred, Ref.updateAndGet(ref, (n) => n + 1))) const result1 = yield* $(Deferred.await(deferred)) const result2 = yield* $(Deferred.await(deferred)) - assert.strictEqual(result1, 14) - assert.strictEqual(result2, 14) + strictEqual(result1, 14) + strictEqual(result2, 14) })) it.effect("complete a deferred using completeWith", () => Effect.gen(function*($) { @@ -32,8 +29,8 @@ describe("Deferred", () => { yield* $(Deferred.completeWith(deferred, Ref.updateAndGet(ref, (n) => n + 1))) const result1 = yield* $(Deferred.await(deferred)) const result2 = yield* $(Deferred.await(deferred)) - assert.strictEqual(result1, 14) - assert.strictEqual(result2, 15) + strictEqual(result1, 14) + strictEqual(result2, 15) })) it.effect("complete a deferred twice", () => Effect.gen(function*($) { @@ -41,16 +38,16 @@ describe("Deferred", () => { yield* $(Deferred.succeed(deferred, 1)) const success = yield* $(Deferred.complete(deferred, Effect.succeed(9))) const result = yield* $(Deferred.await(deferred)) - assert.isFalse(success) - assert.strictEqual(result, 1) + assertFalse(success) + strictEqual(result, 1) })) it.effect("fail a deferred using fail", () => Effect.gen(function*($) { const deferred = yield* $(Deferred.make()) const success = yield* $(Deferred.fail(deferred, "error with fail")) const result = yield* $(deferred, Deferred.await, Effect.exit) - assert.isTrue(success) - assert.isTrue(Exit.isFailure(result)) + assertTrue(success) + assertTrue(Exit.isFailure(result)) })) it.effect("fail a deferred using complete", () => Effect.gen(function*($) { @@ -61,9 +58,9 @@ describe("Deferred", () => { ) const result1 = yield* $(deferred, Deferred.await, Effect.exit) const result2 = yield* $(deferred, Deferred.await, Effect.exit) - assert.isTrue(success) - assert.isTrue(Exit.isFailure(result1)) - assert.isTrue(Exit.isFailure(result2)) + assertTrue(success) + assertTrue(Exit.isFailure(result1)) + assertTrue(Exit.isFailure(result2)) })) it.effect("fail a deferred using completeWith", () => Effect.gen(function*($) { @@ -79,35 +76,35 @@ describe("Deferred", () => { ) const result1 = yield* $(deferred, Deferred.await, Effect.exit) const result2 = yield* $(deferred, Deferred.await, Effect.exit) - assert.isTrue(success) - assert.isTrue(Exit.isFailure(result1)) - assert.isTrue(Exit.isFailure(result2)) + assertTrue(success) + assertTrue(Exit.isFailure(result1)) + assertTrue(Exit.isFailure(result2)) })) it.effect("is done when a deferred is completed", () => Effect.gen(function*($) { const deferred = yield* $(Deferred.make()) yield* $(Deferred.succeed(deferred, 0)) const result = yield* $(Deferred.isDone(deferred)) - assert.isTrue(result) + assertTrue(result) })) it.effect("is done when a deferred is failed", () => Effect.gen(function*($) { const deferred = yield* $(Deferred.make()) yield* $(Deferred.fail(deferred, "failure")) const result = yield* $(Deferred.isDone(deferred)) - assert.isTrue(result) + assertTrue(result) })) it.effect("should interrupt a deferred", () => Effect.gen(function*($) { const deferred = yield* $(Deferred.make()) const result = yield* $(Deferred.interrupt(deferred)) - assert.isTrue(result) + assertTrue(result) })) it.effect("poll a deferred that is not completed yet", () => Effect.gen(function*($) { const deferred = yield* $(Deferred.make()) const result = yield* $(Deferred.poll(deferred)) - assert.isTrue(Option.isNone(result)) + assertTrue(Option.isNone(result)) })) it.effect("poll a deferred that is completed", () => Effect.gen(function*($) { @@ -123,7 +120,7 @@ describe("Deferred", () => { Effect.exit ) ) - assert.deepStrictEqual(result, Exit.succeed(12)) + deepStrictEqual(result, Exit.succeed(12)) })) it.effect("poll a deferred that is failed", () => Effect.gen(function*($) { @@ -139,7 +136,7 @@ describe("Deferred", () => { Effect.exit ) ) - assert.isTrue(Exit.isFailure(result)) + assertTrue(Exit.isFailure(result)) })) it.effect("poll a deferred that is interrupted", () => Effect.gen(function*($) { @@ -155,7 +152,7 @@ describe("Deferred", () => { Effect.exit ) ) - assert.isTrue(Exit.isInterrupted(result)) + assertTrue(Exit.isInterrupted(result)) })) it.effect("is subtype of Effect", () => Effect.gen(function*() { @@ -164,7 +161,7 @@ describe("Deferred", () => { yield* Deferred.complete(deferred, Ref.updateAndGet(ref, (n) => n + 1)) const result1 = yield* deferred const result2 = yield* deferred - assert.strictEqual(result1, 14) - assert.strictEqual(result2, 14) + strictEqual(result1, 14) + strictEqual(result2, 14) })) }) diff --git a/packages/effect/test/Differ.test.ts b/packages/effect/test/Differ.test.ts index 82e7db78712..8809726bd61 100644 --- a/packages/effect/test/Differ.test.ts +++ b/packages/effect/test/Differ.test.ts @@ -1,11 +1,6 @@ -import * as RA from "effect/Array" -import * as Chunk from "effect/Chunk" -import * as Differ from "effect/Differ" -import * as Equal from "effect/Equal" -import { pipe } from "effect/Function" -import * as HashMap from "effect/HashMap" -import * as HashSet from "effect/HashSet" -import { assert, describe, it as it_ } from "vitest" +import { Array as Arr, Chunk, Differ, Equal, HashMap, HashSet, pipe } from "effect" +import { assertTrue, deepStrictEqual } from "effect/test/util" +import { describe, it as it_ } from "vitest" function diffLaws( differ: Differ.Differ, @@ -30,7 +25,7 @@ function diffLaws( const patch3 = differ.diff(value3, value4) const left = differ.combine(differ.combine(patch1, patch2), patch3) const right = differ.combine(patch1, differ.combine(patch2, patch3)) - assert.isTrue(equal(differ.patch(left, value1), differ.patch(right, value1))) + assertTrue(equal(differ.patch(left, value1), differ.patch(right, value1))) }) it("combining a patch with an empty patch is an identity", () => { @@ -39,25 +34,25 @@ function diffLaws( const patch = differ.diff(oldValue, newValue) const left = differ.combine(patch, differ.empty) const right = differ.combine(differ.empty, patch) - assert.isTrue(equal(differ.patch(left, oldValue), newValue)) - assert.isTrue(equal(differ.patch(right, oldValue), newValue)) + assertTrue(equal(differ.patch(left, oldValue), newValue)) + assertTrue(equal(differ.patch(right, oldValue), newValue)) }) it("diffing a value with itself returns an empty patch", () => { const value = gen() - assert.deepStrictEqual(differ.diff(value, value), differ.empty) + deepStrictEqual(differ.diff(value, value), differ.empty) }) it("diffing and then patching is an identity", () => { const oldValue = gen() const newValue = gen() const patch = differ.diff(oldValue, newValue) - assert.isTrue(equal(differ.patch(patch, oldValue), newValue)) + assertTrue(equal(differ.patch(patch, oldValue), newValue)) }) it("patching with an empty patch is an identity", () => { const value = gen() - assert.isTrue(equal(differ.patch(differ.empty, value), value)) + assertTrue(equal(differ.patch(differ.empty, value), value)) }) }) } @@ -75,8 +70,8 @@ function randomChunk(): Chunk.Chunk { function randomHashMap(): HashMap.HashMap { return pipe( - RA.fromIterable(Array.from({ length: 2 }, smallInt)), - RA.cartesian(RA.fromIterable(Array.from({ length: 2 }, smallInt))), + Arr.fromIterable(Array.from({ length: 2 }, smallInt)), + Arr.cartesian(Arr.fromIterable(Array.from({ length: 2 }, smallInt))), HashMap.fromIterable ) } @@ -122,7 +117,7 @@ describe("Differ", () => { diffLaws( Differ.readonlyArray number>(Differ.update()), randomReadonlyArray, - RA.getEquivalence(Equal.equals) + Arr.getEquivalence(Equal.equals) ) }) diff --git a/packages/effect/test/Duration.test.ts b/packages/effect/test/Duration.test.ts index 118bb3ff30b..da9b2e5722d 100644 --- a/packages/effect/test/Duration.test.ts +++ b/packages/effect/test/Duration.test.ts @@ -1,81 +1,78 @@ -import * as Duration from "effect/Duration" -import * as Equal from "effect/Equal" -import { pipe } from "effect/Function" -import * as Option from "effect/Option" -import { deepStrictEqual } from "effect/test/util" -import { assert, describe, expect, it } from "vitest" +import { Duration, Equal, pipe } from "effect" +import { assertFalse, assertNone, assertSome, assertTrue, deepStrictEqual, strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" describe("Duration", () => { it("decode", () => { const millis100 = Duration.millis(100) - expect(Duration.decode(millis100) === millis100).toEqual(true) + assertTrue(Duration.decode(millis100) === millis100) - expect(Duration.decode(100)).toEqual(millis100) + deepStrictEqual(Duration.decode(100), millis100) - expect(Duration.decode(10n)).toEqual(Duration.nanos(10n)) + deepStrictEqual(Duration.decode(10n), Duration.nanos(10n)) - expect(Duration.decode("1 nano")).toEqual(Duration.nanos(1n)) - expect(Duration.decode("10 nanos")).toEqual(Duration.nanos(10n)) - expect(Duration.decode("1 micro")).toEqual(Duration.micros(1n)) - expect(Duration.decode("10 micros")).toEqual(Duration.micros(10n)) - expect(Duration.decode("1 milli")).toEqual(Duration.millis(1)) - expect(Duration.decode("10 millis")).toEqual(Duration.millis(10)) - expect(Duration.decode("1 second")).toEqual(Duration.seconds(1)) - expect(Duration.decode("10 seconds")).toEqual(Duration.seconds(10)) - expect(Duration.decode("1 minute")).toEqual(Duration.minutes(1)) - expect(Duration.decode("10 minutes")).toEqual(Duration.minutes(10)) - expect(Duration.decode("1 hour")).toEqual(Duration.hours(1)) - expect(Duration.decode("10 hours")).toEqual(Duration.hours(10)) - expect(Duration.decode("1 day")).toEqual(Duration.days(1)) - expect(Duration.decode("10 days")).toEqual(Duration.days(10)) - expect(Duration.decode("1 week")).toEqual(Duration.weeks(1)) - expect(Duration.decode("10 weeks")).toEqual(Duration.weeks(10)) + deepStrictEqual(Duration.decode("1 nano"), Duration.nanos(1n)) + deepStrictEqual(Duration.decode("10 nanos"), Duration.nanos(10n)) + deepStrictEqual(Duration.decode("1 micro"), Duration.micros(1n)) + deepStrictEqual(Duration.decode("10 micros"), Duration.micros(10n)) + deepStrictEqual(Duration.decode("1 milli"), Duration.millis(1)) + deepStrictEqual(Duration.decode("10 millis"), Duration.millis(10)) + deepStrictEqual(Duration.decode("1 second"), Duration.seconds(1)) + deepStrictEqual(Duration.decode("10 seconds"), Duration.seconds(10)) + deepStrictEqual(Duration.decode("1 minute"), Duration.minutes(1)) + deepStrictEqual(Duration.decode("10 minutes"), Duration.minutes(10)) + deepStrictEqual(Duration.decode("1 hour"), Duration.hours(1)) + deepStrictEqual(Duration.decode("10 hours"), Duration.hours(10)) + deepStrictEqual(Duration.decode("1 day"), Duration.days(1)) + deepStrictEqual(Duration.decode("10 days"), Duration.days(10)) + deepStrictEqual(Duration.decode("1 week"), Duration.weeks(1)) + deepStrictEqual(Duration.decode("10 weeks"), Duration.weeks(10)) - expect(Duration.decode("1.5 seconds")).toEqual(Duration.seconds(1.5)) - expect(Duration.decode("-1.5 seconds")).toEqual(Duration.zero) + deepStrictEqual(Duration.decode("1.5 seconds"), Duration.seconds(1.5)) + deepStrictEqual(Duration.decode("-1.5 seconds"), Duration.zero) - expect(Duration.decode([500, 123456789])).toEqual(Duration.nanos(500123456789n)) - expect(Duration.decode([-500, 123456789])).toEqual(Duration.zero) + deepStrictEqual(Duration.decode([500, 123456789]), Duration.nanos(500123456789n)) + deepStrictEqual(Duration.decode([-500, 123456789]), Duration.zero) - expect(() => Duration.decode("1.5 secs" as any)).toThrowError(new Error("Invalid DurationInput")) - expect(() => Duration.decode(true as any)).toThrowError(new Error("Invalid DurationInput")) - expect(() => Duration.decode({} as any)).toThrowError(new Error("Invalid DurationInput")) + throws(() => Duration.decode("1.5 secs" as any), new Error("Invalid DurationInput")) + throws(() => Duration.decode(true as any), new Error("Invalid DurationInput")) + throws(() => Duration.decode({} as any), new Error("Invalid DurationInput")) }) it("decodeUnknown", () => { const millis100 = Duration.millis(100) - expect(Duration.decodeUnknown(millis100)).toEqual(Option.some(millis100)) + assertSome(Duration.decodeUnknown(millis100), millis100) - expect(Duration.decodeUnknown(100)).toEqual(Option.some(millis100)) + assertSome(Duration.decodeUnknown(100), millis100) - expect(Duration.decodeUnknown(10n)).toEqual(Option.some(Duration.nanos(10n))) + assertSome(Duration.decodeUnknown(10n), Duration.nanos(10n)) - expect(Duration.decodeUnknown("1 nano")).toEqual(Option.some(Duration.nanos(1n))) - expect(Duration.decodeUnknown("10 nanos")).toEqual(Option.some(Duration.nanos(10n))) - expect(Duration.decodeUnknown("1 micro")).toEqual(Option.some(Duration.micros(1n))) - expect(Duration.decodeUnknown("10 micros")).toEqual(Option.some(Duration.micros(10n))) - expect(Duration.decodeUnknown("1 milli")).toEqual(Option.some(Duration.millis(1))) - expect(Duration.decodeUnknown("10 millis")).toEqual(Option.some(Duration.millis(10))) - expect(Duration.decodeUnknown("1 second")).toEqual(Option.some(Duration.seconds(1))) - expect(Duration.decodeUnknown("10 seconds")).toEqual(Option.some(Duration.seconds(10))) - expect(Duration.decodeUnknown("1 minute")).toEqual(Option.some(Duration.minutes(1))) - expect(Duration.decodeUnknown("10 minutes")).toEqual(Option.some(Duration.minutes(10))) - expect(Duration.decodeUnknown("1 hour")).toEqual(Option.some(Duration.hours(1))) - expect(Duration.decodeUnknown("10 hours")).toEqual(Option.some(Duration.hours(10))) - expect(Duration.decodeUnknown("1 day")).toEqual(Option.some(Duration.days(1))) - expect(Duration.decodeUnknown("10 days")).toEqual(Option.some(Duration.days(10))) - expect(Duration.decodeUnknown("1 week")).toEqual(Option.some(Duration.weeks(1))) - expect(Duration.decodeUnknown("10 weeks")).toEqual(Option.some(Duration.weeks(10))) + assertSome(Duration.decodeUnknown("1 nano"), Duration.nanos(1n)) + assertSome(Duration.decodeUnknown("10 nanos"), Duration.nanos(10n)) + assertSome(Duration.decodeUnknown("1 micro"), Duration.micros(1n)) + assertSome(Duration.decodeUnknown("10 micros"), Duration.micros(10n)) + assertSome(Duration.decodeUnknown("1 milli"), Duration.millis(1)) + assertSome(Duration.decodeUnknown("10 millis"), Duration.millis(10)) + assertSome(Duration.decodeUnknown("1 second"), Duration.seconds(1)) + assertSome(Duration.decodeUnknown("10 seconds"), Duration.seconds(10)) + assertSome(Duration.decodeUnknown("1 minute"), Duration.minutes(1)) + assertSome(Duration.decodeUnknown("10 minutes"), Duration.minutes(10)) + assertSome(Duration.decodeUnknown("1 hour"), Duration.hours(1)) + assertSome(Duration.decodeUnknown("10 hours"), Duration.hours(10)) + assertSome(Duration.decodeUnknown("1 day"), Duration.days(1)) + assertSome(Duration.decodeUnknown("10 days"), Duration.days(10)) + assertSome(Duration.decodeUnknown("1 week"), Duration.weeks(1)) + assertSome(Duration.decodeUnknown("10 weeks"), Duration.weeks(10)) - expect(Duration.decodeUnknown("1.5 seconds")).toEqual(Option.some(Duration.seconds(1.5))) - expect(Duration.decodeUnknown("-1.5 seconds")).toEqual(Option.some(Duration.zero)) + assertSome(Duration.decodeUnknown("1.5 seconds"), Duration.seconds(1.5)) + assertSome(Duration.decodeUnknown("-1.5 seconds"), Duration.zero) - expect(Duration.decodeUnknown([500, 123456789])).toEqual(Option.some(Duration.nanos(500123456789n))) - expect(Duration.decodeUnknown([-500, 123456789])).toEqual(Option.some(Duration.zero)) + assertSome(Duration.decodeUnknown([500, 123456789]), Duration.nanos(500123456789n)) + assertSome(Duration.decodeUnknown([-500, 123456789]), Duration.zero) - expect(Duration.decodeUnknown("1.5 secs")).toEqual(Option.none()) - expect(Duration.decodeUnknown(true)).toEqual(Option.none()) - expect(Duration.decodeUnknown({})).toEqual(Option.none()) + assertNone(Duration.decodeUnknown("1.5 secs")) + assertNone(Duration.decodeUnknown(true)) + assertNone(Duration.decodeUnknown({})) }) it("Order", () => { @@ -128,194 +125,197 @@ describe("Duration", () => { Duration.minutes(1.5) ) - expect(Duration.clamp("1 millis", { - minimum: "2 millis", - maximum: "3 millis" - })).toStrictEqual(Duration.millis(2)) + deepStrictEqual( + Duration.clamp("1 millis", { + minimum: "2 millis", + maximum: "3 millis" + }), + Duration.millis(2) + ) }) it("equals", () => { - assert.isTrue(pipe(Duration.hours(1), Duration.equals(Duration.minutes(60)))) - expect(Duration.equals("2 seconds", "2 seconds")).toBe(true) - expect(Duration.equals("2 seconds", "3 seconds")).toBe(false) + assertTrue(pipe(Duration.hours(1), Duration.equals(Duration.minutes(60)))) + assertTrue(Duration.equals("2 seconds", "2 seconds")) + assertFalse(Duration.equals("2 seconds", "3 seconds")) }) it("between", () => { - assert.isTrue(Duration.between(Duration.hours(1), { + assertTrue(Duration.between(Duration.hours(1), { minimum: Duration.minutes(59), maximum: Duration.minutes(61) })) - assert.isTrue( + assertTrue( Duration.between(Duration.minutes(1), { minimum: Duration.seconds(59), maximum: Duration.seconds(61) }) ) - assert.isTrue(Duration.between("1 minutes", { + assertTrue(Duration.between("1 minutes", { minimum: "59 seconds", maximum: "61 seconds" })) }) it("divide", () => { - expect(Duration.divide(Duration.minutes(1), 2)).toEqual(Option.some(Duration.seconds(30))) - expect(Duration.divide(Duration.seconds(1), 3)).toEqual(Option.some(Duration.nanos(333333333n))) - expect(Duration.divide(Duration.nanos(2n), 2)).toEqual(Option.some(Duration.nanos(1n))) - expect(Duration.divide(Duration.nanos(1n), 3)).toEqual(Option.some(Duration.zero)) - expect(Duration.divide(Duration.infinity, 2)).toEqual(Option.some(Duration.infinity)) - expect(Duration.divide(Duration.zero, 2)).toEqual(Option.some(Duration.zero)) - expect(Duration.divide(Duration.minutes(1), 0)).toEqual(Option.none()) - expect(Duration.divide(Duration.minutes(1), -0)).toEqual(Option.none()) - expect(Duration.divide(Duration.nanos(1n), 0)).toEqual(Option.none()) - expect(Duration.divide(Duration.nanos(1n), -0)).toEqual(Option.none()) - expect(Duration.divide(Duration.minutes(1), 0.5)).toEqual(Option.some(Duration.minutes(2))) - expect(Duration.divide(Duration.minutes(1), 1.5)).toEqual(Option.some(Duration.seconds(40))) - expect(Duration.divide(Duration.minutes(1), NaN)).toEqual(Option.none()) - expect(Duration.divide(Duration.nanos(1n), 0.5)).toEqual(Option.none()) - expect(Duration.divide(Duration.nanos(1n), 1.5)).toEqual(Option.none()) - expect(Duration.divide(Duration.nanos(1n), NaN)).toEqual(Option.none()) - - expect(Duration.divide("1 minute", 2)).toEqual(Option.some(Duration.seconds(30))) + assertSome(Duration.divide(Duration.minutes(1), 2), Duration.seconds(30)) + assertSome(Duration.divide(Duration.seconds(1), 3), Duration.nanos(333333333n)) + assertSome(Duration.divide(Duration.nanos(2n), 2), Duration.nanos(1n)) + assertSome(Duration.divide(Duration.nanos(1n), 3), Duration.zero) + assertSome(Duration.divide(Duration.infinity, 2), Duration.infinity) + assertSome(Duration.divide(Duration.zero, 2), Duration.zero) + assertNone(Duration.divide(Duration.minutes(1), 0)) + assertNone(Duration.divide(Duration.minutes(1), -0)) + assertNone(Duration.divide(Duration.nanos(1n), 0)) + assertNone(Duration.divide(Duration.nanos(1n), -0)) + assertSome(Duration.divide(Duration.minutes(1), 0.5), Duration.minutes(2)) + assertSome(Duration.divide(Duration.minutes(1), 1.5), Duration.seconds(40)) + assertNone(Duration.divide(Duration.minutes(1), NaN)) + assertNone(Duration.divide(Duration.nanos(1n), 0.5)) + assertNone(Duration.divide(Duration.nanos(1n), 1.5)) + assertNone(Duration.divide(Duration.nanos(1n), NaN)) + + assertSome(Duration.divide("1 minute", 2), Duration.seconds(30)) }) it("unsafeDivide", () => { - expect(Duration.unsafeDivide(Duration.minutes(1), 2)).toEqual(Duration.seconds(30)) - expect(Duration.unsafeDivide(Duration.seconds(1), 3)).toEqual(Duration.nanos(333333333n)) - expect(Duration.unsafeDivide(Duration.nanos(2n), 2)).toEqual(Duration.nanos(1n)) - expect(Duration.unsafeDivide(Duration.nanos(1n), 3)).toEqual(Duration.zero) - expect(Duration.unsafeDivide(Duration.infinity, 2)).toEqual(Duration.infinity) - expect(Duration.unsafeDivide(Duration.zero, 2)).toEqual(Duration.zero) - expect(Duration.unsafeDivide(Duration.minutes(1), 0)).toEqual(Duration.infinity) - expect(Duration.unsafeDivide(Duration.minutes(1), -0)).toEqual(Duration.zero) - expect(Duration.unsafeDivide(Duration.nanos(1n), 0)).toEqual(Duration.infinity) - expect(Duration.unsafeDivide(Duration.nanos(1n), -0)).toEqual(Duration.zero) - expect(Duration.unsafeDivide(Duration.minutes(1), 0.5)).toEqual(Duration.minutes(2)) - expect(Duration.unsafeDivide(Duration.minutes(1), 1.5)).toEqual(Duration.seconds(40)) - expect(Duration.unsafeDivide(Duration.minutes(1), NaN)).toEqual(Duration.zero) - expect(() => Duration.unsafeDivide(Duration.nanos(1n), 0.5)).toThrow() - expect(() => Duration.unsafeDivide(Duration.nanos(1n), 1.5)).toThrow() - expect(Duration.unsafeDivide(Duration.nanos(1n), NaN)).toEqual(Duration.zero) - - expect(Duration.unsafeDivide("1 minute", 2)).toEqual(Duration.seconds(30)) + deepStrictEqual(Duration.unsafeDivide(Duration.minutes(1), 2), Duration.seconds(30)) + deepStrictEqual(Duration.unsafeDivide(Duration.seconds(1), 3), Duration.nanos(333333333n)) + deepStrictEqual(Duration.unsafeDivide(Duration.nanos(2n), 2), Duration.nanos(1n)) + deepStrictEqual(Duration.unsafeDivide(Duration.nanos(1n), 3), Duration.zero) + deepStrictEqual(Duration.unsafeDivide(Duration.infinity, 2), Duration.infinity) + deepStrictEqual(Duration.unsafeDivide(Duration.zero, 2), Duration.zero) + deepStrictEqual(Duration.unsafeDivide(Duration.minutes(1), 0), Duration.infinity) + deepStrictEqual(Duration.unsafeDivide(Duration.minutes(1), -0), Duration.zero) + deepStrictEqual(Duration.unsafeDivide(Duration.nanos(1n), 0), Duration.infinity) + deepStrictEqual(Duration.unsafeDivide(Duration.nanos(1n), -0), Duration.zero) + deepStrictEqual(Duration.unsafeDivide(Duration.minutes(1), 0.5), Duration.minutes(2)) + deepStrictEqual(Duration.unsafeDivide(Duration.minutes(1), 1.5), Duration.seconds(40)) + deepStrictEqual(Duration.unsafeDivide(Duration.minutes(1), NaN), Duration.zero) + throws(() => Duration.unsafeDivide(Duration.nanos(1n), 0.5)) + throws(() => Duration.unsafeDivide(Duration.nanos(1n), 1.5)) + deepStrictEqual(Duration.unsafeDivide(Duration.nanos(1n), NaN), Duration.zero) + + deepStrictEqual(Duration.unsafeDivide("1 minute", 2), Duration.seconds(30)) }) it("times", () => { - expect(Duration.times(Duration.seconds(1), 60)).toEqual(Duration.minutes(1)) - expect(Duration.times(Duration.nanos(2n), 10)).toEqual(Duration.nanos(20n)) - expect(Duration.times(Duration.seconds(Infinity), 60)).toEqual(Duration.seconds(Infinity)) + deepStrictEqual(Duration.times(Duration.seconds(1), 60), Duration.minutes(1)) + deepStrictEqual(Duration.times(Duration.nanos(2n), 10), Duration.nanos(20n)) + deepStrictEqual(Duration.times(Duration.seconds(Infinity), 60), Duration.seconds(Infinity)) - expect(Duration.times("1 seconds", 60)).toEqual(Duration.minutes(1)) + deepStrictEqual(Duration.times("1 seconds", 60), Duration.minutes(1)) }) it("sum", () => { - expect(Duration.sum(Duration.seconds(30), Duration.seconds(30))).toEqual(Duration.minutes(1)) - expect(Duration.sum(Duration.nanos(30n), Duration.nanos(30n))).toEqual(Duration.nanos(60n)) - expect(Duration.sum(Duration.seconds(Infinity), Duration.seconds(30))).toEqual(Duration.seconds(Infinity)) - expect(Duration.sum(Duration.seconds(30), Duration.seconds(Infinity))).toEqual(Duration.seconds(Infinity)) + deepStrictEqual(Duration.sum(Duration.seconds(30), Duration.seconds(30)), Duration.minutes(1)) + deepStrictEqual(Duration.sum(Duration.nanos(30n), Duration.nanos(30n)), Duration.nanos(60n)) + deepStrictEqual(Duration.sum(Duration.seconds(Infinity), Duration.seconds(30)), Duration.seconds(Infinity)) + deepStrictEqual(Duration.sum(Duration.seconds(30), Duration.seconds(Infinity)), Duration.seconds(Infinity)) - expect(Duration.sum("30 seconds", "30 seconds")).toEqual(Duration.minutes(1)) + deepStrictEqual(Duration.sum("30 seconds", "30 seconds"), Duration.minutes(1)) }) it("subtract", () => { - expect(Duration.subtract(Duration.seconds(30), Duration.seconds(10))).toEqual(Duration.seconds(20)) - expect(Duration.subtract(Duration.seconds(30), Duration.seconds(30))).toEqual(Duration.zero) - expect(Duration.subtract(Duration.nanos(30n), Duration.nanos(10n))).toEqual(Duration.nanos(20n)) - expect(Duration.subtract(Duration.nanos(30n), Duration.nanos(30n))).toEqual(Duration.zero) - expect(Duration.subtract(Duration.seconds(Infinity), Duration.seconds(30))).toEqual(Duration.seconds(Infinity)) - expect(Duration.subtract(Duration.seconds(30), Duration.seconds(Infinity))).toEqual(Duration.zero) + deepStrictEqual(Duration.subtract(Duration.seconds(30), Duration.seconds(10)), Duration.seconds(20)) + deepStrictEqual(Duration.subtract(Duration.seconds(30), Duration.seconds(30)), Duration.zero) + deepStrictEqual(Duration.subtract(Duration.nanos(30n), Duration.nanos(10n)), Duration.nanos(20n)) + deepStrictEqual(Duration.subtract(Duration.nanos(30n), Duration.nanos(30n)), Duration.zero) + deepStrictEqual(Duration.subtract(Duration.seconds(Infinity), Duration.seconds(30)), Duration.seconds(Infinity)) + deepStrictEqual(Duration.subtract(Duration.seconds(30), Duration.seconds(Infinity)), Duration.zero) - expect(Duration.subtract("30 seconds", "10 seconds")).toEqual(Duration.seconds(20)) + deepStrictEqual(Duration.subtract("30 seconds", "10 seconds"), Duration.seconds(20)) }) it("greaterThan", () => { - assert.isTrue(pipe(Duration.seconds(30), Duration.greaterThan(Duration.seconds(20)))) - assert.isFalse(pipe(Duration.seconds(30), Duration.greaterThan(Duration.seconds(30)))) - assert.isFalse(pipe(Duration.seconds(30), Duration.greaterThan(Duration.seconds(60)))) + assertTrue(pipe(Duration.seconds(30), Duration.greaterThan(Duration.seconds(20)))) + assertFalse(pipe(Duration.seconds(30), Duration.greaterThan(Duration.seconds(30)))) + assertFalse(pipe(Duration.seconds(30), Duration.greaterThan(Duration.seconds(60)))) - assert.isTrue(pipe(Duration.nanos(30n), Duration.greaterThan(Duration.nanos(20n)))) - assert.isFalse(pipe(Duration.nanos(30n), Duration.greaterThan(Duration.nanos(30n)))) - assert.isFalse(pipe(Duration.nanos(30n), Duration.greaterThan(Duration.nanos(60n)))) + assertTrue(pipe(Duration.nanos(30n), Duration.greaterThan(Duration.nanos(20n)))) + assertFalse(pipe(Duration.nanos(30n), Duration.greaterThan(Duration.nanos(30n)))) + assertFalse(pipe(Duration.nanos(30n), Duration.greaterThan(Duration.nanos(60n)))) - assert.isTrue(pipe(Duration.millis(1), Duration.greaterThan(Duration.nanos(1n)))) + assertTrue(pipe(Duration.millis(1), Duration.greaterThan(Duration.nanos(1n)))) - expect(Duration.greaterThan("2 seconds", "2 seconds")).toBe(false) - expect(Duration.greaterThan("3 seconds", "2 seconds")).toBe(true) - expect(Duration.greaterThan("2 seconds", "3 seconds")).toBe(false) + assertFalse(Duration.greaterThan("2 seconds", "2 seconds")) + assertTrue(Duration.greaterThan("3 seconds", "2 seconds")) + assertFalse(Duration.greaterThan("2 seconds", "3 seconds")) }) it("greaterThan - Infinity", () => { - assert.isTrue(pipe(Duration.infinity, Duration.greaterThan(Duration.seconds(20)))) - assert.isFalse(pipe(Duration.seconds(-Infinity), Duration.greaterThan(Duration.infinity))) - assert.isFalse(pipe(Duration.nanos(1n), Duration.greaterThan(Duration.infinity))) + assertTrue(pipe(Duration.infinity, Duration.greaterThan(Duration.seconds(20)))) + assertFalse(pipe(Duration.seconds(-Infinity), Duration.greaterThan(Duration.infinity))) + assertFalse(pipe(Duration.nanos(1n), Duration.greaterThan(Duration.infinity))) }) it("greaterThanOrEqualTo", () => { - assert.isTrue(pipe(Duration.seconds(30), Duration.greaterThanOrEqualTo(Duration.seconds(20)))) - assert.isTrue(pipe(Duration.seconds(30), Duration.greaterThanOrEqualTo(Duration.seconds(30)))) - assert.isFalse(pipe(Duration.seconds(30), Duration.greaterThanOrEqualTo(Duration.seconds(60)))) + assertTrue(pipe(Duration.seconds(30), Duration.greaterThanOrEqualTo(Duration.seconds(20)))) + assertTrue(pipe(Duration.seconds(30), Duration.greaterThanOrEqualTo(Duration.seconds(30)))) + assertFalse(pipe(Duration.seconds(30), Duration.greaterThanOrEqualTo(Duration.seconds(60)))) - assert.isTrue(pipe(Duration.nanos(30n), Duration.greaterThanOrEqualTo(Duration.nanos(20n)))) - assert.isTrue(pipe(Duration.nanos(30n), Duration.greaterThanOrEqualTo(Duration.nanos(30n)))) - assert.isFalse(pipe(Duration.nanos(30n), Duration.greaterThanOrEqualTo(Duration.nanos(60n)))) + assertTrue(pipe(Duration.nanos(30n), Duration.greaterThanOrEqualTo(Duration.nanos(20n)))) + assertTrue(pipe(Duration.nanos(30n), Duration.greaterThanOrEqualTo(Duration.nanos(30n)))) + assertFalse(pipe(Duration.nanos(30n), Duration.greaterThanOrEqualTo(Duration.nanos(60n)))) - expect(Duration.greaterThanOrEqualTo("2 seconds", "2 seconds")).toBe(true) - expect(Duration.greaterThanOrEqualTo("3 seconds", "2 seconds")).toBe(true) - expect(Duration.greaterThanOrEqualTo("2 seconds", "3 seconds")).toBe(false) + assertTrue(Duration.greaterThanOrEqualTo("2 seconds", "2 seconds")) + assertTrue(Duration.greaterThanOrEqualTo("3 seconds", "2 seconds")) + assertFalse(Duration.greaterThanOrEqualTo("2 seconds", "3 seconds")) }) it("lessThan", () => { - assert.isTrue(pipe(Duration.seconds(20), Duration.lessThan(Duration.seconds(30)))) - assert.isFalse(pipe(Duration.seconds(30), Duration.lessThan(Duration.seconds(30)))) - assert.isFalse(pipe(Duration.seconds(60), Duration.lessThan(Duration.seconds(30)))) + assertTrue(pipe(Duration.seconds(20), Duration.lessThan(Duration.seconds(30)))) + assertFalse(pipe(Duration.seconds(30), Duration.lessThan(Duration.seconds(30)))) + assertFalse(pipe(Duration.seconds(60), Duration.lessThan(Duration.seconds(30)))) - assert.isTrue(pipe(Duration.nanos(20n), Duration.lessThan(Duration.nanos(30n)))) - assert.isFalse(pipe(Duration.nanos(30n), Duration.lessThan(Duration.nanos(30n)))) - assert.isFalse(pipe(Duration.nanos(60n), Duration.lessThan(Duration.nanos(30n)))) + assertTrue(pipe(Duration.nanos(20n), Duration.lessThan(Duration.nanos(30n)))) + assertFalse(pipe(Duration.nanos(30n), Duration.lessThan(Duration.nanos(30n)))) + assertFalse(pipe(Duration.nanos(60n), Duration.lessThan(Duration.nanos(30n)))) - assert.isTrue(pipe(Duration.nanos(1n), Duration.lessThan(Duration.millis(1)))) + assertTrue(pipe(Duration.nanos(1n), Duration.lessThan(Duration.millis(1)))) - expect(Duration.lessThan("2 seconds", "2 seconds")).toBe(false) - expect(Duration.lessThan("3 seconds", "2 seconds")).toBe(false) - expect(Duration.lessThan("2 seconds", "3 seconds")).toBe(true) + assertFalse(Duration.lessThan("2 seconds", "2 seconds")) + assertFalse(Duration.lessThan("3 seconds", "2 seconds")) + assertTrue(Duration.lessThan("2 seconds", "3 seconds")) }) it("lessThanOrEqualTo", () => { - assert.isTrue(pipe(Duration.seconds(20), Duration.lessThanOrEqualTo(Duration.seconds(30)))) - assert.isTrue(pipe(Duration.seconds(30), Duration.lessThanOrEqualTo(Duration.seconds(30)))) - assert.isFalse(pipe(Duration.seconds(60), Duration.lessThanOrEqualTo(Duration.seconds(30)))) + assertTrue(pipe(Duration.seconds(20), Duration.lessThanOrEqualTo(Duration.seconds(30)))) + assertTrue(pipe(Duration.seconds(30), Duration.lessThanOrEqualTo(Duration.seconds(30)))) + assertFalse(pipe(Duration.seconds(60), Duration.lessThanOrEqualTo(Duration.seconds(30)))) - assert.isTrue(pipe(Duration.nanos(20n), Duration.lessThanOrEqualTo(Duration.nanos(30n)))) - assert.isTrue(pipe(Duration.nanos(30n), Duration.lessThanOrEqualTo(Duration.nanos(30n)))) - assert.isFalse(pipe(Duration.nanos(60n), Duration.lessThanOrEqualTo(Duration.nanos(30n)))) + assertTrue(pipe(Duration.nanos(20n), Duration.lessThanOrEqualTo(Duration.nanos(30n)))) + assertTrue(pipe(Duration.nanos(30n), Duration.lessThanOrEqualTo(Duration.nanos(30n)))) + assertFalse(pipe(Duration.nanos(60n), Duration.lessThanOrEqualTo(Duration.nanos(30n)))) - expect(Duration.lessThanOrEqualTo("2 seconds", "2 seconds")).toBe(true) - expect(Duration.lessThanOrEqualTo("3 seconds", "2 seconds")).toBe(false) - expect(Duration.lessThanOrEqualTo("2 seconds", "3 seconds")).toBe(true) + assertTrue(Duration.lessThanOrEqualTo("2 seconds", "2 seconds")) + assertFalse(Duration.lessThanOrEqualTo("3 seconds", "2 seconds")) + assertTrue(Duration.lessThanOrEqualTo("2 seconds", "3 seconds")) }) it("String()", () => { - expect(String(Duration.infinity)).toEqual(`Duration(Infinity)`) - expect(String(Duration.nanos(10n))).toEqual(`Duration(10ns)`) - expect(String(Duration.millis(2))).toEqual(`Duration(2ms)`) - expect(String(Duration.millis(2.125))).toEqual(`Duration(2ms 125000ns)`) - expect(String(Duration.seconds(2))).toEqual(`Duration(2s)`) - expect(String(Duration.seconds(2.5))).toEqual(`Duration(2s 500ms)`) + strictEqual(String(Duration.infinity), `Duration(Infinity)`) + strictEqual(String(Duration.nanos(10n)), `Duration(10ns)`) + strictEqual(String(Duration.millis(2)), `Duration(2ms)`) + strictEqual(String(Duration.millis(2.125)), `Duration(2ms 125000ns)`) + strictEqual(String(Duration.seconds(2)), `Duration(2s)`) + strictEqual(String(Duration.seconds(2.5)), `Duration(2s 500ms)`) }) it("format", () => { - expect(Duration.format(Duration.infinity)).toEqual(`Infinity`) - expect(Duration.format(Duration.minutes(5))).toEqual(`5m`) - expect(Duration.format(Duration.minutes(5.325))).toEqual(`5m 19s 500ms`) - expect(Duration.format(Duration.hours(3))).toEqual(`3h`) - expect(Duration.format(Duration.hours(3.11125))).toEqual(`3h 6m 40s 500ms`) - expect(Duration.format(Duration.days(2))).toEqual(`2d`) - expect(Duration.format(Duration.days(2.25))).toEqual(`2d 6h`) - expect(Duration.format(Duration.weeks(1))).toEqual(`7d`) + strictEqual(Duration.format(Duration.infinity), `Infinity`) + strictEqual(Duration.format(Duration.minutes(5)), `5m`) + strictEqual(Duration.format(Duration.minutes(5.325)), `5m 19s 500ms`) + strictEqual(Duration.format(Duration.hours(3)), `3h`) + strictEqual(Duration.format(Duration.hours(3.11125)), `3h 6m 40s 500ms`) + strictEqual(Duration.format(Duration.days(2)), `2d`) + strictEqual(Duration.format(Duration.days(2.25)), `2d 6h`) + strictEqual(Duration.format(Duration.weeks(1)), `7d`) }) it("format", () => { - expect(Duration.parts(Duration.infinity)).toStrictEqual({ + deepStrictEqual(Duration.parts(Duration.infinity), { days: Infinity, hours: Infinity, minutes: Infinity, @@ -324,7 +324,7 @@ describe("Duration", () => { nanos: Infinity }) - expect(Duration.parts(Duration.minutes(5.325))).toStrictEqual({ + deepStrictEqual(Duration.parts(Duration.minutes(5.325)), { days: 0, hours: 0, minutes: 5, @@ -333,7 +333,7 @@ describe("Duration", () => { nanos: 0 }) - expect(Duration.parts(Duration.minutes(3.11125))).toStrictEqual({ + deepStrictEqual(Duration.parts(Duration.minutes(3.11125)), { days: 0, hours: 0, minutes: 3, @@ -344,114 +344,104 @@ describe("Duration", () => { }) it("toJSON", () => { - expect(Duration.seconds(2).toJSON()).toEqual( - { _id: "Duration", _tag: "Millis", millis: 2000 } - ) + deepStrictEqual(Duration.seconds(2).toJSON(), { _id: "Duration", _tag: "Millis", millis: 2000 }) }) it("toJSON/ non-integer millis", () => { - expect(Duration.millis(1.5).toJSON()).toEqual( - { _id: "Duration", _tag: "Nanos", hrtime: [0, 1_500_000] } - ) + deepStrictEqual(Duration.millis(1.5).toJSON(), { _id: "Duration", _tag: "Nanos", hrtime: [0, 1_500_000] }) }) it("toJSON/ nanos", () => { - expect(Duration.nanos(5n).toJSON()).toEqual( - { _id: "Duration", _tag: "Nanos", hrtime: [0, 5] } - ) + deepStrictEqual(Duration.nanos(5n).toJSON(), { _id: "Duration", _tag: "Nanos", hrtime: [0, 5] }) }) it("toJSON/ infinity", () => { - expect(Duration.infinity.toJSON()).toEqual( - { _id: "Duration", _tag: "Infinity" } - ) + deepStrictEqual(Duration.infinity.toJSON(), { _id: "Duration", _tag: "Infinity" }) }) it(`inspect`, () => { if (typeof window === "undefined") { // eslint-disable-next-line @typescript-eslint/no-var-requires const { inspect } = require("node:util") - expect(inspect(Duration.millis(1000))).toEqual( - inspect({ _id: "Duration", _tag: "Millis", millis: 1000 }) - ) + deepStrictEqual(inspect(Duration.millis(1000)), inspect({ _id: "Duration", _tag: "Millis", millis: 1000 })) } }) it("sum/ Infinity", () => { - expect(Duration.sum(Duration.seconds(1), Duration.infinity)).toEqual(Duration.infinity) + deepStrictEqual(Duration.sum(Duration.seconds(1), Duration.infinity), Duration.infinity) }) it(".pipe()", () => { - expect(Duration.seconds(1).pipe(Duration.sum(Duration.seconds(1)))).toEqual(Duration.seconds(2)) + deepStrictEqual(Duration.seconds(1).pipe(Duration.sum(Duration.seconds(1))), Duration.seconds(2)) }) it("isDuration", () => { - expect(Duration.isDuration(Duration.millis(100))).toBe(true) - expect(Duration.isDuration(null)).toBe(false) + assertTrue(Duration.isDuration(Duration.millis(100))) + assertFalse(Duration.isDuration(null)) }) it("zero", () => { - expect(Duration.zero.value).toEqual({ _tag: "Millis", millis: 0 }) + deepStrictEqual(Duration.zero.value, { _tag: "Millis", millis: 0 }) }) it("infinity", () => { - expect(Duration.infinity.value).toEqual({ _tag: "Infinity" }) + deepStrictEqual(Duration.infinity.value, { _tag: "Infinity" }) }) it("weeks", () => { - expect(Equal.equals(Duration.weeks(1), Duration.days(7))).toBe(true) - expect(Equal.equals(Duration.weeks(1), Duration.days(1))).toBe(false) + assertTrue(Equal.equals(Duration.weeks(1), Duration.days(7))) + assertFalse(Equal.equals(Duration.weeks(1), Duration.days(1))) }) it("toMillis", () => { - expect(Duration.millis(1).pipe(Duration.toMillis)).toBe(1) - expect(Duration.nanos(1n).pipe(Duration.toMillis)).toBe(0.000001) - expect(Duration.infinity.pipe(Duration.toMillis)).toBe(Infinity) + strictEqual(Duration.millis(1).pipe(Duration.toMillis), 1) + strictEqual(Duration.nanos(1n).pipe(Duration.toMillis), 0.000001) + strictEqual(Duration.infinity.pipe(Duration.toMillis), Infinity) - expect(Duration.toMillis("1 millis")).toBe(1) + strictEqual(Duration.toMillis("1 millis"), 1) }) it("toSeconds", () => { - expect(Duration.millis(1).pipe(Duration.toSeconds)).toBe(0.001) - expect(Duration.nanos(1n).pipe(Duration.toSeconds)).toBe(1e-9) - expect(Duration.infinity.pipe(Duration.toSeconds)).toBe(Infinity) + strictEqual(Duration.millis(1).pipe(Duration.toSeconds), 0.001) + strictEqual(Duration.nanos(1n).pipe(Duration.toSeconds), 1e-9) + strictEqual(Duration.infinity.pipe(Duration.toSeconds), Infinity) - expect(Duration.toSeconds("1 seconds")).toBe(1) - expect(Duration.toSeconds("3 seconds")).toBe(3) - expect(Duration.toSeconds("3 minutes")).toBe(180) + strictEqual(Duration.toSeconds("1 seconds"), 1) + strictEqual(Duration.toSeconds("3 seconds"), 3) + strictEqual(Duration.toSeconds("3 minutes"), 180) }) it("toNanos", () => { - expect(Duration.nanos(1n).pipe(Duration.toNanos)).toEqual(Option.some(1n)) - expect(Duration.infinity.pipe(Duration.toNanos)).toEqual(Option.none()) - expect(Duration.millis(1.0005).pipe(Duration.toNanos)).toEqual(Option.some(1_000_500n)) - expect(Duration.millis(100).pipe(Duration.toNanos)).toEqual(Option.some(100_000_000n)) + assertSome(Duration.nanos(1n).pipe(Duration.toNanos), 1n) + assertNone(Duration.infinity.pipe(Duration.toNanos)) + assertSome(Duration.millis(1.0005).pipe(Duration.toNanos), 1_000_500n) + assertSome(Duration.millis(100).pipe(Duration.toNanos), 100_000_000n) - expect(Duration.toNanos("1 nanos")).toStrictEqual(Option.some(1n)) + assertSome(Duration.toNanos("1 nanos"), 1n) }) it("unsafeToNanos", () => { - expect(Duration.nanos(1n).pipe(Duration.unsafeToNanos)).toBe(1n) - expect(() => Duration.infinity.pipe(Duration.unsafeToNanos)).toThrow() - expect(Duration.millis(1.0005).pipe(Duration.unsafeToNanos)).toBe(1_000_500n) - expect(Duration.millis(100).pipe(Duration.unsafeToNanos)).toEqual(100_000_000n) + strictEqual(Duration.nanos(1n).pipe(Duration.unsafeToNanos), 1n) + throws(() => Duration.infinity.pipe(Duration.unsafeToNanos)) + strictEqual(Duration.millis(1.0005).pipe(Duration.unsafeToNanos), 1_000_500n) + strictEqual(Duration.millis(100).pipe(Duration.unsafeToNanos), 100_000_000n) - expect(Duration.unsafeToNanos("1 nanos")).toBe(1n) + strictEqual(Duration.unsafeToNanos("1 nanos"), 1n) }) it("toHrTime", () => { - expect(Duration.millis(1).pipe(Duration.toHrTime)).toEqual([0, 1_000_000]) - expect(Duration.nanos(1n).pipe(Duration.toHrTime)).toEqual([0, 1]) - expect(Duration.nanos(1_000_000_001n).pipe(Duration.toHrTime)).toEqual([1, 1]) - expect(Duration.millis(1001).pipe(Duration.toHrTime)).toEqual([1, 1_000_000]) - expect(Duration.infinity.pipe(Duration.toHrTime)).toEqual([Infinity, 0]) + deepStrictEqual(Duration.millis(1).pipe(Duration.toHrTime), [0, 1_000_000]) + deepStrictEqual(Duration.nanos(1n).pipe(Duration.toHrTime), [0, 1]) + deepStrictEqual(Duration.nanos(1_000_000_001n).pipe(Duration.toHrTime), [1, 1]) + deepStrictEqual(Duration.millis(1001).pipe(Duration.toHrTime), [1, 1_000_000]) + deepStrictEqual(Duration.infinity.pipe(Duration.toHrTime), [Infinity, 0]) - expect(Duration.toHrTime("1 millis")).toEqual([0, 1_000_000]) + deepStrictEqual(Duration.toHrTime("1 millis"), [0, 1_000_000]) }) it("floor is 0", () => { - expect(Duration.millis(-1)).toEqual(Duration.zero) - expect(Duration.nanos(-1n)).toEqual(Duration.zero) + deepStrictEqual(Duration.millis(-1), Duration.zero) + deepStrictEqual(Duration.nanos(-1n), Duration.zero) }) it("match", () => { @@ -459,65 +449,65 @@ describe("Duration", () => { onMillis: () => "millis", onNanos: () => "nanos" }) - expect(match(Duration.decode("100 millis"))).toEqual("millis") - expect(match(Duration.decode("10 nanos"))).toEqual("nanos") - expect(match(Duration.decode(Infinity))).toEqual("millis") + strictEqual(match(Duration.decode("100 millis")), "millis") + strictEqual(match(Duration.decode("10 nanos")), "nanos") + strictEqual(match(Duration.decode(Infinity)), "millis") - expect(match("100 millis")).toEqual("millis") + strictEqual(match("100 millis"), "millis") }) it("isFinite", () => { - expect(Duration.isFinite(Duration.millis(100))).toBe(true) - expect(Duration.isFinite(Duration.nanos(100n))).toBe(true) - expect(Duration.isFinite(Duration.infinity)).toBe(false) + assertTrue(Duration.isFinite(Duration.millis(100))) + assertTrue(Duration.isFinite(Duration.nanos(100n))) + assertFalse(Duration.isFinite(Duration.infinity)) }) it("isZero", () => { - expect(Duration.isZero(Duration.zero)).toBe(true) - expect(Duration.isZero(Duration.millis(0))).toBe(true) - expect(Duration.isZero(Duration.nanos(0n))).toBe(true) - expect(Duration.isZero(Duration.infinity)).toBe(false) - expect(Duration.isZero(Duration.millis(1))).toBe(false) - expect(Duration.isZero(Duration.nanos(1n))).toBe(false) + assertTrue(Duration.isZero(Duration.zero)) + assertTrue(Duration.isZero(Duration.millis(0))) + assertTrue(Duration.isZero(Duration.nanos(0n))) + assertFalse(Duration.isZero(Duration.infinity)) + assertFalse(Duration.isZero(Duration.millis(1))) + assertFalse(Duration.isZero(Duration.nanos(1n))) }) it("toMinutes", () => { - expect(Duration.millis(60000).pipe(Duration.toMinutes)).toBe(1) - expect(Duration.nanos(60000000000n).pipe(Duration.toMinutes)).toBe(1) - expect(Duration.infinity.pipe(Duration.toMinutes)).toBe(Infinity) + strictEqual(Duration.millis(60000).pipe(Duration.toMinutes), 1) + strictEqual(Duration.nanos(60000000000n).pipe(Duration.toMinutes), 1) + strictEqual(Duration.infinity.pipe(Duration.toMinutes), Infinity) - expect(Duration.toMinutes("1 minute")).toBe(1) - expect(Duration.toMinutes("2 minutes")).toBe(2) - expect(Duration.toMinutes("1 hour")).toBe(60) + strictEqual(Duration.toMinutes("1 minute"), 1) + strictEqual(Duration.toMinutes("2 minutes"), 2) + strictEqual(Duration.toMinutes("1 hour"), 60) }) it("toHours", () => { - expect(Duration.millis(3_600_000).pipe(Duration.toHours)).toBe(1) - expect(Duration.nanos(3_600_000_000_000n).pipe(Duration.toHours)).toBe(1) - expect(Duration.infinity.pipe(Duration.toHours)).toBe(Infinity) + strictEqual(Duration.millis(3_600_000).pipe(Duration.toHours), 1) + strictEqual(Duration.nanos(3_600_000_000_000n).pipe(Duration.toHours), 1) + strictEqual(Duration.infinity.pipe(Duration.toHours), Infinity) - expect(Duration.toHours("1 hour")).toBe(1) - expect(Duration.toHours("2 hours")).toBe(2) - expect(Duration.toHours("1 day")).toBe(24) + strictEqual(Duration.toHours("1 hour"), 1) + strictEqual(Duration.toHours("2 hours"), 2) + strictEqual(Duration.toHours("1 day"), 24) }) it("toDays", () => { - expect(Duration.millis(86_400_000).pipe(Duration.toDays)).toBe(1) - expect(Duration.nanos(86_400_000_000_000n).pipe(Duration.toDays)).toBe(1) - expect(Duration.infinity.pipe(Duration.toDays)).toBe(Infinity) + strictEqual(Duration.millis(86_400_000).pipe(Duration.toDays), 1) + strictEqual(Duration.nanos(86_400_000_000_000n).pipe(Duration.toDays), 1) + strictEqual(Duration.infinity.pipe(Duration.toDays), Infinity) - expect(Duration.toDays("1 day")).toBe(1) - expect(Duration.toDays("2 days")).toBe(2) - expect(Duration.toDays("1 week")).toBe(7) + strictEqual(Duration.toDays("1 day"), 1) + strictEqual(Duration.toDays("2 days"), 2) + strictEqual(Duration.toDays("1 week"), 7) }) it("toWeeks", () => { - expect(Duration.millis(604_800_000).pipe(Duration.toWeeks)).toBe(1) - expect(Duration.nanos(604_800_000_000_000n).pipe(Duration.toWeeks)).toBe(1) - expect(Duration.infinity.pipe(Duration.toWeeks)).toBe(Infinity) + strictEqual(Duration.millis(604_800_000).pipe(Duration.toWeeks), 1) + strictEqual(Duration.nanos(604_800_000_000_000n).pipe(Duration.toWeeks), 1) + strictEqual(Duration.infinity.pipe(Duration.toWeeks), Infinity) - expect(Duration.toWeeks("1 week")).toBe(1) - expect(Duration.toWeeks("2 weeks")).toBe(2) - expect(Duration.toWeeks("14 days")).toBe(2) + strictEqual(Duration.toWeeks("1 week"), 1) + strictEqual(Duration.toWeeks("2 weeks"), 2) + strictEqual(Duration.toWeeks("14 days"), 2) }) }) diff --git a/packages/effect/test/Effect/acquire-release.test.ts b/packages/effect/test/Effect/acquire-release.test.ts index 04d12e26c61..3c806769a31 100644 --- a/packages/effect/test/Effect/acquire-release.test.ts +++ b/packages/effect/test/Effect/acquire-release.test.ts @@ -5,8 +5,9 @@ import { equals } from "effect/Equal" import * as Exit from "effect/Exit" import { pipe } from "effect/Function" import * as Ref from "effect/Ref" +import { assertTrue, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("acquireUseRelease - happy path", () => @@ -20,8 +21,8 @@ describe("Effect", () => { ) ) const released = yield* $(Ref.get(release)) - assert.strictEqual(result, 43) - assert.isTrue(released) + strictEqual(result, 43) + assertTrue(released) })) it.effect("acquireUseRelease - happy path + disconnect", () => Effect.gen(function*($) { @@ -35,8 +36,8 @@ describe("Effect", () => { Effect.disconnect ) const released = yield* $(Ref.get(release)) - assert.strictEqual(result, 43) - assert.isTrue(released) + strictEqual(result, 43) + assertTrue(released) })) it.effect("acquireUseRelease - error handling", () => Effect.gen(function*($) { @@ -53,8 +54,8 @@ describe("Effect", () => { exit, Exit.matchEffect({ onFailure: Effect.succeed, onSuccess: () => Effect.fail("effect should have failed") }) ) - assert.isTrue(equals(Cause.failures(result), Chunk.of("use failed"))) - assert.isTrue(equals(Cause.defects(result), Chunk.of(releaseDied))) + assertTrue(equals(Cause.failures(result), Chunk.of("use failed"))) + assertTrue(equals(Cause.defects(result), Chunk.of(releaseDied))) })) it.effect("acquireUseRelease - error handling + disconnect", () => Effect.gen(function*($) { @@ -75,8 +76,8 @@ describe("Effect", () => { onSuccess: () => Effect.fail("effect should have failed") }) ) - assert.isTrue(equals(Cause.failures(result), Chunk.of("use failed"))) - assert.isTrue(equals(Cause.defects(result), Chunk.of(releaseDied))) + assertTrue(equals(Cause.failures(result), Chunk.of("use failed"))) + assertTrue(equals(Cause.defects(result), Chunk.of(releaseDied))) })) it.effect("acquireUseRelease - beast mode error handling + disconnect", () => Effect.gen(function*($) { @@ -105,7 +106,7 @@ describe("Effect", () => { ) ) const released = yield* $(Ref.get(release)) - assert.isTrue(equals(Cause.defects(result), Chunk.of(useDied))) - assert.isTrue(released) + assertTrue(equals(Cause.defects(result), Chunk.of(useDied))) + assertTrue(released) })) }) diff --git a/packages/effect/test/Effect/applicative.test.ts b/packages/effect/test/Effect/applicative.test.ts index 1d38ee58ce5..b3a55b9a6fd 100644 --- a/packages/effect/test/Effect/applicative.test.ts +++ b/packages/effect/test/Effect/applicative.test.ts @@ -1,7 +1,7 @@ import * as Effect from "effect/Effect" -import * as Either from "effect/Either" +import { assertLeft, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { const add = (a: number) => (b: number) => a + b @@ -9,7 +9,7 @@ describe("Effect", () => { it.effect("two successes should succeed", () => Effect.gen(function*($) { const result = yield* $(Effect.succeed(add).pipe(Effect.ap(Effect.succeed(1)), Effect.ap(Effect.succeed(2)))) - assert.strictEqual(result, 3) + strictEqual(result, 3) })) it.effect("one failure in data-last position should fail", () => @@ -18,7 +18,7 @@ describe("Effect", () => { Effect.succeed(add).pipe(Effect.ap(Effect.succeed(1)), Effect.ap(Effect.fail("c"))), Effect.either ) - assert.deepStrictEqual(result, Either.left("c")) + assertLeft(result, "c") })) it.effect("one failure in data-first position should fail", () => @@ -27,7 +27,7 @@ describe("Effect", () => { Effect.succeed(add).pipe(Effect.ap(Effect.fail("b")), Effect.ap(Effect.fail("c"))), Effect.either ) - assert.deepStrictEqual(result, Either.left("b")) + assertLeft(result, "b") })) it.effect("an applicative operation that starts with a failure should fail", () => @@ -39,6 +39,6 @@ describe("Effect", () => { ), Effect.either ) - assert.deepStrictEqual(result, Either.left("a")) + assertLeft(result, "a") })) }) diff --git a/packages/effect/test/Effect/async.test.ts b/packages/effect/test/Effect/async.test.ts index f82be95de52..33353ae4d03 100644 --- a/packages/effect/test/Effect/async.test.ts +++ b/packages/effect/test/Effect/async.test.ts @@ -9,7 +9,8 @@ import { pipe } from "effect/Function" import * as Option from "effect/Option" import * as Ref from "effect/Ref" import * as Runtime from "effect/Runtime" -import { assert, describe, it } from "effect/test/utils/extend" +import { assertNone, assertSome, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "effect/test/utils/extend" describe("Effect", () => { it.effect("simple async must return", () => @@ -17,14 +18,14 @@ describe("Effect", () => { const result = yield* $(Effect.async((cb) => { cb(Effect.succeed(42)) })) - assert.strictEqual(result, 42) + strictEqual(result, 42) })) it.effect("simple asyncEffect must return", () => Effect.gen(function*($) { const result = yield* $(Effect.asyncEffect((resume) => { return Effect.succeed(resume(Effect.succeed(42))) })) - assert.strictEqual(result, 42) + strictEqual(result, 42) })) if (typeof window === "undefined") { // eslint-disable-next-line @typescript-eslint/no-var-requires @@ -45,7 +46,7 @@ describe("Effect", () => { } const procNum = Effect.sync(() => os.cpus().length) const result = yield* $(procNum, Effect.flatMap(stackIOs)) - assert.strictEqual(result, 42) + strictEqual(result, 42) })) } it.effect("interrupt of asyncEffect register", () => @@ -68,7 +69,7 @@ describe("Effect", () => { yield* $(Deferred.await(acquire)) yield* $(Fiber.interruptFork(fiber)) const result = yield* $(Deferred.await(release)) - assert.isUndefined(result) + strictEqual(result, undefined) })) it.live("async should not resume fiber twice after interruption", () => Effect.gen(function*($) { @@ -91,8 +92,8 @@ describe("Effect", () => { ) const result = yield* $(Fiber.interrupt(fiber), Effect.timeout(Duration.seconds(1)), Effect.option) const unexpected = yield* $(Ref.get(unexpectedPlace)) - assert.deepStrictEqual(unexpected, Chunk.empty()) - assert.deepStrictEqual(result, Option.none()) // the timeout should happen + deepStrictEqual(unexpected, Chunk.empty()) + assertNone(result) // the timeout should happen })) it.live("async should not resume fiber twice after synchronous result", () => Effect.gen(function*($) { @@ -119,13 +120,13 @@ describe("Effect", () => { ) const result = yield* $(Fiber.interrupt(fiber), Effect.timeout(Duration.seconds(1)), Effect.option) const unexpected = yield* $(Ref.get(unexpectedPlace)) - assert.deepStrictEqual(unexpected, Chunk.empty()) - assert.deepStrictEqual(result, Option.none()) // timeout should happen + deepStrictEqual(unexpected, Chunk.empty()) + assertNone(result) // timeout should happen })) it.effect("sleep 0 must return", () => Effect.gen(function*($) { const result = yield* $(Effect.sleep(Duration.zero)) - assert.isUndefined(result) + strictEqual(result, undefined) })) it.effect("shallow bind of async chain", () => Effect.gen(function*($) { @@ -139,7 +140,7 @@ describe("Effect", () => { }) ) ), Effect.succeed(0))) - assert.strictEqual(result, 10) + strictEqual(result, 10) })) it.effect("asyncEffect can fail before registering", () => Effect.gen(function*($) { @@ -149,7 +150,7 @@ describe("Effect", () => { }), Effect.flip ) - assert.strictEqual(result, "ouch") + strictEqual(result, "ouch") })) it.effect("asyncEffect can defect before registering", () => Effect.gen(function*($) { @@ -170,6 +171,6 @@ describe("Effect", () => { onSuccess: () => Option.none() })) ) - assert.deepStrictEqual(result, Option.some("ouch")) + assertSome(result, "ouch") })) }) diff --git a/packages/effect/test/Effect/caching.test.ts b/packages/effect/test/Effect/caching.test.ts index 3c783ad80d4..a2e2318108e 100644 --- a/packages/effect/test/Effect/caching.test.ts +++ b/packages/effect/test/Effect/caching.test.ts @@ -2,9 +2,10 @@ import * as Duration from "effect/Duration" import * as Effect from "effect/Effect" import { pipe } from "effect/Function" import * as Ref from "effect/Ref" +import { assertTrue, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("cached - returns new instances after duration", () => @@ -21,9 +22,9 @@ describe("Effect", () => { const c = yield* $(cache) yield* $(TestClock.adjust(Duration.minutes(59))) const d = yield* $(cache) - assert.strictEqual(a, b) - assert.notStrictEqual(b, c) - assert.strictEqual(c, d) + strictEqual(a, b) + assertTrue(b !== c) + strictEqual(c, d) })) it.effect("cached - correctly handles an infinite duration time to live", () => Effect.gen(function*($) { @@ -35,9 +36,9 @@ describe("Effect", () => { const a = yield* $(cached) const b = yield* $(cached) const c = yield* $(cached) - assert.strictEqual(a, 0) - assert.strictEqual(b, 0) - assert.strictEqual(c, 0) + strictEqual(a, 0) + strictEqual(b, 0) + strictEqual(c, 0) })) it.effect("cachedInvalidate - returns new instances after duration", () => Effect.gen(function*($) { @@ -57,9 +58,9 @@ describe("Effect", () => { const d = yield* $(cached) yield* $(TestClock.adjust(Duration.minutes(59))) const e = yield* $(cached) - assert.strictEqual(a, b) - assert.notStrictEqual(b, c) - assert.strictEqual(c, d) - assert.notStrictEqual(d, e) + strictEqual(a, b) + assertTrue(b !== c) + strictEqual(c, d) + assertTrue(d !== e) })) }) diff --git a/packages/effect/test/Effect/cause-rendering.test.ts b/packages/effect/test/Effect/cause-rendering.test.ts index 80cf8d8ca98..085a619c72a 100644 --- a/packages/effect/test/Effect/cause-rendering.test.ts +++ b/packages/effect/test/Effect/cause-rendering.test.ts @@ -1,8 +1,7 @@ -import * as Cause from "effect/Cause" -import * as Effect from "effect/Effect" -import * as Option from "effect/Option" +import { Cause, Effect, Option } from "effect" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("Cause should include span data", () => @@ -15,10 +14,10 @@ describe("Effect", () => { ) ))) const rendered = Cause.pretty(cause) - assert.include(rendered, "spanA") - assert.include(rendered, "cause-rendering.test.ts:12") - assert.include(rendered, "spanB") - assert.include(rendered, "cause-rendering.test.ts:11") + assertTrue(rendered.includes("spanA")) + assertTrue(rendered.includes("cause-rendering.test.ts:11:18")) + assertTrue(rendered.includes("spanB")) + assertTrue(rendered.includes("cause-rendering.test.ts:10:16")) })) it.effect("catchTag should not invalidate traces", () => Effect.gen(function*($) { @@ -39,12 +38,12 @@ describe("Effect", () => { ).pipe(Effect.catchTag("E2", (e) => Effect.die(e))) const cause = yield* $(Effect.flip(Effect.sandbox(effect))) const rendered = Cause.pretty(cause) - assert.include(rendered, "spanA") - assert.include(rendered, "spanB") + assertTrue(rendered.includes("spanA")) + assertTrue(rendered.includes("spanB")) const obj = Option.getOrThrow(Cause.failureOption(cause)) - assert.isTrue(obj instanceof E1) - assert.isFalse(err === obj) - assert.isTrue(err === Cause.originalError(obj)) + assertTrue(obj instanceof E1) + assertFalse(err === obj) + assertTrue(err === Cause.originalError(obj)) })) it.effect("refail should not invalidate traces", () => Effect.gen(function*($) { @@ -64,8 +63,8 @@ describe("Effect", () => { ).pipe(Effect.catchAll((e) => Effect.fail(e))) const cause = yield* $(Effect.flip(Effect.sandbox(effect))) const rendered = Cause.pretty(cause) - assert.include(rendered, "spanA") - assert.include(rendered, "spanB") + assertTrue(rendered.includes("spanA")) + assertTrue(rendered.includes("spanB")) })) it.effect("catchTags should not invalidate traces", () => Effect.gen(function*($) { @@ -85,8 +84,8 @@ describe("Effect", () => { ).pipe(Effect.catchTags({ E2: (e) => Effect.die(e) })) const cause = yield* $(Effect.flip(Effect.sandbox(effect))) const rendered = Cause.pretty(cause) - assert.include(rendered, "spanA") - assert.include(rendered, "spanB") + assertTrue(rendered.includes("spanA")) + assertTrue(rendered.includes("spanB")) })) it.effect("shows line where error was created", () => Effect.gen(function*($) { @@ -98,7 +97,7 @@ describe("Effect", () => { Effect.flip ) const pretty = Cause.pretty(cause) - assert.include(pretty, "cause-rendering.test.ts") + assertTrue(pretty.includes("cause-rendering.test.ts")) })) it.effect("functionWithSpan PrettyError stack", () => @@ -109,13 +108,13 @@ describe("Effect", () => { }) const cause = yield* fail(123).pipe(Effect.sandbox, Effect.flip) const prettyErrors = Cause.prettyErrors(cause) - assert.strictEqual(prettyErrors.length, 1) + strictEqual(prettyErrors.length, 1) const error = prettyErrors[0] - assert.strictEqual(error.name, "Error") - assert.notInclude(error.stack, "/internal/") - assert.include(error.stack, "cause-rendering.test.ts:107") - assert.include(error.stack, "span-123") - assert.include(error.stack, "cause-rendering.test.ts:110") + strictEqual(error.name, "Error") + assertTrue(!error.stack?.includes("/internal/")) + assertTrue(error.stack?.includes("cause-rendering.test.ts:106")) + assertTrue(error.stack?.includes("span-123")) + assertTrue(error.stack?.includes("cause-rendering.test.ts:109")) })) it.effect("includes span name in stack", () => @@ -124,7 +123,7 @@ describe("Effect", () => { options: (n) => ({ name: `fn-${n}` }), body: (a: number) => Effect.sync(() => { - assert.strictEqual(a, 2) + strictEqual(a, 2) }) }) const cause = yield* fn(0).pipe( @@ -132,7 +131,7 @@ describe("Effect", () => { Effect.flip ) const prettyErrors = Cause.prettyErrors(cause) - assert.include(prettyErrors[0].stack ?? "", "at fn-0 ") + assertTrue(prettyErrors[0].stack?.includes("at fn-0 ")) })) // ENABLE TO TEST EXPECT OUTPUT @@ -149,7 +148,7 @@ describe("Effect", () => { Effect.flip ) const pretty = Cause.pretty(cause) - assert.isTrue(pretty.startsWith(`Error: Multi-line + assertTrue(pretty.startsWith(`Error: Multi-line error message at`)) @@ -162,7 +161,7 @@ message Effect.flip ) const pretty = Cause.pretty(cause, { renderErrorCause: true }) - assert.include(pretty, "[cause]: Error: child") + assertTrue(pretty.includes("[cause]: Error: child")) })) it.effect("pretty nested cause", () => @@ -174,7 +173,7 @@ message Effect.flip ) const pretty = Cause.pretty(cause, { renderErrorCause: true }) - assert.include(pretty, "[cause]: Error: child") - assert.include(pretty, "[cause]: Error: child2") + assertTrue(pretty.includes("[cause]: Error: child")) + assertTrue(pretty.includes("[cause]: Error: child2")) })) }) diff --git a/packages/effect/test/Effect/collecting.test.ts b/packages/effect/test/Effect/collecting.test.ts index 1abd7cde3f8..d6c9bbc2884 100644 --- a/packages/effect/test/Effect/collecting.test.ts +++ b/packages/effect/test/Effect/collecting.test.ts @@ -1,8 +1,9 @@ import * as Cause from "effect/Cause" import * as Effect from "effect/Effect" import * as Ref from "effect/Ref" +import { deepStrictEqual, notDeepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { describe("all", () => { @@ -12,7 +13,7 @@ describe("Effect", () => { const result = yield* $(Effect.all([1, 2, 3].map(Effect.succeed), { concurrency: "unbounded" })) - assert.deepStrictEqual(Array.from(result), [1, 2, 3]) + deepStrictEqual(Array.from(result), [1, 2, 3]) })) it.effect("concurrency > 1", () => @@ -20,7 +21,7 @@ describe("Effect", () => { const result = yield* $(Effect.all([1, 2, 3].map(Effect.succeed), { concurrency: 2 })) - assert.deepStrictEqual(Array.from(result), [1, 2, 3]) + deepStrictEqual(Array.from(result), [1, 2, 3]) })) }) @@ -30,7 +31,7 @@ describe("Effect", () => { const op = Ref.getAndUpdate(counter, (n) => n + 1) const ops3 = Effect.all([op, op, op], { concurrency: "unbounded" }) const result = yield* $(ops3, Effect.zip(ops3, { concurrent: true })) - assert.notDeepEqual(Array.from(result[0]), Array.from(result[1])) + notDeepStrictEqual(Array.from(result[0]), Array.from(result[1])) })) it.effect("preserves failures", () => @@ -42,7 +43,7 @@ describe("Effect", () => { }), Effect.flip ) - assert.deepStrictEqual(result, new Cause.RuntimeException()) + deepStrictEqual(result, new Cause.RuntimeException()) })) }) }) diff --git a/packages/effect/test/Effect/concurrency.test.ts b/packages/effect/test/Effect/concurrency.test.ts index 4ed3586f665..b848738364a 100644 --- a/packages/effect/test/Effect/concurrency.test.ts +++ b/packages/effect/test/Effect/concurrency.test.ts @@ -6,10 +6,11 @@ import * as Exit from "effect/Exit" import * as Fiber from "effect/Fiber" import { pipe } from "effect/Function" import * as Ref from "effect/Ref" +import { assertFalse, assertLeft, assertRight, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import { withLatch } from "effect/test/utils/latch" import { adjust } from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" export const ExampleError = new Error("Oh noes!") @@ -37,12 +38,12 @@ describe("Effect", () => { it.effect("shallow fork/join identity", () => Effect.gen(function*($) { const result = yield* $(Effect.succeed(42), Effect.fork, Effect.flatMap(Fiber.join)) - assert.strictEqual(result, 42) + strictEqual(result, 42) })) it.effect("deep fork/join identity", () => Effect.gen(function*($) { const result = yield* $(concurrentFib(20)) - assert.strictEqual(result, fib(20)) + strictEqual(result, fib(20)) })) it.effect("asyncEffect creation is interruptible", () => Effect.gen(function*($) { @@ -62,7 +63,7 @@ describe("Effect", () => { yield* $(Deferred.await(acquire)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Deferred.await(release)) - assert.strictEqual(result, 42) + strictEqual(result, 42) })) it.effect("daemon fiber is unsupervised", () => Effect.gen(function*($) { @@ -80,7 +81,7 @@ describe("Effect", () => { const fiber2 = yield* $(Fiber.join(fiber1)) const result = yield* $(Ref.get(ref)) yield* $(Fiber.interrupt(fiber2)) - assert.isFalse(result) + assertFalse(result) })) it.effect("daemon fiber race interruption", () => Effect.gen(function*($) { @@ -106,7 +107,7 @@ describe("Effect", () => { ) ) const result = yield* $(Ref.get(interruptionRef)) - assert.strictEqual(result, 2) + strictEqual(result, 2) })) it.effect("race in daemon is executed", () => Effect.gen(function*($) { @@ -130,8 +131,8 @@ describe("Effect", () => { yield* $(Fiber.interrupt(fiber)) const res1 = yield* $(Deferred.await(deferred1)) const res2 = yield* $(Deferred.await(deferred2)) - assert.isUndefined(res1) - assert.isUndefined(res2) + strictEqual(res1, undefined) + strictEqual(res2, undefined) })) it.live("supervise fibers", () => Effect.gen(function*($) { @@ -155,27 +156,27 @@ describe("Effect", () => { ) ) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 2) + strictEqual(result, 2) })) it.effect("race of fail with success", () => Effect.gen(function*($) { const result = yield* $(Effect.fail(42), Effect.race(Effect.succeed(24)), Effect.either) - assert.deepStrictEqual(result, Either.right(24)) + assertRight(result, 24) })) it.effect("race of terminate with success", () => Effect.gen(function*($) { const result = yield* $(Effect.dieSync(() => new Error()), Effect.race(Effect.succeed(24))) - assert.strictEqual(result, 24) + strictEqual(result, 24) })) it.effect("race of fail with fail", () => Effect.gen(function*($) { const result = yield* $(Effect.fail(42), Effect.race(Effect.fail(24)), Effect.either) - assert.deepStrictEqual(result, Either.left(42)) + assertLeft(result, 42) })) it.effect("race of value and never", () => Effect.gen(function*($) { const result = yield* $(Effect.succeed(42), Effect.race(Effect.never)) - assert.strictEqual(result, 42) + strictEqual(result, 42) })) it.effect("race in uninterruptible region", () => Effect.gen(function*($) { @@ -188,9 +189,9 @@ describe("Effect", () => { ) yield* $(Deferred.await(latch)) yield* $(adjust("30 seconds")) - assert.isTrue(fiber.unsafePoll() === null) + strictEqual(fiber.unsafePoll(), null) yield* $(adjust("60 seconds")) - assert.isFalse(fiber.unsafePoll() === null) + assertTrue(fiber.unsafePoll() !== null) }), 20_000) it.effect("race of two forks does not interrupt winner", () => Effect.gen(function*($) { @@ -225,7 +226,7 @@ describe("Effect", () => { Effect.zipRight(Ref.get(interrupted)) ) ) - assert.equal(count, 2) + strictEqual(count, 2) })) it.effect("firstSuccessOf of values", () => Effect.gen(function*($) { @@ -236,7 +237,7 @@ describe("Effect", () => { ]), Effect.either ) - assert.deepStrictEqual(result, Either.right(100)) + assertRight(result, 100) })) it.live("firstSuccessOf of failures", () => Effect.gen(function*($) { @@ -248,7 +249,7 @@ describe("Effect", () => { Effect.either ) - assert.deepStrictEqual(result, Either.left(101)) + assertLeft(result, 101) })) it.live("firstSuccessOf of failures & 1 success", () => Effect.gen(function*($) { @@ -259,7 +260,7 @@ describe("Effect", () => { ]), Effect.either ) - assert.deepStrictEqual(result, Either.right(102)) + assertRight(result, 102) })) it.effect("raceFirst interrupts loser on success", () => Effect.gen(function*($) { @@ -273,7 +274,7 @@ describe("Effect", () => { ) yield* $(winner, Effect.raceFirst(loser)) const result = yield* $(Deferred.await(effect)) - assert.strictEqual(result, 42) + strictEqual(result, 42) })) it.effect("raceFirst interrupts loser on failure", () => Effect.gen(function*($) { @@ -287,28 +288,28 @@ describe("Effect", () => { ) yield* $(winner, Effect.raceFirst(loser), Effect.either) const result = yield* $(Deferred.await(effect)) - assert.strictEqual(result, 42) + strictEqual(result, 42) })) it.effect("mergeAll", () => Effect.gen(function*($) { const result = yield* $( pipe(["a", "aa", "aaa", "aaaa"].map((a) => Effect.succeed(a)), Effect.mergeAll(0, (b, a) => b + a.length)) ) - assert.strictEqual(result, 10) + strictEqual(result, 10) })) it.effect("mergeAll - empty", () => Effect.gen(function*($) { const result = yield* $( pipe([] as ReadonlyArray>, Effect.mergeAll(0, (b, a) => b + a)) ) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("reduceEffect", () => Effect.gen(function*($) { const result = yield* $( pipe([2, 3, 4].map((n) => Effect.succeed(n)), Effect.reduceEffect(Effect.succeed(1), (acc, a) => acc + a)) ) - assert.strictEqual(result, 10) + strictEqual(result, 10) })) it.effect("reduceEffect - empty list", () => Effect.gen(function*($) { @@ -318,16 +319,16 @@ describe("Effect", () => { Effect.reduceEffect(Effect.succeed(1), (acc, a) => acc + a) ) ) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("timeout of failure", () => Effect.gen(function*($) { const result = yield* $(Effect.fail("uh oh"), Effect.timeout(Duration.hours(1)), Effect.exit) - assert.deepStrictEqual(result, Exit.fail("uh oh")) + deepStrictEqual(result, Exit.fail("uh oh")) })) it.effect("timeout of terminate", () => Effect.gen(function*($) { const result = yield* $(Effect.die(ExampleError), Effect.timeout(Duration.hours(1)), Effect.exit) - assert.deepStrictEqual(result, Exit.die(ExampleError)) + deepStrictEqual(result, Exit.die(ExampleError)) })) }) diff --git a/packages/effect/test/Effect/constructors.test.ts b/packages/effect/test/Effect/constructors.test.ts index 386264f60bc..cc98b6c119e 100644 --- a/packages/effect/test/Effect/constructors.test.ts +++ b/packages/effect/test/Effect/constructors.test.ts @@ -1,18 +1,18 @@ import * as Effect from "effect/Effect" -import * as Option from "effect/Option" +import { assertNone, assertSome, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("can lift a value to an option", () => Effect.gen(function*($) { const result = yield* $(Effect.succeedSome(42)) - assert.deepStrictEqual(result, Option.some(42)) + assertSome(result, 42) })) it.effect("using the none value", () => Effect.gen(function*($) { const result = yield* $(Effect.succeedNone) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("can use .pipe for composition", () => Effect.gen(function*(_) { @@ -26,7 +26,7 @@ describe("Effect", () => { ), Effect.tap((n) => Effect.sync(() => { - assert.strictEqual(n, 3) + strictEqual(n, 3) }) ) )) @@ -40,7 +40,7 @@ describe("Effect", () => { const instance = new MyService() return Effect.map(instance.compute, (n) => { - assert.strictEqual(n, 2) + strictEqual(n, 2) }) }) }) diff --git a/packages/effect/test/Effect/destructors.test.ts b/packages/effect/test/Effect/destructors.test.ts index 24717e2e177..d658327d7da 100644 --- a/packages/effect/test/Effect/destructors.test.ts +++ b/packages/effect/test/Effect/destructors.test.ts @@ -1,10 +1,18 @@ import * as Cause from "effect/Cause" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" -import * as Exit from "effect/Exit" import * as Option from "effect/Option" +import { + assertFailure, + assertFalse, + assertLeft, + assertNone, + assertRight, + assertSome, + assertTrue, + strictEqual +} from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" const ExampleError = new Error("Oh noes!") @@ -12,72 +20,72 @@ describe("Effect", () => { it.effect("head - on non empty list", () => Effect.gen(function*($) { const result = yield* $(Effect.succeed([1, 2, 3]), Effect.head, Effect.either) - assert.deepStrictEqual(result, Either.right(1)) + assertRight(result, 1) })) it.effect("head - on empty list", () => Effect.gen(function*($) { const result = yield* $(Effect.succeed([] as ReadonlyArray), Effect.head, Effect.option) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("head - on failure", () => Effect.gen(function*($) { const result = yield* $(Effect.fail("fail"), Effect.head, Effect.either) - assert.deepStrictEqual(result, Either.left("fail")) + assertLeft(result, "fail") })) it.effect("isFailure - returns true when the effect is a failure", () => Effect.gen(function*($) { const result = yield* $(Effect.isFailure(Effect.fail("fail"))) - assert.isTrue(result) + assertTrue(result) })) it.effect("isFailure - returns false when the effect is a success", () => Effect.gen(function*($) { const result = yield* $(Effect.isFailure(Effect.succeed("succeed"))) - assert.isFalse(result) + assertFalse(result) })) it.effect("isSuccess - returns false when the effect is a failure", () => Effect.gen(function*($) { const result = yield* $(Effect.isSuccess(Effect.fail("fail"))) - assert.isFalse(result) + assertFalse(result) })) it.effect("isSuccess - returns true when the effect is a success", () => Effect.gen(function*($) { const result = yield* $(Effect.isSuccess(Effect.succeed("succeed"))) - assert.isTrue(result) + assertTrue(result) })) it.effect("none - on Some fails with NoSuchElementException", () => Effect.gen(function*($) { const result = yield* $(Effect.exit(Effect.none(Effect.succeed(Option.some(1))))) - assert.deepStrictEqual(result, Exit.fail(new Cause.NoSuchElementException())) + assertFailure(result, Cause.fail(new Cause.NoSuchElementException())) })) it.effect("none - on None succeeds with undefined", () => Effect.gen(function*($) { const result = yield* $(Effect.none(Effect.succeed(Option.none()))) - assert.isUndefined(result) + strictEqual(result, undefined) })) it.effect("none - fails with ex when effect fails with ex", () => Effect.gen(function*($) { const error = new Cause.RuntimeException("failed task") const result = yield* $(Effect.exit(Effect.none(Effect.fail(error)))) - assert.deepStrictEqual(result, Exit.fail(error)) + assertFailure(result, Cause.fail(error)) })) it.effect("option - return success in Some", () => Effect.gen(function*($) { const result = yield* $(Effect.option(Effect.succeed(11))) - assert.deepStrictEqual(result, Option.some(11)) + assertSome(result, 11) })) it.effect("option - return failure as None", () => Effect.gen(function*($) { const result = yield* $(Effect.option(Effect.fail(123))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("option - not catch throwable", () => Effect.gen(function*($) { const result = yield* $(Effect.exit(Effect.option(Effect.die(ExampleError)))) - assert.deepStrictEqual(result, Exit.die(ExampleError)) + assertFailure(result, Cause.die(ExampleError)) })) it.effect("option - catch throwable after sandboxing", () => Effect.gen(function*($) { const result = yield* $(Effect.option(Effect.sandbox(Effect.die(ExampleError)))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) }) diff --git a/packages/effect/test/Effect/environment.test.ts b/packages/effect/test/Effect/environment.test.ts index 67b2941c193..c5dbed9f1bc 100644 --- a/packages/effect/test/Effect/environment.test.ts +++ b/packages/effect/test/Effect/environment.test.ts @@ -2,8 +2,9 @@ import * as Context from "effect/Context" import * as Effect from "effect/Effect" import { pipe } from "effect/Function" import * as Layer from "effect/Layer" +import { deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe, expect } from "vitest" +import { describe } from "vitest" interface NumberService { readonly n: number @@ -55,7 +56,7 @@ describe("Effect", () => { Effect.provide(runtime), Effect.provideService(NumberService, { n: 1 }) ) - expect(env).toStrictEqual({ n: 1 }) + deepStrictEqual(env, { n: 1 }) })) describe("and Then", () => { it.effect("effect tag", () => @@ -65,9 +66,9 @@ describe("Effect", () => { Effect.andThen(Effect.succeed("a"), DemoTag.strings), Effect.andThen(Effect.succeed("a"), DemoTag.fn) ])) - expect(n).toEqual([0, 1]) - expect(s).toEqual(["a", "b"]) - expect(z).toEqual(["a"]) + deepStrictEqual(n, [0, 1]) + deepStrictEqual(s, ["a", "b"]) + deepStrictEqual(z, ["a"]) }).pipe(Effect.provideService(DemoTag, { getNumbers: () => [0, 1], strings: ["a", "b"], @@ -86,12 +87,12 @@ describe("Effect", () => { ])) const s2 = yield* $(DemoTag.pipe(Effect.map((_) => _.strings))) const s3 = yield* $(DemoTag.use((_) => _.fnGen("hello"))) - expect(n).toEqual([0, 1]) - expect(s).toEqual(["a", "b"]) - expect(z).toEqual(["a", "b", "c"]) - expect(zUnion).toEqual([1]) - expect(s2).toEqual(["a", "b"]) - expect(s3).toEqual(["hello"]) + deepStrictEqual(n, [0, 1]) + deepStrictEqual(s, ["a", "b"]) + deepStrictEqual(z, ["a", "b", "c"]) + deepStrictEqual(zUnion, [1]) + deepStrictEqual(s2, ["a", "b"]) + deepStrictEqual(s3, ["hello"]) }).pipe(Effect.provideService(DemoTag, { getNumbers: () => [0, 1], strings: ["a", "b"], @@ -101,12 +102,12 @@ describe("Effect", () => { }))) it.effect("effect tag with primitives", () => Effect.gen(function*($) { - expect(yield* $(DateTag.getTime())).toEqual(DateTag.date.getTime()) - expect(yield* $(NumberTag)).toEqual(100) - expect(Array.from(yield* $(MapTag.keys()))).toEqual([]) + strictEqual(yield* $(DateTag.getTime()), DateTag.date.getTime()) + strictEqual(yield* $(NumberTag), 100) + deepStrictEqual(Array.from(yield* $(MapTag.keys())), []) yield* $(MapTag.set("foo", "bar")) - expect(Array.from(yield* $(MapTag.keys()))).toEqual(["foo"]) - expect(yield* $(MapTag.get("foo"))).toEqual("bar") + deepStrictEqual(Array.from(yield* $(MapTag.keys())), ["foo"]) + strictEqual(yield* $(MapTag.get("foo")), "bar") }).pipe( Effect.provide(Layer.mergeAll( DateTag.Live, @@ -133,9 +134,9 @@ describe("Effect", () => { ) ) const v3 = yield* $(NumberService) - assert.strictEqual(v1.n, 4) - assert.strictEqual(v2.n, 2) - assert.strictEqual(v3.n, 4) + strictEqual(v1.n, 4) + strictEqual(v2.n, 2) + strictEqual(v3.n, 4) }), Effect.provide(Context.make(NumberService, { n: 4 })) )) @@ -144,8 +145,8 @@ describe("Effect", () => { Effect.gen(function*($) { const v1 = yield* $(NumberService) const v2 = yield* $(StringService) - assert.strictEqual(v1.n, 1) - assert.strictEqual(v2.s, "ok") + strictEqual(v1.n, 1) + strictEqual(v2.s, "ok") }), Effect.provide(Context.make(NumberService, { n: 1 })), Effect.provide(Context.make(NumberService, { n: 2 })), @@ -157,7 +158,7 @@ describe("Effect", () => { Effect.async((cb) => cb(Effect.map(NumberService, ({ n }) => n))), Effect.provide(Context.make(NumberService, { n: 10 })) ) - assert.strictEqual(result, 10) + strictEqual(result, 10) })) it.effect("serviceWith - effectfully accesses a service in the environment", () => Effect.gen(function*($) { @@ -165,7 +166,7 @@ describe("Effect", () => { Effect.flatMap(NumberService, ({ n }) => Effect.succeed(n + 3)), Effect.provide(Context.make(NumberService, { n: 0 })) ) - assert.strictEqual(result, 3) + strictEqual(result, 3) })) // TODO: remove // it.effect("serviceWith - traced tag", () => @@ -174,15 +175,15 @@ describe("Effect", () => { // Effect.flatMap(NumberService.traced(sourceLocation(new Error())), ({ n }) => Effect.succeed(n + 3)), // Effect.provide(Context.make(NumberService, { n: 0 })) // ) - // assert.strictEqual(result, 3) + // strictEqual(result, 3) // })) it.effect("updateService - updates a service in the environment", () => pipe( Effect.gen(function*($) { const a = yield* $(NumberService, Effect.updateService(NumberService, ({ n }) => ({ n: n + 1 }))) const b = yield* $(NumberService) - assert.strictEqual(a.n, 1) - assert.strictEqual(b.n, 0) + strictEqual(a.n, 1) + strictEqual(b.n, 0) }), Effect.provide(pipe(Context.make(NumberService, { n: 0 }))) )) @@ -195,7 +196,7 @@ describe("Effect", () => { const { foo } = Effect.serviceFunctions(Service) return pipe( Effect.gen(function*(_) { - expect(yield* _(foo("a", 3))).toEqual("a3") + strictEqual(yield* _(foo("a", 3)), "a3") }), Effect.provideService( Service, @@ -214,7 +215,7 @@ describe("Effect", () => { const { baz } = Effect.serviceConstants(Service) return pipe( Effect.gen(function*(_) { - expect(yield* _(baz)).toEqual("42!") + strictEqual(yield* _(baz), "42!") }), Effect.provideService( Service, @@ -234,8 +235,8 @@ describe("Effect", () => { const { constants, functions } = Effect.serviceMembers(Service) return pipe( Effect.gen(function*(_) { - expect(yield* _(constants.baz)).toEqual("42!") - expect(yield* _(functions.foo("a", 3))).toEqual("a3") + strictEqual(yield* _(constants.baz), "42!") + strictEqual(yield* _(functions.foo("a", 3)), "a3") }), Effect.provideService( Service, diff --git a/packages/effect/test/Effect/error-handling.test.ts b/packages/effect/test/Effect/error-handling.test.ts index 1cd3eb2dfa9..f0cead0b84e 100644 --- a/packages/effect/test/Effect/error-handling.test.ts +++ b/packages/effect/test/Effect/error-handling.test.ts @@ -7,11 +7,12 @@ import * as Fiber from "effect/Fiber" import * as FiberId from "effect/FiberId" import { constFalse, constTrue, identity, pipe } from "effect/Function" import * as Option from "effect/Option" +import { assertLeft, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import { causesArb } from "effect/test/utils/cause" import * as it from "effect/test/utils/extend" import { assertType, satisfies } from "effect/test/utils/types" import * as fc from "fast-check" -import { assert, describe } from "vitest" +import { describe } from "vitest" const ExampleError = new Error("Oh noes!") @@ -46,25 +47,25 @@ describe("Effect", () => { }), Effect.flip ) - assert.deepStrictEqual(result.error, ExampleError) + deepStrictEqual(result.error, ExampleError) })) it.effect("attempt - fail", () => Effect.gen(function*($) { const io1 = Effect.either(ExampleErrorFail) const io2 = Effect.suspend(() => Effect.either(Effect.suspend(() => ExampleErrorFail))) const [first, second] = yield* $(io1, Effect.zip(io2)) - assert.deepStrictEqual(first, Either.left(ExampleError)) - assert.deepStrictEqual(second, Either.left(ExampleError)) + assertLeft(first, ExampleError) + assertLeft(second, ExampleError) })) it.effect("attempt - deep attempt sync effect error", () => Effect.gen(function*($) { const result = yield* $(Effect.flip(deepErrorEffect(100))) - assert.deepStrictEqual(result.error, ExampleError) + deepStrictEqual(result.error, ExampleError) })) it.effect("attempt - deep attempt fail error", () => Effect.gen(function*($) { const result = yield* $(Effect.either(deepErrorFail(100))) - assert.deepStrictEqual(result, Either.left(ExampleError)) + assertLeft(result, ExampleError) })) it.effect("attempt - sandbox -> terminate", () => Effect.gen(function*($) { @@ -75,7 +76,7 @@ describe("Effect", () => { Effect.sandbox, Effect.either ) - assert.deepStrictEqual(result, Either.left(Cause.die(ExampleError))) + assertLeft(result, Cause.die(ExampleError)) })) it.effect("catch - sandbox terminate", () => Effect.gen(function*($) { @@ -86,7 +87,7 @@ describe("Effect", () => { Effect.sandbox, Effect.merge ) - assert.deepStrictEqual(result, Cause.die(ExampleError)) + deepStrictEqual(result, Cause.die(ExampleError)) })) it.effect("catch failing finalizers with fail", () => Effect.gen(function*($) { @@ -110,7 +111,7 @@ describe("Effect", () => { ), Cause.die(InterruptError3) ) - assert.deepStrictEqual(result, Exit.failCause(expected)) + deepStrictEqual(result, Exit.failCause(expected)) })) it.effect("catch failing finalizers with terminate", () => Effect.gen(function*($) { @@ -134,14 +135,14 @@ describe("Effect", () => { ), Cause.die(InterruptError3) ) - assert.deepStrictEqual(result, Exit.failCause(expected)) + deepStrictEqual(result, Exit.failCause(expected)) })) it.effect("catchAllCause", () => Effect.gen(function*($) { const result = yield* $( pipe(Effect.succeed(42), Effect.zipRight(Effect.fail("uh oh")), Effect.catchAllCause(Effect.succeed)) ) - assert.deepStrictEqual(result, Cause.fail("uh oh")) + deepStrictEqual(result, Cause.fail("uh oh")) })) it.effect("catchAllDefect - recovers from all defects", () => Effect.gen(function*($) { @@ -150,7 +151,7 @@ describe("Effect", () => { Effect.die(new Cause.IllegalArgumentException(message)), Effect.catchAllDefect((e) => Effect.succeed((e as Error).message)) ) - assert.strictEqual(result, message) + strictEqual(result, message) })) it.effect("catchAllDefect - leaves errors", () => Effect.gen(function*($) { @@ -158,7 +159,7 @@ describe("Effect", () => { const result = yield* $( pipe(Effect.fail(error), Effect.catchAllDefect((e) => Effect.succeed((e as Error).message)), Effect.exit) ) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) it.effect("catchAllDefect - leaves values", () => Effect.gen(function*($) { @@ -166,7 +167,7 @@ describe("Effect", () => { const result = yield* $( pipe(Effect.succeed(error), Effect.catchAllDefect((e) => Effect.succeed((e as Error).message))) ) - assert.deepStrictEqual(result, error) + deepStrictEqual(result, error) })) it.effect("catchSomeDefect - recovers from some defects", () => Effect.gen(function*($) { @@ -179,7 +180,7 @@ describe("Effect", () => { : Option.none() ) ) - assert.strictEqual(result, message) + strictEqual(result, message) })) it.effect("catchSomeDefect - leaves the rest", () => Effect.gen(function*($) { @@ -193,7 +194,7 @@ describe("Effect", () => { ), Effect.exit ) - assert.deepStrictEqual(result, Exit.die(error)) + deepStrictEqual(result, Exit.die(error)) })) it.effect("catchSomeDefect - leaves errors", () => Effect.gen(function*($) { @@ -207,7 +208,7 @@ describe("Effect", () => { ), Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) it.effect("catchSomeDefect - leaves values", () => Effect.gen(function*($) { @@ -220,7 +221,7 @@ describe("Effect", () => { : Option.none() ) ) - assert.deepStrictEqual(result, error) + deepStrictEqual(result, error) })) it.effect("catch - recovers from one of several tagged errors", () => Effect.gen(function*($) { @@ -235,7 +236,7 @@ describe("Effect", () => { failure: "ErrorA", onFailure: Effect.succeed })) - assert.deepStrictEqual(result, { _tag: "ErrorA" }) + deepStrictEqual(result, { _tag: "ErrorA" }) })) it.effect("catch - does not recover from one of several tagged errors", () => Effect.gen(function*($) { @@ -253,7 +254,7 @@ describe("Effect", () => { }), Effect.exit ) - assert.deepStrictEqual(result, Exit.fail({ _tag: "ErrorB" as const })) + deepStrictEqual(result, Exit.fail({ _tag: "ErrorB" as const })) })) it.effect("catchIf - does not recover from one of several tagged errors", () => Effect.gen(function*($) { @@ -268,7 +269,7 @@ describe("Effect", () => { Effect.catchIf(effect, (e): e is ErrorA => e._tag === "ErrorA", Effect.succeed), Effect.exit ) - assert.deepStrictEqual(result, Exit.fail({ _tag: "ErrorB" as const })) + deepStrictEqual(result, Exit.fail({ _tag: "ErrorB" as const })) satisfies(assertType>()(result)) })) it.effect("catchTags - recovers from one of several tagged errors", () => @@ -283,7 +284,7 @@ describe("Effect", () => { const result = yield* $(Effect.catchTags(effect, { ErrorA: (e) => Effect.succeed(e) })) - assert.deepStrictEqual(result, { _tag: "ErrorA" }) + deepStrictEqual(result, { _tag: "ErrorA" }) })) it.effect("catchTags - does not recover from one of several tagged errors", () => Effect.gen(function*($) { @@ -299,7 +300,7 @@ describe("Effect", () => { ErrorA: (e) => Effect.succeed(e) }) )) - assert.deepStrictEqual(result, Exit.fail({ _tag: "ErrorB" })) + deepStrictEqual(result, Exit.fail({ _tag: "ErrorB" })) })) it.effect("catchTags - recovers from all tagged errors", () => Effect.gen(function*($) { @@ -314,7 +315,7 @@ describe("Effect", () => { ErrorA: (e) => Effect.succeed(e), ErrorB: (e) => Effect.succeed(e) })) - assert.deepStrictEqual(result, { _tag: "ErrorB" }) + deepStrictEqual(result, { _tag: "ErrorB" }) })) it.effect("fold - sandbox -> terminate", () => Effect.gen(function*($) { @@ -328,22 +329,22 @@ describe("Effect", () => { onSuccess: () => Option.none() as Option.Option> }) ) - assert.deepStrictEqual(result, Option.some(Cause.die(ExampleError))) + deepStrictEqual(result, Option.some(Cause.die(ExampleError))) })) it.effect("ignore - return success as unit", () => Effect.gen(function*($) { const result = yield* $(Effect.ignore(Effect.succeed(11))) - assert.isUndefined(result) + strictEqual(result, undefined) })) it.effect("ignore - return failure as unit", () => Effect.gen(function*($) { const result = yield* $(Effect.ignore(Effect.fail(123))) - assert.isUndefined(result) + strictEqual(result, undefined) })) it.effect("ignore - not catch throwable", () => Effect.gen(function*($) { const result = yield* $(Effect.exit(Effect.ignore(Effect.die(ExampleError)))) - assert.deepStrictEqual(result, Exit.die(ExampleError)) + deepStrictEqual(result, Exit.die(ExampleError)) })) it.effect("orElse - does not recover from defects", () => Effect.gen(function*($) { @@ -355,10 +356,10 @@ describe("Effect", () => { const both = yield* $(Effect.failCause(bothCause), Effect.orElse(() => Effect.void), Effect.exit) const then = yield* $(Effect.failCause(thenCause), Effect.orElse(() => Effect.void), Effect.exit) const fail = yield* $(Effect.fail(error), Effect.orElse(() => Effect.void), Effect.exit) - assert.deepStrictEqual(plain, Exit.die(error)) - assert.deepStrictEqual(both, Exit.die(error)) - assert.deepStrictEqual(then, Exit.die(error)) - assert.deepStrictEqual(fail, Exit.succeed(void 0)) + deepStrictEqual(plain, Exit.die(error)) + deepStrictEqual(both, Exit.die(error)) + deepStrictEqual(then, Exit.die(error)) + deepStrictEqual(fail, Exit.succeed(void 0)) })) it.effect("orElse - left failed and right died with kept cause", () => Effect.gen(function*($) { @@ -378,7 +379,7 @@ describe("Effect", () => { return Effect.succeed(false) }) ) - assert.isTrue(result) + assertTrue(result) })) it.effect("orElse - left failed and right failed with kept cause", () => Effect.gen(function*($) { @@ -398,7 +399,7 @@ describe("Effect", () => { return Effect.succeed(false) }) ) - assert.isTrue(result) + assertTrue(result) })) it.it("orElse - is associative", async () => { const smallInts = fc.integer({ min: 0, max: 100 }) @@ -420,42 +421,42 @@ describe("Effect", () => { return { left, right } }) const { left, right } = await Effect.runPromise(program) - assert.deepStrictEqual(left, right) + deepStrictEqual(left, right) })) }) it.effect("orElseFail - executes this effect and returns its value if it succeeds", () => Effect.gen(function*($) { const result = yield* $(Effect.succeed(true), Effect.orElseFail(constFalse)) - assert.isTrue(result) + assertTrue(result) })) it.effect("orElseFail - otherwise fails with the specified error", () => Effect.gen(function*($) { const result = yield* $(Effect.fail(false), Effect.orElseFail(constTrue), Effect.flip) - assert.isTrue(result) + assertTrue(result) })) it.effect("orElseSucceed - executes this effect and returns its value if it succeeds", () => Effect.gen(function*($) { const result = yield* $(Effect.succeed(true), Effect.orElseSucceed(constFalse)) - assert.isTrue(result) + assertTrue(result) })) it.effect("orElseSucceed - otherwise succeeds with the specified value", () => Effect.gen(function*($) { const result = yield* $(Effect.fail(false), Effect.orElseSucceed(constTrue)) - assert.isTrue(result) + assertTrue(result) })) it.effect("parallelErrors - one failure", () => Effect.gen(function*($) { const fiber1 = yield* $(Effect.fork(Effect.fail("error1"))) const fiber2 = yield* $(Effect.fork(Effect.succeed("success1"))) const result = yield* $(fiber1, Fiber.zip(fiber2), Fiber.join, Effect.parallelErrors, Effect.flip) - assert.deepStrictEqual(Array.from(result), ["error1"]) + deepStrictEqual(Array.from(result), ["error1"]) })) it.effect("parallelErrors - all failures", () => Effect.gen(function*($) { const fiber1 = yield* $(Effect.fork(Effect.fail("error1"))) const fiber2 = yield* $(Effect.fork(Effect.fail("error2"))) const result = yield* $(fiber1, Fiber.zip(fiber2), Fiber.join, Effect.parallelErrors, Effect.flip) - assert.deepStrictEqual(Array.from(result), ["error1", "error2"]) + deepStrictEqual(Array.from(result), ["error1", "error2"]) })) it.effect("promise - exception does not kill fiber", () => Effect.gen(function*($) { @@ -465,7 +466,7 @@ describe("Effect", () => { }), Effect.exit ) - assert.deepStrictEqual(result, Exit.die(ExampleError)) + deepStrictEqual(result, Exit.die(ExampleError)) })) it.effect("try = handles exceptions", () => Effect.gen(function*($) { @@ -480,12 +481,12 @@ describe("Effect", () => { Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(message)) + deepStrictEqual(result, Exit.fail(message)) })) it.effect("uncaught - fail", () => Effect.gen(function*($) { const result = yield* $(Effect.exit(ExampleErrorFail)) - assert.deepStrictEqual(result, Exit.fail(ExampleError)) + deepStrictEqual(result, Exit.fail(ExampleError)) })) it.effect("uncaught - sync effect error", () => Effect.gen(function*($) { @@ -496,12 +497,12 @@ describe("Effect", () => { Effect.exit ) - assert.deepStrictEqual(result, Exit.die(ExampleError)) + deepStrictEqual(result, Exit.die(ExampleError)) })) it.effect("uncaught - deep sync effect error", () => Effect.gen(function*($) { const result = yield* $(Effect.flip(deepErrorEffect(100))) - assert.deepStrictEqual(result.error, ExampleError) + deepStrictEqual(result.error, ExampleError) })) it.effect("unwraps exception", () => Effect.gen(function*($) { @@ -516,8 +517,8 @@ describe("Effect", () => { }) ) const result = yield* $(Effect.unsandbox(success)) - assert.strictEqual(message, "fail") - assert.strictEqual(result, 100) + strictEqual(message, "fail") + strictEqual(result, 100) })) it.effect("no information is lost during composition", () => Effect.gen(function*($) { @@ -526,6 +527,6 @@ describe("Effect", () => { } const expectedCause = Cause.fail("oh no") const result = yield* $(cause(pipe(Effect.failCause(expectedCause), Effect.sandbox, Effect.unsandbox))) - assert.deepStrictEqual(result, expectedCause) + deepStrictEqual(result, expectedCause) })) }) diff --git a/packages/effect/test/Effect/error.test.ts b/packages/effect/test/Effect/error.test.ts index 42fbebe1bee..6cf81f6af26 100644 --- a/packages/effect/test/Effect/error.test.ts +++ b/packages/effect/test/Effect/error.test.ts @@ -1,8 +1,7 @@ -import * as Cause from "effect/Cause" -import * as Data from "effect/Data" -import * as Effect from "effect/Effect" +import { Cause, Data, Effect } from "effect" +import { assertTrue, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe, expect } from "vitest" +import { describe } from "vitest" class TestError extends Data.TaggedError("TestError")<{}> {} @@ -11,11 +10,11 @@ describe("Effect", () => { Effect.gen(function*($) { const cause = yield* $(Effect.flip(Effect.sandbox(Effect.withSpan("A")(new TestError())))) const log = Cause.pretty(cause) - expect(log).includes("TestError") + assertTrue(log.includes("TestError")) if (typeof window === "undefined") { - expect(log.replaceAll("\\", "/")).includes("test/Effect/error.test.ts:12:78") + assertTrue(log.replaceAll("\\", "/").includes("test/Effect/error.test.ts:11:78")) } - expect(log).includes("at A") + assertTrue(log.includes("at A")) })) it.effect("tryPromise", () => @@ -31,9 +30,9 @@ describe("Effect", () => { ) const log = Cause.pretty(cause) if (typeof window === "undefined") { - expect(log.replaceAll("\\", "/")).includes("test/Effect/error.test.ts:26") + assertTrue(log.replaceAll("\\", "/").includes("test/Effect/error.test.ts:25")) } - expect(log).includes("at A") + assertTrue(log.includes("at A")) })) it.effect("allow message prop", () => @@ -52,11 +51,11 @@ describe("Effect", () => { Effect.flip ) const log = Cause.pretty(cause) - expect(log).includes("Failure: some message") + assertTrue(log.includes("Failure: some message")) if (typeof window === "undefined") { - expect(log.replaceAll("\\", "/")).includes("test/Effect/error.test.ts:48") + assertTrue(log.replaceAll("\\", "/").includes("test/Effect/error.test.ts:47")) } - expect(log).includes("at A") + assertTrue(log.includes("at A")) })) if (typeof window === "undefined") { @@ -70,8 +69,8 @@ describe("Effect", () => { } } const err = new MessageError() - expect(inspect(err)).include("MessageError: fail") - expect(inspect(err).replaceAll("\\", "/")).include("test/Effect/error.test.ts:72") + assertTrue(inspect(err).includes("MessageError: fail")) + assertTrue(inspect(err).replaceAll("\\", "/").includes("test/Effect/error.test.ts:71")) }) it.it("toString", () => { @@ -80,20 +79,20 @@ describe("Effect", () => { return "fail" } } - expect(inspect(new MessageError()).startsWith("fail\n")).toBe(true) - assert.deepStrictEqual(new MessageError().toJSON(), { _tag: "MessageError" }) + assertTrue(inspect(new MessageError()).startsWith("fail\n")) + deepStrictEqual(new MessageError().toJSON(), { _tag: "MessageError" }) }) it.it("cause", () => { class MessageError extends Data.TaggedError("MessageError")<{ cause: unknown }> {} - expect(inspect(new MessageError({ cause: new Error("boom") }))).includes("[cause]: Error: boom") + assertTrue(inspect(new MessageError({ cause: new Error("boom") })).includes("[cause]: Error: boom")) }) } it.it("toJSON", () => { class MessageError extends Data.TaggedError("MessageError")<{}> {} - assert.deepStrictEqual(new MessageError().toJSON(), { _tag: "MessageError" }) + deepStrictEqual(new MessageError().toJSON(), { _tag: "MessageError" }) }) }) diff --git a/packages/effect/test/Effect/filtering.test.ts b/packages/effect/test/Effect/filtering.test.ts index 6e3e3de12cb..a90792a4b73 100644 --- a/packages/effect/test/Effect/filtering.test.ts +++ b/packages/effect/test/Effect/filtering.test.ts @@ -3,8 +3,9 @@ import * as Effect from "effect/Effect" import * as Either from "effect/Either" import { pipe } from "effect/Function" import * as Ref from "effect/Ref" +import { assertLeft, assertRight, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" const exactlyOnce = ( value: A, @@ -30,8 +31,8 @@ describe("Effect", () => { ) ) const effects = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(results), [2, 4, 6, 6]) - assert.deepStrictEqual(Array.from(effects), [2, 4, 6, 3, 5, 6]) + deepStrictEqual(Array.from(results), [2, 4, 6, 6]) + deepStrictEqual(Array.from(effects), [2, 4, 6, 3, 5, 6]) })) it.effect("filter/negate - filters a collection using an effectual predicate, removing all elements that satisfy the predicate", () => Effect.gen(function*($) { @@ -43,8 +44,8 @@ describe("Effect", () => { ) ) const effects = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(results), [3, 5]) - assert.deepStrictEqual(Array.from(effects), [2, 4, 6, 3, 5, 6]) + deepStrictEqual(Array.from(results), [3, 5]) + deepStrictEqual(Array.from(effects), [2, 4, 6, 3, 5, 6]) })) it.effect("filter/concurrency - filters a collection in parallel using an effectual predicate", () => Effect.gen(function*($) { @@ -54,7 +55,7 @@ describe("Effect", () => { Effect.filter((n) => Effect.succeed(n % 2 === 0), { concurrency: "unbounded" }) ) ) - assert.deepStrictEqual(Array.from(result), [2, 4, 6, 6, 10, 20, 22, 28]) + deepStrictEqual(Array.from(result), [2, 4, 6, 6, 10, 20, 22, 28]) })) it.effect("filter/concurrency+negate - filters a collection in parallel using an effectual predicate, removing all elements that satisfy the predicate", () => Effect.gen(function*($) { @@ -67,7 +68,7 @@ describe("Effect", () => { }) ) ) - assert.deepStrictEqual(Array.from(result), [3, 5, 11, 15, 17, 23, 25]) + deepStrictEqual(Array.from(result), [3, 5, 11, 15, 17, 23, 25]) })) it.effect("filterOrElse - returns checked failure from held value", () => Effect.gen(function*($) { @@ -96,8 +97,8 @@ describe("Effect", () => { Effect.either, Effect.map(Either.mapLeft(Cause.failureOrCause)) ) - assert.deepStrictEqual(goodCase, Either.right(0 as const)) - assert.deepStrictEqual(badCase, Either.left(Either.left("1 was not 0"))) + assertRight(goodCase, 0) + assertLeft(badCase, Either.left("1 was not 0")) })) it.effect("filterOrElse - returns checked failure ignoring value", () => Effect.gen(function*($) { @@ -126,8 +127,8 @@ describe("Effect", () => { Effect.either, Effect.map(Either.mapLeft(Cause.failureOrCause)) ) - assert.deepStrictEqual(goodCase, Either.right(0 as const)) - assert.deepStrictEqual(badCase, Either.left(Either.left("predicate failed!"))) + assertRight(goodCase, 0) + assertLeft(badCase, Either.left("predicate failed!")) })) it.effect("filterOrFail - returns failure ignoring value", () => Effect.gen(function*($) { @@ -156,8 +157,8 @@ describe("Effect", () => { Effect.either, Effect.map(Either.mapLeft(Cause.failureOrCause)) ) - assert.deepStrictEqual(goodCase, Either.right(0 as const)) - assert.deepStrictEqual(badCase, Either.left(Either.left("predicate failed!"))) + assertRight(goodCase, 0) + assertLeft(badCase, Either.left("predicate failed!")) })) it.effect("filterOrFail - returns failure", () => Effect.gen(function*($) { @@ -186,8 +187,8 @@ describe("Effect", () => { Effect.either, Effect.map(Either.mapLeft(Cause.failureOrCause)) ) - assert.deepStrictEqual(goodCase, Either.right(0 as const)) - assert.deepStrictEqual(badCase, Either.left(Either.left("predicate failed, got 1!"))) + assertRight(goodCase, 0) + assertLeft(badCase, Either.left("predicate failed, got 1!")) })) it.effect("filterOrFail - without orFailWith", () => Effect.gen(function*($) { @@ -203,8 +204,8 @@ describe("Effect", () => { Effect.filterOrFail((n) => n === 0), Effect.flip ) - assert.deepStrictEqual(goodCase, 0) - assert.deepStrictEqual(goodCaseDataFirst, 0) - assert.deepStrictEqual(badCase, new Cause.NoSuchElementException()) + deepStrictEqual(goodCase, 0) + deepStrictEqual(goodCaseDataFirst, 0) + deepStrictEqual(badCase, new Cause.NoSuchElementException()) })) }) diff --git a/packages/effect/test/Effect/finalization.test.ts b/packages/effect/test/Effect/finalization.test.ts index 32f866ebac5..590acbe345a 100644 --- a/packages/effect/test/Effect/finalization.test.ts +++ b/packages/effect/test/Effect/finalization.test.ts @@ -9,8 +9,9 @@ import * as Fiber from "effect/Fiber" import { identity, pipe } from "effect/Function" import * as Option from "effect/Option" import * as Ref from "effect/Ref" +import { assertFalse, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" const ExampleError = new Error("Oh noes!") @@ -37,8 +38,8 @@ describe("Effect", () => { })), Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(ExampleError)) - assert.isTrue(finalized) + deepStrictEqual(result, Exit.fail(ExampleError)) + assertTrue(finalized) })) it.effect("fail on error", () => Effect.gen(function*($) { @@ -52,8 +53,8 @@ describe("Effect", () => { ), Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(ExampleError)) - assert.isTrue(finalized) + deepStrictEqual(result, Exit.fail(ExampleError)) + assertTrue(finalized) })) it.effect("finalizer errors not caught", () => Effect.gen(function*($) { @@ -70,7 +71,7 @@ describe("Effect", () => { ) ) const expected = Cause.sequential(Cause.sequential(Cause.fail(ExampleError), Cause.die(e2)), Cause.die(e3)) - assert.deepStrictEqual(result, expected) + deepStrictEqual(result, expected) })) it.effect("finalizer errors reported", () => Effect.gen(function*($) { @@ -92,8 +93,8 @@ describe("Effect", () => { ) ) ) - assert.isUndefined(result) - assert.isFalse(reported !== undefined && Exit.isSuccess(reported)) + strictEqual(result, undefined) + assertFalse(reported !== undefined && Exit.isSuccess(reported)) })) it.effect("acquireUseRelease exit.effect() is usage result", () => Effect.gen(function*($) { @@ -102,7 +103,7 @@ describe("Effect", () => { () => Effect.succeed(42), () => Effect.void )) - assert.strictEqual(result, 42) + strictEqual(result, 42) })) it.effect("error in just acquisition", () => Effect.gen(function*($) { @@ -116,7 +117,7 @@ describe("Effect", () => { Effect.exit ) ) - assert.deepStrictEqual(result, Exit.fail(ExampleError)) + deepStrictEqual(result, Exit.fail(ExampleError)) })) it.effect("error in just release", () => Effect.gen(function*($) { @@ -130,7 +131,7 @@ describe("Effect", () => { Effect.exit ) ) - assert.deepStrictEqual(result, Exit.die(ExampleError)) + deepStrictEqual(result, Exit.die(ExampleError)) })) it.effect("error in just usage", () => Effect.gen(function*($) { @@ -144,7 +145,7 @@ describe("Effect", () => { Effect.exit ) ) - assert.deepStrictEqual(result, Exit.fail(ExampleError)) + deepStrictEqual(result, Exit.fail(ExampleError)) })) it.effect("rethrown caught error in acquisition", () => Effect.gen(function*($) { @@ -158,7 +159,7 @@ describe("Effect", () => { Effect.flatMap(identity), Effect.flip ) - assert.deepEqual(result, ExampleError) + deepStrictEqual(result, ExampleError) })) it.effect("rethrown caught error in release", () => Effect.gen(function*($) { @@ -172,7 +173,7 @@ describe("Effect", () => { Effect.exit ) ) - assert.deepStrictEqual(result, Exit.die(ExampleError)) + deepStrictEqual(result, Exit.die(ExampleError)) })) it.effect("rethrown caught error in usage", () => Effect.gen(function*($) { @@ -184,7 +185,7 @@ describe("Effect", () => { ), Effect.exit ) - assert.deepEqual(result, Exit.fail(ExampleError)) + deepStrictEqual(result, Exit.fail(ExampleError)) })) it.effect("test eval of async fail", () => Effect.gen(function*($) { @@ -202,10 +203,10 @@ describe("Effect", () => { const a2 = yield* $(Effect.exit(io2)) const a3 = yield* $(io1, Effect.exit) const a4 = yield* $(io2, Effect.exit) - assert.deepStrictEqual(a1, Exit.fail(ExampleError)) - assert.deepStrictEqual(a2, Exit.fail(ExampleError)) - assert.deepStrictEqual(a3, Exit.fail(ExampleError)) - assert.deepStrictEqual(a4, Exit.fail(ExampleError)) + deepStrictEqual(a1, Exit.fail(ExampleError)) + deepStrictEqual(a2, Exit.fail(ExampleError)) + deepStrictEqual(a3, Exit.fail(ExampleError)) + deepStrictEqual(a4, Exit.fail(ExampleError)) })) it.live("acquireUseRelease regression 1", () => Effect.gen(function*($) { @@ -250,18 +251,18 @@ describe("Effect", () => { Effect.repeat({ until: (list) => pipe(list, Array.findFirst((s) => s === "release 2"), Option.isSome) }) ) const result = yield* $(Ref.get(ref)) - assert.isTrue(pipe( + assertTrue(pipe( result, Array.findFirst((s) => s === "start 1"), Option.isSome )) - assert.isTrue(pipe( + assertTrue(pipe( result, Array.findFirst((s) => s === "release 1"), Option.isSome )) - assert.isTrue(pipe(result, Array.findFirst((s) => s === "start 2"), Option.isSome)) - assert.isTrue(pipe(result, Array.findFirst((s) => s === "release 2"), Option.isSome)) + assertTrue(pipe(result, Array.findFirst((s) => s === "start 2"), Option.isSome)) + assertTrue(pipe(result, Array.findFirst((s) => s === "release 2"), Option.isSome)) })) it.live("interrupt waits for finalizer", () => Effect.gen(function*($) { @@ -279,7 +280,7 @@ describe("Effect", () => { yield* $(Deferred.await(deferred1)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("onExit - executes that a cleanup function runs when effect succeeds", () => Effect.gen(function*($) { @@ -292,7 +293,7 @@ describe("Effect", () => { })) ) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("onExit - ensures that a cleanup function runs when an effect fails", () => Effect.gen(function*($) { @@ -308,7 +309,7 @@ describe("Effect", () => { Effect.ignore ) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("onExit - ensures that a cleanup function runs when an effect is interrupted", () => Effect.gen(function*($) { @@ -329,6 +330,6 @@ describe("Effect", () => { yield* $(Deferred.await(latch1)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Deferred.await(latch2)) - assert.isUndefined(result) + strictEqual(result, undefined) })) }) diff --git a/packages/effect/test/Effect/fn.test.ts b/packages/effect/test/Effect/fn.test.ts index 7a1725ea909..8023127e713 100644 --- a/packages/effect/test/Effect/fn.test.ts +++ b/packages/effect/test/Effect/fn.test.ts @@ -1,5 +1,6 @@ import { Cause, Effect } from "effect" -import { assert, describe, it } from "effect/test/utils/extend" +import { assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "effect/test/utils/extend" describe("Effect.fn", () => { it.effect("catches defects in the function", () => @@ -18,9 +19,9 @@ describe("Effect.fn", () => { Effect.sandbox, Effect.flip ) - assert(Cause.isDieType(cause)) - assert.isTrue(cause.defect instanceof Error && cause.defect.message === "test") - assert.strictEqual(caught, cause) + assertTrue(Cause.isDieType(cause)) + assertTrue(cause.defect instanceof Error && cause.defect.message === "test") + strictEqual(caught, cause) })) it.effect("catches defects in pipeline", () => @@ -35,8 +36,8 @@ describe("Effect.fn", () => { Effect.sandbox, Effect.flip ) - assert(Cause.isDieType(cause)) - assert.isTrue(cause.defect instanceof Error && cause.defect.message === "test") + assertTrue(Cause.isDieType(cause)) + assertTrue(cause.defect instanceof Error && cause.defect.message === "test") })) it.effect("catches defects in both fn & pipeline", () => @@ -53,10 +54,10 @@ describe("Effect.fn", () => { Effect.sandbox, Effect.flip ) - assert(Cause.isSequentialType(cause)) - assert(Cause.isDieType(cause.left)) - assert(Cause.isDieType(cause.right)) - assert.isTrue(cause.left.defect instanceof Error && cause.left.defect.message === "test") - assert.isTrue(cause.right.defect instanceof Error && cause.right.defect.message === "test2") + assertTrue(Cause.isSequentialType(cause)) + assertTrue(Cause.isDieType(cause.left)) + assertTrue(Cause.isDieType(cause.right)) + assertTrue(cause.left.defect instanceof Error && cause.left.defect.message === "test") + assertTrue(cause.right.defect instanceof Error && cause.right.defect.message === "test2") })) }) diff --git a/packages/effect/test/Effect/foreign.test.ts b/packages/effect/test/Effect/foreign.test.ts index f460ca9ac7b..5d0de722505 100644 --- a/packages/effect/test/Effect/foreign.test.ts +++ b/packages/effect/test/Effect/foreign.test.ts @@ -5,9 +5,10 @@ import * as Either from "effect/Either" import * as Exit from "effect/Exit" import * as Option from "effect/Option" import { nextInt } from "effect/Random" +import { assertLeft, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import { unify } from "effect/Unify" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Foreign", () => { it.effect("Unify", () => @@ -16,16 +17,16 @@ describe("Foreign", () => { const unifiedExit = unify((yield* $(nextInt)) > 1 ? Exit.succeed(0) : Exit.fail(1)) const unifiedEither = unify((yield* $(nextInt)) > 1 ? Either.right(0) : Either.left(1)) const unifiedOption = unify((yield* $(nextInt)) > 1 ? Option.some(0) : Option.none()) - assert.deepEqual(yield* $(unifiedEffect), 0) - assert.deepEqual(yield* $(unifiedExit), 0) - assert.deepEqual(yield* $(unifiedEither), 0) - assert.deepEqual(yield* $(unifiedOption), 0) + deepStrictEqual(yield* $(unifiedEffect), 0) + deepStrictEqual(yield* $(unifiedExit), 0) + deepStrictEqual(yield* $(unifiedEither), 0) + deepStrictEqual(yield* $(unifiedOption), 0) })) it.effect("Tag", () => Effect.gen(function*($) { const tag = Context.GenericTag("number") const result = yield* $(tag, Effect.provideService(tag, 10)) - assert.deepEqual(result, 10) + deepStrictEqual(result, 10) })) it.effect("Either", () => Effect.gen(function*($) { @@ -37,9 +38,9 @@ describe("Foreign", () => { (n) => Effect.succeed(n + 1) ) ) - assert.deepEqual(a, 10) - assert.deepEqual(b, Either.left(10)) - assert.deepEqual(c, 3) + deepStrictEqual(a, 10) + assertLeft(b, 10) + deepStrictEqual(c, 3) })) it.effect("Option", () => Effect.gen(function*($) { @@ -51,8 +52,8 @@ describe("Foreign", () => { (n) => Effect.succeed(n + 1) ) ) - assert.deepEqual(a, 10) - assert.deepEqual(b, Either.left(new Cause.NoSuchElementException())) - assert.deepEqual(c, 3) + deepStrictEqual(a, 10) + assertLeft(b, new Cause.NoSuchElementException()) + deepStrictEqual(c, 3) })) }) diff --git a/packages/effect/test/Effect/forking.test.ts b/packages/effect/test/Effect/forking.test.ts index 787cc2b9f30..65054386659 100644 --- a/packages/effect/test/Effect/forking.test.ts +++ b/packages/effect/test/Effect/forking.test.ts @@ -6,14 +6,15 @@ import * as Fiber from "effect/Fiber" import { pipe } from "effect/Function" import * as Option from "effect/Option" import * as Ref from "effect/Ref" +import { assertFalse, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("fork - propagates interruption", () => Effect.gen(function*($) { const result = yield* $(Effect.never, Effect.fork, Effect.flatMap(Fiber.interrupt)) - assert.isTrue(Exit.isInterrupted(result)) + assertTrue(Exit.isInterrupted(result)) })) it.effect("fork - propagates interruption with zip of defect", () => Effect.gen(function*($) { @@ -27,7 +28,7 @@ describe("Effect", () => { yield* $(Deferred.await(latch)) const result = yield* $(Fiber.interrupt(fiber), Effect.map(Exit.mapErrorCause((cause) => cause))) - assert.isTrue(Exit.isInterrupted(result)) + assertTrue(Exit.isInterrupted(result)) })) it.effect("fork - interruption status is heritable", () => Effect.gen(function*($) { @@ -43,7 +44,7 @@ describe("Effect", () => { ) const result = yield* $(Ref.get(ref)) - assert.isFalse(result) + assertFalse(result) })) it.effect("forkWithErrorHandler - calls provided function when task fails", () => Effect.gen(function*($) { @@ -53,12 +54,12 @@ describe("Effect", () => { Effect.forkWithErrorHandler((e) => pipe(Deferred.succeed(deferred, e), Effect.asVoid)) ) const result = yield* $(Deferred.await(deferred)) - assert.isUndefined(result) + strictEqual(result, undefined) })) it.effect("forkAll - returns the list of results in the same order", () => Effect.gen(function*($) { const result = yield* $([1, 2, 3].map(Effect.succeed), Effect.forkAll(), Effect.flatMap(Fiber.join)) - assert.deepStrictEqual(Array.from(result), [1, 2, 3]) + deepStrictEqual(Array.from(result), [1, 2, 3]) })) it.effect("forkAll - happy-path", () => Effect.gen(function*($) { @@ -67,7 +68,7 @@ describe("Effect", () => { Effect.forkAll(), Effect.flatMap(Fiber.join) ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result), Array.from({ length: 1000 }, (_, i) => i + 1) ) @@ -77,14 +78,14 @@ describe("Effect", () => { const result = yield* $( pipe([] as ReadonlyArray>, Effect.forkAll(), Effect.flatMap(Fiber.join)) ) - assert.strictEqual(result.length, 0) + strictEqual(result.length, 0) })) it.effect("forkAll - propagate failures", () => Effect.gen(function*($) { const boom = new Error() const fail = Effect.fail(boom) const result = yield* $([fail], Effect.forkAll(), Effect.flatMap((fiber) => Effect.flip(Fiber.join(fiber)))) - assert.strictEqual(result, boom) + strictEqual(result, boom) })) it.effect("forkAll - propagates defects", () => Effect.gen(function*($) { @@ -99,10 +100,10 @@ describe("Effect", () => { const result1 = yield* $(joinDefect(fiber1), Effect.map((cause) => cause)) const result2 = yield* $(joinDefect(fiber2), Effect.map((cause) => cause)) const result3 = yield* $(joinDefect(fiber3), Effect.map((cause) => cause)) - assert.deepStrictEqual(Cause.dieOption(result1), Option.some(boom)) - assert.deepStrictEqual(Cause.dieOption(result2), Option.some(boom)) - assert.deepStrictEqual(Cause.dieOption(result3), Option.some(boom)) - assert.isTrue(Cause.isInterrupted(result3)) + deepStrictEqual(Cause.dieOption(result1), Option.some(boom)) + deepStrictEqual(Cause.dieOption(result2), Option.some(boom)) + deepStrictEqual(Cause.dieOption(result3), Option.some(boom)) + assertTrue(Cause.isInterrupted(result3)) })) it.effect("forkAll - infers correctly", () => Effect.gen(function*($) { @@ -112,7 +113,7 @@ describe("Effect", () => { const fiber = yield* $(Effect.forkAll(workers)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("forkAll - infers correctly with error type", () => Effect.gen(function*($) { @@ -122,6 +123,6 @@ describe("Effect", () => { const fiber = yield* $(Effect.forkAll(workers)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) }) diff --git a/packages/effect/test/Effect/interruption.test.ts b/packages/effect/test/Effect/interruption.test.ts index 2e8c8897fed..da85465c767 100644 --- a/packages/effect/test/Effect/interruption.test.ts +++ b/packages/effect/test/Effect/interruption.test.ts @@ -13,23 +13,24 @@ import * as HashSet from "effect/HashSet" import * as MutableRef from "effect/MutableRef" import * as Option from "effect/Option" import * as Ref from "effect/Ref" +import { assertFalse, assertSome, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import { withLatch, withLatchAwait } from "effect/test/utils/latch" import * as TestClock from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("sync forever is interruptible", () => Effect.gen(function*($) { const fiber = yield* $(Effect.succeed(1), Effect.forever, Effect.fork) const result = yield* $(Fiber.interrupt(fiber)) - assert.isTrue(Exit.isFailure(result) && Cause.isInterruptedOnly(result.effect_instruction_i0)) + assertTrue(Exit.isFailure(result) && Cause.isInterruptedOnly(result.effect_instruction_i0)) })) it.effect("interrupt of never is interrupted with cause", () => Effect.gen(function*($) { const fiber = yield* $(Effect.never, Effect.fork) const result = yield* $(Fiber.interrupt(fiber)) - assert.isTrue(Exit.isFailure(result) && Cause.isInterruptedOnly(result.effect_instruction_i0)) + assertTrue(Exit.isFailure(result) && Cause.isInterruptedOnly(result.effect_instruction_i0)) })) it.effect("asyncEffect is interruptible", () => Effect.gen(function*($) { @@ -37,13 +38,13 @@ describe("Effect", () => { pipe(Effect.asyncEffect(() => Effect.never), Effect.fork) ) const result = yield* $(Fiber.interrupt(fiber)) - assert.isTrue(Exit.isFailure(result) && Cause.isInterruptedOnly(result.effect_instruction_i0)) + assertTrue(Exit.isFailure(result) && Cause.isInterruptedOnly(result.effect_instruction_i0)) })) it.effect("async is interruptible", () => Effect.gen(function*($) { const fiber = yield* $(Effect.async(constVoid), Effect.fork) const result = yield* $(Fiber.interrupt(fiber)) - assert.isTrue(Exit.isFailure(result) && Cause.isInterruptedOnly(result.effect_instruction_i0)) + assertTrue(Exit.isFailure(result) && Cause.isInterruptedOnly(result.effect_instruction_i0)) })) it.effect("acquireUseRelease - acquire is uninterruptible", () => Effect.gen(function*($) { @@ -77,7 +78,7 @@ describe("Effect", () => { }) const result = yield* $(program) yield* $(Deferred.succeed(awaiter, void 0)) - assert.strictEqual(result, 42) + strictEqual(result, 42) })) it.effect("acquireUseRelease - use is interruptible", () => Effect.gen(function*($) { @@ -91,7 +92,7 @@ describe("Effect", () => { ) ) const result = yield* $(Fiber.interrupt(fiber)) - assert.isTrue(Exit.isInterrupted(result)) + assertTrue(Exit.isInterrupted(result)) })) it.effect("acquireUseRelease - release is called on interrupt", () => Effect.gen(function*($) { @@ -116,7 +117,7 @@ describe("Effect", () => { duration: Duration.seconds(1) }) ) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("acquireUseRelease acquire returns immediately on interrupt", () => Effect.gen(function*($) { @@ -137,7 +138,7 @@ describe("Effect", () => { yield* $(Deferred.await(deferred1)) const result = yield* $(Fiber.interrupt(fiber)) yield* $(Deferred.succeed(deferred3, void 0)) - assert.isTrue(Exit.isInterrupted(result)) + assertTrue(Exit.isInterrupted(result)) })) it.effect("acquireUseRelease disconnect use is interruptible", () => Effect.gen(function*($) { @@ -151,7 +152,7 @@ describe("Effect", () => { Effect.fork ) const result = yield* $(Fiber.interrupt(fiber)) - assert.isTrue(Exit.isInterrupted(result)) + assertTrue(Exit.isInterrupted(result)) })) it.effect("acquireUseRelease disconnect release called on interrupt in separate fiber", () => Effect.gen(function*($) { @@ -180,7 +181,7 @@ describe("Effect", () => { }) ) ) - assert.isTrue(result) + assertTrue(result) })) it.effect("catchAll + ensuring + interrupt", () => Effect.gen(function*($) { @@ -198,7 +199,7 @@ describe("Effect", () => { yield* $(Deferred.await(latch)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Deferred.await(deferred)) - assert.isTrue(result) + assertTrue(result) })) it.effect("finalizer can detect interruption", () => Effect.gen(function*($) { @@ -220,7 +221,7 @@ describe("Effect", () => { yield* $(Deferred.await(deferred2)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Deferred.await(deferred1)) - assert.isTrue(result) + assertTrue(result) })) it.effect("interrupted cause persists after catching", () => Effect.gen(function*($) { @@ -250,8 +251,8 @@ describe("Effect", () => { ) yield* $(Deferred.await(latch1), Effect.zipRight(Fiber.interrupt(fiber))) const result = yield* $(Ref.get(exits), Effect.map(process)) - assert.strictEqual(Chunk.size(result), 2) - assert.isTrue(pipe( + strictEqual(Chunk.size(result), 2) + assertTrue(pipe( result, Array.reduce(true, (acc, curr) => acc && Exit.isFailure(curr) && Cause.isInterruptedOnly(curr.effect_instruction_i0)) @@ -273,7 +274,7 @@ describe("Effect", () => { yield* $(Deferred.await(latch1), Effect.zipRight(Deferred.await(latch2))) yield* $(Fiber.interrupt(raced)) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 2) + strictEqual(result, 2) })) it.effect("recovery of error in finalizer", () => Effect.gen(function*($) { @@ -292,7 +293,7 @@ describe("Effect", () => { )) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(recovered)) - assert.isTrue(result) + assertTrue(result) })) it.effect("recovery of interruptible", () => Effect.gen(function*($) { @@ -311,7 +312,7 @@ describe("Effect", () => { )) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(recovered)) - assert.isTrue(result) + assertTrue(result) })) it.effect("sandbox of interruptible", () => Effect.gen(function*($) { @@ -331,7 +332,7 @@ describe("Effect", () => { )) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(recovered)) - assert.deepStrictEqual(result, Option.some(Either.left(true))) + assertSome(result, Either.left(true)) })) it.effect("run of interruptible", () => Effect.gen(function*($) { @@ -348,7 +349,7 @@ describe("Effect", () => { )) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(recovered)) - assert.deepStrictEqual(result, Option.some(true)) + assertSome(result, true) })) it.effect("alternating interruptibility", () => Effect.gen(function*($) { @@ -368,7 +369,7 @@ describe("Effect", () => { )) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(counter)) - assert.strictEqual(result, 2) + strictEqual(result, 2) })) it.effect("interruption after defect", () => Effect.gen(function*($) { @@ -387,7 +388,7 @@ describe("Effect", () => { )) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("interruption after defect 2", () => Effect.gen(function*($) { @@ -406,7 +407,7 @@ describe("Effect", () => { )) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("disconnect returns immediately on interrupt", () => Effect.gen(function*($) { @@ -422,7 +423,7 @@ describe("Effect", () => { ) yield* $(Deferred.await(deferred)) const result = yield* $(Fiber.interrupt(fiber)) - assert.isTrue(Exit.isInterrupted(result)) + assertTrue(Exit.isInterrupted(result)) })) it.live("disconnected effect that is then interrupted eventually performs interruption", () => Effect.gen(function*($) { @@ -448,7 +449,7 @@ describe("Effect", () => { yield* $(Fiber.interrupt(fiber)) yield* $(Deferred.await(deferred2)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("cause reflects interruption", () => Effect.gen(function*($) { @@ -456,7 +457,7 @@ describe("Effect", () => { withLatch((release) => pipe(release, Effect.zipRight(Effect.fail("foo")), Effect.fork)), Effect.flatMap(Fiber.interrupt) ) - assert.deepStrictEqual(result, Exit.fail("foo")) + deepStrictEqual(result, Exit.fail("foo")) })) it.live("acquireRelease use inherits interrupt status", () => Effect.gen(function*($) { @@ -484,7 +485,7 @@ describe("Effect", () => { )) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.live("acquireRelease use inherits interrupt status 2", () => Effect.gen(function*($) { @@ -510,7 +511,7 @@ describe("Effect", () => { yield* $(Deferred.succeed(latch2, void 0)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.live("async can be uninterruptible", () => Effect.gen(function*($) { @@ -526,7 +527,7 @@ describe("Effect", () => { )) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.live("closing scope is uninterruptible", () => Effect.gen(function*($) { @@ -542,7 +543,7 @@ describe("Effect", () => { yield* $(Deferred.await(deferred)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("async cancelation", () => Effect.gen(function*($) { @@ -555,7 +556,7 @@ describe("Effect", () => { }) yield* $(Effect.void, Effect.race(effect)) const result = MutableRef.get(ref) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("interruption status is inheritable", () => Effect.gen(function*($) { @@ -570,7 +571,7 @@ describe("Effect", () => { Effect.uninterruptible ) const result = yield* $(Ref.get(ref)) - assert.isFalse(result) + assertFalse(result) })) it.effect("running an effect preserves interruption status", () => Effect.gen(function*($) { @@ -580,7 +581,7 @@ describe("Effect", () => { ) yield* $(Deferred.await(deferred)) const result = yield* $(Fiber.interrupt(fiber)) - assert.isTrue( + assertTrue( Exit.isFailure(result) && Exit.isInterrupted(result) && Cause.isInterruptedOnly(result.effect_instruction_i0) ) })) @@ -589,7 +590,7 @@ describe("Effect", () => { const deferred = yield* $(Deferred.make()) yield* $(Effect.interrupt, Effect.exit, Effect.zipRight(Deferred.succeed(deferred, 42))) const result = yield* $(Deferred.await(deferred)) - assert.strictEqual(result, 42) + strictEqual(result, 42) })) it.effect("AbortSignal is aborted", () => Effect.gen(function*($) { @@ -602,6 +603,6 @@ describe("Effect", () => { ) yield* $(Effect.yieldNow()) yield* $(Fiber.interrupt(fiber)) - assert.strictEqual(signal!.aborted, true) + strictEqual(signal!.aborted, true) })) }) diff --git a/packages/effect/test/Effect/join-order.test.ts b/packages/effect/test/Effect/join-order.test.ts index 8befb3920ea..207afec6746 100644 --- a/packages/effect/test/Effect/join-order.test.ts +++ b/packages/effect/test/Effect/join-order.test.ts @@ -1,9 +1,10 @@ import * as Effect from "effect/Effect" import * as Fiber from "effect/Fiber" import * as FiberRef from "effect/FiberRef" +import { strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("zip/all joins fibers in the correct order", () => @@ -16,6 +17,6 @@ describe("Effect", () => { ))) yield* $(TestClock.adjust("3 seconds")) yield* $(Fiber.join(fiber)) - assert.strictEqual(yield* $(FiberRef.get(ref)), 10) + strictEqual(yield* $(FiberRef.get(ref)), 10) }).pipe(Effect.scoped)) }) diff --git a/packages/effect/test/Effect/latch.test.ts b/packages/effect/test/Effect/latch.test.ts index 019cd8c8d98..8685a685c6f 100644 --- a/packages/effect/test/Effect/latch.test.ts +++ b/packages/effect/test/Effect/latch.test.ts @@ -1,5 +1,6 @@ import { Effect, Exit } from "effect" -import { assert, describe, it } from "effect/test/utils/extend" +import { deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "effect/test/utils/extend" describe("Latch", () => { it.effect("open works", () => @@ -9,15 +10,15 @@ describe("Latch", () => { Effect.fork ) yield* Effect.yieldNow() - assert.isNull(fiber.unsafePoll()) + strictEqual(fiber.unsafePoll(), null) yield* latch.open - assert.deepStrictEqual(yield* fiber.await, Exit.void) + deepStrictEqual(yield* fiber.await, Exit.void) fiber = yield* latch.await.pipe( Effect.fork ) yield* Effect.yieldNow() - assert.deepStrictEqual(fiber.unsafePoll(), Exit.void) + deepStrictEqual(fiber.unsafePoll(), Exit.void) yield* latch.close fiber = yield* Effect.void.pipe( @@ -25,10 +26,10 @@ describe("Latch", () => { Effect.fork ) yield* Effect.yieldNow() - assert.isNull(fiber.unsafePoll()) + strictEqual(fiber.unsafePoll(), null) yield* latch.release - assert.deepStrictEqual(yield* fiber.await, Exit.void) + deepStrictEqual(yield* fiber.await, Exit.void) })) it.effect("subtype of Effect", () => @@ -38,6 +39,6 @@ describe("Latch", () => { yield* latch.open - assert.deepStrictEqual(yield* fiber.await, Exit.void) + deepStrictEqual(yield* fiber.await, Exit.void) })) }) diff --git a/packages/effect/test/Effect/lifting.test.ts b/packages/effect/test/Effect/lifting.test.ts index 48e49fe8830..d6bc295a946 100644 --- a/packages/effect/test/Effect/lifting.test.ts +++ b/packages/effect/test/Effect/lifting.test.ts @@ -1,7 +1,8 @@ import * as Effect from "effect/Effect" import { pipe } from "effect/Function" +import { strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("liftPredicate", () => { @@ -11,35 +12,35 @@ describe("Effect", () => { const onNumberRefinementError = (n: string | number) => `${n} is not a number` return Effect.gen(function*() { - assert.deepStrictEqual( + strictEqual( yield* pipe(1, Effect.liftPredicate(isPositivePredicate, onPositivePredicateError)), 1 ) - assert.deepStrictEqual( + strictEqual( yield* pipe(-1, Effect.liftPredicate(isPositivePredicate, onPositivePredicateError), Effect.flip), `-1 is not positive` ) - assert.deepStrictEqual( + strictEqual( yield* pipe(1, Effect.liftPredicate(isNumberRefinement, onNumberRefinementError)), 1 ) - assert.deepStrictEqual( + strictEqual( yield* pipe("string", Effect.liftPredicate(isNumberRefinement, onNumberRefinementError), Effect.flip), `string is not a number` ) - assert.deepStrictEqual( + strictEqual( yield* Effect.liftPredicate(1, isPositivePredicate, onPositivePredicateError), 1 ) - assert.deepStrictEqual( + strictEqual( yield* Effect.liftPredicate(-1, isPositivePredicate, onPositivePredicateError).pipe(Effect.flip), `-1 is not positive` ) - assert.deepStrictEqual( + strictEqual( yield* Effect.liftPredicate(1, isNumberRefinement, onNumberRefinementError), 1 ) - assert.deepStrictEqual( + strictEqual( yield* Effect.liftPredicate("string", isNumberRefinement, onNumberRefinementError).pipe(Effect.flip), `string is not a number` ) diff --git a/packages/effect/test/Effect/mapping.test.ts b/packages/effect/test/Effect/mapping.test.ts index 2e8e7315927..fb043028885 100644 --- a/packages/effect/test/Effect/mapping.test.ts +++ b/packages/effect/test/Effect/mapping.test.ts @@ -1,11 +1,11 @@ import * as Cause from "effect/Cause" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import * as Exit from "effect/Exit" import { identity, pipe } from "effect/Function" import * as Ref from "effect/Ref" +import { assertFalse, assertLeft, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" const ExampleError = new Error("Oh noes!") @@ -28,17 +28,17 @@ describe("Effect", () => { it.effect("flip must make error into value", () => Effect.gen(function*($) { const result = yield* $(Effect.flip(Effect.fail(ExampleError))) - assert.deepStrictEqual(result, ExampleError) + deepStrictEqual(result, ExampleError) })) it.effect("flip must make value into error", () => Effect.gen(function*($) { const result = yield* $(Effect.either(Effect.flip(Effect.succeed(42)))) - assert.deepStrictEqual(result, Either.left(42)) + assertLeft(result, 42) })) it.effect("flipping twice returns the identical value", () => Effect.gen(function*($) { const result = yield* $(Effect.flip(Effect.flip(Effect.succeed(42)))) - assert.strictEqual(result, 42) + strictEqual(result, 42) })) it.effect("mapBoth - maps over both error and value channels", () => Effect.gen(function*($) { @@ -50,34 +50,34 @@ describe("Effect", () => { }), Effect.either ) - assert.deepStrictEqual(result, Either.left("10")) + assertLeft(result, "10") })) it.effect("mapAccum", () => Effect.gen(function*($) { const result = yield* $( Effect.mapAccum(["a", "b"], "", (prev, cur, i) => Effect.succeed([prev + cur + i, cur])) ) - assert.deepStrictEqual(result, ["a0b1", ["a", "b"]]) + deepStrictEqual(result, ["a0b1", ["a", "b"]]) })) it.effect("tryMap - returns an effect whose success is mapped by the specified side effecting function", () => Effect.gen(function*($) { const result = yield* $(Effect.succeed("123"), Effect.tryMap({ try: parseInt, catch: identity })) - assert.strictEqual(result, 123) + strictEqual(result, 123) })) it.effect("tryMap - translates any thrown exceptions into typed failed effects", () => Effect.gen(function*($) { const result = yield* $(Effect.succeed("hello"), Effect.tryMap({ try: parseInt, catch: identity }), Effect.exit) - assert.deepStrictEqual(result, Exit.fail(new Cause.IllegalArgumentException())) + deepStrictEqual(result, Exit.fail(new Cause.IllegalArgumentException())) })) it.effect("negate - on true returns false", () => Effect.gen(function*($) { const result = yield* $(Effect.negate(Effect.succeed(true))) - assert.isFalse(result) + assertFalse(result) })) it.effect("negate - on false returns true", () => Effect.gen(function*($) { const result = yield* $(Effect.negate(Effect.succeed(false))) - assert.isTrue(result) + assertTrue(result) })) it.effect("summarized - returns summary and value", () => Effect.gen(function*($) { @@ -86,9 +86,9 @@ describe("Effect", () => { const [[start, end], value] = yield* $( pipe(increment, Effect.summarized(increment, (start, end) => [start, end] as const)) ) - assert.strictEqual(start, 1) - assert.strictEqual(value, 2) - assert.strictEqual(end, 3) + strictEqual(start, 1) + strictEqual(value, 2) + strictEqual(end, 3) })) it.effect("point, bind, map", () => Effect.gen(function*($) { @@ -99,7 +99,7 @@ describe("Effect", () => { return pipe(fibEffect(n - 1), Effect.zipWith(fibEffect(n - 2), (a, b) => a + b)) } const result = yield* $(fibEffect(10)) - assert.strictEqual(result, fib(10)) + strictEqual(result, fib(10)) })) it.effect("effect, bind, map", () => Effect.gen(function*($) { @@ -110,7 +110,7 @@ describe("Effect", () => { return pipe(fibEffect(n - 1), Effect.zipWith(fibEffect(n - 2), (a, b) => a + b)) } const result = yield* $(fibEffect(10)) - assert.strictEqual(result, fib(10)) + strictEqual(result, fib(10)) })) it.effect("effect, bind, map, redeem", () => Effect.gen(function*($) { @@ -126,6 +126,6 @@ describe("Effect", () => { return pipe(fibEffect(n - 1), Effect.zipWith(fibEffect(n - 2), (a, b) => a + b)) } const result = yield* $(fibEffect(10)) - assert.strictEqual(result, fib(10)) + strictEqual(result, fib(10)) })) }) diff --git a/packages/effect/test/Effect/memoization.test.ts b/packages/effect/test/Effect/memoization.test.ts index 82055caba87..4c20cf25e8f 100644 --- a/packages/effect/test/Effect/memoization.test.ts +++ b/packages/effect/test/Effect/memoization.test.ts @@ -1,22 +1,24 @@ +import { notStrictEqual } from "assert" import * as Effect from "effect/Effect" import { pipe } from "effect/Function" import * as Random from "effect/Random" import * as Ref from "effect/Ref" +import { strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("non-memoized returns new instances on repeated calls", () => it.flakyTest(Effect.gen(function*($) { const random = Random.nextInt const [first, second] = yield* $(random, Effect.zip(random)) - assert.notStrictEqual(first, second) + notStrictEqual(first, second) }))) it.effect("memoized returns the same instance on repeated calls", () => it.flakyTest(Effect.gen(function*($) { const memo = Effect.cached(Random.nextInt) const [first, second] = yield* $(memo, Effect.flatMap((effect) => pipe(effect, Effect.zip(effect)))) - assert.strictEqual(first, second) + strictEqual(first, second) }))) it.effect("memoized function returns the same instance on repeated calls", () => it.flakyTest(Effect.gen(function*($) { @@ -26,9 +28,9 @@ describe("Effect", () => { const b = yield* $(memoized(10)) const c = yield* $(memoized(11)) const d = yield* $(memoized(11)) - assert.strictEqual(a, b) - assert.notStrictEqual(b, c) - assert.strictEqual(c, d) + strictEqual(a, b) + notStrictEqual(b, c) + strictEqual(c, d) }))) it.effect("once returns an effect that will only be executed once", () => Effect.gen(function*($) { @@ -41,6 +43,6 @@ describe("Effect", () => { }) ) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) }) diff --git a/packages/effect/test/Effect/promise.test.ts b/packages/effect/test/Effect/promise.test.ts index 54db63dcb8c..c14cf6a33f6 100644 --- a/packages/effect/test/Effect/promise.test.ts +++ b/packages/effect/test/Effect/promise.test.ts @@ -1,6 +1,6 @@ -import * as Effect from "effect/Effect" -import * as Option from "effect/Option" -import { describe, expect, it } from "vitest" +import { Cause, Effect, Option } from "effect" +import { assertFailure, assertSuccess, assertTrue } from "effect/test/util" +import { describe, it } from "vitest" const succeedPromiseLike: PromiseLike = { // @ts-ignore @@ -40,8 +40,8 @@ describe("Effect", () => { Effect.option ) const exit = await Effect.runPromiseExit(program) - expect(exit._tag).toBe("Success") - expect(aborted).toBe(true) + assertSuccess(exit, Option.none()) + assertTrue(aborted) }) it("PromiseLike - succeed", async () => { @@ -51,11 +51,7 @@ describe("Effect", () => { Effect.option ) const exit = await Effect.runPromiseExit(program) - expect(exit._tag).toBe("Success") - - if (exit._tag === "Success") { - expect(exit.value).toEqual(Option.some("succeed")) - } + assertSuccess(exit, Option.some("succeed")) }) it("PromiseLike - fail", async () => { @@ -65,10 +61,6 @@ describe("Effect", () => { Effect.option ) const exit = await Effect.runPromiseExit(program) - expect(exit._tag).toBe("Failure") - - if (exit._tag === "Failure") { - expect(exit.cause.toString()).toEqual("Error: fail") - } + assertFailure(exit, Cause.die("fail")) }) }) diff --git a/packages/effect/test/Effect/provide-runtime.test.ts b/packages/effect/test/Effect/provide-runtime.test.ts index 3642424c233..55fbac89cc5 100644 --- a/packages/effect/test/Effect/provide-runtime.test.ts +++ b/packages/effect/test/Effect/provide-runtime.test.ts @@ -6,8 +6,9 @@ import * as FiberRef from "effect/FiberRef" import * as Layer from "effect/Layer" import * as RuntimeFlags from "effect/RuntimeFlags" import * as Scope from "effect/Scope" +import { assertFalse, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" interface A { readonly value: number @@ -35,7 +36,7 @@ describe("Effect", () => { const pre = yield* _(Effect.context()) yield* _(Effect.provide(Effect.void, rt)) const post = yield* _(Effect.context()) - assert.isTrue(Equal.equals(pre, post)) + assertTrue(Equal.equals(pre, post)) }).pipe( Effect.scoped, Effect.provide(Layer.succeed(SomeService, someServiceImpl)) @@ -71,10 +72,10 @@ describe("Effect", () => { await Effect.runPromise(Scope.close(scope, Exit.void)) - assert.deepStrictEqual(all[0].a, 2) - assert.deepStrictEqual(all[0].b, { value: 1 }) - assert.deepStrictEqual(all[0].c, true) - assert.deepStrictEqual(all[1].a, 0) - assert.deepStrictEqual(all[1].c, false) + strictEqual(all[0].a, 2) + deepStrictEqual(all[0].b, { value: 1 }) + assertTrue(all[0].c) + strictEqual(all[1].a, 0) + assertFalse(all[1].c) }) }) diff --git a/packages/effect/test/Effect/query-nested.test.ts b/packages/effect/test/Effect/query-nested.test.ts index 1ca05bdebee..a18b6c4527f 100644 --- a/packages/effect/test/Effect/query-nested.test.ts +++ b/packages/effect/test/Effect/query-nested.test.ts @@ -5,8 +5,9 @@ import * as Effect from "effect/Effect" import * as Layer from "effect/Layer" import * as Request from "effect/Request" import * as Resolver from "effect/RequestResolver" +import { strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { describe, expect } from "vitest" +import { describe } from "vitest" interface Counter { readonly _: unique symbol @@ -171,8 +172,8 @@ describe("Effect", () => { const count = yield* $(Counter) const requests = yield* $(Requests) - expect(count.count).toBe(3) - expect(requests.count).toBe(7) + strictEqual(count.count, 3) + strictEqual(requests.count, 7) }).pipe( Effect.provide(EnvLive) )) diff --git a/packages/effect/test/Effect/query-repro.test.ts b/packages/effect/test/Effect/query-repro.test.ts index 53a3e5ca4ae..305a45054fe 100644 --- a/packages/effect/test/Effect/query-repro.test.ts +++ b/packages/effect/test/Effect/query-repro.test.ts @@ -2,8 +2,9 @@ import * as Effect from "effect/Effect" import * as Layer from "effect/Layer" import * as Request from "effect/Request" import * as RequestResolver from "effect/RequestResolver" +import { strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { describe, expect } from "vitest" +import { describe } from "vitest" export class FindIntraday extends Request.TaggedClass("FindIntraday") {} @@ -41,6 +42,6 @@ describe("interruption", () => { Effect.provide(Svc.Live), Effect.exit )) - expect(exit._tag).toEqual("Success") + strictEqual(exit._tag, "Success") })) }) diff --git a/packages/effect/test/Effect/query.test.ts b/packages/effect/test/Effect/query.test.ts index 72f53c2edd9..a78723d01d4 100644 --- a/packages/effect/test/Effect/query.test.ts +++ b/packages/effect/test/Effect/query.test.ts @@ -9,10 +9,11 @@ import * as FiberRef from "effect/FiberRef" import * as Layer from "effect/Layer" import * as Request from "effect/Request" import * as Resolver from "effect/RequestResolver" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" import type { Concurrency } from "effect/Types" -import { describe, expect } from "vitest" +import { describe } from "vitest" import { pipe } from "../../src/index.js" interface Counter { @@ -174,16 +175,16 @@ describe("Effect", () => { Effect.withRequestCaching(true), Effect.repeatN(3) ) - expect(count).toBe(1) + strictEqual(count, 1) })) it.effect("requests are executed correctly", () => provideEnv( Effect.gen(function*($) { const names = yield* $(getAllUserNames) const count = yield* $(Counter) - expect(count.count).toEqual(3) - expect(names.length).toBeGreaterThan(2) - expect(names).toEqual(userIds.map((id) => userNames.get(id))) + strictEqual(count.count, 3) + assertTrue(names.length > 2) + deepStrictEqual(names, userIds.map((id) => userNames.get(id))) }) )) it.effect("requests with dual syntax are executed correctly", () => @@ -191,9 +192,9 @@ describe("Effect", () => { Effect.gen(function*($) { const names = yield* $(getAllUserNamesPiped) const count = yield* $(Counter) - expect(count.count).toEqual(3) - expect(names.length).toBeGreaterThan(2) - expect(names).toEqual(userIds.map((id) => userNames.get(id))) + strictEqual(count.count, 3) + assertTrue(names.length > 2) + deepStrictEqual(names, userIds.map((id) => userNames.get(id))) }) )) it.effect("requests are executed correctly with fromEffectTagged", () => @@ -201,9 +202,9 @@ describe("Effect", () => { Effect.gen(function*($) { const names = yield* $(getAllUserNamesTagged) const count = yield* $(Counter) - expect(count.count).toEqual(3) - expect(names.length).toBeGreaterThan(2) - expect(names).toEqual(userIds.map((id) => userNames.get(id))) + strictEqual(count.count, 3) + assertTrue(names.length > 2) + deepStrictEqual(names, userIds.map((id) => userNames.get(id))) }) )) it.effect("batching composes", () => @@ -216,10 +217,10 @@ describe("Effect", () => { batching: true })) const count = yield* $(Counter) - expect(count.count).toEqual(3) - expect(names[0].length).toBeGreaterThan(2) - expect(names[0]).toEqual(userIds.map((id) => userNames.get(id))) - expect(names[0]).toEqual(names[1]) + strictEqual(count.count, 3) + assertTrue(names[0].length > 2) + deepStrictEqual(names[0], userIds.map((id) => userNames.get(id))) + deepStrictEqual(names[0], names[1]) }) )) it.effect("withSpan doesn't break batching", () => @@ -234,7 +235,7 @@ describe("Effect", () => { Effect.withRequestCaching(false) ) const count = yield* $(Counter) - expect(count.count).toEqual(1) + strictEqual(count.count, 1) }) )) it.effect("batching is independent from parallelism", () => @@ -242,9 +243,9 @@ describe("Effect", () => { Effect.gen(function*($) { const names = yield* $(getAllUserNamesN(5)) const count = yield* $(Counter) - expect(count.count).toEqual(3) - expect(names.length).toBeGreaterThan(2) - expect(names).toEqual(userIds.map((id) => userNames.get(id))) + strictEqual(count.count, 3) + assertTrue(names.length > 2) + deepStrictEqual(names, userIds.map((id) => userNames.get(id))) }) )) it.effect("batching doesn't break interruption", () => @@ -259,15 +260,15 @@ describe("Effect", () => { }), Effect.exit ) - expect(exit._tag).toEqual("Failure") + strictEqual(exit._tag, "Failure") if (exit._tag === "Failure") { - expect(Cause.isInterruptedOnly(exit.cause)).toEqual(true) + assertTrue(Cause.isInterruptedOnly(exit.cause)) } const cache = yield* $(FiberRef.get(FiberRef.currentRequestCache)) const values = yield* $(cache.values) - expect(values[0].handle.state.current._tag).toEqual("Done") - expect(yield* $(Counter)).toEqual({ count: 0 }) - expect(yield* $(FiberRef.get(interrupts))).toEqual({ interrupts: 1 }) + strictEqual(values[0].handle.state.current._tag, "Done") + deepStrictEqual(yield* $(Counter), { count: 0 }) + deepStrictEqual(yield* $(FiberRef.get(interrupts)), { interrupts: 1 }) }) ) )) @@ -279,12 +280,12 @@ describe("Effect", () => { yield* $(Effect.yieldNow()) yield* $(Fiber.interrupt(fiber)) const exit = yield* $(Fiber.await(fiber)) - expect(exit._tag).toEqual("Failure") + strictEqual(exit._tag, "Failure") if (exit._tag === "Failure") { - expect(Cause.isInterruptedOnly(exit.cause)).toEqual(true) + assertTrue(Cause.isInterruptedOnly(exit.cause)) } - expect(yield* $(Counter)).toEqual({ count: 0 }) - expect(yield* $(FiberRef.get(interrupts))).toEqual({ interrupts: 1 }) + deepStrictEqual(yield* $(Counter), { count: 0 }) + deepStrictEqual(yield* $(FiberRef.get(interrupts)), { interrupts: 1 }) }) ) )) @@ -296,12 +297,12 @@ describe("Effect", () => { yield* $(Effect.yieldNow()) yield* $(Fiber.interrupt(fiber)) const exit = yield* $(Fiber.await(fiber)) - expect(exit._tag).toEqual("Failure") + strictEqual(exit._tag, "Failure") if (exit._tag === "Failure") { - expect(Cause.isInterruptedOnly(exit.cause)).toEqual(true) + assertTrue(Cause.isInterruptedOnly(exit.cause)) } - expect(yield* $(Counter)).toEqual({ count: 3 }) - expect(yield* $(FiberRef.get(interrupts))).toEqual({ interrupts: 0 }) + deepStrictEqual(yield* $(Counter), { count: 3 }) + deepStrictEqual(yield* $(FiberRef.get(interrupts)), { interrupts: 0 }) }) ) )) @@ -317,12 +318,12 @@ describe("Effect", () => { }), Effect.exit ) - expect(exit._tag).toEqual("Failure") + strictEqual(exit._tag, "Failure") if (exit._tag === "Failure") { - expect(Cause.isInterruptedOnly(exit.cause)).toEqual(true) + assertTrue(Cause.isInterruptedOnly(exit.cause)) } - expect(yield* $(Counter)).toEqual({ count: 0 }) - expect(yield* $(FiberRef.get(interrupts))).toEqual({ interrupts: 1 }) + deepStrictEqual(yield* $(Counter), { count: 0 }) + deepStrictEqual(yield* $(FiberRef.get(interrupts)), { interrupts: 1 }) }) ) )) @@ -341,9 +342,9 @@ describe("Effect", () => { Effect.withRequestBatching(true) ) const count = yield* $(Counter) - expect(count.count).toEqual(2) - expect(a).toEqual(userNames.get(userIds[0])) - expect(b).toEqual(userNames.get(userIds[1])) + strictEqual(count.count, 2) + deepStrictEqual(a, userNames.get(userIds[0])) + deepStrictEqual(b, userNames.get(userIds[1])) }) )) it.effect("zip/parallel is batched by default", () => @@ -360,9 +361,9 @@ describe("Effect", () => { ) ) const count = yield* $(Counter) - expect(count.count).toEqual(1) - expect(a).toEqual(userNames.get(userIds[0])) - expect(b).toEqual(userNames.get(userIds[1])) + strictEqual(count.count, 1) + deepStrictEqual(a, userNames.get(userIds[0])) + deepStrictEqual(b, userNames.get(userIds[1])) }) )) it.effect("cache respects ttl", () => @@ -370,15 +371,15 @@ describe("Effect", () => { Effect.gen(function*($) { yield* $(getAllUserIds) yield* $(getAllUserIds) - expect(yield* $(Counter)).toEqual({ count: 1 }) + deepStrictEqual(yield* $(Counter), { count: 1 }) yield* $(TestClock.adjust(seconds(10))) yield* $(getAllUserIds) yield* $(getAllUserIds) - expect(yield* $(Counter)).toEqual({ count: 1 }) + deepStrictEqual(yield* $(Counter), { count: 1 }) yield* $(TestClock.adjust(seconds(60))) yield* $(getAllUserIds) yield* $(getAllUserIds) - expect(yield* $(Counter)).toEqual({ count: 2 }) + deepStrictEqual(yield* $(Counter), { count: 2 }) }) )) it.effect("cache can be warmed up", () => @@ -387,11 +388,11 @@ describe("Effect", () => { yield* $(Effect.cacheRequestResult(GetAllIds({}), Exit.succeed(userIds))) yield* $(getAllUserIds) yield* $(getAllUserIds) - expect(yield* $(Counter)).toEqual({ count: 0 }) + deepStrictEqual(yield* $(Counter), { count: 0 }) yield* $(TestClock.adjust(seconds(65))) yield* $(getAllUserIds) yield* $(getAllUserIds) - expect(yield* $(Counter)).toEqual({ count: 1 }) + deepStrictEqual(yield* $(Counter), { count: 1 }) }) )) it.effect("cache can be disabled", () => @@ -399,15 +400,15 @@ describe("Effect", () => { Effect.withRequestCaching(false)(Effect.gen(function*($) { yield* $(getAllUserIds) yield* $(getAllUserIds) - expect(yield* $(Counter)).toEqual({ count: 2 }) + deepStrictEqual(yield* $(Counter), { count: 2 }) yield* $(TestClock.adjust(seconds(10))) yield* $(getAllUserIds) yield* $(getAllUserIds) - expect(yield* $(Counter)).toEqual({ count: 4 }) + deepStrictEqual(yield* $(Counter), { count: 4 }) yield* $(TestClock.adjust(seconds(60))) yield* $(getAllUserIds) yield* $(getAllUserIds) - expect(yield* $(Counter)).toEqual({ count: 6 }) + deepStrictEqual(yield* $(Counter), { count: 6 }) })) )) @@ -424,8 +425,8 @@ describe("Effect", () => { ) const requests = yield* $(Requests) const invocations = yield* $(Counter) - expect(requests.count).toEqual(2) - expect(invocations.count).toEqual(1) + deepStrictEqual(requests.count, 2) + deepStrictEqual(invocations.count, 1) }) )) }) diff --git a/packages/effect/test/Effect/racing.test.ts b/packages/effect/test/Effect/racing.test.ts index 2d97b46b401..f11be811e89 100644 --- a/packages/effect/test/Effect/racing.test.ts +++ b/packages/effect/test/Effect/racing.test.ts @@ -1,14 +1,15 @@ import * as Duration from "effect/Duration" import * as Effect from "effect/Effect" import { pipe } from "effect/Function" +import { strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("returns first success", () => Effect.gen(function*($) { const result = yield* $(Effect.raceAll([Effect.fail("fail"), Effect.succeed(24)])) - assert.strictEqual(result, 24) + strictEqual(result, 24) })) it.live("returns last failure", () => Effect.gen(function*($) { @@ -18,7 +19,7 @@ describe("Effect", () => { Effect.flip ) ) - assert.strictEqual(result, 24) + strictEqual(result, 24) })) it.live("returns success when it happens after failure", () => Effect.gen(function*($) { @@ -28,6 +29,6 @@ describe("Effect", () => { pipe(Effect.succeed(24), Effect.zipLeft(Effect.sleep(Duration.millis(100)))) ]) ) - assert.strictEqual(result, 24) + strictEqual(result, 24) })) }) diff --git a/packages/effect/test/Effect/rendezvous.test.ts b/packages/effect/test/Effect/rendezvous.test.ts index c2e895f8411..eeca876e1ee 100644 --- a/packages/effect/test/Effect/rendezvous.test.ts +++ b/packages/effect/test/Effect/rendezvous.test.ts @@ -1,9 +1,10 @@ import * as Effect from "effect/Effect" import * as Fiber from "effect/Fiber" import * as Queue from "effect/Queue" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("bounded 0 is rendezvous", () => @@ -38,7 +39,7 @@ describe("Effect", () => { yield* _(Fiber.join(Fiber.zip(fiber, fiber2))) - assert.deepEqual(logs, [ + deepStrictEqual(logs, [ "sending message", "receiving message", "received message", diff --git a/packages/effect/test/Effect/repeating.test.ts b/packages/effect/test/Effect/repeating.test.ts index 7620ca57958..0ae2864b140 100644 --- a/packages/effect/test/Effect/repeating.test.ts +++ b/packages/effect/test/Effect/repeating.test.ts @@ -2,8 +2,9 @@ import * as Effect from "effect/Effect" import { constFalse, constTrue, pipe } from "effect/Function" import * as Ref from "effect/Ref" import * as Schedule from "effect/Schedule" +import { deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("succeeds eventually", () => @@ -20,7 +21,7 @@ describe("Effect", () => { } const ref = yield* $(Ref.make(0)) const result = yield* $(Effect.eventually(effect(ref))) - assert.strictEqual(result, 10) + strictEqual(result, 10) })) it.effect("repeat/until - repeats until condition is true", () => @@ -33,7 +34,7 @@ describe("Effect", () => { Effect.repeat({ until: (n) => n === 0 }) ) const result = yield* $(Ref.get(output)) - assert.strictEqual(result, 10) + strictEqual(result, 10) })) it.effect("repeat/until - preserves return value", () => @@ -43,7 +44,7 @@ describe("Effect", () => { Ref.updateAndGet(input, (n) => n - 1), Effect.repeat({ until: (n) => n === 0 }) ) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("repeat/until - always evaluates effect at least once", () => @@ -51,7 +52,7 @@ describe("Effect", () => { const ref = yield* $(Ref.make(0)) yield* $(Ref.update(ref, (n) => n + 1), Effect.repeat({ until: constTrue })) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("repeat/until - repeats until the effectful condition is true", () => Effect.gen(function*($) { @@ -63,14 +64,14 @@ describe("Effect", () => { Effect.repeat({ until: (n) => Effect.succeed(n === 0) }) ) const result = yield* $(Ref.get(output)) - assert.strictEqual(result, 10) + strictEqual(result, 10) })) it.effect("repeat/until - always evaluates the effect at least once", () => Effect.gen(function*($) { const ref = yield* $(Ref.make(0)) yield* $(Ref.update(ref, (n) => n + 1), Effect.repeat({ until: () => Effect.succeed(true) })) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("repeat/while - repeats while the condition is true", () => Effect.gen(function*($) { @@ -82,14 +83,14 @@ describe("Effect", () => { Effect.repeat({ while: (n) => n >= 0 }) ) const result = yield* $(Ref.get(output)) - assert.strictEqual(result, 11) + strictEqual(result, 11) })) it.effect("repeat/while - always evaluates the effect at least once", () => Effect.gen(function*($) { const ref = yield* $(Ref.make(0)) yield* $(Ref.update(ref, (n) => n + 1), Effect.repeat({ while: constFalse })) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("repeat/while - repeats while condition is true", () => Effect.gen(function*($) { @@ -101,14 +102,14 @@ describe("Effect", () => { Effect.repeat({ while: (v) => Effect.succeed(v >= 0) }) ) const result = yield* $(Ref.get(output)) - assert.strictEqual(result, 11) + strictEqual(result, 11) })) it.effect("repeat/while - always evaluates effect at least once", () => Effect.gen(function*($) { const ref = yield* $(Ref.make(0)) yield* $(Ref.update(ref, (n) => n + 1), Effect.repeat({ while: () => Effect.succeed(false) })) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("repeat/schedule", () => @@ -116,7 +117,7 @@ describe("Effect", () => { const ref = yield* $(Ref.make(0)) yield* $(Ref.update(ref, (n) => n + 1), Effect.repeat(Schedule.recurs(3))) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 4) + strictEqual(result, 4) })) it.effect("repeat/schedule + until", () => @@ -127,7 +128,7 @@ describe("Effect", () => { Effect.repeat({ schedule: Schedule.recurs(3), until: (n) => n === 3 }) ) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 3) + strictEqual(result, 3) })) it.effect("repeat/schedule + while", () => @@ -138,7 +139,7 @@ describe("Effect", () => { Effect.repeat({ schedule: Schedule.recurs(3), while: (n) => n < 3 }) ) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 3) + strictEqual(result, 3) })) it.effect("repeat/times ", () => @@ -152,7 +153,7 @@ describe("Effect", () => { Effect.repeat({ times: 2 }) ) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(result, [0, 1, 2]) - assert.deepStrictEqual(effectResult, [0, 1, 2]) + deepStrictEqual(result, [0, 1, 2]) + deepStrictEqual(effectResult, [0, 1, 2]) })) }) diff --git a/packages/effect/test/Effect/retrying.test.ts b/packages/effect/test/Effect/retrying.test.ts index 1e34603256d..84585ff4b97 100644 --- a/packages/effect/test/Effect/retrying.test.ts +++ b/packages/effect/test/Effect/retrying.test.ts @@ -2,8 +2,9 @@ import * as Effect from "effect/Effect" import { constFalse, constTrue } from "effect/Function" import * as Ref from "effect/Ref" import * as Schedule from "effect/Schedule" +import { strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("retry/until - retries until condition is true", () => @@ -16,14 +17,14 @@ describe("Effect", () => { Effect.flipWith(Effect.retry({ until: (n) => n === 0 })) ) const result = yield* $(Ref.get(output)) - assert.strictEqual(result, 10) + strictEqual(result, 10) })) it.effect("retry/until - runs at least once", () => Effect.gen(function*($) { const ref = yield* $(Ref.make(0)) yield* $(Ref.update(ref, (n) => n + 1), Effect.flipWith(Effect.retry({ until: constTrue }))) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("retry/until - retries until condition is true", () => Effect.gen(function*($) { @@ -35,7 +36,7 @@ describe("Effect", () => { Effect.flipWith(Effect.retry({ until: (n) => Effect.succeed(n === 0) })) ) const result = yield* $(Ref.get(output)) - assert.strictEqual(result, 10) + strictEqual(result, 10) })) it.effect("retry/until - runs at least once", () => Effect.gen(function*($) { @@ -45,7 +46,7 @@ describe("Effect", () => { Effect.flipWith(Effect.retry({ until: () => Effect.succeed(true) })) ) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("retry/while - retries while condition is true", () => Effect.gen(function*($) { @@ -57,14 +58,14 @@ describe("Effect", () => { Effect.flipWith(Effect.retry({ while: (n) => n >= 0 })) ) const result = yield* $(Ref.get(output)) - assert.strictEqual(result, 11) + strictEqual(result, 11) })) it.effect("retry/while - runs at least once", () => Effect.gen(function*($) { const ref = yield* $(Ref.make(0)) yield* $(Ref.update(ref, (n) => n + 1), Effect.flipWith(Effect.retry({ while: constFalse }))) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("retry/while - retries while condition is true", () => Effect.gen(function*($) { @@ -76,7 +77,7 @@ describe("Effect", () => { Effect.flipWith(Effect.retry({ while: (n) => Effect.succeed(n >= 0) })) ) const result = yield* $(Ref.get(output)) - assert.strictEqual(result, 11) + strictEqual(result, 11) })) it.effect("retry/while - runs at least once", () => Effect.gen(function*($) { @@ -86,7 +87,7 @@ describe("Effect", () => { Effect.flipWith(Effect.retry({ while: () => Effect.succeed(false) })) ) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("retry/schedule", () => Effect.gen(function*($) { @@ -96,7 +97,7 @@ describe("Effect", () => { Effect.flipWith(Effect.retry(Schedule.recurs(3))) ) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 4) + strictEqual(result, 4) })) it.effect("retry/schedule + until", () => @@ -110,7 +111,7 @@ describe("Effect", () => { })) ) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 3) + strictEqual(result, 3) })) it.effect("retry/schedule + until effect", () => @@ -124,7 +125,7 @@ describe("Effect", () => { })) ) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 3) + strictEqual(result, 3) })) it.effect("retry/schedule + until error", () => @@ -137,7 +138,7 @@ describe("Effect", () => { until: (_n) => Effect.fail("err" as const) })) ) - assert.strictEqual(result, "err") + strictEqual(result, "err") })) it.effect("retry/schedule + while", () => @@ -151,7 +152,7 @@ describe("Effect", () => { })) ) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 3) + strictEqual(result, 3) })) it.effect("retry/schedule + while error", () => @@ -164,7 +165,7 @@ describe("Effect", () => { while: (_n) => Effect.fail("err" as const) })) ) - assert.strictEqual(result, "err") + strictEqual(result, "err") })) it.effect("retry/schedule + while effect", () => @@ -178,6 +179,6 @@ describe("Effect", () => { })) ) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 3) + strictEqual(result, 3) })) }) diff --git a/packages/effect/test/Effect/runtimeFlags.test.ts b/packages/effect/test/Effect/runtimeFlags.test.ts index 60fb62f43cb..583ea970e2a 100644 --- a/packages/effect/test/Effect/runtimeFlags.test.ts +++ b/packages/effect/test/Effect/runtimeFlags.test.ts @@ -1,25 +1,26 @@ import * as Effect from "effect/Effect" import * as Flags from "effect/RuntimeFlags" import * as Patch from "effect/RuntimeFlagsPatch" +import { assertFalse, assertTrue } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.it("should enable flags in the current fiber", () => Effect.runPromise(Effect.gen(function*($) { const before = yield* $(Effect.getRuntimeFlags) - assert.isFalse(Flags.isEnabled(before, Flags.OpSupervision)) + assertFalse(Flags.isEnabled(before, Flags.OpSupervision)) yield* $(Effect.patchRuntimeFlags(Patch.enable(Flags.OpSupervision))) const after = yield* $(Effect.getRuntimeFlags) - assert.isTrue(Flags.isEnabled(after, Flags.OpSupervision)) + assertTrue(Flags.isEnabled(after, Flags.OpSupervision)) }))) it.it("should enable flags in the wrapped effect", () => Effect.runPromise(Effect.gen(function*($) { const before = yield* $(Effect.getRuntimeFlags) - assert.isFalse(Flags.isEnabled(before, Flags.OpSupervision)) + assertFalse(Flags.isEnabled(before, Flags.OpSupervision)) const inside = yield* $(Effect.getRuntimeFlags, Effect.withRuntimeFlagsPatch(Patch.enable(Flags.OpSupervision))) const after = yield* $(Effect.getRuntimeFlags) - assert.isFalse(Flags.isEnabled(after, Flags.OpSupervision)) - assert.isTrue(Flags.isEnabled(inside, Flags.OpSupervision)) + assertFalse(Flags.isEnabled(after, Flags.OpSupervision)) + assertTrue(Flags.isEnabled(inside, Flags.OpSupervision)) }))) }) diff --git a/packages/effect/test/Effect/scheduler.test.ts b/packages/effect/test/Effect/scheduler.test.ts index 59a5c0cdfc5..898c28a46aa 100644 --- a/packages/effect/test/Effect/scheduler.test.ts +++ b/packages/effect/test/Effect/scheduler.test.ts @@ -1,7 +1,8 @@ import * as Effect from "effect/Effect" import * as Scheduler from "effect/Scheduler" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("matrix schedules according to priority", () => @@ -42,33 +43,33 @@ describe("Effect", () => { Effect.yieldNow(), Effect.withScheduler(scheduler) ) - assert.deepEqual(ps000, [0]) + deepStrictEqual(ps000, [0]) yield* $( Effect.yieldNow({ priority: 50 }), Effect.withScheduler(scheduler) ) - assert.deepEqual(ps000, [0, 0]) + deepStrictEqual(ps000, [0, 0]) yield* $( Effect.yieldNow({ priority: 100 }), Effect.withScheduler(scheduler) ) - assert.deepEqual(ps100, [100]) + deepStrictEqual(ps100, [100]) yield* $( Effect.yieldNow({ priority: 150 }), Effect.withScheduler(scheduler) ) - assert.deepEqual(ps100, [100, 100]) + deepStrictEqual(ps100, [100, 100]) yield* $( Effect.yieldNow({ priority: 200 }), Effect.withScheduler(scheduler) ) - assert.deepEqual(ps100, [100, 100]) - assert.deepEqual(ps200, [200]) + deepStrictEqual(ps100, [100, 100]) + deepStrictEqual(ps200, [200]) yield* $( Effect.yieldNow({ priority: 300 }), Effect.withScheduler(scheduler) ) - assert.deepEqual(ps100, [100, 100]) - assert.deepEqual(ps200, [200]) + deepStrictEqual(ps100, [100, 100]) + deepStrictEqual(ps200, [200]) })) }) diff --git a/packages/effect/test/Effect/scheduling.test.ts b/packages/effect/test/Effect/scheduling.test.ts index 418dae821a9..91f22ca3a5e 100644 --- a/packages/effect/test/Effect/scheduling.test.ts +++ b/packages/effect/test/Effect/scheduling.test.ts @@ -4,9 +4,10 @@ import * as Effect from "effect/Effect" import { pipe } from "effect/Function" import * as Ref from "effect/Ref" import * as Schedule from "effect/Schedule" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("schedule - runs effect for each recurrence of the schedule", () => @@ -21,6 +22,6 @@ describe("Effect", () => { yield* $(TestClock.adjust(Duration.seconds(5))) const value = yield* $(Ref.get(ref)) const expected = [1, 2, 3, 4, 5].map(Duration.seconds) - assert.deepStrictEqual(value, expected) + deepStrictEqual(value, expected) })) }) diff --git a/packages/effect/test/Effect/scope-ref.test.ts b/packages/effect/test/Effect/scope-ref.test.ts index 8bc6d44b539..8550a2a03dc 100644 --- a/packages/effect/test/Effect/scope-ref.test.ts +++ b/packages/effect/test/Effect/scope-ref.test.ts @@ -4,8 +4,9 @@ import * as FiberRef from "effect/FiberRef" import * as Layer from "effect/Layer" import * as List from "effect/List" import * as Logger from "effect/Logger" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" const ref = FiberRef.unsafeMake(List.empty()) const env = GenericTag<"context", number>("context") @@ -45,7 +46,7 @@ describe("Effect", () => { withValue("EXTERN") ) - assert.deepStrictEqual(messages, [ + deepStrictEqual(messages, [ ["1 | acquire | A > INNER > OUTER > EXTERN"], ["1 | release | R > INNER > OUTER > EXTERN"] ]) diff --git a/packages/effect/test/Effect/semaphore.test.ts b/packages/effect/test/Effect/semaphore.test.ts index 483cc67230a..9d01566ce27 100644 --- a/packages/effect/test/Effect/semaphore.test.ts +++ b/packages/effect/test/Effect/semaphore.test.ts @@ -1,8 +1,9 @@ import * as D from "effect/Duration" import * as Effect from "effect/Effect" +import { strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("semaphore works", () => @@ -18,9 +19,9 @@ describe("Effect", () => { )) ) yield* $(TestClock.adjust(D.seconds(3))) - assert.equal(messages.length, 2) + strictEqual(messages.length, 2) yield* $(TestClock.adjust(D.seconds(3))) - assert.equal(messages.length, 4) + strictEqual(messages.length, 4) yield* $( Effect.fork(Effect.all( [0, 1, 2, 3].map((n) => @@ -30,9 +31,9 @@ describe("Effect", () => { )) ) yield* $(TestClock.adjust(D.seconds(3))) - assert.equal(messages.length, 6) + strictEqual(messages.length, 6) yield* $(TestClock.adjust(D.seconds(3))) - assert.equal(messages.length, 8) + strictEqual(messages.length, 8) })) it.effect("releaseAll", () => diff --git a/packages/effect/test/Effect/sequencing.test.ts b/packages/effect/test/Effect/sequencing.test.ts index 1aeb59a094a..b5cbbf0abfa 100644 --- a/packages/effect/test/Effect/sequencing.test.ts +++ b/packages/effect/test/Effect/sequencing.test.ts @@ -8,8 +8,9 @@ import { constFalse, constTrue, pipe } from "effect/Function" import * as HashSet from "effect/HashSet" import * as Option from "effect/Option" import * as Ref from "effect/Ref" +import { assertFalse, assertLeft, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("andThen", () => @@ -24,16 +25,16 @@ describe("Effect", () => { const a7 = Effect.andThen(Effect.succeed(0), "ok") const a8 = Effect.andThen(Effect.succeed(0), () => Promise.resolve("ok")) const a9 = Effect.andThen(Effect.succeed(0), Promise.resolve("ok")) - assert.strictEqual(yield* $(a0), 1) - assert.strictEqual(yield* $(a1), 1) - assert.strictEqual(yield* $(a2), 1) - assert.strictEqual(yield* $(a3), 1) - assert.strictEqual(yield* $(a4), "ok") - assert.strictEqual(yield* $(a5), "ok") - assert.strictEqual(yield* $(a6), "ok") - assert.strictEqual(yield* $(a7), "ok") - assert.strictEqual(yield* $(a8), "ok") - assert.strictEqual(yield* $(a9), "ok") + strictEqual(yield* $(a0), 1) + strictEqual(yield* $(a1), 1) + strictEqual(yield* $(a2), 1) + strictEqual(yield* $(a3), 1) + strictEqual(yield* $(a4), "ok") + strictEqual(yield* $(a5), "ok") + strictEqual(yield* $(a6), "ok") + strictEqual(yield* $(a7), "ok") + strictEqual(yield* $(a8), "ok") + strictEqual(yield* $(a9), "ok") })) it.effect("tap", () => Effect.gen(function*() { @@ -50,27 +51,27 @@ describe("Effect", () => { const a10 = Effect.tap(Effect.succeed(0), "ok") const a11 = Effect.tap(Effect.succeed(0), () => Promise.resolve("ok")) const a12 = Effect.tap(Effect.succeed(0), Promise.resolve("ok")) - assert.strictEqual(yield* a0, 0) - assert.strictEqual(yield* a1, 0) - assert.strictEqual(yield* a2, 0) - assert.strictEqual(yield* a3, 0) - assert.strictEqual(yield* a4, 0) - assert.strictEqual(yield* a5, 0) - assert.strictEqual(yield* a6, 0) - assert.strictEqual(yield* a7, 0) - assert.strictEqual(yield* a8, 0) - assert.strictEqual(yield* a9, 0) - assert.strictEqual(yield* a10, 0) - assert.strictEqual(yield* a11, 0) - assert.strictEqual(yield* a12, 0) + strictEqual(yield* a0, 0) + strictEqual(yield* a1, 0) + strictEqual(yield* a2, 0) + strictEqual(yield* a3, 0) + strictEqual(yield* a4, 0) + strictEqual(yield* a5, 0) + strictEqual(yield* a6, 0) + strictEqual(yield* a7, 0) + strictEqual(yield* a8, 0) + strictEqual(yield* a9, 0) + strictEqual(yield* a10, 0) + strictEqual(yield* a11, 0) + strictEqual(yield* a12, 0) })) it.effect("flattens nested effects", () => Effect.gen(function*($) { const effect = Effect.succeed(Effect.succeed("test")) const flatten1 = yield* $(Effect.flatten(effect)) const flatten2 = yield* $(Effect.flatten(effect)) - assert.strictEqual(flatten1, "test") - assert.strictEqual(flatten2, "test") + strictEqual(flatten1, "test") + strictEqual(flatten2, "test") })) it.effect("if - runs `onTrue` if result of `b` is `true`", () => Effect.gen(function*($) { @@ -81,7 +82,7 @@ describe("Effect", () => { onFalse: () => Effect.succeed(false) }) ) - assert.isTrue(result) + assertTrue(result) })) it.effect("if - runs `onFalse` if result of `b` is `false`", () => Effect.gen(function*($) { @@ -92,7 +93,7 @@ describe("Effect", () => { onTrue: () => Effect.succeed(false) }) ) - assert.isTrue(result) + assertTrue(result) })) describe("", () => { it.effect("tapErrorCause - effectually peeks at the cause of the failure of this effect", () => @@ -102,8 +103,8 @@ describe("Effect", () => { pipe(Effect.dieMessage("die"), Effect.tapErrorCause(() => Ref.set(ref, true)), Effect.exit) ) const effect = yield* $(Ref.get(ref)) - assert.isTrue(Exit.isFailure(result) && Option.isSome(Cause.dieOption(result.effect_instruction_i0))) - assert.isTrue(effect) + assertTrue(Exit.isFailure(result) && Option.isSome(Cause.dieOption(result.effect_instruction_i0))) + assertTrue(effect) })) }) it.effect("tapDefect - effectually peeks at defects", () => @@ -115,8 +116,8 @@ describe("Effect", () => { Effect.exit ) const effect = yield* $(Ref.get(ref)) - assert.isTrue(Exit.isFailure(result) && Option.isSome(Cause.dieOption(result.effect_instruction_i0))) - assert.isTrue(effect) + assertTrue(Exit.isFailure(result) && Option.isSome(Cause.dieOption(result.effect_instruction_i0))) + assertTrue(effect) })) it.effect("tapDefect - leaves failures", () => Effect.gen(function*($) { @@ -127,8 +128,8 @@ describe("Effect", () => { Effect.exit ) const effect = yield* $(Ref.get(ref)) - assert.deepStrictEqual(result, Exit.fail("fail")) - assert.isFalse(effect) + deepStrictEqual(result, Exit.fail("fail")) + assertFalse(effect) })) it.effect("unless - executes correct branch only", () => Effect.gen(function*($) { @@ -140,9 +141,9 @@ describe("Effect", () => { const failure = new Error("expected") yield* $(Effect.fail(failure), Effect.unless(constTrue)) const failed = yield* $(Effect.fail(failure), Effect.unless(constFalse), Effect.either) - assert.strictEqual(v1, 0) - assert.strictEqual(v2, 2) - assert.deepStrictEqual(failed, Either.left(failure)) + strictEqual(v1, 0) + strictEqual(v2, 2) + assertLeft(failed, failure) })) it.effect("unlessEffect - executes condition effect and correct branch", () => Effect.gen(function*($) { @@ -159,11 +160,11 @@ describe("Effect", () => { const failure = new Error("expected") yield* $(Effect.fail(failure), Effect.unlessEffect(conditionTrue)) const failed = yield* $(Effect.fail(failure), Effect.unlessEffect(conditionFalse), Effect.either) - assert.strictEqual(v1, 0) - assert.strictEqual(c1, 1) - assert.strictEqual(v2, 2) - assert.strictEqual(c2, 2) - assert.deepStrictEqual(failed, Either.left(failure)) + strictEqual(v1, 0) + strictEqual(c1, 1) + strictEqual(v2, 2) + strictEqual(c2, 2) + assertLeft(failed, failure) })) it.effect("when - executes correct branch only", () => Effect.gen(function*($) { @@ -175,9 +176,9 @@ describe("Effect", () => { const failure = new Error("expected") yield* $(Effect.fail(failure), Effect.when(constFalse)) const failed = yield* $(Effect.fail(failure), Effect.when(constTrue), Effect.either) - assert.strictEqual(v1, 0) - assert.strictEqual(v2, 2) - assert.deepStrictEqual(failed, Either.left(failure)) + strictEqual(v1, 0) + strictEqual(v2, 2) + assertLeft(failed, failure) })) it.effect("whenEffect - executes condition effect and correct branch", () => Effect.gen(function*($) { @@ -194,11 +195,11 @@ describe("Effect", () => { const failure = new Error("expected") yield* $(Effect.fail(failure), Effect.whenEffect(conditionFalse)) const failed = yield* $(Effect.fail(failure), Effect.whenEffect(conditionTrue), Effect.either) - assert.strictEqual(v1, 0) - assert.strictEqual(c1, 1) - assert.strictEqual(v2, 2) - assert.strictEqual(c2, 2) - assert.deepStrictEqual(failed, Either.left(failure)) + strictEqual(v1, 0) + strictEqual(c1, 1) + strictEqual(v2, 2) + strictEqual(c2, 2) + assertLeft(failed, failure) })) it.effect("zip/parallel - combines results", () => Effect.gen(function*($) { @@ -208,7 +209,7 @@ describe("Effect", () => { Effect.flatMap((tuple) => Effect.succeed(tuple[0] + tuple[1])), Effect.map((n) => n === 3) ) - assert.isTrue(result) + assertTrue(result) })) it.effect("zip/parallel - does not swallow exit causes of loser", () => Effect.gen(function*($) { @@ -222,7 +223,7 @@ describe("Effect", () => { ) ) ) - assert.isAbove(HashSet.size(result), 0) + assertTrue(HashSet.size(result) > 0) })) it.effect("zip/parallel - does not report failure when interrupting loser after it succeeded", () => Effect.gen(function*($) { @@ -235,7 +236,7 @@ describe("Effect", () => { Effect.map(Either.mapLeft(Cause.isInterrupted)) ) ) - assert.deepStrictEqual(result, Either.left(true)) + assertLeft(result, true) })) it.effect("zip/parallel - paralellizes simple success values", () => Effect.gen(function*($) { @@ -249,7 +250,7 @@ describe("Effect", () => { ) } const result = yield* $(countdown(50)) - assert.strictEqual(result, 150) + strictEqual(result, 150) })) it.effect("zip/parallel - does not kill fiber when forked on parent scope", () => Effect.gen(function*($) { @@ -277,8 +278,8 @@ describe("Effect", () => { const rightResult = result[1] const leftResult = yield* $(Fiber.await(leftInnerFiber)) const interrupted = yield* $(Ref.get(ref)) - assert.isFalse(interrupted) - assert.deepStrictEqual(leftResult, Exit.succeed("foo")) - assert.strictEqual(rightResult, 42) + assertFalse(interrupted) + deepStrictEqual(leftResult, Exit.succeed("foo")) + strictEqual(rightResult, 42) })) }) diff --git a/packages/effect/test/Effect/service.test.ts b/packages/effect/test/Effect/service.test.ts index 07a05ba01b3..af6db511d7b 100644 --- a/packages/effect/test/Effect/service.test.ts +++ b/packages/effect/test/Effect/service.test.ts @@ -4,7 +4,8 @@ import * as Effect from "effect/Effect" import { pipe } from "effect/Function" import * as Layer from "effect/Layer" import * as Scope from "effect/Scope" -import { describe, expect, it } from "effect/test/utils/extend" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "effect/test/utils/extend" class Prefix extends Effect.Service()("Prefix", { sync: () => ({ @@ -55,23 +56,23 @@ class Scoped extends Effect.Service()("Scoped", { describe("Effect.Service", () => { it("make is a function", () => { - expect(pipe({ prefix: "OK" }, Prefix.make)).toBeInstanceOf(Prefix) + assertTrue(pipe({ prefix: "OK" }, Prefix.make) instanceof Prefix) }) it("tags is a tag and default is a layer", () => { - expect(Layer.isLayer(Logger.Default)).toBe(true) - expect(Layer.isLayer(Logger.DefaultWithoutDependencies)).toBe(true) - expect(Context.isTag(Logger)).toBe(true) + assertTrue(Layer.isLayer(Logger.Default)) + assertTrue(Layer.isLayer(Logger.DefaultWithoutDependencies)) + assertTrue(Context.isTag(Logger)) }) it.effect("correctly wires dependencies", () => Effect.gen(function*() { yield* Logger.info("Ok") - expect(messages).toEqual(["[PRE][Ok][POST]"]) + deepStrictEqual(messages, ["[PRE][Ok][POST]"]) const { prefix } = yield* Prefix - expect(prefix).toEqual("PRE") + strictEqual(prefix, "PRE") const { postfix } = yield* Postfix - expect(postfix).toEqual("POST") - expect(yield* Prefix.use((_) => _._tag)).toBe("Prefix") + strictEqual(postfix, "POST") + strictEqual(yield* Prefix.use((_) => _._tag), "Prefix") }).pipe( Effect.provide([ Logger.Default, @@ -92,7 +93,7 @@ describe("Effect.Service", () => { } return Effect.gen(function*() { const time = yield* Time.use((_) => _.now) - expect(time).toBeInstanceOf(Date) + assertTrue(time instanceof Date) }).pipe(Effect.provide(Time.Default)) }) @@ -114,7 +115,7 @@ describe("Effect.Service", () => { return Effect.gen(function*() { const time = yield* Time.use((_) => _.now) const time2 = yield* Time.use((_) => _.now2) - expect(time).toStrictEqual(time2) + strictEqual(time, time2) }).pipe(Effect.provide(Time.Default)) }) @@ -137,9 +138,9 @@ describe("Effect.Service", () => { return Effect.gen(function*() { const time = yield* Time const date = yield* Time.use((_) => _.now) - expect(date).toBeInstanceOf(Date) - expect(time).toBeInstanceOf(Time) - expect(time).toBeInstanceOf(TimeLive) + assertTrue(date instanceof Date) + assertTrue(time instanceof Time) + assertTrue(time instanceof TimeLive) }).pipe(Effect.provide(Time.Default)) }) @@ -154,15 +155,15 @@ describe("Effect.Service", () => { Effect.provide(MapThing.Default) ) - expect(map).toBeInstanceOf(MapThing) - expect(map).toBeInstanceOf(Map) + assertTrue(map instanceof MapThing) + assertTrue(map instanceof Map) const map2 = yield* MapThing.set("a", 1).pipe( Effect.provide(MapThing.Default) ) - expect(map2).toBeInstanceOf(MapThing) - expect(map2).toBeInstanceOf(Map) + assertTrue(map2 instanceof MapThing) + assertTrue(map2 instanceof Map) })) it.effect("scoped", () => @@ -181,12 +182,18 @@ describe("Effect.Service", () => { }) {} const withUse = yield* Service.foo().pipe(Effect.flip, Effect.provide(Service.Default)) - expect(withUse).toEqual(new Cause.UnknownException(new Error("foo"))) + deepStrictEqual( + withUse, + new Cause.UnknownException(new Error("foo"), "An unknown error occurred in Effect.andThen") + ) const accessor = yield* Service.foo().pipe(Effect.flip, Effect.provide(Service.Default)) - expect(accessor).toEqual(new Cause.UnknownException(new Error("foo"))) + deepStrictEqual( + accessor, + new Cause.UnknownException(new Error("foo"), "An unknown error occurred in Effect.andThen") + ) const accessorSuccess = yield* Service.bar().pipe(Effect.provide(Service.Default)) - expect(accessorSuccess).toEqual("bar") + strictEqual(accessorSuccess, "bar") })) }) diff --git a/packages/effect/test/Effect/stack-safety.test.ts b/packages/effect/test/Effect/stack-safety.test.ts index 169f76d6996..c0579d4dd06 100644 --- a/packages/effect/test/Effect/stack-safety.test.ts +++ b/packages/effect/test/Effect/stack-safety.test.ts @@ -1,8 +1,9 @@ import * as Effect from "effect/Effect" import { constVoid, identity, pipe } from "effect/Function" import * as Ref from "effect/Ref" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" const deepMapEffect = (n: number): Effect.Effect => { const loop = (n: number, acc: Effect.Effect): Effect.Effect => { @@ -18,7 +19,7 @@ describe("Effect", () => { it.effect("deep map of sync effect", () => Effect.gen(function*($) { const result = yield* $(deepMapEffect(10000)) - assert.strictEqual(result, 10000) + strictEqual(result, 10000) })) it.effect("deep attempt", () => Effect.gen(function*($) { @@ -27,7 +28,7 @@ describe("Effect", () => { (acc, _) => pipe(Effect.orDie(acc), Effect.either, Effect.asVoid), Effect.orDie(Effect.try(constVoid)) )) - assert.isUndefined(result) + strictEqual(result, undefined) })) it.effect("deep flatMap", () => Effect.gen(function*($) { @@ -45,7 +46,7 @@ describe("Effect", () => { const expected = BigInt( "113796925398360272257523782552224175572745930353730513145086634176691092536145985470146129334641866902783673042322088625863396052888690096969577173696370562180400527049497109023054114771394568040040412172632376" ) - assert.deepEqual(result, expected) + deepStrictEqual(result, expected) })) it.effect("deep absolve/attempt is identity", () => Effect.gen(function*($) { @@ -53,7 +54,7 @@ describe("Effect", () => { const result = yield* $( array.reduce((acc, _) => Effect.flatMap(Effect.either(acc), identity), Effect.succeed(42)) ) - assert.strictEqual(result, 42) + strictEqual(result, 42) })) it.effect("deep async absolve/attempt is identity", () => Effect.gen(function*($) { @@ -64,7 +65,7 @@ describe("Effect", () => { cb(Effect.succeed(42)) }) )) - assert.strictEqual(result, 42) + strictEqual(result, 42) })) it.effect("deep effects", () => Effect.gen(function*($) { @@ -83,6 +84,6 @@ describe("Effect", () => { const left = pipe(Ref.make(0), Effect.flatMap((ref) => incLeft(100, ref)), Effect.map((n) => n === 0)) const right = pipe(Ref.make(0), Effect.flatMap((ref) => incRight(1000, ref)), Effect.map((n) => n === 1000)) const result = yield* $(left, Effect.zipWith(right, (a, b) => a && b)) - assert.isTrue(result) + assertTrue(result) })) }) diff --git a/packages/effect/test/Effect/structural.test.ts b/packages/effect/test/Effect/structural.test.ts index 82c803ec2d5..c1593c2cd1d 100644 --- a/packages/effect/test/Effect/structural.test.ts +++ b/packages/effect/test/Effect/structural.test.ts @@ -1,37 +1,38 @@ import * as Effect from "effect/Effect" import * as Either from "effect/Either" import * as Option from "effect/Option" +import { assertLeft, assertNone, assertRight, assertSome, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import { assertType, satisfies } from "effect/test/utils/types" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { describe("all", () => { it.effect("should work with one array argument", () => Effect.gen(function*($) { const res = yield* $(Effect.all([Effect.succeed(0), Effect.succeed(1)])) - assert.deepEqual(res, [0, 1]) + deepStrictEqual(res, [0, 1]) satisfies(assertType<[number, number]>()(res)) })) it.effect("should work with one empty array argument", () => Effect.gen(function*($) { const x = yield* $(Effect.all([])) - assert.deepEqual(x, []) + deepStrictEqual(x, []) satisfies(assertType<[]>()(x)) })) it.effect("should work with an array argument", () => Effect.gen(function*($) { const y = Effect.all([0, 1, 2].map((n) => Effect.succeed(n + 1))) const x = yield* $(y) - assert.deepEqual(x, [1, 2, 3]) + deepStrictEqual(x, [1, 2, 3]) satisfies(assertType>()(x)) })) it.effect("should work with one record argument", () => Effect.gen(function*($) { const result = yield* $(Effect.all({ a: Effect.succeed(0), b: Effect.succeed(1) })) const { a, b } = result - assert.deepEqual(a, 0) - assert.deepEqual(b, 1) + deepStrictEqual(a, 0) + deepStrictEqual(b, 1) satisfies( assertType<{ readonly a: number @@ -42,13 +43,13 @@ describe("Effect", () => { it.effect("should work with one iterable argument", () => Effect.gen(function*($) { const result = yield* $(Effect.all(new Set([Effect.succeed(0), Effect.succeed(1)]))) - assert.deepEqual(result, [0, 1]) + deepStrictEqual(result, [0, 1]) satisfies(assertType>()(result)) })) it.effect("should work with one empty record", () => Effect.gen(function*($) { const x = yield* $(Effect.all({})) - assert.deepEqual(x, {}) + deepStrictEqual(x, {}) satisfies(assertType<{}>()(x)) })) }) @@ -58,7 +59,7 @@ describe("Effect", () => { const res = yield* $(Effect.all([Effect.succeed(0), Effect.succeed(1)], { concurrency: "unbounded" })) - assert.deepEqual(res, [0, 1]) + deepStrictEqual(res, [0, 1]) satisfies(assertType<[number, number]>()(res)) })) it.effect("should work with one empty array argument", () => @@ -66,7 +67,7 @@ describe("Effect", () => { const x = yield* $(Effect.all([], { concurrency: "unbounded" })) - assert.deepEqual(x, []) + deepStrictEqual(x, []) satisfies(assertType<[]>()(x)) })) it.effect("should work with one record argument", () => @@ -75,8 +76,8 @@ describe("Effect", () => { concurrency: "unbounded" })) const { a, b } = result - assert.deepEqual(a, 0) - assert.deepEqual(b, 1) + deepStrictEqual(a, 0) + deepStrictEqual(b, 1) satisfies( assertType<{ a: number @@ -87,7 +88,7 @@ describe("Effect", () => { it.effect("should work with one empty record", () => Effect.gen(function*($) { const x = yield* $(Effect.all({}, { concurrency: "unbounded" })) - assert.deepEqual(x, {}) + deepStrictEqual(x, {}) satisfies(assertType<{}>()(x)) })) }) @@ -95,21 +96,21 @@ describe("Effect", () => { it.effect("should work with one array argument", () => Effect.gen(function*($) { const res = yield* $(Effect.all([Effect.succeed(0), Effect.succeed(1)], { mode: "validate" })) - assert.deepEqual(res, [0, 1]) + deepStrictEqual(res, [0, 1]) satisfies(assertType<[number, number]>()(res)) })) it.effect("failure should work with one array argument", () => Effect.gen(function*($) { const res = yield* $(Effect.flip(Effect.all([Effect.fail(0), Effect.succeed(1)], { mode: "validate" }))) - assert.deepEqual(res, [Option.some(0), Option.none()]) + deepStrictEqual(res, [Option.some(0), Option.none()]) satisfies(assertType<[Option.Option, Option.Option]>()(res)) })) it.effect("should work with one record argument", () => Effect.gen(function*($) { const result = yield* $(Effect.all({ a: Effect.succeed(0), b: Effect.succeed(1) }, { mode: "validate" })) const { a, b } = result - assert.deepEqual(a, 0) - assert.deepEqual(b, 1) + deepStrictEqual(a, 0) + deepStrictEqual(b, 1) satisfies( assertType<{ readonly a: number @@ -123,8 +124,8 @@ describe("Effect", () => { Effect.flip(Effect.all({ a: Effect.fail(0), b: Effect.succeed(1) }, { mode: "validate" })) ) const { a, b } = result - assert.deepEqual(a, Option.some(0)) - assert.deepEqual(b, Option.none()) + assertSome(a, 0) + assertNone(b) satisfies( assertType<{ readonly a: Option.Option @@ -135,7 +136,7 @@ describe("Effect", () => { it.effect("should work with one iterable argument", () => Effect.gen(function*($) { const result = yield* $(Effect.all(new Set([Effect.succeed(0), Effect.succeed(1)]), { mode: "validate" })) - assert.deepEqual(result, [0, 1]) + deepStrictEqual(result, [0, 1]) satisfies(assertType>()(result)) })) }) @@ -143,21 +144,21 @@ describe("Effect", () => { it.effect("should work with one array argument", () => Effect.gen(function*($) { const res = yield* $(Effect.all([Effect.succeed(0), Effect.succeed(1)], { mode: "either" })) - assert.deepEqual(res, [Either.right(0), Either.right(1)]) + deepStrictEqual(res, [Either.right(0), Either.right(1)]) satisfies(assertType<[Either.Either, Either.Either]>()(res)) })) it.effect("failure should work with one array argument", () => Effect.gen(function*($) { const res = yield* $(Effect.all([Effect.fail(0), Effect.succeed(1)], { mode: "either" })) - assert.deepEqual(res, [Either.left(0), Either.right(1)]) + deepStrictEqual(res, [Either.left(0), Either.right(1)]) satisfies(assertType<[Either.Either, Either.Either]>()(res)) })) it.effect("should work with one record argument", () => Effect.gen(function*($) { const result = yield* $(Effect.all({ a: Effect.succeed(0), b: Effect.succeed(1) }, { mode: "either" })) const { a, b } = result - assert.deepEqual(a, Either.right(0)) - assert.deepEqual(b, Either.right(1)) + assertRight(a, 0) + assertRight(b, 1) satisfies( assertType<{ readonly a: Either.Either @@ -171,8 +172,8 @@ describe("Effect", () => { Effect.all({ a: Effect.fail(0), b: Effect.succeed(1) }, { mode: "either" }) ) const { a, b } = result - assert.deepEqual(a, Either.left(0)) - assert.deepEqual(b, Either.right(1)) + assertLeft(a, 0) + assertRight(b, 1) satisfies( assertType<{ readonly a: Either.Either @@ -183,7 +184,7 @@ describe("Effect", () => { it.effect("should work with one iterable argument", () => Effect.gen(function*($) { const result = yield* $(Effect.all(new Set([Effect.succeed(0), Effect.succeed(1)]), { mode: "either" })) - assert.deepEqual(result, [Either.right(0), Either.right(1)]) + deepStrictEqual(result, [Either.right(0), Either.right(1)]) satisfies(assertType>>()(result)) })) }) @@ -194,7 +195,7 @@ describe("Effect", () => { [Effect.succeed(0), Effect.succeed(1)] as const, Effect.allWith() ) - assert.deepEqual(res, [0, 1]) + deepStrictEqual(res, [0, 1]) satisfies(assertType<[number, number]>()(res)) })) }) diff --git a/packages/effect/test/Effect/sync.test.ts b/packages/effect/test/Effect/sync.test.ts index ec47cc75673..be193c12cb1 100644 --- a/packages/effect/test/Effect/sync.test.ts +++ b/packages/effect/test/Effect/sync.test.ts @@ -1,10 +1,10 @@ import * as Cause from "effect/Cause" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import * as Exit from "effect/Exit" import { pipe } from "effect/Function" +import { assertLeft, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" const sum = (n: number): number => { if (n < 0) { @@ -33,7 +33,7 @@ describe("Effect", () => { return pipe(Effect.sync(() => n), Effect.flatMap((b) => pipe(sumEffect(n - 1), Effect.map((a) => a + b)))) } const result = yield* $(sumEffect(1000)) - assert.strictEqual(result, sum(1000)) + strictEqual(result, sum(1000)) })) it.it("sync - must be lazy", async () => { let program @@ -46,7 +46,7 @@ describe("Effect", () => { program = Effect.succeed(false) } const result = await Effect.runPromise(program) - assert.isTrue(result) + assertTrue(result) }) it.it("suspend - must be lazy", async () => { let program @@ -59,7 +59,7 @@ describe("Effect", () => { program = Effect.succeed(false) } const result = await Effect.runPromise(program) - assert.isTrue(result) + assertTrue(result) }) it.effect("suspend - must catch throwable", () => Effect.gen(function*($) { @@ -70,12 +70,12 @@ describe("Effect", () => { }), Effect.exit ) - assert.deepStrictEqual(result, Exit.die(error)) + deepStrictEqual(result, Exit.die(error)) })) it.effect("suspendSucceed - must be evaluatable", () => Effect.gen(function*($) { const result = yield* $(Effect.suspend(() => Effect.succeed(42))) - assert.strictEqual(result, 42) + strictEqual(result, 42) })) it.effect("suspendSucceed - must not catch throwable", () => Effect.gen(function*($) { @@ -87,6 +87,6 @@ describe("Effect", () => { Effect.sandbox, Effect.either ) - assert.deepStrictEqual(result, Either.left(Cause.die(error))) + assertLeft(result, Cause.die(error)) })) }) diff --git a/packages/effect/test/Effect/tapping.test.ts b/packages/effect/test/Effect/tapping.test.ts index ce3e1f27794..06a39df9616 100644 --- a/packages/effect/test/Effect/tapping.test.ts +++ b/packages/effect/test/Effect/tapping.test.ts @@ -1,6 +1,7 @@ import * as Effect from "effect/Effect" import { pipe } from "effect/Function" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" class TestError1 { readonly _tag = "TestError1" @@ -24,6 +25,6 @@ describe("Effect", () => { Effect.runPromise ) - expect(val).toBe(1) + strictEqual(val, 1) }) }) diff --git a/packages/effect/test/Effect/timeout.test.ts b/packages/effect/test/Effect/timeout.test.ts index 810f1531699..7ca71a76161 100644 --- a/packages/effect/test/Effect/timeout.test.ts +++ b/packages/effect/test/Effect/timeout.test.ts @@ -4,10 +4,10 @@ import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" import * as Fiber from "effect/Fiber" import { constFalse, pipe } from "effect/Function" -import * as Option from "effect/Option" +import { assertNone, assertTrue, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("timeout produces a useful error message", () => @@ -20,9 +20,10 @@ describe("Effect", () => { ) yield* TestClock.adjust(Duration.millis(2000)) const result = yield* Fiber.join(fiber) - assert.include( - result.toString(), - "TimeoutException: Operation timed out before the specified duration of '1s 500ms' elapsed" + assertTrue( + result.toString().includes( + "TimeoutException: Operation timed out before the specified duration of '1s 500ms' elapsed" + ) ) })) it.live("timeout a long computation", () => @@ -38,7 +39,7 @@ describe("Effect", () => { Effect.exit ) ) - assert.deepStrictEqual(result, Exit.fail(false)) + deepStrictEqual(result, Exit.fail(false)) })) it.live("timeout a long computation with a cause", () => Effect.gen(function*($) { @@ -55,24 +56,24 @@ describe("Effect", () => { Effect.flip ) ) - assert.deepStrictEqual(result, cause) + deepStrictEqual(result, cause) })) it.live("timeout repetition of uninterruptible effect", () => Effect.gen(function*($) { const result = yield* $( pipe(Effect.void, Effect.uninterruptible, Effect.forever, Effect.timeout(Duration.millis(10)), Effect.option) ) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("timeout in uninterruptible region", () => Effect.gen(function*($) { const result = yield* $(Effect.void, Effect.timeout(Duration.seconds(20)), Effect.uninterruptible) - assert.deepStrictEqual(result, void 0) + deepStrictEqual(result, void 0) })) it.effect("timeout - disconnect - returns with the produced value if the effect completes before the timeout elapses", () => Effect.gen(function*($) { const result = yield* $(Effect.void, Effect.disconnect, Effect.timeout(Duration.millis(100))) - assert.deepStrictEqual(result, void 0) + deepStrictEqual(result, void 0) })) it.effect("timeout - disconnect - returns `NoSuchElementException` otherwise", () => Effect.gen(function*($) { @@ -88,6 +89,6 @@ describe("Effect", () => { ) yield* $(TestClock.adjust(Duration.millis(100))) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) }) diff --git a/packages/effect/test/Effect/traversing.test.ts b/packages/effect/test/Effect/traversing.test.ts index 0515385af96..b062793881f 100644 --- a/packages/effect/test/Effect/traversing.test.ts +++ b/packages/effect/test/Effect/traversing.test.ts @@ -3,13 +3,13 @@ import * as Cause from "effect/Cause" import * as Chunk from "effect/Chunk" import * as Deferred from "effect/Deferred" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import * as Exit from "effect/Exit" import * as Fiber from "effect/Fiber" import { constVoid, identity, pipe } from "effect/Function" import * as Ref from "effect/Ref" +import { assertFalse, assertLeft, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("dropWhile - happy path", () => @@ -20,7 +20,7 @@ describe("Effect", () => { Effect.dropWhile((n) => Effect.succeed(n % 2 === 1)) ) ) - assert.deepStrictEqual(result, [2, 3, 4, 5]) + deepStrictEqual(result, [2, 3, 4, 5]) })) it.effect("dropWhile - error", () => Effect.gen(function*() { @@ -29,7 +29,7 @@ describe("Effect", () => { Effect.dropWhile(() => Effect.fail("Ouch")), Effect.either ) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) it.effect("exists - determines whether any element satisfies the effectual predicate", () => Effect.gen(function*($) { @@ -41,16 +41,16 @@ describe("Effect", () => { concurrency: "unbounded" }) ) - assert.isTrue(result1) - assert.isFalse(result2) + assertTrue(result1) + assertFalse(result2) })) it.effect("forAll - determines whether all elements satisfy the effectual predicate", () => Effect.gen(function*($) { const array = [1, 2, 3, 4, 5, 6] const result1 = yield* $(array, Effect.every((n) => Effect.succeed(n > 3))) const result2 = yield* $(array, Effect.every((n) => Effect.succeed(n > 0))) - assert.isFalse(result1) - assert.isTrue(result2) + assertFalse(result1) + assertTrue(result2) })) it.effect("iterate - iterates with the specified effectual function", () => Effect.gen(function*($) { @@ -58,7 +58,7 @@ describe("Effect", () => { while: (n) => n > 0, body: (n) => Effect.succeed(n - 1) })) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("loop - loops with the specified effectual function", () => Effect.gen(function*($) { @@ -71,7 +71,7 @@ describe("Effect", () => { }) ) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(result, [0, 1, 2, 3, 4]) + deepStrictEqual(result, [0, 1, 2, 3, 4]) })) it.effect("loop/discard - loops with the specified effectual function", () => Effect.gen(function*($) { @@ -83,27 +83,27 @@ describe("Effect", () => { discard: true })) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(result, [0, 1, 2, 3, 4]) + deepStrictEqual(result, [0, 1, 2, 3, 4]) })) it.effect("replicate - zero", () => Effect.gen(function*($) { const result = yield* $(Effect.all(pipe(Effect.succeed(12), Effect.replicate(0)))) - assert.strictEqual(result.length, 0) + strictEqual(result.length, 0) })) it.effect("replicate - negative", () => Effect.gen(function*($) { const result = yield* $(Effect.all(pipe(Effect.succeed(12), Effect.replicate(-2)))) - assert.strictEqual(result.length, 0) + strictEqual(result.length, 0) })) it.effect("replicate - positive", () => Effect.gen(function*($) { const result = yield* $(Effect.all(pipe(Effect.succeed(12), Effect.replicate(2)))) - assert.deepStrictEqual(result, [12, 12]) + deepStrictEqual(result, [12, 12]) })) it.effect(" - returns the list of results", () => Effect.gen(function*($) { const result = yield* $([1, 2, 3, 4, 5, 6], Effect.forEach((n) => Effect.succeed(n + 1))) - assert.deepStrictEqual(result, [2, 3, 4, 5, 6, 7]) + deepStrictEqual(result, [2, 3, 4, 5, 6, 7]) })) it.effect("forEach - both evaluates effects and returns results in the same order", () => Effect.gen(function*($) { @@ -118,8 +118,8 @@ describe("Effect", () => { ) ) const effects = yield* $(Ref.get(ref), Effect.map(Chunk.reverse)) - assert.deepStrictEqual(Chunk.toReadonlyArray(effects), ["1", "2", "3"]) - assert.deepStrictEqual(result, [1, 2, 3]) + deepStrictEqual(Chunk.toReadonlyArray(effects), ["1", "2", "3"]) + deepStrictEqual(result, [1, 2, 3]) })) it.effect("forEach - fails if one of the effects fails", () => Effect.gen(function*($) { @@ -137,14 +137,14 @@ describe("Effect", () => { Effect.exit ) - assert.deepStrictEqual(result, Exit.die(new Cause.IllegalArgumentException())) + deepStrictEqual(result, Exit.die(new Cause.IllegalArgumentException())) })) it.effect("forEach/discard - runs effects in order", () => Effect.gen(function*($) { const ref = yield* $(Ref.make(Array.empty())) yield* $([1, 2, 3, 4, 5], Effect.forEach((n) => Ref.update(ref, Array.append(n)), { discard: true })) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(result, [1, 2, 3, 4, 5]) + deepStrictEqual(result, [1, 2, 3, 4, 5]) })) it.effect("forEach/discard - can be run twice", () => Effect.gen(function*($) { @@ -153,23 +153,23 @@ describe("Effect", () => { yield* $(effect) yield* $(effect) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 30) + strictEqual(result, 30) })) it.effect("forEach/concurrency - runs single task", () => Effect.gen(function*($) { const result = yield* $([2], Effect.forEach((n) => Effect.succeed(n * 2), { concurrency: "unbounded" })) - assert.deepStrictEqual(result, [4]) + deepStrictEqual(result, [4]) })) it.effect("forEach/concurrency - runs two tasks", () => Effect.gen(function*($) { const result = yield* $([2, 3], Effect.forEach((n) => Effect.succeed(n * 2), { concurrency: "unbounded" })) - assert.deepStrictEqual(result, [4, 6]) + deepStrictEqual(result, [4, 6]) })) it.effect("forEach/concurrency - runs many tasks", () => Effect.gen(function*($) { const array = Array.makeBy(100, (i) => i + 1) const result = yield* $(array, Effect.forEach((n) => Effect.succeed(n * 2), { concurrency: "unbounded" })) - assert.deepStrictEqual(result, array.map((n) => n * 2)) + deepStrictEqual(result, array.map((n) => n * 2)) })) it.effect("forEach/concurrency - runs a task that fails", () => Effect.gen(function*($) { @@ -178,7 +178,7 @@ describe("Effect", () => { Effect.forEach((n) => n === 5 ? Effect.fail("boom") : Effect.succeed(n * 2), { concurrency: "unbounded" }), Effect.flip ) - assert.strictEqual(result, "boom") + strictEqual(result, "boom") })) it.effect("forEach/concurrency - runs two failed tasks", () => Effect.gen(function*($) { @@ -192,7 +192,7 @@ describe("Effect", () => { : Effect.succeed(n * 2), { concurrency: "unbounded" }), Effect.flip ) - assert.isTrue(result === "boom1" || result === "boom2") + assertTrue(result === "boom1" || result === "boom2") })) it.effect("forEach/concurrency - runs a task that dies", () => Effect.gen(function*($) { @@ -203,7 +203,7 @@ describe("Effect", () => { }), Effect.exit ) - assert.isTrue(Exit.isFailure(result) && Cause.isDie(result.effect_instruction_i0)) + assertTrue(Exit.isFailure(result) && Cause.isDie(result.effect_instruction_i0)) })) it.effect("forEach/concurrency - runs a task that is interrupted", () => Effect.gen(function*($) { @@ -212,7 +212,7 @@ describe("Effect", () => { Effect.forEach((n) => n === 5 ? Effect.interrupt : Effect.succeed(n * 2), { concurrency: "unbounded" }), Effect.exit ) - assert.isTrue(Exit.isInterrupted(result)) + assertTrue(Exit.isInterrupted(result)) })) it.effect("forEach/concurrency - runs a task that throws an unsuspended exception", () => Effect.gen(function*($) { @@ -224,7 +224,7 @@ describe("Effect", () => { }), { concurrency: "unbounded" }), Effect.exit ) - assert.deepStrictEqual(result, Exit.die(new Error("1"))) + deepStrictEqual(result, Exit.die(new Error("1"))) })) it.effect("forEach/concurrency - returns results in the same order", () => Effect.gen(function*($) { @@ -232,7 +232,7 @@ describe("Effect", () => { ["1", "2", "3"], Effect.forEach((s) => Effect.sync(() => Number.parseInt(s)), { concurrency: "unbounded" }) ) - assert.deepStrictEqual(result, [1, 2, 3]) + deepStrictEqual(result, [1, 2, 3]) })) it.effect("forEach/concurrency - runs effects in parallel", () => Effect.gen(function*($) { @@ -245,7 +245,7 @@ describe("Effect", () => { ) ) const result = yield* $(Deferred.await(deferred)) - assert.isUndefined(result) + strictEqual(result, undefined) })) it.effect("forEach/concurrency - propagates error", () => Effect.gen(function*($) { @@ -254,7 +254,7 @@ describe("Effect", () => { Effect.forEach((n) => n % 2 !== 0 ? Effect.succeed(n) : Effect.fail("not odd"), { concurrency: "unbounded" }), Effect.flip ) - assert.strictEqual(result, "not odd") + strictEqual(result, "not odd") })) it.effect("forEach/concurrency - interrupts effects on first failure", () => Effect.gen(function*($) { @@ -268,8 +268,8 @@ describe("Effect", () => { ] const error = yield* $(actions, Effect.forEach(identity, { concurrency: "unbounded" }), Effect.flip) const value = yield* $(Ref.get(ref)) - assert.strictEqual(error, "C") - assert.isFalse(value) + strictEqual(error, "C") + assertFalse(value) })) it.effect("forEach/concurrency - does not kill fiber when forked on the parent scope", () => Effect.gen(function*($) { @@ -280,7 +280,7 @@ describe("Effect", () => { ) yield* $(fibers, Effect.forEach(Fiber.await)) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 100) + strictEqual(result, 100) })) it.effect("forEach/concurrency - parallelism - returns the results in the appropriate order", () => Effect.gen(function*($) { @@ -290,7 +290,7 @@ describe("Effect", () => { Effect.forEach((n) => Effect.succeed(n.toString()), { concurrency: 2 }) ) ) - assert.deepStrictEqual(result, ["1", "2", "3"]) + deepStrictEqual(result, ["1", "2", "3"]) })) it.effect("forEach/concurrency - parallelism - works on large lists", () => Effect.gen(function*($) { @@ -302,7 +302,7 @@ describe("Effect", () => { Effect.forEach((n) => Effect.succeed(n), { concurrency: parallelism }) ) ) - assert.deepStrictEqual(result, array) + deepStrictEqual(result, array) })) it.effect("forEach/concurrency - parallelism - runs effects in parallel", () => Effect.gen(function*($) { @@ -315,7 +315,7 @@ describe("Effect", () => { ) ) const result = yield* $(Deferred.await(deferred)) - assert.isUndefined(result) + strictEqual(result, undefined) })) it.effect("forEach/concurrency - parallelism - propagates error", () => Effect.gen(function*($) { @@ -324,7 +324,7 @@ describe("Effect", () => { Effect.forEach((n) => n % 2 !== 0 ? Effect.succeed(n) : Effect.fail("not odd"), { concurrency: 4 }), Effect.either ) - assert.deepStrictEqual(result, Either.left("not odd")) + assertLeft(result, "not odd") })) it.effect("forEach/concurrency - parallelism - interrupts effects on first failure", () => Effect.gen(function*($) { @@ -338,7 +338,7 @@ describe("Effect", () => { Effect.forEach(identity, { concurrency: 4 }), Effect.either ) - assert.deepStrictEqual(result, Either.left("C")) + assertLeft(result, "C") })) it.effect("forEach/concurrency+discard - accumulates errors", () => Effect.gen(function*($) { @@ -372,7 +372,7 @@ describe("Effect", () => { onSuccess: () => Chunk.empty() }) ) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [1, 2, 3]) + deepStrictEqual(Chunk.toReadonlyArray(result), [1, 2, 3]) })) it.effect("forEach/concurrency+discard - runs all effects", () => Effect.gen(function*($) { @@ -385,7 +385,7 @@ describe("Effect", () => { }) ) const result = yield* $(Ref.get(ref), Effect.map(Chunk.reverse)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [1, 2, 3, 4, 5]) + deepStrictEqual(Chunk.toReadonlyArray(result), [1, 2, 3, 4, 5]) })) it.effect("forEach/concurrency+discard - completes on empty input", () => Effect.gen(function*($) { @@ -396,7 +396,7 @@ describe("Effect", () => { discard: true }) ) - assert.isUndefined(result) + strictEqual(result, undefined) })) it.effect("forEach/concurrency+discard - parallelism - runs all effects", () => Effect.gen(function*($) { @@ -409,14 +409,14 @@ describe("Effect", () => { }) ) const result = yield* $(Ref.get(ref), Effect.map(Chunk.reverse)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [1, 2, 3, 4, 5]) + deepStrictEqual(Chunk.toReadonlyArray(result), [1, 2, 3, 4, 5]) })) it.effect("merge - on flipped result", () => Effect.gen(function*($) { const effect: Effect.Effect = Effect.succeed(1) const a = yield* $(Effect.merge(effect)) const b = yield* $(Effect.merge(Effect.flip(effect))) - assert.strictEqual(a, b) + strictEqual(a, b) })) it.effect("mergeAll - return zero element on empty input", () => Effect.gen(function*($) { @@ -425,28 +425,28 @@ describe("Effect", () => { const result = yield* $( pipe([] as ReadonlyArray>, Effect.mergeAll(zeroElement, () => nonZero)) ) - assert.strictEqual(result, zeroElement) + strictEqual(result, zeroElement) })) it.effect("mergeAll - merge list using function", () => Effect.gen(function*($) { const result = yield* $([3, 5, 7].map(Effect.succeed), Effect.mergeAll(1, (b, a) => b + a)) - assert.strictEqual(result, 1 + 3 + 5 + 7) + strictEqual(result, 1 + 3 + 5 + 7) })) it.effect("mergeAll - should work when Z is an interable", () => Effect.gen(function*($) { const result = yield* $([3, 5, 7].map(Effect.succeed), Effect.mergeAll([] as Array, (b, a) => [...b, a])) - assert.deepStrictEqual(result, [3, 5, 7]) + deepStrictEqual(result, [3, 5, 7]) })) it.effect("mergeAll - should work when Z is a function", () => Effect.gen(function*($) { const result = yield* $([3, 5, 7].map(Effect.succeed), Effect.mergeAll(() => 1, (_b, a) => () => a)) - assert.deepStrictEqual(result(), 7) + deepStrictEqual(result(), 7) })) it.effect("mergeAll - return error if it exists in list", () => Effect.gen(function*($) { const effects: ReadonlyArray> = [Effect.void, Effect.fail(1)] const result = yield* $(effects, Effect.mergeAll(void 0 as void, constVoid), Effect.exit) - assert.deepStrictEqual(result, Exit.fail(1)) + deepStrictEqual(result, Exit.fail(1)) })) it.effect("mergeAll/concurrency - return zero element on empty input", () => Effect.gen(function*($) { @@ -460,7 +460,7 @@ describe("Effect", () => { }) ) ) - assert.strictEqual(result, zeroElement) + strictEqual(result, zeroElement) })) it.effect("mergeAll/concurrency - merge list using function", () => Effect.gen(function*($) { @@ -470,7 +470,7 @@ describe("Effect", () => { concurrency: "unbounded" }) ) - assert.strictEqual(result, 1 + 3 + 5 + 7) + strictEqual(result, 1 + 3 + 5 + 7) })) it.effect("mergeAll/concurrency - return error if it exists in list", () => Effect.gen(function*($) { @@ -482,21 +482,21 @@ describe("Effect", () => { }), Effect.exit ) - assert.deepStrictEqual(result, Exit.failCause(Cause.fail(1))) + deepStrictEqual(result, Exit.failCause(Cause.fail(1))) })) it.effect("partition - collects only successes", () => Effect.gen(function*($) { const array = Array.makeBy(10, (i) => i) const [left, right] = yield* $(array, Effect.partition(Effect.succeed)) - assert.deepStrictEqual(left, []) - assert.deepStrictEqual(right, array) + deepStrictEqual(left, []) + deepStrictEqual(right, array) })) it.effect("partition - collects only failures", () => Effect.gen(function*($) { const array = Array.makeBy(10, () => 0) const [left, right] = yield* $(array, Effect.partition(Effect.fail)) - assert.deepStrictEqual(left, array) - assert.deepStrictEqual(right, []) + deepStrictEqual(left, array) + deepStrictEqual(right, []) })) it.effect("partition - collects failures and successes", () => Effect.gen(function*($) { @@ -504,8 +504,8 @@ describe("Effect", () => { const [left, right] = yield* $( pipe(array, Effect.partition((n) => n % 2 === 0 ? Effect.fail(n) : Effect.succeed(n))) ) - assert.deepStrictEqual(left, [0, 2, 4, 6, 8]) - assert.deepStrictEqual(right, [1, 3, 5, 7, 9]) + deepStrictEqual(left, [0, 2, 4, 6, 8]) + deepStrictEqual(right, [1, 3, 5, 7, 9]) })) it.effect("partition - evaluates effects in correct order", () => Effect.gen(function*($) { @@ -513,7 +513,7 @@ describe("Effect", () => { const ref = yield* $(Ref.make(Chunk.empty())) yield* $(array, Effect.partition((n) => Ref.update(ref, Chunk.prepend(n)))) const result = yield* $(Ref.get(ref), Effect.map(Chunk.reverse)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [2, 4, 6, 3, 5, 6]) + deepStrictEqual(Chunk.toReadonlyArray(result), [2, 4, 6, 3, 5, 6]) })) it.effect("partition/concurrency - collects successes", () => Effect.gen(function*($) { @@ -524,8 +524,8 @@ describe("Effect", () => { concurrency: "unbounded" }) ) - assert.deepStrictEqual(left, []) - assert.deepStrictEqual(right, array) + deepStrictEqual(left, []) + deepStrictEqual(right, array) })) it.effect("partition/concurrency - collects failures", () => Effect.gen(function*($) { @@ -536,8 +536,8 @@ describe("Effect", () => { concurrency: "unbounded" }) ) - assert.deepStrictEqual(left, array) - assert.deepStrictEqual(right, []) + deepStrictEqual(left, array) + deepStrictEqual(right, []) })) it.effect("partition/concurrency - collects failures and successes", () => Effect.gen(function*($) { @@ -550,8 +550,8 @@ describe("Effect", () => { }) ) ) - assert.deepStrictEqual(left, [0, 2, 4, 6, 8]) - assert.deepStrictEqual(right, [1, 3, 5, 7, 9]) + deepStrictEqual(left, [0, 2, 4, 6, 8]) + deepStrictEqual(right, [1, 3, 5, 7, 9]) })) it.effect("partition/concurrency - parallelism - collects successes", () => Effect.gen(function*($) { @@ -562,8 +562,8 @@ describe("Effect", () => { concurrency: 3 }) ) - assert.deepStrictEqual(left, []) - assert.deepStrictEqual(right, array) + deepStrictEqual(left, []) + deepStrictEqual(right, array) })) it.effect("partition/concurrency - parallelism - collects failures", () => Effect.gen(function*($) { @@ -572,8 +572,8 @@ describe("Effect", () => { array, Effect.partition(Effect.fail, { concurrency: 3 }) ) - assert.deepStrictEqual(left, array) - assert.deepStrictEqual(right, []) + deepStrictEqual(left, array) + deepStrictEqual(right, []) })) it.effect("partition/concurrency - parallelism - collects failures and successes", () => Effect.gen(function*($) { @@ -584,35 +584,35 @@ describe("Effect", () => { concurrency: 3 }) ) - assert.deepStrictEqual(left, [0, 2, 4, 6, 8]) - assert.deepStrictEqual(right, [1, 3, 5, 7, 9]) + deepStrictEqual(left, [0, 2, 4, 6, 8]) + deepStrictEqual(right, [1, 3, 5, 7, 9]) })) it.effect("reduce - with a successful step function sums the list properly", () => Effect.gen(function*($) { const result = yield* $([1, 2, 3, 4, 5], Effect.reduce(0, (acc, curr) => Effect.succeed(acc + curr))) - assert.strictEqual(result, 15) + strictEqual(result, 15) })) it.effect("reduce - with a failing step function returns a failed IO", () => Effect.gen(function*($) { const result = yield* $([1, 2, 3, 4, 5], Effect.reduce(0, () => Effect.fail("fail")), Effect.exit) - assert.deepStrictEqual(result, Exit.fail("fail")) + deepStrictEqual(result, Exit.fail("fail")) })) it.effect("reduce - run sequentially from left to right", () => Effect.gen(function*($) { const result = yield* $( pipe([1, 2, 3, 4, 5], Effect.reduce([] as ReadonlyArray, (acc, curr) => Effect.succeed([...acc, curr]))) ) - assert.deepStrictEqual(result, [1, 2, 3, 4, 5]) + deepStrictEqual(result, [1, 2, 3, 4, 5]) })) it.effect("reduceRight - with a successful step function sums the list properly", () => Effect.gen(function*($) { const result = yield* $([1, 2, 3, 4, 5], Effect.reduceRight(0, (acc, curr) => Effect.succeed(acc + curr))) - assert.strictEqual(result, 15) + strictEqual(result, 15) })) it.effect("reduceRight - with a failing step function returns a failed IO", () => Effect.gen(function*($) { const result = yield* $([1, 2, 3, 4, 5], Effect.reduceRight(0, () => Effect.fail("fail")), Effect.exit) - assert.deepStrictEqual(result, Exit.fail("fail")) + deepStrictEqual(result, Exit.fail("fail")) })) it.effect("reduceRight - run sequentially from right to left", () => Effect.gen(function*($) { @@ -620,7 +620,7 @@ describe("Effect", () => { [1, 2, 3, 4, 5], Effect.reduceRight([] as ReadonlyArray, (curr, acc) => Effect.succeed([curr, ...acc])) ) - assert.deepStrictEqual(result, [1, 2, 3, 4, 5]) + deepStrictEqual(result, [1, 2, 3, 4, 5]) })) it.effect("reduceEffect/concurrency - return zero element on empty input", () => Effect.gen(function*($) { @@ -634,7 +634,7 @@ describe("Effect", () => { }) ) ) - assert.strictEqual(result, zeroElement) + strictEqual(result, zeroElement) })) it.effect("reduceEffect/concurrency - reduce list using function", () => Effect.gen(function*($) { @@ -644,7 +644,7 @@ describe("Effect", () => { concurrency: "unbounded" }) ) - assert.strictEqual(result, 1 + 3 + 5 + 7) + strictEqual(result, 1 + 3 + 5 + 7) })) it.effect("reduceEffect/concurrency - return error if zero is an error", () => Effect.gen(function*($) { @@ -657,7 +657,7 @@ describe("Effect", () => { Effect.exit ) ) - assert.deepStrictEqual(result, Exit.failCause(Cause.fail(1))) + deepStrictEqual(result, Exit.failCause(Cause.fail(1))) })) it.effect("reduceEffect/concurrency - return error if it exists in list", () => Effect.gen(function*($) { @@ -671,7 +671,7 @@ describe("Effect", () => { Effect.exit ) ) - assert.deepStrictEqual(result, Exit.failCause(Cause.fail(1))) + deepStrictEqual(result, Exit.failCause(Cause.fail(1))) })) it.effect("takeUntil - happy path", () => Effect.gen(function*($) { @@ -681,7 +681,7 @@ describe("Effect", () => { (n) => Effect.succeed(n >= 3) ) ) - assert.deepStrictEqual(result, [1, 2, 3]) + deepStrictEqual(result, [1, 2, 3]) })) it.effect("takeUntil - error", () => Effect.gen(function*($) { @@ -692,7 +692,7 @@ describe("Effect", () => { Effect.either ) ) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) it.effect("takeWhile - happy path", () => Effect.gen(function*($) { @@ -702,7 +702,7 @@ describe("Effect", () => { Effect.takeWhile((n) => Effect.succeed(n % 2 === 1)) ) ) - assert.deepStrictEqual(result, [1]) + deepStrictEqual(result, [1]) })) it.effect("takeWhile - error", () => Effect.gen(function*($) { @@ -713,6 +713,6 @@ describe("Effect", () => { Effect.either ) ) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) }) diff --git a/packages/effect/test/Effect/tryPromise.test.ts b/packages/effect/test/Effect/tryPromise.test.ts index ae9ac41de10..7e9f463d802 100644 --- a/packages/effect/test/Effect/tryPromise.test.ts +++ b/packages/effect/test/Effect/tryPromise.test.ts @@ -1,7 +1,6 @@ -import * as Cause from "effect/Cause" -import * as Effect from "effect/Effect" -import * as Either from "effect/Either" -import { describe, expect, it } from "effect/test/utils/extend" +import { Cause, Effect, Option } from "effect" +import { assertLeft, assertSuccess, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "effect/test/utils/extend" describe("Effect", () => { it("tryPromise - success, no catch, no AbortSignal", async () => { @@ -13,7 +12,7 @@ describe("Effect", () => { }) ) const n = await Effect.runPromise(effect) - expect(n).toBe(1) + strictEqual(n, 1) }) it("tryPromise - failure, no catch, no AbortSignal", async () => { @@ -25,7 +24,7 @@ describe("Effect", () => { }) ) const either = await Effect.runPromise(Effect.either(effect)) - expect(either).toStrictEqual(Either.left(new Cause.UnknownException("error"))) + assertLeft(either, new Cause.UnknownException("error", "An unknown error occurred in Effect.tryPromise")) }) it("tryPromise - failure, catch, no AbortSignal", async () => { @@ -39,7 +38,7 @@ describe("Effect", () => { catch: (error) => new Error(String(error)) }) const either = await Effect.runPromise(Effect.either(effect)) - expect(either).toStrictEqual(Either.left(new Error("error"))) + assertLeft(either, new Error("error")) }) it("tryPromise - success, no catch, AbortSignal", async () => { @@ -60,8 +59,8 @@ describe("Effect", () => { Effect.catchTag("TimeoutException", () => Effect.succeedNone) ) const exit = await Effect.runPromiseExit(program) - expect(exit._tag).toBe("Success") - expect(aborted).toBe(true) + assertSuccess(exit, Option.none()) + assertTrue(aborted) }) it("tryPromise - success, catch, AbortSignal", async () => { @@ -85,8 +84,8 @@ describe("Effect", () => { Effect.catchTag("TimeoutException", () => Effect.succeedNone) ) const exit = await Effect.runPromiseExit(program) - expect(exit._tag).toBe("Success") - expect(aborted).toBe(true) + assertSuccess(exit, Option.none()) + assertTrue(aborted) }) it.effect("tryPromise - defects in catch", () => @@ -100,6 +99,6 @@ describe("Effect", () => { Effect.sandbox, Effect.flip ) - expect(cause).toStrictEqual(Cause.die(new Error("error"))) + deepStrictEqual(cause, Cause.die(new Error("error"))) })) }) diff --git a/packages/effect/test/Effect/validation.test.ts b/packages/effect/test/Effect/validation.test.ts index 906f9627596..45c3b307f05 100644 --- a/packages/effect/test/Effect/validation.test.ts +++ b/packages/effect/test/Effect/validation.test.ts @@ -3,8 +3,9 @@ import * as Effect from "effect/Effect" import * as Either from "effect/Either" import { pipe } from "effect/Function" import * as Ref from "effect/Ref" +import { assertLeft, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Effect", () => { it.effect("validate - fails", () => @@ -17,7 +18,7 @@ describe("Effect", () => { Effect.either ) ) - assert.deepStrictEqual(result, Either.left(Cause.fail(2))) + assertLeft(result, Cause.fail(2)) })) it.effect("validate - combines both cause", () => Effect.gen(function*($) { @@ -29,24 +30,24 @@ describe("Effect", () => { Effect.either ) ) - assert.deepStrictEqual(result, Either.left(Cause.sequential(Cause.fail(1), Cause.fail(2)))) + deepStrictEqual(result, Either.left(Cause.sequential(Cause.fail(1), Cause.fail(2)))) })) it.effect("validateWith - succeeds", () => Effect.gen(function*($) { const result = yield* $(Effect.succeed(1), Effect.validateWith(Effect.succeed(2), (a, b) => a + b)) - assert.strictEqual(result, 3) + strictEqual(result, 3) })) it.effect("validateAll - accumulate successes", () => Effect.gen(function*($) { const array = Array.from({ length: 10 }, (_, i) => i) const result = yield* $(array, Effect.validateAll(Effect.succeed)) - assert.deepStrictEqual(Array.from(result), array) + deepStrictEqual(Array.from(result), array) })) it.effect("validateAll - returns all errors if never valid", () => Effect.gen(function*($) { const array = Array.from({ length: 10 }, () => 0) const result = yield* $(array, Effect.validateAll(Effect.fail), Effect.flip) - assert.deepStrictEqual(Array.from(result), array) + deepStrictEqual(Array.from(result), array) })) it.effect("validateAll - accumulate errors and ignore successes", () => Effect.gen(function*($) { @@ -54,19 +55,19 @@ describe("Effect", () => { const result = yield* $( pipe(array, Effect.validateAll((n) => n % 2 === 0 ? Effect.succeed(n) : Effect.fail(n)), Effect.flip) ) - assert.deepStrictEqual(Array.from(result), [1, 3, 5, 7, 9]) + deepStrictEqual(Array.from(result), [1, 3, 5, 7, 9]) })) it.effect("validateAll/discard - returns all errors if never valid", () => Effect.gen(function*($) { const array = Array.from({ length: 10 }, () => 0) const result = yield* $(array, Effect.validateAll(Effect.fail, { discard: true }), Effect.flip) - assert.deepStrictEqual(Array.from(result), array) + deepStrictEqual(Array.from(result), array) })) it.effect("validateAll/concurrency - returns all errors if never valid", () => Effect.gen(function*($) { const array = Array.from({ length: 1000 }, () => 0) const result = yield* $(array, Effect.validateAll(Effect.fail, { concurrency: "unbounded" }), Effect.flip) - assert.deepStrictEqual(Array.from(result), array) + deepStrictEqual(Array.from(result), array) })) it.effect("validateAll/concurrency - accumulate errors and ignore successes", () => Effect.gen(function*($) { @@ -80,13 +81,13 @@ describe("Effect", () => { Effect.flip ) ) - assert.deepStrictEqual(Array.from(result), [1, 3, 5, 7, 9]) + deepStrictEqual(Array.from(result), [1, 3, 5, 7, 9]) })) it.effect("validateAll/concurrency - accumulate successes", () => Effect.gen(function*($) { const array = Array.from({ length: 10 }, (_, i) => i) const result = yield* $(array, Effect.validateAll(Effect.succeed, { concurrency: "unbounded" })) - assert.deepStrictEqual(Array.from(result), array) + deepStrictEqual(Array.from(result), array) })) it.effect("validateAll/concurrency+discard - returns all errors if never valid", () => Effect.gen(function*($) { @@ -99,18 +100,18 @@ describe("Effect", () => { }), Effect.flip ) - assert.deepStrictEqual(Array.from(result), array) + deepStrictEqual(Array.from(result), array) })) it.effect("validateFirst - returns all errors if never valid", () => Effect.gen(function*($) { const array = Array.from({ length: 10 }, () => 0) const result = yield* $(array, Effect.validateFirst(Effect.fail), Effect.flip) - assert.deepStrictEqual(Array.from(result), array) + deepStrictEqual(Array.from(result), array) })) it.effect("validateFirst - returns [] as error if the input is empty", () => Effect.gen(function*($) { const result = yield* $([], Effect.validateFirst(Effect.succeed), Effect.flip) - assert.deepStrictEqual(result, []) + deepStrictEqual(result, []) })) it.effect("validateFirst - runs sequentially and short circuits on first success validation", () => Effect.gen(function*($) { @@ -131,20 +132,20 @@ describe("Effect", () => { ) ) const count = yield* $(Ref.get(counter)) - assert.strictEqual(result, 6) - assert.strictEqual(count, 6) + strictEqual(result, 6) + strictEqual(count, 6) })) it.effect("validateFirst - returns errors in correct order", () => Effect.gen(function*($) { const result = yield* $([2, 4, 6, 3, 5, 6], Effect.validateFirst(Effect.fail), Effect.flip) - assert.deepStrictEqual(Array.from(result), [2, 4, 6, 3, 5, 6]) + deepStrictEqual(Array.from(result), [2, 4, 6, 3, 5, 6]) })) describe("", () => { it.effect("validateFirst/concurrency - returns all errors if never valid", () => Effect.gen(function*($) { const array = Array.from({ length: 1000 }, () => 0) const result = yield* $(array, Effect.validateFirst(Effect.fail, { concurrency: "unbounded" }), Effect.flip) - assert.deepStrictEqual(Array.from(result), array) + deepStrictEqual(Array.from(result), array) })) it.effect("validateFirst/concurrency - returns success if valid", () => Effect.gen(function*($) { @@ -153,7 +154,7 @@ describe("Effect", () => { } const array = Array.from({ length: 10 }, (_, i) => i + 1) const result = yield* $(array, Effect.validateFirst(f, { concurrency: "unbounded" })) - assert.strictEqual(result, 6) + strictEqual(result, 6) })) }) }) diff --git a/packages/effect/test/Either.test.ts b/packages/effect/test/Either.test.ts index dd6784813bb..ce9414265c4 100644 --- a/packages/effect/test/Either.test.ts +++ b/packages/effect/test/Either.test.ts @@ -1,19 +1,16 @@ -import * as Chunk from "effect/Chunk" -import * as Either from "effect/Either" -import { flow, pipe } from "effect/Function" -import * as Num from "effect/Number" -import * as Option from "effect/Option" -import * as Str from "effect/String" -import * as Util from "effect/test/util" -import { describe, expect, it } from "vitest" - -const expectRight = (e: Either.Either, expected: R) => { - Util.deepStrictEqual(e, Either.right(expected)) -} - -const expectLeft = (e: Either.Either, expected: L) => { - Util.deepStrictEqual(e, Either.left(expected)) -} +import { Chunk, Either, flow, Number as Num, Option, pipe, String as Str } from "effect" +import { + assertFalse, + assertLeft, + assertNone, + assertRight, + assertSome, + assertTrue, + deepStrictEqual, + strictEqual, + throws +} from "effect/test/util" +import { describe, it } from "vitest" describe("Either", () => { it("gen", () => { @@ -51,32 +48,36 @@ describe("Either", () => { return x + y }) - expect(a).toEqual(Either.right(3)) - expect(b).toEqual(Either.right(10)) - expect(c).toEqual(Either.right(undefined)) - expect(d).toEqual(Either.right(2)) - expect(e).toEqual(Either.left("err")) - expect(f).toEqual(Either.left("err")) - expect(g).toEqual(Either.right("testContext")) - expect(h).toEqual(Either.right(3)) - }) - - it("exports", () => { - expect(Either.TypeId).exist + assertRight(a, 3) + assertRight(b, 10) + assertRight(c, undefined) + assertRight(d, 2) + assertLeft(e, "err") + assertLeft(f, "err") + assertRight(g, "testContext") + assertRight(h, 3) }) it("toString", () => { - expect(String(Either.right(1))).toEqual(`{ + strictEqual( + String(Either.right(1)), + `{ "_id": "Either", "_tag": "Right", "right": 1 -}`) - expect(String(Either.left("e"))).toEqual(`{ +}` + ) + strictEqual( + String(Either.left("e")), + `{ "_id": "Either", "_tag": "Left", "left": "e" -}`) - expect(String(Either.right(Chunk.make(1, 2, 3)))).toEqual(`{ +}` + ) + strictEqual( + String(Either.right(Chunk.make(1, 2, 3))), + `{ "_id": "Either", "_tag": "Right", "right": { @@ -87,8 +88,11 @@ describe("Either", () => { 3 ] } -}`) - expect(String(Either.left(Chunk.make(1, 2, 3)))).toEqual(`{ +}` + ) + strictEqual( + String(Either.left(Chunk.make(1, 2, 3))), + `{ "_id": "Either", "_tag": "Left", "left": { @@ -99,47 +103,44 @@ describe("Either", () => { 3 ] } -}`) +}` + ) }) it("toJSON", () => { - expect(Either.right(1).toJSON()).toEqual( - { _id: "Either", _tag: "Right", right: 1 } - ) - expect(Either.left("e").toJSON()).toEqual( - { _id: "Either", _tag: "Left", left: "e" } - ) + deepStrictEqual(Either.right(1).toJSON(), { _id: "Either", _tag: "Right", right: 1 }) + deepStrictEqual(Either.left("e").toJSON(), { _id: "Either", _tag: "Left", left: "e" }) }) it("inspect", () => { if (typeof window === "undefined") { // eslint-disable-next-line @typescript-eslint/no-var-requires const { inspect } = require("node:util") - expect(inspect(Either.right(1))).toEqual(inspect({ _id: "Either", _tag: "Right", right: 1 })) - expect(inspect(Either.left("e"))).toEqual(inspect({ _id: "Either", _tag: "Left", left: "e" })) + deepStrictEqual(inspect(Either.right(1)), inspect({ _id: "Either", _tag: "Right", right: 1 })) + deepStrictEqual(inspect(Either.left("e")), inspect({ _id: "Either", _tag: "Left", left: "e" })) } }) it("isEither", () => { - Util.deepStrictEqual(pipe(Either.right(1), Either.isEither), true) - Util.deepStrictEqual(pipe(Either.left("e"), Either.isEither), true) - Util.deepStrictEqual(pipe(Option.some(1), Either.isEither), false) + assertTrue(pipe(Either.right(1), Either.isEither)) + assertTrue(pipe(Either.left("e"), Either.isEither)) + assertFalse(pipe(Option.some(1), Either.isEither)) }) it("getRight", () => { - Util.deepStrictEqual(pipe(Either.right(1), Either.getRight), Option.some(1)) - Util.deepStrictEqual(pipe(Either.left("a"), Either.getRight), Option.none()) + assertSome(pipe(Either.right(1), Either.getRight), 1) + assertNone(pipe(Either.left("a"), Either.getRight)) }) it("getLeft", () => { - Util.deepStrictEqual(pipe(Either.right(1), Either.getLeft), Option.none()) - Util.deepStrictEqual(pipe(Either.left("e"), Either.getLeft), Option.some("e")) + assertNone(pipe(Either.right(1), Either.getLeft)) + assertSome(pipe(Either.left("e"), Either.getLeft), "e") }) it("map", () => { const f = Either.map(Str.length) - Util.deepStrictEqual(pipe(Either.right("abc"), f), Either.right(3)) - Util.deepStrictEqual(pipe(Either.left("s"), f), Either.left("s")) + assertRight(pipe(Either.right("abc"), f), 3) + assertLeft(pipe(Either.left("s"), f), "s") }) it("mapBoth", () => { @@ -147,37 +148,37 @@ describe("Either", () => { onLeft: Str.length, onRight: (n: number) => n > 2 }) - Util.deepStrictEqual(pipe(Either.right(1), f), Either.right(false)) - Util.deepStrictEqual(pipe(Either.left("a"), f), Either.left(1)) + assertRight(pipe(Either.right(1), f), false) + assertLeft(pipe(Either.left("a"), f), 1) }) it("mapLeft", () => { - const f = Either.mapLeft(Util.double) - Util.deepStrictEqual(pipe(Either.right("a"), f), Either.right("a")) - Util.deepStrictEqual(pipe(Either.left(1), f), Either.left(2)) + const f = Either.mapLeft((n: number) => n * 2) + assertRight(pipe(Either.right("a"), f), "a") + assertLeft(pipe(Either.left(1), f), 2) }) it("match", () => { const onLeft = (s: string) => `left${s.length}` const onRight = (s: string) => `right${s.length}` const match = Either.match({ onLeft, onRight }) - Util.deepStrictEqual(match(Either.left("abc")), "left3") - Util.deepStrictEqual(match(Either.right("abc")), "right3") + strictEqual(match(Either.left("abc")), "left3") + strictEqual(match(Either.right("abc")), "right3") }) it("isLeft", () => { - Util.deepStrictEqual(Either.isLeft(Either.right(1)), false) - Util.deepStrictEqual(Either.isLeft(Either.left(1)), true) + assertFalse(Either.isLeft(Either.right(1))) + assertTrue(Either.isLeft(Either.left(1))) }) it("isRight", () => { - Util.deepStrictEqual(Either.isRight(Either.right(1)), true) - Util.deepStrictEqual(Either.isRight(Either.left(1)), false) + assertTrue(Either.isRight(Either.right(1))) + assertFalse(Either.isRight(Either.left(1))) }) it("flip", () => { - Util.deepStrictEqual(Either.flip(Either.right("a")), Either.left("a")) - Util.deepStrictEqual(Either.flip(Either.left("b")), Either.right("b")) + assertLeft(Either.flip(Either.right("a")), "a") + assertRight(Either.flip(Either.left("b")), "b") }) it("liftPredicate", () => { @@ -186,91 +187,91 @@ describe("Either", () => { const isNumberRefinement = (n: string | number): n is number => typeof n === "number" const onNumberRefinementError = (n: string | number) => `${n} is not a number` - Util.deepStrictEqual( + assertRight( pipe(1, Either.liftPredicate(isPositivePredicate, onPositivePredicateError)), - Either.right(1) + 1 ) - Util.deepStrictEqual( + assertLeft( pipe(-1, Either.liftPredicate(isPositivePredicate, onPositivePredicateError)), - Either.left(`-1 is not positive`) + "-1 is not positive" ) - Util.deepStrictEqual( + assertRight( pipe(1, Either.liftPredicate(isNumberRefinement, onNumberRefinementError)), - Either.right(1) + 1 ) - Util.deepStrictEqual( + assertLeft( pipe("string", Either.liftPredicate(isNumberRefinement, onNumberRefinementError)), - Either.left(`string is not a number`) + "string is not a number" ) - Util.deepStrictEqual( + assertRight( Either.liftPredicate(1, isPositivePredicate, onPositivePredicateError), - Either.right(1) + 1 ) - Util.deepStrictEqual( + assertLeft( Either.liftPredicate(-1, isPositivePredicate, onPositivePredicateError), - Either.left(`-1 is not positive`) + "-1 is not positive" ) - Util.deepStrictEqual( + assertRight( Either.liftPredicate(1, isNumberRefinement, onNumberRefinementError), - Either.right(1) + 1 ) - Util.deepStrictEqual( + assertLeft( Either.liftPredicate("string", isNumberRefinement, onNumberRefinementError), - Either.left(`string is not a number`) + "string is not a number" ) }) it("filterOrLeft", () => { - Util.deepStrictEqual(Either.filterOrLeft(Either.right(1), (n) => n > 0, () => "a"), Either.right(1)) - Util.deepStrictEqual(Either.filterOrLeft(Either.right(1), (n) => n > 1, () => "a"), Either.left("a")) - Util.deepStrictEqual(Either.filterOrLeft(Either.left(1), (n) => n > 0, () => "a"), Either.left(1)) + deepStrictEqual(Either.filterOrLeft(Either.right(1), (n) => n > 0, () => "a"), Either.right(1)) + deepStrictEqual(Either.filterOrLeft(Either.right(1), (n) => n > 1, () => "a"), Either.left("a")) + deepStrictEqual(Either.filterOrLeft(Either.left(1), (n) => n > 0, () => "a"), Either.left(1)) - Util.deepStrictEqual(Either.right(1).pipe(Either.filterOrLeft((n) => n > 0, () => "a")), Either.right(1)) - Util.deepStrictEqual(Either.right(1).pipe(Either.filterOrLeft((n) => n > 1, () => "a")), Either.left("a")) - Util.deepStrictEqual(Either.left(1).pipe(Either.filterOrLeft((n) => n > 0, () => "a")), Either.left(1)) + deepStrictEqual(Either.right(1).pipe(Either.filterOrLeft((n) => n > 0, () => "a")), Either.right(1)) + deepStrictEqual(Either.right(1).pipe(Either.filterOrLeft((n) => n > 1, () => "a")), Either.left("a")) + deepStrictEqual(Either.left(1).pipe(Either.filterOrLeft((n) => n > 0, () => "a")), Either.left(1)) }) it("merge", () => { - Util.deepStrictEqual(Either.merge(Either.right(1)), 1) - Util.deepStrictEqual(Either.merge(Either.left("a")), "a") + deepStrictEqual(Either.merge(Either.right(1)), 1) + deepStrictEqual(Either.merge(Either.left("a")), "a") }) it("getEquivalence", () => { const isEquivalent = Either.getEquivalence({ right: Num.Equivalence, left: Str.Equivalence }) - Util.deepStrictEqual(isEquivalent(Either.right(1), Either.right(1)), true) - Util.deepStrictEqual(isEquivalent(Either.right(1), Either.right(2)), false) - Util.deepStrictEqual(isEquivalent(Either.right(1), Either.left("foo")), false) - Util.deepStrictEqual(isEquivalent(Either.left("foo"), Either.left("foo")), true) - Util.deepStrictEqual(isEquivalent(Either.left("foo"), Either.left("bar")), false) - Util.deepStrictEqual(isEquivalent(Either.left("foo"), Either.right(1)), false) + deepStrictEqual(isEquivalent(Either.right(1), Either.right(1)), true) + deepStrictEqual(isEquivalent(Either.right(1), Either.right(2)), false) + deepStrictEqual(isEquivalent(Either.right(1), Either.left("foo")), false) + deepStrictEqual(isEquivalent(Either.left("foo"), Either.left("foo")), true) + deepStrictEqual(isEquivalent(Either.left("foo"), Either.left("bar")), false) + deepStrictEqual(isEquivalent(Either.left("foo"), Either.right(1)), false) }) it("pipe()", () => { - expect(Either.right(1).pipe(Either.map((n) => n + 1))).toEqual(Either.right(2)) + assertRight(Either.right(1).pipe(Either.map((n) => n + 1)), 2) }) it("fromNullable", () => { - Util.deepStrictEqual(Either.fromNullable(null, () => "fallback"), Either.left("fallback")) - Util.deepStrictEqual(Either.fromNullable(undefined, () => "fallback"), Either.left("fallback")) - Util.deepStrictEqual(Either.fromNullable(1, () => "fallback"), Either.right(1)) + deepStrictEqual(Either.fromNullable(null, () => "fallback"), Either.left("fallback")) + deepStrictEqual(Either.fromNullable(undefined, () => "fallback"), Either.left("fallback")) + deepStrictEqual(Either.fromNullable(1, () => "fallback"), Either.right(1)) }) it("fromOption", () => { - Util.deepStrictEqual(Either.fromOption(Option.none(), () => "none"), Either.left("none")) - Util.deepStrictEqual(Either.fromOption(Option.some(1), () => "none"), Either.right(1)) + deepStrictEqual(Either.fromOption(Option.none(), () => "none"), Either.left("none")) + deepStrictEqual(Either.fromOption(Option.some(1), () => "none"), Either.right(1)) }) it("try", () => { - Util.deepStrictEqual(Either.try(() => 1), Either.right(1)) - Util.deepStrictEqual( + deepStrictEqual(Either.try(() => 1), Either.right(1)) + deepStrictEqual( Either.try(() => { throw "b" }), Either.left("b") ) - Util.deepStrictEqual(Either.try({ try: () => 1, catch: (e) => new Error(String(e)) }), Either.right(1)) - Util.deepStrictEqual( + deepStrictEqual(Either.try({ try: () => 1, catch: (e) => new Error(String(e)) }), Either.right(1)) + deepStrictEqual( Either.try({ try: () => { throw "b" @@ -282,130 +283,119 @@ describe("Either", () => { }) it("getOrElse", () => { - Util.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + "!"), 1) - Util.deepStrictEqual(Either.getOrElse(Either.left("not a number"), (error) => error + "!"), "not a number!") + strictEqual(Either.getOrElse(Either.right(1), (error) => error + "!"), 1) + strictEqual(Either.getOrElse(Either.left("not a number"), (error) => error + "!"), "not a number!") }) it("getOrNull", () => { - Util.deepStrictEqual(Either.getOrNull(Either.right(1)), 1) - Util.deepStrictEqual(Either.getOrNull(Either.left("a")), null) + strictEqual(Either.getOrNull(Either.right(1)), 1) + strictEqual(Either.getOrNull(Either.left("a")), null) }) it("getOrUndefined", () => { - Util.deepStrictEqual(Either.getOrUndefined(Either.right(1)), 1) - Util.deepStrictEqual(Either.getOrUndefined(Either.left("a")), undefined) + strictEqual(Either.getOrUndefined(Either.right(1)), 1) + strictEqual(Either.getOrUndefined(Either.left("a")), undefined) }) it("getOrThrowWith", () => { - expect(pipe(Either.right(1), Either.getOrThrowWith((e) => new Error(`Unexpected Left: ${e}`)))).toEqual(1) - expect(() => pipe(Either.left("e"), Either.getOrThrowWith((e) => new Error(`Unexpected Left: ${e}`)))) - .toThrowError( - new Error("Unexpected Left: e") - ) + strictEqual(pipe(Either.right(1), Either.getOrThrowWith((e) => new Error(`Unexpected Left: ${e}`))), 1) + throws(() => pipe(Either.left("e"), Either.getOrThrowWith((e) => new Error(`Unexpected Left: ${e}`)))), + new Error("Unexpected Left: e") }) it("getOrThrow", () => { - expect(pipe(Either.right(1), Either.getOrThrow)).toEqual(1) - expect(() => pipe(Either.left("e"), Either.getOrThrow)).toThrowError( - new Error("getOrThrow called on a Left") - ) + strictEqual(pipe(Either.right(1), Either.getOrThrow), 1) + throws(() => pipe(Either.left("e"), Either.getOrThrow), new Error("getOrThrow called on a Left")) }) it("flatMap", () => { const f = Either.flatMap(flow(Str.length, Either.right)) - Util.deepStrictEqual(pipe(Either.right("abc"), f), Either.right(3)) - Util.deepStrictEqual(pipe(Either.left("maError"), f), Either.left("maError")) + assertRight(pipe(Either.right("abc"), f), 3) + assertLeft(pipe(Either.left("maError"), f), "maError") }) it("andThen", () => { - expect(pipe(Either.right(1), Either.andThen(() => Either.right(2)))).toStrictEqual(Either.right(2)) - expect(pipe(Either.right(1), Either.andThen(Either.right(2)))).toStrictEqual(Either.right(2)) - expect(pipe(Either.right(1), Either.andThen(2))).toStrictEqual(Either.right(2)) - expect(pipe(Either.right(1), Either.andThen(() => 2))).toStrictEqual(Either.right(2)) - expect(pipe(Either.right(1), Either.andThen((a) => a))).toStrictEqual(Either.right(1)) - expect(Either.andThen(Either.right(1), () => Either.right(2))).toStrictEqual(Either.right(2)) - expect(Either.andThen(Either.right(1), Either.right(2))).toStrictEqual(Either.right(2)) - expect(Either.andThen(Either.right(1), () => 2)).toStrictEqual(Either.right(2)) - expect(Either.andThen(Either.right(1), 2)).toStrictEqual(Either.right(2)) - expect(Either.andThen(Either.right(1), (a) => a)).toStrictEqual(Either.right(1)) + assertRight(pipe(Either.right(1), Either.andThen(() => Either.right(2))), 2) + assertRight(pipe(Either.right(1), Either.andThen(Either.right(2))), 2) + assertRight(pipe(Either.right(1), Either.andThen(2)), 2) + assertRight(pipe(Either.right(1), Either.andThen(() => 2)), 2) + assertRight(pipe(Either.right(1), Either.andThen((a) => a)), 1) + assertRight(Either.andThen(Either.right(1), () => Either.right(2)), 2) + assertRight(Either.andThen(Either.right(1), Either.right(2)), 2) + assertRight(Either.andThen(Either.right(1), () => 2), 2) + assertRight(Either.andThen(Either.right(1), 2), 2) + assertRight(Either.andThen(Either.right(1), (a) => a), 1) }) it("ap", () => { const add = (a: number) => (b: number) => a + b - expect(Either.right(add).pipe(Either.ap(Either.right(1)), Either.ap(Either.right(2)))).toStrictEqual( - Either.right(3) - ) - expect(Either.right(add).pipe(Either.ap(Either.left("b")), Either.ap(Either.right(2)))).toStrictEqual( - Either.left("b") - ) - expect(Either.right(add).pipe(Either.ap(Either.right(1)), Either.ap(Either.left("c")))).toStrictEqual( - Either.left("c") - ) - expect(Either.right(add).pipe(Either.ap(Either.left("b")), Either.ap(Either.left("c")))).toStrictEqual( - Either.left("b") - ) - expect( + assertRight(Either.right(add).pipe(Either.ap(Either.right(1)), Either.ap(Either.right(2))), 3) + assertLeft(Either.right(add).pipe(Either.ap(Either.left("b")), Either.ap(Either.right(2))), "b") + assertLeft(Either.right(add).pipe(Either.ap(Either.right(1)), Either.ap(Either.left("c"))), "c") + assertLeft(Either.right(add).pipe(Either.ap(Either.left("b")), Either.ap(Either.left("c"))), "b") + assertLeft( (Either.left("a") as Either.Either).pipe( Either.ap(Either.right(1)), Either.ap(Either.right(2)) - ) - ).toStrictEqual(Either.left("a")) + ), + "a" + ) }) it("zipWith", () => { - expect(pipe(Either.left(0), Either.zipWith(Either.right(2), (a, b) => a + b))).toEqual(Either.left(0)) - expect(pipe(Either.right(1), Either.zipWith(Either.left(0), (a, b) => a + b))).toEqual(Either.left(0)) - expect(pipe(Either.right(1), Either.zipWith(Either.right(2), (a, b) => a + b))).toEqual(Either.right(3)) + assertLeft(pipe(Either.left(0), Either.zipWith(Either.right(2), (a, b) => a + b)), 0) + assertLeft(pipe(Either.right(1), Either.zipWith(Either.left(0), (a, b) => a + b)), 0) + assertRight(pipe(Either.right(1), Either.zipWith(Either.right(2), (a, b) => a + b)), 3) }) it("all", () => { // tuples and arrays - Util.deepStrictEqual(Either.all([]), Either.right([])) - Util.deepStrictEqual(Either.all([Either.right(1)]), Either.right([1])) - Util.deepStrictEqual(Either.all([Either.right(1), Either.right(true)]), Either.right([1, true])) - Util.deepStrictEqual(Either.all([Either.right(1), Either.left("e")]), Either.left("e")) + assertRight(Either.all([]), []) + assertRight(Either.all([Either.right(1)]), [1]) + assertRight(Either.all([Either.right(1), Either.right(true)]), [1, true]) + assertLeft(Either.all([Either.right(1), Either.left("e")]), "e") // structs and records - Util.deepStrictEqual(Either.all({}), Either.right({})) - Util.deepStrictEqual(Either.all({ a: Either.right(1) }), Either.right({ a: 1 })) - Util.deepStrictEqual(Either.all({ a: Either.right(1), b: Either.right(true) }), Either.right({ a: 1, b: true })) - Util.deepStrictEqual(Either.all({ a: Either.right(1), b: Either.left("e") }), Either.left("e")) + assertRight(Either.all({}), {}) + assertRight(Either.all({ a: Either.right(1) }), { a: 1 }) + assertRight(Either.all({ a: Either.right(1), b: Either.right(true) }), { a: 1, b: true }) + assertLeft(Either.all({ a: Either.right(1), b: Either.left("e") }), "e") }) it("orElse", () => { - Util.deepStrictEqual(pipe(Either.right(1), Either.orElse(() => Either.right(2))), Either.right(1)) - Util.deepStrictEqual(pipe(Either.right(1), Either.orElse(() => Either.left("b"))), Either.right(1)) - Util.deepStrictEqual(pipe(Either.left("a"), Either.orElse(() => Either.right(2))), Either.right(2)) - Util.deepStrictEqual(pipe(Either.left("a"), Either.orElse(() => Either.left("b"))), Either.left("b")) + assertRight(pipe(Either.right(1), Either.orElse(() => Either.right(2))), 1) + assertRight(pipe(Either.right(1), Either.orElse(() => Either.left("b"))), 1) + assertRight(pipe(Either.left("a"), Either.orElse(() => Either.right(2))), 2) + assertLeft(pipe(Either.left("a"), Either.orElse(() => Either.left("b"))), "b") }) describe("do notation", () => { it("Do", () => { - expectRight(Either.Do, {}) + assertRight(Either.Do, {}) }) it("bindTo", () => { - expectRight(pipe(Either.right(1), Either.bindTo("a")), { a: 1 }) - expectLeft(pipe(Either.left("left"), Either.bindTo("a")), "left") + assertRight(pipe(Either.right(1), Either.bindTo("a")), { a: 1 }) + assertLeft(pipe(Either.left("left"), Either.bindTo("a")), "left") }) it("bind", () => { - expectRight(pipe(Either.right(1), Either.bindTo("a"), Either.bind("b", ({ a }) => Either.right(a + 1))), { + assertRight(pipe(Either.right(1), Either.bindTo("a"), Either.bind("b", ({ a }) => Either.right(a + 1))), { a: 1, b: 2 }) - expectLeft( + assertLeft( pipe(Either.right(1), Either.bindTo("a"), Either.bind("b", () => Either.left("left"))), "left" ) - expectLeft( + assertLeft( pipe(Either.left("left"), Either.bindTo("a"), Either.bind("b", () => Either.right(2))), "left" ) }) it("let", () => { - expectRight(pipe(Either.right(1), Either.bindTo("a"), Either.let("b", ({ a }) => a + 1)), { a: 1, b: 2 }) - expectLeft( + assertRight(pipe(Either.right(1), Either.bindTo("a"), Either.let("b", ({ a }) => a + 1)), { a: 1, b: 2 }) + assertLeft( pipe(Either.left("left"), Either.bindTo("a"), Either.let("b", () => 2)), "left" ) diff --git a/packages/effect/test/Encoding.test.ts b/packages/effect/test/Encoding.test.ts index 8c477c8d6f4..5bee34daa28 100644 --- a/packages/effect/test/Encoding.test.ts +++ b/packages/effect/test/Encoding.test.ts @@ -1,7 +1,6 @@ -import * as Either from "effect/Either" -import * as Encoding from "effect/Encoding" -import { deepStrictEqual, strictEqual } from "effect/test/util" -import { assert, describe, it } from "vitest" +import { Either, Encoding } from "effect" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Base64", () => { const valid: Array<[string, string]> = [ @@ -38,13 +37,13 @@ describe("Base64", () => { it.each(valid)(`should decode %j <= %j`, (raw: string, b64: string) => { const bytes = new TextEncoder().encode(raw) const decoded = Encoding.decodeBase64(b64) - assert(Either.isRight(decoded)) + assertTrue(Either.isRight(decoded)) deepStrictEqual(decoded.right, bytes) }) it.each(valid)(`should decode %j <= %j (to string)`, (raw: string, b64: string) => { const decoded = Encoding.decodeBase64String(b64) - assert(Either.isRight(decoded)) + assertTrue(Either.isRight(decoded)) deepStrictEqual(decoded.right, raw) }) @@ -55,8 +54,8 @@ describe("Base64", () => { it.each(invalid)(`should refuse to decode %j`, (b64: string) => { const result = Encoding.decodeBase64(b64) - assert(Either.isLeft(result)) - assert(Encoding.isDecodeException(result.left)) + assertTrue(Either.isLeft(result)) + assertTrue(Encoding.isDecodeException(result.left)) }) }) @@ -83,13 +82,13 @@ describe("Base64Url", () => { it.each(valid)(`should decode %j <= %j`, (raw: string, b64url: string) => { const bytes = new TextEncoder().encode(raw) const decoded = Encoding.decodeBase64Url(b64url) - assert(Either.isRight(decoded)) + assertTrue(Either.isRight(decoded)) deepStrictEqual(decoded.right, bytes) }) it.each(valid)(`should decode %j <= %j (to string)`, (raw: string, b64: string) => { const decoded = Encoding.decodeBase64UrlString(b64) - assert(Either.isRight(decoded)) + assertTrue(Either.isRight(decoded)) deepStrictEqual(decoded.right, raw) }) @@ -100,8 +99,8 @@ describe("Base64Url", () => { it.each(invalid)(`should refuse to decode %j`, (b64url: string) => { const result = Encoding.decodeBase64Url(b64url) - assert(Either.isLeft(result)) - assert(Encoding.isDecodeException(result.left)) + assertTrue(Either.isLeft(result)) + assertTrue(Encoding.isDecodeException(result.left)) }) }) @@ -137,13 +136,13 @@ describe("Hex", () => { it.each(valid)(`should decode %j => %o`, (hex: string, bytes: Uint8Array) => { const decoded = Encoding.decodeHex(hex) - assert(Either.isRight(decoded)) + assertTrue(Either.isRight(decoded)) deepStrictEqual(decoded.right, bytes) }) it.each(strings)(`should decode %j => %j to string`, (hex: string, str: string) => { const decoded = Encoding.decodeHexString(hex) - assert(Either.isRight(decoded)) + assertTrue(Either.isRight(decoded)) deepStrictEqual(decoded.right, str) }) @@ -157,8 +156,8 @@ describe("Hex", () => { it.each(invalid)(`should refuse to decode %j`, (hex: string) => { const result = Encoding.decodeHex(hex) - assert(Either.isLeft(result)) - assert(Encoding.isDecodeException(result.left)) + assertTrue(Either.isLeft(result)) + assertTrue(Encoding.isDecodeException(result.left)) }) }) @@ -183,25 +182,25 @@ describe("UriComponent", () => { it.each(valid)(`should decode %j => %j`, (uri: string, raw: string) => { const decoded = Encoding.decodeUriComponent(uri) - assert(Either.isRight(decoded)) + assertTrue(Either.isRight(decoded)) deepStrictEqual(decoded.right, raw) }) it.each(valid)(`should encode %j => %j`, (uri: string, raw: string) => { const encoded = Encoding.encodeUriComponent(raw) - assert(Either.isRight(encoded)) + assertTrue(Either.isRight(encoded)) deepStrictEqual(encoded.right, uri) }) it.each(invalidDecode)(`should refuse to decode %j`, (uri: string) => { const result = Encoding.decodeUriComponent(uri) - assert(Either.isLeft(result)) - assert(Encoding.isDecodeException(result.left)) + assertTrue(Either.isLeft(result)) + assertTrue(Encoding.isDecodeException(result.left)) }) it.each(invalidEncode)(`should refuse to encode %j`, (raw: string) => { const result = Encoding.encodeUriComponent(raw) - assert(Either.isLeft(result)) - assert(Encoding.isEncodeException(result.left)) + assertTrue(Either.isLeft(result)) + assertTrue(Encoding.isEncodeException(result.left)) }) }) diff --git a/packages/effect/test/Equivalence.test.ts b/packages/effect/test/Equivalence.test.ts index 00a6a4cc1b5..9c2bbe9a3fe 100644 --- a/packages/effect/test/Equivalence.test.ts +++ b/packages/effect/test/Equivalence.test.ts @@ -1,22 +1,22 @@ -import * as _ from "effect/Equivalence" -import { pipe } from "effect/Function" -import { describe, expect, it } from "vitest" +import { Equivalence, pipe } from "effect" +import { assertFalse, assertTrue } from "effect/test/util" +import { describe, it } from "vitest" describe("Equivalence", () => { it("array", () => { - const eq = _.array(_.number) + const eq = Equivalence.array(Equivalence.number) - expect(eq([], [])).toEqual(true) - expect(eq([1, 2, 3], [1, 2, 3])).toEqual(true) - expect(eq([1, 2, 3], [1, 2, 4])).toEqual(false) - expect(eq([1, 2, 3], [1, 2])).toEqual(false) + assertTrue(eq([], [])) + assertTrue(eq([1, 2, 3], [1, 2, 3])) + assertFalse(eq([1, 2, 3], [1, 2, 4])) + assertFalse(eq([1, 2, 3], [1, 2])) }) it("strict returns an Equivalence that uses strict equality (===) to compare values", () => { - const eq = _.strict<{ a: number }>() + const eq = Equivalence.strict<{ a: number }>() const a = { a: 1 } - expect(eq(a, a)).toBe(true) - expect(eq({ a: 1 }, { a: 1 })).toBe(false) + assertTrue(eq(a, a)) + assertFalse(eq({ a: 1 }, { a: 1 })) }) it("mapInput", () => { @@ -24,88 +24,88 @@ describe("Equivalence", () => { readonly name: string readonly age: number } - const eqPerson = pipe(_.string, _.mapInput((p: Person) => p.name)) - expect(eqPerson({ name: "a", age: 1 }, { name: "a", age: 2 })).toEqual(true) - expect(eqPerson({ name: "a", age: 1 }, { name: "a", age: 1 })).toEqual(true) - expect(eqPerson({ name: "a", age: 1 }, { name: "b", age: 1 })).toEqual(false) - expect(eqPerson({ name: "a", age: 1 }, { name: "b", age: 2 })).toEqual(false) + const eqPerson = pipe(Equivalence.string, Equivalence.mapInput((p: Person) => p.name)) + assertTrue(eqPerson({ name: "a", age: 1 }, { name: "a", age: 2 })) + assertTrue(eqPerson({ name: "a", age: 1 }, { name: "a", age: 1 })) + assertFalse(eqPerson({ name: "a", age: 1 }, { name: "b", age: 1 })) + assertFalse(eqPerson({ name: "a", age: 1 }, { name: "b", age: 2 })) }) it("Date", () => { - const eq = _.Date - expect(eq(new Date(0), new Date(0))).toEqual(true) - expect(eq(new Date(0), new Date(1))).toEqual(false) - expect(eq(new Date(1), new Date(0))).toEqual(false) + const eq = Equivalence.Date + assertTrue(eq(new Date(0), new Date(0))) + assertFalse(eq(new Date(0), new Date(1))) + assertFalse(eq(new Date(1), new Date(0))) }) it("product", () => { - const eq = _.product(_.string, _.string) - expect(eq(["a", "b"], ["a", "b"])).toEqual(true) - expect(eq(["a", "b"], ["c", "b"])).toEqual(false) - expect(eq(["a", "b"], ["a", "c"])).toEqual(false) + const eq = Equivalence.product(Equivalence.string, Equivalence.string) + assertTrue(eq(["a", "b"], ["a", "b"])) + assertFalse(eq(["a", "b"], ["c", "b"])) + assertFalse(eq(["a", "b"], ["a", "c"])) }) it("productMany", () => { - const eq = _.productMany(_.string, [_.string]) - expect(eq(["a", "b"], ["a", "b"])).toEqual(true) - expect(eq(["a", "b"], ["a", "b", "c"])).toEqual(true) - expect(eq(["a", "b", "c"], ["a", "b"])).toEqual(true) - expect(eq(["a", "b"], ["c", "b"])).toEqual(false) - expect(eq(["a", "b"], ["a", "c"])).toEqual(false) + const eq = Equivalence.productMany(Equivalence.string, [Equivalence.string]) + assertTrue(eq(["a", "b"], ["a", "b"])) + assertTrue(eq(["a", "b"], ["a", "b", "c"])) + assertTrue(eq(["a", "b", "c"], ["a", "b"])) + assertFalse(eq(["a", "b"], ["c", "b"])) + assertFalse(eq(["a", "b"], ["a", "c"])) }) it("all", () => { - const eq = _.all([_.string, _.string]) - expect(eq([], [])).toEqual(true) - expect(eq([], ["a"])).toEqual(true) - expect(eq(["a"], [])).toEqual(true) - expect(eq(["a"], ["a"])).toEqual(true) - expect(eq(["a"], ["b"])).toEqual(false) - expect(eq(["a"], ["a", "b"])).toEqual(true) - expect(eq(["a", "b"], ["a"])).toEqual(true) - expect(eq(["a", "b"], ["a", "b"])).toEqual(true) - expect(eq(["a", "b"], ["a", "c"])).toEqual(false) + const eq = Equivalence.all([Equivalence.string, Equivalence.string]) + assertTrue(eq([], [])) + assertTrue(eq([], ["a"])) + assertTrue(eq(["a"], [])) + assertTrue(eq(["a"], ["a"])) + assertFalse(eq(["a"], ["b"])) + assertTrue(eq(["a"], ["a", "b"])) + assertTrue(eq(["a", "b"], ["a"])) + assertTrue(eq(["a", "b"], ["a", "b"])) + assertFalse(eq(["a", "b"], ["a", "c"])) }) it("combine", () => { type T = readonly [string, number, boolean] - const E0: _.Equivalence = _.mapInput((x: T) => x[0])(_.string) - const E1: _.Equivalence = _.mapInput((x: T) => x[1])(_.number) - const eqE0E1 = _.combine(E0, E1) - expect(eqE0E1(["a", 1, true], ["a", 1, true])).toEqual(true) - expect(eqE0E1(["a", 1, true], ["a", 1, false])).toEqual(true) - expect(eqE0E1(["a", 1, true], ["b", 1, true])).toEqual(false) - expect(eqE0E1(["a", 1, true], ["a", 2, false])).toEqual(false) + const E0: Equivalence.Equivalence = Equivalence.mapInput((x: T) => x[0])(Equivalence.string) + const E1: Equivalence.Equivalence = Equivalence.mapInput((x: T) => x[1])(Equivalence.number) + const eqE0E1 = Equivalence.combine(E0, E1) + assertTrue(eqE0E1(["a", 1, true], ["a", 1, true])) + assertTrue(eqE0E1(["a", 1, true], ["a", 1, false])) + assertFalse(eqE0E1(["a", 1, true], ["b", 1, true])) + assertFalse(eqE0E1(["a", 1, true], ["a", 2, false])) }) it("combineMany", () => { type T = readonly [string, number, boolean] - const E0: _.Equivalence = _.mapInput((x: T) => x[0])(_.string) - const E1: _.Equivalence = _.mapInput((x: T) => x[1])(_.number) - const E2: _.Equivalence = _.mapInput((x: T) => x[2])(_.boolean) - const eqE0E1E2 = _.combineMany(E0, [E1, E2]) - expect(eqE0E1E2(["a", 1, true], ["a", 1, true])).toEqual(true) - expect(eqE0E1E2(["a", 1, true], ["b", 1, true])).toEqual(false) - expect(eqE0E1E2(["a", 1, true], ["a", 2, true])).toEqual(false) - expect(eqE0E1E2(["a", 1, true], ["a", 1, false])).toEqual(false) + const E0: Equivalence.Equivalence = Equivalence.mapInput((x: T) => x[0])(Equivalence.string) + const E1: Equivalence.Equivalence = Equivalence.mapInput((x: T) => x[1])(Equivalence.number) + const E2: Equivalence.Equivalence = Equivalence.mapInput((x: T) => x[2])(Equivalence.boolean) + const eqE0E1E2 = Equivalence.combineMany(E0, [E1, E2]) + assertTrue(eqE0E1E2(["a", 1, true], ["a", 1, true])) + assertFalse(eqE0E1E2(["a", 1, true], ["b", 1, true])) + assertFalse(eqE0E1E2(["a", 1, true], ["a", 2, true])) + assertFalse(eqE0E1E2(["a", 1, true], ["a", 1, false])) }) it("combineAll", () => { type T = readonly [string, number, boolean] - const E0: _.Equivalence = _.mapInput((x: T) => x[0])(_.string) - const E1: _.Equivalence = _.mapInput((x: T) => x[1])(_.number) - const E2: _.Equivalence = _.mapInput((x: T) => x[2])(_.boolean) - const eqE0E1E2 = _.combineAll([E0, E1, E2]) - expect(eqE0E1E2(["a", 1, true], ["a", 1, true])).toEqual(true) - expect(eqE0E1E2(["a", 1, true], ["b", 1, true])).toEqual(false) - expect(eqE0E1E2(["a", 1, true], ["a", 2, true])).toEqual(false) - expect(eqE0E1E2(["a", 1, true], ["a", 1, false])).toEqual(false) + const E0: Equivalence.Equivalence = Equivalence.mapInput((x: T) => x[0])(Equivalence.string) + const E1: Equivalence.Equivalence = Equivalence.mapInput((x: T) => x[1])(Equivalence.number) + const E2: Equivalence.Equivalence = Equivalence.mapInput((x: T) => x[2])(Equivalence.boolean) + const eqE0E1E2 = Equivalence.combineAll([E0, E1, E2]) + assertTrue(eqE0E1E2(["a", 1, true], ["a", 1, true])) + assertFalse(eqE0E1E2(["a", 1, true], ["b", 1, true])) + assertFalse(eqE0E1E2(["a", 1, true], ["a", 2, true])) + assertFalse(eqE0E1E2(["a", 1, true], ["a", 1, false])) }) it("tuple", () => { - const eq = _.tuple(_.string, _.string) - expect(eq(["a", "b"], ["a", "b"])).toEqual(true) - expect(eq(["a", "b"], ["c", "b"])).toEqual(false) - expect(eq(["a", "b"], ["a", "c"])).toEqual(false) + const eq = Equivalence.tuple(Equivalence.string, Equivalence.string) + assertTrue(eq(["a", "b"], ["a", "b"])) + assertFalse(eq(["a", "b"], ["c", "b"])) + assertFalse(eq(["a", "b"], ["a", "c"])) }) }) diff --git a/packages/effect/test/Exit.test.ts b/packages/effect/test/Exit.test.ts index 6f2384dc3c0..792a6e0b1f0 100644 --- a/packages/effect/test/Exit.test.ts +++ b/packages/effect/test/Exit.test.ts @@ -1,10 +1,11 @@ -import * as Exit from "effect/Exit" -import { describe, expect, it } from "vitest" +import { Exit } from "effect" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Exit", () => { describe("toJSON", () => { it("succeed", () => { - expect(Exit.succeed(1).toJSON()).toEqual({ + deepStrictEqual(Exit.succeed(1).toJSON(), { _id: "Exit", _tag: "Success", value: 1 @@ -12,7 +13,7 @@ describe("Exit", () => { }) it("fail", () => { - expect(Exit.fail("failure").toJSON()).toEqual({ + deepStrictEqual(Exit.fail("failure").toJSON(), { _id: "Exit", _tag: "Failure", cause: { @@ -24,15 +25,13 @@ describe("Exit", () => { class MyError { readonly _tag = "MyError" } - expect(Exit.fail(new MyError()).toJSON()).toEqual({ + deepStrictEqual(Exit.fail(new MyError()).toJSON(), { _id: "Exit", _tag: "Failure", cause: { _id: "Cause", _tag: "Fail", - failure: { - _tag: "MyError" - } + failure: new MyError() } }) }) @@ -40,15 +39,20 @@ describe("Exit", () => { describe("toString", () => { it("succeed", () => { - expect(String(Exit.succeed(1))).toEqual(`{ + deepStrictEqual( + String(Exit.succeed(1)), + `{ "_id": "Exit", "_tag": "Success", "value": 1 -}`) +}` + ) }) it("fail", () => { - expect(String(Exit.fail("failure"))).toEqual(`{ + deepStrictEqual( + String(Exit.fail("failure")), + `{ "_id": "Exit", "_tag": "Failure", "cause": { @@ -56,11 +60,14 @@ describe("Exit", () => { "_tag": "Fail", "failure": "failure" } -}`) +}` + ) class Error1 { readonly _tag = "WithTag" } - expect(String(Exit.fail(new Error1()))).toEqual(`{ + deepStrictEqual( + String(Exit.fail(new Error1())), + `{ "_id": "Exit", "_tag": "Failure", "cause": { @@ -70,7 +77,8 @@ describe("Exit", () => { "_tag": "WithTag" } } -}`) +}` + ) }) }) }) diff --git a/packages/effect/test/Fiber.test.ts b/packages/effect/test/Fiber.test.ts index 0442f7b44f7..c24c267ed0c 100644 --- a/packages/effect/test/Fiber.test.ts +++ b/packages/effect/test/Fiber.test.ts @@ -11,9 +11,10 @@ import { constVoid, pipe } from "effect/Function" import * as HashSet from "effect/HashSet" import * as Queue from "effect/Queue" import * as Ref from "effect/Ref" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import { withLatch } from "effect/test/utils/latch" -import { assert, describe } from "vitest" +import { describe } from "vitest" const initial = "initial" const update = "update" @@ -33,7 +34,7 @@ describe("Fiber", () => { ), Effect.eventually ) - assert.deepStrictEqual(blockingOn, Fiber.id(fiber1)) + deepStrictEqual(blockingOn, Fiber.id(fiber1)) })) it.effect("should track blockingOn in race", () => Effect.gen(function*($) { @@ -45,7 +46,7 @@ describe("Fiber", () => { ), Effect.eventually ) - assert.strictEqual(HashSet.size(FiberId.toSet(blockingOn)), 2) + strictEqual(HashSet.size(FiberId.toSet(blockingOn)), 2) })) it.scoped("inheritLocals works for Fiber created using map", () => Effect.gen(function*($) { @@ -55,7 +56,7 @@ describe("Fiber", () => { ) yield* $(child, Fiber.map(constVoid), Fiber.inheritAll) const result = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(result, update) + strictEqual(result, update) })) it.scoped("inheritLocals works for Fiber created using orElse", () => Effect.gen(function*($) { @@ -75,7 +76,7 @@ describe("Fiber", () => { yield* $(Deferred.await(latch1), Effect.zipRight(Deferred.await(latch2))) yield* $(child1, Fiber.orElse(child2), Fiber.inheritAll) const result = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(result, "child1") + strictEqual(result, "child1") })) it.scoped("inheritLocals works for Fiber created using zip", () => Effect.gen(function*($) { @@ -95,13 +96,13 @@ describe("Fiber", () => { yield* $(Deferred.await(latch1), Effect.zipRight(Deferred.await(latch2))) yield* $(child1, Fiber.zip(child2), Fiber.inheritAll) const result = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(result, "child1") + strictEqual(result, "child1") })) it.effect("join on interrupted Fiber is an inner interruption", () => Effect.gen(function*($) { const fiberId = FiberId.make(0, 123) const result = yield* $(Fiber.interrupted(fiberId), Fiber.join, Effect.exit) - assert.deepStrictEqual(result, Exit.interrupt(fiberId)) + deepStrictEqual(result, Exit.interrupt(fiberId)) })) it.effect("scoped should create a new Fiber and scope it", () => Effect.gen(function*($) { @@ -118,7 +119,7 @@ describe("Fiber", () => { yield* $(Effect.scoped(Fiber.scoped(fiber))) yield* $(Fiber.await(fiber)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("shard example", () => Effect.gen(function*($) { @@ -148,7 +149,7 @@ describe("Fiber", () => { yield* $(Queue.offerAll(queue, Array.range(1, 100))) const result = yield* $(Effect.exit(shard(queue, 4, worker))) yield* $(Queue.shutdown(queue)) - assert.isTrue(Exit.isFailure(result)) + assertTrue(Exit.isFailure(result)) })) it.effect("child becoming interruptible is interrupted due to auto-supervision of uninterruptible parent", () => Effect.gen(function*($) { @@ -160,7 +161,7 @@ describe("Fiber", () => { ) yield* $(Effect.uninterruptible(Effect.fork(child))) const result = yield* $(Deferred.await(latch)) - assert.isUndefined(result) + strictEqual(result, undefined) })) it.effect("dual roots", () => Effect.gen(function*($) { @@ -175,7 +176,7 @@ describe("Fiber", () => { Effect.repeat({ until: (_) => _ }) ) const result = yield* $(Fiber.interrupt(fiber1), Effect.zipRight(Fiber.interrupt(fiber2))) - assert.isTrue(Exit.isInterrupted(result)) + assertTrue(Exit.isInterrupted(result)) })) it.effect("interruptAll interrupts fibers in parallel", () => Effect.gen(function*($) { @@ -196,7 +197,7 @@ describe("Fiber", () => { yield* $(Deferred.await(deferred2)) yield* $(Fiber.interruptAll([fiber2, fiber1])) const result = yield* $(Fiber.await(fiber2)) - assert.isTrue(Exit.isInterrupted(result)) + assertTrue(Exit.isInterrupted(result)) })) it.effect("await does not return until all fibers have completed execution", () => Effect.gen(function*($) { @@ -205,31 +206,31 @@ describe("Fiber", () => { yield* $(Fiber.interrupt(fiber)) yield* $(Ref.set(ref, -1)) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, -1) + strictEqual(result, -1) })) it.effect("awaitAll - stack safety", () => Effect.gen(function*($) { const result = yield* $(Fiber.awaitAll(fibers)) - assert.isArray(result) - assert(result.length === fibers.length) - result.forEach((_) => assert.isTrue(Exit.isSuccess(_) && _.value === undefined)) + assertTrue(Array.isArray(result)) + assertTrue(result.length === fibers.length) + result.forEach((_) => assertTrue(Exit.isSuccess(_) && _.value === undefined)) }), 10000) it.effect("joinAll - stack safety", () => Effect.gen(function*($) { const result = yield* $(Fiber.joinAll(fibers)) - assert.isArray(result) - assert(result.length === fibers.length) - result.forEach((_) => assert.isUndefined(_)) + assertTrue(Array.isArray(result)) + assertTrue(result.length === fibers.length) + result.forEach((x) => strictEqual(x, undefined)) }), 10000) it.effect("all - stack safety", () => Effect.gen(function*($) { const result = yield* $(Fiber.join(Fiber.all(fibers)), Effect.asVoid) - assert.isUndefined(result) + strictEqual(result, undefined) }), 10000) it.effect("is subtype of Effect", () => Effect.gen(function*() { const fiber = yield* Effect.fork(Effect.succeed(1)) const fiberResult = yield* fiber - assert(1 === fiberResult) + assertTrue(1 === fiberResult) })) }) diff --git a/packages/effect/test/FiberHandle.test.ts b/packages/effect/test/FiberHandle.test.ts index 3efc116cab4..b8b4e08afec 100644 --- a/packages/effect/test/FiberHandle.test.ts +++ b/packages/effect/test/FiberHandle.test.ts @@ -1,7 +1,7 @@ -import { Deferred, Effect, Exit, Fiber, Ref } from "effect" -import * as FiberHandle from "effect/FiberHandle" +import { Deferred, Effect, Exit, Fiber, FiberHandle, Ref } from "effect" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("FiberHandle", () => { it.effect("interrupts fibers", () => @@ -16,7 +16,7 @@ describe("FiberHandle", () => { Effect.scoped ) - assert.strictEqual(yield* _(Ref.get(ref)), 1) + strictEqual(yield* _(Ref.get(ref)), 1) })) it.effect("runtime", () => @@ -34,12 +34,12 @@ describe("FiberHandle", () => { onlyIfMissing: true }) yield* _(Effect.yieldNow()) - assert.strictEqual(yield* _(Ref.get(ref)), 1) + strictEqual(yield* _(Ref.get(ref)), 1) }), Effect.scoped ) - assert.strictEqual(yield* _(Ref.get(ref)), 2) + strictEqual(yield* _(Ref.get(ref)), 2) })) it.scoped("join", () => @@ -48,7 +48,7 @@ describe("FiberHandle", () => { FiberHandle.unsafeSet(handle, Effect.runFork(Effect.void)) FiberHandle.unsafeSet(handle, Effect.runFork(Effect.fail("fail"))) const result = yield* _(FiberHandle.join(handle), Effect.flip) - assert.strictEqual(result, "fail") + strictEqual(result, "fail") })) it.scoped("onlyIfMissing", () => @@ -58,9 +58,9 @@ describe("FiberHandle", () => { const fiberB = yield* _(FiberHandle.run(handle, Effect.never, { onlyIfMissing: true })) const fiberC = yield* _(FiberHandle.run(handle, Effect.never, { onlyIfMissing: true })) yield* _(Effect.yieldNow()) - assert.isTrue(Exit.isInterrupted(yield* _(fiberB.await))) - assert.isTrue(Exit.isInterrupted(yield* _(fiberC.await))) - assert.strictEqual(fiberA.unsafePoll(), null) + assertTrue(Exit.isInterrupted(yield* _(fiberB.await))) + assertTrue(Exit.isInterrupted(yield* _(fiberC.await))) + strictEqual(fiberA.unsafePoll(), null) })) it.scoped("runtime onlyIfMissing", () => @@ -70,9 +70,9 @@ describe("FiberHandle", () => { const fiberB = run(Effect.never, { onlyIfMissing: true }) const fiberC = run(Effect.never, { onlyIfMissing: true }) yield* _(Effect.yieldNow()) - assert.isTrue(Exit.isInterrupted(yield* _(fiberB.await))) - assert.isTrue(Exit.isInterrupted(yield* _(fiberC.await))) - assert.strictEqual(fiberA.unsafePoll(), null) + assertTrue(Exit.isInterrupted(yield* _(fiberB.await))) + assertTrue(Exit.isInterrupted(yield* _(fiberC.await))) + strictEqual(fiberA.unsafePoll(), null) })) it.scoped("propagateInterruption: false", () => @@ -83,7 +83,7 @@ describe("FiberHandle", () => { }) yield* Effect.yieldNow() yield* Fiber.interrupt(fiber) - assert.isFalse(yield* Deferred.isDone(handle.deferred)) + assertFalse(yield* Deferred.isDone(handle.deferred)) })) it.scoped("propagateInterruption: true", () => @@ -94,7 +94,7 @@ describe("FiberHandle", () => { }) yield* Effect.yieldNow() yield* Fiber.interrupt(fiber) - assert.isTrue(Exit.isInterrupted( + assertTrue(Exit.isInterrupted( yield* FiberHandle.join(handle).pipe( Effect.exit ) diff --git a/packages/effect/test/FiberMap.test.ts b/packages/effect/test/FiberMap.test.ts index c0453ef452e..45c5ede1a0f 100644 --- a/packages/effect/test/FiberMap.test.ts +++ b/packages/effect/test/FiberMap.test.ts @@ -1,7 +1,7 @@ -import { Array, Deferred, Effect, Exit, Fiber, Ref, Scope } from "effect" -import * as FiberMap from "effect/FiberMap" +import { Array, Deferred, Effect, Exit, Fiber, FiberMap, Ref, Scope } from "effect" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("FiberMap", () => { it.effect("interrupts fibers", () => @@ -24,7 +24,7 @@ describe("FiberMap", () => { Effect.scoped ) - assert.strictEqual(yield* _(Ref.get(ref)), 10) + strictEqual(yield* _(Ref.get(ref)), 10) })) it.effect("runtime", () => @@ -48,7 +48,7 @@ describe("FiberMap", () => { Effect.scoped ) - assert.strictEqual(yield* _(Ref.get(ref)), 10) + strictEqual(yield* _(Ref.get(ref)), 10) })) it.scoped("join", () => @@ -59,7 +59,7 @@ describe("FiberMap", () => { FiberMap.unsafeSet(map, "c", Effect.runFork(Effect.fail("fail"))) FiberMap.unsafeSet(map, "d", Effect.runFork(Effect.fail("ignored"))) const result = yield* _(FiberMap.join(map), Effect.flip) - assert.strictEqual(result, "fail") + strictEqual(result, "fail") })) it.effect("size", () => @@ -68,9 +68,9 @@ describe("FiberMap", () => { const set = yield* _(FiberMap.make(), Scope.extend(scope)) FiberMap.unsafeSet(set, "a", Effect.runFork(Effect.never)) FiberMap.unsafeSet(set, "b", Effect.runFork(Effect.never)) - assert.strictEqual(yield* _(FiberMap.size(set)), 2) + strictEqual(yield* _(FiberMap.size(set)), 2) yield* _(Scope.close(scope, Exit.void)) - assert.strictEqual(yield* _(FiberMap.size(set)), 0) + strictEqual(yield* _(FiberMap.size(set)), 0) })) it.scoped("onlyIfMissing", () => @@ -80,9 +80,9 @@ describe("FiberMap", () => { const fiberB = yield* _(FiberMap.run(handle, "a", Effect.never, { onlyIfMissing: true })) const fiberC = yield* _(FiberMap.run(handle, "a", Effect.never, { onlyIfMissing: true })) yield* _(Effect.yieldNow()) - assert.isTrue(Exit.isInterrupted(yield* _(fiberB.await))) - assert.isTrue(Exit.isInterrupted(yield* _(fiberC.await))) - assert.strictEqual(fiberA.unsafePoll(), null) + assertTrue(Exit.isInterrupted(yield* _(fiberB.await))) + assertTrue(Exit.isInterrupted(yield* _(fiberC.await))) + strictEqual(fiberA.unsafePoll(), null) })) it.scoped("runtime onlyIfMissing", () => @@ -92,9 +92,9 @@ describe("FiberMap", () => { const fiberB = run("a", Effect.never, { onlyIfMissing: true }) const fiberC = run("a", Effect.never, { onlyIfMissing: true }) yield* _(Effect.yieldNow()) - assert.isTrue(Exit.isInterrupted(yield* _(fiberB.await))) - assert.isTrue(Exit.isInterrupted(yield* _(fiberC.await))) - assert.strictEqual(fiberA.unsafePoll(), null) + assertTrue(Exit.isInterrupted(yield* _(fiberB.await))) + assertTrue(Exit.isInterrupted(yield* _(fiberC.await))) + strictEqual(fiberA.unsafePoll(), null) })) it.scoped("propagateInterruption false", () => @@ -105,7 +105,7 @@ describe("FiberMap", () => { }) yield* Effect.yieldNow() yield* Fiber.interrupt(fiber) - assert.isFalse(yield* Deferred.isDone(map.deferred)) + assertFalse(yield* Deferred.isDone(map.deferred)) })) it.scoped("propagateInterruption true", () => @@ -116,7 +116,7 @@ describe("FiberMap", () => { }) yield* Effect.yieldNow() yield* Fiber.interrupt(fiber) - assert.isTrue(Exit.isInterrupted( + assertTrue(Exit.isInterrupted( yield* FiberMap.join(map).pipe( Effect.exit ) diff --git a/packages/effect/test/FiberRef.test.ts b/packages/effect/test/FiberRef.test.ts index 41534de7431..6cda954fc0d 100644 --- a/packages/effect/test/FiberRef.test.ts +++ b/packages/effect/test/FiberRef.test.ts @@ -8,8 +8,9 @@ import * as FiberRef from "effect/FiberRef" import { constant, constTrue, identity } from "effect/Function" import * as Option from "effect/Option" import * as Runtime from "effect/Runtime" +import { assertTrue, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" const initial = "initial" const update = "update" @@ -28,45 +29,45 @@ describe("FiberRef", () => { Effect.gen(function*($) { const fiberRef = yield* $(FiberRef.make(initial)) const result = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(result, initial) + strictEqual(result, initial) })) it.scoped("get returns the correct value for a child", () => Effect.gen(function*($) { const fiberRef = yield* $(FiberRef.make(initial)) const fiber = yield* $(Effect.fork(FiberRef.get(fiberRef))) const result = yield* $(Fiber.join(fiber)) - assert.strictEqual(result, initial) + strictEqual(result, initial) })) it.scoped("getAndUpdate - changing the value", () => Effect.gen(function*($) { const fiberRef = yield* $(FiberRef.make(initial)) const value1 = yield* $(FiberRef.getAndUpdate(fiberRef, () => update)) const value2 = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(value1, initial) - assert.strictEqual(value2, update) + strictEqual(value1, initial) + strictEqual(value2, update) })) it.scoped("getAndUpdateSome - changing the value", () => Effect.gen(function*($) { const fiberRef = yield* $(FiberRef.make(initial)) const value1 = yield* $(FiberRef.getAndUpdateSome(fiberRef, () => Option.some(update))) const value2 = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(value1, initial) - assert.strictEqual(value2, update) + strictEqual(value1, initial) + strictEqual(value2, update) })) it.scoped("getAndUpdateSome - not changing value", () => Effect.gen(function*($) { const fiberRef = yield* $(FiberRef.make(initial)) const value1 = yield* $(FiberRef.getAndUpdateSome(fiberRef, () => Option.none())) const value2 = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(value1, initial) - assert.strictEqual(value2, initial) + strictEqual(value1, initial) + strictEqual(value2, initial) })) it.scoped("set updates the current value", () => Effect.gen(function*($) { const fiberRef = yield* $(FiberRef.make(initial)) yield* $(FiberRef.set(fiberRef, update)) const result = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(result, update) + strictEqual(result, update) })) it.scoped("set by a child doesn't update parent's value", () => Effect.gen(function*($) { @@ -80,47 +81,47 @@ describe("FiberRef", () => { ) yield* $(Deferred.await(deferred)) const result = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(result, initial) + strictEqual(result, initial) })) it.scoped("modify - changing the value", () => Effect.gen(function*($) { const fiberRef = yield* $(FiberRef.make(initial)) const value1 = yield* $(FiberRef.modify(fiberRef, () => [1, update])) const value2 = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(value1, 1) - assert.strictEqual(value2, update) + strictEqual(value1, 1) + strictEqual(value2, update) })) it.scoped("modifySome - not changing the value", () => Effect.gen(function*($) { const fiberRef = yield* $(FiberRef.make(initial)) const value1 = yield* $(FiberRef.modifySome(fiberRef, 2, () => Option.none())) const value2 = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(value1, 2) - assert.strictEqual(value2, initial) + strictEqual(value1, 2) + strictEqual(value2, initial) })) it.scoped("updateAndGet - changing the value", () => Effect.gen(function*($) { const fiberRef = yield* $(FiberRef.make(initial)) const value1 = yield* $(FiberRef.updateAndGet(fiberRef, () => update)) const value2 = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(value1, update) - assert.strictEqual(value2, update) + strictEqual(value1, update) + strictEqual(value2, update) })) it.scoped("updateSomeAndGet - changing the value", () => Effect.gen(function*($) { const fiberRef = yield* $(FiberRef.make(initial)) const value1 = yield* $(FiberRef.updateSomeAndGet(fiberRef, () => Option.some(update))) const value2 = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(value1, update) - assert.strictEqual(value2, update) + strictEqual(value1, update) + strictEqual(value2, update) })) it.scoped("updateSomeAndGet - not changing the value", () => Effect.gen(function*($) { const fiberRef = yield* $(FiberRef.make(initial)) const value1 = yield* $(FiberRef.updateSomeAndGet(fiberRef, () => Option.none())) const value2 = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(value1, initial) - assert.strictEqual(value2, initial) + strictEqual(value1, initial) + strictEqual(value2, initial) })) it.scoped("restores the original value", () => Effect.gen(function*($) { @@ -128,15 +129,15 @@ describe("FiberRef", () => { yield* $(FiberRef.set(fiberRef, update)) yield* $(FiberRef.delete(fiberRef)) const result = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(result, initial) + strictEqual(result, initial) })) it.scoped("locally - restores original value", () => Effect.gen(function*($) { const fiberRef = yield* $(FiberRef.make(initial)) const local = yield* $(Effect.locally(fiberRef, update)(FiberRef.get(fiberRef))) const value = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(local, update) - assert.strictEqual(value, initial) + strictEqual(local, update) + strictEqual(value, initial) })) it.scoped("locally - restores parent's value", () => Effect.gen(function*($) { @@ -144,8 +145,8 @@ describe("FiberRef", () => { const child = yield* $(Effect.locally(fiberRef, update)(FiberRef.get(fiberRef).pipe(Effect.fork))) const local = yield* $(Fiber.join(child)) const value = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(local, update) - assert.strictEqual(value, initial) + strictEqual(local, update) + strictEqual(value, initial) })) it.scoped("locally - restores undefined value", () => Effect.gen(function*($) { @@ -155,8 +156,8 @@ describe("FiberRef", () => { const fiberRef = yield* $(Fiber.await(child), Effect.flatten) const localValue = yield* $(Effect.locally(fiberRef, update)(FiberRef.get(fiberRef))) const value = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(localValue, update) - assert.strictEqual(value, initial) + strictEqual(localValue, update) + strictEqual(value, initial) })) it.scoped("initial value is inherited on join", () => Effect.gen(function*($) { @@ -164,14 +165,14 @@ describe("FiberRef", () => { const child = yield* $(Effect.fork(FiberRef.set(fiberRef, update))) yield* $(Fiber.join(child)) const result = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(result, update) + strictEqual(result, update) })) it.scoped("initial value is always available", () => Effect.gen(function*($) { const child = yield* $(Effect.fork(FiberRef.make(initial))) const fiberRef = yield* $(Fiber.await(child), Effect.flatten) const result = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(result, initial) + strictEqual(result, initial) })) it.scoped("fork function is applied on fork - 1", () => Effect.gen(function*($) { @@ -179,7 +180,7 @@ describe("FiberRef", () => { const child = yield* $(Effect.fork(Effect.void)) yield* $(Fiber.join(child)) const result = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.scoped("fork function is applied on fork - 2", () => Effect.gen(function*($) { @@ -187,7 +188,7 @@ describe("FiberRef", () => { const child = yield* $(Effect.void, Effect.fork, Effect.flatMap(Fiber.join), Effect.fork) yield* $(Fiber.join(child)) const result = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(result, 2) + strictEqual(result, 2) })) it.scoped("join function is applied on join - 1", () => Effect.gen(function*($) { @@ -195,7 +196,7 @@ describe("FiberRef", () => { const child = yield* $(Effect.fork(FiberRef.update(fiberRef, increment))) yield* $(Fiber.join(child)) const result = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.scoped("join function is applied on join - 2", () => Effect.gen(function*($) { @@ -204,7 +205,7 @@ describe("FiberRef", () => { yield* $(FiberRef.update(fiberRef, (n) => n + 2)) yield* $(Fiber.join(child)) const result = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(result, 2) + strictEqual(result, 2) })) it.scopedLive("the value of the loser is inherited in zipPar", () => Effect.gen(function*($) { @@ -217,7 +218,7 @@ describe("FiberRef", () => { ) yield* $(winner, Effect.zip(loser, { concurrent: true })) const result = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(result, update2) + strictEqual(result, update2) })) it.scoped("nothing gets inherited with a failure in zipPar", () => Effect.gen(function*($) { @@ -231,7 +232,7 @@ describe("FiberRef", () => { Effect.orElse(() => Effect.void) ) const result = yield* $(FiberRef.get(fiberRef)) - assert.isTrue(result.includes(initial)) + assertTrue(result.includes(initial)) })) it.scoped("the value of all fibers in inherited when running many effects with collectAllPar", () => Effect.gen(function*($) { @@ -245,14 +246,14 @@ describe("FiberRef", () => { discard: true })) const result = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(result, n) + strictEqual(result, n) })) it.scoped("its value is inherited after simple race", () => Effect.gen(function*($) { const fiberRef = yield* $(FiberRef.make(initial)) yield* $(FiberRef.set(fiberRef, update1), Effect.race(FiberRef.set(fiberRef, update2))) const result = yield* $(FiberRef.get(fiberRef)) - assert.isTrue(new RegExp(`${update1}|${update2}`).test(result)) + assertTrue(new RegExp(`${update1}|${update2}`).test(result)) })) it.scopedLive("its value is inherited after a race with a bad winner", () => Effect.gen(function*($) { @@ -267,7 +268,7 @@ describe("FiberRef", () => { ) yield* $(badWinner, Effect.race(goodLoser)) const result = yield* $(FiberRef.get(fiberRef)) - assert.equal(result, update2) + strictEqual(result, update2) })) it.scoped("its value is not inherited after a race of losers", () => Effect.gen(function*($) { @@ -276,14 +277,14 @@ describe("FiberRef", () => { const loser2 = FiberRef.set(fiberRef, update2).pipe(Effect.zipRight(Effect.fail("ups2"))) yield* $(loser1, Effect.race(loser2), Effect.ignore) const result = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(result, initial) + strictEqual(result, initial) })) it.scoped("its value is inherited in a trivial race", () => Effect.gen(function*($) { const fiberRef = yield* $(FiberRef.make(initial)) yield* $(Effect.raceAll([FiberRef.set(fiberRef, update)])) const result = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(result, update) + strictEqual(result, update) })) it.scoped("the value of the winner is inherited when racing two effects with raceAll", () => Effect.gen(function*($) { @@ -302,8 +303,8 @@ describe("FiberRef", () => { const loser2 = FiberRef.set(fiberRef, update2).pipe(Effect.zipRight(Effect.fail(":-O"))) yield* $(Effect.raceAll([loser2, winner2])) const value2 = yield* $(FiberRef.get(fiberRef), Effect.zipLeft(FiberRef.set(fiberRef, initial))) - assert.strictEqual(value1, update1) - assert.strictEqual(value2, update1) + strictEqual(value1, update1) + strictEqual(value2, update1) })) it.scoped("the value of the winner is inherited when racing many effects with raceAll", () => Effect.gen(function*($) { @@ -325,8 +326,8 @@ describe("FiberRef", () => { const losers2 = FiberRef.set(fiberRef, update1).pipe(Effect.zipRight(Effect.fail(":-O")), Effect.replicate(n)) yield* $(Chunk.unsafeFromArray(losers2), Chunk.prepend(winner2), Effect.raceAll) const value2 = yield* $(FiberRef.get(fiberRef), Effect.zipLeft(FiberRef.set(fiberRef, initial))) - assert.strictEqual(value1, update1) - assert.strictEqual(value2, update1) + strictEqual(value1, update1) + strictEqual(value2, update1) })) it.scoped("nothing gets inherited when racing failures with raceAll", () => Effect.gen(function*($) { @@ -334,7 +335,7 @@ describe("FiberRef", () => { const loser = FiberRef.set(fiberRef, update).pipe(Effect.zipRight(Effect.fail("darn"))) yield* $(Effect.raceAll([loser, ...Array.from({ length: 63 }, () => loser)]), Effect.orElse(() => Effect.void)) const result = yield* $(FiberRef.get(fiberRef)) - assert.strictEqual(result, initial) + strictEqual(result, initial) })) it.scoped("fork patch is applied when a fiber is unsafely run", () => Effect.gen(function*($) { @@ -347,7 +348,7 @@ describe("FiberRef", () => { Effect.sync(() => FiberRef.get(fiberRef).pipe(Effect.intoDeferred(deferred), Runtime.runCallback(runtime))) ) const result = yield* $(Deferred.await(deferred)) - assert.isTrue(result) + assertTrue(result) })) it.scoped("fork patch is applied when a fiber is unsafely forked", () => Effect.gen(function*($) { @@ -359,12 +360,12 @@ describe("FiberRef", () => { ) yield* $(Fiber.join(fiber)) const result = yield* $(Deferred.await(deferred)) - assert.isTrue(result) + assertTrue(result) })) it.scoped("is subtype of Effect", () => Effect.gen(function*() { const fiberRef = yield* FiberRef.make(initial) const result = yield* fiberRef - assert.strictEqual(result, initial) + strictEqual(result, initial) })) }) diff --git a/packages/effect/test/FiberRefs.test.ts b/packages/effect/test/FiberRefs.test.ts index 278174f52c6..a9725424dc6 100644 --- a/packages/effect/test/FiberRefs.test.ts +++ b/packages/effect/test/FiberRefs.test.ts @@ -9,8 +9,9 @@ import * as HashMap from "effect/HashMap" import * as Option from "effect/Option" import * as Queue from "effect/Queue" import * as Scope from "effect/Scope" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe, expect } from "vitest" +import { describe } from "vitest" describe("FiberRefs", () => { it.scoped("propagate FiberRef values across fiber boundaries", () => @@ -30,7 +31,7 @@ describe("FiberRefs", () => { ) yield* $(Fiber.join(producer)) const result = yield* $(Fiber.join(consumer)) - assert.isTrue(result) + assertTrue(result) })) it.it("interruptedCause", () => { const parent = FiberId.make(1, Date.now()) as FiberId.Runtime @@ -42,25 +43,25 @@ describe("FiberRefs", () => { value: Cause.interrupt(parent) }) const newParentFiberRefs = FiberRefs.joinAs(parentFiberRefs, parent, childFiberRefs) - assert.deepStrictEqual(FiberRefs.get(newParentFiberRefs, FiberRef.interruptedCause), Option.some(Cause.empty)) + deepStrictEqual(FiberRefs.get(newParentFiberRefs, FiberRef.interruptedCause), Option.some(Cause.empty)) }) describe("currentLogAnnotations", () => { it.it("doesnt leak", () => { Effect.void.pipe(Effect.annotateLogs("test", "abc"), Effect.runSync) - expect(FiberRef.currentLogAnnotations.pipe(FiberRef.get, Effect.map(HashMap.size), Effect.runSync)).toBe(0) + strictEqual(FiberRef.currentLogAnnotations.pipe(FiberRef.get, Effect.map(HashMap.size), Effect.runSync), 0) }) it.effect("annotateLogsScoped", () => Effect.gen(function*() { const scope = yield* Scope.make() - assert.strictEqual(HashMap.size(yield* FiberRef.get(FiberRef.currentLogAnnotations)), 0) + strictEqual(HashMap.size(yield* FiberRef.get(FiberRef.currentLogAnnotations)), 0) yield* Effect.annotateLogsScoped({ test: 123 }).pipe(Scope.extend(scope)) - assert.strictEqual(HashMap.size(yield* FiberRef.get(FiberRef.currentLogAnnotations)), 1) + strictEqual(HashMap.size(yield* FiberRef.get(FiberRef.currentLogAnnotations)), 1) yield* Scope.close(scope, Exit.void) - assert.strictEqual(HashMap.size(yield* FiberRef.get(FiberRef.currentLogAnnotations)), 0) + strictEqual(HashMap.size(yield* FiberRef.get(FiberRef.currentLogAnnotations)), 0) })) }) }) diff --git a/packages/effect/test/FiberSet.test.ts b/packages/effect/test/FiberSet.test.ts index 84ead23be50..a3dba8bf2f1 100644 --- a/packages/effect/test/FiberSet.test.ts +++ b/packages/effect/test/FiberSet.test.ts @@ -1,7 +1,7 @@ -import { Array, Deferred, Effect, Exit, Fiber, Ref, Scope } from "effect" -import * as FiberSet from "effect/FiberSet" +import { Array, Deferred, Effect, Exit, Fiber, FiberSet, Ref, Scope } from "effect" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("FiberSet", () => { it.effect("interrupts fibers", () => @@ -22,7 +22,7 @@ describe("FiberSet", () => { Effect.scoped ) - assert.strictEqual(yield* _(Ref.get(ref)), 10) + strictEqual(yield* _(Ref.get(ref)), 10) })) it.effect("runtime", () => @@ -45,7 +45,7 @@ describe("FiberSet", () => { Effect.scoped ) - assert.strictEqual(yield* _(Ref.get(ref)), 10) + strictEqual(yield* _(Ref.get(ref)), 10) })) it.scoped("join", () => @@ -55,7 +55,7 @@ describe("FiberSet", () => { FiberSet.unsafeAdd(set, Effect.runFork(Effect.void)) FiberSet.unsafeAdd(set, Effect.runFork(Effect.fail("fail"))) const result = yield* _(FiberSet.join(set), Effect.flip) - assert.strictEqual(result, "fail") + strictEqual(result, "fail") })) it.effect("size", () => @@ -64,9 +64,9 @@ describe("FiberSet", () => { const set = yield* _(FiberSet.make(), Scope.extend(scope)) FiberSet.unsafeAdd(set, Effect.runFork(Effect.never)) FiberSet.unsafeAdd(set, Effect.runFork(Effect.never)) - assert.strictEqual(yield* _(FiberSet.size(set)), 2) + strictEqual(yield* _(FiberSet.size(set)), 2) yield* _(Scope.close(scope, Exit.void)) - assert.strictEqual(yield* _(FiberSet.size(set)), 0) + strictEqual(yield* _(FiberSet.size(set)), 0) })) it.scoped("propagateInterruption false", () => @@ -77,7 +77,7 @@ describe("FiberSet", () => { }) yield* Effect.yieldNow() yield* Fiber.interrupt(fiber) - assert.isFalse(yield* Deferred.isDone(set.deferred)) + assertFalse(yield* Deferred.isDone(set.deferred)) })) it.scoped("propagateInterruption true", () => @@ -88,7 +88,7 @@ describe("FiberSet", () => { }) yield* Effect.yieldNow() yield* Fiber.interrupt(fiber) - assert.isTrue(Exit.isInterrupted( + assertTrue(Exit.isInterrupted( yield* FiberSet.join(set).pipe( Effect.exit ) diff --git a/packages/effect/test/Function.test.ts b/packages/effect/test/Function.test.ts index 47ab6cb45a2..40425ff4d80 100644 --- a/packages/effect/test/Function.test.ts +++ b/packages/effect/test/Function.test.ts @@ -1,10 +1,9 @@ -import * as Function from "effect/Function" -import * as String from "effect/String" -import { deepStrictEqual, double } from "effect/test/util" -import { assert, describe, expect, it } from "vitest" +import { Function, String } from "effect" +import { deepStrictEqual, strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" const f = (n: number): number => n + 1 -const g = double +const g = (n: number) => n * 2 describe("Function", () => { it("apply", () => { @@ -12,8 +11,8 @@ describe("Function", () => { }) it("compose", () => { - deepStrictEqual(Function.pipe(String.length, Function.compose(double))("aaa"), 6) - deepStrictEqual(Function.compose(String.length, double)("aaa"), 6) + deepStrictEqual(Function.pipe(String.length, Function.compose((n) => n * 2))("aaa"), 6) + deepStrictEqual(Function.compose(String.length, (n) => n * 2)("aaa"), 6) }) it("flip", () => { @@ -59,15 +58,15 @@ describe("Function", () => { }) it("absurd", () => { - assert.throws(() => Function.absurd(null as any as never)) + throws(() => Function.absurd(null as any as never)) }) it("hole", () => { - assert.throws(() => Function.hole()) + throws(() => Function.hole()) }) it("SK", () => { - expect(Function.SK(1, 2)).toEqual(2) + strictEqual(Function.SK(1, 2), 2) }) it("tupled", () => { @@ -144,21 +143,19 @@ describe("Function", () => { }) it("arity: 0", () => { - expect(() => + throws(() => Function.dual< () => () => number, () => number - >(0, (): number => 2) - ).toThrow(new RangeError("Invalid arity 0")) + >(0, (): number => 2), new RangeError("Invalid arity 0")) }) it("arity: 1", () => { - expect(() => + throws(() => Function.dual< () => (self: number) => number, (self: number) => number - >(1, (self: number): number => self * 2) - ).toThrow(new RangeError("Invalid arity 1")) + >(1, (self: number): number => self * 2), new RangeError("Invalid arity 1")) }) it("arity: 2", () => { diff --git a/packages/effect/test/GlobalValue.test.ts b/packages/effect/test/GlobalValue.test.ts index e1604ac1015..83411351955 100644 --- a/packages/effect/test/GlobalValue.test.ts +++ b/packages/effect/test/GlobalValue.test.ts @@ -1,11 +1,12 @@ import * as G from "effect/GlobalValue" -import { assert, describe, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" const a = G.globalValue("id", () => ({})) const b = G.globalValue("id", () => ({})) describe("GlobalValue", () => { it("should give the same value when invoked with the same id", () => { - assert.strictEqual(a, b) + strictEqual(a, b) }) }) diff --git a/packages/effect/test/Hash.test.ts b/packages/effect/test/Hash.test.ts index 3da943e6215..1e6368b518c 100644 --- a/packages/effect/test/Hash.test.ts +++ b/packages/effect/test/Hash.test.ts @@ -3,82 +3,78 @@ import { absurd, identity } from "effect/Function" import * as Hash from "effect/Hash" import * as HashSet from "effect/HashSet" import * as Option from "effect/Option" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" import * as Utils from "effect/Utils" -import { describe, expect, it } from "vitest" +import { describe, it } from "vitest" describe("Hash", () => { it("structural", () => { const a = { foo: { bar: "ok", baz: { arr: [0, 1, 2] } } } const b = { foo: { bar: "ok", baz: { arr: [0, 1, 2] } } } - expect(Hash.hash(a)).not.toBe(Hash.hash(b)) - expect(Equal.equals(a, b)).toBe(false) + assertTrue(Hash.hash(a) !== Hash.hash(b)) + assertFalse(Equal.equals(a, b)) Utils.structuralRegion(() => { - expect(Hash.hash(a)).toBe(Hash.hash(b)) - expect(Equal.equals(a, b)).toBe(true) + strictEqual(Hash.hash(a), Hash.hash(b)) + assertTrue(Equal.equals(a, b)) }) - expect(Hash.hash(a)).not.toBe(Hash.hash(b)) - expect(Equal.equals(a, b)).toBe(false) + assertTrue(Hash.hash(a) !== Hash.hash(b)) + assertFalse(Equal.equals(a, b)) }) it("structural cached", () => { const a = Option.some({ foo: { bar: "ok", baz: { arr: [0, 1, 2] } } }) const b = Option.some({ foo: { bar: "ok", baz: { arr: [0, 1, 2] } } }) - expect(Hash.hash(a)).not.toBe(Hash.hash(b)) - expect(Equal.equals(a, b)).toBe(false) + assertTrue(Hash.hash(a) !== Hash.hash(b)) + assertFalse(Equal.equals(a, b)) Utils.structuralRegion(() => { - expect(Hash.hash(a)).toBe(Hash.hash(b)) - expect(Equal.equals(a, b)).toBe(true) + strictEqual(Hash.hash(a), Hash.hash(b)) + assertTrue(Equal.equals(a, b)) }) - expect(Hash.hash(a)).not.toBe(Hash.hash(b)) - expect(Equal.equals(a, b)).toBe(false) - }) - it("exports", () => { - expect(Hash.string).exist - expect(Hash.structureKeys).exist - expect(Hash.random).exist + assertTrue(Hash.hash(a) !== Hash.hash(b)) + assertFalse(Equal.equals(a, b)) }) it("number", () => { const set: HashSet.HashSet = HashSet.make(Infinity) - expect(HashSet.has(set, Infinity)).toBe(true) - expect(HashSet.has(set, -Infinity)).toBe(false) - expect(Hash.number(0.1)).not.toBe(Hash.number(0)) + assertTrue(HashSet.has(set, Infinity)) + assertFalse(HashSet.has(set, -Infinity)) + assertTrue(Hash.number(0.1) !== Hash.number(0)) }) it("bigint", () => { const set = HashSet.make(1n) - expect(HashSet.has(set, 1n)).toBe(true) - expect(HashSet.has(set, 2n)).toBe(false) + assertTrue(HashSet.has(set, 1n)) + assertFalse(HashSet.has(set, 2n)) }) it("symbol", () => { const a = Symbol.for("effect/test/Hash/a") const b = Symbol.for("effect/test/Hash/b") const set: HashSet.HashSet = HashSet.make(a) - expect(HashSet.has(set, a)).toBe(true) - expect(HashSet.has(set, b)).toBe(false) + assertTrue(HashSet.has(set, a)) + assertFalse(HashSet.has(set, b)) }) it("undefined", () => { const set: HashSet.HashSet = HashSet.make(1, undefined) - expect(HashSet.has(set, undefined)).toBe(true) - expect(HashSet.has(set, 2)).toBe(false) + assertTrue(HashSet.has(set, undefined)) + assertFalse(HashSet.has(set, 2)) }) it("null", () => { const set: HashSet.HashSet = HashSet.make(1, null) - expect(HashSet.has(set, null)).toBe(true) - expect(HashSet.has(set, 2)).toBe(false) + assertTrue(HashSet.has(set, null)) + assertFalse(HashSet.has(set, 2)) }) it("function", () => { const set: HashSet.HashSet = HashSet.make(identity) - expect(HashSet.has(set, identity)).toBe(true) - expect(HashSet.has(set, absurd)).toBe(false) + assertTrue(HashSet.has(set, identity)) + assertFalse(HashSet.has(set, absurd)) }) it("isHash", () => { - expect(Hash.isHash(HashSet.empty())).toBe(true) - expect(Hash.isHash(null)).toBe(false) - expect(Hash.isHash({})).toBe(false) + assertTrue(Hash.isHash(HashSet.empty())) + assertFalse(Hash.isHash(null)) + assertFalse(Hash.isHash({})) }) }) diff --git a/packages/effect/test/HashMap.test.ts b/packages/effect/test/HashMap.test.ts index 98b760d2fa3..86b579fdbd0 100644 --- a/packages/effect/test/HashMap.test.ts +++ b/packages/effect/test/HashMap.test.ts @@ -3,8 +3,8 @@ import { pipe } from "effect/Function" import * as Hash from "effect/Hash" import * as HM from "effect/HashMap" import * as Option from "effect/Option" -import { deepStrictEqual } from "effect/test/util" -import { assert, describe, expect, it } from "vitest" +import { assertFalse, assertNone, assertSome, assertTrue, deepStrictEqual, strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" class Key implements Equal.Equal { constructor(readonly n: number) {} @@ -41,14 +41,16 @@ describe("HashMap", () => { it("option", () => { const map = HM.make([Option.some(1), 0], [Option.none(), 1]) - expect(pipe(map, HM.has(Option.none()))).toBe(true) - expect(pipe(map, HM.has(Option.some(1)))).toBe(true) - expect(pipe(map, HM.has(Option.some(2)))).toBe(false) + assertTrue(pipe(map, HM.has(Option.none()))) + assertTrue(pipe(map, HM.has(Option.some(1)))) + assertFalse(pipe(map, HM.has(Option.some(2)))) }) it("toString", () => { const map = HM.make([0, "a"]) - expect(String(map)).toEqual(`{ + strictEqual( + String(map), + `{ "_id": "HashMap", "values": [ [ @@ -56,12 +58,13 @@ describe("HashMap", () => { "a" ] ] -}`) +}` + ) }) it("toJSON", () => { const map = HM.make([0, "a"]) - expect(map.toJSON()).toEqual({ _id: "HashMap", values: [[0, "a"]] }) + deepStrictEqual(map.toJSON(), { _id: "HashMap", values: [[0, "a"]] }) }) it("inspect", () => { @@ -69,51 +72,52 @@ describe("HashMap", () => { // eslint-disable-next-line @typescript-eslint/no-var-requires const { inspect } = require("node:util") const map = HM.make([0, "a"]) - expect(inspect(map)).toEqual(inspect({ _id: "HashMap", values: [[0, "a"]] })) + deepStrictEqual(inspect(map), inspect({ _id: "HashMap", values: [[0, "a"]] })) } }) it("has", () => { const map = HM.make([key(0), value("a")]) - assert.isTrue(HM.has(key(0))(map)) - assert.isFalse(HM.has(key(1))(map)) + assertTrue(HM.has(key(0))(map)) + assertFalse(HM.has(key(1))(map)) }) it("hasHash", () => { const map = HM.make([key(0), value("a")]) - assert.isTrue(HM.hasHash(key(0), Hash.hash(key(0)))(map)) - assert.isFalse(HM.hasHash(key(1), Hash.hash(key(0)))(map)) + assertTrue(HM.hasHash(key(0), Hash.hash(key(0)))(map)) + assertFalse(HM.hasHash(key(1), Hash.hash(key(0)))(map)) }) it("get", () => { const map = HM.make([key(0), value("a")]) - deepStrictEqual(HM.get(key(0))(map), Option.some(value("a"))) - deepStrictEqual(HM.get(key(1))(map), Option.none()) + assertSome(HM.get(key(0))(map), value("a")) + assertNone(HM.get(key(1))(map)) }) it("getHash", () => { const map = HM.make([key(0), value("a")]) - deepStrictEqual(HM.getHash(key(0), Hash.hash(0))(map), Option.some(value("a"))) - deepStrictEqual(HM.getHash(key(1), Hash.hash(0))(map), Option.none()) + assertSome(HM.getHash(key(0), Hash.hash(0))(map), value("a")) + assertNone(HM.getHash(key(1), Hash.hash(0))(map)) }) it("set", () => { const map = pipe(HM.empty(), HM.set(key(0), value("a"))) - deepStrictEqual(HM.get(key(0))(map), Option.some(value("a"))) + assertSome(HM.get(key(0))(map), value("a")) }) it("mutation", () => { - let map = HM.empty() - assert.propertyVal(map, "_editable", false) + let map: any = HM.empty() + + assertFalse(map._editable) map = HM.beginMutation(map) - assert.propertyVal(map, "_editable", true) + assertTrue(map._editable) map = HM.endMutation(map) - assert.propertyVal(map, "_editable", false) + assertFalse(map._editable) }) it("mutate", () => { @@ -125,8 +129,8 @@ describe("HashMap", () => { }) ) - deepStrictEqual(HM.get(0)(result), Option.some("a")) - deepStrictEqual(HM.get(1)(result), Option.none()) + assertSome(HM.get(0)(result), "a") + assertNone(HM.get(1)(result)) }) it("flatMap", () => { @@ -140,9 +144,9 @@ describe("HashMap", () => { }) ) - deepStrictEqual(HM.get(key(1))(result1), Option.some(value("a"))) - deepStrictEqual(HM.get(key(2))(result1), Option.some(value("bb"))) - deepStrictEqual(HM.get(key(3))(result1), Option.none()) + assertSome(HM.get(key(1))(result1), value("a")) + assertSome(HM.get(key(2))(result1), value("bb")) + assertNone(HM.get(key(3))(result1)) const map2 = HM.make([key(1), value("a")], [key(2), value("bb")]) const result2 = pipe( @@ -154,9 +158,9 @@ describe("HashMap", () => { }) ) - deepStrictEqual(HM.get(key(2))(result2), Option.some(value("a"))) - deepStrictEqual(HM.get(key(4))(result2), Option.some(value("bb"))) - deepStrictEqual(HM.get(key(6))(result2), Option.none()) + assertSome(HM.get(key(2))(result2), value("a")) + assertSome(HM.get(key(4))(result2), value("bb")) + assertNone(HM.get(key(6))(result2)) }) it("filterMap", () => { @@ -166,8 +170,8 @@ describe("HashMap", () => { HM.filterMap(({ s }) => s.length > 1 ? Option.some(value(s)) : Option.none()) ) - deepStrictEqual(HM.get(key(0))(result1), Option.none()) - deepStrictEqual(HM.get(key(1))(result1), Option.some(value("bb"))) + assertNone(HM.get(key(0))(result1)) + assertSome(HM.get(key(1))(result1), value("bb")) const map2 = HM.make([key(0), value("a")], [key(1), value("bb")]) const result2 = pipe( @@ -175,30 +179,30 @@ describe("HashMap", () => { HM.filterMap((v, { n }) => n > 0 ? Option.some(v) : Option.none()) ) - deepStrictEqual(HM.get(key(0))(result2), Option.none()) - deepStrictEqual(HM.get(key(1))(result2), Option.some(value("bb"))) + assertNone(HM.get(key(0))(result2)) + assertSome(HM.get(key(1))(result2), value("bb")) }) it("compact", () => { const map = HM.make([0, Option.some("a")], [1, Option.none()]) const result = HM.compact(map) - assert.strictEqual(HM.unsafeGet(0)(result), "a") - assert.throws(() => HM.unsafeGet(1)(result)) + strictEqual(HM.unsafeGet(0)(result), "a") + throws(() => HM.unsafeGet(1)(result)) }) it("filter", () => { const map1 = HM.make([key(0), value("a")], [key(1), value("bb")]) const result1 = pipe(map1, HM.filter(({ s }) => s.length > 1)) - deepStrictEqual(HM.get(key(0))(result1), Option.none()) - deepStrictEqual(HM.get(key(1))(result1), Option.some(value("bb"))) + assertNone(HM.get(key(0))(result1)) + assertSome(HM.get(key(1))(result1), value("bb")) const map2 = HM.make([key(0), value("a")], [key(1), value("bb")]) const result2 = pipe(map2, HM.filter(({ s }, { n }) => n > 0 && s.length > 0)) - deepStrictEqual(HM.get(key(0))(result2), Option.none()) - deepStrictEqual(HM.get(key(1))(result2), Option.some(value("bb"))) + assertNone(HM.get(key(0))(result2)) + assertSome(HM.get(key(1))(result2), value("bb")) }) it("forEach", () => { @@ -226,24 +230,24 @@ describe("HashMap", () => { }) it("isEmpty", () => { - assert.isTrue(HM.isEmpty(HM.make())) - assert.isFalse(HM.isEmpty(HM.make([key(0), value("a")]))) + assertTrue(HM.isEmpty(HM.make())) + assertFalse(HM.isEmpty(HM.make([key(0), value("a")]))) }) it("map", () => { const map1 = HM.make([key(0), value("a")], [key(1), value("bb")]) const result1 = pipe(map1, HM.map(({ s }) => s.length)) - deepStrictEqual(HM.get(key(0))(result1), Option.some(1)) - deepStrictEqual(HM.get(key(1))(result1), Option.some(2)) - deepStrictEqual(HM.get(key(2))(result1), Option.none()) + assertSome(HM.get(key(0))(result1), 1) + assertSome(HM.get(key(1))(result1), 2) + assertNone(HM.get(key(2))(result1)) const map2 = HM.make([key(0), value("a")], [key(1), value("bb")]) const result2 = pipe(map2, HM.map(({ s }, { n }) => n + s.length)) - deepStrictEqual(HM.get(key(0))(result2), Option.some(1)) - deepStrictEqual(HM.get(key(1))(result2), Option.some(3)) - deepStrictEqual(HM.get(key(2))(result2), Option.none()) + assertSome(HM.get(key(0))(result2), 1) + assertSome(HM.get(key(1))(result2), 3) + assertNone(HM.get(key(2))(result2)) }) it("modifyAt", () => { @@ -256,16 +260,15 @@ describe("HashMap", () => { Option.none()) ) - deepStrictEqual(HM.get(key(0))(result), Option.some(value("test"))) - deepStrictEqual(HM.get(key(1))(result), Option.some(value("b"))) - deepStrictEqual(HM.get(key(2))(result), Option.none()) + assertSome(HM.get(key(0))(result), value("test")) + assertSome(HM.get(key(1))(result), value("b")) + assertNone(HM.get(key(2))(result)) - deepStrictEqual( + assertNone( HM.get(key(0))(pipe( map, HM.modifyAt(key(0), (): Option.Option => Option.none()) - )), - Option.none() + )) ) }) @@ -279,16 +282,16 @@ describe("HashMap", () => { Option.none()) ) - deepStrictEqual(HM.get(key(0))(result), Option.some(value("test"))) - deepStrictEqual(HM.get(key(1))(result), Option.some(value("b"))) - deepStrictEqual(HM.get(key(2))(result), Option.none()) + assertSome(HM.get(key(0))(result), value("test")) + assertSome(HM.get(key(1))(result), value("b")) + assertNone(HM.get(key(2))(result)) }) it("reduce", () => { const map1 = HM.make([key(0), value("a")], [key(1), value("b")]) const result1 = pipe(map1, HM.reduce("", (acc, { s }) => acc.length > 0 ? `${acc},${s}` : s)) - assert.strictEqual(result1, "a,b") + strictEqual(result1, "a,b") const map2 = HM.make([key(0), value("a")], [key(1), value("b")]) const result2 = pipe( @@ -299,15 +302,15 @@ describe("HashMap", () => { ) ) - assert.strictEqual(result2, "0:a,1:b") + strictEqual(result2, "0:a,1:b") }) it("remove", () => { const map = HM.make([key(0), value("a")], [key(1), value("b")]) const result = pipe(map, HM.remove(key(0))) - deepStrictEqual(HM.get(key(0))(result), Option.none()) - deepStrictEqual(HM.get(key(1))(result), Option.some(value("b"))) + assertNone(HM.get(key(0))(result)) + assertSome(HM.get(key(1))(result), value("b")) }) it("remove non existing key doesn't change the array", () => { @@ -321,15 +324,15 @@ describe("HashMap", () => { const map = HM.make([key(0), value("a")], [key(1), value("b")]) const result = pipe(map, HM.removeMany([key(0), key(1)])) - assert.isFalse(HM.isEmpty(map)) - assert.isTrue(HM.isEmpty(result)) + assertFalse(HM.isEmpty(map)) + assertTrue(HM.isEmpty(result)) }) it("size", () => { const map = HM.make([key(0), value("a")], [key(1), value("b")]) const result = HM.size(map) - assert.strictEqual(result, 2) + strictEqual(result, 2) }) it("union", () => { @@ -337,35 +340,22 @@ describe("HashMap", () => { const map2 = HM.make(["foo", true], ["bar", false]) const result = HM.union(map2)(map1) - deepStrictEqual( - pipe(result, HM.get(0)), - Option.some("a") - ) - deepStrictEqual( - pipe(result, HM.get(1)), - Option.some("b") - ) - deepStrictEqual( - pipe(result, HM.get("foo")), - Option.some(true) - ) - deepStrictEqual( - pipe(result, HM.get("bar")), - Option.some(false) - ) + assertSome(pipe(result, HM.get(0)), "a") + assertSome(pipe(result, HM.get(1)), "b") + assertSome(pipe(result, HM.get("foo")), true) + assertSome(pipe(result, HM.get("bar")), false) }) it("modify", () => { const map = HM.make([key(0), value("a")], [key(1), value("b")]) const result = pipe(map, HM.modify(key(0), ({ s }) => value(`${s}-${s}`))) - deepStrictEqual(HM.get(key(0))(result), Option.some(value("a-a"))) - deepStrictEqual(HM.get(key(1))(result), Option.some(value("b"))) - deepStrictEqual(HM.get(key(2))(result), Option.none()) + assertSome(HM.get(key(0))(result), value("a-a")) + assertSome(HM.get(key(1))(result), value("b")) + assertNone(HM.get(key(2))(result)) - deepStrictEqual( - HM.get(key(2))(pipe(map, HM.modify(key(2), ({ s }) => value(`${s}-${s}`)))), - Option.none() + assertNone( + HM.get(key(2))(pipe(map, HM.modify(key(2), ({ s }) => value(`${s}-${s}`)))) ) }) @@ -385,7 +375,7 @@ describe("HashMap", () => { const result = HM.keySet(hashMap) - assert.deepEqual([...result], [key(0), key(1)]) + deepStrictEqual([...result], [key(0), key(1)]) }) it("values", () => { @@ -410,19 +400,19 @@ describe("HashMap", () => { }) it("pipe()", () => { - expect(HM.empty().pipe(HM.set("key", "value"))).toEqual(HM.make(["key", "value"])) + strictEqual(HM.empty().pipe(HM.set("key", "value")).pipe(HM.size), HM.make(["key", "value"]).pipe(HM.size)) }) it("isHashMap", () => { - expect(HM.isHashMap(HM.empty())).toBe(true) - expect(HM.isHashMap(null)).toBe(false) - expect(HM.isHashMap({})).toBe(false) + assertTrue(HM.isHashMap(HM.empty())) + assertFalse(HM.isHashMap(null)) + assertFalse(HM.isHashMap({})) }) it("findFirst", () => { const map1 = HM.make([key(0), value("a")], [key(1), value("bb")]) - expect(HM.findFirst(map1, (_v, k) => k.n === 0)).toStrictEqual(Option.some([key(0), value("a")])) - expect(HM.findFirst(map1, (v, _k) => v.s === "bb")).toStrictEqual(Option.some([key(1), value("bb")])) - expect(HM.findFirst(map1, (v, k) => k.n === 0 && v.s === "bb")).toStrictEqual(Option.none()) + assertSome(HM.findFirst(map1, (_v, k) => k.n === 0), [key(0), value("a")]) + assertSome(HM.findFirst(map1, (v, _k) => v.s === "bb"), [key(1), value("bb")]) + assertNone(HM.findFirst(map1, (v, k) => k.n === 0 && v.s === "bb")) }) }) diff --git a/packages/effect/test/HashSet.test.ts b/packages/effect/test/HashSet.test.ts index 8add94634a6..65baefd49d9 100644 --- a/packages/effect/test/HashSet.test.ts +++ b/packages/effect/test/HashSet.test.ts @@ -2,8 +2,8 @@ import * as Equal from "effect/Equal" import { pipe } from "effect/Function" import * as Hash from "effect/Hash" import * as HashSet from "effect/HashSet" -import { deepStrictEqual } from "effect/test/util" -import { assert, describe, expect, it } from "vitest" +import { assertFalse, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" class Value implements Equal.Equal { constructor(readonly n: number) {} @@ -32,18 +32,21 @@ describe("HashSet", () => { it("toString", () => { const map = HashSet.make(0, "a") - expect(String(map)).toEqual(`{ + strictEqual( + String(map), + `{ "_id": "HashSet", "values": [ 0, "a" ] -}`) +}` + ) }) it("toJSON", () => { const map = HashSet.make(0, "a") - expect(map.toJSON()).toEqual({ _id: "HashSet", values: [0, "a"] }) + deepStrictEqual(map.toJSON(), { _id: "HashSet", values: [0, "a"] }) }) it("inspect", () => { @@ -53,7 +56,7 @@ describe("HashSet", () => { // eslint-disable-next-line @typescript-eslint/no-var-requires const { inspect } = require("node:util") const map = HashSet.make(0, "a") - expect(inspect(map)).toEqual(inspect({ _id: "HashSet", values: [0, "a"] })) + deepStrictEqual(inspect(map), inspect({ _id: "HashSet", values: [0, "a"] })) }) it("add", () => { @@ -63,12 +66,13 @@ describe("HashSet", () => { }) it("mutation", () => { - let set = HashSet.empty() - assert.nestedPropertyVal(set, "_keyMap._editable", false) + let set: any = HashSet.empty() + + assertFalse(set._keyMap._editable) set = HashSet.beginMutation(set) - assert.nestedPropertyVal(set, "_keyMap._editable", true) + assertTrue(set._keyMap._editable) set = HashSet.endMutation(set) - assert.nestedPropertyVal(set, "_keyMap._editable", false) + assertFalse(set._keyMap._editable) }) it("flatMap", () => { @@ -83,14 +87,14 @@ describe("HashSet", () => { const set2 = makeTestHashSet(2, 3, 4) const result = pipe(set1, HashSet.difference(set2)) - assert.isTrue(Equal.equals(result, HashSet.make(value(0), value(1)))) + assertTrue(Equal.equals(result, HashSet.make(value(0), value(1)))) }) it("every", () => { const set = makeTestHashSet(0, 1, 2) - assert.isTrue(pipe(set, HashSet.every(({ n }) => n >= 0))) - assert.isFalse(pipe(set, HashSet.every(({ n }) => n > 0))) + assertTrue(pipe(set, HashSet.every(({ n }) => n >= 0))) + assertFalse(pipe(set, HashSet.every(({ n }) => n > 0))) }) it("filter", () => { @@ -117,10 +121,10 @@ describe("HashSet", () => { it("has", () => { const set = makeTestHashSet(0, 1, 2) - assert.isTrue(pipe(set, HashSet.has(value(0)))) - assert.isTrue(pipe(set, HashSet.has(value(1)))) - assert.isTrue(pipe(set, HashSet.has(value(2)))) - assert.isFalse(pipe(set, HashSet.has(value(3)))) + assertTrue(pipe(set, HashSet.has(value(0)))) + assertTrue(pipe(set, HashSet.has(value(1)))) + assertTrue(pipe(set, HashSet.has(value(2)))) + assertFalse(pipe(set, HashSet.has(value(3)))) }) it("intersection", () => { @@ -136,8 +140,8 @@ describe("HashSet", () => { const set2 = makeTestHashSet(1, 2) const set3 = makeTestHashSet(0, 1, 2) - assert.isFalse(pipe(set1, HashSet.isSubset(set2))) - assert.isTrue(pipe(set1, HashSet.isSubset(set3))) + assertFalse(pipe(set1, HashSet.isSubset(set2))) + assertTrue(pipe(set1, HashSet.isSubset(set3))) }) it("map", () => { @@ -157,10 +161,10 @@ describe("HashSet", () => { }) ) - assert.isFalse(pipe(result, HashSet.has(value(0)))) - assert.isTrue(pipe(result, HashSet.has(value(1)))) - assert.isTrue(pipe(result, HashSet.has(value(2)))) - assert.isTrue(pipe(result, HashSet.has(value(3)))) + assertFalse(pipe(result, HashSet.has(value(0)))) + assertTrue(pipe(result, HashSet.has(value(1)))) + assertTrue(pipe(result, HashSet.has(value(2)))) + assertTrue(pipe(result, HashSet.has(value(3)))) }) it("partition", () => { @@ -175,32 +179,32 @@ describe("HashSet", () => { const set = makeTestHashSet(0, 1, 2) const result = pipe(set, HashSet.remove(value(0))) - assert.isFalse(pipe(result, HashSet.has(value(0)))) - assert.isTrue(pipe(result, HashSet.has(value(1)))) - assert.isTrue(pipe(result, HashSet.has(value(2)))) + assertFalse(pipe(result, HashSet.has(value(0)))) + assertTrue(pipe(result, HashSet.has(value(1)))) + assertTrue(pipe(result, HashSet.has(value(2)))) }) it("size", () => { const hashSet = makeTestHashSet(0, 1, 2) const result = HashSet.size(hashSet) - assert.strictEqual(result, 3) + strictEqual(result, 3) }) it("some", () => { const set = makeTestHashSet(0, 1, 2) - assert.isTrue(pipe(set, HashSet.some(({ n }) => n > 0))) - assert.isFalse(pipe(set, HashSet.some(({ n }) => n > 2))) + assertTrue(pipe(set, HashSet.some(({ n }) => n > 0))) + assertFalse(pipe(set, HashSet.some(({ n }) => n > 2))) }) it("toggle", () => { let set = makeTestHashSet(0, 1, 2) - assert.isTrue(pipe(set, HashSet.has(value(0)))) + assertTrue(pipe(set, HashSet.has(value(0)))) set = pipe(set, HashSet.toggle(value(0))) - assert.isFalse(pipe(set, HashSet.has(value(0)))) + assertFalse(pipe(set, HashSet.has(value(0)))) set = pipe(set, HashSet.toggle(value(0))) - assert.isTrue(pipe(set, HashSet.has(value(0)))) + assertTrue(pipe(set, HashSet.has(value(0)))) }) it("union", () => { @@ -220,12 +224,15 @@ describe("HashSet", () => { }) it("pipe()", () => { - expect(HashSet.empty().pipe(HashSet.add("value"))).toEqual(HashSet.make("value")) + strictEqual( + HashSet.empty().pipe(HashSet.add("value"), HashSet.size), + HashSet.make("value").pipe(HashSet.size) + ) }) it("isHashSet", () => { - expect(HashSet.isHashSet(HashSet.empty())).toBe(true) - expect(HashSet.isHashSet(null)).toBe(false) - expect(HashSet.isHashSet({})).toBe(false) + assertTrue(HashSet.isHashSet(HashSet.empty())) + assertFalse(HashSet.isHashSet(null)) + assertFalse(HashSet.isHashSet({})) }) }) diff --git a/packages/effect/test/Inspectable.test.ts b/packages/effect/test/Inspectable.test.ts index b9487ef4b14..40413009886 100644 --- a/packages/effect/test/Inspectable.test.ts +++ b/packages/effect/test/Inspectable.test.ts @@ -1,70 +1,91 @@ import * as Inspectable from "effect/Inspectable" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Inspectable", () => { describe("toString", () => { it("primitives", () => { - expect(Inspectable.format(null)).toEqual("null") - expect(Inspectable.format(undefined)).toEqual(undefined) - expect(Inspectable.format(1)).toEqual("1") - expect(Inspectable.format("a")).toEqual(`"a"`) - expect(Inspectable.format(true)).toEqual("true") + strictEqual(Inspectable.format(null), "null") + strictEqual(Inspectable.format(undefined), undefined) + strictEqual(Inspectable.format(1), "1") + strictEqual(Inspectable.format("a"), `"a"`) + strictEqual(Inspectable.format(true), "true") }) it("empty collections", () => { - expect(Inspectable.format({})).toEqual("{}") - expect(Inspectable.format([])).toEqual("[]") + strictEqual(Inspectable.format({}), "{}") + strictEqual(Inspectable.format([]), "[]") }) it("objects", () => { - expect(Inspectable.format({ a: 1 })).toEqual(`{ + strictEqual( + Inspectable.format({ a: 1 }), + `{ "a": 1 -}`) - expect(Inspectable.format({ a: 1, b: 2 })).toEqual(`{ +}` + ) + strictEqual( + Inspectable.format({ a: 1, b: 2 }), + `{ "a": 1, "b": 2 -}`) - expect(Inspectable.format({ a: 1, b: { c: 2 } })).toEqual(`{ +}` + ) + strictEqual( + Inspectable.format({ a: 1, b: { c: 2 } }), + `{ "a": 1, "b": { "c": 2 } -}`) - expect(Inspectable.format({ a: undefined })).toEqual("{}") +}` + ) + strictEqual(Inspectable.format({ a: undefined }), "{}") }) it("arrays", () => { - expect(Inspectable.format([1, 2, 3])).toEqual(`[ + strictEqual( + Inspectable.format([1, 2, 3]), + `[ 1, 2, 3 -]`) - expect(Inspectable.format([1, [2, 3], 4])).toEqual(`[ +]` + ) + strictEqual( + Inspectable.format([1, [2, 3], 4]), + `[ 1, [ 2, 3 ], 4 -]`) +]` + ) }) it("mixed", () => { - expect(Inspectable.format({ "a": [] })).toEqual(`{ + strictEqual( + Inspectable.format({ "a": [] }), + `{ "a": [] -}`) - expect(Inspectable.format({ - "_id": "Cause", - "_tag": "Fail", - "errors": [ - { - "value": { "_id": "Chunk", "values": [0, 1, 2] } - }, - { - "value": { "_id": "Chunk", "values": ["a", "b"] } - } - ] - })).toEqual(`{ +}` + ) + strictEqual( + Inspectable.format({ + "_id": "Cause", + "_tag": "Fail", + "errors": [ + { + "value": { "_id": "Chunk", "values": [0, 1, 2] } + }, + { + "value": { "_id": "Chunk", "values": ["a", "b"] } + } + ] + }), + `{ "_id": "Cause", "_tag": "Fail", "errors": [ @@ -88,7 +109,8 @@ describe("Inspectable", () => { } } ] -}`) +}` + ) }) }) }) diff --git a/packages/effect/test/Iterable.test.ts b/packages/effect/test/Iterable.test.ts index b328c7f4ff0..21709266432 100644 --- a/packages/effect/test/Iterable.test.ts +++ b/packages/effect/test/Iterable.test.ts @@ -3,8 +3,8 @@ import * as Iter from "effect/Iterable" import * as Number from "effect/Number" import * as O from "effect/Option" import type { Predicate } from "effect/Predicate" -import { deepStrictEqual, strictEqual } from "effect/test/util" -import { assert, describe, expect, it } from "vitest" +import { assertFalse, assertNone, assertSome, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" const symA = Symbol.for("a") const symB = Symbol.for("b") @@ -19,7 +19,7 @@ const toArray = (i: Iterable) => { describe("Iterable", () => { it("of", () => { - expect(Array.from(Iter.of(1))).toEqual([1]) + deepStrictEqual(Array.from(Iter.of(1)), [1]) }) describe("iterable inputs", () => { @@ -65,17 +65,17 @@ describe("Iterable", () => { }) it("take", () => { - expect(pipe([1, 2, 3, 4], Iter.take(2), toArray)).toEqual([1, 2]) - expect(pipe([1, 2, 3, 4], Iter.take(0), toArray)).toEqual([]) + deepStrictEqual(pipe([1, 2, 3, 4], Iter.take(2), toArray), [1, 2]) + deepStrictEqual(pipe([1, 2, 3, 4], Iter.take(0), toArray), []) // out of bounds - expect(pipe([1, 2, 3, 4], Iter.take(-10), toArray)).toEqual([]) - expect(pipe([1, 2, 3, 4], Iter.take(10), toArray)).toEqual([1, 2, 3, 4]) + deepStrictEqual(pipe([1, 2, 3, 4], Iter.take(-10), toArray), []) + deepStrictEqual(pipe([1, 2, 3, 4], Iter.take(10), toArray), [1, 2, 3, 4]) - expect(pipe(new Set([1, 2, 3, 4]), Iter.take(2), toArray)).toEqual([1, 2]) - expect(pipe(new Set([1, 2, 3, 4]), Iter.take(0), toArray)).toEqual([]) + deepStrictEqual(pipe(new Set([1, 2, 3, 4]), Iter.take(2), toArray), [1, 2]) + deepStrictEqual(pipe(new Set([1, 2, 3, 4]), Iter.take(0), toArray), []) // out of bounds - expect(pipe(new Set([1, 2, 3, 4]), Iter.take(-10), toArray)).toEqual([]) - expect(pipe(new Set([1, 2, 3, 4]), Iter.take(10), toArray)).toEqual([1, 2, 3, 4]) + deepStrictEqual(pipe(new Set([1, 2, 3, 4]), Iter.take(-10), toArray), []) + deepStrictEqual(pipe(new Set([1, 2, 3, 4]), Iter.take(10), toArray), [1, 2, 3, 4]) }) it("takeWhile", () => { @@ -115,74 +115,72 @@ describe("Iterable", () => { describe("findFirst", () => { it("boolean-returning overloads", () => { - deepStrictEqual(pipe([], Iter.findFirst((n) => n % 2 === 0)), O.none()) - deepStrictEqual(pipe([1, 2, 3], Iter.findFirst((n) => n % 2 === 0)), O.some(2)) - deepStrictEqual(pipe([1, 2, 3, 4], Iter.findFirst((n) => n % 2 === 0)), O.some(2)) + assertNone(pipe([], Iter.findFirst((n) => n % 2 === 0))) + assertSome(pipe([1, 2, 3], Iter.findFirst((n) => n % 2 === 0)), 2) + assertSome(pipe([1, 2, 3, 4], Iter.findFirst((n) => n % 2 === 0)), 2) - deepStrictEqual(pipe(new Set(), Iter.findFirst((n) => n % 2 === 0)), O.none()) - deepStrictEqual(pipe(new Set([1, 2, 3]), Iter.findFirst((n) => n % 2 === 0)), O.some(2)) - deepStrictEqual(pipe(new Set([1, 2, 3, 4]), Iter.findFirst((n) => n % 2 === 0)), O.some(2)) + assertNone(pipe(new Set(), Iter.findFirst((n) => n % 2 === 0))) + assertSome(pipe(new Set([1, 2, 3]), Iter.findFirst((n) => n % 2 === 0)), 2) + assertSome(pipe(new Set([1, 2, 3, 4]), Iter.findFirst((n) => n % 2 === 0)), 2) }) it("Option-returning overloads", () => { - deepStrictEqual(pipe([], Iter.findFirst((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), O.none()) - deepStrictEqual( + assertNone(pipe([], Iter.findFirst((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none()))) + assertSome( pipe([1, 2, 3], Iter.findFirst((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.some([2, 1]) + [2, 1] ) - deepStrictEqual( + assertSome( pipe([1, 2, 3, 4], Iter.findFirst((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.some([2, 1]) + [2, 1] ) - deepStrictEqual( - pipe(new Set(), Iter.findFirst((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.none() + assertNone( + pipe(new Set(), Iter.findFirst((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())) ) - deepStrictEqual( + assertSome( pipe(new Set([1, 2, 3]), Iter.findFirst((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.some([2, 1]) + [2, 1] ) - deepStrictEqual( + assertSome( pipe(new Set([1, 2, 3, 4]), Iter.findFirst((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.some([2, 1]) + [2, 1] ) }) }) describe("findLast", () => { it("boolean-returning overloads", () => { - deepStrictEqual(pipe([], Iter.findLast((n) => n % 2 === 0)), O.none()) - deepStrictEqual(pipe([1, 2, 3], Iter.findLast((n) => n % 2 === 0)), O.some(2)) - deepStrictEqual(pipe([1, 2, 3, 4], Iter.findLast((n) => n % 2 === 0)), O.some(4)) + assertNone(pipe([], Iter.findLast((n) => n % 2 === 0))) + assertSome(pipe([1, 2, 3], Iter.findLast((n) => n % 2 === 0)), 2) + assertSome(pipe([1, 2, 3, 4], Iter.findLast((n) => n % 2 === 0)), 4) - deepStrictEqual(pipe(new Set(), Iter.findLast((n) => n % 2 === 0)), O.none()) - deepStrictEqual(pipe(new Set([1, 2, 3]), Iter.findLast((n) => n % 2 === 0)), O.some(2)) - deepStrictEqual(pipe(new Set([1, 2, 3, 4]), Iter.findLast((n) => n % 2 === 0)), O.some(4)) + assertNone(pipe(new Set(), Iter.findLast((n) => n % 2 === 0))) + assertSome(pipe(new Set([1, 2, 3]), Iter.findLast((n) => n % 2 === 0)), 2) + assertSome(pipe(new Set([1, 2, 3, 4]), Iter.findLast((n) => n % 2 === 0)), 4) }) it("Option-returning overloads", () => { - deepStrictEqual(pipe([], Iter.findLast((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), O.none()) - deepStrictEqual( + assertNone(pipe([], Iter.findLast((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none()))) + assertSome( pipe([1, 2, 3], Iter.findLast((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.some([2, 1]) + [2, 1] ) - deepStrictEqual( + assertSome( pipe([1, 2, 3, 4], Iter.findLast((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.some([4, 3]) + [4, 3] ) - deepStrictEqual( - pipe(new Set(), Iter.findLast((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.none() + assertNone( + pipe(new Set(), Iter.findLast((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())) ) - deepStrictEqual( + assertSome( pipe(new Set([1, 2, 3]), Iter.findLast((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.some([2, 1]) + [2, 1] ) - deepStrictEqual( + assertSome( pipe(new Set([1, 2, 3, 4]), Iter.findLast((n, i) => n % 2 === 0 ? O.some([n, i]) : O.none())), - O.some([4, 3]) + [4, 3] ) }) }) @@ -237,27 +235,27 @@ describe("Iterable", () => { it("containsWith", () => { const contains = Iter.containsWith(Number.Equivalence) - deepStrictEqual(pipe([1, 2, 3], contains(2)), true) - deepStrictEqual(pipe([1, 2, 3], contains(0)), false) + assertTrue(pipe([1, 2, 3], contains(2))) + assertFalse(pipe([1, 2, 3], contains(0))) - deepStrictEqual(pipe(new Set([1, 2, 3]), contains(2)), true) - deepStrictEqual(pipe(new Set([1, 2, 3]), contains(0)), false) + assertTrue(pipe(new Set([1, 2, 3]), contains(2))) + assertFalse(pipe(new Set([1, 2, 3]), contains(0))) }) it("contains", () => { const contains = Iter.contains - deepStrictEqual(pipe([1, 2, 3], contains(2)), true) - deepStrictEqual(pipe([1, 2, 3], contains(0)), false) + assertTrue(pipe([1, 2, 3], contains(2))) + assertFalse(pipe([1, 2, 3], contains(0))) - deepStrictEqual(pipe(new Set([1, 2, 3]), contains(2)), true) - deepStrictEqual(pipe(new Set([1, 2, 3]), contains(0)), false) + assertTrue(pipe(new Set([1, 2, 3]), contains(2))) + assertFalse(pipe(new Set([1, 2, 3]), contains(0))) }) it("dedupeAdjacentWith", () => { const dedupeAdjacent = Iter.dedupeAdjacentWith(Number.Equivalence) - expect(toArray(dedupeAdjacent([]))).toEqual([]) - expect(toArray(dedupeAdjacent([1, 2, 3]))).toEqual([1, 2, 3]) - expect(toArray(dedupeAdjacent([1, 2, 2, 3, 3]))).toEqual([1, 2, 3]) + deepStrictEqual(toArray(dedupeAdjacent([])), []) + deepStrictEqual(toArray(dedupeAdjacent([1, 2, 3])), [1, 2, 3]) + deepStrictEqual(toArray(dedupeAdjacent([1, 2, 2, 3, 3])), [1, 2, 3]) }) }) @@ -295,13 +293,13 @@ describe("Iterable", () => { }) it("getSomes", () => { - assert.deepStrictEqual(toArray(Iter.getSomes([])), []) - assert.deepStrictEqual(toArray(Iter.getSomes([O.some(1), O.some(2), O.some(3)])), [ + deepStrictEqual(toArray(Iter.getSomes([])), []) + deepStrictEqual(toArray(Iter.getSomes([O.some(1), O.some(2), O.some(3)])), [ 1, 2, 3 ]) - assert.deepStrictEqual(toArray(Iter.getSomes([O.some(1), O.none(), O.some(3)])), [ + deepStrictEqual(toArray(Iter.getSomes([O.some(1), O.none(), O.some(3)])), [ 1, 3 ]) @@ -328,14 +326,14 @@ describe("Iterable", () => { }) it("isEmpty", () => { - deepStrictEqual(Iter.isEmpty([1, 2, 3]), false) - deepStrictEqual(Iter.isEmpty([]), true) + assertFalse(Iter.isEmpty([1, 2, 3])) + assertTrue(Iter.isEmpty([])) }) it("head", () => { const as: ReadonlyArray = [1, 2, 3] - deepStrictEqual(Iter.head(as), O.some(1)) - deepStrictEqual(Iter.head([]), O.none()) + assertSome(Iter.head(as), 1) + assertNone(Iter.head([])) }) it("chunksOf", () => { @@ -370,7 +368,7 @@ describe("Iterable", () => { }) it("flatten", () => { - expect(toArray(Iter.flatten([[1], [2], [3]]))).toEqual([1, 2, 3]) + deepStrictEqual(toArray(Iter.flatten([[1], [2], [3]])), [1, 2, 3]) }) it("groupWith", () => { @@ -389,11 +387,11 @@ describe("Iterable", () => { "6": ["foobar"] } ) - expect(Iter.groupBy(["a", "b"], (s) => s === "a" ? symA : s === "b" ? symB : symC)).toStrictEqual({ + deepStrictEqual(Iter.groupBy(["a", "b"], (s) => s === "a" ? symA : s === "b" ? symB : symC), { [symA]: ["a"], [symB]: ["b"] }) - expect(Iter.groupBy(["a", "b", "c", "d"], (s) => s === "a" ? symA : s === "b" ? symB : symC)).toStrictEqual({ + deepStrictEqual(Iter.groupBy(["a", "b", "c", "d"], (s) => s === "a" ? symA : s === "b" ? symB : symC), { [symA]: ["a"], [symB]: ["b"], [symC]: ["c", "d"] @@ -421,15 +419,15 @@ describe("Iterable", () => { }) it("range", () => { - expect(toArray(Iter.range(0, 0))).toEqual([0]) - expect(toArray(Iter.range(0, 1))).toEqual([0, 1]) - expect(toArray(Iter.range(1, 5))).toEqual([1, 2, 3, 4, 5]) - expect(toArray(Iter.range(10, 15))).toEqual([10, 11, 12, 13, 14, 15]) - expect(toArray(Iter.range(-1, 0))).toEqual([-1, 0]) - expect(toArray(Iter.range(-5, -1))).toEqual([-5, -4, -3, -2, -1]) + deepStrictEqual(toArray(Iter.range(0, 0)), [0]) + deepStrictEqual(toArray(Iter.range(0, 1)), [0, 1]) + deepStrictEqual(toArray(Iter.range(1, 5)), [1, 2, 3, 4, 5]) + deepStrictEqual(toArray(Iter.range(10, 15)), [10, 11, 12, 13, 14, 15]) + deepStrictEqual(toArray(Iter.range(-1, 0)), [-1, 0]) + deepStrictEqual(toArray(Iter.range(-5, -1)), [-5, -4, -3, -2, -1]) // out of bound - expect(Array.from(Iter.range(2, 1))).toEqual([2]) - expect(Array.from(Iter.range(-1, -2))).toEqual([-1]) + deepStrictEqual(Array.from(Iter.range(2, 1)), [2]) + deepStrictEqual(Array.from(Iter.range(-1, -2)), [-1]) }) it("empty", () => { @@ -438,19 +436,19 @@ describe("Iterable", () => { it("some", () => { const isPositive: Predicate = (n) => n > 0 - expect(Iter.some([-1, -2, 3], isPositive)).toEqual(true) - expect(Iter.some([-1, -2, -3], isPositive)).toEqual(false) + assertTrue(Iter.some([-1, -2, 3], isPositive)) + assertFalse(Iter.some([-1, -2, -3], isPositive)) }) it("size", () => { - deepStrictEqual(Iter.size(Iter.empty()), 0) - deepStrictEqual(Iter.size([]), 0) - deepStrictEqual(Iter.size(["a"]), 1) + strictEqual(Iter.size(Iter.empty()), 0) + strictEqual(Iter.size([]), 0) + strictEqual(Iter.size(["a"]), 1) }) it("forEach", () => { const log: Array = [] Iter.forEach(["a", "b", "c"], (a, i) => log.push(`${a}-${i}`)) - expect(log).toEqual(["a-0", "b-1", "c-2"]) + deepStrictEqual(log, ["a-0", "b-1", "c-2"]) }) }) diff --git a/packages/effect/test/KeyedPool.test.ts b/packages/effect/test/KeyedPool.test.ts index 181e42a8513..5372b7bffe5 100644 --- a/packages/effect/test/KeyedPool.test.ts +++ b/packages/effect/test/KeyedPool.test.ts @@ -6,9 +6,10 @@ import { pipe } from "effect/Function" import * as KeyedPool from "effect/KeyedPool" import * as Random from "effect/Random" import * as Ref from "effect/Ref" +import { strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { describe, expect } from "vitest" +import { describe } from "vitest" describe("KeyedPool", () => { it.scoped("acquire release many successfully while other key is blocked", () => @@ -40,7 +41,7 @@ describe("KeyedPool", () => { )) yield* $(TestClock.adjust(Duration.millis(10 * N))) const result = yield* $(Fiber.join(fiber)) - expect(result).toBeUndefined() + strictEqual(result, undefined) })) it.scoped("acquire release many with invalidates", () => @@ -75,6 +76,6 @@ describe("KeyedPool", () => { )) yield* $(TestClock.adjust(Duration.millis(15 * N))) const result = yield* $(Fiber.join(fiber)) - expect(result).toBeUndefined() + strictEqual(result, undefined) })) }) diff --git a/packages/effect/test/Layer.test.ts b/packages/effect/test/Layer.test.ts index 050d0f8b60a..8d85717b105 100644 --- a/packages/effect/test/Layer.test.ts +++ b/packages/effect/test/Layer.test.ts @@ -11,8 +11,9 @@ import * as Layer from "effect/Layer" import * as Ref from "effect/Ref" import * as Schedule from "effect/Schedule" import * as Scope from "effect/Scope" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" export const acquire1 = "Acquiring Module 1" export const acquire2 = "Acquiring Module 2" @@ -39,7 +40,7 @@ describe("Layer", () => { const fiber = yield* $(Effect.scoped(env), Effect.forkDaemon) yield* $(Deferred.await(deferred)) const result = yield* $(Fiber.interrupt(fiber), Effect.asVoid) - assert.isUndefined(result) + strictEqual(result, undefined) })) it.effect("preserves identity of acquired resources", () => Effect.gen(function*($) { @@ -68,7 +69,7 @@ describe("Layer", () => { Effect.scoped ) const result = yield* $(Ref.get(testRef)) - assert.deepStrictEqual(Array.from(result), ["test"]) + deepStrictEqual(Array.from(result), ["test"]) })) it.effect("sharing with merge", () => Effect.gen(function*($) { @@ -77,7 +78,7 @@ describe("Layer", () => { const env = layer.pipe(Layer.merge(layer), Layer.build) yield* $(Effect.scoped(env)) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [acquire1, release1]) + deepStrictEqual(Array.from(result), [acquire1, release1]) })) it.scoped("sharing itself with merge", () => Effect.gen(function*($) { @@ -87,7 +88,7 @@ describe("Layer", () => { const result = yield* $( env.pipe(Effect.flatMap((context) => Effect.try(() => context.pipe(Context.get(Service1Tag))))) ) - assert.strictEqual(result, service1) + strictEqual(result, service1) })) it.effect("finalizers", () => Effect.gen(function*($) { @@ -97,10 +98,10 @@ describe("Layer", () => { const env = layer1.pipe(Layer.merge(layer2), Layer.build) yield* $(Effect.scoped(env)) const result = yield* $(Ref.get(ref)) - assert.isDefined(Array.from(result).slice(0, 2).find((s) => s === acquire1)) - assert.isDefined(Array.from(result).slice(0, 2).find((s) => s === acquire2)) - assert.isDefined(Array.from(result).slice(2, 4).find((s) => s === release1)) - assert.isDefined(Array.from(result).slice(2, 4).find((s) => s === release2)) + assertTrue(Array.from(result).slice(0, 2).find((s) => s === acquire1) !== undefined) + assertTrue(Array.from(result).slice(0, 2).find((s) => s === acquire2) !== undefined) + assertTrue(Array.from(result).slice(2, 4).find((s) => s === release1) !== undefined) + assertTrue(Array.from(result).slice(2, 4).find((s) => s === release2) !== undefined) })) it.effect("caching values in dependencies", () => Effect.gen(function*($) { @@ -143,8 +144,8 @@ describe("Layer", () => { ), Effect.scoped ) - assert.strictEqual(result[0].value, 1) - assert.strictEqual(result[1].value, 1) + strictEqual(result[0].value, 1) + strictEqual(result[1].value, 1) })) it.effect("orElse - uses an alternative layer", () => Effect.gen(function*($) { @@ -154,7 +155,7 @@ describe("Layer", () => { const env = Layer.fail("failed!").pipe(Layer.provideMerge(layer1), Layer.orElse(() => layer2), Layer.build) yield* $(Effect.scoped(env)) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [acquire1, release1, acquire2, release2]) + deepStrictEqual(Array.from(result), [acquire1, release1, acquire2, release2]) })) it.effect("handles errors gracefully", () => Effect.gen(function*($) { @@ -183,7 +184,7 @@ describe("Layer", () => { ) ) const result = yield* $(Effect.void, Effect.provide(layer), Effect.exit) - assert.isTrue(Exit.isFailure(result)) + assertTrue(Exit.isFailure(result)) })) it.effect("fresh with merge", () => Effect.gen(function*($) { @@ -192,7 +193,7 @@ describe("Layer", () => { const env = layer.pipe(Layer.merge(Layer.fresh(layer)), Layer.build) yield* $(Effect.scoped(env)) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [acquire1, acquire1, release1, release1]) + deepStrictEqual(Array.from(result), [acquire1, acquire1, release1, release1]) })) it.effect("fresh with to provideTo", () => Effect.gen(function*($) { @@ -204,7 +205,7 @@ describe("Layer", () => { ) yield* $(Effect.scoped(env)) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [acquire1, acquire1, release1, release1]) + deepStrictEqual(Array.from(result), [acquire1, acquire1, release1, release1]) })) it.effect("with multiple layers", () => Effect.gen(function*($) { @@ -217,7 +218,7 @@ describe("Layer", () => { ) yield* $(Effect.scoped(env)) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [acquire1, acquire1, release1, release1]) + deepStrictEqual(Array.from(result), [acquire1, acquire1, release1, release1]) })) it.effect("with identical fresh layers", () => Effect.gen(function*($) { @@ -237,7 +238,7 @@ describe("Layer", () => { ) yield* $(Effect.scoped(env)) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [ + deepStrictEqual(Array.from(result), [ acquire1, acquire2, acquire1, @@ -258,10 +259,10 @@ describe("Layer", () => { yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref), Effect.map((chunk) => Array.from(chunk))) if (result.find((s) => s === acquire1) !== undefined) { - assert.isTrue(result.some((s) => s === release1)) + assertTrue(result.some((s) => s === release1)) } if (result.find((s) => s === acquire2) !== undefined) { - assert.isTrue(result.some((s) => s === release2)) + assertTrue(result.some((s) => s === release2)) } })) it.effect("interruption with provideTo", () => @@ -274,10 +275,10 @@ describe("Layer", () => { yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref), Effect.map((chunk) => Array.from(chunk))) if (result.find((s) => s === acquire1) !== undefined) { - assert.isTrue(result.some((s) => s === release1)) + assertTrue(result.some((s) => s === release1)) } if (result.find((s) => s === acquire2) !== undefined) { - assert.isTrue(result.some((s) => s === release2)) + assertTrue(result.some((s) => s === release2)) } })) it.effect("interruption with multiple layers", () => @@ -296,13 +297,13 @@ describe("Layer", () => { yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref), Effect.map((chunk) => Array.from(chunk))) if (result.find((s) => s === acquire1) !== undefined) { - assert.isTrue(result.some((s) => s === release1)) + assertTrue(result.some((s) => s === release1)) } if (result.find((s) => s === acquire2) !== undefined) { - assert.isTrue(result.some((s) => s === release2)) + assertTrue(result.some((s) => s === release2)) } if (result.find((s) => s === acquire3) !== undefined) { - assert.isTrue(result.some((s) => s === release3)) + assertTrue(result.some((s) => s === release3)) } })) it.effect("can map a layer to an unrelated type", () => @@ -325,7 +326,7 @@ describe("Layer", () => { ) ) const result = yield* $(ServiceBTag, Effect.provide(live)) - assert.strictEqual(result.name, "name") + strictEqual(result.name, "name") })) it.effect("memoizes acquisition of resources", () => Effect.gen(function*($) { @@ -342,7 +343,7 @@ describe("Layer", () => { Effect.scoped ) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [acquire1, release1]) + deepStrictEqual(Array.from(result), [acquire1, release1]) })) it.scoped("fiberRef changes are memoized", () => Effect.gen(function*($) { @@ -355,7 +356,7 @@ describe("Layer", () => { Layer.merge(layer1) ) const result = yield* $(Layer.build(layer3)) - assert.equal(result.pipe(Context.unsafeGet(tag)), true) + assertTrue(result.pipe(Context.unsafeGet(tag))) })) it.effect("provides a partial environment to an effect", () => Effect.gen(function*($) { @@ -366,8 +367,8 @@ describe("Layer", () => { const providesString = Layer.succeed(StringTag, "hi") const needsString = needsNumberAndString.pipe(Effect.provide(providesNumber)) const result = yield* $(needsString, Effect.provide(providesString)) - assert.strictEqual(result[0], 10) - assert.strictEqual(result[1], "hi") + strictEqual(result[0], 10) + strictEqual(result[1], "hi") })) it.effect("to provides a partial environment to another layer", () => Effect.gen(function*($) { @@ -400,8 +401,8 @@ describe("Layer", () => { const needsString = fooBuilder.pipe(Layer.provide(provideNumberRef)) const layer = needsString.pipe(Layer.provide(provideString)) const result = yield* $(Effect.flatMap(FooTag, (_) => _.get), Effect.provide(layer)) - assert.strictEqual(result[0], 10) - assert.strictEqual(result[1], "hi") + strictEqual(result[0], 10) + strictEqual(result[1], "hi") })) it.effect("andTo provides a partial environment to another layer", () => Effect.gen(function*($) { @@ -440,9 +441,9 @@ describe("Layer", () => { ), Effect.provide(layer) ) - assert.strictEqual(result[0], 10) - assert.strictEqual(result[1], 10) - assert.strictEqual(result[2], "hi") + strictEqual(result[0], 10) + strictEqual(result[1], 10) + strictEqual(result[2], "hi") })) it.effect("passthrough passes the inputs through to the next layer", () => Effect.gen(function*($) { @@ -465,8 +466,8 @@ describe("Layer", () => { }), Effect.provide(live) ) - assert.strictEqual(i.value, 1) - assert.strictEqual(s.value, "1") + strictEqual(i.value, 1) + strictEqual(s.value, "1") })) it.effect("project", () => Effect.gen(function*($) { @@ -481,7 +482,7 @@ describe("Layer", () => { const personLayer = Layer.succeed(PersonTag, { name: "User", age: 42 }) const ageLayer = personLayer.pipe(Layer.project(PersonTag, AgeTag, (_) => ({ age: _.age }))) const { age } = yield* $(AgeTag, Effect.provide(ageLayer)) - assert.strictEqual(age, 42) + strictEqual(age, 42) })) it.effect("sharing with provideTo", () => Effect.gen(function*($) { @@ -490,7 +491,7 @@ describe("Layer", () => { const env = layer.pipe(Layer.provide(layer), Layer.build) yield* $(Effect.scoped(env)) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [acquire1, release1]) + deepStrictEqual(Array.from(result), [acquire1, release1]) })) it.effect("sharing with multiple layers with provideTo", () => Effect.gen(function*($) { @@ -505,12 +506,12 @@ describe("Layer", () => { ) yield* $(Effect.scoped(env)) const result = yield* $(Ref.get(ref), Effect.map((chunk) => Array.from(chunk))) - assert.strictEqual(result[0], acquire1) - assert.isTrue(result.slice(1, 3).some((s) => s === acquire2)) - assert.isTrue(result.slice(1, 3).some((s) => s === acquire3)) - assert.isTrue(result.slice(3, 5).some((s) => s === release3)) - assert.isTrue(result.slice(3, 5).some((s) => s === release2)) - assert.strictEqual(result[5], release1) + strictEqual(result[0], acquire1) + assertTrue(result.slice(1, 3).some((s) => s === acquire2)) + assertTrue(result.slice(1, 3).some((s) => s === acquire3)) + assertTrue(result.slice(3, 5).some((s) => s === release3)) + assertTrue(result.slice(3, 5).some((s) => s === release2)) + strictEqual(result[5], release1) })) it.effect("finalizers with provideTo", () => Effect.gen(function*($) { @@ -520,7 +521,7 @@ describe("Layer", () => { const env = layer2.pipe(Layer.provide(layer1), Layer.build) yield* $(Effect.scoped(env)) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [acquire1, acquire2, release2, release1]) + deepStrictEqual(Array.from(result), [acquire1, acquire2, release2, release1]) })) it.effect("finalizers with multiple layers with provideTo", () => Effect.gen(function*($) { @@ -531,7 +532,7 @@ describe("Layer", () => { const env = layer3.pipe(Layer.provide(layer2), Layer.provide(layer1), Layer.build) yield* $(Effect.scoped(env)) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [acquire1, acquire2, acquire3, release3, release2, release1]) + deepStrictEqual(Array.from(result), [acquire1, acquire2, acquire3, release3, release2, release1]) })) it.effect("retry", () => Effect.gen(function*($) { @@ -540,7 +541,7 @@ describe("Layer", () => { const layer = Layer.effectContext(effect).pipe(Layer.retry(Schedule.recurs(3))) yield* $(Effect.ignore(Effect.scoped(Layer.build(layer)))) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 4) + strictEqual(result, 4) })) it.effect("map does not interfere with sharing", () => Effect.gen(function*($) { @@ -556,12 +557,12 @@ describe("Layer", () => { ) yield* $(Effect.scoped(env)) const result = yield* $(Ref.get(ref), Effect.map((chunk) => Array.from(chunk))) - assert.strictEqual(result[0], acquire1) - assert.isTrue(result.slice(1, 3).some((s) => s === acquire2)) - assert.isTrue(result.slice(1, 3).some((s) => s === acquire3)) - assert.isTrue(result.slice(3, 5).some((s) => s === release3)) - assert.isTrue(result.slice(3, 5).some((s) => s === release2)) - assert.strictEqual(result[5], release1) + strictEqual(result[0], acquire1) + assertTrue(result.slice(1, 3).some((s) => s === acquire2)) + assertTrue(result.slice(1, 3).some((s) => s === acquire3)) + assertTrue(result.slice(3, 5).some((s) => s === release3)) + assertTrue(result.slice(3, 5).some((s) => s === release2)) + strictEqual(result[5], release1) })) it.effect("mapError does not interfere with sharing", () => Effect.gen(function*($) { @@ -577,12 +578,12 @@ describe("Layer", () => { ) yield* $(Effect.scoped(env)) const result = yield* $(Ref.get(ref), Effect.map((chunk) => Array.from(chunk))) - assert.strictEqual(result[0], acquire1) - assert.isTrue(result.slice(1, 3).some((s) => s === acquire2)) - assert.isTrue(result.slice(1, 3).some((s) => s === acquire3)) - assert.isTrue(result.slice(3, 5).some((s) => s === release3)) - assert.isTrue(result.slice(3, 5).some((s) => s === release2)) - assert.strictEqual(result[5], release1) + strictEqual(result[0], acquire1) + assertTrue(result.slice(1, 3).some((s) => s === acquire2)) + assertTrue(result.slice(1, 3).some((s) => s === acquire3)) + assertTrue(result.slice(3, 5).some((s) => s === release3)) + assertTrue(result.slice(3, 5).some((s) => s === release2)) + strictEqual(result[5], release1) })) it.effect("orDie does not interfere with sharing", () => Effect.gen(function*($) { @@ -598,12 +599,12 @@ describe("Layer", () => { ) yield* $(Effect.scoped(env)) const result = yield* $(Ref.get(ref), Effect.map((chunk) => Array.from(chunk))) - assert.strictEqual(result[0], acquire1) - assert.isTrue(result.slice(1, 3).some((s) => s === acquire2)) - assert.isTrue(result.slice(1, 3).some((s) => s === acquire3)) - assert.isTrue(result.slice(3, 5).some((s) => s === release3)) - assert.isTrue(result.slice(3, 5).some((s) => s === release2)) - assert.strictEqual(result[5], release1) + strictEqual(result[0], acquire1) + assertTrue(result.slice(1, 3).some((s) => s === acquire2)) + assertTrue(result.slice(1, 3).some((s) => s === acquire3)) + assertTrue(result.slice(3, 5).some((s) => s === release3)) + assertTrue(result.slice(3, 5).some((s) => s === release2)) + strictEqual(result[5], release1) })) it.effect("tap peeks at an acquired resource", () => Effect.gen(function*($) { @@ -617,7 +618,7 @@ describe("Layer", () => { ) yield* $(Effect.scoped(Layer.build(layer))) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, "bar") + strictEqual(result, "bar") })) it.effect("locally", () => Effect.gen(function*($) { @@ -637,7 +638,7 @@ describe("Layer", () => { ) const env = yield* $(Effect.scoped(Layer.build(layer))) const result = Context.get(env, BarTag) - assert.strictEqual(result.bar, "bar: 100") + strictEqual(result.bar, "bar: 100") })) it.effect("locallyWith", () => Effect.gen(function*($) { @@ -657,7 +658,7 @@ describe("Layer", () => { ) const env = yield* $(Effect.scoped(Layer.build(layer))) const result = Context.get(env, BarTag) - assert.strictEqual(result.bar, "bar: 1") + strictEqual(result.bar, "bar: 1") })) describe("MemoMap", () => { @@ -679,7 +680,7 @@ describe("Layer", () => { yield* $(Scope.close(scope1, Exit.void)) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [acquire1, acquire2, release2, acquire2, release2, release1]) + deepStrictEqual(Array.from(result), [acquire1, acquire2, release2, acquire2, release2, release1]) })) it.effect("layers are not released early", () => @@ -699,7 +700,7 @@ describe("Layer", () => { yield* $(Scope.close(scope2, Exit.void)) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [acquire1, acquire2, release2, release1]) + deepStrictEqual(Array.from(result), [acquire1, acquire2, release2, release1]) })) }) }) diff --git a/packages/effect/test/List.test.ts b/packages/effect/test/List.test.ts index bb94112c80f..da3d736d539 100644 --- a/packages/effect/test/List.test.ts +++ b/packages/effect/test/List.test.ts @@ -5,7 +5,8 @@ import * as Either from "effect/Either" import { equals, symbol } from "effect/Equal" import * as List from "effect/List" import * as Option from "effect/Option" -import { describe, expect, it } from "vitest" +import { assertFalse, assertNone, assertSome, assertTrue, deepStrictEqual, strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" const testStructuralSharing = (a: List.List, b: List.List, n = 0): number | undefined => { if (a === b) { @@ -17,195 +18,189 @@ const testStructuralSharing = (a: List.List, b: List.List, n = 0): numb } describe("List", () => { - it("exports", () => { - expect(List.cons).exist - expect(List.size).exist - expect(List.filter).exist - expect(List.filterMap).exist - }) - it("is an iterable", () => { - expect(Array.fromIterable(List.make(0, 1, 2, 3))).toEqual([0, 1, 2, 3]) + deepStrictEqual(Array.fromIterable(List.make(0, 1, 2, 3)), [0, 1, 2, 3]) }) it("isList", () => { - expect(List.isList(List.empty())).toEqual(true) - expect(List.isList(List.make(1))).toEqual(true) - expect(List.isList(null)).toEqual(false) - expect(List.isList({})).toEqual(false) + assertTrue(List.isList(List.empty())) + assertTrue(List.isList(List.make(1))) + assertFalse(List.isList(null)) + assertFalse(List.isList({})) }) it("append", () => { - expect(List.append(List.make(1, 2), 3)).toEqual(List.make(1, 2, 3)) + deepStrictEqual(List.append(List.make(1, 2), 3), List.make(1, 2, 3)) }) it("appendAll", () => { - expect(List.appendAll(List.make(1, 2), List.make(3, 4))).toEqual(List.make(1, 2, 3, 4)) + deepStrictEqual(List.appendAll(List.make(1, 2), List.make(3, 4)), List.make(1, 2, 3, 4)) }) it("drop", () => { - expect(List.drop(List.make(1, 2, 3, 4), 2)).toEqual(List.make(3, 4)) + deepStrictEqual(List.drop(List.make(1, 2, 3, 4), 2), List.make(3, 4)) // out of bound - expect(List.drop(List.make(1, 2), -2)).toEqual(List.make(1, 2)) - expect(List.drop(List.make(1, 2), 3)).toEqual(List.empty()) + deepStrictEqual(List.drop(List.make(1, 2), -2), List.make(1, 2)) + deepStrictEqual(List.drop(List.make(1, 2), 3), List.empty()) }) it("every", () => { - expect(List.every(List.empty(), (n) => n > 2)).toEqual(true) - expect(List.every(List.make(1, 2), (n) => n > 2)).toEqual(false) - expect(List.every(List.make(2, 3), (n) => n > 2)).toEqual(false) - expect(List.every(List.make(3, 4), (n) => n > 2)).toEqual(true) + assertTrue(List.every(List.empty(), (n) => n > 2)) + assertFalse(List.every(List.make(1, 2), (n) => n > 2)) + assertFalse(List.every(List.make(2, 3), (n) => n > 2)) + assertTrue(List.every(List.make(3, 4), (n) => n > 2)) }) it("findFirst", () => { const item = (a: string, b: string) => ({ a, b }) const list = List.make(item("a1", "b1"), item("a2", "b2"), item("a3", "b2")) - expect(List.findFirst(list, ({ b }) => b === "b2")).toEqual(Option.some(item("a2", "b2"))) - expect(List.findFirst(list, ({ b }) => b === "-")).toEqual(Option.none()) + assertSome(List.findFirst(list, ({ b }) => b === "b2"), item("a2", "b2")) + assertNone(List.findFirst(list, ({ b }) => b === "-")) }) it("flatMap", () => { - expect(List.flatMap(List.empty(), (n) => List.make(n - 1, n + 1))).toEqual( - List.empty() - ) - expect(List.flatMap(List.make(1, 2, 3, 4), (n) => List.make(n - 1, n + 1))).toEqual( + deepStrictEqual(List.flatMap(List.empty(), (n) => List.make(n - 1, n + 1)), List.empty()) + deepStrictEqual( + List.flatMap(List.make(1, 2, 3, 4), (n) => List.make(n - 1, n + 1)), List.make(0, 2, 1, 3, 2, 4, 3, 5) ) - expect(List.flatMap(List.make(1, 2, 3, 4), () => List.empty())).toEqual( - List.empty() - ) + deepStrictEqual(List.flatMap(List.make(1, 2, 3, 4), () => List.empty()), List.empty()) }) it("forEach", () => { const as: Array = [] List.forEach(List.make(1, 2, 3, 4), (n) => as.push(n)) - expect(as).toEqual([1, 2, 3, 4]) + deepStrictEqual(as, [1, 2, 3, 4]) }) it("head", () => { - expect(List.head(List.empty())).toEqual(Option.none()) - expect(List.head(List.make(1, 2, 3))).toEqual(Option.some(1)) + assertNone(List.head(List.empty())) + assertSome(List.head(List.make(1, 2, 3)), 1) }) it("isCons", () => { - expect(List.isCons(List.empty())).toBe(false) - expect(List.isCons(List.make(1))).toBe(true) + assertFalse(List.isCons(List.empty())) + assertTrue(List.isCons(List.make(1))) }) it("isNil", () => { - expect(List.isNil(List.nil())).toBe(true) - expect(List.isNil(List.make(1))).toBe(false) + assertTrue(List.isNil(List.nil())) + assertFalse(List.isNil(List.make(1))) }) it("map", () => { - expect(List.map(List.empty(), (n) => n + 1)).toEqual(List.empty()) - expect(List.map(List.make(1, 2, 3, 4), (n) => n + 1)).toEqual(List.make(2, 3, 4, 5)) + deepStrictEqual(List.map(List.empty(), (n) => n + 1), List.empty()) + deepStrictEqual(List.map(List.make(1, 2, 3, 4), (n) => n + 1), List.make(2, 3, 4, 5)) }) it("mapWithIndex", () => { - expect(List.map(List.empty(), (n, i) => [i, n + 1])).toEqual(List.empty()) - expect(List.map(List.make(1, 2, 3, 4), (n, i) => [i, n ** 2])).toEqual(List.make([0, 1], [1, 4], [2, 9], [3, 16])) + deepStrictEqual(List.map(List.empty(), (n, i) => [i, n + 1]), List.empty()) + deepStrictEqual(List.map(List.make(1, 2, 3, 4), (n, i) => [i, n ** 2]), List.make([0, 1], [1, 4], [2, 9], [3, 16])) }) it("partition", () => { - expect(List.partition(List.make(1, 2, 3, 4), (n) => n > 2)).toEqual([ + deepStrictEqual(List.partition(List.make(1, 2, 3, 4), (n) => n > 2), [ List.make(1, 2), List.make(3, 4) ]) }) it("partitionMap", () => { - expect(List.partitionMap(List.make(1, 2, 3, 4), (n) => - n > 2 ? - Either.right(n) : - Either.left(n))).toEqual([List.make(1, 2), List.make(3, 4)]) + deepStrictEqual( + List.partitionMap(List.make(1, 2, 3, 4), (n) => + n > 2 ? + Either.right(n) : + Either.left(n)), + [List.make(1, 2), List.make(3, 4)] + ) }) it("prependAll", () => { - expect(List.prependAll(List.empty(), List.make(1, 2))).toEqual(List.make(1, 2)) - expect(List.prependAll(List.make(1, 2), List.empty())).toEqual(List.make(1, 2)) - expect(List.prependAll(List.make(3), List.make(1, 2))).toEqual(List.make(1, 2, 3)) + deepStrictEqual(List.prependAll(List.empty(), List.make(1, 2)), List.make(1, 2)) + deepStrictEqual(List.prependAll(List.make(1, 2), List.empty()), List.make(1, 2)) + deepStrictEqual(List.prependAll(List.make(3), List.make(1, 2)), List.make(1, 2, 3)) }) it("prependAllReversed", () => { - expect(List.prependAllReversed(List.empty(), List.make(1, 2))).toEqual(List.make(2, 1)) - expect(List.prependAllReversed(List.make(1, 2), List.empty())).toEqual(List.make(1, 2)) - expect(List.prependAllReversed(List.make(3), List.make(1, 2))).toEqual(List.make(2, 1, 3)) + deepStrictEqual(List.prependAllReversed(List.empty(), List.make(1, 2)), List.make(2, 1)) + deepStrictEqual(List.prependAllReversed(List.make(1, 2), List.empty()), List.make(1, 2)) + deepStrictEqual(List.prependAllReversed(List.make(3), List.make(1, 2)), List.make(2, 1, 3)) }) it("reduce", () => { - expect(List.reduce(List.empty(), "-", (b, a) => b + a)).toEqual("-") - expect(List.reduce(List.make("a", "b", "c"), "-", (b, a) => b + a)).toEqual("-abc") + deepStrictEqual(List.reduce(List.empty(), "-", (b, a) => b + a), "-") + deepStrictEqual(List.reduce(List.make("a", "b", "c"), "-", (b, a) => b + a), "-abc") }) it("reduceRight", () => { const f = (b: string, a: string) => b + a - expect(List.reduceRight(List.empty(), "", f)).toEqual("") - expect(List.reduceRight(List.make("a", "b", "c"), "", f)).toEqual("cba") + deepStrictEqual(List.reduceRight(List.empty(), "", f), "") + deepStrictEqual(List.reduceRight(List.make("a", "b", "c"), "", f), "cba") }) it("reverse", () => { - expect(List.reverse(List.empty())).toEqual(List.empty()) - expect(List.reverse(List.make(1, 2, 3))).toEqual(List.make(3, 2, 1)) + deepStrictEqual(List.reverse(List.empty()), List.empty()) + deepStrictEqual(List.reverse(List.make(1, 2, 3)), List.make(3, 2, 1)) }) it("toChunk", () => { - expect(List.toChunk(List.empty())).toEqual(Chunk.empty()) - expect(List.toChunk(List.make(1, 2, 3))).toEqual(Chunk.make(1, 2, 3)) + deepStrictEqual(List.toChunk(List.empty()), Chunk.empty()) + deepStrictEqual(List.toChunk(List.make(1, 2, 3)), Chunk.make(1, 2, 3)) }) it("toChunk", () => { - expect(() => List.unsafeHead(List.empty())).toThrowError(new Error("Expected List to be non-empty")) - expect(List.unsafeHead(List.make(1, 2, 3))).toEqual(1) + throws(() => List.unsafeHead(List.empty()), new Error("Expected List to be non-empty")) + deepStrictEqual(List.unsafeHead(List.make(1, 2, 3)), 1) }) it("some", () => { - expect(List.some(List.empty(), (n) => n > 2)).toEqual(false) - expect(List.some(List.make(1, 2), (n) => n > 2)).toEqual(false) - expect(List.some(List.make(2, 3), (n) => n > 2)).toEqual(true) - expect(List.some(List.make(3, 4), (n) => n > 2)).toEqual(true) + assertFalse(List.some(List.empty(), (n) => n > 2)) + assertFalse(List.some(List.make(1, 2), (n) => n > 2)) + assertTrue(List.some(List.make(2, 3), (n) => n > 2)) + assertTrue(List.some(List.make(3, 4), (n) => n > 2)) }) it("splitAt", () => { - expect(List.splitAt(List.make(1, 2, 3, 4), 2)).toEqual([List.make(1, 2), List.make(3, 4)]) + deepStrictEqual(List.splitAt(List.make(1, 2, 3, 4), 2), [List.make(1, 2), List.make(3, 4)]) }) it("take", () => { - expect(List.take(List.make(1, 2, 3, 4), 2)).toEqual(List.make(1, 2)) - expect(List.take(List.make(1, 2, 3, 4), 0)).toEqual(List.nil()) - expect(List.take(List.make(1, 2, 3, 4), -10)).toEqual(List.nil()) - expect(List.take(List.make(1, 2, 3, 4), 10)).toEqual(List.make(1, 2, 3, 4)) + deepStrictEqual(List.take(List.make(1, 2, 3, 4), 2), List.make(1, 2)) + deepStrictEqual(List.take(List.make(1, 2, 3, 4), 0), List.nil()) + deepStrictEqual(List.take(List.make(1, 2, 3, 4), -10), List.nil()) + deepStrictEqual(List.take(List.make(1, 2, 3, 4), 10), List.make(1, 2, 3, 4)) }) it("tail", () => { - expect(List.tail(List.empty())).toEqual(Option.none()) - expect(List.tail(List.make(1, 2, 3))).toEqual(Option.some(List.make(2, 3))) + assertNone(List.tail(List.empty())) + assertSome(List.tail(List.make(1, 2, 3)), List.make(2, 3)) }) it("unsafeLast", () => { - expect(() => List.unsafeLast(List.empty())).toThrowError( - new Error("Expected List to be non-empty") - ) - expect(List.unsafeLast(List.make(1, 2, 3, 4))).toEqual(4) + throws(() => List.unsafeLast(List.empty()), new Error("Expected List to be non-empty")) + strictEqual(List.unsafeLast(List.make(1, 2, 3, 4)), 4) }) it("unsafeTail", () => { - expect(() => List.unsafeTail(List.empty())).toThrowError( - new Error("Expected List to be non-empty") - ) - expect(List.unsafeTail(List.make(1, 2, 3, 4))).toEqual(List.make(2, 3, 4)) + throws(() => List.unsafeTail(List.empty()), new Error("Expected List to be non-empty")) + deepStrictEqual(List.unsafeTail(List.make(1, 2, 3, 4)), List.make(2, 3, 4)) }) it("pipe()", () => { - expect(List.empty().pipe(List.prepend("a"))).toEqual(List.make("a")) + deepStrictEqual(List.empty().pipe(List.prepend("a")), List.make("a")) }) it("toString", () => { - expect(String(List.empty())).toEqual(`{ + strictEqual( + String(List.empty()), + `{ "_id": "List", "_tag": "Nil" -}`) - expect(String(List.make(0, 1, 2))).toEqual(`{ +}` + ) + strictEqual( + String(List.make(0, 1, 2)), + `{ "_id": "List", "_tag": "Cons", "values": [ @@ -213,19 +208,18 @@ describe("List", () => { 1, 2 ] -}`) +}` + ) }) it("toJSON", () => { - expect(List.empty().toJSON()).toEqual( - { _id: "List", _tag: "Nil" } - ) - expect(List.make(0, 1, 2).toJSON()).toEqual( - { _id: "List", _tag: "Cons", values: [0, 1, 2] } - ) - expect(List.make(0, 1, List.empty()).toJSON()).toEqual( - { _id: "List", _tag: "Cons", values: [0, 1, { _id: "List", _tag: "Nil" }] } - ) + deepStrictEqual(List.empty().toJSON(), { _id: "List", _tag: "Nil" }) + deepStrictEqual(List.make(0, 1, 2).toJSON(), { _id: "List", _tag: "Cons", values: [0, 1, 2] }) + deepStrictEqual(List.make(0, 1, List.empty()).toJSON(), { + _id: "List", + _tag: "Cons", + values: [0, 1, { _id: "List", _tag: "Nil" }] + }) }) it("inspect", () => { @@ -234,93 +228,93 @@ describe("List", () => { } // eslint-disable-next-line @typescript-eslint/no-var-requires const { inspect } = require("node:util") - expect(inspect(List.empty())).toEqual(inspect({ _id: "List", _tag: "Nil" })) - expect(inspect(List.make(0, 1, 2))).toEqual(inspect({ _id: "List", _tag: "Cons", values: [0, 1, 2] })) + deepStrictEqual(inspect(List.empty()), inspect({ _id: "List", _tag: "Nil" })) + deepStrictEqual(inspect(List.make(0, 1, 2)), inspect({ _id: "List", _tag: "Cons", values: [0, 1, 2] })) }) it("equals", () => { - expect(List.empty()[symbol](List.empty())).toEqual(true) - expect(List.make(0)[symbol](List.make(0))).toEqual(true) - expect(List.empty()[symbol](Duration.millis(1))).toEqual(false) - expect(List.make(0)[symbol](Duration.millis(1))).toEqual(false) + assertTrue(List.empty()[symbol](List.empty())) + assertTrue(List.make(0)[symbol](List.make(0))) + assertFalse(List.empty()[symbol](Duration.millis(1))) + assertFalse(List.make(0)[symbol](Duration.millis(1))) - expect(equals(List.empty(), List.empty())).toEqual(true) - expect(equals(List.make(0), List.make(0))).toEqual(true) - expect(equals(List.empty(), Duration.millis(1))).toEqual(false) - expect(equals(List.make(0), Duration.millis(1))).toEqual(false) + assertTrue(equals(List.empty(), List.empty())) + assertTrue(equals(List.make(0), List.make(0))) + assertFalse(equals(List.empty(), Duration.millis(1))) + assertFalse(equals(List.make(0), Duration.millis(1))) }) it("to iterable", () => { - expect(Array.fromIterable(List.empty())).toEqual([]) - expect(Array.fromIterable(List.make(1, 2, 3))).toEqual([1, 2, 3]) + deepStrictEqual(Array.fromIterable(List.empty()), []) + deepStrictEqual(Array.fromIterable(List.make(1, 2, 3)), [1, 2, 3]) }) it("fromIterable", () => { - expect(List.fromIterable([])).toEqual(List.empty()) - expect(List.fromIterable([1, 2, 3])).toEqual(List.make(1, 2, 3)) + deepStrictEqual(List.fromIterable([]), List.empty()) + deepStrictEqual(List.fromIterable([1, 2, 3]), List.make(1, 2, 3)) }) it(".pipe", () => { - expect(List.empty().pipe(List.prepend(1))).toEqual(List.make(1)) - expect(List.make(2).pipe(List.prepend(1))).toEqual(List.make(1, 2)) + deepStrictEqual(List.empty().pipe(List.prepend(1)), List.make(1)) + deepStrictEqual(List.make(2).pipe(List.prepend(1)), List.make(1, 2)) }) it("getEquivalence", () => { const equivalence = List.getEquivalence(equals) - expect(equivalence(List.empty(), List.empty())).toEqual(true) - expect(equivalence(List.empty(), List.of(1))).toEqual(false) - expect(equivalence(List.of(1), List.empty())).toEqual(false) - expect(equivalence(List.of(1), List.of("a"))).toEqual(false) - expect(equivalence(List.make(1, 2, 3), List.make(1, 2))).toEqual(false) - expect(equivalence(List.make(1, 2), List.make(1, 2, 3))).toEqual(false) + assertTrue(equivalence(List.empty(), List.empty())) + assertFalse(equivalence(List.empty(), List.of(1))) + assertFalse(equivalence(List.of(1), List.empty())) + assertFalse(equivalence(List.of(1), List.of("a"))) + assertFalse(equivalence(List.make(1, 2, 3), List.make(1, 2))) + assertFalse(equivalence(List.make(1, 2), List.make(1, 2, 3))) }) it("compact", () => { - expect(List.compact(List.empty())).toEqual(List.empty()) - expect(List.compact(List.make(Option.some(1), Option.some(2), Option.some(3)))).toEqual(List.make(1, 2, 3)) - expect(List.compact(List.make(Option.some(1), Option.none(), Option.some(3)))).toEqual(List.make(1, 3)) + deepStrictEqual(List.compact(List.empty()), List.empty()) + deepStrictEqual(List.compact(List.make(Option.some(1), Option.some(2), Option.some(3))), List.make(1, 2, 3)) + deepStrictEqual(List.compact(List.make(Option.some(1), Option.none(), Option.some(3))), List.make(1, 3)) }) it("last", () => { - expect(List.last(List.empty())).toEqual(Option.none()) - expect(List.last(List.make(1, 2, 3))).toEqual(Option.some(3)) + assertNone(List.last(List.empty())) + assertSome(List.last(List.make(1, 2, 3)), 3) }) it("filter", () => { const isEven = (n: number) => n % 2 === 0 - expect(testStructuralSharing(List.filter(List.empty(), isEven), List.empty())).toBe(0) + strictEqual(testStructuralSharing(List.filter(List.empty(), isEven), List.empty()), 0) const share1 = List.of(2) const input1 = List.cons(1, share1) // 1, 2 const r1 = List.filter(input1, isEven) - expect(r1).toEqual(List.make(2)) - expect(testStructuralSharing(r1, share1)).toBe(0) + deepStrictEqual(r1, List.make(2)) + strictEqual(testStructuralSharing(r1, share1), 0) const share2 = List.make(2, 4) const input2 = List.cons(1, share2) // 1, 2, 4 const r2 = List.filter(input2, isEven) - expect(r2).toEqual(List.make(2, 4)) - expect(testStructuralSharing(r2, share2)).toBe(0) + deepStrictEqual(r2, List.make(2, 4)) + strictEqual(testStructuralSharing(r2, share2), 0) const input3 = List.cons(4, List.cons(3, share1)) // 4, 3, 2 const r3 = List.filter(input3, isEven) - expect(r3).toEqual(List.make(4, 2)) - expect(testStructuralSharing(r3, share1)).toBe(1) + deepStrictEqual(r3, List.make(4, 2)) + strictEqual(testStructuralSharing(r3, share1), 1) - expect(List.filter(List.make(2, 4, 1), isEven)).toEqual(List.make(2, 4)) - expect(List.filter(List.make(2, 4, 1, 3), isEven)).toEqual(List.make(2, 4)) - expect(List.filter(List.make(2, 4, 1, 6, 3), isEven)).toEqual(List.make(2, 4, 6)) + deepStrictEqual(List.filter(List.make(2, 4, 1), isEven), List.make(2, 4)) + deepStrictEqual(List.filter(List.make(2, 4, 1, 3), isEven), List.make(2, 4)) + deepStrictEqual(List.filter(List.make(2, 4, 1, 6, 3), isEven), List.make(2, 4, 6)) const share3 = List.of(6) const r4 = List.filter(List.appendAll(List.make(2, 4, 1, 3), share3), isEven) - expect(r4).toEqual(List.make(2, 4, 6)) - expect(testStructuralSharing(r4, share3)).toBe(2) + deepStrictEqual(r4, List.make(2, 4, 6)) + strictEqual(testStructuralSharing(r4, share3), 2) const r5 = List.filter(List.appendAll(List.make(2, 4, 1), share3), isEven) - expect(r5).toEqual(List.make(2, 4, 6)) - expect(testStructuralSharing(r5, share3)).toBe(2) + deepStrictEqual(r5, List.make(2, 4, 6)) + strictEqual(testStructuralSharing(r5, share3), 2) }) it("toArray", () => { - expect(List.toArray(List.empty())).toStrictEqual([]) - expect(List.toArray(List.make(1, 2, 3))).toStrictEqual([1, 2, 3]) + deepStrictEqual(List.toArray(List.empty()), []) + deepStrictEqual(List.toArray(List.make(1, 2, 3)), [1, 2, 3]) }) }) diff --git a/packages/effect/test/LogLevel.test.ts b/packages/effect/test/LogLevel.test.ts index 9d17e04f903..37d046a3b9e 100644 --- a/packages/effect/test/LogLevel.test.ts +++ b/packages/effect/test/LogLevel.test.ts @@ -1,15 +1,16 @@ import * as LogLevel from "effect/LogLevel" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("LogLevel", () => { it("fromLiteral", () => { - expect(LogLevel.fromLiteral("All")).toStrictEqual(LogLevel.All) - expect(LogLevel.fromLiteral("Debug")).toStrictEqual(LogLevel.Debug) - expect(LogLevel.fromLiteral("Error")).toStrictEqual(LogLevel.Error) - expect(LogLevel.fromLiteral("Fatal")).toStrictEqual(LogLevel.Fatal) - expect(LogLevel.fromLiteral("Info")).toStrictEqual(LogLevel.Info) - expect(LogLevel.fromLiteral("None")).toStrictEqual(LogLevel.None) - expect(LogLevel.fromLiteral("Trace")).toStrictEqual(LogLevel.Trace) - expect(LogLevel.fromLiteral("Warning")).toStrictEqual(LogLevel.Warning) + strictEqual(LogLevel.fromLiteral("All"), LogLevel.All) + strictEqual(LogLevel.fromLiteral("Debug"), LogLevel.Debug) + strictEqual(LogLevel.fromLiteral("Error"), LogLevel.Error) + strictEqual(LogLevel.fromLiteral("Fatal"), LogLevel.Fatal) + strictEqual(LogLevel.fromLiteral("Info"), LogLevel.Info) + strictEqual(LogLevel.fromLiteral("None"), LogLevel.None) + strictEqual(LogLevel.fromLiteral("Trace"), LogLevel.Trace) + strictEqual(LogLevel.fromLiteral("Warning"), LogLevel.Warning) }) }) diff --git a/packages/effect/test/Logger.test.ts b/packages/effect/test/Logger.test.ts index 2590e0c3f59..6f979de219c 100644 --- a/packages/effect/test/Logger.test.ts +++ b/packages/effect/test/Logger.test.ts @@ -1,25 +1,34 @@ -import * as Cause from "effect/Cause" -import * as Chunk from "effect/Chunk" -import * as Effect from "effect/Effect" -import * as FiberId from "effect/FiberId" -import * as FiberRefs from "effect/FiberRefs" -import { identity } from "effect/Function" -import * as HashMap from "effect/HashMap" +import { + Cause, + Chunk, + Effect, + FiberId, + FiberRefs, + HashMap, + identity, + List, + Logger, + LogLevel, + LogSpan, + pipe +} from "effect" import { logLevelInfo } from "effect/internal/core" -import * as List from "effect/List" -import * as Logger from "effect/Logger" -import * as LogLevel from "effect/LogLevel" -import * as LogSpan from "effect/LogSpan" -import { assert, describe, expect, it } from "effect/test/utils/extend" +import { assertFalse, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "effect/test/utils/extend" import { afterEach, beforeEach, vi } from "vitest" describe("Logger", () => { it("isLogger", () => { - expect(Logger.isLogger(Logger.stringLogger)).toBeTruthy() - expect(Logger.isLogger(Logger.logfmtLogger)).toBeTruthy() - expect(Logger.isLogger({})).toBeFalsy() - expect(Logger.isLogger(null)).toBeFalsy() - expect(Logger.isLogger(undefined)).toBeFalsy() + assertTrue(Logger.isLogger(Logger.stringLogger)) + assertTrue(Logger.isLogger(Logger.logfmtLogger)) + assertFalse(Logger.isLogger({})) + assertFalse(Logger.isLogger(null)) + assertFalse(Logger.isLogger(undefined)) + }) + + it(".pipe", () => { + strictEqual(Logger.stringLogger.pipe(identity), Logger.stringLogger) + strictEqual(logLevelInfo.pipe(identity), logLevelInfo) }) }) @@ -59,7 +68,7 @@ describe("withLeveledConsole", () => { Effect.withConsole(newConsole) ) - expect(logs).toEqual([ + deepStrictEqual(logs, [ { level: "info", value: "log plain" }, { level: "info", value: "log info" }, { level: "warn", value: "log warn" }, @@ -102,7 +111,8 @@ describe("stringLogger", () => { date }) - expect(result).toEqual( + strictEqual( + result, `timestamp=${date.toJSON()} level=INFO fiber= message="My message" imma_span__=7ms just_a_key=just_a_value good_key="I am a good value" good_bool=true I_am_bad_key_name="{ \\"coolValue\\": \\"cool value\\" }" good_number=123` @@ -131,7 +141,8 @@ describe("stringLogger", () => { date }) - expect(result).toEqual( + strictEqual( + result, `timestamp=${date.toJSON()} level=INFO fiber= message="My message" imma_span__=7ms I_am_also_a_bad_key_name="{ \\"return\\": \\"cool\\nvalue\\" @@ -157,13 +168,12 @@ with line breaks" good_key3="I_have=a"` date }) - expect(result).toEqual( - `timestamp=${date.toJSON()} level=INFO fiber= message=a message=b message=c` - ) + strictEqual(result, `timestamp=${date.toJSON()} level=INFO fiber= message=a message=b message=c`) }) }) -describe("logfmtLogger", () => { +// Adding sequential to the describe block because otherwise the "batched" test fails locally +describe.sequential("logfmtLogger", () => { beforeEach(() => { vi.useFakeTimers() }) @@ -192,7 +202,8 @@ describe("logfmtLogger", () => { date }) - expect(result).toEqual( + strictEqual( + result, `timestamp=${date.toJSON()} level=INFO fiber= message="My message" imma_span__=7ms just_a_key=just_a_value good_key="I am a good value" I_am_bad_key_name="{\\"coolValue\\":\\"cool value\\"}"` ) }) @@ -221,16 +232,12 @@ describe("logfmtLogger", () => { date }) - expect(result).toEqual( + strictEqual( + result, `timestamp=${date.toJSON()} level=INFO fiber= message="My\\nmessage" imma_span__=7ms I_am_also_a_bad_key_name="{\\"return\\":\\"cool\\\\nvalue\\"}" good_key="{\\"returnWithSpace\\":\\"cool\\\\nvalue or not\\"}" good_bool=true good_number=123 good_key2="I am a good value\\nwith line breaks" good_key3="I_have=a"` ) }) - it(".pipe", () => { - expect(Logger.stringLogger.pipe(identity)).toBe(Logger.stringLogger) - expect(logLevelInfo.pipe(identity)).toBe(logLevelInfo) - }) - it("objects", () => { const date = new Date() vi.setSystemTime(date) @@ -246,9 +253,7 @@ describe("logfmtLogger", () => { date }) - expect(result).toEqual( - `timestamp=${date.toJSON()} level=INFO fiber= message="{\\"hello\\":\\"world\\"}"` - ) + strictEqual(result, `timestamp=${date.toJSON()} level=INFO fiber= message="{\\"hello\\":\\"world\\"}"`) }) it("circular objects", () => { @@ -269,9 +274,7 @@ describe("logfmtLogger", () => { date }) - expect(result).toEqual( - `timestamp=${date.toJSON()} level=INFO fiber= message="{\\"hello\\":\\"world\\"}"` - ) + strictEqual(result, `timestamp=${date.toJSON()} level=INFO fiber= message="{\\"hello\\":\\"world\\"}"`) }) it("symbols", () => { @@ -289,9 +292,7 @@ describe("logfmtLogger", () => { date }) - expect(result).toEqual( - `timestamp=${date.toJSON()} level=INFO fiber= message=Symbol(effect/Logger/test)` - ) + strictEqual(result, `timestamp=${date.toJSON()} level=INFO fiber= message=Symbol(effect/Logger/test)`) }) it("functions", () => { @@ -309,9 +310,7 @@ describe("logfmtLogger", () => { date }) - expect(result).toEqual( - `timestamp=${date.toJSON()} level=INFO fiber= message="() => \\"hello world\\""` - ) + strictEqual(result, `timestamp=${date.toJSON()} level=INFO fiber= message="() => \\"hello world\\""`) }) it("annotations", () => { @@ -331,21 +330,22 @@ describe("logfmtLogger", () => { date }) - expect(result).toEqual( + strictEqual( + result, `timestamp=${date.toJSON()} level=INFO fiber= message="hello world" hashmap="{\\"_id\\":\\"HashMap\\",\\"values\\":[[\\"key\\",2]]}" chunk="{\\"_id\\":\\"Chunk\\",\\"values\\":[1,2]}"` ) }) it("batched", () => - Effect.gen(function*(_) { - const chunks: Array> = [] + Effect.gen(function*() { + const state: Array> = [] const date = new Date() vi.setSystemTime(date) - const logger = yield* _( + const logger = yield* pipe( Logger.logfmtLogger, - Logger.batched("100 millis", (_) => + Logger.batched("100 millis", (strings) => Effect.sync(() => { - chunks.push(_) + state.push(strings) })) ) const log = (message: string) => @@ -363,12 +363,12 @@ describe("logfmtLogger", () => { log("a") log("b") log("c") - yield* _(Effect.promise(() => vi.advanceTimersByTimeAsync(100))) + yield* Effect.promise(() => vi.advanceTimersByTimeAsync(100)) log("d") log("e") - yield* _(Effect.promise(() => vi.advanceTimersByTimeAsync(100))) + yield* Effect.promise(() => vi.advanceTimersByTimeAsync(100)) - assert.deepStrictEqual(chunks, [ + deepStrictEqual(state, [ [ `timestamp=${date.toISOString()} level=INFO fiber= message=a`, `timestamp=${date.toISOString()} level=INFO fiber= message=b`, @@ -396,9 +396,7 @@ describe("logfmtLogger", () => { date }) - expect(result).toEqual( - `timestamp=${date.toJSON()} level=INFO fiber= message=a message=b message=c` - ) + strictEqual(result, `timestamp=${date.toJSON()} level=INFO fiber= message=a message=b message=c`) }) }) @@ -433,7 +431,8 @@ describe("jsonLogger", () => { date }) - expect(result).toEqual( + strictEqual( + result, JSON.stringify({ message: "My message", logLevel: "INFO", @@ -466,14 +465,17 @@ describe("jsonLogger", () => { date }) - expect(result).toEqual(JSON.stringify({ - message: { hello: "world" }, - logLevel: "INFO", - timestamp: date.toJSON(), - annotations: {}, - spans: {}, - fiberId: "" - })) + strictEqual( + result, + JSON.stringify({ + message: { hello: "world" }, + logLevel: "INFO", + timestamp: date.toJSON(), + annotations: {}, + spans: {}, + fiberId: "" + }) + ) }) it("circular objects", () => { @@ -494,14 +496,17 @@ describe("jsonLogger", () => { date }) - expect(result).toEqual(JSON.stringify({ - message: { hello: "world" }, - logLevel: "INFO", - timestamp: date.toJSON(), - annotations: {}, - spans: {}, - fiberId: "" - })) + strictEqual( + result, + JSON.stringify({ + message: { hello: "world" }, + logLevel: "INFO", + timestamp: date.toJSON(), + annotations: {}, + spans: {}, + fiberId: "" + }) + ) }) it("symbols", () => { @@ -519,14 +524,17 @@ describe("jsonLogger", () => { date }) - expect(result).toEqual(JSON.stringify({ - message: Symbol.for("effect/Logger/test").toString(), - logLevel: "INFO", - timestamp: date.toJSON(), - annotations: {}, - spans: {}, - fiberId: "" - })) + strictEqual( + result, + JSON.stringify({ + message: Symbol.for("effect/Logger/test").toString(), + logLevel: "INFO", + timestamp: date.toJSON(), + annotations: {}, + spans: {}, + fiberId: "" + }) + ) }) it("functions", () => { @@ -544,13 +552,16 @@ describe("jsonLogger", () => { date }) - expect(result).toEqual(JSON.stringify({ - message: "() => \"hello world\"", - logLevel: "INFO", - timestamp: date.toJSON(), - annotations: {}, - spans: {}, - fiberId: "" - })) + strictEqual( + result, + JSON.stringify({ + message: "() => \"hello world\"", + logLevel: "INFO", + timestamp: date.toJSON(), + annotations: {}, + spans: {}, + fiberId: "" + }) + ) }) }) diff --git a/packages/effect/test/Mailbox.test.ts b/packages/effect/test/Mailbox.test.ts index 7e7c73e1bb3..5f34c1bf0c6 100644 --- a/packages/effect/test/Mailbox.test.ts +++ b/packages/effect/test/Mailbox.test.ts @@ -1,5 +1,6 @@ -import { Chunk, Effect, Exit, Fiber, Mailbox, Option, Stream } from "effect" -import { assert, describe, it } from "effect/test/utils/extend" +import { Chunk, Effect, Exit, Fiber, Mailbox, Stream } from "effect" +import { assertFalse, assertNone, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "effect/test/utils/extend" describe("Mailbox", () => { it.effect("offerAll with capacity", () => @@ -9,41 +10,41 @@ describe("Mailbox", () => { Effect.fork ) yield* Effect.yieldNow({ priority: 1 }) - assert.isNull(fiber.unsafePoll()) + assertTrue(fiber.unsafePoll() === null) let result = yield* mailbox - assert.deepStrictEqual(Chunk.toReadonlyArray(result[0]), [1, 2]) - assert.isFalse(result[1]) + deepStrictEqual(Chunk.toReadonlyArray(result[0]), [1, 2]) + assertFalse(result[1]) yield* Effect.yieldNow({ priority: 1 }) - assert.isNotNull(fiber.unsafePoll()) + assertTrue(fiber.unsafePoll() !== null) result = yield* mailbox.takeAll - assert.deepStrictEqual(Chunk.toReadonlyArray(result[0]), [3, 4]) - assert.isFalse(result[1]) + deepStrictEqual(Chunk.toReadonlyArray(result[0]), [3, 4]) + assertFalse(result[1]) yield* Effect.yieldNow({ priority: 1 }) - assert.deepStrictEqual(fiber.unsafePoll(), Exit.succeed(Chunk.empty())) + deepStrictEqual(fiber.unsafePoll(), Exit.succeed(Chunk.empty())) })) it.effect("offer dropping", () => Effect.gen(function*() { const mailbox = yield* Mailbox.make({ capacity: 2, strategy: "dropping" }) const remaining = yield* mailbox.offerAll([1, 2, 3, 4]) - assert.deepStrictEqual(Chunk.toReadonlyArray(remaining), [3, 4]) + deepStrictEqual(Chunk.toReadonlyArray(remaining), [3, 4]) const result = yield* mailbox.offer(5) - assert.isFalse(result) - assert.deepStrictEqual(Chunk.toReadonlyArray((yield* mailbox.takeAll)[0]), [1, 2]) + assertFalse(result) + deepStrictEqual(Chunk.toReadonlyArray((yield* mailbox.takeAll)[0]), [1, 2]) })) it.effect("offer sliding", () => Effect.gen(function*() { const mailbox = yield* Mailbox.make({ capacity: 2, strategy: "sliding" }) const remaining = yield* mailbox.offerAll([1, 2, 3, 4]) - assert.deepStrictEqual(Chunk.toReadonlyArray(remaining), []) + deepStrictEqual(Chunk.toReadonlyArray(remaining), []) const result = yield* mailbox.offer(5) - assert.isTrue(result) - assert.deepStrictEqual(Chunk.toReadonlyArray((yield* mailbox.takeAll)[0]), [4, 5]) + assertTrue(result) + deepStrictEqual(Chunk.toReadonlyArray((yield* mailbox.takeAll)[0]), [4, 5]) })) it.effect("offerAll can be interrupted", () => @@ -58,15 +59,15 @@ describe("Mailbox", () => { yield* Effect.yieldNow({ priority: 1 }) let result = yield* mailbox.takeAll - assert.deepStrictEqual(Chunk.toReadonlyArray(result[0]), [1, 2]) - assert.isFalse(result[1]) + deepStrictEqual(Chunk.toReadonlyArray(result[0]), [1, 2]) + assertFalse(result[1]) yield* mailbox.offer(5) yield* Effect.yieldNow({ priority: 1 }) result = yield* mailbox.takeAll - assert.deepStrictEqual(Chunk.toReadonlyArray(result[0]), [5]) - assert.isFalse(result[1]) + deepStrictEqual(Chunk.toReadonlyArray(result[0]), [5]) + assertFalse(result[1]) })) it.effect("done completes takes", () => @@ -77,7 +78,7 @@ describe("Mailbox", () => { ) yield* Effect.yieldNow() yield* mailbox.done(Exit.void) - assert.deepStrictEqual(yield* fiber.await, Exit.succeed([Chunk.empty(), true] as const)) + deepStrictEqual(yield* fiber.await, Exit.succeed([Chunk.empty(), true] as const)) })) it.effect("end", () => @@ -88,9 +89,9 @@ describe("Mailbox", () => { yield* Effect.fork(mailbox.offer(9)) yield* Effect.fork(mailbox.end) const items = yield* Stream.runCollect(Mailbox.toStream(mailbox)) - assert.deepStrictEqual(Chunk.toReadonlyArray(items), [1, 2, 3, 4, 5, 6, 7, 8, 9]) - assert.strictEqual(yield* mailbox.await, void 0) - assert.strictEqual(yield* mailbox.offer(10), false) + deepStrictEqual(Chunk.toReadonlyArray(items), [1, 2, 3, 4, 5, 6, 7, 8, 9]) + strictEqual(yield* mailbox.await, void 0) + strictEqual(yield* mailbox.offer(10), false) })) it.effect("end with take", () => @@ -99,12 +100,12 @@ describe("Mailbox", () => { yield* Effect.fork(mailbox.offerAll([1, 2])) yield* Effect.fork(mailbox.offer(3)) yield* Effect.fork(mailbox.end) - assert.strictEqual(yield* mailbox.take, 1) - assert.strictEqual(yield* mailbox.take, 2) - assert.strictEqual(yield* mailbox.take, 3) - assert.strictEqual(yield* mailbox.take.pipe(Effect.optionFromOptional), Option.none()) - assert.strictEqual(yield* mailbox.await, void 0) - assert.strictEqual(yield* mailbox.offer(10), false) + strictEqual(yield* mailbox.take, 1) + strictEqual(yield* mailbox.take, 2) + strictEqual(yield* mailbox.take, 3) + assertNone(yield* mailbox.take.pipe(Effect.optionFromOptional)) + strictEqual(yield* mailbox.await, void 0) + strictEqual(yield* mailbox.offer(10), false) })) it.effect("fail", () => @@ -114,15 +115,15 @@ describe("Mailbox", () => { yield* Effect.fork(mailbox.offer(5)) yield* Effect.fork(mailbox.fail("boom")) const takeArr = Effect.map(mailbox.takeAll, ([_]) => Chunk.toReadonlyArray(_)) - assert.deepStrictEqual(yield* takeArr, [1, 2]) - assert.deepStrictEqual(yield* takeArr, [3, 4]) + deepStrictEqual(yield* takeArr, [1, 2]) + deepStrictEqual(yield* takeArr, [3, 4]) const [items, done] = yield* mailbox.takeAll - assert.deepStrictEqual(Chunk.toReadonlyArray(items), [5]) - assert.strictEqual(done, false) + deepStrictEqual(Chunk.toReadonlyArray(items), [5]) + strictEqual(done, false) const error = yield* mailbox.takeAll.pipe(Effect.flip) - assert.deepStrictEqual(error, "boom") - assert.strictEqual(yield* mailbox.await.pipe(Effect.flip), "boom") - assert.strictEqual(yield* mailbox.offer(6), false) + deepStrictEqual(error, "boom") + strictEqual(yield* mailbox.await.pipe(Effect.flip), "boom") + strictEqual(yield* mailbox.offer(6), false) })) it.effect("shutdown", () => @@ -132,9 +133,9 @@ describe("Mailbox", () => { yield* Effect.fork(mailbox.offerAll([5, 6, 7, 8])) yield* Effect.fork(mailbox.shutdown) const items = yield* Stream.runCollect(Mailbox.toStream(mailbox)) - assert.deepStrictEqual(Chunk.toReadonlyArray(items), []) - assert.strictEqual(yield* mailbox.await, void 0) - assert.strictEqual(yield* mailbox.offer(10), false) + deepStrictEqual(Chunk.toReadonlyArray(items), []) + strictEqual(yield* mailbox.await, void 0) + strictEqual(yield* mailbox.offer(10), false) })) it.effect("fail doesnt drop items", () => @@ -148,8 +149,8 @@ describe("Mailbox", () => { Stream.runForEach((item) => Effect.sync(() => items.push(item))), Effect.flip ) - assert.deepStrictEqual(items, [1, 2, 3, 4, 5]) - assert.strictEqual(error, "boom") + deepStrictEqual(items, [1, 2, 3, 4, 5]) + strictEqual(error, "boom") })) it.effect("await waits for no items", () => @@ -161,12 +162,12 @@ describe("Mailbox", () => { yield* mailbox.end yield* Effect.yieldNow() - assert.isNull(fiber.unsafePoll()) + assertTrue(fiber.unsafePoll() === null) const [result, done] = yield* mailbox.takeAll - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [1]) - assert.isTrue(done) + deepStrictEqual(Chunk.toReadonlyArray(result), [1]) + assertTrue(done) yield* Effect.yieldNow() - assert.isNotNull(fiber.unsafePoll()) + assertTrue(fiber.unsafePoll() !== null) })) it.effect("bounded 0 capacity", () => @@ -174,11 +175,11 @@ describe("Mailbox", () => { const mailbox = yield* Mailbox.make(0) yield* mailbox.offer(1).pipe(Effect.fork) let result = yield* mailbox.take - assert.strictEqual(result, 1) + strictEqual(result, 1) const fiber = yield* mailbox.take.pipe(Effect.fork) yield* mailbox.offer(2) result = yield* Fiber.join(fiber) - assert.strictEqual(result, 2) + strictEqual(result, 2) })) }) diff --git a/packages/effect/test/ManagedRuntime.test.ts b/packages/effect/test/ManagedRuntime.test.ts index 4c92236f79c..7b80d9445a9 100644 --- a/packages/effect/test/ManagedRuntime.test.ts +++ b/packages/effect/test/ManagedRuntime.test.ts @@ -3,9 +3,10 @@ import * as Context from "effect/Context" import * as Effect from "effect/Effect" import * as FiberRef from "effect/FiberRef" import * as Layer from "effect/Layer" -import { assert, describe, it, test } from "effect/test/utils/extend" +import { deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it, test } from "effect/test/utils/extend" -describe.concurrent("ManagedRuntime", () => { +describe("ManagedRuntime", () => { test("memoizes the layer build", async () => { let count = 0 const layer = Layer.effectDiscard(Effect.sync(() => { @@ -15,7 +16,7 @@ describe.concurrent("ManagedRuntime", () => { await runtime.runPromise(Effect.void) await runtime.runPromise(Effect.void) await runtime.dispose() - assert.strictEqual(count, 1) + strictEqual(count, 1) }) test("provides context", async () => { @@ -24,7 +25,7 @@ describe.concurrent("ManagedRuntime", () => { const runtime = ManagedRuntime.make(layer) const result = await runtime.runPromise(tag) await runtime.dispose() - assert.strictEqual(result, "test") + strictEqual(result, "test") }) test("provides fiberRefs", async () => { @@ -32,7 +33,7 @@ describe.concurrent("ManagedRuntime", () => { const runtime = ManagedRuntime.make(layer) const result = await runtime.runPromise(FiberRef.get(FiberRef.currentRequestCacheEnabled)) await runtime.dispose() - assert.strictEqual(result, true) + strictEqual(result, true) }) test("allows sharing a MemoMap", async () => { @@ -46,7 +47,7 @@ describe.concurrent("ManagedRuntime", () => { await runtimeB.runPromise(Effect.void) await runtimeA.dispose() await runtimeB.dispose() - assert.strictEqual(count, 1) + strictEqual(count, 1) }) it.effect("is subtype of effect", () => @@ -56,7 +57,7 @@ describe.concurrent("ManagedRuntime", () => { const managedRuntime = ManagedRuntime.make(layer) const runtime = yield* managedRuntime const result = Context.get(runtime.context, tag) - assert.strictEqual(result, "test") + strictEqual(result, "test") })) it.effect("does not inherit fiber refs", () => @@ -68,7 +69,7 @@ describe.concurrent("ManagedRuntime", () => { Effect.withLogSpan("test") ) const result = FiberRefs.getOrDefault(runtime.fiberRefs, FiberRef.currentLogSpan) - assert.deepStrictEqual(result, List.empty()) + deepStrictEqual(result, List.empty()) })) it("can be build synchronously", () => { @@ -77,6 +78,6 @@ describe.concurrent("ManagedRuntime", () => { const managedRuntime = ManagedRuntime.make(layer) const runtime = Effect.runSync(managedRuntime.runtimeEffect) const result = Context.get(runtime.context, tag) - assert.strictEqual(result, "test") + strictEqual(result, "test") }) }) diff --git a/packages/effect/test/Match.test.ts b/packages/effect/test/Match.test.ts index 9f4af937436..b44c9f84ad8 100644 --- a/packages/effect/test/Match.test.ts +++ b/packages/effect/test/Match.test.ts @@ -3,8 +3,9 @@ import { pipe } from "effect/Function" import * as M from "effect/Match" import * as O from "effect/Option" import * as Predicate from "effect/Predicate" +import { assertFalse, assertLeft, assertRight, assertSome, assertTrue, strictEqual } from "effect/test/util" import { assertType } from "effect/test/utils/types" -import { describe, expect, it } from "vitest" +import { describe, it } from "vitest" describe("Match", () => { it("exhaustive", () => { @@ -14,8 +15,8 @@ describe("Match", () => { M.when({ b: M.number }, (_) => _.b), M.exhaustive ) - expect(match({ a: 0 })).toBe(0) - expect(match({ b: 1 })).toBe(1) + strictEqual(match({ a: 0 }), 0) + strictEqual(match({ b: 1 }), 1) }) it("exhaustive-literal", () => { @@ -25,8 +26,8 @@ describe("Match", () => { M.when({ _tag: "B" }, (_) => E.right(_.b)), M.exhaustive ) - expect(match({ _tag: "A", a: 0 })).toEqual(E.right(0)) - expect(match({ _tag: "B", b: 1 })).toEqual(E.right(1)) + assertRight(match({ _tag: "A", a: 0 }), 0) + assertRight(match({ _tag: "B", b: 1 }), 1) }) it("schema exhaustive-literal", () => { @@ -45,9 +46,9 @@ describe("Match", () => { throw "absurd" }) ) - expect(match({ _tag: "A", a: 0 })).toEqual(E.right("A")) - expect(match({ _tag: "A", a: "hi" })).toEqual(E.right("A")) - expect(match({ _tag: "B", b: 1 })).toEqual(E.left("B")) + assertRight(match({ _tag: "A", a: 0 }), "A") + assertRight(match({ _tag: "A", a: "hi" }), "A") + assertLeft(match({ _tag: "B", b: 1 }), "B") }) it("exhaustive literal with not", () => { @@ -57,8 +58,8 @@ describe("Match", () => { M.not(1, (_) => false), M.exhaustive ) - expect(match(1)).toEqual(true) - expect(match(2)).toEqual(false) + assertTrue(match(1)) + assertFalse(match(2)) }) it("inline", () => { @@ -68,7 +69,7 @@ describe("Match", () => { M.tag("Left", (_) => _.left), M.exhaustive ) - expect(result).toEqual(0) + strictEqual(result, 0) }) it("piped", () => { @@ -78,7 +79,7 @@ describe("Match", () => { M.when({ _tag: "Right" }, (_) => _.right), M.option ) - expect(result).toEqual(O.some(0)) + assertSome(result, 0) }) it("tuples", () => { @@ -91,7 +92,7 @@ describe("Match", () => { M.option ) - expect(match(["yeah", "a"])).toEqual(O.some(true)) + assertSome(match(["yeah", "a"]), true) }) it("literals", () => { @@ -101,8 +102,8 @@ describe("Match", () => { M.orElse(() => "nah") ) - expect(match("yeah")).toEqual(true) - expect(match("a")).toEqual("nah") + strictEqual(match("yeah"), true) + strictEqual(match("a"), "nah") }) it("piped", () => { @@ -112,7 +113,7 @@ describe("Match", () => { M.when({ _tag: "Right" }, (_) => _.right), M.option ) - expect(result).toEqual(O.some(0)) + assertSome(result, 0) }) it("not schema", () => { @@ -122,8 +123,8 @@ describe("Match", () => { M.when(M.number, (_) => "b"), M.exhaustive ) - expect(match("hi")).toEqual("a") - expect(match(123)).toEqual("b") + strictEqual(match("hi"), "a") + strictEqual(match(123), "b") }) it("not literal", () => { @@ -135,8 +136,8 @@ describe("Match", () => { }), M.orElse((_) => "b") ) - expect(match("hello")).toEqual("a") - expect(match("hi")).toEqual("b") + strictEqual(match("hello"), "a") + strictEqual(match("hi"), "b") }) it("tuples", () => { @@ -149,7 +150,7 @@ describe("Match", () => { M.option ) - expect(match(["yeah", "a"])).toEqual(O.some(true)) + assertSome(match(["yeah", "a"]), true) }) it("literals", () => { @@ -162,8 +163,8 @@ describe("Match", () => { M.orElse(() => "nah") ) - expect(match("yeah")).toEqual(true) - expect(match("a")).toEqual("nah") + strictEqual(match("yeah"), true) + strictEqual(match("a"), "nah") }) it("literals duplicate", () => { @@ -174,7 +175,7 @@ describe("Match", () => { M.orElse((_) => "nah") ) - expect(result).toEqual(true) + strictEqual(result, true) }) it("discriminator", () => { @@ -184,7 +185,7 @@ describe("Match", () => { M.discriminator("type")("B", (_) => _.type), M.exhaustive ) - expect(match({ type: "B" })).toEqual("B") + strictEqual(match({ type: "B" }), "B") }) it("discriminator multiple", () => { @@ -193,7 +194,7 @@ describe("Match", () => { M.discriminator("_tag")("Right", "Left", (_) => "match"), M.exhaustive ) - expect(result).toEqual("match") + strictEqual(result, "match") }) it("nested", () => { @@ -223,11 +224,11 @@ describe("Match", () => { M.exhaustive ) - expect(match({ foo: { bar: { baz: { qux: 1 } } } })).toEqual(1) - expect(match({ foo: { bar: { baz: { qux: 2 } } } })).toEqual("literal 2") - expect(match({ foo: { bar: { baz: { qux: "a" } } } })).toEqual("a") - expect(match({ foo: { bar: { baz: { qux: "b" } } } })).toEqual("literal b") - expect(match({ foo: { bar: null } })).toEqual(null) + strictEqual(match({ foo: { bar: { baz: { qux: 1 } } } }), 1) + strictEqual(match({ foo: { bar: { baz: { qux: 2 } } } }), "literal 2") + strictEqual(match({ foo: { bar: { baz: { qux: "a" } } } }), "a") + strictEqual(match({ foo: { bar: { baz: { qux: "b" } } } }), "literal b") + strictEqual(match({ foo: { bar: null } }), null) }) it("nested Option", () => { @@ -237,8 +238,8 @@ describe("Match", () => { M.orElse((_) => "fail") ) - expect(match({ user: O.some({ name: "a" }) })).toEqual("a") - expect(match({ user: O.none() })).toEqual("fail") + strictEqual(match({ user: O.some({ name: "a" }) }), "a") + strictEqual(match({ user: O.none() }), "fail") }) it("predicate", () => { @@ -248,8 +249,8 @@ describe("Match", () => { M.orElse((_) => `${_.age} is too young`) ) - expect(match({ age: 5 })).toEqual("Age: 5") - expect(match({ age: 4 })).toEqual("4 is too young") + strictEqual(match({ age: 5 }), "Age: 5") + strictEqual(match({ age: 4 }), "4 is too young") }) it("predicate not", () => { @@ -259,8 +260,8 @@ describe("Match", () => { M.orElse((_) => `${_.age} is too old`) ) - expect(match({ age: 4 })).toEqual("Age: 4") - expect(match({ age: 5 })).toEqual("5 is too old") + strictEqual(match({ age: 4 }), "Age: 4") + strictEqual(match({ age: 5 }), "5 is too old") }) it("predicate with functions", () => { @@ -277,8 +278,8 @@ describe("Match", () => { M.orElse(() => "fail") ) - expect(match({ b: { c: "nested" }, a: 200 })).toEqual("nested") - expect(match({ b: { c: "nested" }, a: 400 })).toEqual("400") + strictEqual(match({ b: { c: "nested" }, a: 200 }), "nested") + strictEqual(match({ b: { c: "nested" }, a: 400 }), "400") }) it("predicate at root level", () => { @@ -298,8 +299,8 @@ describe("Match", () => { M.orElse(() => "fail") ) - expect(match({ b: { c: "nested" }, a: 200 })).toEqual("nested") - expect(match({ b: { c: "nested" }, a: 400 })).toEqual("400") + strictEqual(match({ b: { c: "nested" }, a: 200 }), "nested") + strictEqual(match({ b: { c: "nested" }, a: 400 }), "400") }) it("symbols", () => { @@ -314,7 +315,7 @@ describe("Match", () => { M.exhaustive ) - expect(match).toEqual("thing") + strictEqual(match, "thing") }) it("unify", () => { @@ -325,7 +326,7 @@ describe("Match", () => { M.exhaustive ) - expect(match({ _tag: "B" })).toEqual(E.right(123)) + assertRight(match({ _tag: "B" }), 123) }) it("optional props", () => { @@ -335,9 +336,9 @@ describe("Match", () => { M.orElse(() => "no user") ) - expect(match({})).toEqual("no user") - expect(match({ user: undefined })).toEqual(undefined) - expect(match({ user: { name: "Tim" } })).toEqual("Tim") + strictEqual(match({}), "no user") + strictEqual(match({ user: undefined }), undefined) + strictEqual(match({ user: { name: "Tim" } }), "Tim") }) it("optional props defined", () => { @@ -347,10 +348,10 @@ describe("Match", () => { M.orElse(() => "no user") ) - expect(match({})).toEqual("no user") - expect(match({ user: undefined })).toEqual("no user") - expect(match({ user: null })).toEqual("no user") - expect(match({ user: { name: "Tim" } })).toEqual("Tim") + strictEqual(match({}), "no user") + strictEqual(match({ user: undefined }), "no user") + strictEqual(match({ user: null }), "no user") + strictEqual(match({ user: { name: "Tim" } }), "Tim") }) it("deep recursive", () => { @@ -398,10 +399,10 @@ describe("Match", () => { M.exhaustive ) - expect(match(null)).toEqual("null") - expect(match(123)).toEqual("number") - expect(match("hi")).toEqual("string") - expect(match({})).toEqual("record") + strictEqual(match(null), "null") + strictEqual(match(123), "number") + strictEqual(match("hi"), "string") + strictEqual(match({}), "record") }) it("nested option", () => { @@ -416,9 +417,9 @@ describe("Match", () => { M.orElse((_) => "no match") ) - expect(match({ abc: O.some({ _tag: "A" }) })).toEqual("A") - expect(match({ abc: O.some({ _tag: "B" }) })).toEqual("no match") - expect(match({ abc: O.none() })).toEqual("no match") + strictEqual(match({ abc: O.some({ _tag: "A" }) }), "A") + strictEqual(match({ abc: O.some({ _tag: "B" }) }), "no match") + strictEqual(match({ abc: O.none() }), "no match") }) it("getters", () => { @@ -434,7 +435,7 @@ describe("Match", () => { M.orElse(() => "fail") ) - expect(match).toEqual("thing") + strictEqual(match, "thing") }) it("whenOr", () => { @@ -446,9 +447,9 @@ describe("Match", () => { M.when({ _tag: "C" }, (_) => "C"), M.exhaustive ) - expect(match({ _tag: "A", a: 0 })).toEqual("A or B") - expect(match({ _tag: "B", b: 1 })).toEqual("A or B") - expect(match({ _tag: "C" })).toEqual("C") + strictEqual(match({ _tag: "A", a: 0 }), "A or B") + strictEqual(match({ _tag: "B", b: 1 }), "A or B") + strictEqual(match({ _tag: "C" }), "C") }) it("optional array", () => { @@ -458,9 +459,9 @@ describe("Match", () => { M.orElse(() => "no match") ) - expect(match({ a: [{ name: "Tim" }] })).toEqual("match 1") - expect(match({ a: [] })).toEqual("no match") - expect(match({})).toEqual("no match") + strictEqual(match({ a: [{ name: "Tim" }] }), "match 1") + strictEqual(match({ a: [] }), "no match") + strictEqual(match({}), "no match") }) it("whenAnd", () => { @@ -473,9 +474,9 @@ describe("Match", () => { M.when({ _tag: "C" }, (_) => "C"), M.exhaustive ) - expect(match({ _tag: "A", a: 0 })).toEqual("A") - expect(match({ _tag: "B", b: 1 })).toEqual("B") - expect(match({ _tag: "C" })).toEqual("C") + strictEqual(match({ _tag: "A", a: 0 }), "A") + strictEqual(match({ _tag: "B", b: 1 }), "B") + strictEqual(match({ _tag: "C" }), "C") }) it("whenAnd nested", () => { @@ -521,35 +522,39 @@ describe("Match", () => { M.when({ status: M.number }, (_) => "number"), M.exhaustive ) - expect( + strictEqual( match({ status: 200, user: { name: "Tim", manager: { name: "Joe" } }, company: { name: "Apple" } - }) - ).toEqual("200, Tim, Joe, Apple") - expect( + }), + "200, Tim, Joe, Apple" + ) + strictEqual( match({ status: 200, user: { name: "Tim" }, company: { name: "Apple" } - }) - ).toEqual("200, Tim, Apple") - expect( + }), + "200, Tim, Apple" + ) + strictEqual( match({ status: 200, user: { name: "Tim" }, company: { name: "Apple" } - }) - ).toEqual("200, Tim, Apple") - expect( + }), + "200, Tim, Apple" + ) + strictEqual( match({ status: 200, user: { name: "Tim" } - }) - ).toEqual("200, Tim") - expect(match({ status: 100, user: { name: "Tim" } })).toEqual("number, Tim") - expect(match({ status: 100 })).toEqual("number") + }), + "200, Tim" + ) + strictEqual(match({ status: 100, user: { name: "Tim" } }), "number, Tim") + strictEqual(match({ status: 100 }), "number") }) it("instanceOf", () => { @@ -568,8 +573,8 @@ describe("Match", () => { }) ) - expect(match(new Uint8Array([1, 2, 3]))).toEqual("uint8") - expect(match(new Uint16Array([1, 2, 3]))).toEqual("uint16") + strictEqual(match(new Uint8Array([1, 2, 3])), "uint8") + strictEqual(match(new Uint16Array([1, 2, 3])), "uint16") }) it("instanceOf doesnt modify type", () => { @@ -587,7 +592,7 @@ describe("Match", () => { M.orElse(() => 0) ) - expect(result).toEqual(1) + strictEqual(result, 1) }) it("tags", () => { @@ -600,8 +605,8 @@ describe("Match", () => { M.exhaustive ) - expect(match({ _tag: "A", a: 1 })).toEqual(1) - expect(match({ _tag: "B", b: 1 })).toEqual("B") + strictEqual(match({ _tag: "A", a: 1 }), 1) + strictEqual(match({ _tag: "B", b: 1 }), "B") }) it("tagsExhaustive", () => { @@ -613,8 +618,8 @@ describe("Match", () => { }) ) - expect(match({ _tag: "A", a: 1 })).toEqual(1) - expect(match({ _tag: "B", b: 1 })).toEqual("B") + strictEqual(match({ _tag: "A", a: 1 }), 1) + strictEqual(match({ _tag: "B", b: 1 }), "B") }) it("valueTags", () => { @@ -627,26 +632,28 @@ describe("Match", () => { }) ) - expect(match).toEqual(123) + strictEqual(match, 123) }) it("typeTags", () => { type Value = { _tag: "A"; a: number } | { _tag: "B"; b: number } const matcher = M.typeTags() - expect( + strictEqual( matcher({ A: (_) => _.a, B: (_) => "fail" - })({ _tag: "A", a: 123 }) - ).toEqual(123) + })({ _tag: "A", a: 123 }), + 123 + ) - expect( + strictEqual( matcher({ A: (_) => _.a, B: (_) => "B" - })({ _tag: "B", b: 123 }) - ).toEqual("B") + })({ _tag: "B", b: 123 }), + "B" + ) }) it("refinement - with unknown", () => { @@ -662,8 +669,8 @@ describe("Match", () => { M.exhaustive ) - expect(match([])).toEqual("array") - expect(match("fail")).toEqual("string") + strictEqual(match([]), "array") + strictEqual(match("fail"), "string") }) it("refinement nested - with unknown", () => { @@ -678,8 +685,8 @@ describe("Match", () => { M.orElse(() => "fail") ) - expect(match({ a: [123] })).toEqual("array") - expect(match({ a: "fail" })).toEqual("fail") + strictEqual(match({ a: [123] }), "array") + strictEqual(match({ a: "fail" }), "fail") }) it("unknown - refinement", () => { @@ -695,8 +702,8 @@ describe("Match", () => { M.orElse(() => "unknown") ) - expect(match({})).toEqual("record") - expect(match([])).toEqual("unknown") + strictEqual(match({}), "record") + strictEqual(match([]), "unknown") }) it("any - refinement", () => { @@ -712,8 +719,8 @@ describe("Match", () => { M.orElse(() => "unknown") ) - expect(match({})).toEqual("record") - expect(match([])).toEqual("unknown") + strictEqual(match({}), "record") + strictEqual(match([]), "unknown") }) it("pattern type is not fixed by the function argument type", () => { @@ -760,10 +767,10 @@ describe("Match", () => { M.discriminatorStartsWith("type")("B", (_) => 2 as const), M.orElse((_) => 3 as const) ) - expect(match({ type: "A" })).toEqual(1) - expect(match({ type: "A.A" })).toEqual(1) - expect(match({ type: "B" })).toEqual(2) - expect(match({})).toEqual(3) + strictEqual(match({ type: "A" }), 1) + strictEqual(match({ type: "A.A" }), 1) + strictEqual(match({ type: "B" }), 2) + strictEqual(match({}), 3) }) it("symbol", () => { @@ -772,8 +779,8 @@ describe("Match", () => { M.when(M.symbol, (_) => "symbol"), M.orElse(() => "else") ) - expect(match(Symbol.for("a"))).toEqual("symbol") - expect(match(123)).toEqual("else") + strictEqual(match(Symbol.for("a")), "symbol") + strictEqual(match(123), "else") }) it("withReturnType", () => { @@ -783,8 +790,8 @@ describe("Match", () => { M.when("A", (_) => "A"), M.orElse(() => "else") ) - expect(match("A")).toEqual("A") - expect(match("a")).toEqual("else") + strictEqual(match("A"), "A") + strictEqual(match("a"), "else") }) it("withReturnType after predicate", () => { @@ -794,8 +801,8 @@ describe("Match", () => { M.withReturnType(), M.orElse(() => "else") ) - expect(match("A")).toEqual("A") - expect(match("a")).toEqual("else") + strictEqual(match("A"), "A") + strictEqual(match("a"), "else") }) it("withReturnType mismatch", () => { @@ -806,8 +813,9 @@ describe("Match", () => { M.when("A", (_) => 123), M.orElse(() => "else") ) - expect(match("A")).toEqual(123) - expect(match("a")).toEqual("else") + // @ts-expect-error + strictEqual(match("A"), 123) + strictEqual(match("a"), "else") }) it("withReturnType constraint mismatch", () => { @@ -827,8 +835,8 @@ describe("Match", () => { M.when("A", (_) => "a"), M.orElse((_) => "b") ) - expect(match("A")).toEqual("a") - expect(match("a")).toEqual("b") + strictEqual(match("A"), "a") + strictEqual(match("a"), "b") }) it("withReturnType union mismatch", () => { diff --git a/packages/effect/test/Metric.test.ts b/packages/effect/test/Metric.test.ts index f3c793ed1f7..db89e64bb8f 100644 --- a/packages/effect/test/Metric.test.ts +++ b/packages/effect/test/Metric.test.ts @@ -1,20 +1,23 @@ -import * as Array from "effect/Array" -import * as Clock from "effect/Clock" -import * as Duration from "effect/Duration" -import * as Effect from "effect/Effect" -import * as Equal from "effect/Equal" -import * as Fiber from "effect/Fiber" -import { pipe } from "effect/Function" -import * as Metric from "effect/Metric" -import * as MetricBoundaries from "effect/MetricBoundaries" -import * as MetricKey from "effect/MetricKey" -import * as MetricLabel from "effect/MetricLabel" -import * as MetricPolling from "effect/MetricPolling" -import * as MetricState from "effect/MetricState" -import * as Option from "effect/Option" -import * as Schedule from "effect/Schedule" +import { + Array, + Clock, + Duration, + Effect, + Equal, + Fiber, + Metric, + MetricBoundaries, + MetricKey, + MetricLabel, + MetricPolling, + MetricState, + Option, + pipe, + Schedule +} from "effect" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe, expect } from "vitest" +import { describe } from "vitest" const labels = [MetricLabel.make("x", "a"), MetricLabel.make("y", "b")] @@ -36,7 +39,7 @@ describe("Metric", () => { const result = yield* $( counter(Effect.void).pipe(Effect.zipRight(counter(Effect.void)), Effect.zipRight(Metric.value(counter))) ) - assert.deepStrictEqual(result, MetricState.counter(2)) + deepStrictEqual(result, MetricState.counter(2)) })) it.effect("direct increment", () => Effect.gen(function*($) { @@ -48,7 +51,7 @@ describe("Metric", () => { Effect.zipRight(Metric.value(counter)) ) ) - assert.deepStrictEqual(result, MetricState.counter(2)) + deepStrictEqual(result, MetricState.counter(2)) })) it.effect("direct increment bigint", () => @@ -63,7 +66,7 @@ describe("Metric", () => { Effect.zipRight(Metric.value(counter)) ) ) - assert.deepStrictEqual(result, MetricState.counter(BigInt(2))) + deepStrictEqual(result, MetricState.counter(BigInt(2))) })) it.effect("cannot decrement incremental", () => @@ -77,7 +80,7 @@ describe("Metric", () => { Effect.zipRight(Metric.value(counter)) ) ) - assert.deepStrictEqual(result, MetricState.counter(2)) + deepStrictEqual(result, MetricState.counter(2)) })) it.effect("cannot decrement incremental bigint", () => @@ -94,7 +97,7 @@ describe("Metric", () => { Effect.zipRight(Metric.value(counter)) ) ) - assert.deepStrictEqual(result, MetricState.counter(BigInt(2))) + deepStrictEqual(result, MetricState.counter(BigInt(2))) })) it.effect("custom increment by value as aspect", () => @@ -107,7 +110,7 @@ describe("Metric", () => { Effect.zipRight(Metric.value(counter)) ) ) - assert.deepStrictEqual(result, MetricState.counter(15)) + deepStrictEqual(result, MetricState.counter(15)) })) it.effect("custom increment by bigint value as aspect", () => @@ -120,7 +123,7 @@ describe("Metric", () => { Effect.zipRight(Metric.value(counter)) ) ) - assert.deepStrictEqual(result, MetricState.counter(BigInt(15))) + deepStrictEqual(result, MetricState.counter(BigInt(15))) })) it.effect("direct increment referential transparency", () => @@ -153,7 +156,7 @@ describe("Metric", () => { )) ) ) - assert.deepStrictEqual(result, MetricState.counter(2)) + deepStrictEqual(result, MetricState.counter(2)) })) it.effect("custom increment referential transparency", () => Effect.gen(function*($) { @@ -168,7 +171,7 @@ describe("Metric", () => { Effect.zipRight(pipe(Metric.counter(name), Metric.taggedWithLabels(labels), Metric.value)) ) ) - assert.deepStrictEqual(result, MetricState.counter(15)) + deepStrictEqual(result, MetricState.counter(15)) })) it.effect("custom increment with mapInput", () => Effect.gen(function*($) { @@ -198,7 +201,7 @@ describe("Metric", () => { Effect.zipRight(pipe(Metric.counter(name), Metric.taggedWithLabels(labels), Metric.value)) ) ) - assert.deepStrictEqual(result, MetricState.counter(6)) + deepStrictEqual(result, MetricState.counter(6)) })) it.effect("does not count errors", () => Effect.gen(function*($) { @@ -212,7 +215,7 @@ describe("Metric", () => { Effect.zipRight(Metric.value(counter)) ) ) - assert.deepStrictEqual(result, MetricState.counter(1)) + deepStrictEqual(result, MetricState.counter(1)) })) it.effect("count + taggedWith", () => Effect.gen(function*($) { @@ -231,7 +234,7 @@ describe("Metric", () => { Effect.zipRight(pipe(base, Metric.tagged("dyn", "!"), Metric.value)) ) ) - assert.deepStrictEqual(result, MetricState.counter(2)) + deepStrictEqual(result, MetricState.counter(2)) })) it.effect("tags are a region setting", () => Effect.gen(function*($) { @@ -248,7 +251,7 @@ describe("Metric", () => { ) ) ) - assert.deepStrictEqual(result, MetricState.counter(1)) + deepStrictEqual(result, MetricState.counter(1)) })) }) describe("Frequency", () => { @@ -265,7 +268,7 @@ describe("Metric", () => { Effect.zipRight(Metric.value(frequency)) ) ) - assert.deepStrictEqual(result.occurrences, new Map([["hello", 2] as const, ["world", 1] as const])) + deepStrictEqual(result.occurrences, new Map([["hello", 2] as const, ["world", 1] as const])) })) it.effect("direct occurrences", () => Effect.gen(function*($) { @@ -280,7 +283,7 @@ describe("Metric", () => { Effect.zipRight(Metric.value(frequency)) ) ) - assert.deepStrictEqual(result.occurrences, new Map([["hello", 2] as const, ["world", 1] as const])) + deepStrictEqual(result.occurrences, new Map([["hello", 2] as const, ["world", 1] as const])) })) it.effect("custom occurrences with mapInput", () => Effect.gen(function*($) { @@ -299,7 +302,7 @@ describe("Metric", () => { Effect.zipRight(Metric.value(frequency)) ) ) - assert.deepStrictEqual(result.occurrences, new Map([["1", 2] as const, ["2", 1] as const])) + deepStrictEqual(result.occurrences, new Map([["1", 2] as const, ["2", 1] as const])) })) it.effect("occurences + taggedWith", () => Effect.gen(function*($) { @@ -322,9 +325,9 @@ describe("Metric", () => { })) ) ) - assert.isTrue(result1.occurrences.size === 0) - assert.deepStrictEqual(result2.occurrences, new Map([["hello", 2] as const])) - assert.deepStrictEqual(result3.occurrences, new Map([["world", 1] as const])) + strictEqual(result1.occurrences.size, 0) + deepStrictEqual(result2.occurrences, new Map([["hello", 2] as const])) + deepStrictEqual(result3.occurrences, new Map([["world", 1] as const])) })) }) describe("Gauge", () => { @@ -340,7 +343,7 @@ describe("Metric", () => { Effect.zipRight(Metric.value(gauge)) ) ) - assert.deepStrictEqual(result, MetricState.gauge(3)) + deepStrictEqual(result, MetricState.gauge(3)) })) it.effect("direct set", () => Effect.gen(function*($) { @@ -349,7 +352,7 @@ describe("Metric", () => { const result = yield* $( pipe(gauge, Metric.set(1), Effect.zipRight(pipe(gauge, Metric.set(3))), Effect.zipRight(Metric.value(gauge))) ) - assert.deepStrictEqual(result, MetricState.gauge(3)) + deepStrictEqual(result, MetricState.gauge(3)) })) it.effect("increment", () => Effect.gen(function*() { @@ -357,7 +360,7 @@ describe("Metric", () => { const gauge = pipe(Metric.gauge(name), Metric.taggedWithLabels(labels)) yield* Effect.forEach(Array.range(0, 99), () => Metric.increment(gauge), { concurrency: "unbounded" }) const result = yield* Metric.value(gauge) - assert.deepStrictEqual(result, MetricState.gauge(100)) + deepStrictEqual(result, MetricState.gauge(100)) })) it.effect("custom set with mapInput", () => Effect.gen(function*($) { @@ -371,7 +374,7 @@ describe("Metric", () => { Effect.zipRight(Metric.value(gauge)) ) ) - assert.deepStrictEqual(result, MetricState.gauge(6)) + deepStrictEqual(result, MetricState.gauge(6)) })) it.effect("gauge + taggedWith", () => Effect.gen(function*($) { @@ -390,7 +393,7 @@ describe("Metric", () => { Effect.zipRight(pipe(base, Metric.tagged("dyn", "!"), Metric.value)) ) ) - assert.deepStrictEqual(result, MetricState.gauge(1)) + deepStrictEqual(result, MetricState.gauge(1)) })) }) describe("Histogram", () => { @@ -407,10 +410,10 @@ describe("Metric", () => { Effect.zipRight(Metric.value(histogram)) ) ) - assert.strictEqual(result.count, 2) - assert.strictEqual(result.sum, 4) - assert.strictEqual(result.min, 1) - assert.strictEqual(result.max, 3) + strictEqual(result.count, 2) + strictEqual(result.sum, 4) + strictEqual(result.min, 1) + strictEqual(result.max, 3) })) it.effect("direct observe", () => Effect.gen(function*($) { @@ -425,10 +428,10 @@ describe("Metric", () => { Effect.zipRight(Metric.value(histogram)) ) ) - assert.strictEqual(result.count, 2) - assert.strictEqual(result.sum, 4) - assert.strictEqual(result.min, 1) - assert.strictEqual(result.max, 3) + strictEqual(result.count, 2) + strictEqual(result.sum, 4) + strictEqual(result.min, 1) + strictEqual(result.max, 3) })) it.flakyTest( Effect.gen(function*($) { @@ -446,13 +449,13 @@ describe("Metric", () => { const end = yield* $(Effect.sync(() => Date.now())) const elapsed = end - start const result = yield* $(Metric.value(histogram)) - assert.strictEqual(result.count, 2) - assert.isAbove(result.sum, 0.39) - assert.isAtMost(result.sum, elapsed) - assert.isAtLeast(result.min, 0.1) - assert.isBelow(result.min, result.max) - assert.isAtLeast(result.max, 0.3) - assert.isBelow(result.max, elapsed) + strictEqual(result.count, 2) + assertTrue(result.sum > 0.39) + assertTrue(result.sum <= elapsed) + assertTrue(result.min >= 0.1) + assertTrue(result.min < result.max) + assertTrue(result.max >= 0.3) + assertTrue(result.max < elapsed) }) ) it.effect("custom observe with mapInput", () => @@ -472,10 +475,10 @@ describe("Metric", () => { Effect.zipRight(Metric.value(histogram)) ) ) - assert.strictEqual(result.count, 2) - assert.strictEqual(result.sum, 4) - assert.strictEqual(result.min, 1) - assert.strictEqual(result.max, 3) + strictEqual(result.count, 2) + strictEqual(result.sum, 4) + strictEqual(result.min, 1) + strictEqual(result.max, 3) })) it.effect("observe + taggedWith", () => Effect.gen(function*($) { @@ -499,9 +502,9 @@ describe("Metric", () => { result3: pipe(base, Metric.tagged("dyn", "xyz"), Metric.value) })) ) - assert.strictEqual(result1.count, 0) - assert.strictEqual(result2.count, 1) - assert.strictEqual(result3.count, 1) + strictEqual(result1.count, 0) + strictEqual(result2.count, 1) + strictEqual(result3.count, 1) })) }) describe("Summary", () => { @@ -523,10 +526,10 @@ describe("Metric", () => { Effect.zipRight(pipe(Effect.succeed(3), Effect.withMetric(summary))), Effect.zipRight(Metric.value(summary)) ) - assert.strictEqual(result.count, 2) - assert.strictEqual(result.sum, 4) - assert.strictEqual(result.min, 1) - assert.strictEqual(result.max, 3) + strictEqual(result.count, 2) + strictEqual(result.sum, 4) + strictEqual(result.min, 1) + strictEqual(result.max, 3) })) it.effect("direct observe", () => Effect.gen(function*($) { @@ -546,10 +549,10 @@ describe("Metric", () => { Effect.zipRight(pipe(summary, Metric.update(3))), Effect.zipRight(Metric.value(summary)) ) - assert.strictEqual(result.count, 2) - assert.strictEqual(result.sum, 4) - assert.strictEqual(result.min, 1) - assert.strictEqual(result.max, 3) + strictEqual(result.count, 2) + strictEqual(result.sum, 4) + strictEqual(result.min, 1) + strictEqual(result.max, 3) })) it.effect("custom observe with mapInput", () => Effect.gen(function*($) { @@ -570,10 +573,10 @@ describe("Metric", () => { Effect.zipRight(pipe(Effect.succeed("xyz"), Effect.withMetric(summary))), Effect.zipRight(Metric.value(summary)) ) - assert.strictEqual(result.count, 2) - assert.strictEqual(result.sum, 4) - assert.strictEqual(result.min, 1) - assert.strictEqual(result.max, 3) + strictEqual(result.count, 2) + strictEqual(result.sum, 4) + strictEqual(result.min, 1) + strictEqual(result.max, 3) })) it.effect("observeSummaryWith + taggedWith", () => Effect.gen(function*($) { @@ -601,9 +604,9 @@ describe("Metric", () => { result3: pipe(base, Metric.tagged("dyn", "xyz"), Metric.value) })) ) - assert.strictEqual(result1.count, 0) - assert.strictEqual(result2.count, 1) - assert.strictEqual(result3.count, 1) + strictEqual(result1.count, 0) + strictEqual(result2.count, 1) + strictEqual(result3.count, 1) })) }) describe("Polling", () => { @@ -615,7 +618,7 @@ describe("Metric", () => { const fiber = yield* $(metric, MetricPolling.launch(schedule)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Metric.value(gauge)) - assert.strictEqual(result.value, 0) + strictEqual(result.value, 0) })) it.scoped("launch should update the internal metric using the provided Schedule", () => Effect.gen(function*($) { @@ -624,7 +627,7 @@ describe("Metric", () => { const fiber = yield* $(metric, MetricPolling.launch(Schedule.once)) yield* $(Fiber.join(fiber)) const result = yield* $(Metric.value(gauge)) - assert.strictEqual(result.value, 1) + strictEqual(result.value, 1) })) it.scoped("collectAll should generate a metric that polls all the provided metrics", () => Effect.gen(function*($) { @@ -640,8 +643,8 @@ describe("Metric", () => { yield* $(Fiber.join(fiber)) const result1 = yield* $(Metric.value(gauge1)) const result2 = yield* $(Metric.value(gauge2)) - assert.strictEqual(result1.value, gaugeIncrement1 * pollingCount) - assert.strictEqual(result2.value, gaugeIncrement2 * pollingCount) + strictEqual(result1.value, gaugeIncrement1 * pollingCount) + strictEqual(result2.value, gaugeIncrement2 * pollingCount) })) }) @@ -683,25 +686,25 @@ describe("Metric", () => { )) ) - expect(Equal.equals(result1, MetricState.counter(1))).toBe(true) - expect(Equal.equals(result2, MetricState.counter(1))).toBe(true) - expect(Equal.equals(result3, MetricState.counter(1))).toBe(true) - expect(Equal.equals(pair1.metricState, MetricState.counter(1))).toBe(true) - expect(Option.isNone(pair1.metricKey.description)).toBe(true) - expect(Equal.equals(pair2.metricState, MetricState.counter(1))).toBe(true) - expect(Equal.equals( + assertTrue(Equal.equals(result1, MetricState.counter(1))) + assertTrue(Equal.equals(result2, MetricState.counter(1))) + assertTrue(Equal.equals(result3, MetricState.counter(1))) + assertTrue(Equal.equals(pair1.metricState, MetricState.counter(1))) + assertTrue(Option.isNone(pair1.metricKey.description)) + assertTrue(Equal.equals(pair2.metricState, MetricState.counter(1))) + assertTrue(Equal.equals( pair2.metricKey, MetricKey.counter(name, { description: "description1" }) - )).toBe(true) - expect(Equal.equals(pair3.metricState, MetricState.counter(1))).toBe(true) - expect(Equal.equals( + )) + assertTrue(Equal.equals(pair3.metricState, MetricState.counter(1))) + assertTrue(Equal.equals( pair3.metricKey, MetricKey.counter(name, { description: "description2" }) - )).toBe(true) + )) })) it.effect(".register()", () => @@ -713,6 +716,6 @@ describe("Metric", () => { Array.fromIterable(snapshot), Array.findFirst((_) => _.metricKey.name === id) ) - expect(value._tag).toBe("Some") + strictEqual(value._tag, "Some") })) }) diff --git a/packages/effect/test/Micro.test.ts b/packages/effect/test/Micro.test.ts index 1c61d1b9f94..0169051e02b 100644 --- a/packages/effect/test/Micro.test.ts +++ b/packages/effect/test/Micro.test.ts @@ -1,5 +1,6 @@ import { Cause, Context, Effect, Either, Exit, Fiber, Micro, Option, pipe } from "effect" -import { assert, describe, it } from "effect/test/utils/extend" +import { assertFalse, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "effect/test/utils/extend" class ATag extends Context.Tag("ATag")() {} class TestError extends Micro.TaggedError("TestError") {} @@ -8,26 +9,28 @@ describe.concurrent("Micro", () => { describe("tracing", () => { it.effect("Micro.TaggedError", () => Micro.gen(function*() { + // Referenced line to be included in the string output const error = yield* new TestError().pipe(Micro.flip) - assert.deepStrictEqual(error, new TestError()) - assert.include(error.stack, "Micro.test.ts:11") + deepStrictEqual(error, new TestError()) + assertTrue(error.stack?.includes("Micro.test.ts:13")) // <= reference to the line above })) it.effect("withTrace", () => Micro.gen(function*() { const error = yield* Micro.fail("boom").pipe( + // Referenced line to be included in the string output Micro.withTrace("test trace"), Micro.sandbox, Micro.flip ) - assert.include(error.stack, "at test trace") - assert.include(error.stack, "Micro.test.ts:19") + assertTrue(error.stack?.includes("at test trace")) + assertTrue(error.stack?.includes("Micro.test.ts:22")) // <= reference to the line above })) }) it("runPromise", async () => { const result = await Micro.runPromise(Micro.succeed(1)) - assert.strictEqual(result, 1) + strictEqual(result, 1) }) it("acquireUseRelease interrupt", async () => { @@ -45,16 +48,16 @@ describe.concurrent("Micro", () => { }), (_) => Micro.sync(() => { - assert.strictEqual(_, 123) + strictEqual(_, 123) release = true }) ).pipe(Micro.runFork) fiber.unsafeInterrupt() const result = await Micro.runPromise(Micro.fiberAwait(fiber)) - assert.deepStrictEqual(result, Micro.exitInterrupt) - assert.isTrue(acquire) - assert.isFalse(use) - assert.isTrue(release) + deepStrictEqual(result, Micro.exitInterrupt) + assertTrue(acquire) + assertFalse(use) + assertTrue(release) }) it("acquireUseRelease uninterruptible", async () => { @@ -73,21 +76,21 @@ describe.concurrent("Micro", () => { }), (_) => Micro.sync(() => { - assert.strictEqual(_, 123) + strictEqual(_, 123) release = true }) ).pipe(Micro.uninterruptible, Micro.runFork) fiber.unsafeInterrupt() const result = await Micro.runPromise(Micro.fiberAwait(fiber)) - assert.deepStrictEqual(result, Micro.exitInterrupt) - assert.isTrue(acquire) - assert.isTrue(use) - assert.isTrue(release) + deepStrictEqual(result, Micro.exitInterrupt) + assertTrue(acquire) + assertTrue(use) + assertTrue(release) }) it("Context.Tag", () => Micro.service(ATag).pipe( - Micro.tap((_) => Micro.sync(() => assert.strictEqual(_, "A"))), + Micro.tap((_) => Micro.sync(() => strictEqual(_, "A"))), Micro.provideService(ATag, "A"), Micro.runPromise )) @@ -96,7 +99,7 @@ describe.concurrent("Micro", () => { it("from a some", () => Option.some("A").pipe( Micro.fromOption, - Micro.tap((_) => assert.strictEqual(_, "A")), + Micro.tap((_) => strictEqual(_, "A")), Micro.runPromise )) @@ -104,7 +107,7 @@ describe.concurrent("Micro", () => { Option.none().pipe( Micro.fromOption, Micro.flip, - Micro.tap((error) => assert.ok(error instanceof Micro.NoSuchElementException)), + Micro.tap((error) => assertTrue(error instanceof Micro.NoSuchElementException)), Micro.runPromise )) }) @@ -113,7 +116,7 @@ describe.concurrent("Micro", () => { it("from a right", () => Either.right("A").pipe( Micro.fromEither, - Micro.tap((_) => Micro.sync(() => assert.strictEqual(_, "A"))), + Micro.tap((_) => Micro.sync(() => strictEqual(_, "A"))), Micro.runPromise )) @@ -121,7 +124,7 @@ describe.concurrent("Micro", () => { Either.left("error").pipe( Micro.fromEither, Micro.flip, - Micro.tap((error) => Micro.sync(() => assert.strictEqual(error, "error"))), + Micro.tap((error) => Micro.sync(() => strictEqual(error, "error"))), Micro.runPromise )) }) @@ -130,35 +133,35 @@ describe.concurrent("Micro", () => { it("gen", () => Micro.gen(function*() { const result = yield* Micro.succeed(1) - assert.strictEqual(result, 1) + strictEqual(result, 1) return result - }).pipe(Micro.runPromise).then((_) => assert.deepStrictEqual(_, 1))) + }).pipe(Micro.runPromise).then((_) => deepStrictEqual(_, 1))) it("gen with context", () => Micro.gen({ a: 1, b: 2 }, function*() { const result = yield* Micro.succeed(this.a) - assert.strictEqual(result, 1) + strictEqual(result, 1) return result + this.b - }).pipe(Micro.runPromise).then((_) => assert.deepStrictEqual(_, 3))) + }).pipe(Micro.runPromise).then((_) => deepStrictEqual(_, 3))) }) describe("forEach", () => { it("sequential", () => Micro.gen(function*() { const results = yield* Micro.forEach([1, 2, 3], (_) => Micro.succeed(_)) - assert.deepStrictEqual(results, [1, 2, 3]) + deepStrictEqual(results, [1, 2, 3]) }).pipe(Micro.runPromise)) it("unbounded", () => Micro.gen(function*() { const results = yield* Micro.forEach([1, 2, 3], (_) => Micro.succeed(_), { concurrency: "unbounded" }) - assert.deepStrictEqual(results, [1, 2, 3]) + deepStrictEqual(results, [1, 2, 3]) }).pipe(Micro.runPromise)) it("bounded", () => Micro.gen(function*() { const results = yield* Micro.forEach([1, 2, 3, 4, 5], (_) => Micro.succeed(_), { concurrency: 2 }) - assert.deepStrictEqual(results, [1, 2, 3, 4, 5]) + deepStrictEqual(results, [1, 2, 3, 4, 5]) }).pipe(Micro.runPromise)) it("inherit unbounded", () => @@ -170,7 +173,7 @@ describe.concurrent("Micro", () => { Micro.fork ) yield* Micro.sleep(90) - assert.deepStrictEqual(handle.unsafePoll(), Micro.exitSucceed([1, 2, 3])) + deepStrictEqual(handle.unsafePoll(), Micro.exitSucceed([1, 2, 3])) }).pipe(Micro.runPromise)) it("sequential interrupt", () => @@ -184,8 +187,8 @@ describe.concurrent("Micro", () => { yield* Micro.sleep(800) yield* Micro.fiberInterrupt(fiber) const result = yield* Micro.fiberAwait(fiber) - assert.deepStrictEqual(result, Micro.exitInterrupt) - assert.deepStrictEqual(done, [1, 2]) + deepStrictEqual(result, Micro.exitInterrupt) + deepStrictEqual(done, [1, 2]) }).pipe(Micro.runPromise)) it("unbounded interrupt", () => @@ -199,8 +202,8 @@ describe.concurrent("Micro", () => { yield* Micro.sleep(50) yield* Micro.fiberInterrupt(fiber) const result = yield* Micro.fiberAwait(fiber) - assert.deepStrictEqual(result, Micro.exitInterrupt) - assert.deepStrictEqual(done, []) + deepStrictEqual(result, Micro.exitInterrupt) + deepStrictEqual(done, []) }).pipe(Micro.runPromise)) it("bounded interrupt", () => @@ -214,8 +217,8 @@ describe.concurrent("Micro", () => { yield* Micro.sleep(350) yield* Micro.fiberInterrupt(fiber) const result = yield* Micro.fiberAwait(fiber) - assert.deepStrictEqual(result, Micro.exitInterrupt) - assert.deepStrictEqual(done, [1, 2]) + deepStrictEqual(result, Micro.exitInterrupt) + deepStrictEqual(done, [1, 2]) }).pipe(Micro.runPromise)) it("unbounded fail", () => @@ -229,14 +232,14 @@ describe.concurrent("Micro", () => { concurrency: "unbounded" }).pipe(Micro.fork) const result = yield* Micro.fiberAwait(handle) - assert.deepStrictEqual(result, Micro.exitFail("error")) - assert.deepStrictEqual(done, [1, 2, 3]) + deepStrictEqual(result, Micro.exitFail("error")) + deepStrictEqual(done, [1, 2, 3]) }).pipe(Micro.runPromise)) it("length = 0", () => Micro.gen(function*() { const results = yield* Micro.forEach([], (_) => Micro.succeed(_)) - assert.deepStrictEqual(results, []) + deepStrictEqual(results, []) }).pipe(Micro.runPromise)) }) @@ -252,7 +255,7 @@ describe.concurrent("Micro", () => { number, number ] - assert.deepStrictEqual(results, [1, 2, 3]) + deepStrictEqual(results, [1, 2, 3]) }).pipe(Micro.runPromise)) it("record", () => @@ -266,7 +269,7 @@ describe.concurrent("Micro", () => { b: string c: boolean } - assert.deepStrictEqual(results, { + deepStrictEqual(results, { a: 1, b: "2", c: true @@ -280,7 +283,7 @@ describe.concurrent("Micro", () => { b: Micro.succeed("2"), c: Micro.succeed(true) }, { discard: true })) satisfies void - assert.deepStrictEqual(results, void 0) + deepStrictEqual(results, void 0) })) it.effect("iterable", () => @@ -292,7 +295,7 @@ describe.concurrent("Micro", () => { Micro.succeed(3) ]) )) satisfies Array - assert.deepStrictEqual(results, [1, 2, 3]) + deepStrictEqual(results, [1, 2, 3]) })) }) @@ -300,13 +303,13 @@ describe.concurrent("Micro", () => { it.live("odd numbers", () => Micro.gen(function*() { const results = yield* Micro.filter([1, 2, 3, 4, 5], (_) => Micro.succeed(_ % 2 === 1)) - assert.deepStrictEqual(results, [1, 3, 5]) + deepStrictEqual(results, [1, 3, 5]) })) it.live("iterable", () => Micro.gen(function*() { const results = yield* Micro.filter(new Set([1, 2, 3, 4, 5]), (_) => Micro.succeed(_ % 2 === 1)) - assert.deepStrictEqual(results, [1, 3, 5]) + deepStrictEqual(results, [1, 3, 5]) })) }) @@ -324,7 +327,7 @@ describe.concurrent("Micro", () => { yield* Micro.yieldFlush fiber.unsafeInterrupt() yield* Micro.fiberAwait(fiber) - assert.strictEqual(release, true) + strictEqual(release, true) }).pipe(Micro.runPromise)) }) @@ -341,8 +344,8 @@ describe.concurrent("Micro", () => { ) ) )) - assert.strictEqual(result, 100) - assert.deepStrictEqual(interrupted, [500, 300, 200]) + strictEqual(result, 100) + deepStrictEqual(interrupted, [500, 300, 200]) })) it("raceAllFirst", () => @@ -358,15 +361,15 @@ describe.concurrent("Micro", () => { ) ) )).pipe(Micro.exit) - assert.deepStrictEqual(result, Micro.exitFail("boom")) - assert.deepStrictEqual(interrupted, [500, 300, 200, 100]) + deepStrictEqual(result, Micro.exitFail("boom")) + deepStrictEqual(interrupted, [500, 300, 200, 100]) }).pipe(Micro.runPromise)) describe("valid Effect", () => { it.effect("success", () => Effect.gen(function*() { const result = yield* Micro.succeed(123) - assert.strictEqual(result, 123) + strictEqual(result, 123) })) it.effect("failure", () => @@ -375,7 +378,7 @@ describe.concurrent("Micro", () => { Effect.sandbox, Effect.flip ) - assert.deepStrictEqual(result, Cause.fail("boom")) + deepStrictEqual(result, Cause.fail("boom")) })) it.effect("defects", () => @@ -384,7 +387,7 @@ describe.concurrent("Micro", () => { Effect.sandbox, Effect.flip ) - assert.deepStrictEqual(result, Cause.die("boom")) + deepStrictEqual(result, Cause.die("boom")) })) it.effect("context", () => @@ -392,7 +395,7 @@ describe.concurrent("Micro", () => { const result = yield* Micro.service(ATag).pipe( Micro.map((_) => _) ) - assert.deepStrictEqual(result, "A") + deepStrictEqual(result, "A") }).pipe(Effect.provideService(ATag, "A"))) it.effect("interruption", () => @@ -403,7 +406,7 @@ describe.concurrent("Micro", () => { yield* Effect.yieldNow() yield* Fiber.interrupt(fiber) const exit = yield* fiber.await - assert.isTrue(Exit.isInterrupted(exit)) + assertTrue(Exit.isInterrupted(exit)) })) }) @@ -424,7 +427,7 @@ describe.concurrent("Micro", () => { Micro.repeat({ times: 1000 }), Micro.runSync ) - assert.deepStrictEqual(result, 123) + deepStrictEqual(result, 123) }) it.effect("scheduleRecurs", () => @@ -435,7 +438,7 @@ describe.concurrent("Micro", () => { schedule: Micro.scheduleRecurs(3) }) ) - assert.deepStrictEqual(count, 4) + deepStrictEqual(count, 4) })) }) @@ -446,7 +449,7 @@ describe.concurrent("Micro", () => { yield* Micro.sync(() => count++).pipe( Micro.retry({ times: 10000 }) ) - assert.strictEqual(count, 1) + strictEqual(count, 1) })) it.effect("initial + retries", () => @@ -456,7 +459,7 @@ describe.concurrent("Micro", () => { Micro.retry({ times: 2 }), Micro.flip ) - assert.strictEqual(error, 3) + strictEqual(error, 3) })) it.effect("predicate", () => @@ -466,7 +469,7 @@ describe.concurrent("Micro", () => { Micro.retry({ while: (i) => i < 3 }), Micro.flip ) - assert.strictEqual(error, 3) + strictEqual(error, 3) })) }) @@ -478,7 +481,7 @@ describe.concurrent("Micro", () => { Micro.andThen(Micro.succeed(true)), Micro.timeoutOption(10) ) - assert.deepStrictEqual(result, Option.none()) + deepStrictEqual(result, Option.none()) })) it.live("timeout a long computation with a failure", () => Micro.gen(function*() { @@ -493,7 +496,7 @@ describe.concurrent("Micro", () => { Micro.sandbox, Micro.flip ) - assert.deepStrictEqual(result, Micro.causeDie(error)) + deepStrictEqual(result, Micro.causeDie(error)) })) it.effect("timeout repetition of uninterruptible effect", () => Micro.gen(function*() { @@ -503,7 +506,7 @@ describe.concurrent("Micro", () => { Micro.forever, Micro.timeoutOption(10) ) - assert.deepStrictEqual(result, Option.none()) + deepStrictEqual(result, Option.none()) })) it.effect("timeout in uninterruptible region", () => Micro.gen(function*() { @@ -520,7 +523,7 @@ describe.concurrent("Micro", () => { Micro.timeout(10), Micro.flip ) - assert.deepStrictEqual(result, new Micro.TimeoutException()) + deepStrictEqual(result, new Micro.TimeoutException()) })) }) @@ -530,13 +533,13 @@ describe.concurrent("Micro", () => { it.effect("is yieldable", () => Micro.gen(function*() { const error = yield* new TestError().pipe(Micro.flip) - assert.deepStrictEqual(error, new TestError()) + deepStrictEqual(error, new TestError()) })) it.effect("is a valid Effect", () => Effect.gen(function*() { const error = yield* new TestError().pipe(Effect.flip) - assert.deepStrictEqual(error, new TestError()) + deepStrictEqual(error, new TestError()) })) }) @@ -544,7 +547,7 @@ describe.concurrent("Micro", () => { it.effect("is a valid Effect", () => Effect.gen(function*() { const error = yield* new TestError().pipe(Effect.flip) - assert.deepStrictEqual(error, new TestError()) + deepStrictEqual(error, new TestError()) })) it.effect("has a _tag", () => @@ -552,7 +555,7 @@ describe.concurrent("Micro", () => { const result = yield* new TestError().pipe( Micro.catchTag("TestError", (_) => Micro.succeed(true)) ) - assert.strictEqual(result, true) + strictEqual(result, true) })) }) @@ -564,10 +567,10 @@ describe.concurrent("Micro", () => { Micro.sandbox, Micro.flip ) - assert.strictEqual(failure.name, "MicroCause.Die") - assert.strictEqual(failure.message, JSON.stringify({ some: "error" })) - assert.include(failure.stack, `MicroCause.Die: ${JSON.stringify({ some: "error" })}`) - assert.include(failure.stack, "at test trace (") + strictEqual(failure.name, "MicroCause.Die") + strictEqual(failure.message, JSON.stringify({ some: "error" })) + assertTrue(failure.stack?.includes(`MicroCause.Die: ${JSON.stringify({ some: "error" })}`)) + assertTrue(failure.stack?.includes("at test trace (")) })) it.effect("renders non-errors", () => @@ -577,10 +580,10 @@ describe.concurrent("Micro", () => { Micro.sandbox, Micro.flip ) - assert.strictEqual(failure.name, "MicroCause.Fail") - assert.strictEqual(failure.message, JSON.stringify({ some: "error" })) - assert.include(failure.stack, `MicroCause.Fail: ${JSON.stringify({ some: "error" })}`) - assert.include(failure.stack, "at test trace (") + strictEqual(failure.name, "MicroCause.Fail") + strictEqual(failure.message, JSON.stringify({ some: "error" })) + assertTrue(failure.stack?.includes(`MicroCause.Fail: ${JSON.stringify({ some: "error" })}`)) + assertTrue(failure.stack?.includes("at test trace (")) })) it.effect("renders errors", () => @@ -590,10 +593,10 @@ describe.concurrent("Micro", () => { Micro.sandbox, Micro.flip ) - assert.strictEqual(failure.name, "(MicroCause.Fail) Error") - assert.strictEqual(failure.message, "boom") - assert.include(failure.stack, `(MicroCause.Fail) Error: boom`) - assert.include(failure.stack, "at test trace (") + strictEqual(failure.name, "(MicroCause.Fail) Error") + strictEqual(failure.message, "boom") + assertTrue(failure.stack?.includes(`(MicroCause.Fail) Error: boom`)) + assertTrue(failure.stack?.includes("at test trace (")) })) }) @@ -602,14 +605,14 @@ describe.concurrent("Micro", () => { Micro.gen(function*() { const fiber = yield* pipe(Micro.succeed(1), Micro.forever, Micro.fork) yield* Micro.fiberInterrupt(fiber) - assert.deepStrictEqual(fiber.unsafePoll(), Micro.exitInterrupt) + deepStrictEqual(fiber.unsafePoll(), Micro.exitInterrupt) })) it.effect("interrupt of never is interrupted with cause", () => Micro.gen(function*() { const fiber = yield* Micro.fork(Micro.never) yield* Micro.fiberInterrupt(fiber) - assert.deepStrictEqual(fiber.unsafePoll(), Micro.exitInterrupt) + deepStrictEqual(fiber.unsafePoll(), Micro.exitInterrupt) })) it.effect("catchAll + ensuring + interrupt", () => @@ -629,8 +632,8 @@ describe.concurrent("Micro", () => { ) yield* Micro.yieldFlush yield* Micro.fiberInterrupt(handle) - assert.isFalse(catchFailure) - assert.isTrue(ensuring) + assertFalse(catchFailure) + assertTrue(ensuring) })) it.effect("run of interruptible", () => @@ -649,7 +652,7 @@ describe.concurrent("Micro", () => { ) yield* Micro.yieldFlush yield* Micro.fiberInterrupt(fiber) - assert.isTrue(recovered) + assertTrue(recovered) })) it.effect("alternating interruptibility", () => @@ -672,7 +675,7 @@ describe.concurrent("Micro", () => { ) yield* Micro.yieldFlush yield* Micro.fiberInterrupt(fiber) - assert.strictEqual(counter, 2) + strictEqual(counter, 2) })) it.live("acquireUseRelease use inherits interrupt status", () => @@ -693,7 +696,7 @@ describe.concurrent("Micro", () => { ) yield* Micro.yieldFlush yield* Micro.fiberInterrupt(fiber) - assert.isTrue(ref) + assertTrue(ref) })) it.live("async can be uninterruptible", () => @@ -708,7 +711,7 @@ describe.concurrent("Micro", () => { ) yield* Micro.yieldFlush yield* Micro.fiberInterrupt(fiber) - assert.isTrue(ref) + assertTrue(ref) })) it.live("async cannot resume on interrupt", () => @@ -723,7 +726,7 @@ describe.concurrent("Micro", () => { ) yield* Micro.yieldFlush yield* Micro.fiberInterrupt(fiber) - assert.deepStrictEqual(fiber.unsafePoll(), Micro.exitInterrupt) + deepStrictEqual(fiber.unsafePoll(), Micro.exitInterrupt) })) it.live("closing scope is uninterruptible", () => @@ -738,7 +741,7 @@ describe.concurrent("Micro", () => { const fiber = yield* child.pipe(Micro.uninterruptible, Micro.fork) yield* Micro.yieldFlush yield* Micro.fiberInterrupt(fiber) - assert.isTrue(ref) + assertTrue(ref) })) it.effect("AbortSignal is aborted", () => @@ -749,7 +752,7 @@ describe.concurrent("Micro", () => { }).pipe(Micro.fork) yield* Micro.yieldFlush yield* Micro.fiberInterrupt(fiber) - assert.strictEqual(signal!.aborted, true) + strictEqual(signal!.aborted, true) })) }) @@ -772,8 +775,8 @@ describe.concurrent("Micro", () => { yield* Micro.yieldFlush yield* Micro.fiberInterrupt(fiber) yield* Micro.yieldFlush - assert.isTrue(child) - assert.isTrue(parent) + assertTrue(child) + assertTrue(parent) })) }) @@ -795,8 +798,8 @@ describe.concurrent("Micro", () => { ) yield* Micro.yieldFlush yield* Micro.fiberInterrupt(handle) - assert.isFalse(child) - assert.isTrue(parent) + assertFalse(child) + assertTrue(parent) })) }) @@ -813,7 +816,7 @@ describe.concurrent("Micro", () => { ) yield* Micro.yieldFlush yield* scope.close(Micro.exitVoid) - assert.isTrue(interrupted) + assertTrue(interrupted) })) }) @@ -831,7 +834,7 @@ describe.concurrent("Micro", () => { ) yield* Micro.yieldFlush yield* scope.close(Micro.exitVoid) - assert.isTrue(interrupted) + assertTrue(interrupted) })) }) @@ -842,7 +845,7 @@ describe.concurrent("Micro", () => { Micro.let("b", ({ a }) => a + 1), Micro.bind("b", ({ b }) => Micro.succeed(b.toString())), Micro.tap((_) => { - assert.deepStrictEqual(_, { + deepStrictEqual(_, { a: 1, b: "2" }) @@ -873,8 +876,8 @@ describe.concurrent("Micro", () => { })), Micro.exit ) - assert.deepStrictEqual(result, Micro.exitFail(ExampleError)) - assert.isTrue(finalized) + deepStrictEqual(result, Micro.exitFail(ExampleError)) + assertTrue(finalized) })) it.effect("fail on error", () => @@ -888,8 +891,8 @@ describe.concurrent("Micro", () => { ), Micro.exit ) - assert.deepStrictEqual(result, Micro.exitFail(ExampleError)) - assert.isTrue(finalized) + deepStrictEqual(result, Micro.exitFail(ExampleError)) + assertTrue(finalized) })) it.effect("finalizer errors not caught", () => @@ -904,7 +907,7 @@ describe.concurrent("Micro", () => { Micro.flip, Micro.map((cause) => cause) ) - assert.deepStrictEqual(result, Micro.causeDie(e3)) + deepStrictEqual(result, Micro.causeDie(e3)) })) it.effect("finalizer errors reported", () => @@ -925,8 +928,8 @@ describe.concurrent("Micro", () => { ) ) ) - assert.isUndefined(result) - assert.isFalse(reported !== undefined && Micro.exitIsSuccess(reported)) + strictEqual(result, undefined) + assertFalse(reported !== undefined && Micro.exitIsSuccess(reported)) })) it.effect("acquireUseRelease usage result", () => @@ -936,7 +939,7 @@ describe.concurrent("Micro", () => { () => Micro.succeed(42), () => Micro.void ) - assert.strictEqual(result, 42) + strictEqual(result, 42) })) it.effect("error in just acquisition", () => @@ -949,7 +952,7 @@ describe.concurrent("Micro", () => { ), Micro.exit ) - assert.deepStrictEqual(result, Micro.exitFail(ExampleError)) + deepStrictEqual(result, Micro.exitFail(ExampleError)) })) it.effect("error in just release", () => @@ -962,7 +965,7 @@ describe.concurrent("Micro", () => { ), Micro.exit ) - assert.deepStrictEqual(result, Micro.exitDie(ExampleError)) + deepStrictEqual(result, Micro.exitDie(ExampleError)) })) it.effect("error in just usage", () => @@ -975,7 +978,7 @@ describe.concurrent("Micro", () => { ), Micro.exit ) - assert.deepStrictEqual(result, Micro.exitFail(ExampleError)) + deepStrictEqual(result, Micro.exitFail(ExampleError)) })) it.effect("rethrown caught error in acquisition", () => @@ -985,7 +988,7 @@ describe.concurrent("Micro", () => { () => Micro.void, () => Micro.void ).pipe(Micro.flip) - assert.deepEqual(result, ExampleError) + deepStrictEqual(result, ExampleError) })) it.effect("rethrown caught error in release", () => @@ -998,7 +1001,7 @@ describe.concurrent("Micro", () => { ), Micro.exit ) - assert.deepStrictEqual(result, Micro.exitDie(ExampleError)) + deepStrictEqual(result, Micro.exitDie(ExampleError)) })) it.effect("rethrown caught error in usage", () => @@ -1008,7 +1011,7 @@ describe.concurrent("Micro", () => { () => Micro.fail(ExampleError), () => Micro.void ).pipe(Micro.exit) - assert.deepEqual(result, Micro.exitFail(ExampleError)) + deepStrictEqual(result, Micro.exitFail(ExampleError)) })) it.effect("onResult - ensures that a cleanup function runs when an effect fails", () => @@ -1025,7 +1028,7 @@ describe.concurrent("Micro", () => { Micro.sandbox, Micro.ignore ) - assert.isTrue(ref) + assertTrue(ref) })) }) @@ -1042,11 +1045,11 @@ describe.concurrent("Micro", () => { Micro.catchTag("B", (_) => Micro.succeed(2)), Micro.orElseSucceed(() => 3) ) - assert.strictEqual(yield* effect, 1) + strictEqual(yield* effect, 1) error = new ErrorB() - assert.strictEqual(yield* effect, 2) + strictEqual(yield* effect, 2) error = new ErrorC() - assert.strictEqual(yield* effect, 3) + strictEqual(yield* effect, 3) })) }) @@ -1057,8 +1060,8 @@ describe.concurrent("Micro", () => { const task2 = Micro.succeed(1).pipe(Micro.delay(1), Micro.tap(() => executionOrder.push("task2"))) return Micro.gen(function*() { const result = yield* Micro.zip(task1, task2) - assert.deepStrictEqual(result, ["a", 1]) - assert.deepStrictEqual(executionOrder, ["task1", "task2"]) + deepStrictEqual(result, ["a", 1]) + deepStrictEqual(executionOrder, ["task1", "task2"]) }) }) it.effect("concurrent: true", () => { @@ -1067,8 +1070,8 @@ describe.concurrent("Micro", () => { const task2 = Micro.succeed(1).pipe(Micro.delay(1), Micro.tap(() => executionOrder.push("task2"))) return Micro.gen(function*() { const result = yield* Micro.zip(task1, task2, { concurrent: true }) - assert.deepStrictEqual(result, ["a", 1]) - assert.deepStrictEqual(executionOrder, ["task2", "task1"]) + deepStrictEqual(result, ["a", 1]) + deepStrictEqual(executionOrder, ["task2", "task1"]) }) }) }) @@ -1080,8 +1083,8 @@ describe.concurrent("Micro", () => { const task2 = Micro.succeed(1).pipe(Micro.delay(1), Micro.tap(() => executionOrder.push("task2"))) return Micro.gen(function*() { const result = yield* Micro.zipWith(task1, task2, (a, b) => a + b) - assert.deepStrictEqual(result, "a1") - assert.deepStrictEqual(executionOrder, ["task1", "task2"]) + deepStrictEqual(result, "a1") + deepStrictEqual(executionOrder, ["task1", "task2"]) }) }) it.effect("concurrent: true", () => { @@ -1090,8 +1093,8 @@ describe.concurrent("Micro", () => { const task2 = Micro.succeed(1).pipe(Micro.delay(1), Micro.tap(() => executionOrder.push("task2"))) return Micro.gen(function*() { const result = yield* Micro.zipWith(task1, task2, (a, b) => a + b, { concurrent: true }) - assert.deepStrictEqual(result, "a1") - assert.deepStrictEqual(executionOrder, ["task2", "task1"]) + deepStrictEqual(result, "a1") + deepStrictEqual(executionOrder, ["task2", "task1"]) }) }) }) @@ -1100,21 +1103,21 @@ describe.concurrent("Micro", () => { it.effect("first argument as success", () => Micro.gen(function*() { const result = yield* Micro.catchCauseIf(Micro.succeed(1), () => false, () => Micro.fail("e2")) - assert.deepStrictEqual(result, 1) + deepStrictEqual(result, 1) })) it.effect("first argument as failure and predicate return false", () => Micro.gen(function*() { const result = yield* Micro.flip( Micro.catchCauseIf(Micro.fail("e1" as const), () => false, () => Micro.fail("e2" as const)) ) - assert.deepStrictEqual(result, "e1") + deepStrictEqual(result, "e1") })) it.effect("first argument as failure and predicate return true", () => Micro.gen(function*() { const result = yield* Micro.flip( Micro.catchCauseIf(Micro.fail("e1" as const), () => true, () => Micro.fail("e2" as const)) ) - assert.deepStrictEqual(result, "e2") + deepStrictEqual(result, "e2") })) }) @@ -1122,12 +1125,12 @@ describe.concurrent("Micro", () => { it.effect("first argument as success", () => Micro.gen(function*() { const result = yield* Micro.catchAll(Micro.succeed(1), () => Micro.fail("e2" as const)) - assert.deepStrictEqual(result, 1) + deepStrictEqual(result, 1) })) it.effect("first argument as failure", () => Micro.gen(function*() { const result = yield* Micro.flip(Micro.catchAll(Micro.fail("e1" as const), () => Micro.fail("e2" as const))) - assert.deepStrictEqual(result, "e2") + deepStrictEqual(result, "e2") })) }) @@ -1135,14 +1138,14 @@ describe.concurrent("Micro", () => { it.effect("first argument as success", () => Micro.gen(function*() { const result = yield* Micro.catchAllCause(Micro.succeed(1), () => Micro.fail("e2" as const)) - assert.deepStrictEqual(result, 1) + deepStrictEqual(result, 1) })) it.effect("first argument as failure", () => Micro.gen(function*() { const result = yield* Micro.flip( Micro.catchAllCause(Micro.fail("e1" as const), () => Micro.fail("e2" as const)) ) - assert.deepStrictEqual(result, "e2") + deepStrictEqual(result, "e2") })) }) @@ -1165,32 +1168,32 @@ describe.concurrent("Micro", () => { it("scheduleRecurs", () => { const out = dryRun(Micro.scheduleRecurs(5)) - assert.deepStrictEqual(out, [0, 0, 0, 0, 0]) + deepStrictEqual(out, [0, 0, 0, 0, 0]) }) it("scheduleSpaced", () => { const out = dryRun(Micro.scheduleSpaced(10)) - assert.deepStrictEqual(out, [10, 10, 10, 10, 10, 10, 10]) + deepStrictEqual(out, [10, 10, 10, 10, 10, 10, 10]) }) it("scheduleExponential", () => { const out = dryRun(Micro.scheduleExponential(10)) - assert.deepStrictEqual(out, [20, 40, 80, 160, 320, 640, 1280]) + deepStrictEqual(out, [20, 40, 80, 160, 320, 640, 1280]) }) it("scheduleAddDelay", () => { const out = dryRun(Micro.scheduleAddDelay(Micro.scheduleRecurs(5), () => 10)) - assert.deepStrictEqual(out, [10, 10, 10, 10, 10]) + deepStrictEqual(out, [10, 10, 10, 10, 10]) }) it("scheduleWithMaxDelay", () => { const out = dryRun(Micro.scheduleWithMaxDelay(Micro.scheduleExponential(10), 400)) - assert.deepStrictEqual(out, [20, 40, 80, 160, 320, 400, 400]) + deepStrictEqual(out, [20, 40, 80, 160, 320, 400, 400]) }) it("scheduleWithMaxElapsed", () => { const out = dryRun(Micro.scheduleWithMaxElapsed(Micro.scheduleExponential(10), 400)) - assert.deepStrictEqual(out, [20, 40, 80, 160, 320]) + deepStrictEqual(out, [20, 40, 80, 160, 320]) }) it("scheduleUnion", () => { @@ -1198,7 +1201,7 @@ describe.concurrent("Micro", () => { Micro.scheduleExponential(10), Micro.scheduleSpaced(100) )) - assert.deepStrictEqual(out, [20, 40, 80, 100, 100, 100, 100]) + deepStrictEqual(out, [20, 40, 80, 100, 100, 100, 100]) }) it("scheduleIntersect", () => { @@ -1206,7 +1209,7 @@ describe.concurrent("Micro", () => { Micro.scheduleExponential(10), Micro.scheduleSpaced(100) )) - assert.deepStrictEqual(out, [100, 100, 100, 160, 320, 640, 1280]) + deepStrictEqual(out, [100, 100, 100, 160, 320, 640, 1280]) }) }) }) diff --git a/packages/effect/test/MutableHashMap.test.ts b/packages/effect/test/MutableHashMap.test.ts index d7971454503..1c078d22509 100644 --- a/packages/effect/test/MutableHashMap.test.ts +++ b/packages/effect/test/MutableHashMap.test.ts @@ -1,9 +1,6 @@ -import * as Equal from "effect/Equal" -import { pipe } from "effect/Function" -import * as Hash from "effect/Hash" -import * as HM from "effect/MutableHashMap" -import * as O from "effect/Option" -import { assert, describe, expect, it } from "vitest" +import { Equal, Hash, MutableHashMap as HM, Option, pipe } from "effect" +import { assertFalse, assertNone, assertSome, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" class Key implements Equal.Equal { constructor(readonly a: number, readonly b: number) {} @@ -44,7 +41,9 @@ describe("MutableHashMap", () => { [1, "b"] ) - expect(String(map)).toEqual(`{ + strictEqual( + String(map), + `{ "_id": "MutableHashMap", "values": [ [ @@ -56,7 +55,8 @@ describe("MutableHashMap", () => { "b" ] ] -}`) +}` + ) }) it("toJSON", () => { @@ -65,9 +65,7 @@ describe("MutableHashMap", () => { [1, "b"] ) - expect(map.toJSON()).toEqual( - { _id: "MutableHashMap", values: [[0, "a"], [1, "b"]] } - ) + deepStrictEqual(map.toJSON(), { _id: "MutableHashMap", values: [[0, "a"], [1, "b"]] }) }) it("inspect", () => { @@ -82,7 +80,7 @@ describe("MutableHashMap", () => { [1, "b"] ) - expect(inspect(map)).toEqual(inspect({ _id: "MutableHashMap", values: [[0, "a"], [1, "b"]] })) + deepStrictEqual(inspect(map), inspect({ _id: "MutableHashMap", values: [[0, "a"], [1, "b"]] })) }) it("make", () => { @@ -91,9 +89,9 @@ describe("MutableHashMap", () => { [key(1, 1), value(1, 1)] ) - assert.strictEqual(HM.size(map), 2) - assert.isTrue(pipe(map, HM.has(key(0, 0)))) - assert.isTrue(pipe(map, HM.has(key(1, 1)))) + strictEqual(HM.size(map), 2) + assertTrue(pipe(map, HM.has(key(0, 0)))) + assertTrue(pipe(map, HM.has(key(1, 1)))) }) it("fromIterable", () => { @@ -102,9 +100,9 @@ describe("MutableHashMap", () => { [key(1, 1), value(1, 1)] ]) - assert.strictEqual(HM.size(map), 2) - assert.isTrue(pipe(map, HM.has(key(0, 0)))) - assert.isTrue(pipe(map, HM.has(key(1, 1)))) + strictEqual(HM.size(map), 2) + assertTrue(pipe(map, HM.has(key(0, 0)))) + assertTrue(pipe(map, HM.has(key(1, 1)))) }) it("iterate", () => { @@ -126,7 +124,7 @@ describe("MutableHashMap", () => { [b, 0] ) - expect(Array.from(map).length).toEqual(2) + strictEqual(Array.from(map).length, 2) }) it("get", () => { @@ -141,9 +139,7 @@ describe("MutableHashMap", () => { HM.get(key(0, 0)) ) - expect( - result - ).toEqual(O.some(value(1, 1))) + assertSome(result, value(1, 1)) }) it("has", () => { @@ -158,19 +154,19 @@ describe("MutableHashMap", () => { pipe( map, HM.has(key(0, 0)), - assert.isTrue + assertTrue ) pipe( map, HM.has(key(1, 1)), - assert.isTrue + assertTrue ) pipe( map, HM.has(key(4, 4)), - assert.isFalse + assertFalse ) }) @@ -181,7 +177,7 @@ describe("MutableHashMap", () => { HM.set(key(1, 1), value(1, 1)) ) - expect(HM.keys(map)).toStrictEqual([ + deepStrictEqual(HM.keys(map), [ key(0, 0), key(1, 1) ]) @@ -198,44 +194,36 @@ describe("MutableHashMap", () => { map, HM.modifyAt( key(0, 0), - () => O.some(value(0, 1)) + () => Option.some(value(0, 1)) ) ) - assert.strictEqual(HM.size(map), 2) - - expect(pipe( - map, - HM.get(key(0, 0)) - )).toEqual(O.some(value(0, 1))) + strictEqual(HM.size(map), 2) + assertSome(pipe(map, HM.get(key(0, 0))), value(0, 1)) pipe( map, HM.modifyAt( key(2, 2), - O.match({ - onNone: () => O.some(value(2, 2)), - onSome: O.some + Option.match({ + onNone: () => Option.some(value(2, 2)), + onSome: Option.some }) ) ) - assert.strictEqual(HM.size(map), 3) - - expect(pipe( - map, - HM.get(key(2, 2)) - )).toEqual(O.some(value(2, 2))) + strictEqual(HM.size(map), 3) + assertSome(pipe(map, HM.get(key(2, 2))), value(2, 2)) pipe( map, HM.modifyAt( key(2, 2), - () => O.none() + () => Option.none() ) ) - assert.strictEqual(HM.size(map), 2) + strictEqual(HM.size(map), 2) }) it("remove", () => { @@ -245,12 +233,12 @@ describe("MutableHashMap", () => { HM.set(key(1, 1), value(1, 1)) ) - assert.strictEqual(HM.size(map), 2) + strictEqual(HM.size(map), 2) pipe( map, HM.has(key(1, 1)), - assert.isTrue + assertTrue ) pipe( @@ -258,12 +246,12 @@ describe("MutableHashMap", () => { HM.remove(key(1, 1)) ) - assert.strictEqual(HM.size(map), 1) + strictEqual(HM.size(map), 1) pipe( map, HM.has(key(1, 1)), - assert.isFalse + assertFalse ) }) @@ -277,7 +265,7 @@ describe("MutableHashMap", () => { HM.set(key(0, 0), value(4, 4)) ) - expect(Array.from(map)).toEqual([ + deepStrictEqual(Array.from(map), [ [key(0, 0), value(4, 4)], [key(1, 1), value(3, 3)] ]) @@ -293,7 +281,7 @@ describe("MutableHashMap", () => { HM.set(key(0, 0), value(4, 4)) ) - assert.strictEqual(HM.size(map), 2) + strictEqual(HM.size(map), 2) }) it("modify", () => { @@ -308,24 +296,21 @@ describe("MutableHashMap", () => { HM.modify(key(0, 0), (v) => value(v.c + 1, v.d + 1)) ) - expect(pipe( - map, - HM.get(key(0, 0)) - )).toEqual(O.some(value(1, 1))) + assertSome(pipe(map, HM.get(key(0, 0))), value(1, 1)) pipe( map, HM.modify(key(1, 1), (v) => value(v.c + 1, v.d + 1)) ) - expect(pipe( + assertNone(pipe( map, HM.remove(key(0, 0)), HM.get(key(0, 0)) - )).toEqual(O.none()) + )) }) it("pipe()", () => { - expect(HM.empty().pipe(HM.set("key", "value"))).toEqual(HM.make(["key", "value"])) + deepStrictEqual(HM.empty().pipe(HM.set("key", "value")), HM.make(["key", "value"])) }) }) diff --git a/packages/effect/test/MutableHashSet.test.ts b/packages/effect/test/MutableHashSet.test.ts index 545615b8896..b8e6478cb6e 100644 --- a/packages/effect/test/MutableHashSet.test.ts +++ b/packages/effect/test/MutableHashSet.test.ts @@ -1,7 +1,6 @@ -import * as Equal from "effect/Equal" -import * as Hash from "effect/Hash" -import * as MutableHashSet from "effect/MutableHashSet" -import { describe, expect, it } from "vitest" +import { Equal, Hash, MutableHashSet } from "effect" +import { deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" class Value implements Equal.Equal { constructor(readonly a: number, readonly b: number) {} @@ -26,7 +25,9 @@ describe("MutableHashSet", () => { new Value(2, 3) ) - expect(String(set)).toEqual(`{ + strictEqual( + String(set), + `{ "_id": "MutableHashSet", "values": [ { @@ -40,7 +41,8 @@ describe("MutableHashSet", () => { "b": 3 } ] -}`) +}` + ) }) it("toJSON", () => { @@ -49,9 +51,10 @@ describe("MutableHashSet", () => { new Value(2, 3) ) - expect(set.toJSON()).toEqual( - { _id: "MutableHashSet", values: [{ _id: "Value", a: 0, b: 1 }, { _id: "Value", a: 2, b: 3 }] } - ) + deepStrictEqual(set.toJSON(), { + _id: "MutableHashSet", + values: [{ _id: "Value", a: 0, b: 1 }, { _id: "Value", a: 2, b: 3 }] + }) }) it("inspect", () => { @@ -66,7 +69,8 @@ describe("MutableHashSet", () => { new Value(2, 3) ) - expect(inspect(set)).toEqual( + deepStrictEqual( + inspect(set), inspect({ _id: "MutableHashSet", values: [{ _id: "Value", a: 0, b: 1 }, { _id: "Value", a: 2, b: 3 }] }) ) }) diff --git a/packages/effect/test/MutableList.test.ts b/packages/effect/test/MutableList.test.ts index b8a2ce5b9ec..623e39f8dab 100644 --- a/packages/effect/test/MutableList.test.ts +++ b/packages/effect/test/MutableList.test.ts @@ -1,24 +1,24 @@ -import { pipe } from "effect/Function" -import * as MutableList from "effect/MutableList" -import { deepStrictEqual, strictEqual } from "effect/test/util" -import { describe, expect, it } from "vitest" +import { MutableList, pipe } from "effect" +import { assertFalse, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("MutableList", () => { it("toString", () => { - expect(String(MutableList.make(0, 1, 2))).toEqual(`{ + strictEqual( + String(MutableList.make(0, 1, 2)), + `{ "_id": "MutableList", "values": [ 0, 1, 2 ] -}`) +}` + ) }) it("toJSON", () => { - expect(MutableList.make(0, 1, 2).toJSON()).toEqual( - { _id: "MutableList", values: [0, 1, 2] } - ) + deepStrictEqual(MutableList.make(0, 1, 2).toJSON(), { _id: "MutableList", values: [0, 1, 2] }) }) it("inspect", () => { @@ -27,13 +27,11 @@ describe("MutableList", () => { } // eslint-disable-next-line @typescript-eslint/no-var-requires const { inspect } = require("node:util") - expect(inspect(MutableList.make(0, 1, 2))).toEqual( - inspect({ _id: "MutableList", values: [0, 1, 2] }) - ) + deepStrictEqual(inspect(MutableList.make(0, 1, 2)), inspect({ _id: "MutableList", values: [0, 1, 2] })) }) it("pipe()", () => { - expect(MutableList.empty().pipe(MutableList.prepend("a"))).toEqual(MutableList.make("a")) + deepStrictEqual(MutableList.empty().pipe(MutableList.prepend("a")), MutableList.make("a")) }) it("empty", () => { @@ -51,8 +49,8 @@ describe("MutableList", () => { }) it("isEmpty", () => { - strictEqual(MutableList.isEmpty(MutableList.empty()), true) - strictEqual(MutableList.isEmpty(MutableList.make(1, 2, 3)), false) + assertTrue(MutableList.isEmpty(MutableList.empty())) + assertFalse(MutableList.isEmpty(MutableList.make(1, 2, 3))) }) it("length", () => { @@ -61,12 +59,12 @@ describe("MutableList", () => { }) it("tail", () => { - deepStrictEqual(MutableList.tail(MutableList.make()), undefined) + strictEqual(MutableList.tail(MutableList.make()), undefined) deepStrictEqual(MutableList.tail(MutableList.make(1, 2, 3)), 3) }) it("head", () => { - deepStrictEqual(MutableList.head(MutableList.make()), undefined) + strictEqual(MutableList.head(MutableList.make()), undefined) deepStrictEqual(MutableList.head(MutableList.make(1, 2, 3)), 1) }) @@ -103,18 +101,18 @@ describe("MutableList", () => { it("shift", () => { const list = MutableList.make(1, 2, 3) - deepStrictEqual(MutableList.shift(list), 1) - deepStrictEqual(MutableList.shift(list), 2) - deepStrictEqual(MutableList.shift(list), 3) - deepStrictEqual(MutableList.shift(list), undefined) + strictEqual(MutableList.shift(list), 1) + strictEqual(MutableList.shift(list), 2) + strictEqual(MutableList.shift(list), 3) + strictEqual(MutableList.shift(list), undefined) }) it("pop", () => { const list = MutableList.make(1, 2, 3) - deepStrictEqual(MutableList.pop(list), 3) - deepStrictEqual(MutableList.pop(list), 2) - deepStrictEqual(MutableList.pop(list), 1) - deepStrictEqual(MutableList.pop(list), undefined) + strictEqual(MutableList.pop(list), 3) + strictEqual(MutableList.pop(list), 2) + strictEqual(MutableList.pop(list), 1) + strictEqual(MutableList.pop(list), undefined) }) it("prepend", () => { diff --git a/packages/effect/test/MutableQueue.test.ts b/packages/effect/test/MutableQueue.test.ts index d2e03a688b7..5f895e4fde3 100644 --- a/packages/effect/test/MutableQueue.test.ts +++ b/packages/effect/test/MutableQueue.test.ts @@ -1,24 +1,27 @@ -import * as MutableQueue from "effect/MutableQueue" +import { MutableQueue } from "effect" import { assertFalse, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" -import { describe, expect, it } from "vitest" +import { describe, it } from "vitest" describe("MutableQueue", () => { it("toString", () => { const queue = MutableQueue.bounded(2) MutableQueue.offerAll([0, 1, 2])(queue) - expect(String(queue)).toEqual(`{ + strictEqual( + String(queue), + `{ "_id": "MutableQueue", "values": [ 0, 1 ] -}`) +}` + ) }) it("toJSON", () => { const queue = MutableQueue.bounded(2) MutableQueue.offerAll([0, 1, 2])(queue) - expect(queue.toJSON()).toEqual({ _id: "MutableQueue", values: [0, 1] }) + deepStrictEqual(queue.toJSON(), { _id: "MutableQueue", values: [0, 1] }) }) it("inspect", () => { @@ -29,7 +32,7 @@ describe("MutableQueue", () => { const { inspect } = require("node:util") const queue = MutableQueue.bounded(2) MutableQueue.offerAll([0, 1, 2])(queue) - expect(inspect(queue)).toEqual(inspect({ _id: "MutableQueue", values: [0, 1] })) + deepStrictEqual(inspect(queue), inspect({ _id: "MutableQueue", values: [0, 1] })) }) describe("bounded", () => { diff --git a/packages/effect/test/MutableRef.test.ts b/packages/effect/test/MutableRef.test.ts index 0317a85c643..9a9ef84f223 100644 --- a/packages/effect/test/MutableRef.test.ts +++ b/packages/effect/test/MutableRef.test.ts @@ -1,10 +1,12 @@ -import * as Chunk from "effect/Chunk" -import * as MutableRef from "effect/MutableRef" -import { describe, expect, it } from "vitest" +import { Chunk, MutableRef } from "effect" +import { deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("MutableRef", () => { it("toString", () => { - expect(String(MutableRef.make(Chunk.make(1, 2, 3)))).toEqual(`{ + strictEqual( + String(MutableRef.make(Chunk.make(1, 2, 3))), + `{ "_id": "MutableRef", "current": { "_id": "Chunk", @@ -14,13 +16,15 @@ describe("MutableRef", () => { 3 ] } -}`) +}` + ) }) it("toJSON", () => { - expect(MutableRef.make(Chunk.make(1, 2, 3)).toJSON()).toEqual( - { _id: "MutableRef", current: { _id: "Chunk", values: [1, 2, 3] } } - ) + deepStrictEqual(MutableRef.make(Chunk.make(1, 2, 3)).toJSON(), { + _id: "MutableRef", + current: { _id: "Chunk", values: [1, 2, 3] } + }) }) it("inspect", () => { @@ -29,7 +33,8 @@ describe("MutableRef", () => { } // eslint-disable-next-line @typescript-eslint/no-var-requires const { inspect } = require("node:util") - expect(inspect(MutableRef.make(Chunk.make(1, 2, 3)))).toEqual( + deepStrictEqual( + inspect(MutableRef.make(Chunk.make(1, 2, 3))), inspect({ _id: "MutableRef", current: { _id: "Chunk", values: [1, 2, 3] } }) ) }) diff --git a/packages/effect/test/NonEmptyIterable.test.ts b/packages/effect/test/NonEmptyIterable.test.ts index 1a441f4ed87..3ca21786314 100644 --- a/packages/effect/test/NonEmptyIterable.test.ts +++ b/packages/effect/test/NonEmptyIterable.test.ts @@ -1,20 +1,20 @@ -import * as Chunk from "effect/Chunk" -import * as NonEmpty from "effect/NonEmptyIterable" -import { describe, expect, it } from "vitest" +import { Chunk, NonEmptyIterable } from "effect" +import { deepStrictEqual, strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" describe("NonEmptyIterable", () => { it("should get head and rest", () => { - const [head, rest] = NonEmpty.unprepend(Chunk.make(0, 1, 2)) + const [head, rest] = NonEmptyIterable.unprepend(Chunk.make(0, 1, 2)) const restArray: Array = [] let next = rest.next() while (!next.done) { restArray.push(next.value) next = rest.next() } - expect(head).toEqual(0) - expect(restArray).toEqual([1, 2]) + strictEqual(head, 0) + deepStrictEqual(restArray, [1, 2]) }) it("should throw", () => { - expect(() => NonEmpty.unprepend(Chunk.empty as any)).toThrow() + throws(() => NonEmptyIterable.unprepend(Chunk.empty as any)) }) }) diff --git a/packages/effect/test/Number.test.ts b/packages/effect/test/Number.test.ts index 21b89b33474..0ce3875a249 100644 --- a/packages/effect/test/Number.test.ts +++ b/packages/effect/test/Number.test.ts @@ -1,147 +1,145 @@ -import { pipe } from "effect/Function" -import * as Number from "effect/Number" -import * as Option from "effect/Option" -import { deepStrictEqual } from "effect/test/util" -import { assert, describe, expect, it } from "vitest" +import { Number, pipe } from "effect" +import { assertFalse, assertNone, assertSome, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Number", () => { it("isNumber", () => { - expect(Number.isNumber(1)).toEqual(true) - expect(Number.isNumber("a")).toEqual(false) - expect(Number.isNumber(true)).toEqual(false) + assertTrue(Number.isNumber(1)) + assertFalse(Number.isNumber("a")) + assertFalse(Number.isNumber(true)) }) it("sum", () => { - deepStrictEqual(pipe(1, Number.sum(2)), 3) + strictEqual(pipe(1, Number.sum(2)), 3) }) it("multiply", () => { - deepStrictEqual(pipe(2, Number.multiply(3)), 6) + strictEqual(pipe(2, Number.multiply(3)), 6) }) it("subtract", () => { - deepStrictEqual(pipe(3, Number.subtract(1)), 2) + strictEqual(pipe(3, Number.subtract(1)), 2) }) it("divide", () => { - deepStrictEqual(pipe(6, Number.divide(2)), Option.some(3)) - deepStrictEqual(pipe(6, Number.divide(0)), Option.none()) + assertSome(pipe(6, Number.divide(2)), 3) + assertNone(pipe(6, Number.divide(0))) }) it("unsafeDivide", () => { - deepStrictEqual(pipe(6, Number.unsafeDivide(2)), 3) + strictEqual(pipe(6, Number.unsafeDivide(2)), 3) }) it("decrement", () => { - deepStrictEqual(Number.decrement(2), 1) + strictEqual(Number.decrement(2), 1) }) it("Equivalence", () => { - expect(Number.Equivalence(1, 1)).toBe(true) - expect(Number.Equivalence(1, 2)).toBe(false) + assertTrue(Number.Equivalence(1, 1)) + assertFalse(Number.Equivalence(1, 2)) }) it("Order", () => { - deepStrictEqual(Number.Order(1, 2), -1) - deepStrictEqual(Number.Order(2, 1), 1) - deepStrictEqual(Number.Order(2, 2), 0) + strictEqual(Number.Order(1, 2), -1) + strictEqual(Number.Order(2, 1), 1) + strictEqual(Number.Order(2, 2), 0) }) it("sign", () => { - deepStrictEqual(Number.sign(0), 0) - deepStrictEqual(Number.sign(0.0), 0) - deepStrictEqual(Number.sign(-0.1), -1) - deepStrictEqual(Number.sign(-10), -1) - deepStrictEqual(Number.sign(10), 1) - deepStrictEqual(Number.sign(0.1), 1) + strictEqual(Number.sign(0), 0) + strictEqual(Number.sign(0.0), 0) + strictEqual(Number.sign(-0.1), -1) + strictEqual(Number.sign(-10), -1) + strictEqual(Number.sign(10), 1) + strictEqual(Number.sign(0.1), 1) }) it("remainder", () => { - assert.deepStrictEqual(Number.remainder(2, 2), 0) - assert.deepStrictEqual(Number.remainder(3, 2), 1) - assert.deepStrictEqual(Number.remainder(4, 2), 0) - assert.deepStrictEqual(Number.remainder(2.5, 2), 0.5) - assert.deepStrictEqual(Number.remainder(-2, 2), -0) - assert.deepStrictEqual(Number.remainder(-3, 2), -1) - assert.deepStrictEqual(Number.remainder(-4, 2), -0) - assert.deepStrictEqual(Number.remainder(-2.8, -.2), -0) - assert.deepStrictEqual(Number.remainder(-2, -.2), -0) - assert.deepStrictEqual(Number.remainder(-1.5, -.2), -0.1) - assert.deepStrictEqual(Number.remainder(0, -.2), 0) - assert.deepStrictEqual(Number.remainder(1, -.2), 0) - assert.deepStrictEqual(Number.remainder(2.6, -.2), 0) - assert.deepStrictEqual(Number.remainder(3.1, -.2), 0.1) + strictEqual(Number.remainder(2, 2), 0) + strictEqual(Number.remainder(3, 2), 1) + strictEqual(Number.remainder(4, 2), 0) + strictEqual(Number.remainder(2.5, 2), 0.5) + strictEqual(Number.remainder(-2, 2), -0) + strictEqual(Number.remainder(-3, 2), -1) + strictEqual(Number.remainder(-4, 2), -0) + strictEqual(Number.remainder(-2.8, -.2), -0) + strictEqual(Number.remainder(-2, -.2), -0) + strictEqual(Number.remainder(-1.5, -.2), -0.1) + strictEqual(Number.remainder(0, -.2), 0) + strictEqual(Number.remainder(1, -.2), 0) + strictEqual(Number.remainder(2.6, -.2), 0) + strictEqual(Number.remainder(3.1, -.2), 0.1) }) it("lessThan", () => { - assert.deepStrictEqual(Number.lessThan(2, 3), true) - assert.deepStrictEqual(Number.lessThan(3, 3), false) - assert.deepStrictEqual(Number.lessThan(4, 3), false) + assertTrue(Number.lessThan(2, 3)) + assertFalse(Number.lessThan(3, 3)) + assertFalse(Number.lessThan(4, 3)) }) it("lessThanOrEqualTo", () => { - assert.deepStrictEqual(Number.lessThanOrEqualTo(2, 3), true) - assert.deepStrictEqual(Number.lessThanOrEqualTo(3, 3), true) - assert.deepStrictEqual(Number.lessThanOrEqualTo(4, 3), false) + assertTrue(Number.lessThanOrEqualTo(2, 3)) + assertTrue(Number.lessThanOrEqualTo(3, 3)) + assertFalse(Number.lessThanOrEqualTo(4, 3)) }) it("greaterThan", () => { - assert.deepStrictEqual(Number.greaterThan(2, 3), false) - assert.deepStrictEqual(Number.greaterThan(3, 3), false) - assert.deepStrictEqual(Number.greaterThan(4, 3), true) + assertFalse(Number.greaterThan(2, 3)) + assertFalse(Number.greaterThan(3, 3)) + assertTrue(Number.greaterThan(4, 3)) }) it("greaterThanOrEqualTo", () => { - assert.deepStrictEqual(Number.greaterThanOrEqualTo(2, 3), false) - assert.deepStrictEqual(Number.greaterThanOrEqualTo(3, 3), true) - assert.deepStrictEqual(Number.greaterThanOrEqualTo(4, 3), true) + assertFalse(Number.greaterThanOrEqualTo(2, 3)) + assertTrue(Number.greaterThanOrEqualTo(3, 3)) + assertTrue(Number.greaterThanOrEqualTo(4, 3)) }) it("between", () => { - assert.deepStrictEqual(Number.between({ minimum: 0, maximum: 5 })(3), true) - assert.deepStrictEqual(Number.between({ minimum: 0, maximum: 5 })(-1), false) - assert.deepStrictEqual(Number.between({ minimum: 0, maximum: 5 })(6), false) + assertTrue(Number.between({ minimum: 0, maximum: 5 })(3)) + assertFalse(Number.between({ minimum: 0, maximum: 5 })(-1)) + assertFalse(Number.between({ minimum: 0, maximum: 5 })(6)) - assert.deepStrictEqual(Number.between(3, { minimum: 0, maximum: 5 }), true) + assertTrue(Number.between(3, { minimum: 0, maximum: 5 })) }) it("clamp", () => { - assert.deepStrictEqual(Number.clamp({ minimum: 0, maximum: 5 })(3), 3) - assert.deepStrictEqual(Number.clamp({ minimum: 0, maximum: 5 })(-1), 0) - assert.deepStrictEqual(Number.clamp({ minimum: 0, maximum: 5 })(6), 5) + strictEqual(Number.clamp({ minimum: 0, maximum: 5 })(3), 3) + strictEqual(Number.clamp({ minimum: 0, maximum: 5 })(-1), 0) + strictEqual(Number.clamp({ minimum: 0, maximum: 5 })(6), 5) }) it("min", () => { - assert.deepStrictEqual(Number.min(2, 3), 2) + strictEqual(Number.min(2, 3), 2) }) it("max", () => { - assert.deepStrictEqual(Number.max(2, 3), 3) + strictEqual(Number.max(2, 3), 3) }) it("sumAll", () => { - assert.deepStrictEqual(Number.sumAll([2, 3, 4]), 9) + strictEqual(Number.sumAll([2, 3, 4]), 9) }) it("multiplyAll", () => { - assert.deepStrictEqual(Number.multiplyAll([2, 0, 4]), 0) - assert.deepStrictEqual(Number.multiplyAll([2, 3, 4]), 24) + strictEqual(Number.multiplyAll([2, 0, 4]), 0) + strictEqual(Number.multiplyAll([2, 3, 4]), 24) }) it("parse", () => { - assert.deepStrictEqual(Number.parse("NaN"), Option.some(NaN)) - assert.deepStrictEqual(Number.parse("Infinity"), Option.some(Infinity)) - assert.deepStrictEqual(Number.parse("-Infinity"), Option.some(-Infinity)) - assert.deepStrictEqual(Number.parse("42"), Option.some(42)) - assert.deepStrictEqual(Number.parse("a"), Option.none()) + assertSome(Number.parse("NaN"), NaN) + assertSome(Number.parse("Infinity"), Infinity) + assertSome(Number.parse("-Infinity"), -Infinity) + assertSome(Number.parse("42"), 42) + assertNone(Number.parse("a")) }) it("round", () => { - assert.deepStrictEqual(Number.round(1.1234, 2), 1.12) - assert.deepStrictEqual(Number.round(2)(1.1234), 1.12) - assert.deepStrictEqual(Number.round(0)(1.1234), 1) - assert.deepStrictEqual(Number.round(0)(1.1234), 1) - assert.deepStrictEqual(Number.round(1.567, 2), 1.57) - assert.deepStrictEqual(Number.round(2)(1.567), 1.57) + strictEqual(Number.round(1.1234, 2), 1.12) + strictEqual(Number.round(2)(1.1234), 1.12) + strictEqual(Number.round(0)(1.1234), 1) + strictEqual(Number.round(0)(1.1234), 1) + strictEqual(Number.round(1.567, 2), 1.57) + strictEqual(Number.round(2)(1.567), 1.57) }) }) diff --git a/packages/effect/test/Option.test.ts b/packages/effect/test/Option.test.ts index 68eace18830..472b9f31fbc 100644 --- a/packages/effect/test/Option.test.ts +++ b/packages/effect/test/Option.test.ts @@ -1,23 +1,8 @@ -import * as Chunk from "effect/Chunk" -import * as E from "effect/Either" -import * as Equal from "effect/Equal" -import { pipe } from "effect/Function" -import * as Hash from "effect/Hash" -import * as N from "effect/Number" -import * as Option from "effect/Option" -import * as S from "effect/String" -import * as Util from "effect/test/util" -import { assert, assertType, describe, expect, it } from "vitest" - -const p = (n: number): boolean => n > 2 - -const expectNone = (o: Option.Option) => { - Util.deepStrictEqual(o, Option.none()) -} - -const expectSome = (o: Option.Option, expected: A) => { - Util.deepStrictEqual(o, Option.some(expected)) -} +import { Chunk, Either, Equal, Hash, Number as N, Option, pipe, String as S } from "effect" +import { assertFalse, assertNone, assertSome, assertTrue, deepStrictEqual, strictEqual, throws } from "effect/test/util" +import { assertType, describe, it } from "vitest" + +const gt2 = (n: number): boolean => n > 2 describe("Option", () => { it("gen", () => { @@ -55,27 +40,35 @@ describe("Option", () => { return x + y }) - expect(a).toEqual(Option.some(3)) - expect(b).toEqual(Option.some(10)) - expect(c).toEqual(Option.some(undefined)) - expect(d).toEqual(Option.some(2)) - expect(e).toEqual(Option.none()) - expect(f).toEqual(Option.none()) - expect(g).toEqual(Option.some("testContext")) - expect(h).toEqual(Option.some(3)) + assertSome(a, 3) + assertSome(b, 10) + assertSome(c, undefined) + assertSome(d, 2) + assertNone(e) + assertNone(f) + assertSome(g, "testContext") + assertSome(h, 3) }) it("toString", () => { - expect(String(Option.none())).toEqual(`{ + strictEqual( + String(Option.none()), + `{ "_id": "Option", "_tag": "None" -}`) - expect(String(Option.some(1))).toEqual(`{ +}` + ) + strictEqual( + String(Option.some(1)), + `{ "_id": "Option", "_tag": "Some", "value": 1 -}`) - expect(String(Option.some(Chunk.make(1, 2, 3)))).toEqual(`{ +}` + ) + strictEqual( + String(Option.some(Chunk.make(1, 2, 3))), + `{ "_id": "Option", "_tag": "Some", "value": { @@ -86,16 +79,13 @@ describe("Option", () => { 3 ] } -}`) +}` + ) }) it("toJSON", () => { - expect(Option.none().toJSON()).toEqual( - { _id: "Option", _tag: "None" } - ) - expect(Option.some(1).toJSON()).toEqual( - { _id: "Option", _tag: "Some", value: 1 } - ) + deepStrictEqual(Option.none().toJSON(), { _id: "Option", _tag: "None" }) + deepStrictEqual(Option.some(1).toJSON(), { _id: "Option", _tag: "Some", value: 1 }) }) it("inspect", () => { @@ -104,30 +94,30 @@ describe("Option", () => { } // eslint-disable-next-line @typescript-eslint/no-var-requires const { inspect } = require("node:util") - expect(inspect(Option.none())).toEqual(inspect({ _id: "Option", _tag: "None" })) - expect(inspect(Option.some(1))).toEqual(inspect({ _id: "Option", _tag: "Some", value: 1 })) + deepStrictEqual(inspect(Option.none()), inspect({ _id: "Option", _tag: "None" })) + deepStrictEqual(inspect(Option.some(1)), inspect({ _id: "Option", _tag: "Some", value: 1 })) }) it("Equal", () => { - expect(Equal.equals(Option.some(1), Option.some(1))).toEqual(true) - expect(Equal.equals(Option.some(1), Option.some(2))).toEqual(false) - expect(Equal.equals(Option.none(), Option.none())).toEqual(true) + assertTrue(Equal.equals(Option.some(1), Option.some(1))) + assertFalse(Equal.equals(Option.some(1), Option.some(2))) + assertTrue(Equal.equals(Option.none(), Option.none())) }) it("Hash", () => { - expect(Hash.hash(Option.some(1))).toEqual(Hash.hash(Option.some(1))) - expect(Hash.hash(Option.some(1)) === Hash.hash(Option.some(2))).toEqual(false) - expect(Hash.hash(Option.none())).toEqual(Hash.hash(Option.none())) + strictEqual(Hash.hash(Option.some(1)), Hash.hash(Option.some(1))) + strictEqual(Hash.hash(Option.some(1)) === Hash.hash(Option.some(2)), false) + strictEqual(Hash.hash(Option.none()), Hash.hash(Option.none())) }) it("getRight", () => { - expect(Option.getRight(E.right(1))).toEqual(Option.some(1)) - expect(Option.getRight(E.left("a"))).toEqual(Option.none()) + assertSome(Option.getRight(Either.right(1)), 1) + assertNone(Option.getRight(Either.left("a"))) }) it("getLeft", () => { - expect(Option.getLeft(E.right(1))).toEqual(Option.none()) - expect(Option.getLeft(E.left("a"))).toEqual(Option.some("a")) + assertNone(Option.getLeft(Either.right(1))) + assertSome(Option.getLeft(Either.left("a")), "a") }) it("toRefinement", () => { @@ -135,176 +125,174 @@ describe("Option", () => { s: string | number ): Option.Option => (typeof s === "string" ? Option.some(s) : Option.none()) const isString = Option.toRefinement(f) - Util.deepStrictEqual(isString("s"), true) - Util.deepStrictEqual(isString(1), false) + + assertTrue(isString("s")) + assertFalse(isString(1)) + type A = { readonly type: "A" } type B = { readonly type: "B" } type C = A | B const isA = Option.toRefinement((c) => (c.type === "A" ? Option.some(c) : Option.none())) - Util.deepStrictEqual(isA({ type: "A" }), true) - Util.deepStrictEqual(isA({ type: "B" }), false) + + assertTrue(isA({ type: "A" })) + assertFalse(isA({ type: "B" })) }) it("isOption", () => { - Util.deepStrictEqual(pipe(Option.some(1), Option.isOption), true) - Util.deepStrictEqual(pipe(Option.none(), Option.isOption), true) - Util.deepStrictEqual(pipe(E.right(1), Option.isOption), false) + assertTrue(pipe(Option.some(1), Option.isOption)) + assertTrue(pipe(Option.none(), Option.isOption)) + assertFalse(pipe(Either.right(1), Option.isOption)) }) it("firstSomeOf", () => { - Util.deepStrictEqual(Option.firstSomeOf([]), Option.none()) - Util.deepStrictEqual(Option.firstSomeOf([Option.some(1)]), Option.some(1)) - Util.deepStrictEqual(Option.firstSomeOf([Option.none()]), Option.none()) - Util.deepStrictEqual( + assertNone(Option.firstSomeOf([])) + assertSome(Option.firstSomeOf([Option.some(1)]), 1) + assertNone(Option.firstSomeOf([Option.none()])) + assertSome( Option.firstSomeOf([Option.none(), Option.none(), Option.none(), Option.none(), Option.some(1)]), - Option.some(1) + 1 ) - Util.deepStrictEqual( - Option.firstSomeOf([Option.none(), Option.none(), Option.none(), Option.none()]), - Option.none() + assertNone( + Option.firstSomeOf([Option.none(), Option.none(), Option.none(), Option.none()]) ) }) it("orElseEither", () => { - expect(pipe(Option.some(1), Option.orElseEither(() => Option.some(2)))).toEqual(Option.some(E.left(1))) - expect(pipe(Option.some(1), Option.orElseEither(() => Option.none()))).toEqual(Option.some(E.left(1))) - expect(pipe(Option.none(), Option.orElseEither(() => Option.some(2)))).toEqual(Option.some(E.right(2))) - expect(pipe(Option.none(), Option.orElseEither(() => Option.none()))).toEqual(Option.none()) + assertSome(pipe(Option.some(1), Option.orElseEither(() => Option.some(2))), Either.left(1)) + assertSome(pipe(Option.some(1), Option.orElseEither(() => Option.none())), Either.left(1)) + assertSome(pipe(Option.none(), Option.orElseEither(() => Option.some(2))), Either.right(2)) + assertNone(pipe(Option.none(), Option.orElseEither(() => Option.none()))) }) it("orElseSome", () => { - expect(pipe(Option.some(1), Option.orElseSome(() => 2))).toEqual(Option.some(1)) - expect(pipe(Option.none(), Option.orElseSome(() => 2))).toEqual(Option.some(2)) + assertSome(pipe(Option.some(1), Option.orElseSome(() => 2)), 1) + assertSome(pipe(Option.none(), Option.orElseSome(() => 2)), 2) }) it("getOrThrow", () => { - expect(pipe(Option.some(1), Option.getOrThrow)).toEqual(1) - expect(() => pipe(Option.none(), Option.getOrThrow)).toThrowError( - new Error("getOrThrow called on a None") - ) + strictEqual(pipe(Option.some(1), Option.getOrThrow), 1) + throws(() => pipe(Option.none(), Option.getOrThrow), new Error("getOrThrow called on a None")) }) it("getOrThrowWith", () => { - expect(pipe(Option.some(1), Option.getOrThrowWith(() => new Error("Unexpected None")))).toEqual(1) - expect(() => pipe(Option.none(), Option.getOrThrowWith(() => new Error("Unexpected None")))).toThrowError( + strictEqual(pipe(Option.some(1), Option.getOrThrowWith(() => new Error("Unexpected None"))), 1) + throws( + () => pipe(Option.none(), Option.getOrThrowWith(() => new Error("Unexpected None"))), new Error("Unexpected None") ) }) it("unit", () => { - Util.deepStrictEqual(Option.void, Option.some(undefined)) + assertSome(Option.void, undefined) }) it("product", () => { const product = Option.product - Util.deepStrictEqual(product(Option.none(), Option.none()), Option.none()) - Util.deepStrictEqual(product(Option.some(1), Option.none()), Option.none()) - Util.deepStrictEqual(product(Option.none(), Option.some("a")), Option.none()) - Util.deepStrictEqual( - product(Option.some(1), Option.some("a")), - Option.some([1, "a"]) - ) + assertNone(product(Option.none(), Option.none())) + assertNone(product(Option.some(1), Option.none())) + assertNone(product(Option.none(), Option.some("a"))) + assertSome(product(Option.some(1), Option.some("a")), [1, "a"]) }) it("productMany", () => { const productMany = Option.productMany - Util.deepStrictEqual(productMany(Option.none(), []), Option.none()) - Util.deepStrictEqual(productMany(Option.some(1), []), Option.some([1])) - Util.deepStrictEqual(productMany(Option.some(1), [Option.none()]), Option.none()) - Util.deepStrictEqual(productMany(Option.some(1), [Option.some(2)]), Option.some([1, 2])) + assertNone(productMany(Option.none(), [])) + assertSome(productMany(Option.some(1), []), [1]) + assertNone(productMany(Option.some(1), [Option.none()])) + assertSome(productMany(Option.some(1), [Option.some(2)]), [1, 2]) }) it("fromIterable", () => { - Util.deepStrictEqual(Option.fromIterable([]), Option.none()) - Util.deepStrictEqual(Option.fromIterable(["a"]), Option.some("a")) + assertNone(Option.fromIterable([])) + assertSome(Option.fromIterable(["a"]), "a") }) it("map", () => { - Util.deepStrictEqual(pipe(Option.some(2), Option.map(Util.double)), Option.some(4)) - Util.deepStrictEqual(pipe(Option.none(), Option.map(Util.double)), Option.none()) + assertSome(pipe(Option.some(2), Option.map((n) => n * 2)), 4) + assertNone(pipe(Option.none(), Option.map((n) => n * 2))) }) it("flatMap", () => { const f = (n: number) => Option.some(n * 2) const g = () => Option.none() - Util.deepStrictEqual(pipe(Option.some(1), Option.flatMap(f)), Option.some(2)) - Util.deepStrictEqual(pipe(Option.none(), Option.flatMap(f)), Option.none()) - Util.deepStrictEqual(pipe(Option.some(1), Option.flatMap(g)), Option.none()) - Util.deepStrictEqual(pipe(Option.none(), Option.flatMap(g)), Option.none()) + assertSome(pipe(Option.some(1), Option.flatMap(f)), 2) + assertNone(pipe(Option.none(), Option.flatMap(f))) + assertNone(pipe(Option.some(1), Option.flatMap(g))) + assertNone(pipe(Option.none(), Option.flatMap(g))) }) it("andThen", () => { - expect(pipe(Option.some(1), Option.andThen(() => Option.some(2)))).toStrictEqual(Option.some(2)) - expect(pipe(Option.some(1), Option.andThen(Option.some(2)))).toStrictEqual(Option.some(2)) - expect(pipe(Option.some(1), Option.andThen(2))).toStrictEqual(Option.some(2)) - expect(pipe(Option.some(1), Option.andThen(() => 2))).toStrictEqual(Option.some(2)) - expect(pipe(Option.some(1), Option.andThen((a) => a))).toStrictEqual(Option.some(1)) - expect(Option.andThen(Option.some(1), () => Option.some(2))).toStrictEqual(Option.some(2)) - expect(Option.andThen(Option.some(1), Option.some(2))).toStrictEqual(Option.some(2)) - expect(Option.andThen(Option.some(1), 2)).toStrictEqual(Option.some(2)) - expect(Option.andThen(Option.some(1), () => 2)).toStrictEqual(Option.some(2)) - expect(Option.andThen(Option.some(1), (a) => a)).toStrictEqual(Option.some(1)) + assertSome(pipe(Option.some(1), Option.andThen(() => Option.some(2))), 2) + assertSome(pipe(Option.some(1), Option.andThen(Option.some(2))), 2) + assertSome(pipe(Option.some(1), Option.andThen(2)), 2) + assertSome(pipe(Option.some(1), Option.andThen(() => 2)), 2) + assertSome(pipe(Option.some(1), Option.andThen((a) => a)), 1) + assertSome(Option.andThen(Option.some(1), () => Option.some(2)), 2) + assertSome(Option.andThen(Option.some(1), Option.some(2)), 2) + assertSome(Option.andThen(Option.some(1), 2), 2) + assertSome(Option.andThen(Option.some(1), () => 2), 2) + assertSome(Option.andThen(Option.some(1), (a) => a), 1) }) it("orElse", () => { - const assertAlt = ( + const assertOrElse = ( a: Option.Option, b: Option.Option, expected: Option.Option ) => { - Util.deepStrictEqual(pipe(a, Option.orElse(() => b)), expected) + deepStrictEqual(pipe(a, Option.orElse(() => b)), expected) } - assertAlt(Option.some(1), Option.some(2), Option.some(1)) - assertAlt(Option.some(1), Option.none(), Option.some(1)) - assertAlt(Option.none(), Option.some(2), Option.some(2)) - assertAlt(Option.none(), Option.none(), Option.none()) + assertOrElse(Option.some(1), Option.some(2), Option.some(1)) + assertOrElse(Option.some(1), Option.none(), Option.some(1)) + assertOrElse(Option.none(), Option.some(2), Option.some(2)) + assertOrElse(Option.none(), Option.none(), Option.none()) }) it("partitionMap", () => { - const f = (n: number) => (p(n) ? E.right(n + 1) : E.left(n - 1)) - assert.deepStrictEqual(pipe(Option.none(), Option.partitionMap(f)), [Option.none(), Option.none()]) - assert.deepStrictEqual(pipe(Option.some(1), Option.partitionMap(f)), [Option.some(0), Option.none()]) - assert.deepStrictEqual(pipe(Option.some(3), Option.partitionMap(f)), [Option.none(), Option.some(4)]) + const f = (n: number) => (gt2(n) ? Either.right(n + 1) : Either.left(n - 1)) + deepStrictEqual(pipe(Option.none(), Option.partitionMap(f)), [Option.none(), Option.none()]) + deepStrictEqual(pipe(Option.some(1), Option.partitionMap(f)), [Option.some(0), Option.none()]) + deepStrictEqual(pipe(Option.some(3), Option.partitionMap(f)), [Option.none(), Option.some(4)]) }) it("filterMap", () => { - const f = (n: number) => (p(n) ? Option.some(n + 1) : Option.none()) - Util.deepStrictEqual(pipe(Option.none(), Option.filterMap(f)), Option.none()) - Util.deepStrictEqual(pipe(Option.some(1), Option.filterMap(f)), Option.none()) - Util.deepStrictEqual(pipe(Option.some(3), Option.filterMap(f)), Option.some(4)) + const f = (n: number) => (gt2(n) ? Option.some(n + 1) : Option.none()) + assertNone(pipe(Option.none(), Option.filterMap(f))) + assertNone(pipe(Option.some(1), Option.filterMap(f))) + assertSome(pipe(Option.some(3), Option.filterMap(f)), 4) }) it("match", () => { const onNone = () => "none" const onSome = (s: string) => `some${s.length}` const match = Option.match({ onNone, onSome }) - Util.deepStrictEqual(match(Option.none()), "none") - Util.deepStrictEqual(match(Option.some("abc")), "some3") + strictEqual(match(Option.none()), "none") + strictEqual(match(Option.some("abc")), "some3") }) it("getOrElse", () => { - Util.deepStrictEqual(pipe(Option.some(1), Option.getOrElse(() => 0)), 1) - Util.deepStrictEqual(pipe(Option.none(), Option.getOrElse(() => 0)), 0) + strictEqual(pipe(Option.some(1), Option.getOrElse(() => 0)), 1) + strictEqual(pipe(Option.none(), Option.getOrElse(() => 0)), 0) }) it("getOrNull", () => { - Util.deepStrictEqual(Option.getOrNull(Option.none()), null) - Util.deepStrictEqual(Option.getOrNull(Option.some(1)), 1) + strictEqual(Option.getOrNull(Option.none()), null) + strictEqual(Option.getOrNull(Option.some(1)), 1) }) it("getOrUndefined", () => { - Util.deepStrictEqual(Option.getOrUndefined(Option.none()), undefined) - Util.deepStrictEqual(Option.getOrUndefined(Option.some(1)), 1) + strictEqual(Option.getOrUndefined(Option.none()), undefined) + strictEqual(Option.getOrUndefined(Option.some(1)), 1) }) it("getOrder", () => { const OS = Option.getOrder(S.Order) - Util.deepStrictEqual(OS(Option.none(), Option.none()), 0) - Util.deepStrictEqual(OS(Option.some("a"), Option.none()), 1) - Util.deepStrictEqual(OS(Option.none(), Option.some("a")), -1) - Util.deepStrictEqual(OS(Option.some("a"), Option.some("a")), 0) - Util.deepStrictEqual(OS(Option.some("a"), Option.some("b")), -1) - Util.deepStrictEqual(OS(Option.some("b"), Option.some("a")), 1) + strictEqual(OS(Option.none(), Option.none()), 0) + strictEqual(OS(Option.some("a"), Option.none()), 1) + strictEqual(OS(Option.none(), Option.some("a")), -1) + strictEqual(OS(Option.some("a"), Option.some("a")), 0) + strictEqual(OS(Option.some("a"), Option.some("b")), -1) + strictEqual(OS(Option.some("b"), Option.some("a")), 1) }) it("flatMapNullable", () => { @@ -320,240 +308,241 @@ describe("Option", () => { const x1: X = { a: {} } const x2: X = { a: { b: {} } } const x3: X = { a: { b: { c: { d: 1 } } } } - Util.deepStrictEqual( + assertNone( pipe( Option.fromNullable(x1.a), Option.flatMapNullable((x) => x.b), Option.flatMapNullable((x) => x.c), Option.flatMapNullable((x) => x.d) - ), - Option.none() + ) ) - Util.deepStrictEqual( + assertNone( pipe( Option.fromNullable(x2.a), Option.flatMapNullable((x) => x.b), Option.flatMapNullable((x) => x.c), Option.flatMapNullable((x) => x.d) - ), - Option.none() + ) ) - Util.deepStrictEqual( + assertSome( pipe( Option.fromNullable(x3.a), Option.flatMapNullable((x) => x.b), Option.flatMapNullable((x) => x.c), Option.flatMapNullable((x) => x.d) ), - Option.some(1) + 1 ) }) it("fromNullable", () => { - Util.deepStrictEqual(Option.fromNullable(2), Option.some(2)) - Util.deepStrictEqual(Option.fromNullable(null), Option.none()) - Util.deepStrictEqual(Option.fromNullable(undefined), Option.none()) + assertSome(Option.fromNullable(2), 2) + assertNone(Option.fromNullable(null)) + assertNone(Option.fromNullable(undefined)) }) it("liftPredicate", () => { - Util.deepStrictEqual(pipe(1, Option.liftPredicate(p)), Option.none()) - Util.deepStrictEqual(pipe(3, Option.liftPredicate(p)), Option.some(3)) - Util.deepStrictEqual(Option.liftPredicate(1, p), Option.none()) - Util.deepStrictEqual(Option.liftPredicate(3, p), Option.some(3)) + assertNone(pipe(1, Option.liftPredicate(gt2))) + assertSome(pipe(3, Option.liftPredicate(gt2)), 3) + assertNone(Option.liftPredicate(1, gt2)) + assertSome(Option.liftPredicate(3, gt2), 3) type Direction = "asc" | "desc" const isDirection = (s: string): s is Direction => s === "asc" || s === "desc" - Util.deepStrictEqual(pipe("asc", Option.liftPredicate(isDirection)), Option.some("asc")) - Util.deepStrictEqual(pipe("foo", Option.liftPredicate(isDirection)), Option.none()) - Util.deepStrictEqual(Option.liftPredicate("asc", isDirection), Option.some("asc")) - Util.deepStrictEqual(Option.liftPredicate("foo", isDirection), Option.none()) + assertSome(pipe("asc", Option.liftPredicate(isDirection)), "asc") + assertNone(pipe("foo", Option.liftPredicate(isDirection))) + assertSome(Option.liftPredicate("asc", isDirection), "asc") + assertNone(Option.liftPredicate("foo", isDirection)) }) it("containsWith", () => { const containsWith = Option.containsWith((self, that) => self % 2 === that % 2) - Util.deepStrictEqual(pipe(Option.some(2), containsWith(2)), true) - Util.deepStrictEqual(pipe(Option.some(4), containsWith(4)), true) - Util.deepStrictEqual(pipe(Option.some(1), containsWith(3)), true) + assertTrue(pipe(Option.some(2), containsWith(2))) + assertTrue(pipe(Option.some(4), containsWith(4))) + assertTrue(pipe(Option.some(1), containsWith(3))) - Util.deepStrictEqual(pipe(Option.none(), containsWith(2)), false) - Util.deepStrictEqual(pipe(Option.some(2), containsWith(1)), false) + assertFalse(pipe(Option.none(), containsWith(2))) + assertFalse(pipe(Option.some(2), containsWith(1))) }) it("contains", () => { - Util.deepStrictEqual(pipe(Option.none(), Option.contains(2)), false) - Util.deepStrictEqual(pipe(Option.some(2), Option.contains(2)), true) - Util.deepStrictEqual(pipe(Option.some(2), Option.contains(1)), false) + assertFalse(pipe(Option.none(), Option.contains(2))) + assertTrue(pipe(Option.some(2), Option.contains(2))) + assertFalse(pipe(Option.some(2), Option.contains(1))) }) it("isNone", () => { - Util.deepStrictEqual(Option.isNone(Option.none()), true) - Util.deepStrictEqual(Option.isNone(Option.some(1)), false) + assertTrue(Option.isNone(Option.none())) + assertFalse(Option.isNone(Option.some(1))) }) it("isSome", () => { - Util.deepStrictEqual(Option.isSome(Option.none()), false) - Util.deepStrictEqual(Option.isSome(Option.some(1)), true) + assertFalse(Option.isSome(Option.none())) + assertTrue(Option.isSome(Option.some(1))) }) it("exists", () => { const predicate = (a: number) => a === 2 - Util.deepStrictEqual(pipe(Option.none(), Option.exists(predicate)), false) - Util.deepStrictEqual(pipe(Option.some(1), Option.exists(predicate)), false) - Util.deepStrictEqual(pipe(Option.some(2), Option.exists(predicate)), true) + assertFalse(pipe(Option.none(), Option.exists(predicate))) + assertFalse(pipe(Option.some(1), Option.exists(predicate))) + assertTrue(pipe(Option.some(2), Option.exists(predicate))) }) it("liftNullable", () => { const f = Option.liftNullable((n: number) => (n > 0 ? n : null)) - Util.deepStrictEqual(f(1), Option.some(1)) - Util.deepStrictEqual(f(-1), Option.none()) + assertSome(f(1), 1) + assertNone(f(-1)) }) it("liftThrowable", () => { const parse = Option.liftThrowable(JSON.parse) - Util.deepStrictEqual(parse("1"), Option.some(1)) - Util.deepStrictEqual(parse(""), Option.none()) + assertSome(parse("1"), 1) + assertNone(parse("")) }) it("tap", () => { - Util.deepStrictEqual(Option.tap(Option.none(), () => Option.none()), Option.none()) - Util.deepStrictEqual(Option.tap(Option.some(1), () => Option.none()), Option.none()) - Util.deepStrictEqual(Option.tap(Option.none(), (n) => Option.some(n * 2)), Option.none()) - Util.deepStrictEqual(Option.tap(Option.some(1), (n) => Option.some(n * 2)), Option.some(1)) + assertNone(Option.tap(Option.none(), () => Option.none())) + assertNone(Option.tap(Option.some(1), () => Option.none())) + assertNone(Option.tap(Option.none(), (n) => Option.some(n * 2))) + assertSome(Option.tap(Option.some(1), (n) => Option.some(n * 2)), 1) }) it("guard", () => { - Util.deepStrictEqual( + assertSome( pipe( Option.Do, Option.bind("x", () => Option.some("a")), Option.bind("y", () => Option.some("a")), Option.filter(({ x, y }) => x === y) ), - Option.some({ x: "a", y: "a" }) + { x: "a", y: "a" } ) - Util.deepStrictEqual( + assertNone( pipe( Option.Do, Option.bind("x", () => Option.some("a")), Option.bind("y", () => Option.some("b")), Option.filter(({ x, y }) => x === y) - ), - Option.none() + ) ) }) it("zipWith", () => { - expect(pipe(Option.none(), Option.zipWith(Option.some(2), (a, b) => a + b))).toEqual(Option.none()) - expect(pipe(Option.some(1), Option.zipWith(Option.none(), (a, b) => a + b))).toEqual(Option.none()) - expect(pipe(Option.some(1), Option.zipWith(Option.some(2), (a, b) => a + b))).toEqual(Option.some(3)) + assertNone(pipe(Option.none(), Option.zipWith(Option.some(2), (a, b) => a + b))) + assertNone(pipe(Option.some(1), Option.zipWith(Option.none(), (a, b) => a + b))) + assertSome(pipe(Option.some(1), Option.zipWith(Option.some(2), (a, b) => a + b)), 3) }) it("ap", () => { - expect(pipe(Option.some((a: number) => (b: number) => a + b), Option.ap(Option.none()), Option.ap(Option.some(2)))) - .toEqual(Option.none()) - expect(pipe(Option.some((a: number) => (b: number) => a + b), Option.ap(Option.some(1)), Option.ap(Option.none()))) - .toEqual(Option.none()) - expect(pipe(Option.some((a: number) => (b: number) => a + b), Option.ap(Option.some(1)), Option.ap(Option.some(2)))) - .toEqual(Option.some(3)) + assertNone( + pipe(Option.some((a: number) => (b: number) => a + b), Option.ap(Option.none()), Option.ap(Option.some(2))) + ) + assertNone( + pipe(Option.some((a: number) => (b: number) => a + b), Option.ap(Option.some(1)), Option.ap(Option.none())) + ) + assertSome( + pipe(Option.some((a: number) => (b: number) => a + b), Option.ap(Option.some(1)), Option.ap(Option.some(2))), + 3 + ) }) it("reduceCompact", () => { const sumCompact = Option.reduceCompact(0, N.sum) - expect(sumCompact([])).toEqual(0) - expect(sumCompact([Option.some(2), Option.some(3)])).toEqual(5) - expect(sumCompact([Option.some(2), Option.none(), Option.some(3)])).toEqual(5) + strictEqual(sumCompact([]), 0) + strictEqual(sumCompact([Option.some(2), Option.some(3)]), 5) + strictEqual(sumCompact([Option.some(2), Option.none(), Option.some(3)]), 5) }) it("getEquivalence", () => { const isEquivalent = Option.getEquivalence(N.Equivalence) - expect(isEquivalent(Option.none(), Option.none())).toEqual(true) - expect(isEquivalent(Option.none(), Option.some(1))).toEqual(false) - expect(isEquivalent(Option.some(1), Option.none())).toEqual(false) - expect(isEquivalent(Option.some(2), Option.some(1))).toEqual(false) - expect(isEquivalent(Option.some(1), Option.some(2))).toEqual(false) - expect(isEquivalent(Option.some(2), Option.some(2))).toEqual(true) + assertTrue(isEquivalent(Option.none(), Option.none())) + assertFalse(isEquivalent(Option.none(), Option.some(1))) + assertFalse(isEquivalent(Option.some(1), Option.none())) + assertFalse(isEquivalent(Option.some(2), Option.some(1))) + assertFalse(isEquivalent(Option.some(1), Option.some(2))) + assertTrue(isEquivalent(Option.some(2), Option.some(2))) }) it("all/ tuple", () => { assertType>(Option.all([Option.some(1), Option.some("hello")])) - assert.deepStrictEqual(Option.all([]), Option.some([])) - assert.deepStrictEqual(Option.all([Option.some(1), Option.some("hello")]), Option.some([1, "hello"])) - assert.deepStrictEqual(Option.all([Option.some(1), Option.none()]), Option.none()) + assertSome(Option.all([]), []) + assertSome(Option.all([Option.some(1), Option.some("hello")]), [1, "hello"]) + assertNone(Option.all([Option.some(1), Option.none()])) }) it("all/ iterable", () => { assertType>>(Option.all([Option.some(1), Option.some(2)])) assertType>>(Option.all(new Set([Option.some(1), Option.some(2)]))) - Util.deepStrictEqual(Option.all([]), Option.some([])) - Util.deepStrictEqual(Option.all([Option.none()]), Option.none()) - Util.deepStrictEqual(Option.all([Option.some(1), Option.some(2)]), Option.some([1, 2])) - Util.deepStrictEqual(Option.all(new Set([Option.some(1), Option.some(2)])), Option.some([1, 2])) - Util.deepStrictEqual(Option.all([Option.some(1), Option.none()]), Option.none()) + assertSome(Option.all([]), []) + assertNone(Option.all([Option.none()])) + assertSome(Option.all([Option.some(1), Option.some(2)]), [1, 2]) + assertSome(Option.all(new Set([Option.some(1), Option.some(2)])), [1, 2]) + assertNone(Option.all([Option.some(1), Option.none()])) }) it("all/ struct", () => { assertType>(Option.all({ a: Option.some(1), b: Option.some("hello") })) - assert.deepStrictEqual( + assertSome( Option.all({ a: Option.some(1), b: Option.some("hello") }), - Option.some({ a: 1, b: "hello" }) + { a: 1, b: "hello" } ) - assert.deepStrictEqual(Option.all({ a: Option.some(1), b: Option.none() }), Option.none()) + assertNone(Option.all({ a: Option.some(1), b: Option.none() })) }) it(".pipe()", () => { - expect(Option.some(1).pipe(Option.map((n) => n + 1))).toEqual(Option.some(2)) + assertSome(Option.some(1).pipe(Option.map((n) => n + 1)), 2) }) it("lift2", () => { const f = Option.lift2((a: number, b: number): number => a + b) - expect(f(Option.none(), Option.none())).toStrictEqual(Option.none()) - expect(f(Option.some(1), Option.none())).toStrictEqual(Option.none()) - expect(f(Option.none(), Option.some(2))).toStrictEqual(Option.none()) - expect(f(Option.some(1), Option.some(2))).toStrictEqual(Option.some(3)) + assertNone(f(Option.none(), Option.none())) + assertNone(f(Option.some(1), Option.none())) + assertNone(f(Option.none(), Option.some(2))) + assertSome(f(Option.some(1), Option.some(2)), 3) }) describe("do notation", () => { it("Do", () => { - expectSome(Option.Do, {}) + assertSome(Option.Do, {}) }) it("bindTo", () => { - expectSome(pipe(Option.some(1), Option.bindTo("a")), { a: 1 }) - expectNone(pipe(Option.none(), Option.bindTo("a"))) + assertSome(pipe(Option.some(1), Option.bindTo("a")), { a: 1 }) + assertNone(pipe(Option.none(), Option.bindTo("a"))) }) it("bind", () => { - expectSome(pipe(Option.some(1), Option.bindTo("a"), Option.bind("b", ({ a }) => Option.some(a + 1))), { + assertSome(pipe(Option.some(1), Option.bindTo("a"), Option.bind("b", ({ a }) => Option.some(a + 1))), { a: 1, b: 2 }) - expectNone( + assertNone( pipe(Option.some(1), Option.bindTo("a"), Option.bind("b", () => Option.none())) ) - expectNone( + assertNone( pipe(Option.none(), Option.bindTo("a"), Option.bind("b", () => Option.some(2))) ) }) it("let", () => { - expectSome(pipe(Option.some(1), Option.bindTo("a"), Option.let("b", ({ a }) => a + 1)), { a: 1, b: 2 }) - expectNone( + assertSome(pipe(Option.some(1), Option.bindTo("a"), Option.let("b", ({ a }) => a + 1)), { a: 1, b: 2 }) + assertNone( pipe(Option.none(), Option.bindTo("a"), Option.let("b", () => 2)) ) }) }) it("as", () => { - expectNone(Option.none().pipe(Option.as("a"))) - expectSome(Option.some(1).pipe(Option.as("a")), "a") + assertNone(Option.none().pipe(Option.as("a"))) + assertSome(Option.some(1).pipe(Option.as("a")), "a") - expectNone(Option.as(Option.none(), "a")) - expectSome(Option.as(Option.some(1), "a"), "a") + assertNone(Option.as(Option.none(), "a")) + assertSome(Option.as(Option.some(1), "a"), "a") }) it("asVoid", () => { - expectNone(Option.none().pipe(Option.asVoid)) - expectSome(Option.some(1).pipe(Option.asVoid), undefined) + assertNone(Option.none().pipe(Option.asVoid)) + assertSome(Option.some(1).pipe(Option.asVoid), undefined) }) }) diff --git a/packages/effect/test/Order.test.ts b/packages/effect/test/Order.test.ts index 6b2e8781c2e..64218360847 100644 --- a/packages/effect/test/Order.test.ts +++ b/packages/effect/test/Order.test.ts @@ -1,151 +1,149 @@ -import { sort } from "effect/Array" -import { pipe } from "effect/Function" -import * as _ from "effect/Order" -import * as U from "effect/test/util" +import { Array as Arr, Order, pipe } from "effect" +import { assertFalse, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import { describe, it } from "vitest" describe("Order", () => { it("struct", () => { - const O = _.struct({ a: _.string, b: _.string }) - U.deepStrictEqual(O({ a: "a", b: "b" }, { a: "a", b: "c" }), -1) - U.deepStrictEqual(O({ a: "a", b: "b" }, { a: "a", b: "b" }), 0) - U.deepStrictEqual(O({ a: "a", b: "c" }, { a: "a", b: "b" }), 1) + const O = Order.struct({ a: Order.string, b: Order.string }) + strictEqual(O({ a: "a", b: "b" }, { a: "a", b: "c" }), -1) + strictEqual(O({ a: "a", b: "b" }, { a: "a", b: "b" }), 0) + strictEqual(O({ a: "a", b: "c" }, { a: "a", b: "b" }), 1) }) it("tuple", () => { - const O = _.tuple(_.string, _.string) - U.deepStrictEqual(O(["a", "b"], ["a", "c"]), -1) - U.deepStrictEqual(O(["a", "b"], ["a", "b"]), 0) - U.deepStrictEqual(O(["a", "b"], ["a", "a"]), 1) - U.deepStrictEqual(O(["a", "b"], ["b", "a"]), -1) + const O = Order.tuple(Order.string, Order.string) + strictEqual(O(["a", "b"], ["a", "c"]), -1) + strictEqual(O(["a", "b"], ["a", "b"]), 0) + strictEqual(O(["a", "b"], ["a", "a"]), 1) + strictEqual(O(["a", "b"], ["b", "a"]), -1) }) it("all", () => { - const O = _.all([_.string, _.string, _.string]) - U.deepStrictEqual(O([], []), 0) - U.deepStrictEqual(O(["a", "b"], ["a"]), 0) - U.deepStrictEqual(O(["a"], ["a", "c"]), 0) - U.deepStrictEqual(O(["a", "b"], ["a", "c"]), -1) - U.deepStrictEqual(O(["a", "b"], ["a", "b"]), 0) - U.deepStrictEqual(O(["a", "b"], ["a", "a"]), 1) - U.deepStrictEqual(O(["a", "b"], ["b", "a"]), -1) + const O = Order.all([Order.string, Order.string, Order.string]) + strictEqual(O([], []), 0) + strictEqual(O(["a", "b"], ["a"]), 0) + strictEqual(O(["a"], ["a", "c"]), 0) + strictEqual(O(["a", "b"], ["a", "c"]), -1) + strictEqual(O(["a", "b"], ["a", "b"]), 0) + strictEqual(O(["a", "b"], ["a", "a"]), 1) + strictEqual(O(["a", "b"], ["b", "a"]), -1) }) it("mapInput", () => { - const O = _.mapInput(_.number, (s: string) => s.length) - U.deepStrictEqual(O("a", "b"), 0) - U.deepStrictEqual(O("a", "bb"), -1) - U.deepStrictEqual(O("aa", "b"), 1) + const O = Order.mapInput(Order.number, (s: string) => s.length) + strictEqual(O("a", "b"), 0) + strictEqual(O("a", "bb"), -1) + strictEqual(O("aa", "b"), 1) }) it("Date", () => { - const O = _.Date - U.deepStrictEqual(O(new Date(0), new Date(1)), -1) - U.deepStrictEqual(O(new Date(1), new Date(1)), 0) - U.deepStrictEqual(O(new Date(1), new Date(0)), 1) + const O = Order.Date + strictEqual(O(new Date(0), new Date(1)), -1) + strictEqual(O(new Date(1), new Date(1)), 0) + strictEqual(O(new Date(1), new Date(0)), 1) }) it("clamp", () => { - const clamp = _.clamp(_.number)({ minimum: 1, maximum: 10 }) - U.deepStrictEqual(clamp(2), 2) - U.deepStrictEqual(clamp(10), 10) - U.deepStrictEqual(clamp(20), 10) - U.deepStrictEqual(clamp(1), 1) - U.deepStrictEqual(clamp(-10), 1) + const clamp = Order.clamp(Order.number)({ minimum: 1, maximum: 10 }) + strictEqual(clamp(2), 2) + strictEqual(clamp(10), 10) + strictEqual(clamp(20), 10) + strictEqual(clamp(1), 1) + strictEqual(clamp(-10), 1) - U.deepStrictEqual(_.clamp(_.number)({ minimum: 1, maximum: 10 })(2), 2) + strictEqual(Order.clamp(Order.number)({ minimum: 1, maximum: 10 })(2), 2) }) it("between", () => { - const between = _.between(_.number)({ minimum: 1, maximum: 10 }) - U.deepStrictEqual(between(2), true) - U.deepStrictEqual(between(10), true) - U.deepStrictEqual(between(20), false) - U.deepStrictEqual(between(1), true) - U.deepStrictEqual(between(-10), false) + const between = Order.between(Order.number)({ minimum: 1, maximum: 10 }) + assertTrue(between(2)) + assertTrue(between(10)) + assertFalse(between(20)) + assertTrue(between(1)) + assertFalse(between(-10)) - U.deepStrictEqual(_.between(_.number)(2, { minimum: 1, maximum: 10 }), true) + assertTrue(Order.between(Order.number)(2, { minimum: 1, maximum: 10 })) }) it("reverse", () => { - const O = _.reverse(_.number) - U.deepStrictEqual(O(1, 2), 1) - U.deepStrictEqual(O(2, 1), -1) - U.deepStrictEqual(O(2, 2), 0) + const O = Order.reverse(Order.number) + strictEqual(O(1, 2), 1) + strictEqual(O(2, 1), -1) + strictEqual(O(2, 2), 0) }) it("lessThan", () => { - const lessThan = _.lessThan(_.number) - U.deepStrictEqual(lessThan(0, 1), true) - U.deepStrictEqual(lessThan(1, 1), false) - U.deepStrictEqual(lessThan(2, 1), false) + const lessThan = Order.lessThan(Order.number) + assertTrue(lessThan(0, 1)) + assertFalse(lessThan(1, 1)) + assertFalse(lessThan(2, 1)) }) it("lessThanOrEqualTo", () => { - const lessThanOrEqualTo = _.lessThanOrEqualTo(_.number) - U.deepStrictEqual(lessThanOrEqualTo(0, 1), true) - U.deepStrictEqual(lessThanOrEqualTo(1, 1), true) - U.deepStrictEqual(lessThanOrEqualTo(2, 1), false) + const lessThanOrEqualTo = Order.lessThanOrEqualTo(Order.number) + assertTrue(lessThanOrEqualTo(0, 1)) + assertTrue(lessThanOrEqualTo(1, 1)) + assertFalse(lessThanOrEqualTo(2, 1)) }) it("greaterThan", () => { - const greaterThan = _.greaterThan(_.number) - U.deepStrictEqual(greaterThan(0, 1), false) - U.deepStrictEqual(greaterThan(1, 1), false) - U.deepStrictEqual(greaterThan(2, 1), true) + const greaterThan = Order.greaterThan(Order.number) + assertFalse(greaterThan(0, 1)) + assertFalse(greaterThan(1, 1)) + assertTrue(greaterThan(2, 1)) }) it("greaterThanOrEqualTo", () => { - const greaterThanOrEqualTo = _.greaterThanOrEqualTo(_.number) - U.deepStrictEqual(greaterThanOrEqualTo(0, 1), false) - U.deepStrictEqual(greaterThanOrEqualTo(1, 1), true) - U.deepStrictEqual(greaterThanOrEqualTo(2, 1), true) + const greaterThanOrEqualTo = Order.greaterThanOrEqualTo(Order.number) + assertFalse(greaterThanOrEqualTo(0, 1)) + assertTrue(greaterThanOrEqualTo(1, 1)) + assertTrue(greaterThanOrEqualTo(2, 1)) }) it("min", () => { type A = { a: number } - const min = _.min( + const min = Order.min( pipe( - _.number, - _.mapInput((a: A) => a.a) + Order.number, + Order.mapInput((a: A) => a.a) ) ) - U.deepStrictEqual(min({ a: 1 }, { a: 2 }), { a: 1 }) - U.deepStrictEqual(min({ a: 2 }, { a: 1 }), { a: 1 }) + deepStrictEqual(min({ a: 1 }, { a: 2 }), { a: 1 }) + deepStrictEqual(min({ a: 2 }, { a: 1 }), { a: 1 }) const first = { a: 1 } const second = { a: 1 } - U.strictEqual(min(first, second), first) + deepStrictEqual(min(first, second), first) }) it("max", () => { type A = { a: number } - const max = _.max( + const max = Order.max( pipe( - _.number, - _.mapInput((a: A) => a.a) + Order.number, + Order.mapInput((a: A) => a.a) ) ) - U.deepStrictEqual(max({ a: 1 }, { a: 2 }), { a: 2 }) - U.deepStrictEqual(max({ a: 2 }, { a: 1 }), { a: 2 }) + deepStrictEqual(max({ a: 1 }, { a: 2 }), { a: 2 }) + deepStrictEqual(max({ a: 2 }, { a: 1 }), { a: 2 }) const first = { a: 1 } const second = { a: 1 } - U.strictEqual(max(first, second), first) + deepStrictEqual(max(first, second), first) }) it("product", () => { - const O = _.product(_.string, _.number) - U.deepStrictEqual(O(["a", 1], ["a", 2]), -1) - U.deepStrictEqual(O(["a", 1], ["a", 1]), 0) - U.deepStrictEqual(O(["a", 1], ["a", 0]), 1) - U.deepStrictEqual(O(["a", 1], ["b", 1]), -1) + const O = Order.product(Order.string, Order.number) + strictEqual(O(["a", 1], ["a", 2]), -1) + strictEqual(O(["a", 1], ["a", 1]), 0) + strictEqual(O(["a", 1], ["a", 0]), 1) + strictEqual(O(["a", 1], ["b", 1]), -1) }) it("productMany", () => { - const O = _.productMany(_.string, [_.string, _.string]) - U.deepStrictEqual(O(["a", "b"], ["a", "c"]), -1) - U.deepStrictEqual(O(["a", "b"], ["a", "b"]), 0) - U.deepStrictEqual(O(["a", "b"], ["a", "a"]), 1) - U.deepStrictEqual(O(["a", "b"], ["b", "a"]), -1) + const O = Order.productMany(Order.string, [Order.string, Order.string]) + strictEqual(O(["a", "b"], ["a", "c"]), -1) + strictEqual(O(["a", "b"], ["a", "b"]), 0) + strictEqual(O(["a", "b"], ["a", "a"]), 1) + strictEqual(O(["a", "b"], ["b", "a"]), -1) }) it("combine / combineMany", () => { @@ -157,32 +155,32 @@ describe("Order", () => { [1, "c"] ] const sortByFst = pipe( - _.number, - _.mapInput((x: T) => x[0]) + Order.number, + Order.mapInput((x: T) => x[0]) ) const sortBySnd = pipe( - _.string, - _.mapInput((x: T) => x[1]) + Order.string, + Order.mapInput((x: T) => x[1]) ) - U.deepStrictEqual(sort(_.combine(sortByFst, sortBySnd))(tuples), [ + deepStrictEqual(Arr.sort(Order.combine(sortByFst, sortBySnd))(tuples), [ [1, "b"], [1, "c"], [2, "a"], [2, "c"] ]) - U.deepStrictEqual(sort(_.combine(sortBySnd, sortByFst))(tuples), [ + deepStrictEqual(Arr.sort(Order.combine(sortBySnd, sortByFst))(tuples), [ [2, "a"], [1, "b"], [1, "c"], [2, "c"] ]) - U.deepStrictEqual(sort(_.combineMany(sortBySnd, []))(tuples), [ + deepStrictEqual(Arr.sort(Order.combineMany(sortBySnd, []))(tuples), [ [2, "a"], [1, "b"], [2, "c"], [1, "c"] ]) - U.deepStrictEqual(sort(_.combineMany(sortBySnd, [sortByFst]))(tuples), [ + deepStrictEqual(Arr.sort(Order.combineMany(sortBySnd, [sortByFst]))(tuples), [ [2, "a"], [1, "b"], [1, "c"], diff --git a/packages/effect/test/Ordering.test.ts b/packages/effect/test/Ordering.test.ts index 9fb8f5b1a49..5155a442271 100644 --- a/packages/effect/test/Ordering.test.ts +++ b/packages/effect/test/Ordering.test.ts @@ -1,39 +1,39 @@ -import * as _ from "effect/Ordering" -import { deepStrictEqual } from "effect/test/util" +import { Ordering } from "effect" +import { strictEqual } from "effect/test/util" import { describe, it } from "vitest" describe("Ordering", () => { it("match", () => { - const f = _.match({ + const f = Ordering.match({ onLessThan: () => "lt", onEqual: () => "eq", onGreaterThan: () => "gt" }) - deepStrictEqual(f(-1), "lt") - deepStrictEqual(f(0), "eq") - deepStrictEqual(f(1), "gt") + strictEqual(f(-1), "lt") + strictEqual(f(0), "eq") + strictEqual(f(1), "gt") }) it("reverse", () => { - deepStrictEqual(_.reverse(-1), 1) - deepStrictEqual(_.reverse(0), 0) - deepStrictEqual(_.reverse(1), -1) + strictEqual(Ordering.reverse(-1), 1) + strictEqual(Ordering.reverse(0), 0) + strictEqual(Ordering.reverse(1), -1) }) it("combine", () => { - deepStrictEqual(_.combine(0, 0), 0) - deepStrictEqual(_.combine(0, 1), 1) - deepStrictEqual(_.combine(1, -1), 1) - deepStrictEqual(_.combine(-1, 1), -1) + strictEqual(Ordering.combine(0, 0), 0) + strictEqual(Ordering.combine(0, 1), 1) + strictEqual(Ordering.combine(1, -1), 1) + strictEqual(Ordering.combine(-1, 1), -1) }) it("combineMany", () => { - deepStrictEqual(_.combineMany(0, []), 0) - deepStrictEqual(_.combineMany(1, []), 1) - deepStrictEqual(_.combineMany(-1, []), -1) - deepStrictEqual(_.combineMany(0, [0, 0, 0]), 0) - deepStrictEqual(_.combineMany(0, [0, 0, 1]), 1) - deepStrictEqual(_.combineMany(1, [0, 0, -1]), 1) - deepStrictEqual(_.combineMany(-1, [0, 0, 1]), -1) + strictEqual(Ordering.combineMany(0, []), 0) + strictEqual(Ordering.combineMany(1, []), 1) + strictEqual(Ordering.combineMany(-1, []), -1) + strictEqual(Ordering.combineMany(0, [0, 0, 0]), 0) + strictEqual(Ordering.combineMany(0, [0, 0, 1]), 1) + strictEqual(Ordering.combineMany(1, [0, 0, -1]), 1) + strictEqual(Ordering.combineMany(-1, [0, 0, 1]), -1) }) }) diff --git a/packages/effect/test/Pipeable.test.ts b/packages/effect/test/Pipeable.test.ts index 4937b2d9f73..168323e64e9 100644 --- a/packages/effect/test/Pipeable.test.ts +++ b/packages/effect/test/Pipeable.test.ts @@ -1,29 +1,73 @@ -import * as _ from "effect/Option" -import { describe, expect, it } from "vitest" +import { Option } from "effect" +import { assertSome } from "effect/test/util" +import { describe, it } from "vitest" describe("Pipeable", () => { it("pipeArguments", () => { const f = (n: number): number => n + 1 const g = (n: number): number => n * 2 - expect(_.some(2).pipe(_.map(f))).toEqual(_.some(3)) - expect(_.some(2).pipe(_.map(f), _.map(g))).toEqual(_.some(6)) - expect(_.some(2).pipe(_.map(f), _.map(g), _.map(f))).toEqual(_.some(7)) - expect(_.some(2).pipe(_.map(f), _.map(g), _.map(f), _.map(g))).toEqual(_.some(14)) - expect(_.some(2).pipe(_.map(f), _.map(g), _.map(f), _.map(g), _.map(f))).toEqual(_.some(15)) - expect(_.some(2).pipe(_.map(f), _.map(g), _.map(f), _.map(g), _.map(f), _.map(g))).toEqual(_.some(30)) - expect(_.some(2).pipe(_.map(f), _.map(g), _.map(f), _.map(g), _.map(f), _.map(g), _.map(f))).toEqual(_.some(31)) - expect(_.some(2).pipe(_.map(f), _.map(g), _.map(f), _.map(g), _.map(f), _.map(g), _.map(f), _.map(g))).toEqual( - _.some(62) + assertSome(Option.some(2).pipe(Option.map(f)), 3) + assertSome(Option.some(2).pipe(Option.map(f), Option.map(g)), 6) + assertSome(Option.some(2).pipe(Option.map(f), Option.map(g), Option.map(f)), 7) + assertSome(Option.some(2).pipe(Option.map(f), Option.map(g), Option.map(f), Option.map(g)), 14) + assertSome(Option.some(2).pipe(Option.map(f), Option.map(g), Option.map(f), Option.map(g), Option.map(f)), 15) + assertSome( + Option.some(2).pipe(Option.map(f), Option.map(g), Option.map(f), Option.map(g), Option.map(f), Option.map(g)), + 30 ) - expect(_.some(2).pipe(_.map(f), _.map(g), _.map(f), _.map(g), _.map(f), _.map(g), _.map(f), _.map(g), _.map(f))) - .toEqual( - _.some(63) - ) - expect( - _.some(2).pipe(_.map(f), _.map(g), _.map(f), _.map(g), _.map(f), _.map(g), _.map(f), _.map(g), _.map(f), _.map(g)) + assertSome( + Option.some(2).pipe( + Option.map(f), + Option.map(g), + Option.map(f), + Option.map(g), + Option.map(f), + Option.map(g), + Option.map(f) + ), + 31 + ) + assertSome( + Option.some(2).pipe( + Option.map(f), + Option.map(g), + Option.map(f), + Option.map(g), + Option.map(f), + Option.map(g), + Option.map(f), + Option.map(g) + ), + 62 + ) + assertSome( + Option.some(2).pipe( + Option.map(f), + Option.map(g), + Option.map(f), + Option.map(g), + Option.map(f), + Option.map(g), + Option.map(f), + Option.map(g), + Option.map(f) + ), + 63 + ) + assertSome( + Option.some(2).pipe( + Option.map(f), + Option.map(g), + Option.map(f), + Option.map(g), + Option.map(f), + Option.map(g), + Option.map(f), + Option.map(g), + Option.map(f), + Option.map(g) + ), + 126 ) - .toEqual( - _.some(126) - ) }) }) diff --git a/packages/effect/test/Pool.test.ts b/packages/effect/test/Pool.test.ts index 7e98bf75de1..8394285889f 100644 --- a/packages/effect/test/Pool.test.ts +++ b/packages/effect/test/Pool.test.ts @@ -1,5 +1,6 @@ -import { Deferred, Duration, Effect, Exit, Fiber, Option, Pool, Ref, Scope, TestClock, TestServices } from "effect" -import { assert, describe, expect, it } from "effect/test/utils/extend" +import { Deferred, Duration, Effect, Exit, Fiber, Pool, Ref, Scope, TestClock, TestServices } from "effect" +import { assertNone, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "effect/test/utils/extend" describe("Pool", () => { it.scoped("preallocates pool items", () => @@ -12,7 +13,7 @@ describe("Pool", () => { yield* Pool.make({ acquire: get, size: 10 }) yield* Effect.repeat(Ref.get(count), { until: (n) => n === 10 }) const result = yield* Ref.get(count) - assert.strictEqual(result, 10) + strictEqual(result, 10) })) // it.scoped("benchmark", () => @@ -38,7 +39,7 @@ describe("Pool", () => { yield* Effect.repeat(Ref.get(count), { until: (n) => n === 10 }) yield* Scope.close(scope, Exit.succeed(void 0)) const result = yield* Ref.get(count) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.scoped("defects don't prevent cleanup", () => @@ -53,7 +54,7 @@ describe("Pool", () => { yield* Effect.repeat(Ref.get(count), { until: (n) => n === 10 }) yield* Scope.close(scope, Exit.succeed(void 0)) const result = yield* Ref.get(count) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.scoped("acquire one item", () => @@ -66,7 +67,7 @@ describe("Pool", () => { const pool = yield* $(Pool.make({ acquire: get, size: 10 })) yield* $(Effect.repeat(Ref.get(count), { until: (n) => n === 10 })) const item = yield* $(Pool.get(pool)) - assert.strictEqual(item, 1) + strictEqual(item, 1) })) it.scoped("reports failures via get", () => @@ -81,7 +82,7 @@ describe("Pool", () => { ) const pool = yield* $(Pool.make({ acquire: get, size: 10 })) const values = yield* $(Effect.all(Effect.replicate(9)(Effect.flip(Pool.get(pool))))) - expect(Array.from(values)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]) + deepStrictEqual(Array.from(values), [1, 2, 3, 4, 5, 6, 7, 8, 9]) })) it.scoped("blocks when item not available", () => @@ -101,7 +102,7 @@ describe("Pool", () => { Effect.option ) )) - expect(result).toEqual(Option.none()) + assertNone(result) })) it.scoped("reuse released items", () => @@ -114,7 +115,7 @@ describe("Pool", () => { const pool = yield* $(Pool.make({ acquire: get, size: 10 })) yield* $(Effect.repeatN(99)(Effect.scoped(Pool.get(pool)))) const result = yield* $(Ref.get(count)) - expect(result).toBe(10) + strictEqual(result, 10) })) it.scoped("invalidate item", () => @@ -130,8 +131,8 @@ describe("Pool", () => { yield* Effect.yieldNow() // allow lazy resize to run const result = yield* Effect.scoped(Pool.get(pool)) const value = yield* Ref.get(count) - expect(result).toBe(2) - expect(value).toBe(10) + strictEqual(result, 2) + strictEqual(value, 10) })) it.scoped("invalidate all items in pool and check that pool.get doesn't hang forever", () => @@ -149,9 +150,9 @@ describe("Pool", () => { const result = yield* $(Effect.scoped(Pool.get(pool))) const allocatedCount = yield* $(Ref.get(allocated)) const finalizedCount = yield* $(Ref.get(finalized)) - expect(result).toBe(3) - expect(allocatedCount).toBe(4) - expect(finalizedCount).toBe(2) + strictEqual(result, 3) + strictEqual(allocatedCount, 4) + strictEqual(finalizedCount, 2) })) it.scoped("retry on failed acquire should not exhaust pool", () => @@ -167,7 +168,7 @@ describe("Pool", () => { Effect.flip, TestServices.provideLive ) - expect(result).toBe("error") + strictEqual(result, "error") })) it.scoped("compositional retry", () => @@ -182,7 +183,7 @@ describe("Pool", () => { ) const pool = yield* $(Pool.make({ acquire: get, size: 10 })) const result = yield* $(Effect.eventually(Effect.scoped(Pool.get(pool)))) - expect(result).toBe(11) + strictEqual(result, 11) })) it.scoped("max pool size", () => @@ -212,8 +213,8 @@ describe("Pool", () => { const max = yield* $(Ref.get(count)) yield* $(TestClock.adjust(Duration.seconds(60))) const min = yield* $(Ref.get(count)) - expect(min).toBe(10) - expect(max).toBe(15) + strictEqual(min, 10) + strictEqual(max, 15) })) it.scoped("max pool size with concurrency: 3", () => @@ -244,8 +245,8 @@ describe("Pool", () => { const max = yield* $(Ref.get(count)) yield* $(TestClock.adjust(Duration.seconds(60))) const min = yield* $(Ref.get(count)) - expect(min).toBe(10) - expect(max).toBe(15) + strictEqual(min, 10) + strictEqual(max, 15) })) it.scoped("concurrency reclaim", () => @@ -271,8 +272,8 @@ describe("Pool", () => { yield* Scope.close(scope1, Exit.void) yield* Pool.get(pool) yield* Pool.get(pool) - assert.strictEqual(yield* Pool.get(pool), 1) - assert.strictEqual(yield* Ref.get(count), 2) + strictEqual(yield* Pool.get(pool), 1) + strictEqual(yield* Ref.get(count), 2) })) it.scoped("scale to zero", () => @@ -303,8 +304,8 @@ describe("Pool", () => { const max = yield* $(Ref.get(count)) yield* $(TestClock.adjust(Duration.seconds(60))) const min = yield* $(Ref.get(count)) - expect(min).toBe(0) - expect(max).toBe(10) + strictEqual(min, 0) + strictEqual(max, 10) })) it.scoped("max pool size creation strategy", () => @@ -331,9 +332,9 @@ describe("Pool", () => { const two = yield* $(Ref.get(invalidated)) yield* Scope.close(scope, Exit.void) const three = yield* $(Ref.get(invalidated)) - assert.strictEqual(one, 0) - assert.strictEqual(two, 0) - assert.strictEqual(three, 15) + strictEqual(one, 0) + strictEqual(two, 0) + strictEqual(three, 15) })) it.scoped("shutdown robustness", () => @@ -352,7 +353,7 @@ describe("Pool", () => { ) yield* $(Scope.close(scope, Exit.succeed(void 0))) const result = yield* $(Effect.repeat(Ref.get(count), { until: (n) => n === 0 })) - expect(result).toBe(0) + strictEqual(result, 0) })) it.scoped("shutdown with pending takers", () => @@ -372,7 +373,7 @@ describe("Pool", () => { ) yield* $(Scope.close(scope, Exit.succeed(void 0))) const result = yield* $(Effect.repeat(Ref.get(count), { until: (n) => n === 0 })) - expect(result).toBe(0) + strictEqual(result, 0) })) it.scoped("get is interruptible", () => @@ -387,7 +388,7 @@ describe("Pool", () => { yield* $(Effect.repeatN(Pool.get(pool), 9)) const fiber = yield* $(Effect.fork(Pool.get(pool))) const result = yield* $(Fiber.interrupt(fiber)) - expect(result).toEqual(Exit.interrupt(fiberId)) + deepStrictEqual(result, Exit.interrupt(fiberId)) })) it.scoped("get is interruptible with dynamic size", () => @@ -398,7 +399,7 @@ describe("Pool", () => { yield* $(Effect.repeatN(Pool.get(pool), 9)) const fiber = yield* $(Effect.fork(Pool.get(pool))) const result = yield* $(Fiber.interrupt(fiber)) - expect(result).toEqual(Exit.interrupt(fiberId)) + deepStrictEqual(result, Exit.interrupt(fiberId)) })) it.scoped("finalizer is called for failed allocations", () => @@ -418,8 +419,8 @@ describe("Pool", () => { yield* Effect.scoped(pool.get).pipe( Effect.ignore ) - expect(yield* Ref.get(allocations)).toBe(2) - expect(yield* Ref.get(released)).toBe(2) + strictEqual(yield* Ref.get(allocations), 2) + strictEqual(yield* Ref.get(released), 2) })) it.scoped("is subtype of Effect", () => @@ -429,6 +430,6 @@ describe("Pool", () => { size: 1 }) const item = yield* pool - assert.strictEqual(item, 1) + strictEqual(item, 1) })) }) diff --git a/packages/effect/test/Predicate.test.ts b/packages/effect/test/Predicate.test.ts index b90676244ab..f4289d56c3b 100644 --- a/packages/effect/test/Predicate.test.ts +++ b/packages/effect/test/Predicate.test.ts @@ -1,7 +1,7 @@ import { constFalse, constTrue, pipe } from "effect/Function" import * as _ from "effect/Predicate" -import { deepStrictEqual } from "effect/test/util" -import { assert, describe, expect, it } from "vitest" +import { assertFalse, assertTrue } from "effect/test/util" +import { describe, it } from "vitest" const isPositive: _.Predicate = (n) => n > 0 const isNegative: _.Predicate = (n) => n < 0 @@ -19,9 +19,9 @@ const isNonEmptyString: _.Refinement = (s): s is NonEmpt describe("Predicate", () => { it("compose", () => { const refinement = pipe(isString, _.compose(isNonEmptyString)) - deepStrictEqual(refinement("a"), true) - deepStrictEqual(refinement(null), false) - deepStrictEqual(refinement(""), false) + assertTrue(refinement("a")) + assertFalse(refinement(null)) + assertFalse(refinement("")) }) it("mapInput", () => { @@ -32,312 +32,312 @@ describe("Predicate", () => { isPositive, _.mapInput((a: A) => a.a) ) - deepStrictEqual(predicate({ a: -1 }), false) - deepStrictEqual(predicate({ a: 0 }), false) - deepStrictEqual(predicate({ a: 1 }), true) + assertFalse(predicate({ a: -1 })) + assertFalse(predicate({ a: 0 })) + assertTrue(predicate({ a: 1 })) }) it("product", () => { const product = _.product const p = product(isPositive, isNegative) - deepStrictEqual(p([1, -1]), true) - deepStrictEqual(p([1, 1]), false) - deepStrictEqual(p([-1, -1]), false) - deepStrictEqual(p([-1, 1]), false) + assertTrue(p([1, -1])) + assertFalse(p([1, 1])) + assertFalse(p([-1, -1])) + assertFalse(p([-1, 1])) }) it("productMany", () => { const productMany = _.productMany const p = productMany(isPositive, [isNegative]) - deepStrictEqual(p([1, -1]), true) - deepStrictEqual(p([1, 1]), false) - deepStrictEqual(p([-1, -1]), false) - deepStrictEqual(p([-1, 1]), false) + assertTrue(p([1, -1])) + assertFalse(p([1, 1])) + assertFalse(p([-1, -1])) + assertFalse(p([-1, 1])) }) it("tuple", () => { const p = _.tuple(isPositive, isNegative) - deepStrictEqual(p([1, -1]), true) - deepStrictEqual(p([1, 1]), false) - deepStrictEqual(p([-1, -1]), false) - deepStrictEqual(p([-1, 1]), false) + assertTrue(p([1, -1])) + assertFalse(p([1, 1])) + assertFalse(p([-1, -1])) + assertFalse(p([-1, 1])) }) it("struct", () => { const p = _.struct({ a: isPositive, b: isNegative }) - deepStrictEqual(p({ a: 1, b: -1 }), true) - deepStrictEqual(p({ a: 1, b: 1 }), false) - deepStrictEqual(p({ a: -1, b: -1 }), false) - deepStrictEqual(p({ a: -1, b: 1 }), false) + assertTrue(p({ a: 1, b: -1 })) + assertFalse(p({ a: 1, b: 1 })) + assertFalse(p({ a: -1, b: -1 })) + assertFalse(p({ a: -1, b: 1 })) }) it("all", () => { const p = _.all([isPositive, isNegative]) - deepStrictEqual(p([1]), true) - deepStrictEqual(p([1, -1]), true) - deepStrictEqual(p([1, 1]), false) - deepStrictEqual(p([-1, -1]), false) - deepStrictEqual(p([-1, 1]), false) + assertTrue(p([1])) + assertTrue(p([1, -1])) + assertFalse(p([1, 1])) + assertFalse(p([-1, -1])) + assertFalse(p([-1, 1])) }) it("not", () => { const p = _.not(isPositive) - deepStrictEqual(p(1), false) - deepStrictEqual(p(0), true) - deepStrictEqual(p(-1), true) + assertFalse(p(1)) + assertTrue(p(0)) + assertTrue(p(-1)) }) it("or", () => { const p = pipe(isPositive, _.or(isNegative)) - deepStrictEqual(p(-1), true) - deepStrictEqual(p(1), true) - deepStrictEqual(p(0), false) + assertTrue(p(-1)) + assertTrue(p(1)) + assertFalse(p(0)) }) it("and", () => { const p = pipe(isPositive, _.and(isLessThan2)) - deepStrictEqual(p(1), true) - deepStrictEqual(p(-1), false) - deepStrictEqual(p(3), false) + assertTrue(p(1)) + assertFalse(p(-1)) + assertFalse(p(3)) }) it("xor", () => { - expect(pipe(constTrue, _.xor(constTrue))(null)).toBeFalsy() // true xor true = false - expect(pipe(constTrue, _.xor(constFalse))(null)).toBeTruthy() // true xor false = true - expect(pipe(constFalse, _.xor(constTrue))(null)).toBeTruthy() // false xor true = true - expect(pipe(constFalse, _.xor(constFalse))(null)).toBeFalsy() // false xor false = false + assertFalse(pipe(constTrue, _.xor(constTrue))(null)) // true xor true = false + assertTrue(pipe(constTrue, _.xor(constFalse))(null)) // true xor false = true + assertTrue(pipe(constFalse, _.xor(constTrue))(null)) // false xor true = true + assertFalse(pipe(constFalse, _.xor(constFalse))(null)) // false xor false = false }) it("eqv", () => { - expect(pipe(constTrue, _.eqv(constTrue))(null)).toBeTruthy() // true eqv true = true - expect(pipe(constTrue, _.eqv(constFalse))(null)).toBeFalsy() // true eqv false = false - expect(pipe(constFalse, _.eqv(constTrue))(null)).toBeFalsy() // false eqv true = false - expect(pipe(constFalse, _.eqv(constFalse))(null)).toBeTruthy() // false eqv false = true + assertTrue(pipe(constTrue, _.eqv(constTrue))(null)) // true eqv true = true + assertFalse(pipe(constTrue, _.eqv(constFalse))(null)) // true eqv false = false + assertFalse(pipe(constFalse, _.eqv(constTrue))(null)) // false eqv true = false + assertTrue(pipe(constFalse, _.eqv(constFalse))(null)) // false eqv false = true }) it("implies", () => { - expect(pipe(constTrue, _.implies(constTrue))(null)).toBeTruthy() // true implies true = true - expect(pipe(constTrue, _.implies(constFalse))(null)).toBeFalsy() // true implies false = false - expect(pipe(constFalse, _.implies(constTrue))(null)).toBeTruthy() // false implies true = true - expect(pipe(constFalse, _.implies(constFalse))(null)).toBeTruthy() // false implies false = true + assertTrue(pipe(constTrue, _.implies(constTrue))(null)) // true implies true = true + assertFalse(pipe(constTrue, _.implies(constFalse))(null)) // true implies false = false + assertTrue(pipe(constFalse, _.implies(constTrue))(null)) // false implies true = true + assertTrue(pipe(constFalse, _.implies(constFalse))(null)) // false implies false = true }) it("nor", () => { - expect(pipe(constTrue, _.nor(constTrue))(null)).toBeFalsy() // true nor true = false - expect(pipe(constTrue, _.nor(constFalse))(null)).toBeFalsy() // true nor false = false - expect(pipe(constFalse, _.nor(constTrue))(null)).toBeFalsy() // false nor true = false - expect(pipe(constFalse, _.nor(constFalse))(null)).toBeTruthy() // false nor false = true + assertFalse(pipe(constTrue, _.nor(constTrue))(null)) // true nor true = false + assertFalse(pipe(constTrue, _.nor(constFalse))(null)) // true nor false = false + assertFalse(pipe(constFalse, _.nor(constTrue))(null)) // false nor true = false + assertTrue(pipe(constFalse, _.nor(constFalse))(null)) // false nor false = true }) it("nand", () => { - expect(pipe(constTrue, _.nand(constTrue))(null)).toBeFalsy() // true nand true = false - expect(pipe(constTrue, _.nand(constFalse))(null)).toBeTruthy() // true nand false = true - expect(pipe(constFalse, _.nand(constTrue))(null)).toBeTruthy() // false nand true = true - expect(pipe(constFalse, _.nand(constFalse))(null)).toBeTruthy() // false nand false = true + assertFalse(pipe(constTrue, _.nand(constTrue))(null)) // true nand true = false + assertTrue(pipe(constTrue, _.nand(constFalse))(null)) // true nand false = true + assertTrue(pipe(constFalse, _.nand(constTrue))(null)) // false nand true = true + assertTrue(pipe(constFalse, _.nand(constFalse))(null)) // false nand false = true }) it("some", () => { const predicate = _.some([isPositive, isNegative]) - deepStrictEqual(predicate(0), false) - deepStrictEqual(predicate(-1), true) - deepStrictEqual(predicate(1), true) + assertFalse(predicate(0)) + assertTrue(predicate(-1)) + assertTrue(predicate(1)) }) it("every", () => { const predicate = _.every([isPositive, isLessThan2]) - deepStrictEqual(predicate(0), false) - deepStrictEqual(predicate(-2), false) - deepStrictEqual(predicate(1), true) + assertFalse(predicate(0)) + assertFalse(predicate(-2)) + assertTrue(predicate(1)) }) it("isTruthy", () => { - expect(_.isTruthy(true)).toEqual(true) - expect(_.isTruthy(false)).toEqual(false) - expect(_.isTruthy("a")).toEqual(true) - expect(_.isTruthy("")).toEqual(false) - expect(_.isTruthy(1)).toEqual(true) - expect(_.isTruthy(0)).toEqual(false) - expect(_.isTruthy(1n)).toEqual(true) - expect(_.isTruthy(0n)).toEqual(false) + assertTrue(_.isTruthy(true)) + assertFalse(_.isTruthy(false)) + assertTrue(_.isTruthy("a")) + assertFalse(_.isTruthy("")) + assertTrue(_.isTruthy(1)) + assertFalse(_.isTruthy(0)) + assertTrue(_.isTruthy(1n)) + assertFalse(_.isTruthy(0n)) }) it("isFunction", () => { - assert.deepStrictEqual(_.isFunction(_.isFunction), true) - assert.deepStrictEqual(_.isFunction("function"), false) + assertTrue(_.isFunction(_.isFunction)) + assertFalse(_.isFunction("function")) }) it("isUndefined", () => { - assert.deepStrictEqual(_.isUndefined(undefined), true) - assert.deepStrictEqual(_.isUndefined(null), false) - assert.deepStrictEqual(_.isUndefined("undefined"), false) + assertTrue(_.isUndefined(undefined)) + assertFalse(_.isUndefined(null)) + assertFalse(_.isUndefined("undefined")) }) it("isNotUndefined", () => { - assert.deepStrictEqual(_.isNotUndefined(undefined), false) - assert.deepStrictEqual(_.isNotUndefined(null), true) - assert.deepStrictEqual(_.isNotUndefined("undefined"), true) + assertFalse(_.isNotUndefined(undefined)) + assertTrue(_.isNotUndefined(null)) + assertTrue(_.isNotUndefined("undefined")) }) it("isNull", () => { - assert.deepStrictEqual(_.isNull(null), true) - assert.deepStrictEqual(_.isNull(undefined), false) - assert.deepStrictEqual(_.isNull("null"), false) + assertTrue(_.isNull(null)) + assertFalse(_.isNull(undefined)) + assertFalse(_.isNull("null")) }) it("isNotNull", () => { - assert.deepStrictEqual(_.isNotNull(null), false) - assert.deepStrictEqual(_.isNotNull(undefined), true) - assert.deepStrictEqual(_.isNotNull("null"), true) + assertFalse(_.isNotNull(null)) + assertTrue(_.isNotNull(undefined)) + assertTrue(_.isNotNull("null")) }) it("isNever", () => { - assert.deepStrictEqual(_.isNever(null), false) - assert.deepStrictEqual(_.isNever(undefined), false) - assert.deepStrictEqual(_.isNever({}), false) - assert.deepStrictEqual(_.isNever([]), false) + assertFalse(_.isNever(null)) + assertFalse(_.isNever(undefined)) + assertFalse(_.isNever({})) + assertFalse(_.isNever([])) }) it("isUnknown", () => { - assert.deepStrictEqual(_.isUnknown(null), true) - assert.deepStrictEqual(_.isUnknown(undefined), true) - assert.deepStrictEqual(_.isUnknown({}), true) - assert.deepStrictEqual(_.isUnknown([]), true) + assertTrue(_.isUnknown(null)) + assertTrue(_.isUnknown(undefined)) + assertTrue(_.isUnknown({})) + assertTrue(_.isUnknown([])) }) it("isObject", () => { - assert.deepStrictEqual(_.isObject({}), true) - assert.deepStrictEqual(_.isObject([]), true) - assert.deepStrictEqual(_.isObject(() => 1), true) - assert.deepStrictEqual(_.isObject(null), false) - assert.deepStrictEqual(_.isObject(undefined), false) - assert.deepStrictEqual(_.isObject("a"), false) - assert.deepStrictEqual(_.isObject(1), false) - assert.deepStrictEqual(_.isObject(true), false) - assert.deepStrictEqual(_.isObject(1n), false) - assert.deepStrictEqual(_.isObject(Symbol.for("a")), false) + assertTrue(_.isObject({})) + assertTrue(_.isObject([])) + assertTrue(_.isObject(() => 1)) + assertFalse(_.isObject(null)) + assertFalse(_.isObject(undefined)) + assertFalse(_.isObject("a")) + assertFalse(_.isObject(1)) + assertFalse(_.isObject(true)) + assertFalse(_.isObject(1n)) + assertFalse(_.isObject(Symbol.for("a"))) }) it("isSet", () => { - assert.deepStrictEqual(_.isSet(new Set([1, 2])), true) - assert.deepStrictEqual(_.isSet(new Set()), true) - assert.deepStrictEqual(_.isSet({}), false) - assert.deepStrictEqual(_.isSet(null), false) - assert.deepStrictEqual(_.isSet(undefined), false) + assertTrue(_.isSet(new Set([1, 2]))) + assertTrue(_.isSet(new Set())) + assertFalse(_.isSet({})) + assertFalse(_.isSet(null)) + assertFalse(_.isSet(undefined)) }) it("isMap", () => { - assert.deepStrictEqual(_.isMap(new Map()), true) - assert.deepStrictEqual(_.isMap({}), false) - assert.deepStrictEqual(_.isMap(null), false) - assert.deepStrictEqual(_.isMap(undefined), false) + assertTrue(_.isMap(new Map())) + assertFalse(_.isMap({})) + assertFalse(_.isMap(null)) + assertFalse(_.isMap(undefined)) }) it("hasProperty", () => { const a = Symbol.for("effect/test/a") - assert.deepStrictEqual(_.hasProperty({ a: 1 }, "a"), true) - assert.deepStrictEqual(_.hasProperty("a")({ a: 1 }), true) - assert.deepStrictEqual(_.hasProperty({ [a]: 1 }, a), true) - assert.deepStrictEqual(_.hasProperty(a)({ [a]: 1 }), true) + assertTrue(_.hasProperty({ a: 1 }, "a")) + assertTrue(_.hasProperty("a")({ a: 1 })) + assertTrue(_.hasProperty({ [a]: 1 }, a)) + assertTrue(_.hasProperty(a)({ [a]: 1 })) - assert.deepStrictEqual(_.hasProperty({}, "a"), false) - assert.deepStrictEqual(_.hasProperty(null, "a"), false) - assert.deepStrictEqual(_.hasProperty(undefined, "a"), false) - assert.deepStrictEqual(_.hasProperty({}, "a"), false) - assert.deepStrictEqual(_.hasProperty(() => {}, "a"), false) + assertFalse(_.hasProperty({}, "a")) + assertFalse(_.hasProperty(null, "a")) + assertFalse(_.hasProperty(undefined, "a")) + assertFalse(_.hasProperty({}, "a")) + assertFalse(_.hasProperty(() => {}, "a")) - assert.deepStrictEqual(_.hasProperty({}, a), false) - assert.deepStrictEqual(_.hasProperty(null, a), false) - assert.deepStrictEqual(_.hasProperty(undefined, a), false) - assert.deepStrictEqual(_.hasProperty({}, a), false) - assert.deepStrictEqual(_.hasProperty(() => {}, a), false) + assertFalse(_.hasProperty({}, a)) + assertFalse(_.hasProperty(null, a)) + assertFalse(_.hasProperty(undefined, a)) + assertFalse(_.hasProperty({}, a)) + assertFalse(_.hasProperty(() => {}, a)) }) it("isTagged", () => { - assert.deepStrictEqual(_.isTagged(1, "a"), false) - assert.deepStrictEqual(_.isTagged("", "a"), false) - assert.deepStrictEqual(_.isTagged({}, "a"), false) - assert.deepStrictEqual(_.isTagged("a")({}), false) - assert.deepStrictEqual(_.isTagged({ a: "a" }, "a"), false) - assert.deepStrictEqual(_.isTagged({ _tag: "a" }, "a"), true) - assert.deepStrictEqual(_.isTagged("a")({ _tag: "a" }), true) + assertFalse(_.isTagged(1, "a")) + assertFalse(_.isTagged("", "a")) + assertFalse(_.isTagged({}, "a")) + assertFalse(_.isTagged("a")({})) + assertFalse(_.isTagged({ a: "a" }, "a")) + assertTrue(_.isTagged({ _tag: "a" }, "a")) + assertTrue(_.isTagged("a")({ _tag: "a" })) }) it("isNullable", () => { - assert.deepStrictEqual(_.isNullable(null), true) - assert.deepStrictEqual(_.isNullable(undefined), true) - assert.deepStrictEqual(_.isNullable({}), false) - assert.deepStrictEqual(_.isNullable([]), false) + assertTrue(_.isNullable(null)) + assertTrue(_.isNullable(undefined)) + assertFalse(_.isNullable({})) + assertFalse(_.isNullable([])) }) it("isNotNullable", () => { - assert.deepStrictEqual(_.isNotNullable({}), true) - assert.deepStrictEqual(_.isNotNullable([]), true) - assert.deepStrictEqual(_.isNotNullable(null), false) - assert.deepStrictEqual(_.isNotNullable(undefined), false) + assertTrue(_.isNotNullable({})) + assertTrue(_.isNotNullable([])) + assertFalse(_.isNotNullable(null)) + assertFalse(_.isNotNullable(undefined)) }) it("isError", () => { - assert.deepStrictEqual(_.isError(new Error()), true) - assert.deepStrictEqual(_.isError(null), false) - assert.deepStrictEqual(_.isError({}), false) + assertTrue(_.isError(new Error())) + assertFalse(_.isError(null)) + assertFalse(_.isError({})) }) it("isUint8Array", () => { - assert.deepStrictEqual(_.isUint8Array(new Uint8Array()), true) - assert.deepStrictEqual(_.isUint8Array(null), false) - assert.deepStrictEqual(_.isUint8Array({}), false) + assertTrue(_.isUint8Array(new Uint8Array())) + assertFalse(_.isUint8Array(null)) + assertFalse(_.isUint8Array({})) }) it("isDate", () => { - assert.deepStrictEqual(_.isDate(new Date()), true) - assert.deepStrictEqual(_.isDate(null), false) - assert.deepStrictEqual(_.isDate({}), false) + assertTrue(_.isDate(new Date())) + assertFalse(_.isDate(null)) + assertFalse(_.isDate({})) }) it("isIterable", () => { - assert.deepStrictEqual(_.isIterable([]), true) - assert.deepStrictEqual(_.isIterable(new Set()), true) - assert.deepStrictEqual(_.isIterable(null), false) - assert.deepStrictEqual(_.isIterable({}), false) + assertTrue(_.isIterable([])) + assertTrue(_.isIterable(new Set())) + assertFalse(_.isIterable(null)) + assertFalse(_.isIterable({})) }) it("isRecord", () => { - assert.deepStrictEqual(_.isRecord({}), true) - assert.deepStrictEqual(_.isRecord({ a: 1 }), true) + assertTrue(_.isRecord({})) + assertTrue(_.isRecord({ a: 1 })) - assert.deepStrictEqual(_.isRecord([]), false) - assert.deepStrictEqual(_.isRecord([1, 2, 3]), false) - assert.deepStrictEqual(_.isRecord(null), false) - assert.deepStrictEqual(_.isRecord(undefined), false) - assert.deepStrictEqual(_.isRecord(() => null), false) + assertFalse(_.isRecord([])) + assertFalse(_.isRecord([1, 2, 3])) + assertFalse(_.isRecord(null)) + assertFalse(_.isRecord(undefined)) + assertFalse(_.isRecord(() => null)) }) it("isReadonlyRecord", () => { - assert.deepStrictEqual(_.isReadonlyRecord({}), true) - assert.deepStrictEqual(_.isReadonlyRecord({ a: 1 }), true) + assertTrue(_.isReadonlyRecord({})) + assertTrue(_.isReadonlyRecord({ a: 1 })) - assert.deepStrictEqual(_.isReadonlyRecord([]), false) - assert.deepStrictEqual(_.isReadonlyRecord([1, 2, 3]), false) - assert.deepStrictEqual(_.isReadonlyRecord(null), false) - assert.deepStrictEqual(_.isReadonlyRecord(undefined), false) + assertFalse(_.isReadonlyRecord([])) + assertFalse(_.isReadonlyRecord([1, 2, 3])) + assertFalse(_.isReadonlyRecord(null)) + assertFalse(_.isReadonlyRecord(undefined)) }) it("isTupleOf", () => { - assert.deepStrictEqual(_.isTupleOf([1, 2, 3], 3), true) - assert.deepStrictEqual(_.isTupleOf([1, 2, 3], 4), false) - assert.deepStrictEqual(_.isTupleOf([1, 2, 3], 2), false) + assertTrue(_.isTupleOf([1, 2, 3], 3)) + assertFalse(_.isTupleOf([1, 2, 3], 4)) + assertFalse(_.isTupleOf([1, 2, 3], 2)) }) it("isTupleOfAtLeast", () => { - assert.deepStrictEqual(_.isTupleOfAtLeast([1, 2, 3], 3), true) - assert.deepStrictEqual(_.isTupleOfAtLeast([1, 2, 3], 2), true) - assert.deepStrictEqual(_.isTupleOfAtLeast([1, 2, 3], 4), false) + assertTrue(_.isTupleOfAtLeast([1, 2, 3], 3)) + assertTrue(_.isTupleOfAtLeast([1, 2, 3], 2)) + assertFalse(_.isTupleOfAtLeast([1, 2, 3], 4)) }) it("isRegExp", () => { - assert.deepStrictEqual(_.isRegExp(/a/), true) - assert.deepStrictEqual(_.isRegExp(null), false) - assert.deepStrictEqual(_.isRegExp("a"), false) + assertTrue(_.isRegExp(/a/)) + assertFalse(_.isRegExp(null)) + assertFalse(_.isRegExp("a")) }) }) diff --git a/packages/effect/test/PubSub.test.ts b/packages/effect/test/PubSub.test.ts index 7c07915cea4..0b97511fc18 100644 --- a/packages/effect/test/PubSub.test.ts +++ b/packages/effect/test/PubSub.test.ts @@ -1,13 +1,7 @@ -import { Chunk, Option } from "effect" -import * as Array from "effect/Array" -import * as Deferred from "effect/Deferred" -import * as Effect from "effect/Effect" -import * as Fiber from "effect/Fiber" -import { pipe } from "effect/Function" -import * as PubSub from "effect/PubSub" -import * as Queue from "effect/Queue" +import { Array, Chunk, Deferred, Effect, Fiber, pipe, PubSub, Queue } from "effect" +import { assertSome, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("PubSub", () => { it.effect("publishAll - capacity 2 (BoundedPubSubPow2)", () => { @@ -21,8 +15,8 @@ describe("PubSub", () => { yield* _(PubSub.publishAll(pubsub, messages)) const takes1 = yield* _(Queue.takeAll(dequeue1)) const takes2 = yield* _(Queue.takeAll(dequeue2)) - assert.deepStrictEqual([...takes1], messages) - assert.deepStrictEqual([...takes2], messages) + deepStrictEqual([...takes1], messages) + deepStrictEqual([...takes2], messages) }) ) ) @@ -39,8 +33,8 @@ describe("PubSub", () => { yield* _(PubSub.publishAll(pubsub, messages)) const takes1 = yield* _(Queue.takeAll(dequeue1)) const takes2 = yield* _(Queue.takeAll(dequeue2)) - assert.deepStrictEqual([...takes1], messages) - assert.deepStrictEqual([...takes2], messages) + deepStrictEqual([...takes1], messages) + deepStrictEqual([...takes2], messages) }) ) ) @@ -57,8 +51,8 @@ describe("PubSub", () => { yield* _(PubSub.publishAll(pubsub, messages)) const takes1 = yield* _(Queue.takeAll(dequeue1)) const takes2 = yield* _(Queue.takeAll(dequeue2)) - assert.deepStrictEqual([...takes1], messages) - assert.deepStrictEqual([...takes2], messages) + deepStrictEqual([...takes1], messages) + deepStrictEqual([...takes2], messages) }) ) ) @@ -88,7 +82,7 @@ describe("PubSub", () => { yield* $(values, Effect.forEach((n) => PubSub.publish(pubsub, n))) yield* $(Deferred.succeed(deferred2, void 0)) const result = yield* $(Fiber.join(subscriber)) - assert.deepStrictEqual(result, values) + deepStrictEqual(result, values) })) it.effect("sequential publishers and subscribers with one publisher and two subscribers", () => Effect.gen(function*($) { @@ -131,8 +125,8 @@ describe("PubSub", () => { yield* $(Deferred.succeed(deferred3, undefined)) const result1 = yield* $(Fiber.join(subscriber1)) const result2 = yield* $(Fiber.join(subscriber2)) - assert.deepStrictEqual(result1, values) - assert.deepStrictEqual(result2, values) + deepStrictEqual(result1, values) + deepStrictEqual(result2, values) })) it.effect("backpressured concurrent publishers and subscribers - one to one", () => Effect.gen(function*($) { @@ -157,7 +151,7 @@ describe("PubSub", () => { Effect.fork ) const result = yield* $(Fiber.join(subscriber)) - assert.deepStrictEqual(result, values) + deepStrictEqual(result, values) })) it.effect("backpressured concurrent publishers and subscribers - one to many", () => Effect.gen(function*($) { @@ -196,8 +190,8 @@ describe("PubSub", () => { ) const result1 = yield* $(Fiber.join(subscriber1)) const result2 = yield* $(Fiber.join(subscriber2)) - assert.deepStrictEqual(result1, values) - assert.deepStrictEqual(result2, values) + deepStrictEqual(result1, values) + deepStrictEqual(result2, values) })) it.effect("backpressured concurrent publishers and subscribers - many to many", () => Effect.gen(function*($) { @@ -246,13 +240,13 @@ describe("PubSub", () => { const result1 = yield* $(Fiber.join(subscriber1)) const result2 = yield* $(Fiber.join(subscriber2)) yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(pipe(result1, Array.filter((n) => n > 0)), values) - assert.deepStrictEqual( + deepStrictEqual(pipe(result1, Array.filter((n) => n > 0)), values) + deepStrictEqual( pipe(result1, Array.filter((n) => n < 0)), pipe(values, Array.map((n) => -n)) ) - assert.deepStrictEqual(pipe(result2, Array.filter((n) => n > 0)), values) - assert.deepStrictEqual( + deepStrictEqual(pipe(result2, Array.filter((n) => n > 0)), values) + deepStrictEqual( pipe(result2, Array.filter((n) => n < 0)), pipe(values, Array.map((n) => -n)) ) @@ -280,7 +274,7 @@ describe("PubSub", () => { Effect.fork ) const result = yield* $(Fiber.join(subscriber)) - assert.deepStrictEqual(result, values) + deepStrictEqual(result, values) })) it.effect("dropping concurrent publishers and subscribers - one to many", () => Effect.gen(function*($) { @@ -319,8 +313,8 @@ describe("PubSub", () => { ) const result1 = yield* $(Fiber.join(subscriber1)) const result2 = yield* $(Fiber.join(subscriber2)) - assert.deepStrictEqual(result1, values) - assert.deepStrictEqual(result2, values) + deepStrictEqual(result1, values) + deepStrictEqual(result2, values) })) it.effect("dropping concurrent publishers and subscribers - many to many", () => Effect.gen(function*($) { @@ -369,13 +363,13 @@ describe("PubSub", () => { const result1 = yield* $(Fiber.join(subscriber1)) const result2 = yield* $(Fiber.join(subscriber2)) yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(pipe(result1, Array.filter((n) => n > 0)), values) - assert.deepStrictEqual( + deepStrictEqual(pipe(result1, Array.filter((n) => n > 0)), values) + deepStrictEqual( pipe(result1, Array.filter((n) => n < 0)), pipe(values, Array.map((n) => -n)) ) - assert.deepStrictEqual(pipe(result2, Array.filter((n) => n > 0)), values) - assert.deepStrictEqual( + deepStrictEqual(pipe(result2, Array.filter((n) => n > 0)), values) + deepStrictEqual( pipe(result2, Array.filter((n) => n < 0)), pipe(values, Array.map((n) => -n)) ) @@ -403,7 +397,7 @@ describe("PubSub", () => { Effect.fork ) const result = yield* $(Fiber.join(subscriber)) - assert.deepStrictEqual(result, values) + deepStrictEqual(result, values) })) it.effect("sliding concurrent publishers and subscribers - one to many", () => Effect.gen(function*($) { @@ -442,8 +436,8 @@ describe("PubSub", () => { ) const result1 = yield* $(Fiber.join(subscriber1)) const result2 = yield* $(Fiber.join(subscriber2)) - assert.deepStrictEqual(result1, values) - assert.deepStrictEqual(result2, values) + deepStrictEqual(result1, values) + deepStrictEqual(result2, values) })) it.effect("sliding concurrent publishers and subscribers - many to many", () => Effect.gen(function*($) { @@ -492,13 +486,13 @@ describe("PubSub", () => { const result1 = yield* $(Fiber.join(subscriber1)) const result2 = yield* $(Fiber.join(subscriber2)) yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(pipe(result1, Array.filter((n) => n > 0)), values) - assert.deepStrictEqual( + deepStrictEqual(pipe(result1, Array.filter((n) => n > 0)), values) + deepStrictEqual( pipe(result1, Array.filter((n) => n < 0)), pipe(values, Array.map((n) => -n)) ) - assert.deepStrictEqual(pipe(result2, Array.filter((n) => n > 0)), values) - assert.deepStrictEqual( + deepStrictEqual(pipe(result2, Array.filter((n) => n > 0)), values) + deepStrictEqual( pipe(result2, Array.filter((n) => n < 0)), pipe(values, Array.map((n) => -n)) ) @@ -527,7 +521,7 @@ describe("PubSub", () => { ) const result = yield* $(Fiber.join(subscriber)) - assert.deepStrictEqual(result, values) + deepStrictEqual(result, values) })) it.effect("unbounded concurrent publishers and subscribers - one to many", () => Effect.gen(function*($) { @@ -566,8 +560,8 @@ describe("PubSub", () => { ) const result1 = yield* $(Fiber.join(subscriber1)) const result2 = yield* $(Fiber.join(subscriber2)) - assert.deepStrictEqual(result1, values) - assert.deepStrictEqual(result2, values) + deepStrictEqual(result1, values) + deepStrictEqual(result2, values) })) it.effect("unbounded concurrent publishers and subscribers - many to many", () => Effect.gen(function*($) { @@ -617,13 +611,13 @@ describe("PubSub", () => { const result1 = yield* $(Fiber.join(subscriber1)) const result2 = yield* $(Fiber.join(subscriber2)) yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Array.filter(result1, (n) => n > 0), values) - assert.deepStrictEqual( + deepStrictEqual(Array.filter(result1, (n) => n > 0), values) + deepStrictEqual( Array.filter(result1, (n) => n < 0), Array.map(values, (n) => -n) ) - assert.deepStrictEqual(Array.filter(result2, (n) => n > 0), values) - assert.deepStrictEqual( + deepStrictEqual(Array.filter(result2, (n) => n > 0), values) + deepStrictEqual( Array.filter(result2, (n) => n < 0), Array.map(values, (n) => -n) ) @@ -639,8 +633,8 @@ describe("PubSub", () => { yield* PubSub.publishAll(pubsub, messages) const takes1 = yield* Queue.takeAll(dequeue1) const takes2 = yield* Queue.takeAll(dequeue2) - assert.deepStrictEqual([...takes1], messages) - assert.deepStrictEqual([...takes2], messages) + deepStrictEqual([...takes1], messages) + deepStrictEqual([...takes2], messages) }) ) ) @@ -652,14 +646,14 @@ describe("PubSub", () => { const pubsub = yield* PubSub.dropping(2) yield* PubSub.publish(pubsub, 1) yield* PubSub.publish(pubsub, 2) - assert.deepStrictEqual(pubsub.unsafeSize(), Option.some(0)) + assertSome(pubsub.unsafeSize(), 0) })) it.scoped("publishAll does not increase size while no subscribers", () => Effect.gen(function*() { const pubsub = yield* PubSub.dropping(2) yield* PubSub.publishAll(pubsub, [1, 2]) - assert.deepStrictEqual(pubsub.unsafeSize(), Option.some(0)) + assertSome(pubsub.unsafeSize(), 0) })) describe("replay", () => { @@ -669,7 +663,7 @@ describe("PubSub", () => { const pubsub = yield* PubSub.unbounded({ replay: 3 }) yield* PubSub.publishAll(pubsub, messages) const sub = yield* PubSub.subscribe(pubsub) - assert.deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub)), [3, 4, 5]) + deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub)), [3, 4, 5]) })) it.effect("unbounded takeUpTo", () => { @@ -684,11 +678,11 @@ describe("PubSub", () => { yield* PubSub.publish(pubsub, 6) const dequeue2 = yield* PubSub.subscribe(pubsub) - assert.strictEqual(yield* Queue.size(dequeue1), 4) - assert.strictEqual(yield* Queue.size(dequeue2), 3) - assert.deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeUpTo(dequeue1, 2)), [3, 4]) - assert.deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeUpTo(dequeue1, 2)), [5, 6]) - assert.deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeUpTo(dequeue2, 3)), [4, 5, 6]) + strictEqual(yield* Queue.size(dequeue1), 4) + strictEqual(yield* Queue.size(dequeue2), 3) + deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeUpTo(dequeue1, 2)), [3, 4]) + deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeUpTo(dequeue1, 2)), [5, 6]) + deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeUpTo(dequeue2, 3)), [4, 5, 6]) }) ) ) @@ -702,19 +696,19 @@ describe("PubSub", () => { yield* PubSub.publishAll(pubsub, messages) const sub = yield* PubSub.subscribe(pubsub) - assert.deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub)), [3, 4, 5]) + deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub)), [3, 4, 5]) yield* PubSub.publishAll(pubsub, [6, 7]) - assert.deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub)), [6, 7]) + deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub)), [6, 7]) const sub2 = yield* PubSub.subscribe(pubsub) - assert.deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub2)), [5, 6, 7]) + deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub2)), [5, 6, 7]) yield* PubSub.publishAll(pubsub, [8, 9, 10, 11]) - assert.deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub)), [8, 9]) - assert.deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub2)), [8, 9]) + deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub)), [8, 9]) + deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub2)), [8, 9]) const sub3 = yield* PubSub.subscribe(pubsub) - assert.deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub3)), [7, 8, 9]) + deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub3)), [7, 8, 9]) })) it.scoped("sliding", () => @@ -724,19 +718,19 @@ describe("PubSub", () => { yield* PubSub.publishAll(pubsub, messages) const sub = yield* PubSub.subscribe(pubsub) - assert.deepStrictEqual(yield* Queue.take(sub), 3) + deepStrictEqual(yield* Queue.take(sub), 3) yield* PubSub.publishAll(pubsub, [6, 7, 8, 9, 10]) - assert.deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub)), [5, 6, 7, 8, 9, 10]) + deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub)), [5, 6, 7, 8, 9, 10]) const sub2 = yield* PubSub.subscribe(pubsub) - assert.deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub2)), [8, 9, 10]) + deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub2)), [8, 9, 10]) yield* PubSub.publishAll(pubsub, [11, 12, 13, 14, 15, 16]) - assert.deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub)), [13, 14, 15, 16]) - assert.deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub2)), [13, 14, 15, 16]) + deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub)), [13, 14, 15, 16]) + deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub2)), [13, 14, 15, 16]) const sub3 = yield* PubSub.subscribe(pubsub) - assert.deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub3)), [14, 15, 16]) + deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub3)), [14, 15, 16]) })) }) }) diff --git a/packages/effect/test/Queue.test.ts b/packages/effect/test/Queue.test.ts index 56c88832529..aee2ad34a36 100644 --- a/packages/effect/test/Queue.test.ts +++ b/packages/effect/test/Queue.test.ts @@ -1,17 +1,15 @@ -import * as Array from "effect/Array" -import * as Cause from "effect/Cause" -import * as Chunk from "effect/Chunk" -import * as Deferred from "effect/Deferred" -import * as Effect from "effect/Effect" -import * as Either from "effect/Either" -import * as Exit from "effect/Exit" -import * as Fiber from "effect/Fiber" -import { identity, pipe } from "effect/Function" -import * as Option from "effect/Option" -import * as Queue from "effect/Queue" -import * as Ref from "effect/Ref" +import { Array, Cause, Chunk, Deferred, Effect, Exit, Fiber, identity, pipe, Queue, Ref } from "effect" +import { + assertFalse, + assertLeft, + assertNone, + assertSome, + assertTrue, + deepStrictEqual, + strictEqual +} from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe, expect } from "vitest" +import { describe } from "vitest" export const waitForValue = (ref: Effect.Effect, value: A): Effect.Effect => { return ref.pipe(Effect.zipLeft(Effect.yieldNow()), Effect.repeat({ until: (a) => value === a })) @@ -26,31 +24,31 @@ describe("Queue", () => { Effect.gen(function*($) { const queue = yield* $(Queue.bounded(5)) const result = yield* $(Queue.offerAll(queue, [1, 2, 3])) - assert.isTrue(result) + assertTrue(result) })) it.effect("dropping - with offerAll", () => Effect.gen(function*($) { const queue = yield* $(Queue.dropping(4)) const result1 = yield* $(Queue.offerAll(queue, [1, 2, 3, 4, 5])) const result2 = yield* $(Queue.takeAll(queue)) - assert.isFalse(result1) - assert.deepStrictEqual(Chunk.toReadonlyArray(result2), [1, 2, 3, 4]) + assertFalse(result1) + deepStrictEqual(Chunk.toReadonlyArray(result2), [1, 2, 3, 4]) })) it.effect("dropping - with offerAll, check offer returns false", () => Effect.gen(function*($) { const queue = yield* $(Queue.dropping(2)) const result1 = yield* $(Queue.offerAll(queue, [1, 2, 3, 4, 5, 6])) const result2 = yield* $(Queue.takeAll(queue)) - assert.isFalse(result1) - assert.deepStrictEqual(Chunk.toReadonlyArray(result2), [1, 2]) + assertFalse(result1) + deepStrictEqual(Chunk.toReadonlyArray(result2), [1, 2]) })) it.effect("dropping - with offerAll, check ordering", () => Effect.gen(function*($) { const queue = yield* $(Queue.dropping(128)) const result1 = yield* $(Queue.offerAll(queue, Array.makeBy(256, (i) => i + 1))) const result2 = yield* $(Queue.takeAll(queue)) - assert.isFalse(result1) - assert.deepStrictEqual(Chunk.toReadonlyArray(result2), Array.makeBy(128, (i) => i + 1)) + assertFalse(result1) + deepStrictEqual(Chunk.toReadonlyArray(result2), Array.makeBy(128, (i) => i + 1)) })) it.effect("dropping - with pending taker", () => Effect.gen(function*($) { @@ -59,8 +57,8 @@ describe("Queue", () => { yield* $(waitForSize(queue, -1)) const result1 = yield* $(Queue.offerAll(queue, [1, 2, 3, 4])) const result2 = yield* $(Fiber.join(fiber)) - assert.isFalse(result1) - assert.strictEqual(result2, 1) + assertFalse(result1) + strictEqual(result2, 1) })) it.effect("sliding - with offer", () => Effect.gen(function*($) { @@ -69,17 +67,17 @@ describe("Queue", () => { const result1 = yield* $(Queue.offer(queue, 2)) const result2 = yield* $(Queue.offer(queue, 3)) const result3 = yield* $(Queue.takeAll(queue)) - assert.isTrue(result1) - assert.isTrue(result2) - assert.deepStrictEqual(Chunk.toReadonlyArray(result3), [2, 3]) + assertTrue(result1) + assertTrue(result2) + deepStrictEqual(Chunk.toReadonlyArray(result3), [2, 3]) })) it.effect("sliding - with offerAll", () => Effect.gen(function*($) { const queue = yield* $(Queue.sliding(2)) const result1 = yield* $(Queue.offerAll(queue, [1, 2, 3])) const result2 = yield* $(Queue.size(queue)) - assert.isTrue(result1) - assert.strictEqual(result2, 2) + assertTrue(result1) + strictEqual(result2, 2) })) it.effect("sliding - with enough capacity", () => Effect.gen(function*($) { @@ -88,15 +86,15 @@ describe("Queue", () => { yield* $(Queue.offer(queue, 2)) yield* $(Queue.offer(queue, 3)) const result = yield* $(Queue.takeAll(queue)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [1, 2, 3]) + deepStrictEqual(Chunk.toReadonlyArray(result), [1, 2, 3]) })) it.effect("sliding - with offerAll and takeAll", () => Effect.gen(function*($) { const queue = yield* $(Queue.sliding(2)) const result1 = yield* $(Queue.offerAll(queue, [1, 2, 3, 4, 5, 6])) const result2 = yield* $(Queue.takeAll(queue)) - assert.isTrue(result1) - assert.deepStrictEqual(Chunk.toReadonlyArray(result2), [5, 6]) + assertTrue(result1) + deepStrictEqual(Chunk.toReadonlyArray(result2), [5, 6]) })) it.effect("sliding - with pending taker", () => Effect.gen(function*($) { @@ -105,14 +103,14 @@ describe("Queue", () => { yield* $(waitForSize(queue, -1)) const result1 = yield* $(Queue.offerAll(queue, [1, 2, 3, 4])) const result2 = yield* $(Queue.take(queue)) - assert.isTrue(result1) - assert.strictEqual(result2, 3) + assertTrue(result1) + strictEqual(result2, 3) })) it.effect("sliding - check offerAll returns true", () => Effect.gen(function*($) { const queue = yield* $(Queue.sliding(5)) const result = yield* $(Queue.offerAll(queue, [1, 2, 3])) - assert.isTrue(result) + assertTrue(result) })) it.effect("awaitShutdown - once", () => Effect.gen(function*($) { @@ -121,7 +119,7 @@ describe("Queue", () => { yield* $(Queue.awaitShutdown(queue), Effect.zipRight(Deferred.succeed(deferred, true)), Effect.fork) yield* $(Queue.shutdown(queue)) const result = yield* $(Deferred.await(deferred)) - assert.isTrue(result) + assertTrue(result) })) it.effect("awaitShutdown - multiple", () => Effect.gen(function*($) { @@ -133,8 +131,8 @@ describe("Queue", () => { yield* $(Queue.shutdown(queue)) const result1 = yield* $(Deferred.await(deferred1)) const result2 = yield* $(Deferred.await(deferred2)) - assert.isTrue(result1) - assert.isTrue(result2) + assertTrue(result1) + assertTrue(result2) })) it.effect("offers are suspended by back pressure", () => Effect.gen(function*($) { @@ -145,7 +143,7 @@ describe("Queue", () => { yield* $(waitForSize(queue, 11)) const result = yield* $(Ref.get(ref)) yield* $(Fiber.interrupt(fiber)) - assert.isTrue(result) + assertTrue(result) })) it.effect("back pressured offers are retrieved", () => Effect.gen(function*($) { @@ -161,7 +159,7 @@ describe("Queue", () => { ) const result = yield* $(Ref.get(ref)) yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(result, values) + deepStrictEqual(result, values) })) it.effect("back-pressured offer completes after take", () => Effect.gen(function*($) { @@ -172,8 +170,8 @@ describe("Queue", () => { const result1 = yield* $(Queue.take(queue)) const result2 = yield* $(Queue.take(queue)) yield* $(Fiber.join(fiber)) - assert.strictEqual(result1, 1) - assert.strictEqual(result2, 2) + strictEqual(result1, 1) + strictEqual(result2, 2) })) it.effect("back-pressured offer completes after takeAll", () => Effect.gen(function*($) { @@ -183,7 +181,7 @@ describe("Queue", () => { yield* $(waitForSize(queue, 3)) const result = yield* $(Queue.takeAll(queue)) yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [1, 2]) + deepStrictEqual(Chunk.toReadonlyArray(result), [1, 2]) })) it.effect("back-pressured offer completes after takeUpTo", () => Effect.gen(function*($) { @@ -193,7 +191,7 @@ describe("Queue", () => { yield* $(waitForSize(queue, 3)) const result = yield* $(Queue.takeUpTo(queue, 2)) yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [1, 2]) + deepStrictEqual(Chunk.toReadonlyArray(result), [1, 2]) })) it.effect("back-pressured offerAll completes after takeAll", () => Effect.gen(function*($) { @@ -205,9 +203,9 @@ describe("Queue", () => { const result2 = yield* $(Queue.takeAll(queue)) const result3 = yield* $(Queue.takeAll(queue)) yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result1), [1, 2]) - assert.deepStrictEqual(Chunk.toReadonlyArray(result2), [3, 4]) - assert.deepStrictEqual(Chunk.toReadonlyArray(result3), [5]) + deepStrictEqual(Chunk.toReadonlyArray(result1), [1, 2]) + deepStrictEqual(Chunk.toReadonlyArray(result2), [3, 4]) + deepStrictEqual(Chunk.toReadonlyArray(result3), [5]) })) it.effect("take interruption", () => Effect.gen(function*($) { @@ -216,7 +214,7 @@ describe("Queue", () => { yield* $(waitForSize(queue, -1)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Queue.size(queue)) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("offer interruption", () => Effect.gen(function*($) { @@ -227,7 +225,7 @@ describe("Queue", () => { yield* $(waitForSize(queue, 3)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Queue.size(queue)) - assert.strictEqual(result, 2) + strictEqual(result, 2) })) it.effect("offerAll with takeAll", () => Effect.gen(function*($) { @@ -236,7 +234,7 @@ describe("Queue", () => { yield* $(Queue.offerAll(queue, values)) yield* $(waitForSize(queue, 10)) const result = yield* $(Queue.takeAll(queue)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 10)) + deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 10)) })) it.effect("offerAll with takeAll and back pressure", () => Effect.gen(function*($) { @@ -246,8 +244,8 @@ describe("Queue", () => { const size = yield* $(waitForSize(queue, 3)) const result = yield* $(Queue.takeAll(queue)) yield* $(Fiber.interrupt(fiber)) - assert.strictEqual(size, 3) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [1, 2]) + strictEqual(size, 3) + deepStrictEqual(Chunk.toReadonlyArray(result), [1, 2]) })) it.effect("offerAll with takeAll and back pressure + interruption", () => Effect.gen(function*($) { @@ -260,8 +258,8 @@ describe("Queue", () => { yield* $(Fiber.interrupt(fiber)) const result1 = yield* $(Queue.takeAll(queue)) const result2 = yield* $(Queue.takeAll(queue)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result1), values1) - assert.isTrue(Chunk.isEmpty(result2)) + deepStrictEqual(Chunk.toReadonlyArray(result1), values1) + assertTrue(Chunk.isEmpty(result2)) })) it.effect("offerAll with takeAll and back pressure, check ordering", () => Effect.gen(function*($) { @@ -270,7 +268,7 @@ describe("Queue", () => { yield* $(waitForSize(queue, 128)) const result = yield* $(Queue.takeAll(queue)) yield* $(Fiber.interrupt(fiber)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 64)) + deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 64)) })) it.effect("offerAll with pending takers", () => Effect.gen(function*($) { @@ -280,8 +278,8 @@ describe("Queue", () => { yield* $(queue.offerAll(Array.makeBy(100, (i) => i + 1))) const result = yield* $(Fiber.join(takers)) const size = yield* $(Queue.size(queue)) - assert.strictEqual(size, 0) - assert.deepStrictEqual(result, Array.range(1, 100)) + strictEqual(size, 0) + deepStrictEqual(result, Array.range(1, 100)) })) it.effect("offerAll with pending takers, check ordering", () => Effect.gen(function*($) { @@ -291,8 +289,8 @@ describe("Queue", () => { yield* $(Queue.offerAll(queue, Array.makeBy(128, (i) => i + 1))) const result = yield* $(Fiber.join(takers)) const size = yield* $(Queue.size(queue)) - assert.strictEqual(size, 64) - assert.deepStrictEqual(result, Array.range(1, 64)) + strictEqual(size, 64) + deepStrictEqual(result, Array.range(1, 64)) })) it.effect("offerAll with pending takers, check ordering of taker resolution", () => Effect.gen(function*($) { @@ -305,8 +303,8 @@ describe("Queue", () => { const result = yield* $(Fiber.join(takers)) const size = yield* $(Queue.size(queue)) yield* $(Fiber.interrupt(fiber)) - assert.strictEqual(size, -100) - assert.deepStrictEqual(result, Array.range(1, 100)) + strictEqual(size, -100) + deepStrictEqual(result, Array.range(1, 100)) })) it.effect("offerAll with take and back pressure", () => Effect.gen(function*($) { @@ -316,9 +314,9 @@ describe("Queue", () => { const result1 = yield* $(Queue.take(queue)) const result2 = yield* $(Queue.take(queue)) const result3 = yield* $(Queue.take(queue)) - assert.strictEqual(result1, 1) - assert.strictEqual(result2, 2) - assert.strictEqual(result3, 3) + strictEqual(result1, 1) + strictEqual(result2, 2) + strictEqual(result3, 3) })) it.effect("offerAll multiple with back pressure", () => Effect.gen(function*($) { @@ -332,11 +330,11 @@ describe("Queue", () => { const result3 = yield* $(Queue.take(queue)) const result4 = yield* $(Queue.take(queue)) const result5 = yield* $(Queue.take(queue)) - assert.strictEqual(result1, 1) - assert.strictEqual(result2, 2) - assert.strictEqual(result3, 3) - assert.strictEqual(result4, 4) - assert.strictEqual(result5, 5) + strictEqual(result1, 1) + strictEqual(result2, 2) + strictEqual(result3, 3) + strictEqual(result4, 4) + strictEqual(result5, 5) })) it.effect("offerAll with takeAll, check ordering", () => Effect.gen(function*($) { @@ -345,7 +343,7 @@ describe("Queue", () => { yield* $(Queue.offerAll(queue, Array.range(2, 1000))) yield* $(waitForSize(queue, 1000)) const result = yield* $(Queue.takeAll(queue)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 1000)) + deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 1000)) })) it.effect("offerAll combination of offer, offerAll, take, takeAll", () => Effect.gen(function*($) { @@ -358,10 +356,10 @@ describe("Queue", () => { const result2 = yield* $(Queue.take(queue)) const result3 = yield* $(Queue.take(queue)) const result4 = yield* $(Queue.take(queue)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result1), Array.range(1, 32)) - assert.strictEqual(result2, 33) - assert.strictEqual(result3, 34) - assert.strictEqual(result4, 35) + deepStrictEqual(Chunk.toReadonlyArray(result1), Array.range(1, 32)) + strictEqual(result2, 33) + strictEqual(result3, 34) + strictEqual(result4, 35) })) it.effect("parallel takes and sequential offers", () => Effect.gen(function*($) { @@ -372,7 +370,7 @@ describe("Queue", () => { .reduce((acc, curr) => pipe(acc, Effect.zipRight(curr)), Effect.succeed(false)) ) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(result, Array.range(1, 10)) + deepStrictEqual(result, Array.range(1, 10)) })) it.effect("parallel offers and sequential takes", () => Effect.gen(function*($) { @@ -387,7 +385,7 @@ describe("Queue", () => { ) const result = yield* $(Ref.get(ref)) yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(result, Array.makeBy(10, (i) => i + 1)) + deepStrictEqual(result, Array.makeBy(10, (i) => i + 1)) })) it.effect("sequential offer and take", () => Effect.gen(function*($) { @@ -396,10 +394,10 @@ describe("Queue", () => { const result1 = yield* $(Queue.take(queue)) const offer2 = yield* $(Queue.offer(queue, 20)) const result2 = yield* $(Queue.take(queue)) - assert.isTrue(offer1) - assert.strictEqual(result1, 10) - assert.isTrue(offer2) - assert.strictEqual(result2, 20) + assertTrue(offer1) + strictEqual(result1, 10) + assertTrue(offer2) + strictEqual(result2, 20) })) it.effect("sequential take and offer", () => Effect.gen(function*($) { @@ -407,13 +405,13 @@ describe("Queue", () => { const fiber = yield* $(Queue.take(queue), Effect.zipWith(Queue.take(queue), (a, b) => a + b), Effect.fork) yield* $(Queue.offer(queue, "don't "), Effect.zipRight(Queue.offer(queue, "give up :D"))) const result = yield* $(Fiber.join(fiber)) - assert.strictEqual(result, "don't give up :D") + strictEqual(result, "don't give up :D") })) it.effect("poll on empty queue", () => Effect.gen(function*($) { const queue = yield* $(Queue.bounded(5)) const result = yield* $(Queue.poll(queue)) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("poll on queue just emptied", () => Effect.gen(function*($) { @@ -421,7 +419,7 @@ describe("Queue", () => { yield* $(Queue.offerAll(queue, [1, 2, 3, 4])) yield* $(Queue.takeAll(queue)) const result = yield* $(Queue.poll(queue)) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("multiple polls", () => Effect.gen(function*($) { @@ -431,10 +429,10 @@ describe("Queue", () => { const result2 = yield* $(Queue.poll(queue)) const result3 = yield* $(Queue.poll(queue)) const result4 = yield* $(Queue.poll(queue)) - assert.deepStrictEqual(result1, Option.some(1)) - assert.deepStrictEqual(result2, Option.some(2)) - assert.deepStrictEqual(result3, Option.none()) - assert.deepStrictEqual(result4, Option.none()) + assertSome(result1, 1) + assertSome(result2, 2) + assertNone(result3) + assertNone(result4) })) it.effect("shutdown with take fiber", () => Effect.gen(function*($) { @@ -444,7 +442,7 @@ describe("Queue", () => { yield* $(waitForSize(queue, -1)) yield* $(Queue.shutdown(queue)) const result = yield* $(Effect.either(Effect.sandbox(Fiber.join(fiber)))) - assert.deepStrictEqual(result, Either.left(Cause.interrupt(fiberId))) + assertLeft(result, Cause.interrupt(fiberId)) })) it.effect("shutdown with offer fiber", () => Effect.gen(function*($) { @@ -456,7 +454,7 @@ describe("Queue", () => { yield* $(waitForSize(queue, 3)) yield* $(Queue.shutdown(queue)) const result = yield* $(Effect.either(Effect.sandbox(Fiber.join(fiber)))) - assert.deepStrictEqual(result, Either.left(Cause.interrupt(fiberId))) + assertLeft(result, Cause.interrupt(fiberId)) })) it.effect("shutdown with offer", () => Effect.gen(function*($) { @@ -464,7 +462,7 @@ describe("Queue", () => { const queue = yield* $(Queue.bounded(1)) yield* $(Queue.shutdown(queue)) const result = yield* $(Queue.offer(queue, 1), Effect.sandbox, Effect.either) - assert.deepStrictEqual(result, Either.left(Cause.interrupt(fiberId))) + assertLeft(result, Cause.interrupt(fiberId)) })) it.effect("shutdown with take", () => Effect.gen(function*($) { @@ -472,7 +470,7 @@ describe("Queue", () => { const queue = yield* $(Queue.bounded(1)) yield* $(Queue.shutdown(queue)) const result = yield* $(Queue.take(queue), Effect.sandbox, Effect.either) - assert.deepStrictEqual(result, Either.left(Cause.interrupt(fiberId))) + assertLeft(result, Cause.interrupt(fiberId)) })) it.effect("shutdown with takeAll", () => Effect.gen(function*($) { @@ -480,7 +478,7 @@ describe("Queue", () => { const queue = yield* $(Queue.bounded(1)) yield* $(Queue.shutdown(queue)) const result = yield* $(Queue.takeAll(queue), Effect.sandbox, Effect.either) - assert.deepStrictEqual(result, Either.left(Cause.interrupt(fiberId))) + assertLeft(result, Cause.interrupt(fiberId)) })) it.effect("shutdown with takeUpTo", () => Effect.gen(function*($) { @@ -488,7 +486,7 @@ describe("Queue", () => { const queue = yield* $(Queue.bounded(1)) yield* $(Queue.shutdown(queue)) const result = yield* $(Queue.takeUpTo(queue, 1), Effect.sandbox, Effect.either) - assert.deepStrictEqual(result, Either.left(Cause.interrupt(fiberId))) + assertLeft(result, Cause.interrupt(fiberId)) })) it.effect("shutdown with size", () => Effect.gen(function*($) { @@ -496,7 +494,7 @@ describe("Queue", () => { const queue = yield* $(Queue.bounded(1)) yield* $(Queue.shutdown(queue)) const result = yield* $(Queue.size(queue), Effect.sandbox, Effect.either) - assert.deepStrictEqual(result, Either.left(Cause.interrupt(fiberId))) + assertLeft(result, Cause.interrupt(fiberId)) })) it.effect("shutdown race condition with offer", () => Effect.gen(function*($) { @@ -504,7 +502,7 @@ describe("Queue", () => { const fiber = yield* $(Queue.offer(queue, 1), Effect.forever, Effect.fork) yield* $(Queue.shutdown(queue)) const result = yield* $(Fiber.await(fiber)) - assert.isTrue(Exit.isFailure(result)) + assertTrue(Exit.isFailure(result)) })) it.effect("shutdown race condition with take", () => Effect.gen(function*($) { @@ -514,7 +512,7 @@ describe("Queue", () => { const fiber = yield* $(Queue.take(queue), Effect.forever, Effect.fork) yield* $(Queue.shutdown(queue)) const result = yield* $(Fiber.await(fiber)) - assert.isTrue(Exit.isFailure(result)) + assertTrue(Exit.isFailure(result)) })) it.effect("isShutdown indicates shutdown status", () => Effect.gen(function*($) { @@ -526,10 +524,10 @@ describe("Queue", () => { const result3 = yield* $(Queue.isShutdown(queue)) yield* $(Queue.shutdown(queue)) const result4 = yield* $(Queue.isShutdown(queue)) - assert.isFalse(result1) - assert.isFalse(result2) - assert.isFalse(result3) - assert.isTrue(result4) + assertFalse(result1) + assertFalse(result2) + assertFalse(result3) + assertTrue(result4) })) it.effect("takeAll returns all values from a non-empty queue", () => Effect.gen(function*($) { @@ -538,7 +536,7 @@ describe("Queue", () => { yield* $(Queue.offer(queue, 2)) yield* $(Queue.offer(queue, 3)) const result = yield* $(Queue.takeAll(queue)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 3)) + deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 3)) })) it.effect("elements can be enqueued syncroniously when there is space", () => Effect.gen(function*($) { @@ -547,7 +545,7 @@ describe("Queue", () => { Queue.unsafeOffer(queue, 2) Queue.unsafeOffer(queue, 3) const result = yield* $(Queue.takeAll(queue)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 3)) + deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 3)) })) it.effect("takeAll returns all values from an empty queue", () => Effect.gen(function*($) { @@ -556,8 +554,8 @@ describe("Queue", () => { yield* $(Queue.offer(queue, 1)) yield* $(Queue.take(queue)) const result2 = yield* $(Queue.takeAll(queue)) - assert.isTrue(Chunk.isEmpty(result1)) - assert.isTrue(Chunk.isEmpty(result2)) + assertTrue(Chunk.isEmpty(result1)) + assertTrue(Chunk.isEmpty(result2)) })) it.effect("takeAll does not return more than the queue size", () => Effect.gen(function*($) { @@ -571,8 +569,8 @@ describe("Queue", () => { yield* $(waitForSize(queue, 5)) const result1 = yield* $(Queue.takeAll(queue)) const result2 = yield* $(Queue.take(queue)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result1), Array.range(1, 4)) - assert.strictEqual(result2, 5) + deepStrictEqual(Chunk.toReadonlyArray(result1), Array.range(1, 4)) + strictEqual(result2, 5) })) it.effect("takeBetween returns immediately if there is enough elements", () => Effect.gen(function*($) { @@ -581,7 +579,7 @@ describe("Queue", () => { yield* $(Queue.offer(queue, 2)) yield* $(Queue.offer(queue, 3)) const result = yield* $(Queue.takeBetween(queue, 2, 5)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 3)) + deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 3)) })) it.effect("takeBetween returns an empty list if boundaries are inverted", () => Effect.gen(function*($) { @@ -590,7 +588,7 @@ describe("Queue", () => { yield* $(Queue.offer(queue, 2)) yield* $(Queue.offer(queue, 3)) const result = yield* $(Queue.takeBetween(queue, 5, 2)) - assert.isTrue(Chunk.isEmpty(result)) + assertTrue(Chunk.isEmpty(result)) })) it.effect("takeBetween returns an empty list if boundaries are negative", () => Effect.gen(function*($) { @@ -599,7 +597,7 @@ describe("Queue", () => { yield* $(Queue.offer(queue, 2)) yield* $(Queue.offer(queue, 3)) const result = yield* $(Queue.takeBetween(queue, -5, -2)) - assert.isTrue(Chunk.isEmpty(result)) + assertTrue(Chunk.isEmpty(result)) })) it.effect("takeBetween blocks until a required minimum of elements is collected", () => Effect.gen(function*($) { @@ -607,7 +605,7 @@ describe("Queue", () => { const updater = pipe(Queue.offer(queue, 10), Effect.forever) const getter = Queue.takeBetween(queue, 5, 10) const result = yield* $(getter, Effect.race(updater)) - assert.isAtLeast(result.length, 5) + assertTrue(result.length >= 5) })) it.effect("takeBetween returns elements in the correct order", () => Effect.gen(function*($) { @@ -616,14 +614,14 @@ describe("Queue", () => { const fiber = yield* $(values, Effect.forEach((n) => Queue.offer(queue, n)), Effect.fork) const result = yield* $(Queue.takeBetween(queue, values.length, values.length)) yield* $(Fiber.interrupt(fiber)) - assert.deepStrictEqual(Array.fromIterable(result), values) + deepStrictEqual(Array.fromIterable(result), values) })) it.effect("takeN returns immediately if there is enough elements", () => Effect.gen(function*($) { const queue = yield* $(Queue.bounded(100)) yield* $(Queue.offerAll(queue, [1, 2, 3, 4, 5])) const result = yield* $(Queue.takeN(queue, 3)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 3)) + deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 3)) })) it.effect("takeN returns an empty list if a negative number or zero is specified", () => Effect.gen(function*($) { @@ -631,8 +629,8 @@ describe("Queue", () => { yield* $(Queue.offerAll(queue, [1, 2, 3])) const result1 = yield* $(Queue.takeN(queue, -3)) const result2 = yield* $(Queue.takeN(queue, 0)) - assert.isTrue(Chunk.isEmpty(result1)) - assert.isTrue(Chunk.isEmpty(result2)) + assertTrue(Chunk.isEmpty(result1)) + assertTrue(Chunk.isEmpty(result2)) })) it.effect("takeN blocks until the required number of elements is available", () => Effect.gen(function*($) { @@ -640,7 +638,7 @@ describe("Queue", () => { const updater = pipe(Queue.offer(queue, 10), Effect.forever) const getter = Queue.takeN(queue, 5) const result = yield* $(getter, Effect.race(updater)) - assert.strictEqual(result.length, 5) + strictEqual(result.length, 5) })) it.effect("should return the specified number of elements from a non-empty queue", () => Effect.gen(function*($) { @@ -648,19 +646,19 @@ describe("Queue", () => { yield* $(Queue.offer(queue, 1)) yield* $(Queue.offer(queue, 2)) const result = yield* $(Queue.takeUpTo(queue, 2)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 2)) + deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 2)) })) it.effect("should return an empty collection from an empty queue", () => Effect.gen(function*($) { const queue = yield* $(Queue.bounded(100)) const result = yield* $(Queue.takeUpTo(queue, 2)) - assert.isTrue(Chunk.isEmpty(result)) + assertTrue(Chunk.isEmpty(result)) })) it.effect("should handle an empty queue with max higher than queue size", () => Effect.gen(function*($) { const queue = yield* $(Queue.bounded(100)) const result = yield* $(Queue.takeUpTo(queue, 101)) - assert.isTrue(Chunk.isEmpty(result)) + assertTrue(Chunk.isEmpty(result)) })) it.effect("should leave behind elements if necessary", () => Effect.gen(function*($) { @@ -670,7 +668,7 @@ describe("Queue", () => { yield* $(Queue.offer(queue, 3)) yield* $(Queue.offer(queue, 4)) const result = yield* $(Queue.takeUpTo(queue, 2)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 2)) + deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 2)) })) it.effect("should handle not enough items", () => Effect.gen(function*($) { @@ -680,7 +678,7 @@ describe("Queue", () => { yield* $(Queue.offer(queue, 3)) yield* $(Queue.offer(queue, 4)) const result = yield* $(Queue.takeUpTo(queue, 10)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 4)) + deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 4)) })) it.effect("should handle taking up to 0 items", () => Effect.gen(function*($) { @@ -690,7 +688,7 @@ describe("Queue", () => { yield* $(Queue.offer(queue, 3)) yield* $(Queue.offer(queue, 4)) const result = yield* $(Queue.takeUpTo(queue, 0)) - assert.isTrue(Chunk.isEmpty(result)) + assertTrue(Chunk.isEmpty(result)) })) it.effect("should handle taking up to -1 items", () => Effect.gen(function*($) { @@ -700,14 +698,14 @@ describe("Queue", () => { yield* $(Queue.offer(queue, 3)) yield* $(Queue.offer(queue, 4)) const result = yield* $(Queue.takeUpTo(queue, -1)) - assert.isTrue(Chunk.isEmpty(result)) + assertTrue(Chunk.isEmpty(result)) })) it.effect("should handle taking up to Number.POSITIVE_INFINITY items", () => Effect.gen(function*($) { const queue = yield* $(Queue.bounded(100)) yield* $(Queue.offer(queue, 1)) const result = yield* $(Queue.takeUpTo(queue, Number.POSITIVE_INFINITY)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [1]) + deepStrictEqual(Chunk.toReadonlyArray(result), [1]) })) it.effect("multiple take up to calls", () => Effect.gen(function*($) { @@ -718,8 +716,8 @@ describe("Queue", () => { yield* $(Queue.offer(queue, 3)) yield* $(Queue.offer(queue, 4)) const result2 = yield* $(Queue.takeUpTo(queue, 2)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result1), Array.range(1, 2)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result2), Array.range(3, 4)) + deepStrictEqual(Chunk.toReadonlyArray(result1), Array.range(1, 2)) + deepStrictEqual(Chunk.toReadonlyArray(result2), Array.range(3, 4)) })) it.effect("consecutive take up to calls", () => Effect.gen(function*($) { @@ -730,8 +728,8 @@ describe("Queue", () => { yield* $(Queue.offer(queue, 4)) const result1 = yield* $(Queue.takeUpTo(queue, 2)) const result2 = yield* $(Queue.takeUpTo(queue, 2)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result1), Array.range(1, 2)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result2), Array.range(3, 4)) + deepStrictEqual(Chunk.toReadonlyArray(result1), Array.range(1, 2)) + deepStrictEqual(Chunk.toReadonlyArray(result2), Array.range(3, 4)) })) it.effect("does not return back-pressured offers", () => Effect.gen(function*($) { @@ -745,14 +743,14 @@ describe("Queue", () => { yield* $(waitForSize(queue, 5)) const result = yield* $(Queue.takeUpTo(queue, 5)) yield* $(Fiber.interrupt(fiber)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 4)) + deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 4)) })) it.effect("rts - handles falsy values", () => Effect.gen(function*($) { const queue = yield* $(Queue.unbounded()) yield* $(Queue.offer(queue, 0)) const result = yield* $(Queue.take(queue)) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("rts - queue is ordered", () => Effect.gen(function*($) { @@ -763,16 +761,16 @@ describe("Queue", () => { const result1 = yield* $(Queue.take(queue)) const result2 = yield* $(Queue.take(queue)) const result3 = yield* $(Queue.take(queue)) - assert.strictEqual(result1, 1) - assert.strictEqual(result2, 2) - assert.strictEqual(result3, 3) + strictEqual(result1, 1) + strictEqual(result2, 2) + strictEqual(result3, 3) })) it.effect( ".pipe", () => Effect.gen(function*(_) { const queue = yield* _(Queue.unbounded()) - expect(queue.pipe(identity)).toBe(queue) + strictEqual(queue.pipe(identity), queue) }) ) it.effect( @@ -782,7 +780,7 @@ describe("Queue", () => { const queue = yield* Queue.unbounded() yield* Queue.offer(queue, 1) const result1 = yield* queue - assert.strictEqual(result1, 1) + strictEqual(result1, 1) }) ) }) diff --git a/packages/effect/test/Random.test.ts b/packages/effect/test/Random.test.ts index 26a408e59d9..15a46af13ee 100644 --- a/packages/effect/test/Random.test.ts +++ b/packages/effect/test/Random.test.ts @@ -1,6 +1,7 @@ import { Array, Cause, Chunk, Data, Effect, Random } from "effect" -import { expect, it } from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { it } from "effect/test/utils/extend" +import { describe } from "vitest" describe("Random", () => { it.effect("integer is correctly distributed", () => @@ -10,14 +11,14 @@ describe("Random", () => { while (lastRandom < tenYearsMillis / 2) { lastRandom = yield* Random.nextIntBetween(0, tenYearsMillis) } - assert.isTrue(lastRandom >= tenYearsMillis / 2) + assertTrue(lastRandom >= tenYearsMillis / 2) })) it.effect("shuffle", () => Effect.gen(function*() { const start = Array.range(0, 100) const end = yield* Random.shuffle(start) - assert.isTrue(Chunk.every(end, (n) => n !== undefined)) - assert.deepStrictEqual(start.sort(), Array.fromIterable(end).sort()) + assertTrue(Chunk.every(end, (n) => n !== undefined)) + deepStrictEqual(start.sort(), Array.fromIterable(end).sort()) }).pipe(Effect.repeatN(100))) it.effect("make", () => @@ -30,19 +31,22 @@ describe("Random", () => { const n1 = yield* random1.next const n2 = yield* random2.next const n3 = yield* random3.next - assert.strictEqual(n0, n1) - assert.strictEqual(n2, n3) - assert.notStrictEqual(n0, n2) + strictEqual(n0, n1) + strictEqual(n2, n3) + assertTrue(n0 !== n2) })) it.live("choice", () => Effect.gen(function*() { - expect(yield* Random.choice([]).pipe(Effect.flip)).toEqual(new Cause.NoSuchElementException()) - expect(yield* Random.choice([1])).toEqual(1) + deepStrictEqual( + yield* Random.choice([]).pipe(Effect.flip), + new Cause.NoSuchElementException("Cannot select a random element from an empty array") + ) + strictEqual(yield* Random.choice([1]), 1) const randomItems = yield* Random.choice([1, 2, 3]).pipe(Array.replicate(100), Effect.all) - expect(Array.intersection(randomItems, [1, 2, 3]).length).toEqual(randomItems.length) + strictEqual(Array.intersection(randomItems, [1, 2, 3]).length, randomItems.length) - expect(yield* Random.choice(Chunk.fromIterable([1, 2, 3]))).oneOf([1, 2, 3]) + assertTrue([1, 2, 3].includes(yield* Random.choice(Chunk.fromIterable([1, 2, 3])))) })) }) diff --git a/packages/effect/test/RateLimiter.test.ts b/packages/effect/test/RateLimiter.test.ts index d94a893b1ac..4a6989c1a15 100644 --- a/packages/effect/test/RateLimiter.test.ts +++ b/packages/effect/test/RateLimiter.test.ts @@ -1,6 +1,7 @@ -import { Array, Clock, Deferred, Effect, Either, Fiber, Function, Option, RateLimiter, Ref, TestClock } from "effect" +import { Array, Clock, Deferred, Effect, Fiber, Function, Option, RateLimiter, Ref, TestClock } from "effect" +import { assertFalse, assertLeft, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("RateLimiter", () => { describe.concurrent("fixed-window", () => { @@ -25,8 +26,8 @@ describe("RateLimiter", () => { const nowAfter1Second = yield* _(Clock.currentTimeMillis) const times = yield* _(Fiber.join(fib)) - assert(times.slice(0, 10).every((t) => t === now)) - assert(times.slice(10).every((t) => t === nowAfter1Second)) + assertTrue(times.slice(0, 10).every((t) => t === now)) + assertTrue(times.slice(10).every((t) => t === nowAfter1Second)) })) it.scoped("will respect different costs per effect and interleave them.", () => @@ -57,7 +58,7 @@ describe("RateLimiter", () => { const times = yield* _(Fiber.join(fib)) - assert.deepEqual( + deepStrictEqual( times, [ ["rl1", start], @@ -105,8 +106,8 @@ describe("RateLimiter", () => { const times = yield* _(Fiber.join(fib)) - assert(timestamps.length === 60) - assert(times.length === 32) + assertTrue(timestamps.length === 60) + assertTrue(times.length === 32) const resultTimes = [ now, @@ -115,7 +116,7 @@ describe("RateLimiter", () => { ...timestamps.slice(59).flatMap((x) => [x, x]) ] - assert.deepEqual(times, resultTimes) + deepStrictEqual(times, resultTimes) }), 10_000) }) @@ -143,13 +144,13 @@ describe("RateLimiter", () => { Effect.zipRight(Deferred.succeed(deferred, void 0)), Effect.fork ) - assert.isFalse(yield* _(Deferred.isDone(deferred))) + assertFalse(yield* _(Deferred.isDone(deferred))) // Ensure that the request is successful once a token is replenished yield* _(TestClock.adjust("100 millis")) yield* _(Effect.yieldNow()) - assert.isTrue(yield* _(Deferred.isDone(deferred))) + assertTrue(yield* _(Deferred.isDone(deferred))) }))) }) }) @@ -168,7 +169,7 @@ const RateLimiterTestSuite = (algorithm: "fixed-window" | "token-bucket") => { () => limit(Clock.currentTimeMillis) )) const result = Array.every(times, (time) => time === now) - assert.isTrue(result) + assertTrue(result) })) it.scoped(`${algorithm} - is not affected by stream chunk size`, () => @@ -193,7 +194,7 @@ const RateLimiterTestSuite = (algorithm: "fixed-window" | "token-bucket") => { const times2 = yield* _(Effect.forEach(fibers, Fiber.join, { concurrency: "unbounded" })) const times = Array.appendAll(times1, times2) const result = Array.filter(times, (time) => time === now) - assert.strictEqual(result.length, 10) + strictEqual(result.length, 10) })) it.scoped(`${algorithm} - succeed with the result of the call`, () => @@ -204,7 +205,7 @@ const RateLimiterTestSuite = (algorithm: "fixed-window" | "token-bucket") => { algorithm })) const result = yield* _(limit(Effect.succeed(3))) - assert.strictEqual(result, 3) + strictEqual(result, 3) })) it.scoped(`${algorithm} - fail with the result of a failed call`, () => @@ -215,18 +216,18 @@ const RateLimiterTestSuite = (algorithm: "fixed-window" | "token-bucket") => { algorithm })) const result = yield* _(limit(Effect.either(Effect.fail(Option.none())))) - assert.deepStrictEqual(result, Either.left(Option.none())) + assertLeft(result, Option.none()) })) it.scoped(`${algorithm} - continue after a failed call`, () => - Effect.gen(function*(_) { - const limit = yield* _(RateLimiter.make({ + Effect.gen(function*() { + const limit = yield* RateLimiter.make({ limit: 10, interval: "1 seconds", algorithm - })) - yield* _(limit(Effect.either(Effect.fail(Option.none())))) - yield* _(limit(Effect.succeed(3))) + }) + yield* limit(Effect.either(Effect.fail(Option.none()))) + yield* limit(Effect.succeed(3)) })) it.scoped(`${algorithm} - holds back up calls after the max`, () => @@ -252,8 +253,8 @@ const RateLimiterTestSuite = (algorithm: "fixed-window" | "token-bucket") => { const times = yield* _(Fiber.join(fiber)) const later = yield* _(Clock.currentTimeMillis) - assert.isTrue(times.slice(0, 10).every((x) => x === now)) - assert.isTrue(times.slice(10).every((x) => x > now && x <= later)) + assertTrue(times.slice(0, 10).every((x) => x === now)) + assertTrue(times.slice(10).every((x) => x > now && x <= later)) })) it.scoped(`${algorithm} - will interrupt the effect when a call is interrupted`, () => @@ -289,7 +290,7 @@ const RateLimiterTestSuite = (algorithm: "fixed-window" | "token-bucket") => { const fiber = yield* _(Effect.fork(limit(Ref.set(count, 1)))) const interruption = yield* _(Effect.fork(Fiber.interrupt(fiber))) yield* _(Fiber.join(interruption)) - assert.strictEqual(yield* _(Ref.get(count)), 0) + strictEqual(yield* _(Ref.get(count)), 0) })) it.scoped(`${algorithm} - will wait for interruption to complete of an effect that is already executing`, () => @@ -311,7 +312,7 @@ const RateLimiterTestSuite = (algorithm: "fixed-window" | "token-bucket") => { yield* _(Deferred.await(latch)) yield* _(Fiber.interrupt(fiber)) const interruptions = yield* _(Ref.get(effectInterrupted)) - assert.strictEqual(interruptions, 1) + strictEqual(interruptions, 1) })) it.scoped(`${algorithm} - will make effects wait for interrupted effects to pass through the rate limiter`, () => @@ -328,7 +329,7 @@ const RateLimiterTestSuite = (algorithm: "fixed-window" | "token-bucket") => { const fiber2 = yield* _(Effect.fork(limit(Clock.currentTimeMillis))) yield* _(TestClock.adjust("1 seconds")) const lastExecutionTime = yield* _(Fiber.join(fiber2)) - assert(lastExecutionTime === 2000) + strictEqual(lastExecutionTime, 2000) })) it.scoped("will not include interrupted effects in the throttling", () => diff --git a/packages/effect/test/RcMap.test.ts b/packages/effect/test/RcMap.test.ts index 52455135f9d..bfec4aa4f84 100644 --- a/packages/effect/test/RcMap.test.ts +++ b/packages/effect/test/RcMap.test.ts @@ -1,5 +1,6 @@ import { Cause, Data, Effect, Exit, RcMap, Scope, TestClock } from "effect" -import { assert, describe, it } from "effect/test/utils/extend" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "effect/test/utils/extend" describe("RcMap", () => { it.effect("deallocation", () => @@ -20,10 +21,10 @@ describe("RcMap", () => { Scope.extend(mapScope) ) - assert.deepStrictEqual(acquired, []) - assert.strictEqual(yield* Effect.scoped(RcMap.get(map, "foo")), "foo") - assert.deepStrictEqual(acquired, ["foo"]) - assert.deepStrictEqual(released, ["foo"]) + deepStrictEqual(acquired, []) + strictEqual(yield* Effect.scoped(RcMap.get(map, "foo")), "foo") + deepStrictEqual(acquired, ["foo"]) + deepStrictEqual(released, ["foo"]) const scopeA = yield* Scope.make() const scopeB = yield* Scope.make() @@ -31,26 +32,26 @@ describe("RcMap", () => { yield* Effect.scoped(RcMap.get(map, "bar")) yield* RcMap.get(map, "baz").pipe(Scope.extend(scopeB)) yield* Effect.scoped(RcMap.get(map, "baz")) - assert.deepStrictEqual(acquired, ["foo", "bar", "baz"]) - assert.deepStrictEqual(released, ["foo"]) + deepStrictEqual(acquired, ["foo", "bar", "baz"]) + deepStrictEqual(released, ["foo"]) yield* Scope.close(scopeB, Exit.void) - assert.deepStrictEqual(acquired, ["foo", "bar", "baz"]) - assert.deepStrictEqual(released, ["foo", "baz"]) + deepStrictEqual(acquired, ["foo", "bar", "baz"]) + deepStrictEqual(released, ["foo", "baz"]) yield* Scope.close(scopeA, Exit.void) - assert.deepStrictEqual(acquired, ["foo", "bar", "baz"]) - assert.deepStrictEqual(released, ["foo", "baz", "bar"]) + deepStrictEqual(acquired, ["foo", "bar", "baz"]) + deepStrictEqual(released, ["foo", "baz", "bar"]) const scopeC = yield* Scope.make() yield* RcMap.get(map, "qux").pipe(Scope.extend(scopeC)) - assert.deepStrictEqual(acquired, ["foo", "bar", "baz", "qux"]) - assert.deepStrictEqual(released, ["foo", "baz", "bar"]) + deepStrictEqual(acquired, ["foo", "bar", "baz", "qux"]) + deepStrictEqual(released, ["foo", "baz", "bar"]) yield* Scope.close(mapScope, Exit.void) - assert.deepStrictEqual(acquired, ["foo", "bar", "baz", "qux"]) - assert.deepStrictEqual(released, ["foo", "baz", "bar", "qux"]) + deepStrictEqual(acquired, ["foo", "bar", "baz", "qux"]) + deepStrictEqual(released, ["foo", "baz", "bar", "qux"]) const exit = yield* RcMap.get(map, "boom").pipe(Effect.scoped, Effect.exit) - assert.isTrue(Exit.isInterrupted(exit)) + assertTrue(Exit.isInterrupted(exit)) })) it.scoped("idleTimeToLive", () => @@ -69,25 +70,25 @@ describe("RcMap", () => { idleTimeToLive: 1000 }) - assert.deepStrictEqual(acquired, []) - assert.strictEqual(yield* Effect.scoped(RcMap.get(map, "foo")), "foo") - assert.deepStrictEqual(acquired, ["foo"]) - assert.deepStrictEqual(released, []) + deepStrictEqual(acquired, []) + strictEqual(yield* Effect.scoped(RcMap.get(map, "foo")), "foo") + deepStrictEqual(acquired, ["foo"]) + deepStrictEqual(released, []) yield* TestClock.adjust(1000) - assert.deepStrictEqual(released, ["foo"]) + deepStrictEqual(released, ["foo"]) - assert.strictEqual(yield* Effect.scoped(RcMap.get(map, "bar")), "bar") - assert.deepStrictEqual(acquired, ["foo", "bar"]) - assert.deepStrictEqual(released, ["foo"]) + strictEqual(yield* Effect.scoped(RcMap.get(map, "bar")), "bar") + deepStrictEqual(acquired, ["foo", "bar"]) + deepStrictEqual(released, ["foo"]) yield* TestClock.adjust(500) - assert.strictEqual(yield* Effect.scoped(RcMap.get(map, "bar")), "bar") - assert.deepStrictEqual(acquired, ["foo", "bar"]) - assert.deepStrictEqual(released, ["foo"]) + strictEqual(yield* Effect.scoped(RcMap.get(map, "bar")), "bar") + deepStrictEqual(acquired, ["foo", "bar"]) + deepStrictEqual(released, ["foo"]) yield* TestClock.adjust(1000) - assert.deepStrictEqual(released, ["foo", "bar"]) + deepStrictEqual(released, ["foo", "bar"]) })) it.scoped("capacity", () => @@ -98,18 +99,18 @@ describe("RcMap", () => { idleTimeToLive: 1000 }) - assert.strictEqual(yield* Effect.scoped(RcMap.get(map, "foo")), "foo") - assert.strictEqual(yield* Effect.scoped(RcMap.get(map, "foo")), "foo") - assert.strictEqual(yield* Effect.scoped(RcMap.get(map, "bar")), "bar") + strictEqual(yield* Effect.scoped(RcMap.get(map, "foo")), "foo") + strictEqual(yield* Effect.scoped(RcMap.get(map, "foo")), "foo") + strictEqual(yield* Effect.scoped(RcMap.get(map, "bar")), "bar") const exit = yield* RcMap.get(map, "baz").pipe(Effect.scoped, Effect.exit) - assert.deepStrictEqual( + deepStrictEqual( exit, Exit.fail(new Cause.ExceededCapacityException(`RcMap attempted to exceed capacity of 2`)) ) yield* TestClock.adjust(1000) - assert.strictEqual(yield* Effect.scoped(RcMap.get(map, "baz")), "baz") + strictEqual(yield* Effect.scoped(RcMap.get(map, "baz")), "baz") })) it.scoped("complex key", () => @@ -120,9 +121,9 @@ describe("RcMap", () => { capacity: 1 }) - assert.strictEqual(yield* RcMap.get(map, new Key({ id: 1 })), 1) + strictEqual(yield* RcMap.get(map, new Key({ id: 1 })), 1) // no failure means a hit - assert.strictEqual(yield* RcMap.get(map, new Key({ id: 1 })), 1) + strictEqual(yield* RcMap.get(map, new Key({ id: 1 })), 1) })) it.scoped("keys lookup", () => @@ -135,6 +136,6 @@ describe("RcMap", () => { yield* RcMap.get(map, "bar") yield* RcMap.get(map, "baz") - assert.deepStrictEqual(yield* RcMap.keys(map), ["foo", "bar", "baz"]) + deepStrictEqual(yield* RcMap.keys(map), ["foo", "bar", "baz"]) })) }) diff --git a/packages/effect/test/RcRef.test.ts b/packages/effect/test/RcRef.test.ts index 02cab8c20b6..4f1a058b889 100644 --- a/packages/effect/test/RcRef.test.ts +++ b/packages/effect/test/RcRef.test.ts @@ -1,5 +1,6 @@ import { Effect, Exit, RcRef, Scope, TestClock } from "effect" -import { assert, describe, it } from "effect/test/utils/extend" +import { assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "effect/test/utils/extend" describe("RcRef", () => { it.effect("deallocation", () => @@ -22,35 +23,35 @@ describe("RcRef", () => { Scope.extend(refScope) ) - assert.strictEqual(acquired, 0) - assert.strictEqual(yield* Effect.scoped(ref), "foo") - assert.strictEqual(acquired, 1) - assert.strictEqual(released, 1) + strictEqual(acquired, 0) + strictEqual(yield* Effect.scoped(ref), "foo") + strictEqual(acquired, 1) + strictEqual(released, 1) const scopeA = yield* Scope.make() const scopeB = yield* Scope.make() yield* ref.pipe(Scope.extend(scopeA)) yield* ref.pipe(Scope.extend(scopeB)) - assert.strictEqual(acquired, 2) - assert.strictEqual(released, 1) + strictEqual(acquired, 2) + strictEqual(released, 1) yield* Scope.close(scopeB, Exit.void) - assert.strictEqual(acquired, 2) - assert.strictEqual(released, 1) + strictEqual(acquired, 2) + strictEqual(released, 1) yield* Scope.close(scopeA, Exit.void) - assert.strictEqual(acquired, 2) - assert.strictEqual(released, 2) + strictEqual(acquired, 2) + strictEqual(released, 2) const scopeC = yield* Scope.make() yield* ref.pipe(Scope.extend(scopeC)) - assert.strictEqual(acquired, 3) - assert.strictEqual(released, 2) + strictEqual(acquired, 3) + strictEqual(released, 2) yield* Scope.close(refScope, Exit.void) - assert.strictEqual(acquired, 3) - assert.strictEqual(released, 3) + strictEqual(acquired, 3) + strictEqual(released, 3) const exit = yield* ref.get.pipe(Effect.scoped, Effect.exit) - assert.isTrue(Exit.isInterrupted(exit)) + assertTrue(Exit.isInterrupted(exit)) })) it.scoped("idleTimeToLive", () => @@ -71,24 +72,24 @@ describe("RcRef", () => { idleTimeToLive: 1000 }) - assert.strictEqual(acquired, 0) - assert.strictEqual(yield* Effect.scoped(RcRef.get(ref)), "foo") - assert.strictEqual(acquired, 1) - assert.strictEqual(released, 0) + strictEqual(acquired, 0) + strictEqual(yield* Effect.scoped(RcRef.get(ref)), "foo") + strictEqual(acquired, 1) + strictEqual(released, 0) yield* TestClock.adjust(1000) - assert.strictEqual(released, 1) + strictEqual(released, 1) - assert.strictEqual(yield* Effect.scoped(RcRef.get(ref)), "foo") - assert.strictEqual(acquired, 2) - assert.strictEqual(released, 1) + strictEqual(yield* Effect.scoped(RcRef.get(ref)), "foo") + strictEqual(acquired, 2) + strictEqual(released, 1) yield* TestClock.adjust(500) - assert.strictEqual(yield* Effect.scoped(RcRef.get(ref)), "foo") - assert.strictEqual(acquired, 2) - assert.strictEqual(released, 1) + strictEqual(yield* Effect.scoped(RcRef.get(ref)), "foo") + strictEqual(acquired, 2) + strictEqual(released, 1) yield* TestClock.adjust(1000) - assert.strictEqual(released, 2) + strictEqual(released, 2) })) }) diff --git a/packages/effect/test/Record.test.ts b/packages/effect/test/Record.test.ts index 763acdc15aa..239d92f4707 100644 --- a/packages/effect/test/Record.test.ts +++ b/packages/effect/test/Record.test.ts @@ -1,9 +1,6 @@ -import * as Either from "effect/Either" -import { pipe } from "effect/Function" -import * as N from "effect/Number" -import * as Option from "effect/Option" -import * as RR from "effect/Record" -import { assert, describe, expect, it } from "vitest" +import { Either, Number as N, Option, pipe, Record as R } from "effect" +import { assertFalse, assertNone, assertSome, assertTrue, deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" const symA = Symbol.for("a") const symB = Symbol.for("b") @@ -12,20 +9,20 @@ const symC = Symbol.for("c") const stringRecord: Record = { a: 1, [symA]: null } const symbolRecord: Record = { [symA]: 1, [symB]: 2 } -describe("ReadonlyRecord", () => { +describe("Record", () => { describe("string | symbol APIs", () => { it("empty", () => { - expect(RR.empty()).toEqual({}) + deepStrictEqual(R.empty(), {}) }) it("fromIterableWith", () => { - expect(RR.fromIterableWith([1, 2, 3, 4], (a) => [a === 3 ? "a" : String(a), a * 2])).toEqual({ + deepStrictEqual(R.fromIterableWith([1, 2, 3, 4], (a) => [a === 3 ? "a" : String(a), a * 2]), { "1": 2, "2": 4, a: 6, "4": 8 }) - expect(RR.fromIterableWith([1, 2, 3, 4], (a) => [a === 3 ? symA : String(a), a * 2])).toEqual({ + deepStrictEqual(R.fromIterableWith([1, 2, 3, 4], (a) => [a === 3 ? symA : String(a), a * 2]), { "1": 2, "2": 4, [symA]: 6, @@ -38,23 +35,22 @@ describe("ReadonlyRecord", () => { { id: "2", name: "name2" }, { id: "1", name: "name1" } ] - expect(RR.fromIterableBy(users, (user) => user.id)).toEqual({ + deepStrictEqual(R.fromIterableBy(users, (user) => user.id), { "2": { id: "2", name: "name2" }, "1": { id: "1", name: "name1" } }) - expect(RR.fromIterableBy(["a", symA], (s) => s)) - .toEqual({ a: "a", [symA]: symA }) + deepStrictEqual(R.fromIterableBy(["a", symA], (s) => s), { a: "a", [symA]: symA }) }) it("fromEntries", () => { - expect(RR.fromEntries([["1", 2], ["2", 4], ["3", 6], ["4", 8]])).toEqual({ + deepStrictEqual(R.fromEntries([["1", 2], ["2", 4], ["3", 6], ["4", 8]]), { "1": 2, "2": 4, "3": 6, "4": 8 }) - expect(RR.fromEntries([["1", 2], ["2", 4], ["3", 6], ["4", 8], [symA, 10], [symB, 12]])).toEqual({ + deepStrictEqual(R.fromEntries([["1", 2], ["2", 4], ["3", 6], ["4", 8], [symA, 10], [symB, 12]]), { "1": 2, "2": 4, "3": 6, @@ -65,256 +61,247 @@ describe("ReadonlyRecord", () => { }) it("has", () => { - assert.deepStrictEqual(RR.has(stringRecord, "a"), true) - assert.deepStrictEqual(RR.has(stringRecord, "c"), false) + assertTrue(R.has(stringRecord, "a")) + assertFalse(R.has(stringRecord, "c")) - assert.deepStrictEqual(RR.has(symbolRecord, symA), true) - assert.deepStrictEqual(RR.has(symbolRecord, symC), false) + assertTrue(R.has(symbolRecord, symA)) + assertFalse(R.has(symbolRecord, symC)) }) it("get", () => { - expect(pipe(RR.empty(), RR.get("a"))).toEqual(Option.none()) - expect(pipe(stringRecord, RR.get("a"))).toEqual(Option.some(1)) + assertNone(pipe(R.empty(), R.get("a"))) + assertSome(pipe(stringRecord, R.get("a")), 1) - expect(pipe(RR.empty(), RR.get(symA))).toEqual(Option.none()) - expect(pipe(symbolRecord, RR.get(symA))).toEqual(Option.some(1)) + assertNone(pipe(R.empty(), R.get(symA))) + assertSome(pipe(symbolRecord, R.get(symA)), 1) }) it("modify", () => { - expect(pipe(RR.empty(), RR.modify("a", (n: number) => n + 1))).toEqual({}) - expect(pipe(stringRecord, RR.modify("a", (n: number) => n + 1))).toEqual({ a: 2, [symA]: null }) - expect(pipe(stringRecord, RR.modify("a", (n: number) => String(n)))).toEqual( - { a: "1", [symA]: null } - ) + deepStrictEqual(pipe(R.empty(), R.modify("a", (n: number) => n + 1)), {}) + deepStrictEqual(pipe(stringRecord, R.modify("a", (n: number) => n + 1)), { a: 2, [symA]: null }) + deepStrictEqual(pipe(stringRecord, R.modify("a", (n: number) => String(n))), { a: "1", [symA]: null }) - expect(pipe(RR.empty(), RR.modify(symA, (n: number) => n + 1))).toEqual({}) - expect(pipe(symbolRecord, RR.modify(symA, (n: number) => n + 1))).toEqual({ + deepStrictEqual(pipe(R.empty(), R.modify(symA, (n: number) => n + 1)), {}) + deepStrictEqual(pipe(symbolRecord, R.modify(symA, (n: number) => n + 1)), { [symA]: 2, [symB]: 2 }) - expect(pipe(symbolRecord, RR.modify(symA, (n: number) => String(n)))).toEqual( - { [symA]: "1", [symB]: 2 } - ) + deepStrictEqual(pipe(symbolRecord, R.modify(symA, (n: number) => String(n))), { [symA]: "1", [symB]: 2 }) }) it("modifyOption", () => { - expect(pipe(RR.empty(), RR.modifyOption("a", (n) => n + 1))).toEqual(Option.none()) - expect(pipe(stringRecord, RR.modifyOption("a", (n: number) => n + 1))).toEqual( - Option.some({ a: 2, [symA]: null }) - ) - expect(pipe(stringRecord, RR.modifyOption("a", (n: number) => String(n)))).toEqual( - Option.some({ a: "1", [symA]: null }) - ) - - expect(pipe(RR.empty(), RR.modifyOption(symA, (n) => n + 1))).toEqual(Option.none()) - expect(pipe(symbolRecord, RR.modifyOption(symA, (n: number) => n + 1))).toEqual( - Option.some({ [symA]: 2, [symB]: 2 }) - ) - expect(pipe(symbolRecord, RR.modifyOption(symA, (n: number) => String(n)))).toEqual( - Option.some({ [symA]: "1", [symB]: 2 }) + assertNone(pipe(R.empty(), R.modifyOption("a", (n) => n + 1))) + assertSome(pipe(stringRecord, R.modifyOption("a", (n: number) => n + 1)), { a: 2, [symA]: null }) + assertSome(pipe(stringRecord, R.modifyOption("a", (n: number) => String(n))), { a: "1", [symA]: null }) + + assertNone(pipe(R.empty(), R.modifyOption(symA, (n) => n + 1))) + assertSome(pipe(symbolRecord, R.modifyOption(symA, (n: number) => n + 1)), { [symA]: 2, [symB]: 2 }) + assertSome( + pipe(symbolRecord, R.modifyOption(symA, (n: number) => String(n))), + { [symA]: "1", [symB]: 2 } ) }) it("replaceOption", () => { - expect(pipe(RR.empty(), RR.replaceOption("a", 2))).toEqual(Option.none()) - expect(pipe(stringRecord, RR.replaceOption("a", 2))).toEqual(Option.some({ a: 2, [symA]: null })) - expect(pipe(stringRecord, RR.replaceOption("a", true))).toEqual(Option.some({ a: true, [symA]: null })) + assertNone(pipe(R.empty(), R.replaceOption("a", 2))) + assertSome(pipe(stringRecord, R.replaceOption("a", 2)), { a: 2, [symA]: null }) + assertSome(pipe(stringRecord, R.replaceOption("a", true)), { a: true, [symA]: null }) - expect(pipe(RR.empty(), RR.replaceOption(symA, 2))).toEqual(Option.none()) - expect(pipe(symbolRecord, RR.replaceOption(symA, 2))).toEqual(Option.some({ [symA]: 2, [symB]: 2 })) - expect(pipe(symbolRecord, RR.replaceOption(symA, true))).toEqual(Option.some({ [symA]: true, [symB]: 2 })) + assertNone(pipe(R.empty(), R.replaceOption(symA, 2))) + assertSome(pipe(symbolRecord, R.replaceOption(symA, 2)), { [symA]: 2, [symB]: 2 }) + assertSome(pipe(symbolRecord, R.replaceOption(symA, true)), { [symA]: true, [symB]: 2 }) }) it("remove", () => { - assert.deepStrictEqual(RR.remove(stringRecord, "a"), { [symA]: null }) - assert.deepStrictEqual(RR.remove(stringRecord, "c"), stringRecord) + deepStrictEqual(R.remove(stringRecord, "a"), { [symA]: null }) + deepStrictEqual(R.remove(stringRecord, "c"), stringRecord) - assert.deepStrictEqual(RR.remove(symbolRecord, symA), { [symB]: 2 }) - assert.deepStrictEqual(RR.remove(symbolRecord, symC), symbolRecord) + deepStrictEqual(R.remove(symbolRecord, symA), { [symB]: 2 }) + deepStrictEqual(R.remove(symbolRecord, symC), symbolRecord) }) describe("pop", () => { it("should return the value associated with the given key, if the key is present in the record", () => { - const result1 = RR.pop(stringRecord, "a") - assert.deepStrictEqual(result1, Option.some([1, { [symA]: null }] as [number, Record])) + const result1 = R.pop(stringRecord, "a") + assertSome(result1, [1, { [symA]: null }]) - const result2 = RR.pop(symbolRecord, symA) - assert.deepStrictEqual(result2, Option.some([1, { [symB]: 2 }] as [number, Record])) + const result2 = R.pop(symbolRecord, symA) + assertSome(result2, [1, { [symB]: 2 }]) }) it("should return none if the key is not present in the record", () => { - const result1 = RR.pop(stringRecord, "c") - assert.deepStrictEqual(result1, Option.none()) + const result1 = R.pop(stringRecord, "c") + assertNone(result1) - const result2 = RR.pop(symbolRecord, symC) - assert.deepStrictEqual(result2, Option.none()) + const result2 = R.pop(symbolRecord, symC) + assertNone(result2) }) }) describe("set", () => { it("should replace an existing value", () => { - assert.deepStrictEqual(RR.set(stringRecord, "a", 2), { a: 2, [symA]: null }) + deepStrictEqual(R.set(stringRecord, "a", 2), { a: 2, [symA]: null }) - assert.deepStrictEqual(RR.set(symbolRecord, symA, 2), { [symA]: 2, [symB]: 2 }) + deepStrictEqual(R.set(symbolRecord, symA, 2), { [symA]: 2, [symB]: 2 }) }) it("should add the key / value pair", () => { - assert.deepStrictEqual(RR.set(stringRecord, "c", 3), { a: 1, [symA]: null, c: 3 }) + deepStrictEqual(R.set(stringRecord, "c", 3), { a: 1, [symA]: null, c: 3 }) - assert.deepStrictEqual(RR.set(symbolRecord, symC, 3), { [symA]: 1, [symB]: 2, [symC]: 3 }) + deepStrictEqual(R.set(symbolRecord, symC, 3), { [symA]: 1, [symB]: 2, [symC]: 3 }) }) }) it("replace", () => { - expect(RR.replace(stringRecord, "c", 3)).toStrictEqual(stringRecord) - expect(RR.replace(stringRecord, "a", 2)).toStrictEqual({ a: 2, [symA]: null }) + deepStrictEqual(R.replace(stringRecord, "c", 3), stringRecord) + deepStrictEqual(R.replace(stringRecord, "a", 2), { a: 2, [symA]: null }) - expect(RR.replace(symbolRecord, symC, 3)).toStrictEqual(symbolRecord) - expect(RR.replace(symbolRecord, symA, 2)).toStrictEqual({ [symA]: 2, [symB]: 2 }) + deepStrictEqual(R.replace(symbolRecord, symC, 3), symbolRecord) + deepStrictEqual(R.replace(symbolRecord, symA, 2), { [symA]: 2, [symB]: 2 }) }) it("singleton", () => { - assert.deepStrictEqual(RR.singleton("a", 1), { a: 1 }) + deepStrictEqual(R.singleton("a", 1), { a: 1 }) - assert.deepStrictEqual(RR.singleton(symA, 1), { [symA]: 1 }) + deepStrictEqual(R.singleton(symA, 1), { [symA]: 1 }) }) }) describe("string only APIs", () => { it("map", () => { - expect(pipe(stringRecord, RR.map((n) => n * 2))).toEqual({ a: 2, [symA]: null }) - expect(pipe(stringRecord, RR.map((n, k) => `${k}-${n}`))).toEqual({ a: "a-1", [symA]: null }) + deepStrictEqual(pipe(stringRecord, R.map((n) => n * 2)), { a: 2, [symA]: null }) + deepStrictEqual(pipe(stringRecord, R.map((n, k) => `${k}-${n}`)), { a: "a-1", [symA]: null }) }) it("collect", () => { const x = { a: 1, b: 2, c: 3, [symA]: null } - assert.deepStrictEqual(RR.collect(x, (key, n) => [key, n]), [["a", 1], ["b", 2], ["c", 3]]) + deepStrictEqual(R.collect(x, (key, n) => [key, n]), [["a", 1], ["b", 2], ["c", 3]]) }) it("toEntries", () => { const x = { a: 1, b: 2, c: 3, [symA]: null } - assert.deepStrictEqual(RR.toEntries(x), [["a", 1], ["b", 2], ["c", 3]]) + deepStrictEqual(R.toEntries(x), [["a", 1], ["b", 2], ["c", 3]]) }) it("filterMap", () => { const x: Record = { a: 1, b: 2, c: 3, [symA]: null } - const filtered = RR.filterMap(x, (value, key) => (value > 2 ? Option.some(key) : Option.none())) - expect(filtered).toEqual({ c: "c" }) + const filtered = R.filterMap(x, (value, key) => (value > 2 ? Option.some(key) : Option.none())) + deepStrictEqual(filtered, { c: "c" }) }) it("getSomes", () => { const x = { a: Option.some(1), b: Option.none(), c: Option.some(2), [symA]: null } - assert.deepStrictEqual(RR.getSomes(x), { a: 1, c: 2 }) + deepStrictEqual(R.getSomes(x), { a: 1, c: 2 }) }) it("filter", () => { const x: Record = { a: 1, b: 2, c: 3, d: 4, [symA]: null } - assert.deepStrictEqual(RR.filter(x, (value) => value > 2), { c: 3, d: 4 }) + deepStrictEqual(R.filter(x, (value) => value > 2), { c: 3, d: 4 }) }) it("partitionMap", () => { const f = (n: number) => (n > 2 ? Either.right(n + 1) : Either.left(n - 1)) - assert.deepStrictEqual(RR.partitionMap({}, f), [{}, {}]) - assert.deepStrictEqual(RR.partitionMap({ a: 1, b: 3, [symA]: null }, f), [{ a: 0 }, { b: 4 }]) + deepStrictEqual(R.partitionMap({}, f), [{}, {}]) + deepStrictEqual(R.partitionMap({ a: 1, b: 3, [symA]: null }, f), [{ a: 0 }, { b: 4 }]) }) it("partition", () => { const f = (n: number) => n > 2 - assert.deepStrictEqual(RR.partition({}, f), [{}, {}]) - assert.deepStrictEqual(RR.partition({ a: 1, b: 3, [symA]: null }, f), [{ a: 1 }, { b: 3 }]) + deepStrictEqual(R.partition({}, f), [{}, {}]) + deepStrictEqual(R.partition({ a: 1, b: 3, [symA]: null }, f), [{ a: 1 }, { b: 3 }]) }) it("separate", () => { - assert.deepStrictEqual( - RR.separate({ a: Either.left("e"), b: Either.right(1), [symA]: null }), + deepStrictEqual( + R.separate({ a: Either.left("e"), b: Either.right(1), [symA]: null }), [{ a: "e" }, { b: 1 }] ) // should ignore non own properties - const o: RR.ReadonlyRecord<"a", Either.Either> = Object.create({ a: 1 }) - assert.deepStrictEqual(pipe(o, RR.separate), [{}, {}]) + const o: R.ReadonlyRecord<"a", Either.Either> = Object.create({ a: 1 }) + deepStrictEqual(pipe(o, R.separate), [{}, {}]) }) it("isEmptyRecord", () => { - assert.deepStrictEqual(RR.isEmptyRecord({}), true) - assert.deepStrictEqual(RR.isEmptyRecord({ [symA]: null }), true) - assert.deepStrictEqual(RR.isEmptyRecord({ a: 3 }), false) + deepStrictEqual(R.isEmptyRecord({}), true) + deepStrictEqual(R.isEmptyRecord({ [symA]: null }), true) + deepStrictEqual(R.isEmptyRecord({ a: 3 }), false) }) it("isEmptyReadonlyRecord", () => { - assert.deepStrictEqual(RR.isEmptyReadonlyRecord({}), true) - assert.deepStrictEqual(RR.isEmptyReadonlyRecord({ [symA]: null }), true) - assert.deepStrictEqual(RR.isEmptyReadonlyRecord({ a: 3 }), false) + deepStrictEqual(R.isEmptyReadonlyRecord({}), true) + deepStrictEqual(R.isEmptyReadonlyRecord({ [symA]: null }), true) + deepStrictEqual(R.isEmptyReadonlyRecord({ a: 3 }), false) }) it("size", () => { - assert.deepStrictEqual(RR.size({ a: "a", b: 1, c: true, [symA]: null }), 3) + deepStrictEqual(R.size({ a: "a", b: 1, c: true, [symA]: null }), 3) }) it("keys", () => { - assert.deepStrictEqual(RR.keys({ a: 1, b: 2, [symA]: null }), ["a", "b"]) + deepStrictEqual(R.keys({ a: 1, b: 2, [symA]: null }), ["a", "b"]) }) it("values", () => { - assert.deepStrictEqual(RR.values({ a: 1, b: 2, [symA]: null }), [1, 2]) + deepStrictEqual(R.values({ a: 1, b: 2, [symA]: null }), [1, 2]) }) it("isSubrecord", () => { - expect(RR.isSubrecord(RR.empty(), {})).toBe(true) - expect(RR.isSubrecord(RR.empty(), { a: 1 })).toBe(true) - expect(RR.isSubrecord({ a: 1 }, { a: 1 })).toBe(true) - expect(RR.isSubrecord(stringRecord, { a: 1 })).toBe(true) - expect(RR.isSubrecord({ a: 1 }, stringRecord)).toBe(true) - expect(RR.isSubrecord({ a: 1 } as Record, { a: 1, b: 2 })).toBe(true) - expect(RR.isSubrecord({ b: 2, a: 1 }, { a: 1, b: 2 })).toBe(true) - expect(RR.isSubrecord({ a: 1 }, { a: 2 })).toBe(false) - expect(RR.isSubrecord({ b: 2 } as Record, { a: 1 })).toBe(false) + assertTrue(R.isSubrecord(R.empty(), {})) + assertTrue(R.isSubrecord(R.empty(), { a: 1 })) + assertTrue(R.isSubrecord({ a: 1 }, { a: 1 })) + assertTrue(R.isSubrecord(stringRecord, { a: 1 })) + assertTrue(R.isSubrecord({ a: 1 }, stringRecord)) + assertTrue(R.isSubrecord({ a: 1 } as Record, { a: 1, b: 2 })) + assertTrue(R.isSubrecord({ b: 2, a: 1 }, { a: 1, b: 2 })) + assertFalse(R.isSubrecord({ a: 1 }, { a: 2 })) + assertFalse(R.isSubrecord({ b: 2 } as Record, { a: 1 })) }) it("reduce", () => { // data-first - assert.deepStrictEqual( - RR.reduce({ k1: "a", k2: "b", [symA]: null }, "-", (accumulator, value, key) => accumulator + key + value), + deepStrictEqual( + R.reduce({ k1: "a", k2: "b", [symA]: null }, "-", (accumulator, value, key) => accumulator + key + value), "-k1ak2b" ) // data-last - assert.deepStrictEqual( + deepStrictEqual( pipe( { k1: "a", k2: "b", [symA]: null }, - RR.reduce("-", (accumulator, value, key) => accumulator + key + value) + R.reduce("-", (accumulator, value, key) => accumulator + key + value) ), "-k1ak2b" ) }) it("every", () => { - assert.deepStrictEqual(RR.every((n: number) => n <= 2)({ a: 1, b: 2, [symA]: null }), true) - assert.deepStrictEqual(RR.every((n: number) => n <= 1)({ a: 1, b: 2, [symA]: null }), false) + assertTrue(R.every((n: number) => n <= 2)({ a: 1, b: 2, [symA]: null })) + assertFalse(R.every((n: number) => n <= 1)({ a: 1, b: 2, [symA]: null })) }) it("some", () => { - assert.deepStrictEqual(RR.some((n: number) => n <= 1)({ a: 1, b: 2, [symA]: null }), true) - assert.deepStrictEqual(RR.some((n: number) => n <= 0)({ a: 1, b: 2, [symA]: null }), false) + assertTrue(R.some((n: number) => n <= 1)({ a: 1, b: 2, [symA]: null })) + assertFalse(R.some((n: number) => n <= 0)({ a: 1, b: 2, [symA]: null })) }) it("union", () => { const combine = (s1: string, s2: string) => s1 + s2 - const x: RR.ReadonlyRecord = { + const x: R.ReadonlyRecord = { a: "a1", b: "b1", c: "c1", [symA]: null } - const y: RR.ReadonlyRecord = { + const y: R.ReadonlyRecord = { b: "b2", c: "c2", d: "d2", [symA]: null } - assert.deepStrictEqual(RR.union(x, {}, combine), x) - assert.deepStrictEqual(RR.union({}, x, combine), x) - assert.deepStrictEqual(RR.union(x, {}, combine), x) - assert.deepStrictEqual(RR.union({}, x, combine), x) - assert.deepStrictEqual(RR.union(x, y, combine), { + deepStrictEqual(R.union(x, {}, combine), x) + deepStrictEqual(R.union({}, x, combine), x) + deepStrictEqual(R.union(x, {}, combine), x) + deepStrictEqual(R.union({}, x, combine), x) + deepStrictEqual(R.union(x, y, combine), { a: "a1", b: "b1b2", c: "c1c2", @@ -324,64 +311,67 @@ describe("ReadonlyRecord", () => { it("intersection", () => { const combine = (s1: string, s2: string) => s1 + s2 - const x: RR.ReadonlyRecord = { + const x: R.ReadonlyRecord = { a: "a1", b: "b1", c: "c1", [symA]: null } - const y: RR.ReadonlyRecord = { + const y: R.ReadonlyRecord = { b: "b2", c: "c2", d: "d2", [symA]: null } - assert.deepStrictEqual(RR.intersection(x, {}, combine), {}) - assert.deepStrictEqual(RR.intersection({}, y, combine), {}) - assert.deepStrictEqual(RR.intersection(x, y, combine), { + deepStrictEqual(R.intersection(x, {}, combine), {}) + deepStrictEqual(R.intersection({}, y, combine), {}) + deepStrictEqual(R.intersection(x, y, combine), { b: "b1b2", c: "c1c2" }) }) it("difference", () => { - const x: RR.ReadonlyRecord = { + const x: R.ReadonlyRecord = { a: "a1", b: "b1", c: "c1", [symA]: null } - const y: RR.ReadonlyRecord = { + const y: R.ReadonlyRecord = { b: "b2", c: "c2", d: "d2", [symA]: null } - assert.deepStrictEqual(RR.difference({}, x), x) - assert.deepStrictEqual(RR.difference(x, {}), x) - assert.deepStrictEqual(RR.difference({}, x), x) - assert.deepStrictEqual(RR.difference(x, {}), x) - assert.deepStrictEqual(RR.difference(x, y), { + deepStrictEqual(R.difference({}, x), x) + deepStrictEqual(R.difference(x, {}), x) + deepStrictEqual(R.difference({}, x), x) + deepStrictEqual(R.difference(x, {}), x) + deepStrictEqual(R.difference(x, y), { a: "a1", d: "d2" }) }) it("getEquivalence", () => { - assert.deepStrictEqual(RR.getEquivalence(N.Equivalence)({ a: 1 }, { a: 1 }), true) - assert.deepStrictEqual(RR.getEquivalence(N.Equivalence)({ a: 1 }, stringRecord), true) - assert.deepStrictEqual(RR.getEquivalence(N.Equivalence)({ a: 1 }, { a: 2 }), false) - assert.deepStrictEqual(RR.getEquivalence(N.Equivalence)({ a: 1 }, { b: 1 }), false) + deepStrictEqual(R.getEquivalence(N.Equivalence)({ a: 1 }, { a: 1 }), true) + deepStrictEqual(R.getEquivalence(N.Equivalence)({ a: 1 }, stringRecord), true) + deepStrictEqual(R.getEquivalence(N.Equivalence)({ a: 1 }, { a: 2 }), false) + deepStrictEqual(R.getEquivalence(N.Equivalence)({ a: 1 }, { b: 1 }), false) const noPrototype = Object.create(null) - assert.deepStrictEqual(RR.getEquivalence(N.Equivalence)(noPrototype, { b: 1 }), false) + deepStrictEqual(R.getEquivalence(N.Equivalence)(noPrototype, { b: 1 }), false) }) it("mapKeys", () => { - expect(pipe({ a: 1, b: 2, [symA]: null }, RR.mapKeys((key) => key.toUpperCase()))).toStrictEqual({ A: 1, B: 2 }) + deepStrictEqual(pipe({ a: 1, b: 2, [symA]: null }, R.mapKeys((key) => key.toUpperCase())), { + A: 1, + B: 2 + }) }) it("mapEntries", () => { - expect(pipe(stringRecord, RR.mapEntries((a, key) => [key.toUpperCase(), a + 1]))).toStrictEqual({ A: 2 }) + deepStrictEqual(pipe(stringRecord, R.mapEntries((a, key) => [key.toUpperCase(), a + 1])), { A: 2 }) }) }) }) diff --git a/packages/effect/test/RedBlackTree.test.ts b/packages/effect/test/RedBlackTree.test.ts index 0c4a3b5857d..2dfd95258cd 100644 --- a/packages/effect/test/RedBlackTree.test.ts +++ b/packages/effect/test/RedBlackTree.test.ts @@ -1,22 +1,18 @@ -import * as Equal from "effect/Equal" -import { pipe } from "effect/Function" -import * as Hash from "effect/Hash" -import * as number from "effect/Number" -import * as Option from "effect/Option" -import * as Order from "effect/Order" -import * as RedBlackTree from "effect/RedBlackTree" -import { deepStrictEqual } from "effect/test/util" -import { assert, describe, expect, it } from "vitest" +import { Equal, Hash, Number as Num, Option, Order, pipe, RedBlackTree } from "effect" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("RedBlackTree", () => { it("toString", () => { const tree = pipe( - RedBlackTree.empty(number.Order), + RedBlackTree.empty(Num.Order), RedBlackTree.insert(1, "a"), RedBlackTree.insert(0, "b") ) - expect(String(tree)).toEqual(`{ + strictEqual( + String(tree), + `{ "_id": "RedBlackTree", "values": [ [ @@ -28,19 +24,18 @@ describe("RedBlackTree", () => { "a" ] ] -}`) +}` + ) }) it("toJSON", () => { const tree = pipe( - RedBlackTree.empty(number.Order), + RedBlackTree.empty(Num.Order), RedBlackTree.insert(1, "a"), RedBlackTree.insert(0, "b") ) - expect(tree.toJSON()).toEqual( - { _id: "RedBlackTree", values: [[0, "b"], [1, "a"]] } - ) + deepStrictEqual(tree.toJSON(), { _id: "RedBlackTree", values: [[0, "b"], [1, "a"]] }) }) it("inspect", () => { @@ -51,18 +46,18 @@ describe("RedBlackTree", () => { const { inspect } = require("node:util") const tree = pipe( - RedBlackTree.empty(number.Order), + RedBlackTree.empty(Num.Order), RedBlackTree.insert(1, "a"), RedBlackTree.insert(0, "b") ) - expect(inspect(tree)).toEqual(inspect({ _id: "RedBlackTree", values: [[0, "b"], [1, "a"]] })) + deepStrictEqual(inspect(tree), inspect({ _id: "RedBlackTree", values: [[0, "b"], [1, "a"]] })) }) it("forEach", () => { const ordered: Array<[number, string]> = [] pipe( - RedBlackTree.empty(number.Order), + RedBlackTree.empty(Num.Order), RedBlackTree.insert(1, "a"), RedBlackTree.insert(0, "b"), RedBlackTree.insert(-1, "c"), @@ -84,7 +79,7 @@ describe("RedBlackTree", () => { it("iterable", () => { const tree = pipe( - RedBlackTree.empty(number.Order), + RedBlackTree.empty(Num.Order), RedBlackTree.insert(1, "a"), RedBlackTree.insert(0, "b"), RedBlackTree.insert(-1, "c"), @@ -92,7 +87,7 @@ describe("RedBlackTree", () => { RedBlackTree.insert(3, "e") ) - assert.strictEqual(RedBlackTree.size(tree), 5) + strictEqual(RedBlackTree.size(tree), 5) deepStrictEqual(Array.from(tree), [ [-2, "d"], [-1, "c"], @@ -103,15 +98,15 @@ describe("RedBlackTree", () => { }) it("iterable empty", () => { - const tree = RedBlackTree.empty(number.Order) + const tree = RedBlackTree.empty(Num.Order) - assert.strictEqual(RedBlackTree.size(tree), 0) + strictEqual(RedBlackTree.size(tree), 0) deepStrictEqual(Array.from(tree), []) }) it("backwards", () => { const tree = pipe( - RedBlackTree.empty(number.Order), + RedBlackTree.empty(Num.Order), RedBlackTree.insert(1, "a"), RedBlackTree.insert(0, "b"), RedBlackTree.insert(-1, "c"), @@ -119,7 +114,7 @@ describe("RedBlackTree", () => { RedBlackTree.insert(3, "e") ) - assert.strictEqual(RedBlackTree.size(tree), 5) + strictEqual(RedBlackTree.size(tree), 5) deepStrictEqual(Array.from(RedBlackTree.reversed(tree)), [ [3, "e"], [1, "a"], @@ -130,15 +125,15 @@ describe("RedBlackTree", () => { }) it("backwards empty", () => { - const tree = RedBlackTree.empty(number.Order) + const tree = RedBlackTree.empty(Num.Order) - assert.strictEqual(RedBlackTree.size(tree), 0) + strictEqual(RedBlackTree.size(tree), 0) deepStrictEqual(Array.from(RedBlackTree.reversed(tree)), []) }) it("values", () => { const tree = pipe( - RedBlackTree.empty(number.Order), + RedBlackTree.empty(Num.Order), RedBlackTree.insert(1, "a"), RedBlackTree.insert(0, "b"), RedBlackTree.insert(-1, "c"), @@ -146,13 +141,13 @@ describe("RedBlackTree", () => { RedBlackTree.insert(3, "e") ) - assert.strictEqual(RedBlackTree.size(tree), 5) + strictEqual(RedBlackTree.size(tree), 5) deepStrictEqual(Array.from(RedBlackTree.values(tree)), ["d", "c", "b", "a", "e"]) }) it("keys", () => { const tree = pipe( - RedBlackTree.empty(number.Order), + RedBlackTree.empty(Num.Order), RedBlackTree.insert(1, "a"), RedBlackTree.insert(0, "b"), RedBlackTree.insert(-1, "c"), @@ -160,13 +155,13 @@ describe("RedBlackTree", () => { RedBlackTree.insert(3, "e") ) - assert.strictEqual(RedBlackTree.size(tree), 5) + strictEqual(RedBlackTree.size(tree), 5) deepStrictEqual(Array.from(RedBlackTree.keys(tree)), [-2, -1, 0, 1, 3]) }) it("begin/end", () => { const tree = pipe( - RedBlackTree.empty(number.Order), + RedBlackTree.empty(Num.Order), RedBlackTree.insert(1, "a"), RedBlackTree.insert(0, "b"), RedBlackTree.insert(-1, "c"), @@ -182,7 +177,7 @@ describe("RedBlackTree", () => { it("forEachGreaterThanEqual", () => { const ordered: Array<[number, string]> = [] pipe( - RedBlackTree.empty(number.Order), + RedBlackTree.empty(Num.Order), RedBlackTree.insert(1, "a"), RedBlackTree.insert(0, "b"), RedBlackTree.insert(-1, "c"), @@ -199,7 +194,7 @@ describe("RedBlackTree", () => { it("forEachLessThan", () => { const ordered: Array<[number, string]> = [] pipe( - RedBlackTree.empty(number.Order), + RedBlackTree.empty(Num.Order), RedBlackTree.insert(1, "a"), RedBlackTree.insert(0, "b"), RedBlackTree.insert(-1, "c"), @@ -216,7 +211,7 @@ describe("RedBlackTree", () => { it("forEachBetween", () => { const ordered: Array<[number, string]> = [] pipe( - RedBlackTree.empty(number.Order), + RedBlackTree.empty(Num.Order), RedBlackTree.insert(1, "a"), RedBlackTree.insert(0, "b"), RedBlackTree.insert(-1, "c"), @@ -236,7 +231,7 @@ describe("RedBlackTree", () => { it("greaterThan", () => { const tree = pipe( - RedBlackTree.empty(number.Order), + RedBlackTree.empty(Num.Order), RedBlackTree.insert(1, "a"), RedBlackTree.insert(0, "b"), RedBlackTree.insert(-1, "c"), @@ -261,7 +256,7 @@ describe("RedBlackTree", () => { it("greaterThanEqual", () => { const tree = pipe( - RedBlackTree.empty(number.Order), + RedBlackTree.empty(Num.Order), RedBlackTree.insert(1, "a"), RedBlackTree.insert(0, "b"), RedBlackTree.insert(-1, "c"), @@ -286,7 +281,7 @@ describe("RedBlackTree", () => { it("lessThan", () => { const tree = pipe( - RedBlackTree.empty(number.Order), + RedBlackTree.empty(Num.Order), RedBlackTree.insert(1, "a"), RedBlackTree.insert(0, "b"), RedBlackTree.insert(-1, "c"), @@ -311,7 +306,7 @@ describe("RedBlackTree", () => { it("lessThanEqual", () => { const tree = pipe( - RedBlackTree.empty(number.Order), + RedBlackTree.empty(Num.Order), RedBlackTree.insert(1, "a"), RedBlackTree.insert(0, "b"), RedBlackTree.insert(-1, "c"), @@ -336,7 +331,7 @@ describe("RedBlackTree", () => { it("findAll", () => { const tree = pipe( - RedBlackTree.empty(number.Order), + RedBlackTree.empty(Num.Order), RedBlackTree.insert(1, "a"), RedBlackTree.insert(2, "c"), RedBlackTree.insert(1, "b"), @@ -372,7 +367,7 @@ describe("RedBlackTree", () => { } } - const ord = pipe(number.Order, Order.mapInput((key: Key) => key.n)) + const ord = pipe(Num.Order, Order.mapInput((key: Key) => key.n)) const tree = pipe( RedBlackTree.empty(ord), @@ -412,14 +407,14 @@ describe("RedBlackTree", () => { }) it("Equal.symbol", () => { - expect( - Equal.equals(RedBlackTree.empty(number.Order), RedBlackTree.empty(number.Order)) - ).toBe(true) - expect( + assertTrue( + Equal.equals(RedBlackTree.empty(Num.Order), RedBlackTree.empty(Num.Order)) + ) + assertTrue( Equal.equals( - RedBlackTree.make(number.Order)([1, true], [2, true]), - RedBlackTree.make(number.Order)([1, true], [2, true]) + RedBlackTree.make(Num.Order)([1, true], [2, true]), + RedBlackTree.make(Num.Order)([1, true], [2, true]) ) - ).toBe(true) + ) }) }) diff --git a/packages/effect/test/Redacted.test.ts b/packages/effect/test/Redacted.test.ts index 0cec5acd918..165b22002b1 100644 --- a/packages/effect/test/Redacted.test.ts +++ b/packages/effect/test/Redacted.test.ts @@ -1,72 +1,67 @@ -import * as Chunk from "effect/Chunk" -import * as Equal from "effect/Equal" -import * as Hash from "effect/Hash" -import * as Redacted from "effect/Redacted" -import * as Secret from "effect/Secret" -import { assert, describe, it } from "vitest" +import { Chunk, Equal, Hash, Redacted, Secret } from "effect" +import { assertFalse, assertTrue, strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" describe("Redacted", () => { it("chunk constructor", () => { const redacted = Redacted.make(Chunk.fromIterable("redacted".split(""))) - assert.isTrue(Equal.equals(redacted, Redacted.make(Chunk.fromIterable("redacted".split(""))))) + assertTrue(Equal.equals(redacted, Redacted.make(Chunk.fromIterable("redacted".split(""))))) }) it("value", () => { const redacted = Redacted.make(Chunk.fromIterable("redacted".split(""))) const value = Redacted.value(redacted) - assert.isTrue(Equal.equals(value, Chunk.fromIterable("redacted".split("")))) + assertTrue(Equal.equals(value, Chunk.fromIterable("redacted".split("")))) }) it("pipe", () => { const value = { asd: 123 } const redacted = Redacted.make(value) const extractedValue = redacted.pipe(Redacted.value) - assert.strictEqual(value, extractedValue) + strictEqual(value, extractedValue) }) it("toString", () => { const redacted = Redacted.make("redacted") - assert.strictEqual(`${redacted}`, "") + strictEqual(`${redacted}`, "") }) it("toJSON", () => { const redacted = Redacted.make("redacted") - assert.strictEqual(JSON.stringify(redacted), "\"\"") + strictEqual(JSON.stringify(redacted), "\"\"") }) it("unsafeWipe", () => { const redacted = Redacted.make("redacted") - assert.isTrue(Redacted.unsafeWipe(redacted)) - assert.throw(() => Redacted.value(redacted), "Unable to get redacted value") + assertTrue(Redacted.unsafeWipe(redacted)) + throws(() => Redacted.value(redacted), new Error("Unable to get redacted value")) }) it("Equal", () => { - assert.isTrue(Equal.equals(Redacted.make(1), Redacted.make(1))) - assert.isFalse(Equal.equals(Redacted.make(1), Redacted.make(2))) + assertTrue(Equal.equals(Redacted.make(1), Redacted.make(1))) + assertFalse(Equal.equals(Redacted.make(1), Redacted.make(2))) }) it("Hash", () => { - assert.strictEqual(Hash.hash(Redacted.make(1)), Hash.hash(Redacted.make(1))) - assert.notStrictEqual(Hash.hash(Redacted.make(1)), Hash.hash(Redacted.make(2))) + strictEqual(Hash.hash(Redacted.make(1)), Hash.hash(Redacted.make(1))) + assertTrue(Hash.hash(Redacted.make(1)) !== Hash.hash(Redacted.make(2))) }) describe("Secret extends Redacted", () => { it("Redacted.isRedacted", () => { const secret = Secret.fromString("test") - assert.isTrue( + assertTrue( Redacted.isRedacted(secret) ) }) it("Redacted.unsafeWipe", () => { const secret = Secret.fromString("test") - assert.isTrue( - Redacted.unsafeWipe(secret) - ) + assertTrue(Redacted.unsafeWipe(secret)) }) it("Redacted.value", () => { const value = "test" const secret = Secret.fromString(value) - assert.strictEqual(value, Redacted.value(secret)) + strictEqual(value, Redacted.value(secret)) }) }) }) diff --git a/packages/effect/test/Ref.test.ts b/packages/effect/test/Ref.test.ts index 92ddfeddebe..0f347c723c1 100644 --- a/packages/effect/test/Ref.test.ts +++ b/packages/effect/test/Ref.test.ts @@ -1,9 +1,7 @@ -import { Readable } from "effect" -import * as Effect from "effect/Effect" -import * as Option from "effect/Option" -import * as Ref from "effect/Ref" +import { Effect, Option, Readable, Ref } from "effect" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" const current = "value" const update = "new value" @@ -34,14 +32,14 @@ describe("Ref", () => { it.effect("implements Readable", () => Effect.gen(function*(_) { const ref = yield* _(Ref.make(123)) - assert.isTrue(Readable.isReadable(ref)) - assert.strictEqual(yield* ref, 123) + assertTrue(Readable.isReadable(ref)) + strictEqual(yield* ref, 123) })) it.effect("get", () => Effect.gen(function*($) { const result = yield* $(Ref.make(current), Effect.flatMap(Ref.get)) - assert.strictEqual(result, current) + strictEqual(result, current) })) it.effect("getAndSet", () => Effect.gen(function*() { @@ -49,16 +47,16 @@ describe("Ref", () => { const result1 = yield* Ref.getAndSet(ref, update) const result2 = yield* ref - assert.strictEqual(result1, current) - assert.strictEqual(result2, update) + strictEqual(result1, current) + strictEqual(result2, update) })) it.effect("getAndUpdate", () => Effect.gen(function*($) { const ref = yield* $(Ref.make(current)) const result1 = yield* $(Ref.getAndUpdate(ref, () => update)) const result2 = yield* ref - assert.strictEqual(result1, current) - assert.strictEqual(result2, update) + strictEqual(result1, current) + strictEqual(result2, update) })) it.effect("getAndUpdateSome - once", () => Effect.gen(function*($) { @@ -67,8 +65,8 @@ describe("Ref", () => { Ref.getAndUpdateSome(ref, (state) => isClosed(state) ? Option.some(Changed) : Option.none()) ) const result2 = yield* $(Ref.get(ref)) - assert.strictEqual(result1, Active) - assert.strictEqual(result2, Active) + strictEqual(result1, Active) + strictEqual(result2, Active) })) it.effect("getAndUpdateSome - twice", () => Effect.gen(function*($) { @@ -85,36 +83,36 @@ describe("Ref", () => { Option.none()) ) const result3 = yield* $(Ref.get(ref)) - assert.strictEqual(result1, Active) - assert.strictEqual(result2, Changed) - assert.strictEqual(result3, Closed) + strictEqual(result1, Active) + strictEqual(result2, Changed) + strictEqual(result3, Closed) })) it.effect("set", () => Effect.gen(function*($) { const ref = yield* $(Ref.make(current)) yield* $(Ref.set(ref, update)) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, update) + strictEqual(result, update) })) it.effect("update", () => Effect.gen(function*($) { const ref = yield* $(Ref.make(current)) yield* $(Ref.update(ref, () => update)) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, update) + strictEqual(result, update) })) it.effect("updateAndGet", () => Effect.gen(function*($) { const ref = yield* $(Ref.make(current)) const result = yield* $(Ref.updateAndGet(ref, () => update)) - assert.strictEqual(result, update) + strictEqual(result, update) })) it.effect("updateSome - once", () => Effect.gen(function*($) { const ref = yield* $(Ref.make(Active)) yield* $(Ref.updateSome(ref, (state) => isClosed(state) ? Option.some(Changed) : Option.none())) const result = yield* $(Ref.get(ref)) - assert.deepEqual(result, Active) + deepStrictEqual(result, Active) })) it.effect("updateSome - twice", () => Effect.gen(function*($) { @@ -130,8 +128,8 @@ describe("Ref", () => { Option.none()) ) const result2 = yield* $(Ref.get(ref)) - assert.deepEqual(result1, Changed) - assert.deepEqual(result2, Closed) + deepStrictEqual(result1, Changed) + deepStrictEqual(result2, Closed) })) it.effect("updateSomeAndGet - once", () => Effect.gen(function*($) { @@ -139,7 +137,7 @@ describe("Ref", () => { const result = yield* $( Ref.updateSomeAndGet(ref, (state) => isClosed(state) ? Option.some(Changed) : Option.none()) ) - assert.strictEqual(result, Active) + strictEqual(result, Active) })) it.effect("updateSomeAndGet - twice", () => Effect.gen(function*($) { @@ -156,16 +154,16 @@ describe("Ref", () => { Option.none() }) ) - assert.deepEqual(result1, Changed) - assert.deepEqual(result2, Closed) + deepStrictEqual(result1, Changed) + deepStrictEqual(result2, Closed) })) it.effect("modify", () => Effect.gen(function*($) { const ref = yield* $(Ref.make(current)) const result1 = yield* $(Ref.modify(ref, () => ["hello", update])) const result2 = yield* $(Ref.get(ref)) - assert.strictEqual(result1, "hello") - assert.strictEqual(result2, update) + strictEqual(result1, "hello") + strictEqual(result2, update) })) it.effect("modifySome - once", () => Effect.gen(function*($) { @@ -176,7 +174,7 @@ describe("Ref", () => { Option.some(["active", Active]) : Option.none()) ) - assert.strictEqual(result, "state does not change") + strictEqual(result, "state does not change") })) it.effect("modifySome - twice", () => Effect.gen(function*($) { @@ -195,7 +193,7 @@ describe("Ref", () => { Option.some(["closed", Closed]) : Option.none()) ) - assert.strictEqual(result1, "changed") - assert.strictEqual(result2, "closed") + strictEqual(result1, "changed") + strictEqual(result2, "closed") })) }) diff --git a/packages/effect/test/RegExp.test.ts b/packages/effect/test/RegExp.test.ts index b39ceab0d04..6faece89b88 100644 --- a/packages/effect/test/RegExp.test.ts +++ b/packages/effect/test/RegExp.test.ts @@ -1,11 +1,12 @@ -import * as RegExp from "effect/RegExp" -import { describe, expect, it } from "vitest" +import { RegExp } from "effect" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("RegExp", () => { it("isRegExp", () => { - expect(RegExp.isRegExp(/a/)).toEqual(true) - expect(RegExp.isRegExp(null)).toEqual(false) - expect(RegExp.isRegExp("a")).toEqual(false) + assertTrue(RegExp.isRegExp(/a/)) + assertFalse(RegExp.isRegExp(null)) + assertFalse(RegExp.isRegExp("a")) }) describe("escape", () => { @@ -31,7 +32,7 @@ describe("RegExp", () => { testCases.forEach(([input, expected]) => { const result = RegExp.escape(input) - expect(result).toEqual(expected) + strictEqual(result, expected) }) }) }) diff --git a/packages/effect/test/Reloadable.test.ts b/packages/effect/test/Reloadable.test.ts index 6c5e48d67a8..4a87e197e9a 100644 --- a/packages/effect/test/Reloadable.test.ts +++ b/packages/effect/test/Reloadable.test.ts @@ -1,11 +1,8 @@ -import * as Context from "effect/Context" -import * as Effect from "effect/Effect" -import { pipe } from "effect/Function" -import * as Layer from "effect/Layer" -import * as Reloadable from "effect/Reloadable" +import { Context, Effect, Layer, pipe, Reloadable } from "effect" +import { strictEqual } from "effect/test/util" import * as Counter from "effect/test/utils/counter" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" const DummyServiceTypeId = Symbol.for("effect/test/Reloadable/DummyService") type DummyServiceTypeId = typeof DummyServiceTypeId @@ -29,7 +26,7 @@ describe("Reloadable", () => { }) yield* $(Reloadable.get(Tag), Effect.provide(layer)) const acquired = yield* $(counter.acquired()) - assert.strictEqual(acquired, 1) + strictEqual(acquired, 1) })) it.effect("reload", () => Effect.gen(function*($) { @@ -39,6 +36,6 @@ describe("Reloadable", () => { }) yield* $(Reloadable.reload(Tag), Effect.provide(layer)) const acquired = yield* $(counter.acquired()) - assert.strictEqual(acquired, 2) + strictEqual(acquired, 2) })) }) diff --git a/packages/effect/test/Resource.test.ts b/packages/effect/test/Resource.test.ts index a2b7af50f5b..a9b16c5fbb5 100644 --- a/packages/effect/test/Resource.test.ts +++ b/packages/effect/test/Resource.test.ts @@ -1,62 +1,59 @@ -import * as Duration from "effect/Duration" -import * as Effect from "effect/Effect" -import * as Either from "effect/Either" -import { identity, pipe } from "effect/Function" -import * as Ref from "effect/Ref" -import * as Cached from "effect/Resource" -import * as Schedule from "effect/Schedule" +import { Duration, Effect, Either, identity, pipe, Ref, Resource, Schedule } from "effect" +import { strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Resource", () => { it.scoped("manual", () => Effect.gen(function*($) { const ref = yield* $(Ref.make(0)) - const cached = yield* $(Cached.manual(Ref.get(ref))) - const resul1 = yield* $(Cached.get(cached)) + const cached = yield* $(Resource.manual(Ref.get(ref))) + const resul1 = yield* $(Resource.get(cached)) const result2 = yield* $( - pipe(Ref.set(ref, 1), Effect.zipRight(Cached.refresh(cached)), Effect.zipRight(Cached.get(cached))) + pipe(Ref.set(ref, 1), Effect.zipRight(Resource.refresh(cached)), Effect.zipRight(Resource.get(cached))) ) - assert.strictEqual(resul1, 0) - assert.strictEqual(result2, 1) + strictEqual(resul1, 0) + strictEqual(result2, 1) })) it.scoped("auto", () => Effect.gen(function*($) { const ref = yield* $(Ref.make(0)) - const cached = yield* $(Cached.auto(Ref.get(ref), Schedule.spaced(Duration.millis(4)))) - const result1 = yield* $(Cached.get(cached)) + const cached = yield* $(Resource.auto(Ref.get(ref), Schedule.spaced(Duration.millis(4)))) + const result1 = yield* $(Resource.get(cached)) const result2 = yield* $( pipe( Ref.set(ref, 1), Effect.zipRight(TestClock.adjust(Duration.millis(5))), - Effect.zipRight(Cached.get(cached)) + Effect.zipRight(Resource.get(cached)) ) ) - assert.strictEqual(result1, 0) - assert.strictEqual(result2, 1) + strictEqual(result1, 0) + strictEqual(result2, 1) })) it.scopedLive("failed refresh doesn't affect cached value", () => Effect.gen(function*($) { const ref = yield* $(Ref.make>(Either.right(0))) - const cached = yield* $(Cached.auto(Effect.flatMap(Ref.get(ref), identity), Schedule.spaced(Duration.millis(4)))) - const result1 = yield* $(Cached.get(cached)) + const cached = yield* $( + Resource.auto(Effect.flatMap(Ref.get(ref), identity), Schedule.spaced(Duration.millis(4))) + ) + const result1 = yield* $(Resource.get(cached)) const result2 = yield* $( pipe( Ref.set(ref, Either.left("Uh oh!")), Effect.zipRight(Effect.sleep(Duration.millis(5))), - Effect.zipRight(Cached.get(cached)) + Effect.zipRight(Resource.get(cached)) ) ) - assert.strictEqual(result1, 0) - assert.strictEqual(result2, 0) + strictEqual(result1, 0) + strictEqual(result2, 0) })) it.scoped("subtype of Effect", () => Effect.gen(function*() { const ref = yield* Ref.make(0) - const cached = yield* Cached.manual(ref) + const cached = yield* Resource.manual(ref) const resul1 = yield* cached - assert.strictEqual(resul1, 0) + strictEqual(resul1, 0) })) }) diff --git a/packages/effect/test/Runtime.test.ts b/packages/effect/test/Runtime.test.ts index 2ca0c6bc2bf..a4844d8b487 100644 --- a/packages/effect/test/Runtime.test.ts +++ b/packages/effect/test/Runtime.test.ts @@ -1,5 +1,6 @@ import { Effect, Exit, FiberRef, Layer, Runtime } from "effect" -import { assert, describe } from "vitest" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe } from "vitest" import * as it from "./utils/extend.js" describe("Runtime", () => { @@ -10,10 +11,10 @@ describe("Runtime", () => { Runtime.setFiberRef(ref, 1) ) let result = Runtime.runSync(runtime)(FiberRef.get(ref)) - assert.strictEqual(result, 1) + strictEqual(result, 1) result = yield* _(FiberRef.get(ref), Effect.provide(runtime)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.scoped("deleteFiberRef", () => @@ -22,19 +23,21 @@ describe("Runtime", () => { const runtime = yield* _(Layer.toRuntime(Layer.effectDiscard(FiberRef.set(ref, { value: 1 })))) let result = Runtime.runSync(runtime)(FiberRef.get(ref)) - assert.deepStrictEqual(result, { value: 1 }) + deepStrictEqual(result, { value: 1 }) result = Runtime.runSync(Runtime.deleteFiberRef(runtime, ref))(FiberRef.get(ref)) - assert.deepStrictEqual(result, { value: 0 }) + deepStrictEqual(result, { value: 0 }) })) it.it("runPromiseExit/signal", async () => { const aborted = AbortSignal.abort() - assert(Exit.isInterrupted(await Runtime.runPromiseExit(Runtime.defaultRuntime)(Effect.never, { signal: aborted }))) + assertTrue( + Exit.isInterrupted(await Runtime.runPromiseExit(Runtime.defaultRuntime)(Effect.never, { signal: aborted })) + ) const controller = new AbortController() setTimeout(() => controller.abort(), 10) - assert( + assertTrue( Exit.isInterrupted( await Runtime.runPromiseExit(Runtime.defaultRuntime)(Effect.never, { signal: controller.signal }) ) diff --git a/packages/effect/test/RuntimeFlags.test.ts b/packages/effect/test/RuntimeFlags.test.ts index 5db840989f5..6ac79e75be0 100644 --- a/packages/effect/test/RuntimeFlags.test.ts +++ b/packages/effect/test/RuntimeFlags.test.ts @@ -1,8 +1,6 @@ -import { pipe } from "effect/Function" -import * as RuntimeFlags from "effect/RuntimeFlags" -import * as RuntimeFlagsPatch from "effect/RuntimeFlagsPatch" -import * as fc from "fast-check" -import { assert, describe, it } from "vitest" +import { FastCheck as fc, pipe, RuntimeFlags, RuntimeFlagsPatch } from "effect" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" const arbRuntimeFlag = fc.constantFrom( RuntimeFlags.None, @@ -23,11 +21,11 @@ describe("RuntimeFlags", () => { RuntimeFlags.RuntimeMetrics, RuntimeFlags.Interruption ) - assert.isTrue(RuntimeFlags.isEnabled(flags, RuntimeFlags.RuntimeMetrics)) - assert.isTrue(RuntimeFlags.isEnabled(flags, RuntimeFlags.Interruption)) - assert.isFalse(RuntimeFlags.isEnabled(flags, RuntimeFlags.CooperativeYielding)) - assert.isFalse(RuntimeFlags.isEnabled(flags, RuntimeFlags.OpSupervision)) - assert.isFalse(RuntimeFlags.isEnabled(flags, RuntimeFlags.WindDown)) + assertTrue(RuntimeFlags.isEnabled(flags, RuntimeFlags.RuntimeMetrics)) + assertTrue(RuntimeFlags.isEnabled(flags, RuntimeFlags.Interruption)) + assertFalse(RuntimeFlags.isEnabled(flags, RuntimeFlags.CooperativeYielding)) + assertFalse(RuntimeFlags.isEnabled(flags, RuntimeFlags.OpSupervision)) + assertFalse(RuntimeFlags.isEnabled(flags, RuntimeFlags.WindDown)) }) it("enabled patching", () => { @@ -41,7 +39,7 @@ describe("RuntimeFlags", () => { RuntimeFlags.RuntimeMetrics, RuntimeFlags.OpSupervision ) - assert.strictEqual(result, expected) + strictEqual(result, expected) }) it("inverse patching", () => { @@ -58,11 +56,11 @@ describe("RuntimeFlags", () => { RuntimeFlagsPatch.andThen(RuntimeFlagsPatch.enable(RuntimeFlags.OpSupervision)), RuntimeFlagsPatch.inverse ) - assert.strictEqual( + strictEqual( RuntimeFlags.patch(flags, patch1), RuntimeFlags.make(RuntimeFlags.OpSupervision) ) - assert.strictEqual( + strictEqual( RuntimeFlags.patch(flags, patch2), RuntimeFlags.none ) @@ -71,7 +69,7 @@ describe("RuntimeFlags", () => { it("diff", () => { const flags1 = RuntimeFlags.make(RuntimeFlags.RuntimeMetrics) const flags2 = RuntimeFlags.make(RuntimeFlags.RuntimeMetrics, RuntimeFlags.OpSupervision) - assert.strictEqual( + strictEqual( RuntimeFlags.diff(flags1, flags2), RuntimeFlagsPatch.enable(RuntimeFlags.OpSupervision) ) @@ -82,14 +80,14 @@ describe("RuntimeFlags", () => { const result = Array.from(RuntimeFlags.toSet(flags)).every( (flag) => RuntimeFlags.isEnabled(flags, flag) ) - assert.isTrue(result) + assertTrue(result) })) }) it("patching a diff between `none` and a set of flags is an identity", () => { fc.assert(fc.property(arbRuntimeFlags, (flags) => { const diff = RuntimeFlags.diff(RuntimeFlags.none, flags) - assert.strictEqual( + strictEqual( RuntimeFlags.patch(RuntimeFlags.none, diff), flags ) @@ -99,11 +97,11 @@ describe("RuntimeFlags", () => { it("patching the inverse diff between `non` and a set of flags is `none`", () => { fc.assert(fc.property(arbRuntimeFlags, (flags) => { const diff = RuntimeFlags.diff(RuntimeFlags.none, flags) - assert.strictEqual( + strictEqual( RuntimeFlags.patch(flags, RuntimeFlagsPatch.inverse(diff)), RuntimeFlags.none ) - assert.strictEqual( + strictEqual( RuntimeFlags.patch(flags, RuntimeFlagsPatch.inverse(RuntimeFlagsPatch.inverse(diff))), flags ) diff --git a/packages/effect/test/STM.test.ts b/packages/effect/test/STM.test.ts index 0b72e06b09d..b872660d3f5 100644 --- a/packages/effect/test/STM.test.ts +++ b/packages/effect/test/STM.test.ts @@ -1,20 +1,34 @@ -import * as Cause from "effect/Cause" -import * as Chunk from "effect/Chunk" -import * as Context from "effect/Context" -import * as Deferred from "effect/Deferred" -import * as Effect from "effect/Effect" -import * as Either from "effect/Either" -import * as Exit from "effect/Exit" -import * as Fiber from "effect/Fiber" -import { constFalse, constTrue, constVoid, pipe } from "effect/Function" -import * as Option from "effect/Option" -import * as STM from "effect/STM" -import * as TDeferred from "effect/TDeferred" +import { + Cause, + Chunk, + Context, + Deferred, + Effect, + Either, + Exit, + FastCheck as fc, + Fiber, + Option, + pipe, + STM, + TDeferred, + TQueue, + TRef +} from "effect" +import { constFalse, constTrue, constVoid } from "effect/Function" +import { + assertFailure, + assertFalse, + assertLeft, + assertNone, + assertRight, + assertSome, + assertTrue, + deepStrictEqual, + strictEqual +} from "effect/test/util" import * as it from "effect/test/utils/extend" -import * as TQueue from "effect/TQueue" -import * as TRef from "effect/TRef" -import * as fc from "fast-check" -import { assert, describe } from "vitest" +import { describe } from "vitest" interface STMEnv { readonly ref: TRef.TRef @@ -149,7 +163,7 @@ describe("STM", () => { STM.catchAll((s) => STM.succeed(`${s} phew`)) ) const result = yield* STM.commit(transaction) - assert.deepStrictEqual(result, "Ouch! phew") + deepStrictEqual(result, "Ouch! phew") })) it.effect("collectAll - ordering", () => @@ -162,7 +176,7 @@ describe("STM", () => { STM.flatMap((queue) => STM.all(Array.from({ length: 3 }, () => TQueue.take(queue)))) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(Array.from(result), [1, 2, 3]) + deepStrictEqual(Array.from(result), [1, 2, 3]) })) it.effect("catchSome - catches matched errors", () => @@ -177,7 +191,7 @@ describe("STM", () => { ) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, "gotcha") + deepStrictEqual(result, "gotcha") })) it.effect("catchSome - lets the error pass", () => @@ -193,7 +207,7 @@ describe("STM", () => { ) ) const result = yield* $(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) it.effect("collectAll - collects a list of transactional effects to a single transaction", () => @@ -206,21 +220,21 @@ describe("STM", () => { concurrency: "unbounded" }) ) - assert.deepStrictEqual(Array.from(result), Array.from(chunk)) + deepStrictEqual(Array.from(result), Array.from(chunk)) })) it.effect("either - convert a successful computation into a Right", () => Effect.gen(function*($) { const transaction = STM.either(STM.succeed(42)) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, Either.right(42)) + deepStrictEqual(result, Either.right(42)) })) it.effect("either - convert a failed computation into a Left", () => Effect.gen(function*($) { const transaction = STM.either(STM.fail("Ouch")) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, Either.left("Ouch")) + deepStrictEqual(result, Either.left("Ouch")) })) it.effect("environment - access and provide outside transaction", () => @@ -236,7 +250,7 @@ describe("STM", () => { ) ) )) - assert.deepStrictEqual(result, 1) + deepStrictEqual(result, 1) })) it.effect("environment - access and provide inside transaction", () => @@ -251,7 +265,7 @@ describe("STM", () => { ) ) )) - assert.deepStrictEqual(result, 1) + deepStrictEqual(result, 1) })) it.effect("eventually - succeeds", () => @@ -268,13 +282,13 @@ describe("STM", () => { STM.flatMap((ref) => STM.eventually(f(ref))) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 10) + strictEqual(result, 10) })) it.effect("fail", () => Effect.gen(function*($) { const result = yield* $(Effect.exit(STM.commit(STM.fail("Ouch")))) - assert.deepStrictEqual(result, Exit.fail("Ouch")) + deepStrictEqual(result, Exit.fail("Ouch")) })) it.effect("filter - filters a collection using an effectual predicate", () => @@ -290,8 +304,8 @@ describe("STM", () => { return { results, effects } }) const { effects, results } = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(Array.from(results), [2, 4, 6, 6]) - assert.deepStrictEqual(Array.from(effects), array) + deepStrictEqual(Array.from(results), [2, 4, 6, 6]) + deepStrictEqual(Array.from(effects), array) })) it.effect("filterOrDie - dies when predicate fails", () => @@ -302,7 +316,7 @@ describe("STM", () => { STM.filterOrDie((n) => n !== 1, () => error) ) const result = yield* $(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.die(error)) + deepStrictEqual(result, Exit.die(error)) })) it.effect("filterOrDieMessage - dies with message when predicate fails", () => @@ -312,7 +326,7 @@ describe("STM", () => { STM.filterOrDieMessage((n) => n !== 1, "Ouch") ) const result = yield* $(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.die(new Cause.RuntimeException("Ouch"))) + deepStrictEqual(result, Exit.die(new Cause.RuntimeException("Ouch"))) })) it.effect("filterOrElse - returns checked failure", () => @@ -322,7 +336,7 @@ describe("STM", () => { STM.filterOrElse((n) => n === 1, () => STM.succeed(2)) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("filterOrElse - returns held value", () => @@ -332,7 +346,7 @@ describe("STM", () => { STM.filterOrElse((n) => n !== 1, () => STM.succeed(2)) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 2) + strictEqual(result, 2) })) it.effect("filterOrElse - returns checked failure", () => @@ -342,7 +356,7 @@ describe("STM", () => { STM.filterOrElse((n) => n === 1, (n) => STM.succeed(n + 1)) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("filterOrElse - returns held value", () => @@ -352,7 +366,7 @@ describe("STM", () => { STM.filterOrElse((n) => n !== 1, (n) => STM.succeed(n + 1)) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 2) + strictEqual(result, 2) })) it.effect("filterOrElse - returns error", () => @@ -364,7 +378,7 @@ describe("STM", () => { STM.filterOrElse((n) => n === 1, (n) => STM.succeed(n + 1)) ) const result = yield* $(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) it.effect("filterOrFail - returns failure when predicate fails", () => @@ -375,14 +389,14 @@ describe("STM", () => { STM.filterOrFail((n) => n !== 1, () => error) ) const result = yield* $(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) it.effect("flatten", () => Effect.gen(function*($) { const transaction = STM.flatten(STM.succeed(STM.succeed("test"))) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, "test") + strictEqual(result, "test") })) it.effect("forEach - performs an action on each chunk element and return a single transaction", () => @@ -392,7 +406,7 @@ describe("STM", () => { yield* $(pipe(chunk, STM.forEach((n) => pipe(ref, TRef.update((i) => i + n))))) const expected = pipe(chunk, Chunk.reduceRight(0, (acc, curr) => acc + curr)) const result = yield* $(TRef.get(ref)) - assert.strictEqual(result, expected) + strictEqual(result, expected) })) it.effect("forEach - performs an action on each chunk element", () => @@ -402,7 +416,7 @@ describe("STM", () => { yield* $(STM.forEach(chunk, (n) => pipe(ref, TRef.update((i) => i + n)), { discard: true })) const expected = pipe(chunk, Chunk.reduceRight(0, (acc, curr) => acc + curr)) const result = yield* $(TRef.get(ref)) - assert.strictEqual(result, expected) + strictEqual(result, expected) })) it.effect("fold - handles both failure and success", () => @@ -412,8 +426,8 @@ describe("STM", () => { failure: pipe(STM.fail("no"), STM.match({ onFailure: () => -1, onSuccess: () => 1 })) }) const { failure, success } = yield* $(STM.commit(transaction)) - assert.strictEqual(success, 1) - assert.strictEqual(failure, -1) + strictEqual(success, 1) + strictEqual(failure, -1) })) it.effect("foldSTM - folds over the `STM` effect, and handle failure and success", () => @@ -423,29 +437,29 @@ describe("STM", () => { failure: pipe(STM.fail("no"), STM.matchSTM({ onFailure: STM.succeed, onSuccess: () => STM.succeed("yes") })) }) const { failure, success } = yield* $(STM.commit(transaction)) - assert.strictEqual(failure, "no") - assert.strictEqual(success, "yes") + strictEqual(failure, "no") + strictEqual(success, "yes") })) it.effect("head - extracts the first value from an iterable", () => Effect.gen(function*($) { const transaction = STM.head(STM.succeed([1, 2])) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("head - returns None if the iterable is empty", () => Effect.gen(function*($) { const transaction = STM.head(STM.succeed([])) const result = yield* $(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.fail(Option.none())) + assertFailure(result, Cause.fail(Option.none())) })) it.effect("head - returns Some if there is an error", () => Effect.gen(function*($) { const transaction = STM.head(STM.fail("Ouch")) const result = yield* $(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.fail(Option.some("Ouch"))) + assertFailure(result, Cause.fail(Option.some("Ouch"))) })) it.effect("if - runs `onTrue` if result is `true`", () => @@ -458,7 +472,7 @@ describe("STM", () => { }) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("if - runs `onFalse` if result is `false`", () => @@ -471,42 +485,42 @@ describe("STM", () => { }) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, -1) + strictEqual(result, -1) })) it.effect("mapBoth - success value", () => Effect.gen(function*($) { const transaction = pipe(STM.succeed(1), STM.mapBoth({ onFailure: () => -1, onSuccess: (n) => `${n} as string` })) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, "1 as string") + strictEqual(result, "1 as string") })) it.effect("mapBoth - success value", () => Effect.gen(function*($) { const transaction = pipe(STM.fail(-1), STM.mapBoth({ onFailure: (n) => `${n} as string`, onSuccess: () => 0 })) const result = yield* $(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.fail("-1 as string")) + deepStrictEqual(result, Exit.fail("-1 as string")) })) it.effect("mapError - map from one error to another", () => Effect.gen(function*($) { const transaction = pipe(STM.fail(-1), STM.mapError(() => "Ouch")) const result = yield* $(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.fail("Ouch")) + deepStrictEqual(result, Exit.fail("Ouch")) })) it.effect("merge - on error", () => Effect.gen(function*($) { const transaction = STM.merge(STM.fromEither(Either.left(1))) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("merge - on success", () => Effect.gen(function*($) { const transaction = STM.merge(STM.fromEither(Either.right(1))) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("mergeAll - return zero element on empty input", () => @@ -516,7 +530,7 @@ describe("STM", () => { STM.mergeAll(42, () => 43) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 42) + strictEqual(result, 42) })) it.effect("mergeAll - merge iterable using function", () => @@ -526,7 +540,7 @@ describe("STM", () => { STM.mergeAll(1, (acc, curr) => acc + curr) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 1 + 3 + 5 + 7) + strictEqual(result, 1 + 3 + 5 + 7) })) it.effect("mergeAll - return error if it exists in list", () => @@ -536,21 +550,21 @@ describe("STM", () => { STM.mergeAll(void 0 as void, constVoid) ) const result = yield* $(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.fail(1)) + deepStrictEqual(result, Exit.fail(1)) })) it.effect("none - on None", () => Effect.gen(function*($) { const transaction = STM.none(STM.succeed(Option.none())) const result = yield* $(STM.commit(transaction)) - assert.isUndefined(result) + strictEqual(result, undefined) })) it.effect("none - on Some", () => Effect.gen(function*($) { const transaction = STM.none(STM.succeed(Option.some(1))) const result = yield* $(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.fail(Option.none())) + assertFailure(result, Cause.fail(Option.none())) })) it.effect("none - on error", () => @@ -558,21 +572,21 @@ describe("STM", () => { const error = new Cause.RuntimeException("Ouch") const transaction = STM.none(STM.fail(error)) const result = yield* $(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.fail(Option.some(error))) + assertFailure(result, Cause.fail(Option.some(error))) })) it.effect("option - success converts to Some", () => Effect.gen(function*($) { const transaction = STM.option(STM.succeed(42)) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, Option.some(42)) + assertSome(result, 42) })) it.effect("option - failure converts to None", () => Effect.gen(function*($) { const transaction = STM.option(STM.fail("Ouch")) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("orElse - succeeds if left succeeds", () => @@ -580,7 +594,7 @@ describe("STM", () => { const left = STM.succeed("left") const right = STM.succeed("right") const result = yield* $(STM.commit(pipe(left, STM.orElse(() => right)))) - assert.strictEqual(result, "left") + strictEqual(result, "left") })) it.effect("orElse - succeeds if right succeeds", () => @@ -588,7 +602,7 @@ describe("STM", () => { const left = STM.retry const right = STM.succeed("right") const result = yield* $(STM.commit(pipe(left, STM.orElse(() => right)))) - assert.strictEqual(result, "right") + strictEqual(result, "right") })) it.effect("orElse - tries alternative once left retries", () => @@ -598,7 +612,7 @@ describe("STM", () => { const right = pipe(ref, TRef.update((n) => n + 200)) yield* $(pipe(left, STM.orElse(() => right))) const result = yield* $(TRef.get(ref)) - assert.strictEqual(result, 200) + strictEqual(result, 200) })) it.effect("orElse - tries alternative once left fails", () => @@ -608,7 +622,7 @@ describe("STM", () => { const right = pipe(ref, TRef.update((n) => n + 200)) yield* $(pipe(left, STM.orElse(() => right))) const result = yield* $(TRef.get(ref)) - assert.strictEqual(result, 200) + strictEqual(result, 200) })) it.effect("orElse - fail if alternative fails", () => @@ -616,7 +630,7 @@ describe("STM", () => { const left = STM.fail("left") const right = STM.fail("right") const result = yield* $(pipe(left, STM.orElse(() => right), Effect.exit)) - assert.deepStrictEqual(result, Exit.fail("right")) + assertFailure(result, Cause.fail("right")) })) it.effect("orElseEither - orElseEither returns result of the first successful transaction", () => @@ -624,72 +638,72 @@ describe("STM", () => { const result1 = yield* $(pipe(STM.retry, STM.orElseEither(() => STM.succeed(42)))) const result2 = yield* $(pipe(STM.succeed(1), STM.orElseEither(() => STM.succeed("no")))) const result3 = yield* $(pipe(STM.succeed(2), STM.orElseEither(() => STM.retry))) - assert.deepStrictEqual(result1, Either.right(42)) - assert.deepStrictEqual(result2, Either.left(1)) - assert.deepStrictEqual(result3, Either.left(2)) + assertRight(result1, 42) + assertLeft(result2, 1) + assertLeft(result3, 2) })) it.effect("orElseFail - tries left first", () => Effect.gen(function*($) { const transaction = pipe(STM.succeed(true), STM.orElseFail(() => false)) const result = yield* $(STM.commit(transaction)) - assert.isTrue(result) + assertTrue(result) })) it.effect("orElseFail - fails with the specified error once left retries", () => Effect.gen(function*($) { const transaction = pipe(STM.retry, STM.orElseFail(() => false), STM.either) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, Either.left(false)) + assertLeft(result, false) })) it.effect("orElseFail - fails with the specified error once left fails", () => Effect.gen(function*($) { const transaction = pipe(STM.fail(true), STM.orElseFail(() => false), STM.either) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, Either.left(false)) + assertLeft(result, false) })) it.effect("orElseSucceed - tries left first", () => Effect.gen(function*($) { const transaction = pipe(STM.succeed(true), STM.orElseSucceed(() => false)) const result = yield* $(STM.commit(transaction)) - assert.isTrue(result) + assertTrue(result) })) it.effect("orElseSucceed - succeeds with the specified error once left retries", () => Effect.gen(function*($) { const transaction = pipe(STM.retry, STM.orElseSucceed(() => false)) const result = yield* $(STM.commit(transaction)) - assert.isFalse(result) + assertFalse(result) })) it.effect("orElseSucceed - succeeds with the specified error once left fails", () => Effect.gen(function*($) { const transaction = pipe(STM.fail(true), STM.orElseSucceed(() => false)) const result = yield* $(STM.commit(transaction)) - assert.isFalse(result) + assertFalse(result) })) it.effect("unsome - converts Some in E to error in E", () => Effect.gen(function*($) { const transaction = STM.unsome(STM.fromEither(Either.left(Option.some("Ouch")))) const result = yield* $(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.fail("Ouch")) + deepStrictEqual(result, Exit.fail("Ouch")) })) it.effect("unsome - converts None in E to None in A", () => Effect.gen(function*($) { const transaction = STM.unsome(STM.fromEither(Either.left(Option.none()))) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("unsome - no error", () => Effect.gen(function*($) { const transaction = STM.unsome(STM.fromEither(Either.right(42))) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, Option.some(42)) + assertSome(result, 42) })) it.effect("orDie - when failure should die", () => @@ -697,14 +711,14 @@ describe("STM", () => { const error = new Cause.RuntimeException("Ouch") const transaction = STM.orDie(STM.fail(error)) const result = yield* $(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.die(error)) + deepStrictEqual(result, Exit.die(error)) })) it.effect("orDie - when succeed should keep going", () => Effect.gen(function*($) { const transaction = STM.orDie(STM.succeed(1)) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("orDieWith - when failure should die", () => @@ -712,7 +726,7 @@ describe("STM", () => { const error = new Cause.RuntimeException("Ouch") const transaction = pipe(STM.fail("-1"), STM.orDieWith(() => error)) const result = yield* $(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.die(error)) + deepStrictEqual(result, Exit.die(error)) })) it.effect("orDieWith - when succeed should keep going", () => @@ -720,7 +734,7 @@ describe("STM", () => { const error = new Cause.RuntimeException("Ouch") const transaction = pipe(STM.succeed(1), STM.orDieWith(() => error)) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("partition - collects only successes", () => @@ -728,8 +742,8 @@ describe("STM", () => { const input = Chunk.range(0, 9) const transaction = pipe(input, STM.partition(STM.succeed)) const [left, right] = yield* $(STM.commit(transaction)) - assert.isTrue(left.length === 0) - assert.deepStrictEqual(Array.from(right), Array.from(input)) + assertTrue(left.length === 0) + deepStrictEqual(Array.from(right), Array.from(input)) })) it.effect("partition - collects only failures", () => @@ -737,8 +751,8 @@ describe("STM", () => { const input = Chunk.range(0, 9) const transaction = pipe(input, STM.partition(STM.fail)) const [left, right] = yield* $(STM.commit(transaction)) - assert.isTrue(right.length === 0) - assert.deepStrictEqual(Array.from(left), Array.from(input)) + assertTrue(right.length === 0) + deepStrictEqual(Array.from(left), Array.from(input)) })) it.effect("partition - collects successes and failures", () => @@ -746,8 +760,8 @@ describe("STM", () => { const input = Chunk.range(0, 9) const transaction = pipe(input, STM.partition((n) => n % 2 === 0 ? STM.fail(n) : STM.succeed(n))) const [left, right] = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(Array.from(left), [0, 2, 4, 6, 8]) - assert.deepStrictEqual(Array.from(right), [1, 3, 5, 7, 9]) + deepStrictEqual(Array.from(left), [0, 2, 4, 6, 8]) + deepStrictEqual(Array.from(right), [1, 3, 5, 7, 9]) })) it.effect("partition - evaluates effects in the correct order", () => @@ -759,21 +773,21 @@ describe("STM", () => { return yield* $(TRef.get(ref)) }) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(Array.from(result), input) + deepStrictEqual(Array.from(result), input) })) it.it("reduce - with a successful step function sums the list properly", () => fc.assert(fc.asyncProperty(fc.array(fc.integer()), async (array) => { const transaction = pipe(array, STM.reduce(0, (acc, curr) => STM.succeed(acc + curr))) const result = await Effect.runPromise(STM.commit(transaction)) - assert.strictEqual(result, array.reduce((acc, curr) => acc + curr, 0)) + strictEqual(result, array.reduce((acc, curr) => acc + curr, 0)) }))) it.it("reduce - with a failing step function returns a failed transaction", () => fc.assert(fc.asyncProperty(fc.array(fc.integer(), { minLength: 1 }), async (array) => { const transaction = pipe(array, STM.reduce(0, () => STM.fail("Ouch"))) const result = await Effect.runPromise(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.fail("Ouch")) + deepStrictEqual(result, Exit.fail("Ouch")) }))) it.it("reduce - run sequentially from left to right", () => @@ -786,7 +800,7 @@ describe("STM", () => { ) ) const result = await Effect.runPromise(STM.commit(transaction)) - assert.deepStrictEqual(Array.from(result), array) + deepStrictEqual(Array.from(result), array) }))) it.effect("reduceAll", () => @@ -796,7 +810,7 @@ describe("STM", () => { STM.reduceAll(STM.succeed(1), (a, b) => a + b) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 10) + strictEqual(result, 10) })) it.effect("reduceAll - empty iterable", () => @@ -806,21 +820,21 @@ describe("STM", () => { STM.reduceAll(STM.succeed(1), (a, b) => a + b) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.it("reduceRight - with a successful step function sums the list properly", () => fc.assert(fc.asyncProperty(fc.array(fc.integer()), async (array) => { const transaction = pipe(array, STM.reduceRight(0, (acc, curr) => STM.succeed(acc + curr))) const result = await Effect.runPromise(STM.commit(transaction)) - assert.strictEqual(result, array.reduce((acc, curr) => acc + curr, 0)) + strictEqual(result, array.reduce((acc, curr) => acc + curr, 0)) }))) it.it("reduceRight - with a failing step function returns a failed transaction", () => fc.assert(fc.asyncProperty(fc.array(fc.integer(), { minLength: 1 }), async (array) => { const transaction = pipe(array, STM.reduceRight(0, () => STM.fail("Ouch"))) const result = await Effect.runPromise(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.fail("Ouch")) + deepStrictEqual(result, Exit.fail("Ouch")) }))) it.it("reduceRight - run sequentially from right to left", () => @@ -833,7 +847,7 @@ describe("STM", () => { ) ) const result = await Effect.runPromise(STM.commit(transaction)) - assert.deepStrictEqual(Array.from(result), array) + deepStrictEqual(Array.from(result), array) }))) it.effect("reject - doesnt collect value", () => @@ -843,7 +857,7 @@ describe("STM", () => { STM.reject((n) => n !== 0 ? Option.some("Ouch") : Option.none()) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("reject - returns failure ignoring value", () => @@ -853,7 +867,7 @@ describe("STM", () => { STM.reject((n) => n !== 0 ? Option.some("Ouch") : Option.none()) ) const result = yield* $(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.fail("Ouch")) + deepStrictEqual(result, Exit.fail("Ouch")) })) it.effect("rejectSTM - doesnt collect value", () => @@ -863,7 +877,7 @@ describe("STM", () => { STM.rejectSTM((n) => n !== 0 ? Option.some(STM.succeed("Ouch")) : Option.none()) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("rejectSTM - returns failure ignoring value", () => @@ -873,7 +887,7 @@ describe("STM", () => { STM.rejectSTM((n) => n !== 0 ? Option.some(STM.succeed("Ouch")) : Option.none()) ) const result = yield* $(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.fail("Ouch")) + deepStrictEqual(result, Exit.fail("Ouch")) })) it.effect("repeatWhile - runs effect while it satisfies predicate", () => @@ -889,7 +903,7 @@ describe("STM", () => { ) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("repeatUntil - runs effect until it satisfies predicate", () => @@ -905,42 +919,42 @@ describe("STM", () => { ) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("replicate - zero", () => Effect.gen(function*($) { const transaction = STM.all(STM.replicate(STM.succeed(12), 0)) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(Array.from(result), []) + deepStrictEqual(Array.from(result), []) })) it.effect("replicate - negative", () => Effect.gen(function*($) { const transaction = STM.all(STM.replicate(STM.succeed(12), -1)) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(Array.from(result), []) + deepStrictEqual(Array.from(result), []) })) it.effect("replicate - positive", () => Effect.gen(function*($) { const transaction = STM.all(STM.replicate(STM.succeed(12), 2)) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(Array.from(result), [12, 12]) + deepStrictEqual(Array.from(result), [12, 12]) })) it.effect("some - extracts the value from Some", () => Effect.gen(function*($) { const transaction = STM.some(STM.succeed(Option.some(1))) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("some - fails on None", () => Effect.gen(function*($) { const transaction = STM.some(STM.succeed(Option.none())) const result = yield* $(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.fail(Option.none())) + assertFailure(result, Cause.fail(Option.none())) })) it.effect("some - fails on error", () => @@ -948,19 +962,19 @@ describe("STM", () => { const error = new Cause.RuntimeException("Ouch") const transaction = STM.some(STM.fail(error)) const result = yield* $(Effect.exit(STM.commit(transaction))) - assert.deepStrictEqual(result, Exit.fail(Option.some(error))) + assertFailure(result, Cause.fail(Option.some(error))) })) it.effect("succeed", () => Effect.gen(function*($) { const result = yield* $(STM.commit(STM.succeed("test"))) - assert.strictEqual(result, "test") + strictEqual(result, "test") })) it.effect("gen with context", () => STM.gen({ context: "Context" as const }, function*() { const result = yield* STM.succeed(this.context) - assert.strictEqual(result, "Context") + strictEqual(result, "Context") })) it.effect("summarized - returns summary and value", () => @@ -975,7 +989,7 @@ describe("STM", () => { return [result[0][0], result[1], result[0][1]] as const }) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [1, 2, 3]) + deepStrictEqual(result, [1, 2, 3]) })) it.effect("tap - applies the function to the result preserving the original result", () => @@ -990,8 +1004,8 @@ describe("STM", () => { ) ) const { result1, result2 } = yield* $(STM.commit(transaction)) - assert.strictEqual(result1, 10) - assert.strictEqual(result2, 11) + strictEqual(result1, 10) + strictEqual(result2, 11) })) it.effect("tapBoth - applies the function to success values preserving the original result", () => @@ -1010,7 +1024,7 @@ describe("STM", () => { return [result, success] as const }) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [42, 42]) + deepStrictEqual(result, [42, 42]) })) it.effect("tapBoth - applies the function to error values preserving the original error", () => @@ -1030,7 +1044,7 @@ describe("STM", () => { return [result, error] as const }) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [Either.left("error"), "error"]) + deepStrictEqual(result, [Either.left("error"), "error"]) })) it.effect("tapError - should apply the function to the error result preserving the original error", () => @@ -1047,7 +1061,7 @@ describe("STM", () => { return [result, error] }) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [Either.left("error"), "error"]) + deepStrictEqual(result, [Either.left("error"), "error"]) })) it.effect("validateAll - returns all errors if never valid", () => @@ -1059,7 +1073,7 @@ describe("STM", () => { Effect.mapError((chunk) => Array.from(chunk)), Effect.exit )) - assert.deepStrictEqual(result, Exit.fail(input)) + deepStrictEqual(result, Exit.fail(input)) })) it.effect("validateAll - accumulate errors and ignore successes", () => @@ -1071,7 +1085,7 @@ describe("STM", () => { Effect.mapError((chunk) => Array.from(chunk)), Effect.exit )) - assert.deepStrictEqual(result, Exit.fail([1, 3, 5, 7, 9])) + deepStrictEqual(result, Exit.fail([1, 3, 5, 7, 9])) })) it.effect("validateAll - accumulate successes", () => @@ -1082,7 +1096,7 @@ describe("STM", () => { STM.commit(transaction), Effect.map((chunk) => Array.from(chunk)) )) - assert.deepStrictEqual(result, input) + deepStrictEqual(result, input) })) it.effect("validateFirst - returns all errors if never valid", () => @@ -1094,7 +1108,7 @@ describe("STM", () => { Effect.mapError((chunk) => Array.from(chunk)), Effect.exit )) - assert.deepStrictEqual(result, Exit.fail(input)) + deepStrictEqual(result, Exit.fail(input)) })) it.effect("validateFirst - runs sequentially and short circuits on first success validation", () => @@ -1111,7 +1125,7 @@ describe("STM", () => { return [result, counter] as const }) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [6, 6]) + deepStrictEqual(result, [6, 6]) })) it.effect("validateFirst - returns errors in correct order", () => @@ -1123,7 +1137,7 @@ describe("STM", () => { Effect.mapError((chunk) => Array.from(chunk)), Effect.exit )) - assert.deepStrictEqual(result, Exit.fail(input)) + deepStrictEqual(result, Exit.fail(input)) })) it.effect("when - true", () => @@ -1136,7 +1150,7 @@ describe("STM", () => { STM.zipRight(TRef.get(ref)) ) const result = yield* $(STM.commit(transaction)) - assert.isTrue(result) + assertTrue(result) })) it.effect("when - false", () => @@ -1149,7 +1163,7 @@ describe("STM", () => { STM.zipRight(TRef.get(ref)) ) const result = yield* $(STM.commit(transaction)) - assert.isFalse(result) + assertFalse(result) })) it.effect("whenSTM - true", () => @@ -1163,7 +1177,7 @@ describe("STM", () => { STM.zipRight(TRef.get(ref)) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("whenSTM - false", () => @@ -1177,21 +1191,21 @@ describe("STM", () => { STM.zipRight(TRef.get(ref)) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("zip - return a tuple of two computations", () => Effect.gen(function*($) { const transaction = pipe(STM.succeed(1), STM.zip(STM.succeed("A"))) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [1, "A"]) + deepStrictEqual(result, [1, "A"]) })) it.effect("zipWith - perform an action on two computations", () => Effect.gen(function*($) { const transaction = pipe(STM.succeed(578), STM.zipWith(STM.succeed(2), (a, b) => a + b)) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 580) + strictEqual(result, 580) })) it.effect("stack-safety - long orElse chains", () => @@ -1208,41 +1222,41 @@ describe("STM", () => { ), discard: true })) - assert.strictEqual(value, void 0) + strictEqual(value, void 0) return yield* $(TRef.get(ref)) }) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 10_000) + strictEqual(result, 10_000) })) it.effect("stack-safety - long map chains", () => Effect.gen(function*($) { const result = yield* $(chain(10_000)(STM.map((n) => n + 1))) - assert.strictEqual(result, 10_000) + strictEqual(result, 10_000) })) it.effect("stack-safety - long collect chains", () => Effect.gen(function*($) { const result = yield* $(chain(10_000)(STM.collect((n) => Option.some(n + 1)))) - assert.strictEqual(result, 10_000) + strictEqual(result, 10_000) })) it.effect("stack-safety - long collectSTM chains", () => Effect.gen(function*($) { const result = yield* $(chain(10_000)(STM.collectSTM((n) => Option.some(STM.succeed(n + 1))))) - assert.strictEqual(result, 10_000) + strictEqual(result, 10_000) })) it.effect("stack-safety - long flatMap chains", () => Effect.gen(function*($) { const result = yield* $(chain(10_000)(STM.flatMap((n) => STM.succeed(n + 1)))) - assert.strictEqual(result, 10_000) + strictEqual(result, 10_000) })) it.effect("stack-safety - long fold chains", () => Effect.gen(function*($) { const result = yield* $(chain(10_000)(STM.match({ onFailure: () => 0, onSuccess: (n) => n + 1 }))) - assert.strictEqual(result, 10_000) + strictEqual(result, 10_000) })) it.effect("stack-safety - long foldSTM chains", () => @@ -1250,13 +1264,13 @@ describe("STM", () => { const result = yield* $( chain(10_000)(STM.matchSTM({ onFailure: () => STM.succeed(0), onSuccess: (n) => STM.succeed(n + 1) })) ) - assert.strictEqual(result, 10_000) + strictEqual(result, 10_000) })) it.effect("stack-safety - long mapError chains", () => Effect.gen(function*($) { const result = yield* $(Effect.exit(chainError(10_000))) - assert.deepStrictEqual(result, Exit.fail(10_000)) + deepStrictEqual(result, Exit.fail(10_000)) })) it.effect("stack-safety - long orElse chains", () => @@ -1274,13 +1288,13 @@ describe("STM", () => { STM.flatMap(TRef.get) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 10_000) + strictEqual(result, 10_000) })) it.effect("stack-safety - long provideEnvironment chains", () => Effect.gen(function*($) { const result = yield* $(chain(10_000)(STM.provideContext(Context.empty()))) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("ZIO STM (Issue #2073)", () => @@ -1305,7 +1319,7 @@ describe("STM", () => { STM.commit )) const result = yield* $(Fiber.join(fiber)) - assert.isTrue(result === 0 || result === 2) + assertTrue(result === 0 || result === 2) })) describe("concurrent computations", () => { @@ -1317,7 +1331,7 @@ describe("STM", () => { )) yield* $(Fiber.join(fiber)) const result = yield* $(TRef.get(ref)) - assert.strictEqual(result, 1_000) + strictEqual(result, 1_000) })) it.effect("compute a `TRef` from 2 variables, increment the first `TRef` and decrement the second `TRef` in different fibers", () => @@ -1328,7 +1342,7 @@ describe("STM", () => { )) yield* $(Fiber.join(fiber)) const result = yield* $(TRef.get(refs[2])) - assert.strictEqual(result, 10_000) + strictEqual(result, 10_000) })) }) @@ -1343,7 +1357,7 @@ describe("STM", () => { STM.zipRight(TRef.get(ref2)), STM.commit )) - assert.strictEqual(result, "success") + strictEqual(result, "success") })) it.effect("condition locks - resume directly when the condition is already satisfied and change the ref with non-satisfying value", () => @@ -1356,8 +1370,8 @@ describe("STM", () => { )) yield* $(pipe(ref, TRef.set(9), STM.commit)) const value = yield* $(TRef.get(ref)) - assert.strictEqual(result, 42) - assert.strictEqual(value, 9) + strictEqual(result, 42) + strictEqual(value, 9) })) it.effect("condition locks - resume after satisfying the condition", () => { @@ -1384,8 +1398,8 @@ describe("STM", () => { yield* $(Deferred.await(done)) const newValue = yield* $(TRef.get(ref2)) const result = yield* $(Fiber.join(fiber)) - assert.strictEqual(oldValue, "failed") - assert.strictEqual(newValue, result) + strictEqual(oldValue, "failed") + strictEqual(newValue, result) }) }) @@ -1398,8 +1412,8 @@ describe("STM", () => { yield* $(pipe(TRef.get(sender), STM.retryUntil((n) => n === 50))) const senderValue = yield* $(TRef.get(sender)) const receiverValue = yield* $(TRef.get(receiver)) - assert.strictEqual(senderValue, 50) - assert.strictEqual(receiverValue, 150) + strictEqual(senderValue, 50) + strictEqual(receiverValue, 150) })) it.effect("condition locks - run both transactions sequentially", () => @@ -1416,8 +1430,8 @@ describe("STM", () => { yield* $(Fiber.join(fiber)) const senderValue = yield* $(TRef.get(sender)) const receiverValue = yield* $(TRef.get(receiver)) - assert.strictEqual(senderValue, 150) - assert.strictEqual(receiverValue, 0) + strictEqual(senderValue, 150) + strictEqual(receiverValue, 0) })) it.effect("condition locks - run both transactions concurrently #1", () => @@ -1439,8 +1453,8 @@ describe("STM", () => { yield* $(Fiber.join(fiber2)) const senderValue = yield* $(TRef.get(sender)) const receiverValue = yield* $(TRef.get(receiver)) - assert.strictEqual(senderValue, 100) - assert.strictEqual(receiverValue, 0) + strictEqual(senderValue, 100) + strictEqual(receiverValue, 0) })) it.effect("condition locks - run both transactions concurrently #2", () => @@ -1454,8 +1468,8 @@ describe("STM", () => { yield* $(Fiber.join(fiber)) const senderValue = yield* $(TRef.get(sender)) const receiverValue = yield* $(TRef.get(receiver)) - assert.strictEqual(senderValue, 100) - assert.strictEqual(receiverValue, 0) + strictEqual(senderValue, 100) + strictEqual(receiverValue, 0) })) it.effect("condition locks - atomically run a transaction with a TRef for 20 fibers, each one checking and incrementing the value", () => @@ -1475,7 +1489,7 @@ describe("STM", () => { )) yield* $(Fiber.join(fiber)) const result = yield* $(TRef.get(ref)) - assert.strictEqual(result, 21) + strictEqual(result, 21) })) it.effect("condition locks - atomically run a transaction that could not be satisfied", () => { @@ -1494,7 +1508,7 @@ describe("STM", () => { yield* $(Fiber.interrupt(fiber)) yield* $(pipe(ref, TRef.set(10))) const result = yield* $(pipe(Effect.yieldNow(), Effect.zipRight(TRef.get(ref)))) - assert.strictEqual(result, 10) + strictEqual(result, 10) }) }) @@ -1517,7 +1531,7 @@ describe("STM", () => { yield* $(Fiber.interrupt(fiber)) yield* $(pipe(ref, TRef.set(-1))) const result = yield* $(pipe(Effect.yieldNow(), Effect.zipRight(TRef.get(ref)))) - assert.strictEqual(result, -1) + strictEqual(result, -1) }) }) @@ -1533,7 +1547,7 @@ describe("STM", () => { )) yield* $(Fiber.interrupt(fiber)) const result = yield* $(pipe(Fiber.join(fiber), Effect.sandbox, Effect.either)) - assert.isTrue( + assertTrue( Either.isLeft(result) && pipe( result.left, @@ -1549,8 +1563,8 @@ describe("STM", () => { yield* $(permutation(ref1, ref2)) const result1 = yield* $(TRef.get(ref1)) const result2 = yield* $(TRef.get(ref2)) - assert.strictEqual(result1, 2) - assert.strictEqual(result2, 1) + strictEqual(result1, 2) + strictEqual(result2, 1) })) it.effect("permutations - permutes two variables in 100 fibers", () => @@ -1566,7 +1580,7 @@ describe("STM", () => { yield* $(Fiber.join(fiber)) const result1 = yield* $(TRef.get(ref1)) const result2 = yield* $(TRef.get(ref2)) - assert.strictEqual(result1, oldValue1) - assert.strictEqual(result2, oldValue2) + strictEqual(result1, oldValue1) + strictEqual(result2, oldValue2) })) }) diff --git a/packages/effect/test/Schedule.test.ts b/packages/effect/test/Schedule.test.ts index 958fb43e946..2c316f2cb87 100644 --- a/packages/effect/test/Schedule.test.ts +++ b/packages/effect/test/Schedule.test.ts @@ -1,42 +1,45 @@ -import * as Array from "effect/Array" -import * as Cause from "effect/Cause" -import * as Chunk from "effect/Chunk" -import * as Clock from "effect/Clock" -import * as Deferred from "effect/Deferred" -import * as Duration from "effect/Duration" -import * as Effect from "effect/Effect" -import * as Exit from "effect/Exit" -import * as Fiber from "effect/Fiber" +import { + Array, + Cause, + Chunk, + Clock, + Deferred, + Duration, + Effect, + Exit, + Fiber, + Option, + Ref, + Schedule, + ScheduleDecision, + ScheduleIntervals +} from "effect" import { constVoid } from "effect/Function" -import * as Option from "effect/Option" -import * as Ref from "effect/Ref" -import * as Schedule from "effect/Schedule" -import * as ScheduleDecision from "effect/ScheduleDecision" -import * as Intervals from "effect/ScheduleIntervals" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Schedule", () => { it.effect("collect all inputs into a list as long as the condition f holds", () => Effect.gen(function*($) { const result = yield* $(repeat(Schedule.collectWhile((n) => n < 10))) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 9)) + deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 9)) })) it.effect("collect all inputs into a list as long as the effectful condition f holds", () => Effect.gen(function*($) { const result = yield* $(repeat(Schedule.collectWhileEffect((n) => Effect.succeed(n > 10)))) - assert.isTrue(Chunk.isEmpty(result)) + assertTrue(Chunk.isEmpty(result)) })) it.effect("collect all inputs into a list until the effectful condition f fails", () => Effect.gen(function*($) { const result = yield* $(repeat(Schedule.collectUntil((n) => n < 10 && n > 1))) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [1]) + deepStrictEqual(Chunk.toReadonlyArray(result), [1]) })) it.effect("collect all inputs into a list until the effectful condition f fails", () => Effect.gen(function*($) { const result = yield* $(repeat(Schedule.collectUntilEffect((n) => Effect.succeed(n > 10)))) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 10)) + deepStrictEqual(Chunk.toReadonlyArray(result), Array.range(1, 10)) })) it.effect("union composes", () => Effect.gen(function*($) { @@ -50,7 +53,7 @@ describe("Schedule", () => { const input = Array.range(1, 5) const actual = yield* $(alsoWednesday, Schedule.delays, Schedule.run(now, input)) const expected = yield* $(wednesday, Schedule.delays, Schedule.run(now, input)) - assert.deepStrictEqual(Chunk.toReadonlyArray(actual), Chunk.toReadonlyArray(expected)) + deepStrictEqual(Chunk.toReadonlyArray(actual), Chunk.toReadonlyArray(expected)) })) it.effect("either should not wait if neither schedule wants to continue", () => Effect.gen(function*($) { @@ -60,7 +63,7 @@ describe("Schedule", () => { ) const input = Array.makeBy(4, constVoid) const result = yield* $(runCollect(schedule, input)) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [Duration.zero]) + deepStrictEqual(Chunk.toReadonlyArray(result), [Duration.zero]) })) it.effect("perform log for each recurrence of effect", () => Effect.gen(function*($) { @@ -70,7 +73,7 @@ describe("Schedule", () => { const ref = yield* $(Ref.make(0)) yield* $(Ref.getAndUpdate(ref, (n) => n + 1), Effect.repeat(schedule(ref))) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 8) + strictEqual(result, 8) })) it.effect("reset after some inactivity", () => Effect.gen(function*($) { @@ -99,7 +102,7 @@ describe("Schedule", () => { yield* $(TestClock.adjust("10 seconds")) yield* $(Fiber.join(fiber)) const retries = yield* $(Ref.get(retriesCounter)) - assert.strictEqual(retries, 10) + strictEqual(retries, 10) })) it.effect("union of two schedules should continue as long as either wants to continue", () => Effect.gen(function*($) { @@ -107,7 +110,7 @@ describe("Schedule", () => { const input = Chunk.make(true, false, false, false, false) const result = yield* $(runCollect(schedule.pipe(Schedule.compose(Schedule.elapsed)), input)) const expected = [0, 0, 1, 2, 3].map(Duration.seconds) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), expected) + deepStrictEqual(Chunk.toReadonlyArray(result), expected) })) it.effect("Schedule.fixed should compute delays correctly", () => Effect.gen(function*($) { @@ -116,7 +119,7 @@ describe("Schedule", () => { runManually(Schedule.fixed("5 seconds"), inputs), Effect.map((output) => output[0].pipe(Chunk.map((tuple) => tuple[0]))) ) - assert.deepStrictEqual(result, Chunk.make(5000, 10000)) + deepStrictEqual(result, Chunk.make(5000, 10000)) })) it.effect("intersection of schedules recurring in bounded intervals", () => Effect.gen(function*($) { @@ -127,8 +130,8 @@ describe("Schedule", () => { const actual = Chunk.toReadonlyArray(scanLeft(delays, now, (now, delay) => now + Duration.toMillis(delay))).slice( 1 ) - assert.isTrue(actual.map((n) => new Date(n).getHours()).every((n) => n === 4)) - assert.isTrue(actual.map((n) => new Date(n).getMinutes()).every((n) => n === 20)) + assertTrue(actual.map((n) => new Date(n).getHours()).every((n) => n === 4)) + assertTrue(actual.map((n) => new Date(n).getMinutes()).every((n) => n === 20)) })) it.effect("passthrough", () => Effect.gen(function*($) { @@ -136,7 +139,7 @@ describe("Schedule", () => { const result = yield* $( Ref.getAndUpdate(ref, (n) => n + 1).pipe(Effect.repeat(Schedule.recurs(10).pipe(Schedule.passthrough))) ) - assert.strictEqual(result, 10) + strictEqual(result, 10) })) describe("simulate a schedule", () => { it.effect("without timing out", () => @@ -146,7 +149,7 @@ describe("Schedule", () => { Clock.currentTimeMillis, Effect.flatMap((now) => schedule.pipe(Schedule.run(now, Array.makeBy(5, constVoid)))) ) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [ + deepStrictEqual(Chunk.toReadonlyArray(result), [ Duration.minutes(1), Duration.minutes(2), Duration.minutes(4), @@ -162,7 +165,7 @@ describe("Schedule", () => { Effect.flatMap((now) => schedule.pipe(Schedule.run(now, Array.range(1, 10)))) ) ) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [ + deepStrictEqual(Chunk.toReadonlyArray(result), [ [0, Duration.minutes(1)], [1, Duration.minutes(2)], [2, Duration.minutes(4)] @@ -176,7 +179,7 @@ describe("Schedule", () => { Effect.flatMap((now) => schedule.pipe(Schedule.run(now, Array.range(1, 10)))) ) ) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [0, 1, 2, 3, 4, 5]) + deepStrictEqual(Chunk.toReadonlyArray(result), [0, 1, 2, 3, 4, 5]) })) }) describe("repeat an action a single time", () => { @@ -184,7 +187,7 @@ describe("Schedule", () => { Effect.gen(function*($) { const ref = yield* $(Ref.make(0)) const result = yield* $(Effect.flip(alwaysFail(ref))) - assert.strictEqual(result, "Error: 1") + strictEqual(result, "Error: 1") })) it.effect("repeat a scheduled repeat repeats the whole number", () => Effect.gen(function*($) { @@ -193,7 +196,7 @@ describe("Schedule", () => { const effect = ref.pipe(Ref.update((n) => n + 1), Effect.repeat(Schedule.recurs(n))) yield* $(effect, Effect.repeat(Schedule.recurs(1))) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, (n + 1) * 2) + strictEqual(result, (n + 1) * 2) })) }) describe("repeat an action two times and call ensuring should", () => { @@ -208,8 +211,8 @@ describe("Schedule", () => { ) const value = yield* $(Ref.get(ref)) const finalizerValue = yield* $(Deferred.poll(deferred)) - assert.strictEqual(value, 6) - assert.isTrue(Option.isSome(finalizerValue)) + strictEqual(value, 6) + assertTrue(Option.isSome(finalizerValue)) })) }) describe("repeat on success according to a provided strategy", () => { @@ -217,72 +220,72 @@ describe("Schedule", () => { Effect.gen(function*($) { // A repeat with a negative number of times should not repeat the action at all const result = yield* $(repeat(Schedule.recurs(-5))) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("for 'recurs(0)' does repeat 0 additional time", () => Effect.gen(function*($) { // A repeat with 0 number of times should not repeat the action at all const result = yield* $(repeat(Schedule.recurs(0))) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("for 'recurs(1)' does repeat 1 additional time", () => Effect.gen(function*($) { const result = yield* $(repeat(Schedule.recurs(1))) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("for 'once' will repeat 1 additional time", () => Effect.gen(function*($) { const ref = yield* $(Ref.make(0)) yield* $(Ref.update(ref, (n) => n + 1), Effect.repeat(Schedule.once)) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 2) + strictEqual(result, 2) })) it.effect("for 'recurs(a positive given number)' repeats that additional number of time", () => Effect.gen(function*($) { const result = yield* $(repeat(Schedule.recurs(42))) - assert.strictEqual(result, 42) + strictEqual(result, 42) })) it.effect("for 'recurWhile(cond)' repeats while the cond still holds", () => Effect.gen(function*($) { const result = yield* $(repeat(Schedule.recurWhile((n) => n < 10))) - assert.strictEqual(result, 10) + strictEqual(result, 10) })) it.effect("for 'recurWhileEffect(cond)' repeats while the effectful cond still holds", () => Effect.gen(function*($) { const result = yield* $(repeat(Schedule.recurWhileEffect((n) => Effect.succeed(n > 10)))) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("for 'recurUntil(cond)' repeats until the cond is satisfied", () => Effect.gen(function*($) { const result = yield* $(repeat(Schedule.recurUntil((n) => n < 10))) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("for 'recurUntilEffect(cond)' repeats until the effectful cond is satisfied", () => Effect.gen(function*($) { const result = yield* $(repeat(Schedule.recurUntilEffect((n) => Effect.succeed(n > 10)))) - assert.strictEqual(result, 11) + strictEqual(result, 11) })) }) describe("delays", () => { it.effect("duration", () => Effect.gen(function*($) { const [actual, expected] = yield* $(checkDelays(Schedule.duration("1 seconds"))) - assert.deepStrictEqual(actual, expected) + deepStrictEqual(actual, expected) })) it.effect("exponential", () => Effect.gen(function*($) { const [actual, expected] = yield* $(checkDelays(Schedule.exponential("1 seconds"))) - assert.deepStrictEqual(actual, expected) + deepStrictEqual(actual, expected) })) it.effect("fibonacci", () => Effect.gen(function*($) { const [actual, expected] = yield* $(checkDelays(Schedule.fibonacci("1 seconds"))) - assert.deepStrictEqual(actual, expected) + deepStrictEqual(actual, expected) })) it.effect("fromDelay", () => Effect.gen(function*($) { const [actual, expected] = yield* $(checkDelays(Schedule.fromDelay("1 seconds"))) - assert.deepStrictEqual(actual, expected) + deepStrictEqual(actual, expected) })) it.effect("fromDelays", () => Effect.gen(function*($) { @@ -291,74 +294,74 @@ describe("Schedule", () => { Schedule.fromDelays("1 seconds", "2 seconds", "3 seconds", "4 seconds") ) ) - assert.deepStrictEqual(actual, expected) + deepStrictEqual(actual, expected) })) it.effect("linear", () => Effect.gen(function*($) { const [actual, expected] = yield* $(checkDelays(Schedule.linear("1 seconds"))) - assert.deepStrictEqual(actual, expected) + deepStrictEqual(actual, expected) })) }) describe("repetitions", () => { it.effect("forever", () => Effect.gen(function*($) { const [actual, expected] = yield* $(checkRepetitions(Schedule.repeatForever)) - assert.deepStrictEqual(actual, expected) + deepStrictEqual(actual, expected) })) it.effect("count", () => Effect.gen(function*($) { const [actual, expected] = yield* $(checkRepetitions(Schedule.count)) - assert.deepStrictEqual(actual, expected) + deepStrictEqual(actual, expected) })) it.effect("dayOfMonth", () => Effect.gen(function*($) { const [actual, expected] = yield* $(checkRepetitions(Schedule.dayOfMonth(1))) - assert.deepStrictEqual(actual, expected) + deepStrictEqual(actual, expected) })) it.effect("dayOfWeek", () => Effect.gen(function*($) { const [actual, expected] = yield* $(checkRepetitions(Schedule.dayOfWeek(1))) - assert.deepStrictEqual(actual, expected) + deepStrictEqual(actual, expected) })) it.effect("hourOfDay", () => Effect.gen(function*($) { const [actual, expected] = yield* $(checkRepetitions(Schedule.hourOfDay(1))) - assert.deepStrictEqual(actual, expected) + deepStrictEqual(actual, expected) })) it.effect("minuteOfHour", () => Effect.gen(function*($) { const [actual, expected] = yield* $(checkRepetitions(Schedule.minuteOfHour(1))) - assert.deepStrictEqual(actual, expected) + deepStrictEqual(actual, expected) })) it.effect("secondOfMinute", () => Effect.gen(function*($) { const [actual, expected] = yield* $(checkRepetitions(Schedule.secondOfMinute(1))) - assert.deepStrictEqual(actual, expected) + deepStrictEqual(actual, expected) })) it.effect("fixed", () => Effect.gen(function*($) { const [actual, expected] = yield* $(checkRepetitions(Schedule.fixed("1 seconds"))) - assert.deepStrictEqual(actual, expected) + deepStrictEqual(actual, expected) })) it.effect("repeatForever", () => Effect.gen(function*($) { const [actual, expected] = yield* $(checkRepetitions(Schedule.repeatForever)) - assert.deepStrictEqual(actual, expected) + deepStrictEqual(actual, expected) })) it.effect("recurs", () => Effect.gen(function*($) { const [actual, expected] = yield* $(checkRepetitions(Schedule.recurs(2))) - assert.deepStrictEqual(actual, expected) + deepStrictEqual(actual, expected) })) it.effect("spaced", () => Effect.gen(function*($) { const [actual, expected] = yield* $(checkRepetitions(Schedule.spaced("1 seconds"))) - assert.deepStrictEqual(actual, expected) + deepStrictEqual(actual, expected) })) it.effect("windowed", () => Effect.gen(function*($) { const [actual, expected] = yield* $(checkRepetitions(Schedule.windowed("1 seconds"))) - assert.deepStrictEqual(actual, expected) + deepStrictEqual(actual, expected) })) }) describe("retries", () => { @@ -372,19 +375,19 @@ describe("Schedule", () => { Effect.flatMap(() => i < 5 ? Effect.fail("KeepTryingError") : Effect.succeed(i)) ) const result = yield* $(io, Effect.retry(strategy)) - assert.strictEqual(result, 5) + strictEqual(result, 5) })) it.effect("retry exactly one time for `once` when second time succeeds - retryOrElse", () => Effect.gen(function*($) { const ref = yield* $(Ref.make(0)) const result = yield* $(failOn0(ref), Effect.retryOrElse(Schedule.once, ioFail)) - assert.strictEqual(result, 2) + strictEqual(result, 2) })) it.effect("if fallback succeeded - retryOrElse", () => Effect.gen(function*($) { const ref = yield* $(Ref.make(0)) const result = yield* $(alwaysFail(ref), Effect.retryOrElse(Schedule.once, ioSucceed)) - assert.strictEqual(result, "OrElse") + strictEqual(result, "OrElse") })) it.effect("if fallback failed - retryOrElse", () => Effect.gen(function*($) { @@ -395,14 +398,14 @@ describe("Schedule", () => { Effect.flip ) ) - assert.strictEqual(result, "OrElseFailed") + strictEqual(result, "OrElseFailed") })) it.effect("retry 0 time for `once` when first time succeeds", () => Effect.gen(function*($) { const ref = yield* $(Ref.make(0)) yield* $(Ref.update(ref, (n) => n + 1), Effect.retry(Schedule.once)) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("retry 0 time for `recurs(0)`", () => Effect.gen(function*($) { @@ -413,7 +416,7 @@ describe("Schedule", () => { Effect.flip ) ) - assert.strictEqual(result, "Error: 1") + strictEqual(result, "Error: 1") })) it.effect("retry exactly one time for `once` when second time succeeds", () => Effect.gen(function*($) { @@ -422,7 +425,7 @@ describe("Schedule", () => { // One retry on failure yield* $(failOn0(ref), Effect.retry(Schedule.once)) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 2) + strictEqual(result, 2) })) it.effect("retry exactly one time for `once` even if still in error", () => Effect.gen(function*($) { @@ -435,13 +438,13 @@ describe("Schedule", () => { Effect.flip ) ) - assert.strictEqual(result, "Error: 2") + strictEqual(result, "Error: 2") })) it.effect("retry exactly 'n' times after failure", () => Effect.gen(function*($) { const ref = yield* $(Ref.make(0)) const result = yield* $(alwaysFail(ref), Effect.retry({ times: 3 }), Effect.flip) - assert.strictEqual(result, "Error: 4") + strictEqual(result, "Error: 4") })) // TODO(Max): after TestRandom // it.skip("for a given number of times with random jitter in (0, 1)") @@ -449,7 +452,7 @@ describe("Schedule", () => { // const schedule = Schedule.spaced((500).millis).jittered(0, 1) // const result = $(runCollect(schedule.compose(Schedule.elapsed), Chunk.fill(5, constVoid))) // const expected = Chunk((0).millis, (250).millis, (500).millis, (750).millis, (1000).millis) - // assert.isTrue() + // assertTrue() // }).unsafeRunPromise() // TODO(Max): after TestRandom // it.skip("for a given number of times with random jitter in custom interval") @@ -457,7 +460,7 @@ describe("Schedule", () => { // const schedule = Schedule.spaced((500).millis).jittered(2, 4) // const result = $(runCollect(schedule.compose(Schedule.elapsed), Chunk.fill(5, constVoid))) // const expected = Chunk((0).millis, (1500).millis, (3000).millis, (5000).millis, (7000).millis) - // assert.isTrue() + // assertTrue() // }).unsafeRunPromise() it.effect("fixed delay with error predicate", () => Effect.gen(function*($) { @@ -475,49 +478,49 @@ describe("Schedule", () => { TestClock.currentTimeMillis.pipe(Effect.map((now) => [Duration.millis(now), s, n] as const))) ) const result = yield* $(run(program)) - assert.deepStrictEqual(result, [Duration.millis(800), "GiveUpError", 4] as const) + deepStrictEqual(result, [Duration.millis(800), "GiveUpError", 4] as const) })) it.effect("fibonacci delay", () => Effect.gen(function*($) { const schedule = Schedule.fibonacci("100 millis").pipe(Schedule.compose(Schedule.elapsed)) const result = yield* $(runCollect(schedule, Array.makeBy(5, constVoid))) const expected = [0, 100, 200, 400, 700].map(Duration.millis) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), expected) + deepStrictEqual(Chunk.toReadonlyArray(result), expected) })) it.effect("linear delay", () => Effect.gen(function*($) { const schedule = Schedule.linear("100 millis").pipe(Schedule.compose(Schedule.elapsed)) const result = yield* $(runCollect(schedule, Array.makeBy(5, constVoid))) const expected = [0, 100, 300, 600, 1000].map(Duration.millis) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), expected) + deepStrictEqual(Chunk.toReadonlyArray(result), expected) })) it.effect("spaced delay", () => Effect.gen(function*($) { const schedule = Schedule.spaced("100 millis").pipe(Schedule.compose(Schedule.elapsed)) const result = yield* $(runCollect(schedule, Array.makeBy(5, constVoid))) const expected = [0, 100, 200, 300, 400].map(Duration.millis) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), expected) + deepStrictEqual(Chunk.toReadonlyArray(result), expected) })) it.effect("fixed delay", () => Effect.gen(function*($) { const schedule = Schedule.fixed("100 millis").pipe(Schedule.compose(Schedule.elapsed)) const result = yield* $(runCollect(schedule, Array.makeBy(5, constVoid))) const expected = [0, 100, 200, 300, 400].map(Duration.millis) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), expected) + deepStrictEqual(Chunk.toReadonlyArray(result), expected) })) it.effect("fixed delay with zero delay", () => Effect.gen(function*($) { const schedule = Schedule.fixed(Duration.zero).pipe(Schedule.compose(Schedule.elapsed)) const result = yield* $(runCollect(schedule, Array.makeBy(5, constVoid))) const expected = Array.makeBy(5, () => Duration.zero) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), expected) + deepStrictEqual(Chunk.toReadonlyArray(result), expected) })) it.effect("windowed", () => Effect.gen(function*($) { const schedule = Schedule.windowed("100 millis").pipe(Schedule.compose(Schedule.elapsed)) const result = yield* $(runCollect(schedule, Array.makeBy(5, constVoid))) const expected = [0, 100, 200, 300, 400].map(Duration.millis) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), expected) + deepStrictEqual(Chunk.toReadonlyArray(result), expected) })) it.effect("modified linear delay", () => Effect.gen(function*($) { @@ -527,21 +530,21 @@ describe("Schedule", () => { ) const result = yield* $(runCollect(schedule, Array.makeBy(5, constVoid))) const expected = [0, 200, 600, 1200, 2000].map(Duration.millis) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), expected) + deepStrictEqual(Chunk.toReadonlyArray(result), expected) })) it.effect("exponential delay with default factor", () => Effect.gen(function*($) { const schedule = Schedule.exponential("100 millis").pipe(Schedule.compose(Schedule.elapsed)) const result = yield* $(runCollect(schedule, Array.makeBy(5, constVoid))) const expected = [0, 100, 300, 700, 1500].map(Duration.millis) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), expected) + deepStrictEqual(Chunk.toReadonlyArray(result), expected) })) it.effect("exponential delay with other factor", () => Effect.gen(function*($) { const schedule = Schedule.exponential("100 millis", 3).pipe(Schedule.compose(Schedule.elapsed)) const result = yield* $(runCollect(schedule, Array.makeBy(5, constVoid))) const expected = [0, 100, 400, 1300, 4000].map(Duration.millis) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), expected) + deepStrictEqual(Chunk.toReadonlyArray(result), expected) })) it.effect("fromDelays", () => Effect.gen(function*($) { @@ -554,7 +557,7 @@ describe("Schedule", () => { const schedule = delays.pipe(Schedule.compose(Schedule.elapsed)) const result = yield* $(runCollect(schedule, Array.makeBy(5, constVoid))) const expected = [0, 4, 11, 23, 42].map(Duration.seconds) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), expected) + deepStrictEqual(Chunk.toReadonlyArray(result), expected) })) it.effect("retry a failed action 2 times and call `ensuring` should run the specified finalizer as soon as the schedule is complete", () => Effect.gen(function*($) { @@ -567,8 +570,8 @@ describe("Schedule", () => { ) ) const finalizerValue = yield* $(Deferred.poll(deferred)) - assert.isTrue(Option.isNone(value)) - assert.isTrue(Option.isSome(finalizerValue)) + assertTrue(Option.isNone(value)) + assertTrue(Option.isSome(finalizerValue)) })) }) describe("cron-like scheduling - repeats at point of time (minute of hour, day of week, ...)", () => { @@ -592,7 +595,7 @@ describe("Schedule", () => { "Mon Jan 01 2024 00:06:00", "Mon Jan 01 2024 00:08:00" ] - assert.deepStrictEqual(result, expected) + deepStrictEqual(result, expected) })) it.effect("recur at time matching cron expression", () => Effect.gen(function*($) { @@ -617,7 +620,7 @@ describe("Schedule", () => { "Wed Jan 17 2024 04:30:00", "Wed Jan 24 2024 04:30:00" ] - assert.deepStrictEqual(result, expected) + deepStrictEqual(result, expected) })) it.effect("recur at time matching cron expression (second granularity)", () => Effect.gen(function*($) { @@ -645,7 +648,7 @@ describe("Schedule", () => { "Mon Jan 01 2024 00:00:27", "Mon Jan 01 2024 00:00:30" ] - assert.deepStrictEqual(result, expected) + deepStrictEqual(result, expected) })) it.effect("recur at 01 second of each minute", () => Effect.gen(function*($) { @@ -665,7 +668,7 @@ describe("Schedule", () => { const expected = expectedDate.getTime() const afterTimeExpected = new Date(expectedDate).setMinutes(expectedDate.getMinutes() + 1) const expectedOutput = Chunk.make(expected, afterTimeExpected, expected, afterTimeExpected) - assert.deepStrictEqual(result, expectedOutput) + deepStrictEqual(result, expectedOutput) })) it.effect("recur at 01 minute of each hour", () => Effect.gen(function*($) { @@ -684,7 +687,7 @@ describe("Schedule", () => { const expected = new Date(new Date(originOffset).setMinutes(1)) const afterTimeExpected = new Date(expected).setHours(expected.getHours() + 1) const expectedOutput = Chunk.make(expected.getTime(), afterTimeExpected, expected.getTime(), afterTimeExpected) - assert.deepStrictEqual(result, expectedOutput) + deepStrictEqual(result, expectedOutput) })) it.effect("recur at 01 hour of each day", () => Effect.gen(function*($) { @@ -704,7 +707,7 @@ describe("Schedule", () => { const expected = expectedDate.getTime() const afterTimeExpected = new Date(expectedDate).setDate(expectedDate.getDate() + 1) const expectedOutput = Chunk.make(expected, afterTimeExpected, expected, afterTimeExpected) - assert.deepStrictEqual(result, expectedOutput) + deepStrictEqual(result, expectedOutput) })) it.effect("recur at Tuesday of each week", () => Effect.gen(function*($) { @@ -732,7 +735,7 @@ describe("Schedule", () => { expectedTuesday.getTime(), nextTuesday ) - assert.deepStrictEqual(result, expectedOutput) + deepStrictEqual(result, expectedOutput) })) it.effect("recur in the 2nd day of each month", () => Effect.gen(function*($) { @@ -753,7 +756,7 @@ describe("Schedule", () => { new Date(expectedBefore).getMonth() + 1 ) const expected = Chunk.make(expectedFirstInTime.getTime(), expectedSecondInTime, expectedBefore, expectedAfter) - assert.deepStrictEqual(result, expected) + deepStrictEqual(result, expected) })) it.effect("recur only in months containing valid number of days", () => Effect.gen(function*($) { @@ -764,7 +767,7 @@ describe("Schedule", () => { Effect.map((output) => output[0].pipe(Chunk.map((tuple) => tuple[0]))) ) const expected = Chunk.make(new Date(originOffset).setMonth(2, 30)) - assert.deepStrictEqual(result, expected) + deepStrictEqual(result, expected) })) it.effect("union with cron like schedules", () => Effect.gen(function*($) { @@ -780,7 +783,7 @@ describe("Schedule", () => { yield* $(TestClock.adjust("2 minutes")) const result = yield* $(Ref.get(ref)) const expected = [5, 25, 30, 50, 70, 90, 110] - assert.deepStrictEqual(result, expected) + deepStrictEqual(result, expected) })) it.effect("throw IllegalArgumentException on invalid `second` argument of `secondOfMinute`", () => Effect.gen(function*($) { @@ -789,7 +792,7 @@ describe("Schedule", () => { const exception = new Cause.IllegalArgumentException( "Invalid argument in: secondOfMinute(60). Must be in range 0...59" ) - assert.deepStrictEqual(exit, Exit.die(exception)) + deepStrictEqual(exit, Exit.die(exception)) })) it.effect("throw IllegalArgumentException on invalid `minute` argument of `minuteOfHour`", () => Effect.gen(function*($) { @@ -798,7 +801,7 @@ describe("Schedule", () => { const exception = new Cause.IllegalArgumentException( "Invalid argument in: minuteOfHour(60). Must be in range 0...59" ) - assert.deepStrictEqual(exit, Exit.die(exception)) + deepStrictEqual(exit, Exit.die(exception)) })) it.effect("throw IllegalArgumentException on invalid `hour` argument of `hourOfDay`", () => Effect.gen(function*($) { @@ -807,7 +810,7 @@ describe("Schedule", () => { const exception = new Cause.IllegalArgumentException( "Invalid argument in: hourOfDay(24). Must be in range 0...23" ) - assert.deepStrictEqual(exit, Exit.die(exception)) + deepStrictEqual(exit, Exit.die(exception)) })) it.effect("throw IllegalArgumentException on invalid `day` argument of `dayOfWeek`", () => Effect.gen(function*($) { @@ -816,7 +819,7 @@ describe("Schedule", () => { const exception = new Cause.IllegalArgumentException( "Invalid argument in: dayOfWeek(8). Must be in range 1 (Monday)...7 (Sunday)" ) - assert.deepStrictEqual(exit, Exit.die(exception)) + deepStrictEqual(exit, Exit.die(exception)) })) it.effect("throw IllegalArgumentException on invalid `day` argument of `dayOfMonth`", () => Effect.gen(function*($) { @@ -825,7 +828,7 @@ describe("Schedule", () => { const exception = new Cause.IllegalArgumentException( "Invalid argument in: dayOfMonth(32). Must be in range 1...31" ) - assert.deepStrictEqual(exit, Exit.die(exception)) + deepStrictEqual(exit, Exit.die(exception)) })) }) }) @@ -999,7 +1002,7 @@ const runManuallyLoop = ( schedule, state, rest, - acc.pipe(Chunk.prepend([Intervals.start(decision.intervals), out] as const)) + acc.pipe(Chunk.prepend([ScheduleIntervals.start(decision.intervals), out] as const)) ) }) ) diff --git a/packages/effect/test/Schema/Arbitrary/Arbitrary.test.ts b/packages/effect/test/Schema/Arbitrary/Arbitrary.test.ts index 67714bbe04d..b9946fdfc4c 100644 --- a/packages/effect/test/Schema/Arbitrary/Arbitrary.test.ts +++ b/packages/effect/test/Schema/Arbitrary/Arbitrary.test.ts @@ -1,10 +1,7 @@ -import { Schema as S, SchemaAST as AST } from "effect" -import * as Arbitrary from "effect/Arbitrary" -import * as fc from "effect/FastCheck" -import * as Order from "effect/Order" -import { isUnknown } from "effect/Predicate" +import { Arbitrary, FastCheck as fc, Order, Predicate, Schema as S, SchemaAST as AST } from "effect" import * as Util from "effect/test/Schema/TestUtils" -import { assert, describe, expect, it } from "vitest" +import { assertTrue, deepStrictEqual, fail, strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" const expectConstraints = ( schema: S.Schema, @@ -25,28 +22,29 @@ const expectConstraints = ( case "NumberConstraints": case "BigIntConstraints": case "DateConstraints": - return expect(op.config).toEqual(constraints) + return deepStrictEqual(op.config, constraints) case "ArrayConstraints": { const { ast: _ast, ...rest } = op.config - return expect(rest).toEqual(constraints) + return deepStrictEqual(rest, constraints) } } } case "Succeed": // eslint-disable-next-line no-console console.log(op) - assert.fail(`expected a Deferred, got a Succeed`) + fail(`expected a Deferred, got a Succeed`) } } else { - assert.fail(`expected a Refinement, got ${ast._tag}`) + fail(`expected a Refinement, got ${ast._tag}`) } } describe("Arbitrary", () => { describe("Unsupported schemas", () => { it("should throw on declarations without annotations", () => { - const schema = S.declare(isUnknown) - expect(() => Arbitrary.makeLazy(schema)).toThrow( + const schema = S.declare(Predicate.isUnknown) + throws( + () => Arbitrary.makeLazy(schema), new Error(`Missing annotation details: Generating an Arbitrary for this schema requires an "arbitrary" annotation schema (Declaration): `) @@ -54,13 +52,15 @@ schema (Declaration): `) }) it("the errors should disply a path", () => { - expect(() => Arbitrary.makeLazy(S.Tuple(S.declare(isUnknown)))).toThrow( + throws( + () => Arbitrary.makeLazy(S.Tuple(S.declare(Predicate.isUnknown))), new Error(`Missing annotation at path: [0] details: Generating an Arbitrary for this schema requires an "arbitrary" annotation schema (Declaration): `) ) - expect(() => Arbitrary.makeLazy(S.Struct({ a: S.declare(isUnknown) }))).toThrow( + throws( + () => Arbitrary.makeLazy(S.Struct({ a: S.declare(Predicate.isUnknown) })), new Error(`Missing annotation at path: ["a"] details: Generating an Arbitrary for this schema requires an "arbitrary" annotation @@ -69,7 +69,8 @@ schema (Declaration): `) }) it("Never", () => { - expect(() => Arbitrary.makeLazy(S.Never)).toThrow( + throws( + () => Arbitrary.makeLazy(S.Never), new Error(`Missing annotation details: Generating an Arbitrary for this schema requires an "arbitrary" annotation schema (NeverKeyword): never`) @@ -211,7 +212,8 @@ schema (NeverKeyword): never`) it("empty enums should throw", () => { enum Fruits {} const schema = S.Enums(Fruits) - expect(() => Arbitrary.makeLazy(schema)(fc)).toThrow( + throws( + () => Arbitrary.makeLazy(schema)(fc), new Error(`Empty Enums schema details: Generating an Arbitrary for this schema requires at least one enum`) ) @@ -833,7 +835,7 @@ details: Generating an Arbitrary for this schema requires at least one enum`) const expectHook = (source: S.Schema) => { const schema = source.annotations({ arbitrary: () => (fc) => fc.constant("custom arbitrary") as any }) const arb = Arbitrary.make(schema) - expect(fc.sample(arb, 1)[0]).toEqual("custom arbitrary") + strictEqual(fc.sample(arb, 1)[0], "custom arbitrary" as any) } it("Void", () => { @@ -932,8 +934,8 @@ details: Generating an Arbitrary for this schema requires at least one enum`) it("should provide the `from` Arbitrary", () => { const schema = S.String.pipe(S.filter((s) => s.length > 2, { arbitrary: (from, ctx) => (fc) => { - assert.isFunction(from) - assert.isObject(ctx) + assertTrue(Predicate.isFunction(from)) + assertTrue(Predicate.isObject(ctx)) return from(fc).filter((s) => s.length > 2) } })) diff --git a/packages/effect/test/Schema/JSONSchema.test.ts b/packages/effect/test/Schema/JSONSchema.test.ts index c588b76e502..ebbf7bba0f4 100644 --- a/packages/effect/test/Schema/JSONSchema.test.ts +++ b/packages/effect/test/Schema/JSONSchema.test.ts @@ -3,8 +3,9 @@ import * as A from "effect/Arbitrary" import * as JSONSchema from "effect/JSONSchema" import * as Schema from "effect/Schema" import * as AST from "effect/SchemaAST" +import { assertFalse, assertTrue, deepStrictEqual, throws } from "effect/test/util" import * as fc from "fast-check" -import { describe, expect, it } from "vitest" +import { describe, it } from "vitest" type Root = JSONSchema.JsonSchema7Root @@ -36,10 +37,10 @@ const expectJSONSchema = ( expectedJsonSchema: object ) => { const jsonSchema = JSONSchema.make(schema) - expect(jsonSchema).toStrictEqual({ + deepStrictEqual(jsonSchema, { "$schema": "http://json-schema.org/draft-07/schema#", ...expectedJsonSchema - }) + } as any) return jsonSchema } @@ -53,8 +54,8 @@ const expectJSONSchema2019 = ( definitions, target: "jsonSchema2019-09" }) - expect(jsonSchema).toStrictEqual(expectedJsonSchema) - expect(definitions).toStrictEqual(expectedDefinitions) + deepStrictEqual(jsonSchema, expectedJsonSchema) + deepStrictEqual(definitions, expectedDefinitions) return jsonSchema } @@ -68,8 +69,8 @@ const expectJSONSchemaOpenApi31 = ( definitions, target: "openApi3.1" }) - expect(jsonSchema).toStrictEqual(expectedJsonSchema) - expect(definitions).toStrictEqual(expectedDefinitions) + deepStrictEqual(jsonSchema, expectedJsonSchema) + deepStrictEqual(definitions, expectedDefinitions) return jsonSchema } @@ -96,7 +97,7 @@ const expectJSONSchemaAnnotations = ( } const expectError = (schema: Schema.Schema, message: string) => { - expect(() => JSONSchema.make(schema)).toThrow(new Error(message)) + throws(() => JSONSchema.make(schema), new Error(message)) } // Using this instead of Schema.JsonNumber to avoid cluttering the output with unnecessary description and title @@ -110,10 +111,10 @@ describe("makeWithOptions", () => { definitions, definitionPath: "#/components/schemas/" }) - expect(jsonSchema).toStrictEqual({ + deepStrictEqual(jsonSchema, { "$ref": "#/components/schemas/08368672-2c02-4d6d-92b0-dd0019b33a7b" }) - expect(definitions).toStrictEqual({ + deepStrictEqual(definitions, { "08368672-2c02-4d6d-92b0-dd0019b33a7b": { "type": "string" } @@ -220,11 +221,11 @@ describe("makeWithOptions", () => { const jsonSchema = JSONSchema.fromAST(schema.ast, { definitions }) - expect(jsonSchema).toStrictEqual({ + deepStrictEqual(jsonSchema, { "type": "string", "contentMediaType": "application/json" }) - expect(definitions).toStrictEqual({}) + deepStrictEqual(definitions, {}) }) }) @@ -594,10 +595,10 @@ describe("makeWithOptions", () => { definitions, topLevelReferenceStrategy: "skip" }) - expect(jsonSchema).toStrictEqual({ + deepStrictEqual(jsonSchema, { "type": "string" }) - expect(definitions).toStrictEqual({}) + deepStrictEqual(definitions, {}) }) }) }) @@ -768,7 +769,7 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } expectJSONSchema(Schema.Never, jsonSchema) const validate = getAjvValidate(jsonSchema) - expect(validate(null)).toEqual(false) + assertFalse(validate(null)) }) it("Any", () => { @@ -798,12 +799,12 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` expectJSONSchemaAnnotations(Schema.Object, jsonSchema) const validate = getAjvValidate(jsonSchema) - expect(validate({})).toEqual(true) - expect(validate({ a: 1 })).toEqual(true) - expect(validate([])).toEqual(true) - expect(validate("a")).toEqual(false) - expect(validate(1)).toEqual(false) - expect(validate(true)).toEqual(false) + assertTrue(validate({})) + assertTrue(validate({ a: 1 })) + assertTrue(validate([])) + assertFalse(validate("a")) + assertFalse(validate(1)) + assertFalse(validate(true)) }) it("empty struct: Schema.Struct({})", () => { @@ -818,12 +819,12 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } expectJSONSchemaAnnotations(schema, jsonSchema) const validate = getAjvValidate(jsonSchema) - expect(validate({})).toEqual(true) - expect(validate({ a: 1 })).toEqual(true) - expect(validate([])).toEqual(true) - expect(validate(null)).toEqual(false) - expect(validate(1)).toEqual(false) - expect(validate(true)).toEqual(false) + assertTrue(validate({})) + assertTrue(validate({ a: 1 })) + assertTrue(validate([])) + assertFalse(validate(null)) + assertFalse(validate(1)) + assertFalse(validate(true)) }) it("Void", () => { @@ -874,10 +875,10 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } expectJSONSchemaAnnotations(schema, jsonSchema) const validate = getAjvValidate(jsonSchema) - expect(validate("a1")).toEqual(true) - expect(validate("a12")).toEqual(true) - expect(validate("a")).toEqual(false) - expect(validate("aa")).toEqual(false) + assertTrue(validate("a1")) + assertTrue(validate("a12")) + assertFalse(validate("a")) + assertFalse(validate("aa")) }) describe("Literal", () => { @@ -947,7 +948,7 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` "not": {} }) const validate = getAjvValidate(jsonSchema) - expect(validate(1)).toEqual(false) + assertFalse(validate(1)) }) it("single enum", () => { @@ -1628,8 +1629,8 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } expectJSONSchemaAnnotations(schema, jsonSchema) const validate = getAjvValidate(jsonSchema) - expect(validate([])).toEqual(true) - expect(validate([1])).toEqual(false) + assertTrue(validate([])) + assertFalse(validate([1])) }) it("element", () => { @@ -1644,10 +1645,10 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } expectJSONSchemaAnnotations(schema, jsonSchema) const validate = getAjvValidate(jsonSchema) - expect(validate([1])).toEqual(true) - expect(validate([])).toEqual(false) - expect(validate(["a"])).toEqual(false) - expect(validate([1, "a"])).toEqual(false) + assertTrue(validate([1])) + assertFalse(validate([])) + assertFalse(validate(["a"])) + assertFalse(validate([1, "a"])) }) it("element + inner annotations", () => { @@ -1696,10 +1697,10 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } expectJSONSchemaAnnotations(schema, jsonSchema) const validate = getAjvValidate(jsonSchema) - expect(validate([])).toEqual(true) - expect(validate([1])).toEqual(true) - expect(validate(["a"])).toEqual(false) - expect(validate([1, 2])).toEqual(false) + assertTrue(validate([])) + assertTrue(validate([1])) + assertFalse(validate(["a"])) + assertFalse(validate([1, 2])) }) it("optionalElement + inner annotations", () => { @@ -1762,11 +1763,11 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } expectJSONSchemaAnnotations(schema, jsonSchema) const validate = getAjvValidate(jsonSchema) - expect(validate(["a"])).toEqual(true) - expect(validate(["a", 1])).toEqual(true) - expect(validate([])).toEqual(false) - expect(validate([1])).toEqual(false) - expect(validate([1, 2])).toEqual(false) + assertTrue(validate(["a"])) + assertTrue(validate(["a", 1])) + assertFalse(validate([])) + assertFalse(validate([1])) + assertFalse(validate([1, 2])) }) it("rest", () => { @@ -1779,12 +1780,12 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } expectJSONSchemaAnnotations(schema, jsonSchema) const validate = getAjvValidate(jsonSchema) - expect(validate([])).toEqual(true) - expect(validate([1])).toEqual(true) - expect(validate([1, 2])).toEqual(true) - expect(validate([1, 2, 3])).toEqual(true) - expect(validate(["a"])).toEqual(false) - expect(validate([1, 2, 3, "a"])).toEqual(false) + assertTrue(validate([])) + assertTrue(validate([1])) + assertTrue(validate([1, 2])) + assertTrue(validate([1, 2, 3])) + assertFalse(validate(["a"])) + assertFalse(validate([1, 2, 3, "a"])) }) it("rest + inner annotations", () => { @@ -1817,12 +1818,12 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } expectJSONSchemaAnnotations(schema, jsonSchema) const validate = getAjvValidate(jsonSchema) - expect(validate([])).toEqual(true) - expect(validate(["a"])).toEqual(true) - expect(validate(["a", 1])).toEqual(true) - expect(validate([1])).toEqual(false) - expect(validate([1, 2])).toEqual(false) - expect(validate(["a", "b", 1])).toEqual(false) + assertTrue(validate([])) + assertTrue(validate(["a"])) + assertTrue(validate(["a", 1])) + assertFalse(validate([1])) + assertFalse(validate([1, 2])) + assertFalse(validate(["a", "b", 1])) }) it("optionalElement + rest + outer annotations should override inner annotations", () => { @@ -1861,13 +1862,13 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } expectJSONSchemaAnnotations(schema, jsonSchema) const validate = getAjvValidate(jsonSchema) - expect(validate(["a"])).toEqual(true) - expect(validate(["a", 1])).toEqual(true) - expect(validate(["a", 1, 2])).toEqual(true) - expect(validate(["a", 1, 2, 3])).toEqual(true) - expect(validate([])).toEqual(false) - expect(validate([1])).toEqual(false) - expect(validate(["a", "b"])).toEqual(false) + assertTrue(validate(["a"])) + assertTrue(validate(["a", 1])) + assertTrue(validate(["a", 1, 2])) + assertTrue(validate(["a", 1, 2, 3])) + assertFalse(validate([])) + assertFalse(validate([1])) + assertFalse(validate(["a", "b"])) }) it("NonEmptyArray", () => { @@ -1899,11 +1900,11 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } expectJSONSchemaAnnotations(schema, jsonSchema) const validate = getAjvValidate(jsonSchema) - expect(validate({ a: "a", b: 1 })).toEqual(true) - expect(validate({})).toEqual(false) - expect(validate({ a: "a" })).toEqual(false) - expect(validate({ b: 1 })).toEqual(false) - expect(validate({ a: "a", b: 1, c: true })).toEqual(false) + assertTrue(validate({ a: "a", b: 1 })) + assertFalse(validate({})) + assertFalse(validate({ a: "a" })) + assertFalse(validate({ b: 1 })) + assertFalse(validate({ a: "a", b: 1, c: true })) }) it("field + inner annotation", () => { @@ -1968,12 +1969,12 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } expectJSONSchemaAnnotations(schema, jsonSchema) const validate = getAjvValidate(jsonSchema) - expect(validate({ a: "a" })).toEqual(true) - expect(validate({ a: "a", b: "b" })).toEqual(true) - expect(validate({})).toEqual(false) - expect(validate({ b: "b" })).toEqual(false) - expect(validate({ a: 1 })).toEqual(false) - expect(validate({ a: "a", b: 1 })).toEqual(false) + assertTrue(validate({ a: "a" })) + assertTrue(validate({ a: "a", b: "b" })) + assertFalse(validate({})) + assertFalse(validate({ b: "b" })) + assertFalse(validate({ a: 1 })) + assertFalse(validate({ a: "a", b: 1 })) }) it("exact optional field", () => { @@ -1996,11 +1997,11 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } expectJSONSchemaAnnotations(schema, jsonSchema) const validate = getAjvValidate(jsonSchema) - expect(validate({ a: "a", b: 1 })).toEqual(true) - expect(validate({ a: "a" })).toEqual(true) - expect(validate({})).toEqual(false) - expect(validate({ b: 1 })).toEqual(false) - expect(validate({ a: "a", b: 1, c: true })).toEqual(false) + assertTrue(validate({ a: "a", b: 1 })) + assertTrue(validate({ a: "a" })) + assertFalse(validate({})) + assertFalse(validate({ b: 1 })) + assertFalse(validate({ a: "a", b: 1, c: true })) }) it("exact optional field + inner annotation", () => { @@ -2119,13 +2120,13 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } expectJSONSchemaAnnotations(schema, jsonSchema) const validate = getAjvValidate(jsonSchema) - expect(validate({})).toEqual(true) - expect(validate({ "-": 1 })).toEqual(true) - expect(validate({ "a-": 1 })).toEqual(true) - expect(validate({ "-b": 1 })).toEqual(true) - expect(validate({ "a-b": 1 })).toEqual(true) - expect(validate({ "": 1 })).toEqual(false) - expect(validate({ "-": "a" })).toEqual(false) + assertTrue(validate({})) + assertTrue(validate({ "-": 1 })) + assertTrue(validate({ "a-": 1 })) + assertTrue(validate({ "-b": 1 })) + assertTrue(validate({ "a-b": 1 })) + assertFalse(validate({ "": 1 })) + assertFalse(validate({ "-": "a" })) }) it("Record(pattern, number)", () => { @@ -2148,15 +2149,15 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } } expectJSONSchemaAnnotations(schema, jsonSchema) - expect(jsonSchema).toStrictEqual(jsonSchema) + deepStrictEqual(jsonSchema, jsonSchema) const validate = getAjvValidate(jsonSchema) - expect(validate({})).toEqual(true) - expect(validate({ "-": 1 })).toEqual(true) - expect(validate({ "a-": 1 })).toEqual(true) - expect(validate({ "-b": 1 })).toEqual(true) - expect(validate({ "a-b": 1 })).toEqual(true) - expect(validate({ "": 1 })).toEqual(false) - expect(validate({ "-": "a" })).toEqual(false) + assertTrue(validate({})) + assertTrue(validate({ "-": 1 })) + assertTrue(validate({ "a-": 1 })) + assertTrue(validate({ "-b": 1 })) + assertTrue(validate({ "a-b": 1 })) + assertFalse(validate({ "": 1 })) + assertFalse(validate({ "-": "a" })) }) }) @@ -2822,15 +2823,15 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } expectJSONSchemaProperty(schema, jsonSchema) const validate = getAjvValidate(jsonSchema) - expect(validate({ a: "a1", as: [] })).toEqual(true) - expect(validate({ a: "a1", as: [{ a: "a2", as: [] }] })).toEqual(true) - expect(validate({ a: "a1", as: [{ a: "a2", as: [] }, { a: "a3", as: [] }] })).toEqual(true) - expect( + assertTrue(validate({ a: "a1", as: [] })) + assertTrue(validate({ a: "a1", as: [{ a: "a2", as: [] }] })) + assertTrue(validate({ a: "a1", as: [{ a: "a2", as: [] }, { a: "a3", as: [] }] })) + assertTrue( validate({ a: "a1", as: [{ a: "a2", as: [] }, { a: "a3", as: [{ a: "a4", as: [] }] }] }) - ).toEqual(true) - expect( + ) + assertFalse( validate({ a: "a1", as: [{ a: "a2", as: [] }, { a: "a3", as: [{ a: "a4", as: [1] }] }] }) - ).toEqual(false) + ) }) it("should support inner suspended schemas with inner identifier annotation", () => { @@ -2888,15 +2889,15 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } expectJSONSchemaProperty(schema, jsonSchema) const validate = getAjvValidate(jsonSchema) - expect(validate({ a: "a1", as: [] })).toEqual(true) - expect(validate({ a: "a1", as: [{ a: "a2", as: [] }] })).toEqual(true) - expect(validate({ a: "a1", as: [{ a: "a2", as: [] }, { a: "a3", as: [] }] })).toEqual(true) - expect( + assertTrue(validate({ a: "a1", as: [] })) + assertTrue(validate({ a: "a1", as: [{ a: "a2", as: [] }] })) + assertTrue(validate({ a: "a1", as: [{ a: "a2", as: [] }, { a: "a3", as: [] }] })) + assertTrue( validate({ a: "a1", as: [{ a: "a2", as: [] }, { a: "a3", as: [{ a: "a4", as: [] }] }] }) - ).toEqual(true) - expect( + ) + assertFalse( validate({ a: "a1", as: [{ a: "a2", as: [] }, { a: "a3", as: [{ a: "a4", as: [1] }] }] }) - ).toEqual(false) + ) }) it("should support inner suspended schemas with outer identifier annotation", () => { @@ -2934,22 +2935,22 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } expectJSONSchemaProperty(schema, jsonSchema) const validate = getAjvValidate(jsonSchema) - expect(validate({ name: "a1", categories: [] })).toEqual(true) - expect(validate({ name: "a1", categories: [{ name: "a2", categories: [] }] })).toEqual(true) - expect(validate({ name: "a1", categories: [{ name: "a2", categories: [] }, { name: "a3", categories: [] }] })) - .toEqual(true) - expect( + assertTrue(validate({ name: "a1", categories: [] })) + assertTrue(validate({ name: "a1", categories: [{ name: "a2", categories: [] }] })) + assertTrue(validate({ name: "a1", categories: [{ name: "a2", categories: [] }, { name: "a3", categories: [] }] })) + + assertTrue( validate({ name: "a1", categories: [{ name: "a2", categories: [] }, { name: "a3", categories: [{ name: "a4", categories: [] }] }] }) - ).toEqual(true) - expect( + ) + assertFalse( validate({ name: "a1", categories: [{ name: "a2", categories: [] }, { name: "a3", categories: [{ name: "a4", categories: [1] }] }] }) - ).toEqual(false) + ) }) it("should support mutually suspended schemas", () => { @@ -3040,7 +3041,7 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } expectJSONSchemaProperty(Operation, jsonSchema, { numRuns: 5 }) const validate = getAjvValidate(jsonSchema) - expect(validate({ + assertTrue(validate({ type: "operation", operator: "+", left: { @@ -3062,7 +3063,7 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema` } } } - })).toEqual(true) + })) }) }) diff --git a/packages/effect/test/Schema/ParseResult.test.ts b/packages/effect/test/Schema/ParseResult.test.ts index 1ec10bbe73e..5e70fa092d7 100644 --- a/packages/effect/test/Schema/ParseResult.test.ts +++ b/packages/effect/test/Schema/ParseResult.test.ts @@ -1,23 +1,33 @@ -import { Effect, Either, Exit } from "effect" -import * as P from "effect/ParseResult" +import { Cause, Effect, Either, ParseResult } from "effect" import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" +import { + assertFailure, + assertLeft, + assertSuccess, + assertTrue, + deepStrictEqual, + strictEqual, + throws +} from "effect/test/util" import { inspect } from "node:util" -import { assert, describe, expect, it } from "vitest" +import { describe, it } from "vitest" + +const asEffect = (either: Either.Either): Effect.Effect => either const expectGetRefinementExpected = (schema: S.Schema.Any, expected: string) => { if (AST.isRefinement(schema.ast)) { - expect(P.getRefinementExpected(schema.ast)).toBe(expected) + strictEqual(ParseResult.getRefinementExpected(schema.ast), expected) } else { // eslint-disable-next-line no-console console.log(schema.ast) - assert.fail(`expected a Refinement`) + throw new Error(`expected a Refinement`) } } describe("ParseResult", () => { - const typeParseError1 = P.parseError(new P.Type(S.String.ast, null)) - const typeParseError2 = P.parseError(new P.Type(S.Number.ast, null)) + const typeParseError1 = ParseResult.parseError(new ParseResult.Type(S.String.ast, null)) + const typeParseError2 = ParseResult.parseError(new ParseResult.Type(S.Number.ast, null)) it("getRefinementExpected", () => { expectGetRefinementExpected(S.Number.pipe(S.filter(() => true)), "{ number | filter }") @@ -29,147 +39,140 @@ describe("ParseResult", () => { describe("ParseError", () => { it("toString()", () => { const schema = S.Struct({ a: S.String }) - expect(S.decodeUnknownEither(schema)({}).pipe(Either.mapLeft((e) => e.toString()))).toStrictEqual( - Either.left(`{ readonly a: string } + assertLeft( + S.decodeUnknownEither(schema)({}).pipe(Either.mapLeft((e) => e.toString())), + `{ readonly a: string } └─ ["a"] - └─ is missing`) + └─ is missing` ) }) it("toJSON()", () => { const schema = S.Struct({ a: S.String }) - expect(S.decodeUnknownEither(schema)({}).pipe(Either.mapLeft((e) => (e as any).toJSON()))) - .toStrictEqual( - Either.left({ - _id: "ParseError", - message: `{ readonly a: string } + assertLeft(S.decodeUnknownEither(schema)({}).pipe(Either.mapLeft((e) => (e as any).toJSON())), { + _id: "ParseError", + message: `{ readonly a: string } └─ ["a"] └─ is missing` - }) - ) + }) }) it("[NodeInspectSymbol]", () => { const schema = S.Struct({ a: S.String }) - expect(S.decodeUnknownEither(schema)({}).pipe(Either.mapLeft((e) => inspect(e)))) - .toStrictEqual( - Either.left(inspect({ - _id: "ParseError", - message: `{ readonly a: string } + assertLeft( + S.decodeUnknownEither(schema)({}).pipe(Either.mapLeft((e) => inspect(e))), + inspect({ + _id: "ParseError", + message: `{ readonly a: string } └─ ["a"] └─ is missing` - })) - ) + }) + ) }) it("Error.stack", () => { - expect( - P.parseError(new P.Type(S.String.ast, 1)).stack?.startsWith( + assertTrue( + ParseResult.parseError(new ParseResult.Type(S.String.ast, 1)).stack?.startsWith( `ParseError: Expected string, actual 1` ) ) - .toEqual(true) }) it("Effect.catchTag can be used to catch ParseError", () => { const program = Effect.fail(typeParseError1).pipe( Effect.catchTag("ParseError", () => Effect.succeed(1)) ) - expect(Effect.runSync(program)).toBe(1) + strictEqual(Effect.runSync(program), 1) }) }) it("map (Either)", () => { - expect(P.map(Either.right(1), (n) => n + 1)).toStrictEqual(Either.right(2)) - expect(P.map(Either.left(typeParseError1), (n) => n + 1)).toStrictEqual( - Either.left(typeParseError1) - ) + deepStrictEqual(ParseResult.map(Either.right(1), (n) => n + 1), asEffect(Either.right(2))) + deepStrictEqual(ParseResult.map(Either.left(typeParseError1), (n) => n + 1), asEffect(Either.left(typeParseError1))) // pipeable - expect(Either.right(1).pipe(P.map((n) => n + 1))).toStrictEqual(Either.right(2)) + deepStrictEqual(Either.right(1).pipe(ParseResult.map((n) => n + 1)), Either.right(2)) }) it("map (Effect)", () => { - expect(Effect.runSyncExit(P.map(Effect.succeed(1), (n) => n + 1))).toStrictEqual( - Exit.succeed(2) + assertSuccess(Effect.runSyncExit(ParseResult.map(Effect.succeed(1), (n) => n + 1)), 2) + assertFailure( + Effect.runSyncExit(ParseResult.map(Effect.fail(typeParseError1), (n) => n + 1)), + Cause.fail(typeParseError1) ) - expect(Effect.runSyncExit(P.map(Effect.fail(typeParseError1), (n) => n + 1))) - .toStrictEqual(Exit.fail(typeParseError1)) }) it("mapLeft (Either)", () => { - expect(P.mapError(Either.right(1), () => typeParseError2)).toStrictEqual( - Either.right(1) + deepStrictEqual(ParseResult.mapError(Either.right(1), () => typeParseError2), asEffect(Either.right(1))) + deepStrictEqual( + ParseResult.mapError(Either.left(typeParseError1), () => typeParseError2), + asEffect(Either.left(typeParseError2)) ) - expect(P.mapError(Either.left(typeParseError1), () => typeParseError2)) - .toStrictEqual(Either.left(typeParseError2)) // pipeable - expect(Either.right(1).pipe(P.mapError(() => typeParseError2))).toStrictEqual( - Either.right(1) - ) + deepStrictEqual(Either.right(1).pipe(ParseResult.mapError(() => typeParseError2)), Either.right(1)) }) it("mapLeft (Effect)", () => { - expect(Effect.runSyncExit(P.mapError(Effect.succeed(1), () => typeParseError2))) - .toStrictEqual(Exit.succeed(1)) - expect( + assertSuccess(Effect.runSyncExit(ParseResult.mapError(Effect.succeed(1), () => typeParseError2)), 1) + assertFailure( Effect.runSyncExit( - P.mapError(Effect.fail(typeParseError1), () => typeParseError2) - ) - ).toStrictEqual(Exit.fail(typeParseError2)) + ParseResult.mapError(Effect.fail(typeParseError1), () => typeParseError2) + ), + Cause.fail(typeParseError2) + ) }) it("mapBoth (Either)", () => { - expect(P.mapBoth(Either.right(1), { onFailure: () => typeParseError2, onSuccess: (n) => n + 1 })) - .toStrictEqual(Either.right(2)) - expect( - P.mapBoth(Either.left(typeParseError1), { + deepStrictEqual( + ParseResult.mapBoth(Either.right(1), { onFailure: () => typeParseError2, onSuccess: (n) => n + 1 }), + asEffect(Either.right(2)) + ) + deepStrictEqual( + ParseResult.mapBoth(Either.left(typeParseError1), { onFailure: () => typeParseError2, onSuccess: (n) => n + 1 - }) - ).toStrictEqual(Either.left(typeParseError2)) + }), + asEffect(Either.left(typeParseError2)) + ) // pipeable - expect(Either.right(1).pipe(P.mapBoth({ onFailure: () => typeParseError2, onSuccess: (n) => n + 1 }))) - .toStrictEqual(Either.right(2)) + deepStrictEqual( + Either.right(1).pipe(ParseResult.mapBoth({ onFailure: () => typeParseError2, onSuccess: (n) => n + 1 })), + Either.right(2) + ) }) it("mapBoth (Effect)", () => { - expect( + assertSuccess( Effect.runSyncExit( - P.mapBoth(Effect.succeed(1), { onFailure: () => typeParseError2, onSuccess: (n) => n + 1 }) - ) - ).toStrictEqual(Exit.succeed(2)) - expect( + ParseResult.mapBoth(Effect.succeed(1), { onFailure: () => typeParseError2, onSuccess: (n) => n + 1 }) + ), + 2 + ) + assertFailure( Effect.runSyncExit( - P.mapBoth(Effect.fail(typeParseError1), { + ParseResult.mapBoth(Effect.fail(typeParseError1), { onFailure: () => typeParseError2, onSuccess: (n) => n + 1 }) - ) - ).toStrictEqual(Exit.fail(typeParseError2)) + ), + Cause.fail(typeParseError2) + ) }) it("orElse (Either)", () => { - expect(P.orElse(Either.right(1), () => Either.right(2))).toStrictEqual( - Either.right(1) - ) - expect(P.orElse(Either.left(typeParseError1), () => Either.right(2))) - .toStrictEqual(Either.right(2)) + deepStrictEqual(ParseResult.orElse(Either.right(1), () => Either.right(2)), asEffect(Either.right(1))) + deepStrictEqual(ParseResult.orElse(Either.left(typeParseError1), () => Either.right(2)), asEffect(Either.right(2))) // pipeable - expect(Either.right(1).pipe(P.orElse(() => Either.right(2)))).toStrictEqual( - Either.right(1) - ) + deepStrictEqual(Either.right(1).pipe(ParseResult.orElse(() => Either.right(2))), Either.right(1)) }) it("orElse (Effect)", () => { - expect(Effect.runSyncExit(P.orElse(Effect.succeed(1), () => Either.right(2)))) - .toStrictEqual( - Exit.succeed(1) - ) - expect( + assertSuccess(Effect.runSyncExit(ParseResult.orElse(Effect.succeed(1), () => Either.right(2))), 1) + assertSuccess( Effect.runSyncExit( - P.orElse(Effect.fail(typeParseError1), () => Either.right(2)) - ) - ).toStrictEqual(Exit.succeed(2)) + ParseResult.orElse(Effect.fail(typeParseError1), () => Either.right(2)) + ), + 2 + ) }) }) @@ -180,13 +183,13 @@ describe("ParseIssue.actual", () => { S.Boolean, { strict: true, - decode: (n, _, ast) => P.fail(new P.Type(ast, n)), - encode: (b, _, ast) => P.fail(new P.Type(ast, b)) + decode: (n, _, ast) => ParseResult.fail(new ParseResult.Type(ast, n)), + encode: (b, _, ast) => ParseResult.fail(new ParseResult.Type(ast, b)) } ))("1") if (Either.isRight(result)) throw new Error("Expected failure") - expect(result.left.issue.actual).toEqual("1") - expect((result.left.issue as P.Transformation).issue.actual).toEqual(1) + strictEqual(result.left.issue.actual, "1") + strictEqual((result.left.issue as ParseResult.Transformation).issue.actual, 1) }) it("transform encode", () => { @@ -195,114 +198,119 @@ describe("ParseIssue.actual", () => { S.NumberFromString, { strict: true, - decode: (n, _, ast) => P.fail(new P.Type(ast, n)), - encode: (b, _, ast) => P.fail(new P.Type(ast, b)) + decode: (n, _, ast) => ParseResult.fail(new ParseResult.Type(ast, n)), + encode: (b, _, ast) => ParseResult.fail(new ParseResult.Type(ast, b)) } ))(1) if (Either.isRight(result)) throw new Error("Expected failure") - expect(result.left.issue.actual).toEqual(1) - expect((result.left.issue as P.Transformation).issue.actual).toEqual("1") + strictEqual(result.left.issue.actual, 1) + strictEqual((result.left.issue as ParseResult.Transformation).issue.actual, "1") }) it("compose decode", () => { const result = S.decodeEither(S.compose(S.NumberFromString, S.negative()(S.Number)))("1") if (Either.isRight(result)) throw new Error("Expected failure") - expect(result.left.issue.actual).toEqual("1") - expect((result.left.issue as P.Transformation).issue.actual).toEqual(1) + strictEqual(result.left.issue.actual, "1") + strictEqual((result.left.issue as ParseResult.Transformation).issue.actual, 1) }) it("compose encode", () => { const result = S.encodeEither(S.compose(S.length(5)(S.String), S.NumberFromString))(1) if (Either.isRight(result)) throw new Error("Expected failure") - expect(result.left.issue.actual).toEqual(1) - expect((result.left.issue as P.Transformation).issue.actual).toEqual("1") + strictEqual(result.left.issue.actual, 1) + strictEqual((result.left.issue as ParseResult.Transformation).issue.actual, "1") }) it("decode", () => { - expect(Either.isEither(P.decode(S.String)("a"))) + assertTrue(Either.isEither(ParseResult.decode(S.String)("a"))) }) it("encode", () => { - expect(Either.isEither(P.encode(S.String)("a"))) + assertTrue(Either.isEither(ParseResult.encode(S.String)("a"))) }) it("mergeInternalOptions", () => { - expect(P.mergeInternalOptions(undefined, undefined)).toStrictEqual(undefined) - expect(P.mergeInternalOptions({}, undefined)).toStrictEqual({}) - expect(P.mergeInternalOptions(undefined, {})).toStrictEqual({}) - expect(P.mergeInternalOptions({ errors: undefined }, undefined)).toStrictEqual({ errors: undefined }) - expect(P.mergeInternalOptions(undefined, { errors: undefined })).toStrictEqual({ errors: undefined }) - expect(P.mergeInternalOptions({ errors: "all" }, { errors: "first" })).toStrictEqual({ + strictEqual(ParseResult.mergeInternalOptions(undefined, undefined), undefined) + deepStrictEqual(ParseResult.mergeInternalOptions({}, undefined), {}) + deepStrictEqual(ParseResult.mergeInternalOptions(undefined, {}), {}) + deepStrictEqual(ParseResult.mergeInternalOptions({ errors: undefined }, undefined), { errors: undefined }) + deepStrictEqual(ParseResult.mergeInternalOptions(undefined, { errors: undefined }), { errors: undefined }) + deepStrictEqual(ParseResult.mergeInternalOptions({ errors: "all" }, { errors: "first" }), { errors: "first" }) - expect(P.mergeInternalOptions({ onExcessProperty: "ignore" }, { onExcessProperty: "error" })).toStrictEqual({ + deepStrictEqual(ParseResult.mergeInternalOptions({ onExcessProperty: "ignore" }, { onExcessProperty: "error" }), { onExcessProperty: "error" }) - expect(P.mergeInternalOptions({}, { exact: false })).toStrictEqual({ exact: false }) - expect(P.mergeInternalOptions({ exact: true }, { exact: false })).toStrictEqual({ exact: false }) + deepStrictEqual(ParseResult.mergeInternalOptions({}, { exact: false }), { exact: false }) + deepStrictEqual(ParseResult.mergeInternalOptions({ exact: true }, { exact: false }), { exact: false }) - expect(P.mergeInternalOptions({ isEffectAllowed: true }, {})).toStrictEqual({ isEffectAllowed: true }) - expect(P.mergeInternalOptions({}, { isEffectAllowed: true })).toStrictEqual({ isEffectAllowed: true }) - expect(P.mergeInternalOptions({ isEffectAllowed: false }, { isEffectAllowed: true })).toStrictEqual({ + deepStrictEqual(ParseResult.mergeInternalOptions({ isEffectAllowed: true }, {}), { isEffectAllowed: true }) + deepStrictEqual(ParseResult.mergeInternalOptions({}, { isEffectAllowed: true }), { isEffectAllowed: true }) + deepStrictEqual(ParseResult.mergeInternalOptions({ isEffectAllowed: false }, { isEffectAllowed: true }), { isEffectAllowed: true }) }) it("asserts", () => { const schema = S.String - expect(P.asserts(schema)("a")).toEqual(undefined) - expect(() => P.asserts(schema)(1)).toThrow( - new Error(`Expected string, actual 1`) + strictEqual(ParseResult.asserts(schema)("a"), undefined) + throws( + () => ParseResult.asserts(schema)(1), + new ParseResult.ParseError({ issue: new ParseResult.Type(schema.ast, 1) }) ) }) describe("getLiterals", () => { it("StringKeyword", () => { - expect(P.getLiterals(S.String.ast, true)).toEqual([]) + deepStrictEqual(ParseResult.getLiterals(S.String.ast, true), []) }) it("Struct", () => { - expect(P.getLiterals(S.Struct({ _tag: S.Literal("a") }).ast, true)) - .toEqual([["_tag", new AST.Literal("a")]]) + deepStrictEqual(ParseResult.getLiterals(S.Struct({ _tag: S.Literal("a") }).ast, true), [[ + "_tag", + new AST.Literal("a") + ]]) }) it("Tuple", () => { - expect(P.getLiterals(S.Tuple(S.Literal("a"), S.String).ast, true)) - .toEqual([[0, new AST.Literal("a")]]) + deepStrictEqual(ParseResult.getLiterals(S.Tuple(S.Literal("a"), S.String).ast, true), [[0, new AST.Literal("a")]]) }) it("Refinement", () => { - expect( - P.getLiterals( + deepStrictEqual( + ParseResult.getLiterals( S.Struct({ _tag: S.Literal("a") }).pipe( S.filter(() => true) ).ast, true - ) - ).toEqual([["_tag", new AST.Literal("a")]]) + ), + [["_tag", new AST.Literal("a")]] + ) }) it("Transform (decode)", () => { - expect( - P.getLiterals( + deepStrictEqual( + ParseResult.getLiterals( S.Struct({ radius: S.Number }).pipe(S.attachPropertySignature("kind", "circle")).ast, true - ) - ).toEqual([]) + ), + [] + ) }) it("Transform (encode)", () => { - expect( - P.getLiterals( + deepStrictEqual( + ParseResult.getLiterals( S.Struct({ radius: S.Number }).pipe(S.attachPropertySignature("kind", "circle")).ast, false - ) - ).toEqual([["kind", new AST.Literal("circle")]]) + ), + [["kind", new AST.Literal("circle")]] + ) }) it("property Transform (encode)", () => { - expect( - P.getLiterals( + deepStrictEqual( + ParseResult.getLiterals( S.Struct({ _tag: S.transform( S.Literal("a"), @@ -312,24 +320,25 @@ describe("ParseIssue.actual", () => { }) .ast, false - ) - ).toEqual([["_tag", new AST.Literal("b")]]) + ), + [["_tag", new AST.Literal("b")]] + ) }) it("Class (decode)", () => { class A extends S.Class("A")({ _tag: S.Literal("a") }) {} - expect(P.getLiterals(A.ast, true)).toEqual([["_tag", new AST.Literal("a")]]) + deepStrictEqual(ParseResult.getLiterals(A.ast, true), [["_tag", new AST.Literal("a")]]) }) it("Class (encode)", () => { class A extends S.Class("A")({ _tag: S.Literal("a") }) {} - expect(P.getLiterals(A.ast, false)).toEqual([["_tag", new AST.Literal("a")]]) + deepStrictEqual(ParseResult.getLiterals(A.ast, false), [["_tag", new AST.Literal("a")]]) }) }) describe("getSearchTree", () => { it("primitive + primitive", () => { - expect(P.getSearchTree([S.String.ast, S.Number.ast], true)).toEqual({ + deepStrictEqual(ParseResult.getSearchTree([S.String.ast, S.Number.ast], true), { keys: {}, otherwise: [S.String.ast, S.Number.ast], candidates: [] @@ -338,27 +347,25 @@ describe("ParseIssue.actual", () => { it("struct + primitive", () => { const a = S.Struct({ _tag: S.Literal("a") }) - expect(P.getSearchTree([a.ast, S.Number.ast], true)).toEqual( - { - keys: { - _tag: { - buckets: { - a: [a.ast] - }, - literals: [new AST.Literal("a")], - candidates: [a.ast] - } - }, - otherwise: [S.Number.ast], - candidates: [a.ast] - } - ) + deepStrictEqual(ParseResult.getSearchTree([a.ast, S.Number.ast], true), { + keys: { + _tag: { + buckets: { + a: [a.ast] + }, + literals: [new AST.Literal("a")], + candidates: [a.ast] + } + }, + otherwise: [S.Number.ast], + candidates: [a.ast] + }) }) it("struct + struct (same tag key)", () => { const a = S.Struct({ _tag: S.Literal("a") }) const b = S.Struct({ _tag: S.Literal("b") }) - expect(P.getSearchTree([a.ast, b.ast], true)).toEqual({ + deepStrictEqual(ParseResult.getSearchTree([a.ast, b.ast], true), { keys: { _tag: { buckets: { @@ -377,163 +384,169 @@ describe("ParseIssue.actual", () => { it("struct + struct (different tag key)", () => { const A = S.Struct({ a: S.Literal("A"), c: S.String }) const B = S.Struct({ b: S.Literal("B"), d: S.Number }) - expect( - P.getSearchTree([A.ast, B.ast], true) - ).toEqual({ - keys: { - a: { - buckets: { - A: [A.ast] + deepStrictEqual( + ParseResult.getSearchTree([A.ast, B.ast], true), + { + keys: { + a: { + buckets: { + A: [A.ast] + }, + literals: [new AST.Literal("A")], + candidates: [A.ast] }, - literals: [new AST.Literal("A")], - candidates: [A.ast] + b: { + buckets: { + B: [B.ast] + }, + literals: [new AST.Literal("B")], + candidates: [B.ast] + } }, - b: { - buckets: { - B: [B.ast] - }, - literals: [new AST.Literal("B")], - candidates: [B.ast] - } - }, - otherwise: [], - candidates: [A.ast, B.ast] - }) + otherwise: [], + candidates: [A.ast, B.ast] + } + ) }) it("struct + struct (multiple tags)", () => { const A = S.Struct({ _tag: S.Literal("A"), _tag2: S.Literal("A1"), c: S.String }) const B = S.Struct({ _tag: S.Literal("A"), _tag2: S.Literal("A2"), d: S.Number }) - expect( - P.getSearchTree([A.ast, B.ast], true) - ).toEqual({ - keys: { - _tag: { - buckets: { - A: [A.ast] + deepStrictEqual( + ParseResult.getSearchTree([A.ast, B.ast], true), + { + keys: { + _tag: { + buckets: { + A: [A.ast] + }, + literals: [new AST.Literal("A")], + candidates: [A.ast] }, - literals: [new AST.Literal("A")], - candidates: [A.ast] + _tag2: { + buckets: { + A2: [B.ast] + }, + literals: [new AST.Literal("A2")], + candidates: [B.ast] + } }, - _tag2: { - buckets: { - A2: [B.ast] - }, - literals: [new AST.Literal("A2")], - candidates: [B.ast] - } - }, - otherwise: [], - candidates: [A.ast, B.ast] - }) + otherwise: [], + candidates: [A.ast, B.ast] + } + ) }) it("tuple + tuple (same tag key)", () => { const a = S.Tuple(S.Literal("a"), S.String) const b = S.Tuple(S.Literal("b"), S.Number) - expect( - P.getSearchTree([a.ast, b.ast], true) - ).toEqual({ - keys: { - 0: { - buckets: { - a: [a.ast], - b: [b.ast] - }, - literals: [new AST.Literal("a"), new AST.Literal("b")], - candidates: [a.ast, b.ast] - } - }, - otherwise: [], - candidates: [a.ast, b.ast] - }) + deepStrictEqual( + ParseResult.getSearchTree([a.ast, b.ast], true), + { + keys: { + 0: { + buckets: { + a: [a.ast], + b: [b.ast] + }, + literals: [new AST.Literal("a"), new AST.Literal("b")], + candidates: [a.ast, b.ast] + } + }, + otherwise: [], + candidates: [a.ast, b.ast] + } + ) }) it("tuple + tuple (different tag key)", () => { const a = S.Tuple(S.Literal("a"), S.String) const b = S.Tuple(S.Number, S.Literal("b")) - expect( - P.getSearchTree([a.ast, b.ast], true) - ).toEqual({ - keys: { - 0: { - buckets: { - a: [a.ast] + deepStrictEqual( + ParseResult.getSearchTree([a.ast, b.ast], true), + { + keys: { + 0: { + buckets: { + a: [a.ast] + }, + literals: [new AST.Literal("a")], + candidates: [a.ast] }, - literals: [new AST.Literal("a")], - candidates: [a.ast] + 1: { + buckets: { + b: [b.ast] + }, + literals: [new AST.Literal("b")], + candidates: [b.ast] + } }, - 1: { - buckets: { - b: [b.ast] - }, - literals: [new AST.Literal("b")], - candidates: [b.ast] - } - }, - otherwise: [], - candidates: [a.ast, b.ast] - }) + otherwise: [], + candidates: [a.ast, b.ast] + } + ) }) it("tuple + tuple (multiple tags)", () => { const a = S.Tuple(S.Literal("a"), S.Literal("b"), S.String) const b = S.Tuple(S.Literal("a"), S.Literal("c"), S.Number) - expect( - P.getSearchTree([a.ast, b.ast], true) - ).toEqual({ - keys: { - 0: { - buckets: { - a: [a.ast] + deepStrictEqual( + ParseResult.getSearchTree([a.ast, b.ast], true), + { + keys: { + 0: { + buckets: { + a: [a.ast] + }, + literals: [new AST.Literal("a")], + candidates: [a.ast] }, - literals: [new AST.Literal("a")], - candidates: [a.ast] + 1: { + buckets: { + c: [b.ast] + }, + literals: [new AST.Literal("c")], + candidates: [b.ast] + } }, - 1: { - buckets: { - c: [b.ast] - }, - literals: [new AST.Literal("c")], - candidates: [b.ast] - } - }, - otherwise: [], - candidates: [a.ast, b.ast] - }) + otherwise: [], + candidates: [a.ast, b.ast] + } + ) }) it("should handle multiple tags", () => { const a = S.Struct({ category: S.Literal("catA"), tag: S.Literal("a") }) const b = S.Struct({ category: S.Literal("catA"), tag: S.Literal("b") }) const c = S.Struct({ category: S.Literal("catA"), tag: S.Literal("c") }) - expect( - P.getSearchTree([ + deepStrictEqual( + ParseResult.getSearchTree([ a.ast, b.ast, c.ast - ], true) - ).toEqual({ - keys: { - category: { - buckets: { - catA: [a.ast] + ], true), + { + keys: { + category: { + buckets: { + catA: [a.ast] + }, + literals: [new AST.Literal("catA")], + candidates: [a.ast] }, - literals: [new AST.Literal("catA")], - candidates: [a.ast] + tag: { + buckets: { + b: [b.ast], + c: [c.ast] + }, + literals: [new AST.Literal("b"), new AST.Literal("c")], + candidates: [b.ast, c.ast] + } }, - tag: { - buckets: { - b: [b.ast], - c: [c.ast] - }, - literals: [new AST.Literal("b"), new AST.Literal("c")], - candidates: [b.ast, c.ast] - } - }, - otherwise: [], - candidates: [a.ast, b.ast, c.ast] - }) + otherwise: [], + candidates: [a.ast, b.ast, c.ast] + } + ) }) it("big union", () => { @@ -553,7 +566,7 @@ describe("ParseIssue.actual", () => { S.Struct({ type: S.Array(S.Number), value: S.String }) ) const types = (schema.ast as AST.Union).types - expect(P.getSearchTree(types, true)).toEqual({ + deepStrictEqual(ParseResult.getSearchTree(types, true), { keys: { type: { buckets: { @@ -596,7 +609,7 @@ describe("ParseIssue.actual", () => { const AB = S.Union(A, B) const schema = S.Union(ab, AB) const types = (schema.ast as AST.Union).types - expect(P.getSearchTree(types, true)).toEqual({ + deepStrictEqual(ParseResult.getSearchTree(types, true), { keys: {}, otherwise: [ab.ast, AB.ast], candidates: [] diff --git a/packages/effect/test/Schema/ParseResultFormatter.test.ts b/packages/effect/test/Schema/ParseResultFormatter.test.ts index 579d1316cc4..8c928861a7a 100644 --- a/packages/effect/test/Schema/ParseResultFormatter.test.ts +++ b/packages/effect/test/Schema/ParseResultFormatter.test.ts @@ -8,7 +8,8 @@ import * as S from "effect/Schema" import type { ParseOptions } from "effect/SchemaAST" import * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertLeft } from "effect/test/util" +import { describe, it } from "vitest" const options: ParseOptions = { errors: "all", onExcessProperty: "error" } @@ -16,7 +17,7 @@ const expectIssues = (schema: S.Schema, input: unknown, issues: Arra const result = S.decodeUnknownEither(schema)(input, options).pipe( Either.mapLeft((e) => ParseResult.ArrayFormatter.formatIssueSync(e.issue)) ) - expect(result).toStrictEqual(Either.left(issues)) + assertLeft(result, issues) } describe("ParseResultFormatter", () => { @@ -24,11 +25,10 @@ describe("ParseResultFormatter", () => { it("default message", () => { const schema = Util.AsyncString const input = "" - expect(() => S.decodeUnknownSync(schema)(input)).toThrow( - new Error( - `AsyncString + Util.assertParseError( + () => S.decodeUnknownSync(schema)(input), + `AsyncString └─ cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work` - ) ) expectIssues(schema, input, [{ _tag: "Forbidden", @@ -41,11 +41,10 @@ describe("ParseResultFormatter", () => { it("default message with identifier", () => { const schema = Util.AsyncString const input = "" - expect(() => S.decodeUnknownSync(schema)(input)).toThrow( - new Error( - `AsyncString + Util.assertParseError( + () => S.decodeUnknownSync(schema)(input), + `AsyncString └─ cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work` - ) ) expectIssues(schema, input, [{ _tag: "Forbidden", @@ -58,9 +57,10 @@ describe("ParseResultFormatter", () => { it("custom message (override=false)", () => { const schema = Util.AsyncString.annotations({ message: () => "custom message" }) const input = "" - expect(() => S.decodeUnknownSync(schema)(input)).toThrow( - new Error(`AsyncString -└─ cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work`) + Util.assertParseError( + () => S.decodeUnknownSync(schema)(input), + `AsyncString +└─ cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work` ) expectIssues(schema, input, [{ _tag: "Forbidden", @@ -75,9 +75,10 @@ describe("ParseResultFormatter", () => { message: () => ({ message: "custom message", override: true }) }) const input = "" - expect(() => S.decodeUnknownSync(schema)(input)).toThrow( - new Error(`AsyncString -└─ cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work`) + Util.assertParseError( + () => S.decodeUnknownSync(schema)(input), + `AsyncString +└─ cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work` ) expectIssues(schema, input, [{ _tag: "Forbidden", @@ -1310,11 +1311,13 @@ it("Effect as message", () => { const result = S.decodeUnknownEither(Name)("") // no service - expect(Either.mapLeft(result, (error) => Effect.runSync(ParseResult.TreeFormatter.formatError(error)))) - .toStrictEqual(Either.left("Invalid string")) + assertLeft( + Either.mapLeft(result, (error) => Effect.runSync(ParseResult.TreeFormatter.formatError(error))), + "Invalid string" + ) // it locale - expect( + assertLeft( Either.mapLeft( result, (error) => @@ -1324,11 +1327,12 @@ it("Effect as message", () => { translations })) ) - ) - ).toStrictEqual(Either.left("Nome non valido")) + ), + "Nome non valido" + ) // en locale - expect( + assertLeft( Either.mapLeft( result, (error) => @@ -1338,6 +1342,7 @@ it("Effect as message", () => { translations })) ) - ) - ).toStrictEqual(Either.left("Invalid name")) + ), + "Invalid name" + ) }) diff --git a/packages/effect/test/Schema/Pretty.test.ts b/packages/effect/test/Schema/Pretty.test.ts index 1a250583391..1ff3f59cf94 100644 --- a/packages/effect/test/Schema/Pretty.test.ts +++ b/packages/effect/test/Schema/Pretty.test.ts @@ -2,24 +2,26 @@ import { isUnknown } from "effect/Predicate" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" describe("Pretty", () => { it("make", () => { const schema = S.NumberFromString const pretty = Pretty.make(schema) - expect(pretty(1)).toEqual(`1`) + strictEqual(pretty(1), `1`) }) it("make(S.encodedSchema(schema))", () => { const schema = S.NumberFromString const pretty = Pretty.make(S.encodedSchema(schema)) - expect(pretty("a")).toEqual(`"a"`) + strictEqual(pretty("a"), `"a"`) }) it("should throw on declarations without annotations", () => { const schema = S.declare(isUnknown) - expect(() => Pretty.make(schema)).toThrow( + throws( + () => Pretty.make(schema), new Error(`Missing annotation details: Generating a Pretty for this schema requires a "pretty" annotation schema (Declaration): `) @@ -29,19 +31,19 @@ schema (Declaration): `) it("should throw on never", () => { const schema = S.Never const pretty = Pretty.make(schema) - expect(() => pretty("a" as any as never)).toThrow( - new Error("Cannot pretty print a `never` value") - ) + throws(() => pretty("a" as any as never), new Error("Cannot pretty print a `never` value")) }) it("the errors should disply a path", () => { - expect(() => Pretty.make(S.Tuple(S.declare(isUnknown)))).toThrow( + throws( + () => Pretty.make(S.Tuple(S.declare(isUnknown))), new Error(`Missing annotation at path: [0] details: Generating a Pretty for this schema requires a "pretty" annotation schema (Declaration): `) ) - expect(() => Pretty.make(S.Struct({ a: S.declare(isUnknown) }))).toThrow( + throws( + () => Pretty.make(S.Struct({ a: S.declare(isUnknown) })), new Error(`Missing annotation at path: ["a"] details: Generating a Pretty for this schema requires a "pretty" annotation @@ -56,73 +58,73 @@ schema (Declaration): `) } const go = AST.getCompiler(match) const pretty = (schema: S.Schema) => (a: A): string => go(schema.ast, [])(a) - expect(pretty(S.Boolean)(true)).toEqual(`True`) + strictEqual(pretty(S.Boolean)(true), `True`) const schema = S.Tuple(S.String, S.Boolean) - expect(pretty(schema)(["a", true])).toEqual(`["a", True]`) + strictEqual(pretty(schema)(["a", true]), `["a", True]`) }) describe("templateLiteral", () => { it("a${string}b", () => { const schema = S.TemplateLiteral(S.Literal("a"), S.String, S.Literal("b")) const pretty = Pretty.make(schema) - expect(pretty("acb")).toEqual(`"acb"`) + strictEqual(pretty("acb"), `"acb"`) }) }) it("unknown", () => { const schema = S.Unknown const pretty = Pretty.make(schema) - expect(pretty("a")).toEqual(`"a"`) - expect(pretty(1n)).toEqual(`1n`) + strictEqual(pretty("a"), `"a"`) + strictEqual(pretty(1n), `1n`) }) it("string", () => { const schema = S.String const pretty = Pretty.make(schema) - expect(pretty("a")).toEqual(`"a"`) + strictEqual(pretty("a"), `"a"`) }) it("number", () => { const schema = S.Number const pretty = Pretty.make(schema) - expect(pretty(1)).toEqual("1") - expect(pretty(NaN)).toEqual("NaN") - expect(pretty(Infinity)).toEqual("Infinity") - expect(pretty(-Infinity)).toEqual("-Infinity") + strictEqual(pretty(1), "1") + strictEqual(pretty(NaN), "NaN") + strictEqual(pretty(Infinity), "Infinity") + strictEqual(pretty(-Infinity), "-Infinity") }) it("boolean", () => { const schema = S.Boolean const pretty = Pretty.make(schema) - expect(pretty(true)).toEqual("true") + strictEqual(pretty(true), "true") }) it("bigint", () => { const pretty = Pretty.make(S.BigIntFromSelf) - expect(pretty(1n)).toEqual("1n") + strictEqual(pretty(1n), "1n") }) it("symbol", () => { const pretty = Pretty.make(S.SymbolFromSelf) - expect(pretty(Symbol.for("effect/test/a"))).toEqual("Symbol(effect/test/a)") + strictEqual(pretty(Symbol.for("effect/test/a")), "Symbol(effect/test/a)") }) it("void", () => { const pretty = Pretty.make(S.Void) - expect(pretty(undefined)).toEqual("void(0)") + strictEqual(pretty(undefined), "void(0)") }) describe("literal", () => { it("null", () => { const schema = S.Literal(null) const pretty = Pretty.make(schema) - expect(pretty(null)).toEqual("null") + strictEqual(pretty(null), "null") }) it("bigint", () => { const schema = S.Literal(1n) const pretty = Pretty.make(schema) - expect(pretty(1n)).toEqual("1n") + strictEqual(pretty(1n), "1n") }) }) @@ -130,7 +132,7 @@ schema (Declaration): `) const a = Symbol.for("effect/Schema/test/a") const schema = S.UniqueSymbolFromSelf(a) const pretty = Pretty.make(schema) - expect(pretty(a)).toEqual("Symbol(effect/Schema/test/a)") + strictEqual(pretty(a), "Symbol(effect/Schema/test/a)") }) describe("enums", () => { @@ -141,8 +143,8 @@ schema (Declaration): `) } const schema = S.Enums(Fruits) const pretty = Pretty.make(schema) - expect(pretty(Fruits.Apple)).toEqual(`0`) - expect(pretty(Fruits.Banana)).toEqual(`1`) + strictEqual(pretty(Fruits.Apple), `0`) + strictEqual(pretty(Fruits.Banana), `1`) }) it("String enums", () => { @@ -153,9 +155,9 @@ schema (Declaration): `) } const schema = S.Enums(Fruits) const pretty = Pretty.make(schema) - expect(pretty(Fruits.Apple)).toEqual(`"apple"`) - expect(pretty(Fruits.Banana)).toEqual(`"banana"`) - expect(pretty(Fruits.Cantaloupe)).toEqual(`0`) + strictEqual(pretty(Fruits.Apple), `"apple"`) + strictEqual(pretty(Fruits.Banana), `"banana"`) + strictEqual(pretty(Fruits.Cantaloupe), `0`) }) it("Const enums", () => { @@ -166,9 +168,9 @@ schema (Declaration): `) } as const const schema = S.Enums(Fruits) const pretty = Pretty.make(schema) - expect(pretty(Fruits.Apple)).toEqual(`"apple"`) - expect(pretty(Fruits.Banana)).toEqual(`"banana"`) - expect(pretty(Fruits.Cantaloupe)).toEqual(`3`) + strictEqual(pretty(Fruits.Apple), `"apple"`) + strictEqual(pretty(Fruits.Banana), `"banana"`) + strictEqual(pretty(Fruits.Cantaloupe), `3`) }) }) @@ -176,73 +178,69 @@ schema (Declaration): `) it("empty", () => { const schema = S.Struct({}) const pretty = Pretty.make(schema) - expect(pretty({})).toEqual( - "{}" - ) + strictEqual(pretty({}), "{}") }) it("required fields", () => { const schema = S.Struct({ a: S.String, b: S.Number }) const pretty = Pretty.make(schema) - expect(pretty({ a: "a", b: 1 })).toEqual( - `{ "a": "a", "b": 1 }` - ) + strictEqual(pretty({ a: "a", b: 1 }), `{ "a": "a", "b": 1 }`) }) it("should not output exact optional property signatures", () => { const schema = S.Struct({ a: S.optionalWith(S.Number, { exact: true }) }) const pretty = Pretty.make(schema) - expect(pretty({})).toEqual("{}") - expect(pretty({ a: 1 })).toEqual(`{ "a": 1 }`) + strictEqual(pretty({}), "{}") + strictEqual(pretty({ a: 1 }), `{ "a": 1 }`) }) it("should escape keys", () => { const schema = S.Struct({ "-": S.Number }) const pretty = Pretty.make(schema) - expect(pretty({ "-": 1 })).toEqual(`{ "-": 1 }`) + strictEqual(pretty({ "-": 1 }), `{ "-": 1 }`) }) it("required property signature", () => { const schema = S.Struct({ a: S.Number }) const pretty = Pretty.make(schema) - expect(pretty({ a: 1 })).toEqual(`{ "a": 1 }`) + strictEqual(pretty({ a: 1 }), `{ "a": 1 }`) const x = { a: 1, b: "b" } - expect(pretty(x)).toEqual(`{ "a": 1 }`) + strictEqual(pretty(x), `{ "a": 1 }`) }) it("required property signature with undefined", () => { const schema = S.Struct({ a: S.Union(S.Number, S.Undefined) }) const pretty = Pretty.make(schema) - expect(pretty({ a: 1 })).toEqual(`{ "a": 1 }`) - expect(pretty({ a: undefined })).toEqual(`{ "a": undefined }`) + strictEqual(pretty({ a: 1 }), `{ "a": 1 }`) + strictEqual(pretty({ a: undefined }), `{ "a": undefined }`) const x = { a: 1, b: "b" } - expect(pretty(x)).toEqual(`{ "a": 1 }`) + strictEqual(pretty(x), `{ "a": 1 }`) }) it("exact optional property signature", () => { const schema = S.Struct({ a: S.optionalWith(S.Number, { exact: true }) }) const pretty = Pretty.make(schema) - expect(pretty({})).toEqual(`{}`) - expect(pretty({ a: 1 })).toEqual(`{ "a": 1 }`) + strictEqual(pretty({}), `{}`) + strictEqual(pretty({ a: 1 }), `{ "a": 1 }`) const x = { a: 1, b: "b" } - expect(pretty(x)).toEqual(`{ "a": 1 }`) + strictEqual(pretty(x), `{ "a": 1 }`) }) it("exact optional property signature with undefined", () => { const schema = S.Struct({ a: S.optionalWith(S.Union(S.Number, S.Undefined), { exact: true }) }) const pretty = Pretty.make(schema) - expect(pretty({})).toEqual(`{}`) - expect(pretty({ a: 1 })).toEqual(`{ "a": 1 }`) + strictEqual(pretty({}), `{}`) + strictEqual(pretty({ a: 1 }), `{ "a": 1 }`) const x = { a: 1, b: "b" } - expect(pretty(x)).toEqual(`{ "a": 1 }`) - expect(pretty({ a: undefined })).toEqual(`{ "a": undefined }`) + strictEqual(pretty(x), `{ "a": 1 }`) + strictEqual(pretty({ a: undefined }), `{ "a": undefined }`) }) it("extend: struct and record", () => { const schema = S.Struct({ a: S.String }, S.Record({ key: S.String, value: S.Union(S.String, S.Number) })) const pretty = Pretty.make(schema) - expect(pretty({ a: "a" })).toEqual(`{ "a": "a" }`) - expect(pretty({ a: "a", b: "b", c: 1 })).toEqual(`{ "a": "a", "b": "b", "c": 1 }`) + strictEqual(pretty({ a: "a" }), `{ "a": "a" }`) + strictEqual(pretty({ a: "a", b: "b", c: 1 }), `{ "a": "a", "b": "b", "c": 1 }`) }) }) @@ -250,18 +248,14 @@ schema (Declaration): `) it("record(string, string)", () => { const schema = S.Record({ key: S.String, value: S.String }) const pretty = Pretty.make(schema) - expect(pretty({ a: "a", b: "b" })).toEqual( - `{ "a": "a", "b": "b" }` - ) + strictEqual(pretty({ a: "a", b: "b" }), `{ "a": "a", "b": "b" }`) }) it("record(symbol, string)", () => { const a = Symbol.for("effect/Schema/test/a") const schema = S.Record({ key: S.SymbolFromSelf, value: S.String }) const pretty = Pretty.make(schema) - expect(pretty({ [a]: "a" })).toEqual( - `{ Symbol(effect/Schema/test/a): "a" }` - ) + strictEqual(pretty({ [a]: "a" }), `{ Symbol(effect/Schema/test/a): "a" }`) }) }) @@ -269,119 +263,119 @@ schema (Declaration): `) it("required element", () => { const schema = S.Tuple(S.Number) const pretty = Pretty.make(schema) - expect(pretty([1])).toEqual(`[1]`) + strictEqual(pretty([1]), `[1]`) const x = [1, "b"] as any - expect(pretty(x)).toEqual(`[1]`) + strictEqual(pretty(x), `[1]`) }) it("required element with undefined", () => { const schema = S.Tuple(S.Union(S.Number, S.Undefined)) const pretty = Pretty.make(schema) - expect(pretty([1])).toEqual(`[1]`) - expect(pretty([undefined])).toEqual(`[undefined]`) + strictEqual(pretty([1]), `[1]`) + strictEqual(pretty([undefined]), `[undefined]`) const x = [1, "b"] as any - expect(pretty(x)).toEqual(`[1]`) + strictEqual(pretty(x), `[1]`) }) it("optional element", () => { const schema = S.Tuple(S.optionalElement(S.Number)) const pretty = Pretty.make(schema) - expect(pretty([])).toEqual(`[]`) - expect(pretty([1])).toEqual(`[1]`) + strictEqual(pretty([]), `[]`) + strictEqual(pretty([1]), `[1]`) const x = [1, "b"] as any - expect(pretty(x)).toEqual(`[1]`) + strictEqual(pretty(x), `[1]`) }) it("optional element with undefined", () => { const schema = S.Tuple(S.optionalElement(S.Union(S.Number, S.Undefined))) const pretty = Pretty.make(schema) - expect(pretty([])).toEqual(`[]`) - expect(pretty([1])).toEqual(`[1]`) + strictEqual(pretty([]), `[]`) + strictEqual(pretty([1]), `[1]`) const x = [1, "b"] as any - expect(pretty(x)).toEqual(`[1]`) - expect(pretty([undefined])).toEqual(`[undefined]`) + strictEqual(pretty(x), `[1]`) + strictEqual(pretty([undefined]), `[undefined]`) }) it("baseline", () => { const schema = S.Tuple(S.String, S.Number) const pretty = Pretty.make(schema) - expect(pretty(["a", 1])).toEqual(`["a", 1]`) + strictEqual(pretty(["a", 1]), `["a", 1]`) }) it("empty tuple", () => { const schema = S.Tuple() const pretty = Pretty.make(schema) - expect(pretty([])).toEqual(`[]`) + strictEqual(pretty([]), `[]`) }) it("optional elements", () => { const schema = S.Tuple(S.optionalElement(S.String), S.optionalElement(S.Number)) const pretty = Pretty.make(schema) - expect(pretty([])).toEqual(`[]`) - expect(pretty(["a"])).toEqual(`["a"]`) - expect(pretty(["a", 1])).toEqual(`["a", 1]`) + strictEqual(pretty([]), `[]`) + strictEqual(pretty(["a"]), `["a"]`) + strictEqual(pretty(["a", 1]), `["a", 1]`) }) it("array", () => { const schema = S.Array(S.String) const pretty = Pretty.make(schema) - expect(pretty([])).toEqual(`[]`) - expect(pretty(["a"])).toEqual(`["a"]`) + strictEqual(pretty([]), `[]`) + strictEqual(pretty(["a"]), `["a"]`) }) it("post rest element", () => { const schema = S.Tuple([], S.Number, S.Boolean) const pretty = Pretty.make(schema) - expect(pretty([true])).toEqual(`[true]`) - expect(pretty([1, true])).toEqual(`[1, true]`) - expect(pretty([1, 2, true])).toEqual(`[1, 2, true]`) - expect(pretty([1, 2, 3, true])).toEqual(`[1, 2, 3, true]`) + strictEqual(pretty([true]), `[true]`) + strictEqual(pretty([1, true]), `[1, true]`) + strictEqual(pretty([1, 2, true]), `[1, 2, true]`) + strictEqual(pretty([1, 2, 3, true]), `[1, 2, 3, true]`) }) it("post rest elements", () => { const schema = S.Tuple([], S.Number, S.Boolean, S.Union(S.String, S.Undefined)) const pretty = Pretty.make(schema) - expect(pretty([true, "c"])).toEqual(`[true, "c"]`) - expect(pretty([1, true, "c"])).toEqual(`[1, true, "c"]`) - expect(pretty([1, 2, true, "c"])).toEqual(`[1, 2, true, "c"]`) - expect(pretty([1, 2, 3, true, "c"])).toEqual(`[1, 2, 3, true, "c"]`) - expect(pretty([1, 2, 3, true, undefined])).toEqual(`[1, 2, 3, true, undefined]`) + strictEqual(pretty([true, "c"]), `[true, "c"]`) + strictEqual(pretty([1, true, "c"]), `[1, true, "c"]`) + strictEqual(pretty([1, 2, true, "c"]), `[1, 2, true, "c"]`) + strictEqual(pretty([1, 2, 3, true, "c"]), `[1, 2, 3, true, "c"]`) + strictEqual(pretty([1, 2, 3, true, undefined]), `[1, 2, 3, true, undefined]`) }) it("post rest elements when rest is unknown", () => { const schema = S.Tuple([], S.Unknown, S.Boolean) const pretty = Pretty.make(schema) - expect(pretty([1, "a", 2, "b", true])).toEqual(`[1, "a", 2, "b", true]`) - expect(pretty([true])).toEqual(`[true]`) + strictEqual(pretty([1, "a", 2, "b", true]), `[1, "a", 2, "b", true]`) + strictEqual(pretty([true]), `[true]`) }) it("all", () => { const schema = S.Tuple([S.String], S.Number, S.Boolean) const pretty = Pretty.make(schema) - expect(pretty(["a", true])).toEqual(`["a", true]`) - expect(pretty(["a", 1, true])).toEqual(`["a", 1, true]`) - expect(pretty(["a", 1, 2, true])).toEqual(`["a", 1, 2, true]`) + strictEqual(pretty(["a", true]), `["a", true]`) + strictEqual(pretty(["a", 1, true]), `["a", 1, true]`) + strictEqual(pretty(["a", 1, 2, true]), `["a", 1, 2, true]`) }) it("nonEmptyArray", () => { const schema = S.NonEmptyArray(S.Number) const pretty = Pretty.make(schema) - expect(pretty([1])).toEqual(`[1]`) - expect(pretty([1, 2])).toEqual(`[1, 2]`) + strictEqual(pretty([1]), `[1]`) + strictEqual(pretty([1, 2]), `[1, 2]`) }) it("ReadonlyArray", () => { const schema = S.Array(S.Unknown) const pretty = Pretty.make(schema) - expect(pretty([])).toEqual(`[]`) - expect(pretty(["a", 1, true])).toEqual(`["a", 1, true]`) + strictEqual(pretty([]), `[]`) + strictEqual(pretty(["a", 1, true]), `["a", 1, true]`) }) it("ReadonlyArray", () => { const schema = S.Array(S.Any) const pretty = Pretty.make(schema) - expect(pretty([])).toEqual(`[]`) - expect(pretty(["a", 1, true])).toEqual(`["a", 1, true]`) + strictEqual(pretty([]), `[]`) + strictEqual(pretty(["a", 1, true]), `["a", 1, true]`) }) }) @@ -389,12 +383,8 @@ schema (Declaration): `) it("primitives", () => { const schema = S.Union(S.String, S.Number) const pretty = Pretty.make(schema) - expect(pretty("a")).toEqual( - `"a"` - ) - expect(pretty(1)).toEqual( - "1" - ) + strictEqual(pretty("a"), `"a"`) + strictEqual(pretty(1), "1") }) it("discriminated", () => { @@ -403,12 +393,8 @@ schema (Declaration): `) S.Struct({ tag: S.Literal("b"), b: S.Number }) ) const pretty = Pretty.make(schema) - expect(pretty({ tag: "a", a: "-" })).toEqual( - `{ "tag": "a", "a": "-" }` - ) - expect(pretty({ tag: "b", b: 1 })).toEqual( - `{ "tag": "b", "b": 1 }` - ) + strictEqual(pretty({ tag: "a", a: "-" }), `{ "tag": "a", "a": "-" }`) + strictEqual(pretty({ tag: "b", b: 1 }), `{ "tag": "b", "b": 1 }`) }) }) @@ -422,21 +408,19 @@ schema (Declaration): `) as: S.Array(S.suspend((): S.Schema => A)) }) const pretty = Pretty.make(A) - expect(pretty({ a: "a", as: [] })).toEqual( - `{ "a": "a", "as": [] }` - ) + strictEqual(pretty({ a: "a", as: [] }), `{ "a": "a", "as": [] }`) }) it("transformation", () => { const pretty = Pretty.make(S.Trim) - expect(pretty("a")).toEqual(`"a"`) + strictEqual(pretty("a"), `"a"`) }) describe("should handle annotations", () => { const expectHook = (source: S.Schema) => { const schema = source.annotations({ pretty: () => () => "custom pretty" }) const pretty = Pretty.make(schema) - expect(pretty(null as any)).toEqual("custom pretty") + strictEqual(pretty(null as any), "custom pretty") } it("void", () => { @@ -541,7 +525,8 @@ schema (Declaration): `) const schema = S.Union(A, S.Number) const x: {} = { a: undefined } const input: typeof A.Type = x - expect(() => Pretty.make(schema)(input)).toThrow( + throws( + () => Pretty.make(schema)(input), new Error(`Unexpected Error details: Cannot find a matching schema for {"a":undefined} schema (Union): { readonly a?: string } | number`) diff --git a/packages/effect/test/Schema/Schema/Array/Array.test.ts b/packages/effect/test/Schema/Schema/Array/Array.test.ts index 0c640642af4..ca0d1ec5da2 100644 --- a/packages/effect/test/Schema/Schema/Array/Array.test.ts +++ b/packages/effect/test/Schema/Schema/Array/Array.test.ts @@ -2,12 +2,13 @@ import * as Either from "effect/Either" import * as ParseResult from "effect/ParseResult" import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" -import { assert, describe, expect, it } from "vitest" +import { deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Array", () => { it("annotations()", () => { const schema = S.Array(S.String).annotations({ identifier: "X" }).annotations({ title: "Y" }) - expect(schema.ast.annotations).toStrictEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.IdentifierAnnotationId]: "X", [AST.TitleAnnotationId]: "Y" }) @@ -15,7 +16,7 @@ describe("Array", () => { it("should expose the value", () => { const schema = S.Array(S.String) - expect(schema.value).toStrictEqual(S.String) + strictEqual(schema.value, S.String) }) it("should compute the partial result", () => { @@ -24,23 +25,23 @@ describe("Array", () => { if (Either.isLeft(all)) { const issue = all.left.issue if (ParseResult.isComposite(issue)) { - expect(issue.output).toStrictEqual([1, 2]) + deepStrictEqual(issue.output, [1, 2]) } else { - assert.fail("expected an And") + throw new Error("expected an And") } } else { - assert.fail("expected a Left") + throw new Error("expected a Left") } const first = S.decodeUnknownEither(schema)([1, "a", 2, "b"], { errors: "first" }) if (Either.isLeft(first)) { const issue = first.left.issue if (ParseResult.isComposite(issue)) { - expect(issue.output).toStrictEqual([1]) + deepStrictEqual(issue.output, [1]) } else { - assert.fail("expected an And") + throw new Error("expected an And") } } else { - assert.fail("expected a Left") + throw new Error("expected a Left") } }) }) diff --git a/packages/effect/test/Schema/Schema/Array/itemsCount.test.ts b/packages/effect/test/Schema/Schema/Array/itemsCount.test.ts index b0be9b8179e..24f015f37d3 100644 --- a/packages/effect/test/Schema/Schema/Array/itemsCount.test.ts +++ b/packages/effect/test/Schema/Schema/Array/itemsCount.test.ts @@ -1,10 +1,12 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { throws } from "effect/test/util" +import { describe, it } from "vitest" describe("itemsCount", () => { it("should throw for invalid argument", () => { - expect(() => S.Array(S.Number).pipe(S.itemsCount(-1))).toThrowError( + throws( + () => S.Array(S.Number).pipe(S.itemsCount(-1)), new Error(`Invalid Argument details: Expected an integer greater than or equal to 0, actual -1`) ) diff --git a/packages/effect/test/Schema/Schema/Array/maxItems.test.ts b/packages/effect/test/Schema/Schema/Array/maxItems.test.ts index 3d082d7296b..f67a0aba3fd 100644 --- a/packages/effect/test/Schema/Schema/Array/maxItems.test.ts +++ b/packages/effect/test/Schema/Schema/Array/maxItems.test.ts @@ -1,10 +1,12 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { throws } from "effect/test/util" +import { describe, it } from "vitest" describe("maxItems", () => { it("should throw for invalid argument", () => { - expect(() => S.Array(S.Number).pipe(S.maxItems(-1))).toThrowError( + throws( + () => S.Array(S.Number).pipe(S.maxItems(-1)), new Error(`Invalid Argument details: Expected an integer greater than or equal to 1, actual -1`) ) diff --git a/packages/effect/test/Schema/Schema/Array/minItems.test.ts b/packages/effect/test/Schema/Schema/Array/minItems.test.ts index b84179fd9e0..0fe240040ca 100644 --- a/packages/effect/test/Schema/Schema/Array/minItems.test.ts +++ b/packages/effect/test/Schema/Schema/Array/minItems.test.ts @@ -1,10 +1,12 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { throws } from "effect/test/util" +import { describe, it } from "vitest" describe("minItems", () => { it("should throw for invalid argument", () => { - expect(() => S.Array(S.Number).pipe(S.minItems(-1))).toThrowError( + throws( + () => S.Array(S.Number).pipe(S.minItems(-1)), new Error(`Invalid Argument details: Expected an integer greater than or equal to 1, actual -1`) ) diff --git a/packages/effect/test/Schema/Schema/ArrayEnsure.test.ts b/packages/effect/test/Schema/Schema/ArrayEnsure.test.ts index 103140e72e6..863ee7b6c06 100644 --- a/packages/effect/test/Schema/Schema/ArrayEnsure.test.ts +++ b/packages/effect/test/Schema/Schema/ArrayEnsure.test.ts @@ -1,12 +1,13 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("ArrayEnsure", () => { it("annotations()", () => { const schema = S.ArrayEnsure(S.String).annotations({ identifier: "X" }).annotations({ title: "Y" }) - expect(schema.ast.annotations).toStrictEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.IdentifierAnnotationId]: "X", [AST.TitleAnnotationId]: "Y" }) diff --git a/packages/effect/test/Schema/Schema/BigDecimal/BigDecimalFromSelf.test.ts b/packages/effect/test/Schema/Schema/BigDecimal/BigDecimalFromSelf.test.ts index 74d51093a05..2585f061ffa 100644 --- a/packages/effect/test/Schema/Schema/BigDecimal/BigDecimalFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/BigDecimal/BigDecimalFromSelf.test.ts @@ -2,7 +2,8 @@ import { BigDecimal } from "effect" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("BigDecimalFromSelf", () => { const schema = S.BigDecimalFromSelf @@ -35,17 +36,17 @@ describe("BigDecimalFromSelf", () => { const schema = S.BigDecimalFromSelf const pretty = Pretty.make(schema) - expect(pretty(BigDecimal.fromNumber(123))).toEqual("BigDecimal(123)") - expect(pretty(BigDecimal.unsafeFromString("123.100"))).toEqual("BigDecimal(123.1)") - expect(pretty(BigDecimal.unsafeFromString(""))).toEqual("BigDecimal(0)") + strictEqual(pretty(BigDecimal.fromNumber(123)), "BigDecimal(123)") + strictEqual(pretty(BigDecimal.unsafeFromString("123.100")), "BigDecimal(123.1)") + strictEqual(pretty(BigDecimal.unsafeFromString("")), "BigDecimal(0)") }) it("equivalence", () => { const schema = S.BigDecimalFromSelf const equivalence = S.equivalence(schema) - expect(equivalence(BigDecimal.fromNumber(1), BigDecimal.unsafeFromString("1"))).toBe(true) - expect(equivalence(BigDecimal.fromNumber(2), BigDecimal.unsafeFromString("1"))).toBe(false) - expect(equivalence(BigDecimal.fromNumber(1), BigDecimal.unsafeFromString("2"))).toBe(false) + assertTrue(equivalence(BigDecimal.fromNumber(1), BigDecimal.unsafeFromString("1"))) + assertFalse(equivalence(BigDecimal.fromNumber(2), BigDecimal.unsafeFromString("1"))) + assertFalse(equivalence(BigDecimal.fromNumber(1), BigDecimal.unsafeFromString("2"))) }) }) diff --git a/packages/effect/test/Schema/Schema/BigDecimal/clampBigDecimal.test.ts b/packages/effect/test/Schema/Schema/BigDecimal/clampBigDecimal.test.ts index 444ad068d21..fdd73128125 100644 --- a/packages/effect/test/Schema/Schema/BigDecimal/clampBigDecimal.test.ts +++ b/packages/effect/test/Schema/Schema/BigDecimal/clampBigDecimal.test.ts @@ -9,8 +9,13 @@ describe("clampBigDecimal", () => { const max = BigDecimal.make(1n, 0) const schema = S.BigDecimalFromSelf.pipe(S.clampBigDecimal(min, max)) // [-1, 1] - await Util.assertions.decoding.succeed(schema, BigDecimal.make(3n, 0), BigDecimal.make(1n, 0)) + // TODO: remove normalize + await Util.assertions.decoding.succeed(schema, BigDecimal.make(3n, 0), BigDecimal.normalize(BigDecimal.make(1n, 0))) await Util.assertions.decoding.succeed(schema, BigDecimal.make(0n, 0), BigDecimal.make(0n, 0)) - await Util.assertions.decoding.succeed(schema, BigDecimal.make(-3n, 0), BigDecimal.make(-1n, 0)) + await Util.assertions.decoding.succeed( + schema, + BigDecimal.make(-3n, 0), + BigDecimal.normalize(BigDecimal.make(-1n, 0)) + ) }) }) diff --git a/packages/effect/test/Schema/Schema/Cause/Cause.test.ts b/packages/effect/test/Schema/Schema/Cause/Cause.test.ts index 14c4e14a047..f2e7d4b79a8 100644 --- a/packages/effect/test/Schema/Schema/Cause/Cause.test.ts +++ b/packages/effect/test/Schema/Schema/Cause/Cause.test.ts @@ -1,7 +1,8 @@ import { Cause, FiberId } from "effect" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { assert, describe, it } from "vitest" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Cause", () => { it("test roundtrip consistency", () => { @@ -162,15 +163,15 @@ describe("Cause", () => { ) let failWithStack = S.encodeSync(schema)(Cause.die(new Error("fail"))) - assert(failWithStack._tag === "Die") - assert.deepStrictEqual(failWithStack.defect, { + assertTrue(failWithStack._tag === "Die") + deepStrictEqual(failWithStack.defect, { name: "Error", message: "fail" }) failWithStack = S.encodeSync(schemaUnknown)(Cause.die(new Error("fail"))) - assert(failWithStack._tag === "Die") - assert.strictEqual((failWithStack.defect as Error).message, "fail") + assertTrue(failWithStack._tag === "Die") + strictEqual((failWithStack.defect as Error).message, "fail") }) }) }) diff --git a/packages/effect/test/Schema/Schema/Cause/CauseFromSelf.test.ts b/packages/effect/test/Schema/Schema/Cause/CauseFromSelf.test.ts index 8d77a1fba9b..3eda34c9cf6 100644 --- a/packages/effect/test/Schema/Schema/Cause/CauseFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/Cause/CauseFromSelf.test.ts @@ -3,7 +3,8 @@ import * as FiberId from "effect/FiberId" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("CauseFromSelf", () => { it("arbitrary", () => { @@ -60,16 +61,19 @@ describe("CauseFromSelf", () => { it("pretty", () => { const schema = S.CauseFromSelf({ error: S.String, defect: S.Unknown }) const pretty = Pretty.make(schema) - expect(pretty(Cause.die("error"))).toEqual(`Cause.die(Error: error)`) - expect(pretty(Cause.empty)).toEqual(`Cause.empty`) - expect(pretty(Cause.fail("error"))).toEqual(`Cause.fail("error")`) - expect(pretty(Cause.interrupt(FiberId.composite(FiberId.none, FiberId.none)))).toEqual( + strictEqual(pretty(Cause.die("error")), `Cause.die(Error: error)`) + strictEqual(pretty(Cause.empty), `Cause.empty`) + strictEqual(pretty(Cause.fail("error")), `Cause.fail("error")`) + strictEqual( + pretty(Cause.interrupt(FiberId.composite(FiberId.none, FiberId.none))), `Cause.interrupt(FiberId.composite(FiberId.none, FiberId.none))` ) - expect(pretty(Cause.parallel(Cause.die("error"), Cause.fail("error")))).toEqual( + strictEqual( + pretty(Cause.parallel(Cause.die("error"), Cause.fail("error"))), `Cause.parallel(Cause.die(Error: error), Cause.fail("error"))` ) - expect(pretty(Cause.sequential(Cause.die("error"), Cause.fail("error")))).toEqual( + strictEqual( + pretty(Cause.sequential(Cause.die("error"), Cause.fail("error"))), `Cause.sequential(Cause.die(Error: error), Cause.fail("error"))` ) }) diff --git a/packages/effect/test/Schema/Schema/Chunk/ChunkFromSelf.test.ts b/packages/effect/test/Schema/Schema/Chunk/ChunkFromSelf.test.ts index 540865879fd..270321d54ff 100644 --- a/packages/effect/test/Schema/Schema/Chunk/ChunkFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/Chunk/ChunkFromSelf.test.ts @@ -3,7 +3,8 @@ import * as P from "effect/ParseResult" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("ChunkFromSelf", () => { it("test roundtrip consistency", () => { @@ -49,19 +50,17 @@ describe("ChunkFromSelf", () => { it("is", () => { const schema = S.ChunkFromSelf(S.String) const is = P.is(schema) - expect(is(C.empty())).toEqual(true) - expect(is(C.fromIterable(["a", "b", "c"]))).toEqual(true) + assertTrue(is(C.empty())) + assertTrue(is(C.fromIterable(["a", "b", "c"]))) - expect(is(C.fromIterable(["a", "b", 1]))).toEqual(false) - expect(is({ _id: Symbol.for("effect/Schema/test/FakeChunk") })).toEqual(false) + assertFalse(is(C.fromIterable(["a", "b", 1]))) + assertFalse(is({ _id: Symbol.for("effect/Schema/test/FakeChunk") })) }) it("pretty", () => { const schema = S.ChunkFromSelf(S.String) const pretty = Pretty.make(schema) - expect(pretty(C.empty())).toEqual("Chunk()") - expect(pretty(C.fromIterable(["a", "b"]))).toEqual( - `Chunk("a", "b")` - ) + strictEqual(pretty(C.empty()), "Chunk()") + strictEqual(pretty(C.fromIterable(["a", "b"])), `Chunk("a", "b")`) }) }) diff --git a/packages/effect/test/Schema/Schema/Chunk/NonEmptyChunkFromSelf.test.ts b/packages/effect/test/Schema/Schema/Chunk/NonEmptyChunkFromSelf.test.ts index 0ee86e8d1f9..f0d0f570b32 100644 --- a/packages/effect/test/Schema/Schema/Chunk/NonEmptyChunkFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/Chunk/NonEmptyChunkFromSelf.test.ts @@ -4,7 +4,8 @@ import * as FastCheck from "effect/FastCheck" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("NonEmptyChunkFromSelf", () => { it("test roundtrip consistency", () => { @@ -56,23 +57,21 @@ describe("NonEmptyChunkFromSelf", () => { it("pretty", () => { const schema = S.NonEmptyChunkFromSelf(S.String) const pretty = Pretty.make(schema) - expect(pretty(C.make("a", "b"))).toEqual( - `NonEmptyChunk("a", "b")` - ) + strictEqual(pretty(C.make("a", "b")), `NonEmptyChunk("a", "b")`) }) it("equivalence", () => { const schema = S.NonEmptyChunkFromSelf(S.String) const equivalence = S.equivalence(schema) - expect(equivalence(C.make("a", "b"), C.make("a", "b"))).toEqual(true) - expect(equivalence(C.make("a", "b"), C.make("a", "c"))).toEqual(false) - expect(equivalence(C.make("a", "b"), C.make("a"))).toEqual(false) + assertTrue(equivalence(C.make("a", "b"), C.make("a", "b"))) + assertFalse(equivalence(C.make("a", "b"), C.make("a", "c"))) + assertFalse(equivalence(C.make("a", "b"), C.make("a"))) }) it("arbitrary", () => { const schema = S.NonEmptyChunkFromSelf(S.String) const arb = Arbitrary.make(schema) FastCheck.assert(FastCheck.property(arb, C.isNonEmpty)) - expect(FastCheck.sample(arb, 10).every(C.isNonEmpty)).toBe(true) + assertTrue(FastCheck.sample(arb, 10).every(C.isNonEmpty)) }) }) diff --git a/packages/effect/test/Schema/Schema/Class/Class.test.ts b/packages/effect/test/Schema/Schema/Class/Class.test.ts index 0995d9d88d7..c22fab1e930 100644 --- a/packages/effect/test/Schema/Schema/Class/Class.test.ts +++ b/packages/effect/test/Schema/Schema/Class/Class.test.ts @@ -1,17 +1,7 @@ -import { - Context, - Data, - Effect, - Equal, - JSONSchema, - Option, - ParseResult, - Pretty, - Schema as S, - SchemaAST as AST -} from "effect" +import { Context, Data, Effect, Equal, JSONSchema, ParseResult, Pretty, Schema as S, SchemaAST as AST } from "effect" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertSome, assertTrue, deepStrictEqual, strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" class Person extends S.Class("Person")({ id: S.Number, @@ -59,59 +49,61 @@ describe("Class", () => { it("should be a Schema", () => { class A extends S.Class("A")({ a: S.String }) {} - expect(S.isSchema(A)).toEqual(true) - expect(String(A)).toBe("(A (Encoded side) <-> A)") - expect(S.format(A)).toBe("(A (Encoded side) <-> A)") + assertTrue(S.isSchema(A)) + strictEqual(String(A), "(A (Encoded side) <-> A)") + strictEqual(S.format(A), "(A (Encoded side) <-> A)") }) it("should expose the fields", () => { class A extends S.Class("A")({ a: S.String }) {} - expect(A.fields).toEqual({ a: S.String }) + deepStrictEqual(A.fields, { a: S.String }) }) it("should expose the identifier", () => { class A extends S.Class("A")({ a: S.String }) {} - expect(A.identifier).toEqual("A") + strictEqual(A.identifier, "A") }) it("should add an identifier annotation", () => { class A extends S.Class("MyName")({ a: S.String }) {} - expect(A.ast.to.annotations[AST.IdentifierAnnotationId]).toEqual("MyName") + strictEqual(A.ast.to.annotations[AST.IdentifierAnnotationId], "MyName") }) describe("constructor", () => { it("should be a constructor", () => { class A extends S.Class("A")({ a: S.String }) {} const instance = new A({ a: "a" }) - expect(instance.a).toStrictEqual("a") - expect(instance instanceof A).toBe(true) + strictEqual(instance.a, "a") + assertTrue(instance instanceof A) }) it("should validate the input by default", () => { class A extends S.Class("A")({ a: S.NonEmptyString }) {} - expect(() => new A({ a: "" })).toThrow( - new Error(`A (Constructor) + Util.assertParseError( + () => new A({ a: "" }), + `A (Constructor) └─ ["a"] └─ NonEmptyString └─ Predicate refinement failure - └─ Expected a non empty string, actual ""`) + └─ Expected a non empty string, actual ""` ) - expect(() => A.make({ a: "" })).toThrow( - new Error(`A (Constructor) + Util.assertParseError( + () => A.make({ a: "" }), + `A (Constructor) └─ ["a"] └─ NonEmptyString └─ Predicate refinement failure - └─ Expected a non empty string, actual ""`) + └─ Expected a non empty string, actual ""` ) }) it("validation can be disabled", () => { class A extends S.Class("A")({ a: S.NonEmptyString }) {} - expect(new A({ a: "" }, true).a).toStrictEqual("") - expect(new A({ a: "" }, { disableValidation: true }).a).toStrictEqual("") + strictEqual(new A({ a: "" }, true).a, "") + strictEqual(new A({ a: "" }, { disableValidation: true }).a, "") - expect(A.make({ a: "" }, true).a).toStrictEqual("") - expect(A.make({ a: "" }, { disableValidation: true }).a).toStrictEqual("") + strictEqual(A.make({ a: "" }, true).a, "") + strictEqual(A.make({ a: "" }, { disableValidation: true }).a, "") }) it("should support defaults", () => { @@ -120,15 +112,15 @@ describe("Class", () => { a: S.propertySignature(S.String).pipe(S.withConstructorDefault(() => "")), [b]: S.propertySignature(S.Number).pipe(S.withConstructorDefault(() => 1)) }) {} - expect({ ...new A({ a: "a", [b]: 2 }) }).toStrictEqual({ a: "a", [b]: 2 }) - expect({ ...new A({ a: "a" }) }).toStrictEqual({ a: "a", [b]: 1 }) - expect({ ...new A({ [b]: 2 }) }).toStrictEqual({ a: "", [b]: 2 }) - expect({ ...new A({}) }).toStrictEqual({ a: "", [b]: 1 }) - - expect({ ...A.make({ a: "a", [b]: 2 }) }).toStrictEqual({ a: "a", [b]: 2 }) - expect({ ...A.make({ a: "a" }) }).toStrictEqual({ a: "a", [b]: 1 }) - expect({ ...A.make({ [b]: 2 }) }).toStrictEqual({ a: "", [b]: 2 }) - expect({ ...A.make({}) }).toStrictEqual({ a: "", [b]: 1 }) + deepStrictEqual({ ...new A({ a: "a", [b]: 2 }) }, { a: "a", [b]: 2 }) + deepStrictEqual({ ...new A({ a: "a" }) }, { a: "a", [b]: 1 }) + deepStrictEqual({ ...new A({ [b]: 2 }) }, { a: "", [b]: 2 }) + deepStrictEqual({ ...new A({}) }, { a: "", [b]: 1 }) + + deepStrictEqual({ ...A.make({ a: "a", [b]: 2 }) }, { a: "a", [b]: 2 }) + deepStrictEqual({ ...A.make({ a: "a" }) }, { a: "a", [b]: 1 }) + deepStrictEqual({ ...A.make({ [b]: 2 }) }, { a: "", [b]: 2 }) + deepStrictEqual({ ...A.make({}) }, { a: "", [b]: 1 }) }) it("should support lazy defaults", () => { @@ -136,58 +128,58 @@ describe("Class", () => { class A extends S.Class("A")({ a: S.propertySignature(S.Number).pipe(S.withConstructorDefault(() => ++i)) }) {} - expect({ ...new A({}) }).toStrictEqual({ a: 1 }) - expect({ ...new A({}) }).toStrictEqual({ a: 2 }) + deepStrictEqual({ ...new A({}) }, { a: 1 }) + deepStrictEqual({ ...new A({}) }, { a: 2 }) new A({ a: 10 }) - expect({ ...new A({}) }).toStrictEqual({ a: 3 }) + deepStrictEqual({ ...new A({}) }, { a: 3 }) - expect({ ...A.make({}) }).toStrictEqual({ a: 4 }) - expect({ ...A.make({}) }).toStrictEqual({ a: 5 }) + deepStrictEqual({ ...A.make({}) }, { a: 4 }) + deepStrictEqual({ ...A.make({}) }, { a: 5 }) new A({ a: 10 }) - expect({ ...A.make({}) }).toStrictEqual({ a: 6 }) + deepStrictEqual({ ...A.make({}) }, { a: 6 }) }) it("should treat `undefined` as missing field", () => { class A extends S.Class("A")({ a: S.propertySignature(S.UndefinedOr(S.String)).pipe(S.withConstructorDefault(() => "")) }) {} - expect({ ...new A({}) }).toStrictEqual({ a: "" }) - expect({ ...new A({ a: undefined }) }).toStrictEqual({ a: "" }) + deepStrictEqual({ ...new A({}) }, { a: "" }) + deepStrictEqual({ ...new A({ a: undefined }) }, { a: "" }) - expect({ ...A.make({}) }).toStrictEqual({ a: "" }) - expect({ ...A.make({ a: undefined }) }).toStrictEqual({ a: "" }) + deepStrictEqual({ ...A.make({}) }, { a: "" }) + deepStrictEqual({ ...A.make({ a: undefined }) }, { a: "" }) }) it("should accept void if the Class has no fields", () => { class A extends S.Class("A")({}) {} - expect({ ...new A() }).toStrictEqual({}) - expect({ ...new A(undefined) }).toStrictEqual({}) - expect({ ...new A(undefined, true) }).toStrictEqual({}) - expect({ ...new A(undefined, false) }).toStrictEqual({}) - expect({ ...new A({}) }).toStrictEqual({}) - - expect({ ...A.make() }).toStrictEqual({}) - expect({ ...A.make(undefined) }).toStrictEqual({}) - expect({ ...A.make(undefined, true) }).toStrictEqual({}) - expect({ ...A.make(undefined, false) }).toStrictEqual({}) - expect({ ...A.make({}) }).toStrictEqual({}) + deepStrictEqual({ ...new A() }, {}) + deepStrictEqual({ ...new A(undefined) }, {}) + deepStrictEqual({ ...new A(undefined, true) }, {}) + deepStrictEqual({ ...new A(undefined, false) }, {}) + deepStrictEqual({ ...new A({}) }, {}) + + deepStrictEqual({ ...A.make() }, {}) + deepStrictEqual({ ...A.make(undefined) }, {}) + deepStrictEqual({ ...A.make(undefined, true) }, {}) + deepStrictEqual({ ...A.make(undefined, false) }, {}) + deepStrictEqual({ ...A.make({}) }, {}) }) it("should accept void if the Class has all the fields with a default", () => { class A extends S.Class("A")({ a: S.String.pipe(S.propertySignature, S.withConstructorDefault(() => "")) }) {} - expect({ ...new A() }).toStrictEqual({ a: "" }) - expect({ ...new A(undefined) }).toStrictEqual({ a: "" }) - expect({ ...new A(undefined, true) }).toStrictEqual({ a: "" }) - expect({ ...new A(undefined, false) }).toStrictEqual({ a: "" }) - expect({ ...new A({}) }).toStrictEqual({ a: "" }) - - expect({ ...A.make() }).toStrictEqual({ a: "" }) - expect({ ...A.make(undefined) }).toStrictEqual({ a: "" }) - expect({ ...A.make(undefined, true) }).toStrictEqual({ a: "" }) - expect({ ...A.make(undefined, false) }).toStrictEqual({ a: "" }) - expect({ ...A.make({}) }).toStrictEqual({ a: "" }) + deepStrictEqual({ ...new A() }, { a: "" }) + deepStrictEqual({ ...new A(undefined) }, { a: "" }) + deepStrictEqual({ ...new A(undefined, true) }, { a: "" }) + deepStrictEqual({ ...new A(undefined, false) }, { a: "" }) + deepStrictEqual({ ...new A({}) }, { a: "" }) + + deepStrictEqual({ ...A.make() }, { a: "" }) + deepStrictEqual({ ...A.make(undefined) }, { a: "" }) + deepStrictEqual({ ...A.make(undefined, true) }, { a: "" }) + deepStrictEqual({ ...A.make(undefined, false) }, { a: "" }) + deepStrictEqual({ ...A.make({}) }, { a: "" }) }) }) @@ -197,7 +189,7 @@ describe("Class", () => { return `method: ${this.a} ${b}` } } - expect(new A({ a: "a" }).method("b")).toEqual("method: a b") + strictEqual(new A({ a: "a" }).method("b"), "method: a b") }) it("should support getters", () => { @@ -206,29 +198,29 @@ describe("Class", () => { return `getter: ${this.a}` } } - expect(new A({ a: "a" }).getter).toEqual("getter: a") + strictEqual(new A({ a: "a" }).getter, "getter: a") }) it("using S.annotations() on a Class should return a Schema", () => { class A extends S.Class("A")({ a: S.String }) {} const schema = A.pipe(S.annotations({ title: "X" })) - expect(S.isSchema(schema)).toEqual(true) - expect(schema.ast._tag).toEqual("Transformation") - expect(schema.ast.annotations[AST.TitleAnnotationId]).toEqual("X") + assertTrue(S.isSchema(schema)) + strictEqual(schema.ast._tag, "Transformation") + strictEqual(schema.ast.annotations[AST.TitleAnnotationId], "X") }) it("using the .annotations() method of a Class should return a Schema", () => { class A extends S.Class("A")({ a: S.String }) {} const schema = A.annotations({ title: "X" }) - expect(S.isSchema(schema)).toEqual(true) - expect(schema.ast._tag).toEqual("Transformation") - expect(schema.ast.annotations[AST.TitleAnnotationId]).toEqual("X") + assertTrue(S.isSchema(schema)) + strictEqual(schema.ast._tag, "Transformation") + strictEqual(schema.ast.annotations[AST.TitleAnnotationId], "X") }) it("default toString()", () => { const b = Symbol.for("b") class A extends S.Class("A")({ a: S.String, [b]: S.Number }) {} - expect(String(new A({ a: "a", [b]: 1 }))).toBe(`A({ "a": "a", Symbol(b): 1 })`) + strictEqual(String(new A({ a: "a", [b]: 1 })), `A({ "a": "a", Symbol(b): 1 })`) }) it("decoding", async () => { @@ -273,10 +265,11 @@ describe("Class", () => { it("duplicated fields should not be allowed when extending with extend()", () => { class A extends S.Class("A")({ a: S.String }) {} - expect(() => { - class A2 extends A.extend("A2")({ a: S.String }) {} - A2 - }).toThrow( + throws( + () => { + class A2 extends A.extend("A2")({ a: S.String }) {} + A2 + }, new Error(`Duplicate property signature details: Duplicate key "a"`) ) @@ -294,7 +287,7 @@ details: Duplicate key "a"`) b: S.String, c: S.Boolean }) - expect({ ...new C({ a: "a", b: "b", c: true }) }).toStrictEqual({ a: "a", b: "b", c: true }) + deepStrictEqual({ ...new C({ a: "a", b: "b", c: true }) }, { a: "a", b: "b", c: true }) }) it("can be extended with TaggedClass fields", () => { @@ -310,7 +303,7 @@ details: Duplicate key "a"`) b: S.String, c: S.Boolean }) - expect({ ...new D({ a: "a", b: "b", c: true }) }).toStrictEqual({ _tag: "D", a: "a", b: "b", c: true }) + deepStrictEqual({ ...new D({ a: "a", b: "b", c: true }) }, { _tag: "D", a: "a", b: "b", c: true }) }) it("S.typeSchema(Class)", async () => { @@ -325,8 +318,8 @@ details: Duplicate key "a"`) it("is", () => { const is = S.is(S.typeSchema(Person)) - expect(is(new Person({ id: 1, name: "name" }))).toEqual(true) - expect(is({ id: 1, name: "name" })).toEqual(false) + assertTrue(is(new Person({ id: 1, name: "name" }))) + assertFalse(is({ id: 1, name: "name" })) }) it("with a field with a context !== never", async () => { @@ -339,7 +332,7 @@ details: Duplicate key "a"`) Effect.provideService(Name, "John"), Effect.runSync ) - expect(person.name).toEqual("John") + strictEqual(person.name, "John") const PersonFromSelf = S.typeSchema(Person) await Util.assertions.decoding.succeed(PersonFromSelf, new Person({ id: 1, name: "John" })) @@ -372,10 +365,11 @@ details: Duplicate key "a"`) └─ Predicate refinement failure └─ a should be equal to b` ) - expect(() => new A({ a: 1, b: 2 })).toThrow( - new Error(`A (Constructor) + Util.assertParseError( + () => new A({ a: 1, b: 2 }), + `A (Constructor) └─ Predicate refinement failure - └─ a should be equal to b`) + └─ a should be equal to b` ) }) @@ -383,24 +377,22 @@ details: Duplicate key "a"`) const person = new Person({ id: 1, name: "John" }) const personAge = new PersonWithAge({ id: 1, name: "John", age: 30 }) - expect(String(person)).toEqual(`Person({ "id": 1, "name": "John" })`) - expect(String(personAge)).toEqual(`PersonWithAge({ "id": 1, "name": "John", "age": 30 })`) + strictEqual(String(person), `Person({ "id": 1, "name": "John" })`) + strictEqual(String(personAge), `PersonWithAge({ "id": 1, "name": "John", "age": 30 })`) - expect(person instanceof Data.Class).toEqual(true) - expect(personAge instanceof Data.Class).toEqual(true) + assertTrue(person instanceof Data.Class) + assertTrue(personAge instanceof Data.Class) const person2 = new Person({ id: 1, name: "John" }) - expect(Equal.equals(person, person2)).toEqual(true) + assertTrue(Equal.equals(person, person2)) const person3 = new Person({ id: 2, name: "John" }) - expect(Equal.equals(person, person3)).toEqual(false) + assertFalse(Equal.equals(person, person3)) }) it("pretty", () => { const pretty = Pretty.make(Person) - expect(pretty(new Person({ id: 1, name: "John" }))).toEqual( - `Person({ "id": 1, "name": "John" })` - ) + strictEqual(pretty(new Person({ id: 1, name: "John" })), `Person({ "id": 1, "name": "John" })`) }) describe("encode", () => { @@ -487,8 +479,8 @@ details: Duplicate key "a"`) } } const a = A.make({ n: 1 }) - expect(a instanceof A).toEqual(true) - expect(a.a()).toEqual("1a") + assertTrue(a instanceof A) + strictEqual(a.a(), "1a") }) describe("should support annotations when declaring the Class", () => { @@ -497,7 +489,7 @@ details: Duplicate key "a"`) a: S.NonEmptyString }, { title: "mytitle" }) {} - expect(A.ast.to.annotations[AST.TitleAnnotationId]).toEqual("mytitle") + strictEqual(A.ast.to.annotations[AST.TitleAnnotationId], "mytitle") await Util.assertions.encoding.fail( A, @@ -523,9 +515,9 @@ details: Duplicate key "a"`) { identifier: "EncodedID" } ] ) {} - expect(AST.getIdentifierAnnotation(A.ast.to)).toEqual(Option.some("TypeID")) - expect(AST.getIdentifierAnnotation(A.ast)).toEqual(Option.some("TransformationID")) - expect(AST.getIdentifierAnnotation(A.ast.from)).toEqual(Option.some("EncodedID")) + assertSome(AST.getIdentifierAnnotation(A.ast.to), "TypeID") + assertSome(AST.getIdentifierAnnotation(A.ast), "TransformationID") + assertSome(AST.getIdentifierAnnotation(A.ast.from), "EncodedID") await Util.assertions.decoding.fail( A, @@ -559,7 +551,7 @@ details: Duplicate key "a"`) └─ is missing` ) - expect(JSONSchema.make(S.typeSchema(A))).toStrictEqual({ + deepStrictEqual(JSONSchema.make(S.typeSchema(A)), { "$defs": { "NonEmptyString": { "title": "nonEmptyString", @@ -585,33 +577,31 @@ details: Duplicate key "a"`) "$schema": "http://json-schema.org/draft-07/schema#" }) - expect(JSONSchema.make(A)).toStrictEqual( - { - "$defs": { - "NonEmptyString": { - "title": "nonEmptyString", - "description": "a non empty string", - "minLength": 1, - "type": "string" - }, - "TransformationID": { - "additionalProperties": false, - "description": "TypeDescription", - "properties": { - "a": { - "$ref": "#/$defs/NonEmptyString" - } - }, - "required": [ - "a" - ], - "type": "object" - } + deepStrictEqual(JSONSchema.make(A), { + "$defs": { + "NonEmptyString": { + "title": "nonEmptyString", + "description": "a non empty string", + "minLength": 1, + "type": "string" }, - "$ref": "#/$defs/TransformationID", - "$schema": "http://json-schema.org/draft-07/schema#" - } - ) + "TransformationID": { + "additionalProperties": false, + "description": "TypeDescription", + "properties": { + "a": { + "$ref": "#/$defs/NonEmptyString" + } + }, + "required": [ + "a" + ], + "type": "object" + } + }, + "$ref": "#/$defs/TransformationID", + "$schema": "http://json-schema.org/draft-07/schema#" + }) }) }) }) diff --git a/packages/effect/test/Schema/Schema/Class/TaggedClass.test.ts b/packages/effect/test/Schema/Schema/Class/TaggedClass.test.ts index b31bfa001ce..5e3d12a5203 100644 --- a/packages/effect/test/Schema/Schema/Class/TaggedClass.test.ts +++ b/packages/effect/test/Schema/Schema/Class/TaggedClass.test.ts @@ -1,48 +1,50 @@ import { pipe, Struct } from "effect" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, deepStrictEqual, strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" describe("TaggedClass", () => { it("the constructor should add a `_tag` field", () => { class TA extends S.TaggedClass()("TA", { a: S.String }) {} - expect({ ...new TA({ a: "a" }) }).toStrictEqual({ _tag: "TA", a: "a" }) + deepStrictEqual({ ...new TA({ a: "a" }) }, { _tag: "TA", a: "a" }) }) it("should expose the fields and the tag", () => { class TA extends S.TaggedClass()("TA", { a: S.String }) {} Util.expectFields(TA.fields, { _tag: S.getClassTag("TA"), a: S.String }) - expect(S.Struct(TA.fields).make({ a: "a" })).toStrictEqual({ _tag: "TA", a: "a" }) - expect(TA._tag).toBe("TA") + deepStrictEqual(S.Struct(TA.fields).make({ a: "a" }), { _tag: "TA", a: "a" }) + strictEqual(TA._tag, "TA") }) it("should expose the identifier", () => { class TA extends S.TaggedClass()("TA", { a: S.String }) {} - expect(TA.identifier).toEqual("TA") + strictEqual(TA.identifier, "TA") class TB extends S.TaggedClass("id")("TB", { a: S.String }) {} - expect(TB.identifier).toEqual("id") + strictEqual(TB.identifier, "id") }) it("constructor parameters should not overwrite the tag", async () => { class A extends S.TaggedClass()("A", { a: S.String }) {} - expect(new A({ ...{ _tag: "B", a: "a" } })._tag).toBe("A") - expect(new A({ ...{ _tag: "B", a: "a" } }, true)._tag).toBe("A") + strictEqual(new A({ ...{ _tag: "B", a: "a" } })._tag, "A") + strictEqual(new A({ ...{ _tag: "B", a: "a" } }, true)._tag, "A") }) it("a TaggedClass with no fields should have a void constructor", () => { class TA extends S.TaggedClass()("TA", {}) {} - expect({ ...new TA() }).toStrictEqual({ _tag: "TA" }) - expect({ ...new TA(undefined) }).toStrictEqual({ _tag: "TA" }) - expect({ ...new TA(undefined, true) }).toStrictEqual({ _tag: "TA" }) + deepStrictEqual({ ...new TA() }, { _tag: "TA" }) + deepStrictEqual({ ...new TA(undefined) }, { _tag: "TA" }) + deepStrictEqual({ ...new TA(undefined, true) }, { _tag: "TA" }) }) it("a custom _tag field should be not allowed", () => { - expect(() => { - class _TA extends S.TaggedClass<_TA>()("TA", { _tag: S.Literal("X"), a: S.String }) {} - _TA - }).toThrow( + throws( + () => { + class _TA extends S.TaggedClass<_TA>()("TA", { _tag: S.Literal("X"), a: S.String }) {} + _TA + }, new Error(`Duplicate property signature details: Duplicate key "_tag"`) ) @@ -71,10 +73,11 @@ details: Duplicate key "_tag"`) └─ Predicate refinement failure └─ a should be equal to b` ) - expect(() => new A({ a: 1, b: 2 })).toThrow( - new Error(`A (Constructor) + Util.assertParseError( + () => new A({ a: 1, b: 2 }), + `A (Constructor) └─ Predicate refinement failure - └─ a should be equal to b`) + └─ a should be equal to b` ) }) @@ -131,7 +134,7 @@ details: Duplicate key "_tag"`) a: S.String, b: S.Number }) - expect({ ...new B({ _tag: "TA", a: "a", b: 1 }) }).toStrictEqual({ _tag: "TA", a: "a", b: 1 }) + deepStrictEqual({ ...new B({ _tag: "TA", a: "a", b: 1 }) }, { _tag: "TA", a: "a", b: 1 }) }) it("can be extended with TaggedClass fields", () => { @@ -145,7 +148,7 @@ details: Duplicate key "_tag"`) a: S.String, b: S.Number }) - expect({ ...new TB({ a: "a", b: 1 }) }).toStrictEqual({ _tag: "TB", a: "a", b: 1 }) + deepStrictEqual({ ...new TB({ a: "a", b: 1 }) }, { _tag: "TB", a: "a", b: 1 }) }) it("equivalence", () => { @@ -153,18 +156,18 @@ details: Duplicate key "_tag"`) a: S.String }) {} const eqA = S.equivalence(A) - expect(eqA(new A({ a: "a" }), new A({ a: "a" }))).toBe(true) - expect(eqA(new A({ a: "a" }), new A({ a: "b" }))).toBe(false) + assertTrue(eqA(new A({ a: "a" }), new A({ a: "a" }))) + assertFalse(eqA(new A({ a: "a" }), new A({ a: "b" }))) class B extends S.TaggedClass()("B", { b: S.Number, as: S.Array(A) }) {} const eqB = S.equivalence(B) - expect(eqB(new B({ b: 1, as: [] }), new B({ b: 1, as: [] }))).toBe(true) - expect(eqB(new B({ b: 1, as: [] }), new B({ b: 2, as: [] }))).toBe(false) - expect(eqB(new B({ b: 1, as: [new A({ a: "a" })] }), new B({ b: 1, as: [new A({ a: "a" })] }))).toBe(true) - expect(eqB(new B({ b: 1, as: [new A({ a: "a" })] }), new B({ b: 1, as: [new A({ a: "b" })] }))).toBe(false) + assertTrue(eqB(new B({ b: 1, as: [] }), new B({ b: 1, as: [] }))) + assertFalse(eqB(new B({ b: 1, as: [] }), new B({ b: 2, as: [] }))) + assertTrue(eqB(new B({ b: 1, as: [new A({ a: "a" })] }), new B({ b: 1, as: [new A({ a: "a" })] }))) + assertFalse(eqB(new B({ b: 1, as: [new A({ a: "a" })] }), new B({ b: 1, as: [new A({ a: "b" })] }))) }) it("baseline", () => { @@ -187,20 +190,17 @@ details: Duplicate key "_tag"`) let person = new TaggedPersonWithAge({ id: 1, name: "John", age: 30 }) - expect(String(person)).toEqual( - `TaggedPersonWithAge({ "_tag": "TaggedPerson", "id": 1, "name": "John", "age": 30 })` - ) - expect(person._tag).toEqual("TaggedPerson") - expect(person.upperName).toEqual("JOHN") + strictEqual(String(person), `TaggedPersonWithAge({ "_tag": "TaggedPerson", "id": 1, "name": "John", "age": 30 })`) + strictEqual(person._tag, "TaggedPerson") + strictEqual(person.upperName, "JOHN") - expect(() => S.decodeUnknownSync(TaggedPersonWithAge)({ id: 1, name: "John", age: 30 })).toThrow( - new Error( - `(TaggedPersonWithAge (Encoded side) <-> TaggedPersonWithAge) + Util.assertParseError( + () => S.decodeUnknownSync(TaggedPersonWithAge)({ id: 1, name: "John", age: 30 }), + `(TaggedPersonWithAge (Encoded side) <-> TaggedPersonWithAge) └─ Encoded side transformation failure └─ TaggedPersonWithAge (Encoded side) └─ ["_tag"] └─ is missing` - ) ) person = S.decodeUnknownSync(TaggedPersonWithAge)({ _tag: "TaggedPerson", @@ -208,8 +208,8 @@ details: Duplicate key "_tag"`) name: "John", age: 30 }) - expect(person._tag).toEqual("TaggedPerson") - expect(person.upperName).toEqual("JOHN") + strictEqual(person._tag, "TaggedPerson") + strictEqual(person.upperName, "JOHN") }) it("should expose a make constructor", () => { @@ -221,8 +221,8 @@ details: Duplicate key "_tag"`) } } const ta = TA.make({ n: 1 }) - expect(ta instanceof TA).toEqual(true) - expect(ta._tag).toEqual("TA") - expect(ta.a()).toEqual("1a") + assertTrue(ta instanceof TA) + strictEqual(ta._tag, "TA") + strictEqual(ta.a(), "1a") }) }) diff --git a/packages/effect/test/Schema/Schema/Class/TaggedError.test.ts b/packages/effect/test/Schema/Schema/Class/TaggedError.test.ts index 7de9225297e..82e748532ae 100644 --- a/packages/effect/test/Schema/Schema/Class/TaggedError.test.ts +++ b/packages/effect/test/Schema/Schema/Class/TaggedError.test.ts @@ -1,14 +1,15 @@ import { Cause, Effect, Inspectable, Schema } from "effect" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("TaggedError", () => { it("should expose the fields and the tag", () => { class TE extends S.TaggedError()("TE", { a: S.String }) {} Util.expectFields(TE.fields, { _tag: S.getClassTag("TE"), a: S.String }) - expect(S.Struct(TE.fields).make({ a: "a" })).toStrictEqual({ _tag: "TE", a: "a" }) - expect(TE._tag).toBe("TE") + deepStrictEqual(S.Struct(TE.fields).make({ a: "a" }), { _tag: "TE", a: "a" }) + strictEqual(TE._tag, "TE") }) it("should accept a Struct as argument", () => { @@ -34,10 +35,11 @@ describe("TaggedError", () => { └─ Predicate refinement failure └─ a should be equal to b` ) - expect(() => new A({ a: 1, b: 2 })).toThrow( - new Error(`A (Constructor) + Util.assertParseError( + () => new A({ a: 1, b: 2 }), + `A (Constructor) └─ Predicate refinement failure - └─ a should be equal to b`) + └─ a should be equal to b` ) }) @@ -48,18 +50,18 @@ describe("TaggedError", () => { let err = new MyError({ id: 1 }) - expect(String(err)).toEqual(`MyError: { "id": 1 }`) - expect(err.stack).toContain("TaggedError.test.ts:") - expect(err._tag).toEqual("MyError") - expect(err.id).toEqual(1) + strictEqual(String(err), `MyError: { "id": 1 }`) + assertTrue(err.stack?.includes("TaggedError.test.ts:")) + strictEqual(err._tag, "MyError") + strictEqual(err.id, 1) err = Effect.runSync(Effect.flip(err)) - expect(err._tag).toEqual("MyError") - expect(err.id).toEqual(1) + strictEqual(err._tag, "MyError") + strictEqual(err.id, 1) err = S.decodeUnknownSync(MyError)({ _tag: "MyError", id: 1 }) - expect(err._tag).toEqual("MyError") - expect(err.id).toEqual(1) + strictEqual(err._tag, "MyError") + strictEqual(err.id, 1) }) it("message", () => { @@ -73,10 +75,10 @@ describe("TaggedError", () => { const err = new MyError({ id: 1 }) - expect(String(err).includes(`MyError: bad id: 1`)).toBe(true) - expect(err.stack).toContain("TaggedError.test.ts:") - expect(err._tag).toEqual("MyError") - expect(err.id).toEqual(1) + assertTrue(String(err).includes(`MyError: bad id: 1`)) + assertTrue(err.stack?.includes("TaggedError.test.ts:")) + strictEqual(err._tag, "MyError") + strictEqual(err.id, 1) }) it("message field", () => { @@ -88,10 +90,10 @@ describe("TaggedError", () => { const err = new MyError({ id: 1, message: "boom" }) - expect(String(err).includes(`MyError: boom`)).toBe(true) - expect(err.stack).toContain("TaggedError.test.ts:") - expect(err._tag).toEqual("MyError") - expect(err.id).toEqual(1) + assertTrue(String(err).includes(`MyError: boom`)) + assertTrue(err.stack?.includes("TaggedError.test.ts:")) + strictEqual(err._tag, "MyError") + strictEqual(err.id, 1) }) it("should expose a make constructor", () => { @@ -103,9 +105,9 @@ describe("TaggedError", () => { } } const a = A.make({ n: 1 }) - expect(a instanceof A).toEqual(true) - expect(a._tag).toEqual("A") - expect(a.a()).toEqual("1a") + assertTrue(a instanceof A) + strictEqual(a._tag, "A") + strictEqual(a.a(), "1a") }) it("cause", () => { @@ -114,8 +116,8 @@ describe("TaggedError", () => { }) {} const err = new MyError({ cause: new Error("child") }) - expect(Cause.pretty(Cause.fail(err), { renderErrorCause: true })).includes("[cause]: Error: child") + assertTrue(Cause.pretty(Cause.fail(err), { renderErrorCause: true }).includes("[cause]: Error: child")) // ensure node renders the error directly - expect(err[Inspectable.NodeInspectSymbol]()).toEqual(err) + deepStrictEqual(err[Inspectable.NodeInspectSymbol](), err) }) }) diff --git a/packages/effect/test/Schema/Schema/Class/TaggedRequest.test.ts b/packages/effect/test/Schema/Schema/Class/TaggedRequest.test.ts index b8a976ee781..eb1c73d6a5d 100644 --- a/packages/effect/test/Schema/Schema/Class/TaggedRequest.test.ts +++ b/packages/effect/test/Schema/Schema/Class/TaggedRequest.test.ts @@ -4,7 +4,8 @@ import * as ParseResult from "effect/ParseResult" import * as Request from "effect/Request" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { assert, describe, expect, it } from "vitest" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" const Name = Context.GenericTag<"Name", string>("Name") const NameString = S.String.pipe( @@ -54,9 +55,9 @@ describe("TaggedRequest", () => { _tag: S.getClassTag("TRA"), id: S.Number }) - expect(TRA._tag).toBe("TRA") - expect(TRA.success).toBe(S.Number) - expect(TRA.failure).toBe(S.String) + strictEqual(TRA._tag, "TRA") + strictEqual(TRA.success, S.Number) + strictEqual(TRA.failure, S.String) }) it("should expose the identifier", () => { @@ -67,7 +68,7 @@ describe("TaggedRequest", () => { id: S.Number } }) {} - expect(TRA.identifier).toEqual("TRA") + strictEqual(TRA.identifier, "TRA") class TRB extends S.TaggedRequest("id")("TRB", { failure: S.String, success: S.Number, @@ -75,7 +76,7 @@ describe("TaggedRequest", () => { id: S.Number } }) {} - expect(TRB.identifier).toEqual("id") + strictEqual(TRB.identifier, "id") }) it("baseline", () => { @@ -89,15 +90,15 @@ describe("TaggedRequest", () => { let req = new MyRequest({ id: 1 }) - expect(String(req)).toEqual(`MyRequest({ "_tag": "MyRequest", "id": 1 })`) - expect(req._tag).toEqual("MyRequest") - expect(req.id).toEqual(1) - expect(Request.isRequest(req)).toEqual(true) + strictEqual(String(req), `MyRequest({ "_tag": "MyRequest", "id": 1 })`) + strictEqual(req._tag, "MyRequest") + strictEqual(req.id, 1) + assertTrue(Request.isRequest(req)) req = S.decodeSync(MyRequest)({ _tag: "MyRequest", id: 1 }) - expect(req._tag).toEqual("MyRequest") - expect(req.id).toEqual(1) - expect(Request.isRequest(req)).toEqual(true) + strictEqual(req._tag, "MyRequest") + strictEqual(req.id, 1) + assertTrue(Request.isRequest(req)) }) it("TaggedRequest extends SerializableWithExit", () => { @@ -110,28 +111,28 @@ describe("TaggedRequest", () => { }) {} const req = new MyRequest({ id: 1 }) - assert.deepStrictEqual( + deepStrictEqual( S.serialize(req).pipe(Effect.runSync), { _tag: "MyRequest", id: 1 } ) - assert(Equal.equals( + assertTrue(Equal.equals( S.deserialize(req, { _tag: "MyRequest", id: 1 }).pipe(Effect.runSync), req )) - assert.deepStrictEqual( + deepStrictEqual( S.serializeExit(req, Exit.fail("fail")).pipe(Effect.runSync), { _tag: "Failure", cause: { _tag: "Fail", error: "fail" } } ) - assert.deepStrictEqual( + deepStrictEqual( S.deserializeExit(req, { _tag: "Failure", cause: { _tag: "Fail", error: "fail" } }) .pipe(Effect.runSync), Exit.fail("fail") ) - assert.deepStrictEqual( + deepStrictEqual( S.serializeExit(req, Exit.succeed(123)).pipe(Effect.runSync), { _tag: "Success", value: "123" } ) - assert.deepStrictEqual( + deepStrictEqual( S.deserializeExit(req, { _tag: "Success", value: "123" }).pipe(Effect.runSync), Exit.succeed(123) ) @@ -147,36 +148,36 @@ describe("TaggedRequest", () => { }) {} let req = new MyRequest({ id: 1 }, true) - expect(String(req)).toEqual(`MyRequest({ "_tag": "MyRequest", "id": 1 })`) + strictEqual(String(req), `MyRequest({ "_tag": "MyRequest", "id": 1 })`) req = S.decode(MyRequest)({ _tag: "MyRequest", id: 1 }).pipe( Effect.provideService(Id, 1), Effect.runSync ) - expect(String(req)).toEqual(`MyRequest({ "_tag": "MyRequest", "id": 1 })`) + strictEqual(String(req), `MyRequest({ "_tag": "MyRequest", "id": 1 })`) - assert.deepStrictEqual( + deepStrictEqual( S.serialize(req).pipe( Effect.provideService(Id, 1), Effect.runSync ), { _tag: "MyRequest", id: 1 } ) - assert.deepStrictEqual( + deepStrictEqual( S.deserialize(req, { _tag: "MyRequest", id: 1 }).pipe( Effect.provideService(Id, 1), Effect.runSync ), req ) - assert.deepStrictEqual( + deepStrictEqual( S.serializeExit(req, Exit.fail("fail")).pipe( Effect.provideService(Name, "fail"), Effect.runSync ), { _tag: "Failure", cause: { _tag: "Fail", error: "fail" } } ) - assert.deepStrictEqual( + deepStrictEqual( S.deserializeExit(req, { _tag: "Failure", cause: { _tag: "Fail", error: "fail" } }) .pipe( Effect.provideService(Name, "fail"), @@ -199,8 +200,8 @@ describe("TaggedRequest", () => { } } const tra = TRA.make({ n: 1 }) - expect(tra instanceof TRA).toEqual(true) - expect(tra._tag).toEqual("TRA") - expect(tra.a()).toEqual("1a") + assertTrue(tra instanceof TRA) + strictEqual(tra._tag, "TRA") + strictEqual(tra.a(), "1a") }) }) diff --git a/packages/effect/test/Schema/Schema/Class/extend.test.ts b/packages/effect/test/Schema/Schema/Class/extend.test.ts index a8a1b5056ae..d16f0abd1a4 100644 --- a/packages/effect/test/Schema/Schema/Class/extend.test.ts +++ b/packages/effect/test/Schema/Schema/Class/extend.test.ts @@ -1,6 +1,7 @@ -import { JSONSchema, Option, Schema as S, SchemaAST as AST } from "effect" +import { JSONSchema, Schema as S, SchemaAST as AST } from "effect" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertSome, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" class Person extends S.Class("Person")({ id: S.Number, @@ -30,16 +31,16 @@ describe("extend", () => { name: "John", age: 30 }) - expect(PersonWithAge.fields).toStrictEqual({ + deepStrictEqual(PersonWithAge.fields, { ...Person.fields, age: S.Number }) - expect(PersonWithAge.identifier).toStrictEqual("PersonWithAge") - expect(person.name).toEqual("John") - expect(person.age).toEqual(30) - expect(person.isAdult).toEqual(true) - expect(person.upperName).toEqual("JOHN") - expect(typeof person.upperName).toEqual("string") + strictEqual(PersonWithAge.identifier, "PersonWithAge") + strictEqual(person.name, "John") + strictEqual(person.age, 30) + strictEqual(person.isAdult, true) + strictEqual(person.upperName, "JOHN") + strictEqual(typeof person.upperName, "string") }) it("2 extend", () => { @@ -49,8 +50,8 @@ describe("extend", () => { age: 30, nick: "Joe" }) - expect(person.age).toEqual(30) - expect(person.nick).toEqual("Joe") + strictEqual(person.age, 30) + strictEqual(person.nick, "Joe") }) it("should accept a Struct as argument", () => { @@ -79,10 +80,11 @@ describe("extend", () => { └─ Predicate refinement failure └─ a should be equal to b` ) - expect(() => new A({ base: "base", a: 1, b: 2 })).toThrow( - new Error(`A (Constructor) + Util.assertParseError( + () => new A({ base: "base", a: 1, b: 2 }), + `A (Constructor) └─ Predicate refinement failure - └─ a should be equal to b`) + └─ a should be equal to b` ) }) @@ -114,9 +116,9 @@ describe("extend", () => { } } const b = B.make({ n: 1, c: "c" }) - expect(b instanceof B).toEqual(true) - expect(b.a()).toEqual("1a") - expect(b.b()).toEqual("1b") + assertTrue(b instanceof B) + strictEqual(b.a(), "1a") + strictEqual(b.b(), "1b") }) it("users can override an instance member property", () => { @@ -134,7 +136,7 @@ describe("extend", () => { override readonly b = 2 } - expect(new OverrideExtended1({ a: "a", c: "c" }).b).toEqual(2) + strictEqual(new OverrideExtended1({ a: "a", c: "c" }).b, 2) }) it("users can override an instance member function", () => { @@ -156,7 +158,7 @@ describe("extend", () => { } } - expect(new OverrideExtended2({ a: "a", c: "c" }).b()).toEqual(2) + strictEqual(new OverrideExtended2({ a: "a", c: "c" }).b(), 2) }) it("users can override a field with an instance member property", () => { @@ -172,7 +174,7 @@ describe("extend", () => { override readonly a = "default" } - expect(new OverrideExtended3({ a: "a", c: "c" }).a).toEqual("default") + strictEqual(new OverrideExtended3({ a: "a", c: "c" }).a, "default") }) it("users can't override an instance member property with a field", () => { @@ -188,7 +190,7 @@ describe("extend", () => { b: S.Number }) {} - expect(new OverrideExtended4({ a: "a", b: 2 }).b).toEqual(1) + strictEqual(new OverrideExtended4({ a: "a", b: 2 }).b, 1) }) describe("should support annotations when declaring the Class", () => { @@ -200,7 +202,7 @@ describe("extend", () => { b: S.NonEmptyString }, { title: "mytitle" }) {} - expect(B.ast.to.annotations[AST.TitleAnnotationId]).toEqual("mytitle") + strictEqual(B.ast.to.annotations[AST.TitleAnnotationId], "mytitle") await Util.assertions.encoding.fail( B, @@ -226,9 +228,9 @@ describe("extend", () => { { identifier: "TransformationID" }, { identifier: "EncodedID" } ]) {} - expect(AST.getIdentifierAnnotation(B.ast.to)).toEqual(Option.some("TypeID")) - expect(AST.getIdentifierAnnotation(B.ast)).toEqual(Option.some("TransformationID")) - expect(AST.getIdentifierAnnotation(B.ast.from)).toEqual(Option.some("EncodedID")) + assertSome(AST.getIdentifierAnnotation(B.ast.to), "TypeID") + assertSome(AST.getIdentifierAnnotation(B.ast), "TransformationID") + assertSome(AST.getIdentifierAnnotation(B.ast.from), "EncodedID") await Util.assertions.decoding.fail( B, @@ -262,7 +264,7 @@ describe("extend", () => { └─ is missing` ) - expect(JSONSchema.make(S.typeSchema(B))).toStrictEqual({ + deepStrictEqual(JSONSchema.make(S.typeSchema(B)), { "$defs": { "NonEmptyString": { "title": "nonEmptyString", @@ -289,34 +291,32 @@ describe("extend", () => { "$schema": "http://json-schema.org/draft-07/schema#" }) - expect(JSONSchema.make(B)).toStrictEqual( - { - "$defs": { - "NonEmptyString": { - "title": "nonEmptyString", - "description": "a non empty string", - "minLength": 1, - "type": "string" - }, - "TransformationID": { - "additionalProperties": false, - "description": "TypeDescription", - "properties": { - "a": { - "$ref": "#/$defs/NonEmptyString" - }, - "b": { - "$ref": "#/$defs/NonEmptyString" - } - }, - "required": ["a", "b"], - "type": "object" - } + deepStrictEqual(JSONSchema.make(B), { + "$defs": { + "NonEmptyString": { + "title": "nonEmptyString", + "description": "a non empty string", + "minLength": 1, + "type": "string" }, - "$ref": "#/$defs/TransformationID", - "$schema": "http://json-schema.org/draft-07/schema#" - } - ) + "TransformationID": { + "additionalProperties": false, + "description": "TypeDescription", + "properties": { + "a": { + "$ref": "#/$defs/NonEmptyString" + }, + "b": { + "$ref": "#/$defs/NonEmptyString" + } + }, + "required": ["a", "b"], + "type": "object" + } + }, + "$ref": "#/$defs/TransformationID", + "$schema": "http://json-schema.org/draft-07/schema#" + }) }) }) }) diff --git a/packages/effect/test/Schema/Schema/Class/transformOrFail.test.ts b/packages/effect/test/Schema/Schema/Class/transformOrFail.test.ts index 5aa48fcc464..66854912bfd 100644 --- a/packages/effect/test/Schema/Schema/Class/transformOrFail.test.ts +++ b/packages/effect/test/Schema/Schema/Class/transformOrFail.test.ts @@ -2,7 +2,8 @@ import * as Option from "effect/Option" import * as ParseResult from "effect/ParseResult" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" class Person extends S.Class("Person")({ id: S.Number, @@ -45,16 +46,16 @@ describe("transformOrFail", () => { id: 1, name: "John" }) - expect(PersonWithTransform.fields).toStrictEqual({ + deepStrictEqual(PersonWithTransform.fields, { ...Person.fields, thing: Thing }) - expect(PersonWithTransform.identifier).toStrictEqual("PersonWithTransform") - expect(person.id).toEqual(1) - expect(person.name).toEqual("John") - expect(Option.isSome(person.thing) && person.thing.value.id === 123).toEqual(true) - expect(person.upperName).toEqual("JOHN") - expect(typeof person.upperName).toEqual("string") + strictEqual(PersonWithTransform.identifier, "PersonWithTransform") + strictEqual(person.id, 1) + strictEqual(person.name, "John") + assertTrue(Option.isSome(person.thing) && person.thing.value.id === 123) + strictEqual(person.upperName, "JOHN") + strictEqual(typeof person.upperName, "string") await Util.assertions.decoding.fail( PersonWithTransform, @@ -87,7 +88,7 @@ describe("transformOrFail", () => { it("should expose a make constructor", () => { const instance = PersonWithTransform.make({ id: 2, name: "John", thing: Option.some({ id: 1 }) }) - expect(instance instanceof PersonWithTransform).toEqual(true) - expect(instance.a()).toEqual("2a") + assertTrue(instance instanceof PersonWithTransform) + strictEqual(instance.a(), "2a") }) }) diff --git a/packages/effect/test/Schema/Schema/Class/transformOrFailFrom.test.ts b/packages/effect/test/Schema/Schema/Class/transformOrFailFrom.test.ts index 7244deadda4..3923b9638ad 100644 --- a/packages/effect/test/Schema/Schema/Class/transformOrFailFrom.test.ts +++ b/packages/effect/test/Schema/Schema/Class/transformOrFailFrom.test.ts @@ -2,7 +2,8 @@ import * as Option from "effect/Option" import * as ParseResult from "effect/ParseResult" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" class Person extends S.Class("Person")({ id: S.Number, @@ -45,16 +46,16 @@ describe("", () => { id: 1, name: "John" }) - expect(PersonWithTransformFrom.fields).toStrictEqual({ + deepStrictEqual(PersonWithTransformFrom.fields, { ...Person.fields, thing: Thing }) - expect(PersonWithTransformFrom.identifier).toStrictEqual("PersonWithTransformFrom") - expect(person.id).toEqual(1) - expect(person.name).toEqual("John") - expect(Option.isSome(person.thing) && person.thing.value.id === 123).toEqual(true) - expect(person.upperName).toEqual("JOHN") - expect(typeof person.upperName).toEqual("string") + strictEqual(PersonWithTransformFrom.identifier, "PersonWithTransformFrom") + strictEqual(person.id, 1) + strictEqual(person.name, "John") + assertTrue(Option.isSome(person.thing) && person.thing.value.id === 123) + strictEqual(person.upperName, "JOHN") + strictEqual(typeof person.upperName, "string") await Util.assertions.decoding.fail( PersonWithTransformFrom, @@ -81,7 +82,7 @@ describe("", () => { it("should expose a make constructor", () => { const instance = PersonWithTransformFrom.make({ id: 2, name: "John", thing: Option.some({ id: 1 }) }) - expect(instance instanceof PersonWithTransformFrom).toEqual(true) - expect(instance.a()).toEqual("2a") + assertTrue(instance instanceof PersonWithTransformFrom) + strictEqual(instance.a(), "2a") }) }) diff --git a/packages/effect/test/Schema/Schema/Config/Config.test.ts b/packages/effect/test/Schema/Schema/Config/Config.test.ts index 39401620da9..3404399390a 100644 --- a/packages/effect/test/Schema/Schema/Config/Config.test.ts +++ b/packages/effect/test/Schema/Schema/Config/Config.test.ts @@ -1,51 +1,40 @@ -import type * as Config from "effect/Config" -import * as ConfigError from "effect/ConfigError" -import * as ConfigProvider from "effect/ConfigProvider" -import * as Effect from "effect/Effect" -import * as Exit from "effect/Exit" -import * as Schema from "effect/Schema" -import { describe, expect, it } from "vitest" +import type { Config } from "effect" +import { Cause, ConfigError, ConfigProvider, Effect, Schema } from "effect" +import { assertFailure, assertSuccess } from "effect/test/util" +import { describe, it } from "vitest" /** * Asserts that loading a configuration with invalid data fails with the expected error. - * - * @param config - The configuration to load. - * @param map - The map of configuration values. - * @param error - The expected error. */ -const assertFailure = ( +const assertConfigFailure = ( config: Config.Config, map: ReadonlyArray, error: ConfigError.ConfigError ) => { const configProvider = ConfigProvider.fromMap(new Map(map)) const result = Effect.runSync(Effect.exit(configProvider.load(config))) - expect(result).toStrictEqual(Exit.fail(error)) + assertFailure(result, Cause.fail(error)) } /** * Asserts that loading a configuration with valid data succeeds and returns the expected value. - * - * @param config - The configuration to load. - * @param map - The map of configuration values. - * @param a - The expected value. */ -const assertSuccess = ( +const assertConfigSuccess = ( config: Config.Config, map: ReadonlyArray, a: A ) => { const configProvider = ConfigProvider.fromMap(new Map(map)) const result = Effect.runSync(Effect.exit(configProvider.load(config))) - expect(result).toStrictEqual(Exit.succeed(a)) + assertSuccess(result, a) } describe("Config", () => { it("should validate the configuration schema correctly", () => { const config = Schema.Config("A", Schema.NonEmptyString) - assertSuccess(config, [["A", "a"]], "a") - assertFailure(config, [], ConfigError.MissingData(["A"], `Expected A to exist in the provided map`)) - assertFailure( + assertConfigSuccess(config, [["A", "a"]], "a") + assertConfigFailure(config, [], ConfigError.MissingData(["A"], `Expected A to exist in the provided map`)) + assertConfigFailure( config, [["A", ""]], ConfigError.InvalidData( @@ -59,8 +48,8 @@ describe("Config", () => { it("should work with a template literal", () => { const config = Schema.Config("A", Schema.TemplateLiteral("a", Schema.Number)) - assertSuccess(config, [["A", "a1"]], "a1") - assertFailure( + assertConfigSuccess(config, [["A", "a1"]], "a1") + assertConfigFailure( config, [["A", "ab"]], ConfigError.InvalidData( diff --git a/packages/effect/test/Schema/Schema/Data/DataFromSelf.test.ts b/packages/effect/test/Schema/Schema/Data/DataFromSelf.test.ts index d44d7690c0f..a9b1269fbcf 100644 --- a/packages/effect/test/Schema/Schema/Data/DataFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/Data/DataFromSelf.test.ts @@ -3,7 +3,8 @@ import * as P from "effect/ParseResult" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("DataFromSelf", () => { it("test roundtrip consistency", () => { @@ -45,14 +46,14 @@ describe("DataFromSelf", () => { it("is", () => { const schema = S.DataFromSelf(S.Struct({ a: S.String, b: S.Number })) const is = P.is(schema) - expect(is(Data.struct({ a: "ok", b: 0 }))).toEqual(true) - expect(is({ a: "ok", b: 0 })).toEqual(false) - expect(is(Data.struct({ a: "ok", b: "no" }))).toEqual(false) + assertTrue(is(Data.struct({ a: "ok", b: 0 }))) + assertFalse(is({ a: "ok", b: 0 })) + assertFalse(is(Data.struct({ a: "ok", b: "no" }))) }) it("pretty", () => { const schema = S.DataFromSelf(S.Struct({ a: S.String, b: S.Number })) const pretty = Pretty.make(schema) - expect(pretty(Data.struct({ a: "ok", b: 0 }))).toEqual(`Data({ "a": "ok", "b": 0 })`) + strictEqual(pretty(Data.struct({ a: "ok", b: 0 })), `Data({ "a": "ok", "b": 0 })`) }) }) diff --git a/packages/effect/test/Schema/Schema/Date/DateFromNumber.test.ts b/packages/effect/test/Schema/Schema/Date/DateFromNumber.test.ts index 1d62ce3477c..9fd74183786 100644 --- a/packages/effect/test/Schema/Schema/Date/DateFromNumber.test.ts +++ b/packages/effect/test/Schema/Schema/Date/DateFromNumber.test.ts @@ -1,13 +1,14 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("DateFromNumber", () => { it("decoding", async () => { await Util.assertions.decoding.succeed(S.DateFromNumber, 0, new Date(0)) - expect(S.decodeSync(S.DateFromNumber)(NaN) instanceof Date).toBe(true) - expect(S.decodeSync(S.DateFromNumber)(Infinity) instanceof Date).toBe(true) - expect(S.decodeSync(S.DateFromNumber)(-Infinity) instanceof Date).toBe(true) + assertTrue(S.decodeSync(S.DateFromNumber)(NaN) instanceof Date) + assertTrue(S.decodeSync(S.DateFromNumber)(Infinity) instanceof Date) + assertTrue(S.decodeSync(S.DateFromNumber)(-Infinity) instanceof Date) await Util.assertions.decoding.fail( S.DateFromNumber, @@ -20,9 +21,9 @@ describe("DateFromNumber", () => { it("encoding", async () => { await Util.assertions.encoding.succeed(S.DateFromNumber, new Date(0), 0) - expect(S.encodeSync(S.DateFromNumber)(new Date("invalid"))).toBe(NaN) - expect(S.encodeSync(S.DateFromNumber)(new Date(NaN))).toBe(NaN) - expect(S.encodeSync(S.DateFromNumber)(new Date(Infinity))).toBe(NaN) - expect(S.encodeSync(S.DateFromNumber)(new Date(-Infinity))).toBe(NaN) + strictEqual(S.encodeSync(S.DateFromNumber)(new Date("invalid")), NaN) + strictEqual(S.encodeSync(S.DateFromNumber)(new Date(NaN)), NaN) + strictEqual(S.encodeSync(S.DateFromNumber)(new Date(Infinity)), NaN) + strictEqual(S.encodeSync(S.DateFromNumber)(new Date(-Infinity)), NaN) }) }) diff --git a/packages/effect/test/Schema/Schema/Date/DateFromSelf.test.ts b/packages/effect/test/Schema/Schema/Date/DateFromSelf.test.ts index f3dcdaa81b4..758cc6c3e4d 100644 --- a/packages/effect/test/Schema/Schema/Date/DateFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/Date/DateFromSelf.test.ts @@ -1,7 +1,8 @@ import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("DateFromSelf", () => { it("test roundtrip consistency", () => { @@ -28,6 +29,6 @@ describe("DateFromSelf", () => { it("pretty", () => { const pretty = Pretty.make(S.DateFromSelf) - expect(pretty(new Date(0))).toEqual("new Date(\"1970-01-01T00:00:00.000Z\")") + strictEqual(pretty(new Date(0)), `new Date("1970-01-01T00:00:00.000Z")`) }) }) diff --git a/packages/effect/test/Schema/Schema/DateTime/DateTimeUtcFromDate.test.ts b/packages/effect/test/Schema/Schema/DateTime/DateTimeUtcFromDate.test.ts index 04f92ff4d7d..39b32f1371c 100644 --- a/packages/effect/test/Schema/Schema/DateTime/DateTimeUtcFromDate.test.ts +++ b/packages/effect/test/Schema/Schema/DateTime/DateTimeUtcFromDate.test.ts @@ -1,7 +1,8 @@ import * as DateTime from "effect/DateTime" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("DateTimeUtcFromDate", () => { const schema = S.DateTimeUtcFromDate @@ -36,10 +37,11 @@ describe("DateTimeUtcFromDate", () => { it("encoding", async () => { await Util.assertions.encoding.succeed(schema, DateTime.unsafeMake(0), new Date(0)) - expect( + deepStrictEqual( S.encodeSync(schema)( DateTime.unsafeMake({ day: 6, month: 12, year: 2024, hour: 0, minute: 0, second: 0, millisecond: 0 }) - ) - ).toStrictEqual(new Date("2024-12-06T00:00:00Z")) + ), + new Date("2024-12-06T00:00:00Z") + ) }) }) diff --git a/packages/effect/test/Schema/Schema/DecodingFallbackAnnotation.test.ts b/packages/effect/test/Schema/Schema/DecodingFallbackAnnotation.test.ts index b34f7f9a046..2cd93b18341 100644 --- a/packages/effect/test/Schema/Schema/DecodingFallbackAnnotation.test.ts +++ b/packages/effect/test/Schema/Schema/DecodingFallbackAnnotation.test.ts @@ -1,7 +1,8 @@ import { Effect, Either } from "effect" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("DecodingFallbackAnnotation", () => { it("using Either", async () => { @@ -27,7 +28,7 @@ describe("DecodingFallbackAnnotation", () => { null, "" ) - expect(log).toEqual([null]) + deepStrictEqual(log, [null]) }) it("using an async Effect", async () => { @@ -45,10 +46,11 @@ describe("DecodingFallbackAnnotation", () => { null, "" ) - expect(log).toEqual([null]) - expect(() => S.decodeUnknownSync(schema)(null)).toThrowError( - new Error(`string -└─ cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work`) + deepStrictEqual(log, [null]) + Util.assertParseError( + () => S.decodeUnknownSync(schema)(null), + `string +└─ cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work` ) }) diff --git a/packages/effect/test/Schema/Schema/Defect/Defect.test.ts b/packages/effect/test/Schema/Schema/Defect/Defect.test.ts index dc9fbd68855..f30e87e94ec 100644 --- a/packages/effect/test/Schema/Schema/Defect/Defect.test.ts +++ b/packages/effect/test/Schema/Schema/Defect/Defect.test.ts @@ -1,6 +1,7 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Defect", () => { describe("decoding", () => { @@ -14,21 +15,21 @@ describe("Defect", () => { it("an object with a message", () => { const err = S.decodeUnknownSync(S.Defect)({ message: "message" }) - expect(err).toEqual(new Error("message")) + deepStrictEqual(err, new Error("message")) }) it("an object with a message and a name", () => { const err = S.decodeUnknownSync(S.Defect)({ message: "message", name: "name" }) - expect(err).toEqual(new Error("message")) - expect(err instanceof Error).toBe(true) - expect((err as Error).name).toEqual("name") + assertTrue(err instanceof Error) + strictEqual(err.message, "message") + strictEqual(err.name, "name") }) it("an object with a message and a stack", () => { const err = S.decodeUnknownSync(S.Defect)({ message: "message", stack: "stack" }) - expect(err).toEqual(new Error("message")) - expect(err instanceof Error).toBe(true) - expect((err as Error).stack).toEqual("stack") + assertTrue(err instanceof Error) + strictEqual(err.message, "message") + strictEqual(err.stack, "stack") }) }) diff --git a/packages/effect/test/Schema/Schema/Duration/DurationFromSelf.test.ts b/packages/effect/test/Schema/Schema/Duration/DurationFromSelf.test.ts index a1934378452..79a0e17913a 100644 --- a/packages/effect/test/Schema/Schema/Duration/DurationFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/Duration/DurationFromSelf.test.ts @@ -2,7 +2,8 @@ import { Duration } from "effect" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("DurationFromSelf", () => { const schema = S.DurationFromSelf @@ -33,8 +34,8 @@ describe("DurationFromSelf", () => { it("pretty", () => { const pretty = Pretty.make(schema) - expect(pretty(Duration.millis(500))).toEqual("Duration(500ms)") - expect(pretty(Duration.seconds(30))).toEqual("Duration(30s)") - expect(pretty(Duration.minutes(5.25))).toEqual("Duration(5m 15s)") + strictEqual(pretty(Duration.millis(500)), "Duration(500ms)") + strictEqual(pretty(Duration.seconds(30)), "Duration(30s)") + strictEqual(pretty(Duration.minutes(5.25)), "Duration(5m 15s)") }) }) diff --git a/packages/effect/test/Schema/Schema/Either/EitherFromSelf.test.ts b/packages/effect/test/Schema/Schema/Either/EitherFromSelf.test.ts index ff2d2cb2a9c..f63deb4bcb4 100644 --- a/packages/effect/test/Schema/Schema/Either/EitherFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/Either/EitherFromSelf.test.ts @@ -3,7 +3,8 @@ import * as P from "effect/ParseResult" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("EitherFromSelf", () => { it("arbitrary", () => { @@ -17,14 +18,14 @@ describe("EitherFromSelf", () => { it("is", () => { const schema = S.EitherFromSelf({ left: S.String, right: S.Number }) const is = P.is(schema) - expect(is(E.left("a"))).toEqual(true) - expect(is(E.right(1))).toEqual(true) - expect(is(null)).toEqual(false) - expect(is(E.right("a"))).toEqual(false) - expect(is(E.left(1))).toEqual(false) + assertTrue(is(E.left("a"))) + assertTrue(is(E.right(1))) + assertFalse(is(null)) + assertFalse(is(E.right("a"))) + assertFalse(is(E.left(1))) - expect(is({ _tag: "Right", right: 1 })).toEqual(false) - expect(is({ _tag: "Left", left: "a" })).toEqual(false) + assertFalse(is({ _tag: "Right", right: 1 })) + assertFalse(is({ _tag: "Left", left: "a" })) }) it("decoding", async () => { @@ -60,7 +61,7 @@ describe("EitherFromSelf", () => { it("pretty", () => { const schema = S.EitherFromSelf({ left: S.String, right: S.Number }) const pretty = Pretty.make(schema) - expect(pretty(E.left("a"))).toEqual(`left("a")`) - expect(pretty(E.right(1))).toEqual("right(1)") + strictEqual(pretty(E.left("a")), `left("a")`) + strictEqual(pretty(E.right(1)), "right(1)") }) }) diff --git a/packages/effect/test/Schema/Schema/Either/EitherFromUnion.test.ts b/packages/effect/test/Schema/Schema/Either/EitherFromUnion.test.ts index ca394ac4cf7..34b9d10f657 100644 --- a/packages/effect/test/Schema/Schema/Either/EitherFromUnion.test.ts +++ b/packages/effect/test/Schema/Schema/Either/EitherFromUnion.test.ts @@ -1,7 +1,8 @@ import * as E from "effect/Either" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertTrue } from "effect/test/util" +import { describe, it } from "vitest" describe("EitherFromUnion", () => { it("test roundtrip consistency", () => { @@ -13,8 +14,8 @@ describe("EitherFromUnion", () => { await Util.assertions.decoding.succeed(schema, "1970-01-01T00:00:00.000Z", E.left(new Date(0))) await Util.assertions.decoding.succeed(schema, "1", E.right(1)) - expect(E.isEither(S.decodeSync(schema)("1970-01-01T00:00:00.000Z"))).toEqual(true) - expect(E.isEither(S.decodeSync(schema)("1"))).toEqual(true) + assertTrue(E.isEither(S.decodeSync(schema)("1970-01-01T00:00:00.000Z"))) + assertTrue(E.isEither(S.decodeSync(schema)("1"))) }) it("decoding error (Encoded side transformation failure)", async () => { diff --git a/packages/effect/test/Schema/Schema/Enums/Enums.test.ts b/packages/effect/test/Schema/Schema/Enums/Enums.test.ts index 4e2f910b42f..162776df81b 100644 --- a/packages/effect/test/Schema/Schema/Enums/Enums.test.ts +++ b/packages/effect/test/Schema/Schema/Enums/Enums.test.ts @@ -1,6 +1,7 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Enums", () => { it("enums should be exposed", () => { @@ -9,8 +10,8 @@ describe("Enums", () => { Banana } const schema = S.Enums(Fruits).annotations({ identifier: "Fruits" }) - expect(schema.enums.Apple).toBe(0) - expect(schema.enums.Banana).toBe(1) + strictEqual(schema.enums.Apple, 0) + strictEqual(schema.enums.Banana, 1) }) describe("Numeric enums", () => { diff --git a/packages/effect/test/Schema/Schema/FiberId/FiberIdFromSelf.test.ts b/packages/effect/test/Schema/Schema/FiberId/FiberIdFromSelf.test.ts index c33af02798d..0d6f360b66f 100644 --- a/packages/effect/test/Schema/Schema/FiberId/FiberIdFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/FiberId/FiberIdFromSelf.test.ts @@ -2,7 +2,8 @@ import * as FiberId from "effect/FiberId" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("FiberIdFromSelf", () => { it("arbitrary", () => { @@ -30,10 +31,8 @@ describe("FiberIdFromSelf", () => { it("pretty", () => { const schema = S.FiberIdFromSelf const pretty = Pretty.make(schema) - expect(pretty(FiberId.none)).toEqual(`FiberId.none`) - expect(pretty(FiberId.runtime(1, 100))).toEqual(`FiberId.runtime(1, 100)`) - expect(pretty(FiberId.composite(FiberId.none, FiberId.none))).toEqual( - `FiberId.composite(FiberId.none, FiberId.none)` - ) + strictEqual(pretty(FiberId.none), `FiberId.none`) + strictEqual(pretty(FiberId.runtime(1, 100)), `FiberId.runtime(1, 100)`) + strictEqual(pretty(FiberId.composite(FiberId.none, FiberId.none)), `FiberId.composite(FiberId.none, FiberId.none)`) }) }) diff --git a/packages/effect/test/Schema/Schema/HashMap/HashMapFromSelf.test.ts b/packages/effect/test/Schema/Schema/HashMap/HashMapFromSelf.test.ts index c2c57237a64..1b2346b4d04 100644 --- a/packages/effect/test/Schema/Schema/HashMap/HashMapFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/HashMap/HashMapFromSelf.test.ts @@ -3,7 +3,8 @@ import * as P from "effect/ParseResult" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("HashMapFromSelf", () => { it("test roundtrip consistency", () => { @@ -51,24 +52,22 @@ describe("HashMapFromSelf", () => { it("is", () => { const schema = S.HashMapFromSelf({ key: S.Number, value: S.String }) const is = P.is(schema) - expect(is(HashMap.fromIterable([]))).toEqual(true) - expect(is(HashMap.fromIterable([[1, "a"], [2, "b"], [3, "c"]]))).toEqual(true) + assertTrue(is(HashMap.fromIterable([]))) + assertTrue(is(HashMap.fromIterable([[1, "a"], [2, "b"], [3, "c"]]))) - expect(is(null)).toEqual(false) - expect(is(undefined)).toEqual(false) - expect(is(HashMap.fromIterable([[1, "a"], [2, 1]]))).toEqual(false) - expect(is(HashMap.fromIterable([[1, 1], [2, "b"]]))).toEqual(false) - expect(is(HashMap.fromIterable([[1, 1], [2, 2]]))).toEqual(false) - expect(is(HashMap.fromIterable([["a", 1], ["b", 2], [3, 1]]))).toEqual(false) - expect(is(HashMap.fromIterable([[1, "a"], [2, "b"], [3, 1]]))).toEqual(false) + assertFalse(is(null)) + assertFalse(is(undefined)) + assertFalse(is(HashMap.fromIterable([[1, "a"], [2, 1]]))) + assertFalse(is(HashMap.fromIterable([[1, 1], [2, "b"]]))) + assertFalse(is(HashMap.fromIterable([[1, 1], [2, 2]]))) + assertFalse(is(HashMap.fromIterable([["a", 1], ["b", 2], [3, 1]]))) + assertFalse(is(HashMap.fromIterable([[1, "a"], [2, "b"], [3, 1]]))) }) it("pretty", () => { const schema = S.HashMapFromSelf({ key: S.Number, value: S.String }) const pretty = Pretty.make(schema) - expect(pretty(HashMap.fromIterable([]))).toEqual("HashMap([])") - expect(pretty(HashMap.fromIterable([[1, "a"], [2, "b"]]))).toEqual( - `HashMap([[1, "a"], [2, "b"]])` - ) + strictEqual(pretty(HashMap.fromIterable([])), "HashMap([])") + strictEqual(pretty(HashMap.fromIterable([[1, "a"], [2, "b"]])), `HashMap([[1, "a"], [2, "b"]])`) }) }) diff --git a/packages/effect/test/Schema/Schema/HashSet/HashSetFromSelf.test.ts b/packages/effect/test/Schema/Schema/HashSet/HashSetFromSelf.test.ts index ff73f935ac4..1d2fea58426 100644 --- a/packages/effect/test/Schema/Schema/HashSet/HashSetFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/HashSet/HashSetFromSelf.test.ts @@ -3,7 +3,8 @@ import * as P from "effect/ParseResult" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("HashSetFromSelf", () => { it("test roundtrip consistency", () => { @@ -49,19 +50,17 @@ describe("HashSetFromSelf", () => { it("is", () => { const schema = S.HashSetFromSelf(S.String) const is = P.is(schema) - expect(is(HashSet.empty())).toEqual(true) - expect(is(HashSet.fromIterable(["a", "b", "c"]))).toEqual(true) + assertTrue(is(HashSet.empty())) + assertTrue(is(HashSet.fromIterable(["a", "b", "c"]))) - expect(is(HashSet.fromIterable(["a", "b", 1]))).toEqual(false) - expect(is({ _id: Symbol.for("effect/Schema/test/FakeHashSet") })).toEqual(false) + assertFalse(is(HashSet.fromIterable(["a", "b", 1]))) + assertFalse(is({ _id: Symbol.for("effect/Schema/test/FakeHashSet") })) }) it("pretty", () => { const schema = S.HashSetFromSelf(S.String) const pretty = Pretty.make(schema) - expect(pretty(HashSet.empty())).toEqual("HashSet()") - expect(pretty(HashSet.fromIterable(["a", "b"]))).toEqual( - `HashSet("a", "b")` - ) + strictEqual(pretty(HashSet.empty()), "HashSet()") + strictEqual(pretty(HashSet.fromIterable(["a", "b"])), `HashSet("a", "b")`) }) }) diff --git a/packages/effect/test/Schema/Schema/List/ListFromSelf.test.ts b/packages/effect/test/Schema/Schema/List/ListFromSelf.test.ts index 20bef8cec5d..08bdefb54d6 100644 --- a/packages/effect/test/Schema/Schema/List/ListFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/List/ListFromSelf.test.ts @@ -3,7 +3,8 @@ import * as P from "effect/ParseResult" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("ListFromSelf", () => { it("test roundtrip consistency", () => { @@ -49,19 +50,17 @@ describe("ListFromSelf", () => { it("is", () => { const schema = S.ListFromSelf(S.String) const is = P.is(schema) - expect(is(List.empty())).toEqual(true) - expect(is(List.fromIterable(["a", "b", "c"]))).toEqual(true) + assertTrue(is(List.empty())) + assertTrue(is(List.fromIterable(["a", "b", "c"]))) - expect(is(List.fromIterable(["a", "b", 1]))).toEqual(false) - expect(is({ _id: Symbol.for("effect/Schema/test/FakeList") })).toEqual(false) + assertFalse(is(List.fromIterable(["a", "b", 1]))) + assertFalse(is({ _id: Symbol.for("effect/Schema/test/FakeList") })) }) it("pretty", () => { const schema = S.ListFromSelf(S.String) const pretty = Pretty.make(schema) - expect(pretty(List.empty())).toEqual("List()") - expect(pretty(List.fromIterable(["a", "b"]))).toEqual( - `List("a", "b")` - ) + strictEqual(pretty(List.empty()), "List()") + strictEqual(pretty(List.fromIterable(["a", "b"])), `List("a", "b")`) }) }) diff --git a/packages/effect/test/Schema/Schema/Literal/Literal.test.ts b/packages/effect/test/Schema/Schema/Literal/Literal.test.ts index f4911dd9a80..31d5cf9344a 100644 --- a/packages/effect/test/Schema/Schema/Literal/Literal.test.ts +++ b/packages/effect/test/Schema/Schema/Literal/Literal.test.ts @@ -1,12 +1,13 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Literal", () => { it("annotations()", () => { const schema = S.Literal(1).annotations({ identifier: "X" }).annotations({ title: "Y" }) - expect(schema.ast.annotations).toStrictEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.IdentifierAnnotationId]: "X", [AST.TitleAnnotationId]: "Y" }) @@ -14,23 +15,21 @@ describe("Literal", () => { it("should expose the literals", () => { const schema = S.Literal("a", "b") - expect(schema.literals).toStrictEqual(["a", "b"]) + deepStrictEqual(schema.literals, ["a", "b"]) }) it("should return an unwrapped AST with exactly one literal", () => { - expect(S.Literal(1).ast).toEqual(new AST.Literal(1)) + deepStrictEqual(S.Literal(1).ast, new AST.Literal(1)) }) it("should return a union with more than one literal", () => { - expect(S.Literal(1, 2).ast).toEqual( - AST.Union.make([new AST.Literal(1), new AST.Literal(2)]) - ) + deepStrictEqual(S.Literal(1, 2).ast, AST.Union.make([new AST.Literal(1), new AST.Literal(2)])) }) it("should return the literal interface when using the .annotations() method", () => { const schema = S.Literal("a", "b").annotations({ identifier: "literal test" }) - expect(schema.ast.annotations).toStrictEqual({ [AST.IdentifierAnnotationId]: "literal test" }) - expect(schema.literals).toStrictEqual(["a", "b"]) + deepStrictEqual(schema.ast.annotations, { [AST.IdentifierAnnotationId]: "literal test" }) + deepStrictEqual(schema.literals, ["a", "b"]) }) describe("decoding", () => { diff --git a/packages/effect/test/Schema/Schema/Map/Map.test.ts b/packages/effect/test/Schema/Schema/Map/Map.test.ts index 3b2096c5dec..999d40b45ea 100644 --- a/packages/effect/test/Schema/Schema/Map/Map.test.ts +++ b/packages/effect/test/Schema/Schema/Map/Map.test.ts @@ -1,9 +1,11 @@ import * as S from "effect/Schema" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Map", () => { it("description", () => { - expect(String(S.Map({ key: S.String, value: S.Number }))).toStrictEqual( + strictEqual( + String(S.Map({ key: S.String, value: S.Number })), "(ReadonlyArray <-> Map)" ) }) diff --git a/packages/effect/test/Schema/Schema/Map/MapFromSelf.test.ts b/packages/effect/test/Schema/Schema/Map/MapFromSelf.test.ts index 0239d6850e6..85764018efd 100644 --- a/packages/effect/test/Schema/Schema/Map/MapFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/Map/MapFromSelf.test.ts @@ -1,8 +1,9 @@ import * as S from "effect/Schema" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("MapFromSelf", () => { it("description", () => { - expect(String(S.MapFromSelf({ key: S.String, value: S.Number }))).toStrictEqual("Map") + strictEqual(String(S.MapFromSelf({ key: S.String, value: S.Number })), "Map") }) }) diff --git a/packages/effect/test/Schema/Schema/NonEmptyArrayEnsure.test.ts b/packages/effect/test/Schema/Schema/NonEmptyArrayEnsure.test.ts index 2143939f0c3..6263dc465b6 100644 --- a/packages/effect/test/Schema/Schema/NonEmptyArrayEnsure.test.ts +++ b/packages/effect/test/Schema/Schema/NonEmptyArrayEnsure.test.ts @@ -1,12 +1,13 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("NonEmptyArrayEnsure", () => { it("annotations()", () => { const schema = S.NonEmptyArrayEnsure(S.String).annotations({ identifier: "X" }).annotations({ title: "Y" }) - expect(schema.ast.annotations).toStrictEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.IdentifierAnnotationId]: "X", [AST.TitleAnnotationId]: "Y" }) diff --git a/packages/effect/test/Schema/Schema/Number/greaterThan.test.ts b/packages/effect/test/Schema/Schema/Number/greaterThan.test.ts index 55cb47a299b..07122d7d881 100644 --- a/packages/effect/test/Schema/Schema/Number/greaterThan.test.ts +++ b/packages/effect/test/Schema/Schema/Number/greaterThan.test.ts @@ -2,7 +2,8 @@ import * as P from "effect/ParseResult" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("greaterThan", () => { const schema = S.greaterThan(0)(S.Number) @@ -13,9 +14,9 @@ describe("greaterThan", () => { it("is", () => { const is = P.is(schema) - expect(is(0)).toEqual(false) - expect(is(1)).toEqual(true) - expect(is(-1)).toEqual(false) + assertFalse(is(0)) + assertTrue(is(1)) + assertFalse(is(-1)) }) it("decoding", async () => { @@ -38,6 +39,6 @@ describe("greaterThan", () => { it("pretty", () => { const pretty = Pretty.make(schema) - expect(pretty(1)).toEqual("1") + strictEqual(pretty(1), "1") }) }) diff --git a/packages/effect/test/Schema/Schema/Number/greaterThanOrEqualTo.test.ts b/packages/effect/test/Schema/Schema/Number/greaterThanOrEqualTo.test.ts index f11480ba703..eb2451fa651 100644 --- a/packages/effect/test/Schema/Schema/Number/greaterThanOrEqualTo.test.ts +++ b/packages/effect/test/Schema/Schema/Number/greaterThanOrEqualTo.test.ts @@ -2,7 +2,8 @@ import * as P from "effect/ParseResult" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("greaterThanOrEqualTo", () => { const schema = S.greaterThanOrEqualTo(0)(S.Number) @@ -13,9 +14,9 @@ describe("greaterThanOrEqualTo", () => { it("is", () => { const is = P.is(schema) - expect(is(0)).toEqual(true) - expect(is(1)).toEqual(true) - expect(is(-1)).toEqual(false) + assertTrue(is(0)) + assertTrue(is(1)) + assertFalse(is(-1)) }) it("decoding", async () => { @@ -32,6 +33,6 @@ describe("greaterThanOrEqualTo", () => { it("pretty", () => { const pretty = Pretty.make(schema) - expect(pretty(1)).toEqual("1") + strictEqual(pretty(1), "1") }) }) diff --git a/packages/effect/test/Schema/Schema/Number/int.test.ts b/packages/effect/test/Schema/Schema/Number/int.test.ts index c22da40074c..5dd6254d3ae 100644 --- a/packages/effect/test/Schema/Schema/Number/int.test.ts +++ b/packages/effect/test/Schema/Schema/Number/int.test.ts @@ -2,7 +2,8 @@ import * as P from "effect/ParseResult" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Int", () => { const schema = S.Int @@ -13,11 +14,11 @@ describe("Int", () => { it("is", () => { const is = P.is(schema) - expect(is(0)).toEqual(true) - expect(is(1)).toEqual(true) - expect(is(0.5)).toEqual(false) - expect(is(Number.MAX_SAFE_INTEGER + 1)).toEqual(false) - expect(is(Number.MIN_SAFE_INTEGER - 1)).toEqual(false) + assertTrue(is(0)) + assertTrue(is(1)) + assertFalse(is(0.5)) + assertFalse(is(Number.MAX_SAFE_INTEGER + 1)) + assertFalse(is(Number.MIN_SAFE_INTEGER - 1)) }) it("decoding", async () => { @@ -34,6 +35,6 @@ describe("Int", () => { it("pretty", () => { const pretty = Pretty.make(schema) - expect(pretty(1)).toEqual("1") + strictEqual(pretty(1), "1") }) }) diff --git a/packages/effect/test/Schema/Schema/Number/lessThan.test.ts b/packages/effect/test/Schema/Schema/Number/lessThan.test.ts index 0dcb1c3386f..0c733bbccd3 100644 --- a/packages/effect/test/Schema/Schema/Number/lessThan.test.ts +++ b/packages/effect/test/Schema/Schema/Number/lessThan.test.ts @@ -2,7 +2,8 @@ import * as P from "effect/ParseResult" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("lessThan", () => { it("test roundtrip consistency", () => { @@ -11,9 +12,9 @@ describe("lessThan", () => { it("is", () => { const is = P.is(S.lessThan(0)(S.Number)) - expect(is(0)).toEqual(false) - expect(is(1)).toEqual(false) - expect(is(-1)).toEqual(true) + assertFalse(is(0)) + assertFalse(is(1)) + assertTrue(is(-1)) }) it("decoding", async () => { @@ -37,6 +38,6 @@ describe("lessThan", () => { it("pretty", () => { const pretty = Pretty.make(S.lessThan(0)(S.Number)) - expect(pretty(1)).toEqual("1") + strictEqual(pretty(1), "1") }) }) diff --git a/packages/effect/test/Schema/Schema/Number/lessThanOrEqualTo.test.ts b/packages/effect/test/Schema/Schema/Number/lessThanOrEqualTo.test.ts index 5a2ce28dbfd..36fdd5a449b 100644 --- a/packages/effect/test/Schema/Schema/Number/lessThanOrEqualTo.test.ts +++ b/packages/effect/test/Schema/Schema/Number/lessThanOrEqualTo.test.ts @@ -2,7 +2,8 @@ import * as P from "effect/ParseResult" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("lessThanOrEqualTo", () => { it("test roundtrip consistency", () => { @@ -11,9 +12,9 @@ describe("lessThanOrEqualTo", () => { it("is", () => { const is = P.is(S.lessThanOrEqualTo(0)(S.Number)) - expect(is(0)).toEqual(true) - expect(is(1)).toEqual(false) - expect(is(-1)).toEqual(true) + assertTrue(is(0)) + assertFalse(is(1)) + assertTrue(is(-1)) }) it("decoding", async () => { @@ -31,6 +32,6 @@ describe("lessThanOrEqualTo", () => { it("pretty", () => { const pretty = Pretty.make(S.lessThanOrEqualTo(0)(S.Number)) - expect(pretty(1)).toEqual("1") + strictEqual(pretty(1), "1") }) }) diff --git a/packages/effect/test/Schema/Schema/Number/multipleOf.test.ts b/packages/effect/test/Schema/Schema/Number/multipleOf.test.ts index 49babc065e7..678e8a917e3 100644 --- a/packages/effect/test/Schema/Schema/Number/multipleOf.test.ts +++ b/packages/effect/test/Schema/Schema/Number/multipleOf.test.ts @@ -1,7 +1,8 @@ import * as P from "effect/ParseResult" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue } from "effect/test/util" +import { describe, it } from "vitest" describe("multipleOf", () => { it("test roundtrip consistency", () => { @@ -11,13 +12,13 @@ describe("multipleOf", () => { it("is", () => { const schema = S.Number.pipe(S.multipleOf(-.2)) const is = P.is(schema) - expect(is(-2.8)).toEqual(true) - expect(is(-2)).toEqual(true) - expect(is(-1.5)).toEqual(false) - expect(is(0)).toEqual(true) - expect(is(1)).toEqual(true) - expect(is(2.6)).toEqual(true) - expect(is(3.1)).toEqual(false) + assertTrue(is(-2.8)) + assertTrue(is(-2)) + assertFalse(is(-1.5)) + assertTrue(is(0)) + assertTrue(is(1)) + assertTrue(is(2.6)) + assertFalse(is(3.1)) }) it("decoding", async () => { diff --git a/packages/effect/test/Schema/Schema/Number/nonNaN.test.ts b/packages/effect/test/Schema/Schema/Number/nonNaN.test.ts index 99b7cac887c..3d93c9b1a52 100644 --- a/packages/effect/test/Schema/Schema/Number/nonNaN.test.ts +++ b/packages/effect/test/Schema/Schema/Number/nonNaN.test.ts @@ -2,7 +2,8 @@ import * as P from "effect/ParseResult" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("NonNaN", () => { const schema = S.NonNaN @@ -13,8 +14,8 @@ describe("NonNaN", () => { it("is", () => { const is = P.is(schema) - expect(is(1)).toEqual(true) - expect(is(NaN)).toEqual(false) + assertTrue(is(1)) + assertFalse(is(NaN)) }) it("decoding", async () => { @@ -30,7 +31,7 @@ describe("NonNaN", () => { it("pretty", () => { const pretty = Pretty.make(schema) - expect(pretty(1)).toEqual("1") - expect(pretty(NaN)).toEqual("NaN") + strictEqual(pretty(1), "1") + strictEqual(pretty(NaN), "NaN") }) }) diff --git a/packages/effect/test/Schema/Schema/Option/OptionFromNullOr.test.ts b/packages/effect/test/Schema/Schema/Option/OptionFromNullOr.test.ts index e93eb8bda3d..9f2b62d333f 100644 --- a/packages/effect/test/Schema/Schema/Option/OptionFromNullOr.test.ts +++ b/packages/effect/test/Schema/Schema/Option/OptionFromNullOr.test.ts @@ -1,7 +1,8 @@ import * as O from "effect/Option" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertTrue } from "effect/test/util" +import { describe, it } from "vitest" describe("OptionFromNullOr", () => { it("test roundtrip consistency", () => { @@ -13,8 +14,8 @@ describe("OptionFromNullOr", () => { await Util.assertions.decoding.succeed(schema, null, O.none()) await Util.assertions.decoding.succeed(schema, "1", O.some(1)) - expect(O.isOption(S.decodeSync(schema)(null))).toEqual(true) - expect(O.isOption(S.decodeSync(schema)("1"))).toEqual(true) + assertTrue(O.isOption(S.decodeSync(schema)(null))) + assertTrue(O.isOption(S.decodeSync(schema)("1"))) await Util.assertions.decoding.fail( schema, diff --git a/packages/effect/test/Schema/Schema/Option/OptionFromNullishOr.test.ts b/packages/effect/test/Schema/Schema/Option/OptionFromNullishOr.test.ts index 9958d22b0d3..5bef78f0862 100644 --- a/packages/effect/test/Schema/Schema/Option/OptionFromNullishOr.test.ts +++ b/packages/effect/test/Schema/Schema/Option/OptionFromNullishOr.test.ts @@ -1,7 +1,8 @@ import * as O from "effect/Option" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertTrue } from "effect/test/util" +import { describe, it } from "vitest" describe("OptionFromNullishOr", () => { it("test roundtrip consistency", () => { @@ -15,9 +16,9 @@ describe("OptionFromNullishOr", () => { await Util.assertions.decoding.succeed(schema, undefined, O.none()) await Util.assertions.decoding.succeed(schema, "1", O.some(1)) - expect(O.isOption(S.decodeSync(schema)(null))).toEqual(true) - expect(O.isOption(S.decodeSync(schema)(undefined))).toEqual(true) - expect(O.isOption(S.decodeSync(schema)("1"))).toEqual(true) + assertTrue(O.isOption(S.decodeSync(schema)(null))) + assertTrue(O.isOption(S.decodeSync(schema)(undefined))) + assertTrue(O.isOption(S.decodeSync(schema)("1"))) await Util.assertions.decoding.fail( schema, diff --git a/packages/effect/test/Schema/Schema/Option/OptionFromSelf.test.ts b/packages/effect/test/Schema/Schema/Option/OptionFromSelf.test.ts index cc7f34612a1..6e381c004e2 100644 --- a/packages/effect/test/Schema/Schema/Option/OptionFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/Option/OptionFromSelf.test.ts @@ -3,7 +3,8 @@ import * as P from "effect/ParseResult" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("OptionFromSelf", () => { it("arbitrary", () => { @@ -17,13 +18,13 @@ describe("OptionFromSelf", () => { it("is", () => { const schema = S.OptionFromSelf(S.Number) const is = P.is(schema) - expect(is(O.none())).toEqual(true) - expect(is(O.some(1))).toEqual(true) - expect(is(null)).toEqual(false) - expect(is(O.some("a"))).toEqual(false) + assertTrue(is(O.none())) + assertTrue(is(O.some(1))) + assertFalse(is(null)) + assertFalse(is(O.some("a"))) - expect(is({ _tag: "None" })).toEqual(false) - expect(is({ _tag: "Some", value: 1 })).toEqual(false) + assertFalse(is({ _tag: "None" })) + assertFalse(is({ _tag: "Some", value: 1 })) }) it("decoding", async () => { @@ -41,7 +42,7 @@ describe("OptionFromSelf", () => { it("pretty", () => { const schema = S.OptionFromSelf(S.Number) const pretty = Pretty.make(schema) - expect(pretty(O.none())).toEqual("none()") - expect(pretty(O.some(1))).toEqual("some(1)") + strictEqual(pretty(O.none()), "none()") + strictEqual(pretty(O.some(1)), "some(1)") }) }) diff --git a/packages/effect/test/Schema/Schema/Option/OptionFromUndefinedOr.test.ts b/packages/effect/test/Schema/Schema/Option/OptionFromUndefinedOr.test.ts index 16b039d5928..380df264fc3 100644 --- a/packages/effect/test/Schema/Schema/Option/OptionFromUndefinedOr.test.ts +++ b/packages/effect/test/Schema/Schema/Option/OptionFromUndefinedOr.test.ts @@ -1,7 +1,8 @@ import * as O from "effect/Option" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertTrue } from "effect/test/util" +import { describe, it } from "vitest" describe("OptionFromUndefinedOr", () => { it("test roundtrip consistency", () => { @@ -13,8 +14,8 @@ describe("OptionFromUndefinedOr", () => { await Util.assertions.decoding.succeed(schema, undefined, O.none()) await Util.assertions.decoding.succeed(schema, "1", O.some(1)) - expect(O.isOption(S.decodeSync(schema)(undefined))).toEqual(true) - expect(O.isOption(S.decodeSync(schema)("1"))).toEqual(true) + assertTrue(O.isOption(S.decodeSync(schema)(undefined))) + assertTrue(O.isOption(S.decodeSync(schema)("1"))) await Util.assertions.decoding.fail( schema, diff --git a/packages/effect/test/Schema/Schema/ParseOptions-exact.test.ts b/packages/effect/test/Schema/Schema/ParseOptions-exact.test.ts index 538e530f3ad..0775969d75a 100644 --- a/packages/effect/test/Schema/Schema/ParseOptions-exact.test.ts +++ b/packages/effect/test/Schema/Schema/ParseOptions-exact.test.ts @@ -1,6 +1,7 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue } from "effect/test/util" +import { describe, it } from "vitest" describe("`exact` option", () => { describe("decoding", () => { @@ -25,12 +26,12 @@ describe("`exact` option", () => { describe("is", () => { it("true (default)", async () => { const schema = S.Struct({ a: S.Unknown }) - expect(S.is(schema)({})).toBe(false) + assertFalse(S.is(schema)({})) }) it("false", async () => { const schema = S.Struct({ a: S.Unknown }) - expect(S.is(schema)({}, { exact: false })).toBe(true) + assertTrue(S.is(schema)({}, { exact: false })) }) }) diff --git a/packages/effect/test/Schema/Schema/ParseOptions-onExcessProperty.test.ts b/packages/effect/test/Schema/Schema/ParseOptions-onExcessProperty.test.ts index 7fa95c27491..99ab6e03c05 100644 --- a/packages/effect/test/Schema/Schema/ParseOptions-onExcessProperty.test.ts +++ b/packages/effect/test/Schema/Schema/ParseOptions-onExcessProperty.test.ts @@ -1,8 +1,8 @@ -import * as Either from "effect/Either" import * as ParseResult from "effect/ParseResult" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertLeft } from "effect/test/util" +import { describe, it } from "vitest" describe("`onExcessProperty` option", () => { describe("`ignore` option", () => { @@ -88,28 +88,30 @@ describe("`onExcessProperty` option", () => { const schema = S.Struct({ a: S.String }) const input = { a: "a", b: 1 } const e = ParseResult.decodeUnknownEither(schema)(input, Util.onExcessPropertyError) - expect(e).toEqual(Either.left( + assertLeft( + e, new ParseResult.Composite( schema.ast, input, new ParseResult.Pointer("b", input, new ParseResult.Unexpected(1, `is unexpected, expected: "a"`)), {} ) - )) + ) }) it("tuple", () => { const schema = S.Tuple(S.String) const input = ["a", 1] const e = ParseResult.decodeUnknownEither(schema)(input, Util.onExcessPropertyError) - expect(e).toEqual(Either.left( + assertLeft( + e, new ParseResult.Composite( schema.ast, input, new ParseResult.Pointer(1, input, new ParseResult.Unexpected(1, `is unexpected, expected: 0`)), [] ) - )) + ) }) }) diff --git a/packages/effect/test/Schema/Schema/ParseOptions-preserveKeyOrder.test.ts b/packages/effect/test/Schema/Schema/ParseOptions-preserveKeyOrder.test.ts index 7d0dddb021f..fc79bc2fa64 100644 --- a/packages/effect/test/Schema/Schema/ParseOptions-preserveKeyOrder.test.ts +++ b/packages/effect/test/Schema/Schema/ParseOptions-preserveKeyOrder.test.ts @@ -2,7 +2,8 @@ import type { Duration } from "effect" import * as Effect from "effect/Effect" import * as ParseResult from "effect/ParseResult" import * as S from "effect/Schema" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("`preserveKeyOrder` option", () => { const b = Symbol.for("effect/Schema/test/b") @@ -35,9 +36,9 @@ describe("`preserveKeyOrder` option", () => { it("should preserve the order of input properties (sync)", () => { const input = { [b]: ["b"], c: { c: 1 }, d: "1", e: true, a: "a", other: 1, f: undefined } const output = S.decodeUnknownSync(Sync)(input, { propertyOrder: "original", onExcessProperty: "preserve" }) - const expectedOutput = { [b]: ["b"], c: { c: 1 }, d: 1, e: true, a: "a", other: 1, f: undefined } - expect(output).toStrictEqual(expectedOutput) - expect(Reflect.ownKeys(output)).toStrictEqual(Reflect.ownKeys(expectedOutput)) + const expectedOutput = { [b]: ["b"], c: { c: 1 }, d: 1, e: true, a: "a", other: 1, f: undefined } as const + deepStrictEqual(output, expectedOutput) + deepStrictEqual(Reflect.ownKeys(output), Reflect.ownKeys(expectedOutput)) }) it("should preserve the order of input properties (async)", async () => { @@ -46,8 +47,8 @@ describe("`preserveKeyOrder` option", () => { S.decodeUnknown(Async)(input, { propertyOrder: "original", onExcessProperty: "preserve" }) ) const expectedOutput = { a: 1, c: 3, [b]: 2, other: 1 } - expect(output).toStrictEqual(expectedOutput) - expect(Reflect.ownKeys(output)).toStrictEqual(Reflect.ownKeys(expectedOutput)) + deepStrictEqual(output, expectedOutput) + deepStrictEqual(Reflect.ownKeys(output), Reflect.ownKeys(expectedOutput)) }) }) @@ -55,9 +56,9 @@ describe("`preserveKeyOrder` option", () => { it("should preserve the order of input properties (sync)", () => { const input = { [b]: ["b"], c: { c: 1 }, d: 1, e: true, a: "a", other: 1, f: undefined } const output = S.encodeUnknownSync(Sync)(input, { propertyOrder: "original", onExcessProperty: "preserve" }) - const expectedOutput = { [b]: ["b"], c: { c: 1 }, d: "1", e: true, a: "a", other: 1, f: undefined } - expect(output).toStrictEqual(expectedOutput) - expect(Reflect.ownKeys(output)).toStrictEqual(Reflect.ownKeys(expectedOutput)) + const expectedOutput = { [b]: ["b"], c: { c: 1 }, d: "1", e: true, a: "a", other: 1, f: undefined } as const + deepStrictEqual(output, expectedOutput) + deepStrictEqual(Reflect.ownKeys(output), Reflect.ownKeys(expectedOutput)) }) it("should preserve the order of input properties (async)", async () => { @@ -66,8 +67,8 @@ describe("`preserveKeyOrder` option", () => { S.encodeUnknown(Async)(input, { propertyOrder: "original", onExcessProperty: "preserve" }) ) const expectedOutput = { a: "1", c: "3", [b]: "2", other: 1 } - expect(output).toStrictEqual(expectedOutput) - expect(Reflect.ownKeys(output)).toStrictEqual(Reflect.ownKeys(expectedOutput)) + deepStrictEqual(output, expectedOutput) + deepStrictEqual(Reflect.ownKeys(output), Reflect.ownKeys(expectedOutput)) }) }) }) diff --git a/packages/effect/test/Schema/Schema/PropertyKey/PropertyKey.test.ts b/packages/effect/test/Schema/Schema/PropertyKey/PropertyKey.test.ts index 6f58556fb13..0caf5de10e8 100644 --- a/packages/effect/test/Schema/Schema/PropertyKey/PropertyKey.test.ts +++ b/packages/effect/test/Schema/Schema/PropertyKey/PropertyKey.test.ts @@ -1,12 +1,13 @@ import * as Schema from "effect/Schema" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("PropertyKey", () => { it("should handle symbol, string, and number", () => { const encodeSync = Schema.encodeSync(Schema.PropertyKey) const decodeSync = Schema.decodeSync(Schema.PropertyKey) const expectRoundtrip = (pk: PropertyKey) => { - expect(decodeSync(encodeSync(pk))).toStrictEqual(pk) + strictEqual(decodeSync(encodeSync(pk)), pk) } expectRoundtrip("path") diff --git a/packages/effect/test/Schema/Schema/PropertySignature.test.ts b/packages/effect/test/Schema/Schema/PropertySignature.test.ts index b7bcbd7be62..33491b0235c 100644 --- a/packages/effect/test/Schema/Schema/PropertySignature.test.ts +++ b/packages/effect/test/Schema/Schema/PropertySignature.test.ts @@ -3,24 +3,27 @@ import * as Option from "effect/Option" import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("PropertySignature", () => { it("should expose a from property", () => { const schema = S.propertySignature(S.String) - expect(schema.from).toStrictEqual(S.String) + strictEqual(schema.from, S.String) }) it("should expose a from property after an annotations call", () => { const schema = S.propertySignature(S.String).annotations({}) - expect(schema.from).toStrictEqual(S.String) + strictEqual(schema.from, S.String) }) it("toString", () => { - expect(String(S.optional(S.String))).toStrictEqual( + strictEqual( + String(S.optional(S.String)), `PropertySignature<"?:", string | undefined, never, "?:", string | undefined>` ) - expect(String(S.optional(S.String).pipe(S.fromKey("a")))).toStrictEqual( + strictEqual( + String(S.optional(S.String).pipe(S.fromKey("a"))), `PropertySignature<"?:", string | undefined, "a", "?:", string | undefined>` ) }) @@ -31,7 +34,7 @@ describe("PropertySignature", () => { a: S.propertySignature(S.String).annotations({ description: "a description" }).annotations({ title: "a title" }) }) const ast = schema.ast as AST.TypeLiteral - expect(ast.propertySignatures[0].annotations).toEqual({ + deepStrictEqual(ast.propertySignatures[0].annotations, { [AST.DescriptionAnnotationId]: "a description", [AST.TitleAnnotationId]: "a title" }) @@ -44,7 +47,7 @@ describe("PropertySignature", () => { }) }) const ast = schema.ast as AST.TypeLiteral - expect(ast.propertySignatures[0].annotations).toEqual({ + deepStrictEqual(ast.propertySignatures[0].annotations, { [AST.DescriptionAnnotationId]: "a description", [AST.TitleAnnotationId]: "a title" }) @@ -55,7 +58,7 @@ describe("PropertySignature", () => { a: S.optional(S.String).annotations({ description: "a description" }).annotations({ title: "a title" }) }) const ast = schema.ast as AST.TypeLiteral - expect(ast.propertySignatures[0].annotations).toEqual({ + deepStrictEqual(ast.propertySignatures[0].annotations, { [AST.DescriptionAnnotationId]: "a description", [AST.TitleAnnotationId]: "a title" }) @@ -68,7 +71,7 @@ describe("PropertySignature", () => { }) }) const ast = schema.ast as AST.TypeLiteral - expect(ast.propertySignatures[0].annotations).toEqual({ + deepStrictEqual(ast.propertySignatures[0].annotations, { [AST.DescriptionAnnotationId]: "a description", [AST.TitleAnnotationId]: "a title" }) @@ -82,7 +85,7 @@ describe("PropertySignature", () => { }) const ast = schema.ast as AST.Transformation const to = ast.to as AST.TypeLiteral - expect(to.propertySignatures[0].annotations).toEqual({ + deepStrictEqual(to.propertySignatures[0].annotations, { [AST.DescriptionAnnotationId]: "a description", [AST.TitleAnnotationId]: "a title" }) @@ -95,7 +98,7 @@ describe("PropertySignature", () => { }) const ast = schema.ast as AST.Transformation const to = ast.to as AST.TypeLiteral - expect(to.propertySignatures[0].annotations).toEqual({ + deepStrictEqual(to.propertySignatures[0].annotations, { [AST.DescriptionAnnotationId]: "a description", [AST.TitleAnnotationId]: "a title" }) diff --git a/packages/effect/test/Schema/Schema/ReadonlyMap/ReadonlyMapFromSelf.test.ts b/packages/effect/test/Schema/Schema/ReadonlyMap/ReadonlyMapFromSelf.test.ts index 135a36a0366..c572d6d5dd6 100644 --- a/packages/effect/test/Schema/Schema/ReadonlyMap/ReadonlyMapFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/ReadonlyMap/ReadonlyMapFromSelf.test.ts @@ -2,7 +2,8 @@ import * as P from "effect/ParseResult" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("ReadonlyMapFromSelf", () => { it("test roundtrip consistency", () => { @@ -50,24 +51,22 @@ describe("ReadonlyMapFromSelf", () => { it("is", () => { const schema = S.ReadonlyMapFromSelf({ key: S.Number, value: S.String }) const is = P.is(schema) - expect(is(new Map())).toEqual(true) - expect(is(new Map([[1, "a"], [2, "b"], [3, "c"]]))).toEqual(true) + assertTrue(is(new Map())) + assertTrue(is(new Map([[1, "a"], [2, "b"], [3, "c"]]))) - expect(is(null)).toEqual(false) - expect(is(undefined)).toEqual(false) - expect(is(new Map([[1, "a"], [2, 1]]))).toEqual(false) - expect(is(new Map([[1, 1], [2, "b"]]))).toEqual(false) - expect(is(new Map([[1, 1], [2, 2]]))).toEqual(false) - expect(is(new Map([["a", 1], ["b", 2], [3, 1]]))).toEqual(false) - expect(is(new Map([[1, "a"], [2, "b"], [3, 1]]))).toEqual(false) + assertFalse(is(null)) + assertFalse(is(undefined)) + assertFalse(is(new Map([[1, "a"], [2, 1]]))) + assertFalse(is(new Map([[1, 1], [2, "b"]]))) + assertFalse(is(new Map([[1, 1], [2, 2]]))) + assertFalse(is(new Map([["a", 1], ["b", 2], [3, 1]]))) + assertFalse(is(new Map([[1, "a"], [2, "b"], [3, 1]]))) }) it("pretty", () => { const schema = S.ReadonlyMapFromSelf({ key: S.Number, value: S.String }) const pretty = Pretty.make(schema) - expect(pretty(new Map())).toEqual("new Map([])") - expect(pretty(new Map([[1, "a"], [2, "b"]]))).toEqual( - `new Map([[1, "a"], [2, "b"]])` - ) + strictEqual(pretty(new Map()), "new Map([])") + strictEqual(pretty(new Map([[1, "a"], [2, "b"]])), `new Map([[1, "a"], [2, "b"]])`) }) }) diff --git a/packages/effect/test/Schema/Schema/ReadonlySet/ReadonlySetFromSelf.test.ts b/packages/effect/test/Schema/Schema/ReadonlySet/ReadonlySetFromSelf.test.ts index 720d5a472ea..e03533cb002 100644 --- a/packages/effect/test/Schema/Schema/ReadonlySet/ReadonlySetFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/ReadonlySet/ReadonlySetFromSelf.test.ts @@ -2,7 +2,8 @@ import * as P from "effect/ParseResult" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("ReadonlySetFromSelf", () => { it("test roundtrip consistency", () => { @@ -40,20 +41,18 @@ describe("ReadonlySetFromSelf", () => { it("is", () => { const schema = S.ReadonlySetFromSelf(S.String) const is = P.is(schema) - expect(is(new Set())).toEqual(true) - expect(is(new Set(["a", "b", "c"]))).toEqual(true) + assertTrue(is(new Set())) + assertTrue(is(new Set(["a", "b", "c"]))) - expect(is(new Set(["a", "b", 1]))).toEqual(false) - expect(is(null)).toEqual(false) - expect(is(undefined)).toEqual(false) + assertFalse(is(new Set(["a", "b", 1]))) + assertFalse(is(null)) + assertFalse(is(undefined)) }) it("pretty", () => { const schema = S.ReadonlySetFromSelf(S.String) const pretty = Pretty.make(schema) - expect(pretty(new Set())).toEqual("new Set([])") - expect(pretty(new Set(["a", "b"]))).toEqual( - `new Set(["a", "b"])` - ) + strictEqual(pretty(new Set()), "new Set([])") + strictEqual(pretty(new Set(["a", "b"])), `new Set(["a", "b"])`) }) }) diff --git a/packages/effect/test/Schema/Schema/Record/Record.test.ts b/packages/effect/test/Schema/Schema/Record/Record.test.ts index 955fbf72681..6987e6a5dea 100644 --- a/packages/effect/test/Schema/Schema/Record/Record.test.ts +++ b/packages/effect/test/Schema/Schema/Record/Record.test.ts @@ -3,14 +3,15 @@ import * as ParseResult from "effect/ParseResult" import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" -import { assert, describe, expect, it } from "vitest" +import { deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("record", () => { it("annotations()", () => { const schema = S.Record({ key: S.String, value: S.Number }).annotations({ identifier: "X" }).annotations({ title: "Y" }) - expect(schema.ast.annotations).toStrictEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.IdentifierAnnotationId]: "X", [AST.TitleAnnotationId]: "Y" }) @@ -18,8 +19,8 @@ describe("record", () => { it("should expose the key and the value", () => { const schema = S.Record({ key: S.String, value: S.Number }) - expect(schema.key).toStrictEqual(S.String) - expect(schema.value).toStrictEqual(S.Number) + strictEqual(schema.key, S.String) + strictEqual(schema.value, S.Number) }) it("should compute the partial result", () => { @@ -28,23 +29,23 @@ describe("record", () => { if (Either.isLeft(all)) { const issue = all.left.issue if (ParseResult.isComposite(issue)) { - expect(issue.output).toStrictEqual({ a: 1, c: 2 }) + deepStrictEqual(issue.output, { a: 1, c: 2 }) } else { - assert.fail("expected an And") + throw new Error("expected an And") } } else { - assert.fail("expected a Left") + throw new Error("expected a Left") } const first = S.decodeUnknownEither(schema)({ a: 1, b: "b", c: 2, d: "d" }, { errors: "first" }) if (Either.isLeft(first)) { const issue = first.left.issue if (ParseResult.isComposite(issue)) { - expect(issue.output).toStrictEqual({ a: 1 }) + deepStrictEqual(issue.output, { a: 1 }) } else { - assert.fail("expected an And") + throw new Error("expected an And") } } else { - assert.fail("expected a Left") + throw new Error("expected a Left") } }) diff --git a/packages/effect/test/Schema/Schema/Redacted/Redacted.test.ts b/packages/effect/test/Schema/Schema/Redacted/Redacted.test.ts index 9149216f2e6..3193298f992 100644 --- a/packages/effect/test/Schema/Schema/Redacted/Redacted.test.ts +++ b/packages/effect/test/Schema/Schema/Redacted/Redacted.test.ts @@ -2,7 +2,8 @@ import { Redacted } from "effect" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Redacted", () => { const schema = S.Redacted(S.String) @@ -40,6 +41,6 @@ describe("Redacted", () => { it("Pretty", () => { const pretty = Pretty.make(schema) - expect(pretty(Redacted.make("keep me safe"))).toEqual(`Redacted()`) + strictEqual(pretty(Redacted.make("keep me safe")), `Redacted()`) }) }) diff --git a/packages/effect/test/Schema/Schema/Redacted/RedactedFromSelf.test.ts b/packages/effect/test/Schema/Schema/Redacted/RedactedFromSelf.test.ts index e2daec54b98..e6f49a760f0 100644 --- a/packages/effect/test/Schema/Schema/Redacted/RedactedFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/Redacted/RedactedFromSelf.test.ts @@ -2,7 +2,8 @@ import { Redacted } from "effect" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("RedactedFromSelf", () => { const schema = S.RedactedFromSelf(S.String) @@ -39,6 +40,6 @@ describe("RedactedFromSelf", () => { it("Pretty", () => { const pretty = Pretty.make(schema) - expect(pretty(Redacted.make("keep me safe"))).toEqual(`Redacted()`) + strictEqual(pretty(Redacted.make("keep me safe")), `Redacted()`) }) }) diff --git a/packages/effect/test/Schema/Schema/Set/Set.test.ts b/packages/effect/test/Schema/Schema/Set/Set.test.ts index 7ac771c82d9..91e79230d70 100644 --- a/packages/effect/test/Schema/Schema/Set/Set.test.ts +++ b/packages/effect/test/Schema/Schema/Set/Set.test.ts @@ -1,8 +1,9 @@ import * as S from "effect/Schema" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Set", () => { it("description", () => { - expect(String(S.Set(S.Number))).toStrictEqual("(ReadonlyArray <-> Set)") + strictEqual(String(S.Set(S.Number)), "(ReadonlyArray <-> Set)") }) }) diff --git a/packages/effect/test/Schema/Schema/Set/SetFromSelf.test.ts b/packages/effect/test/Schema/Schema/Set/SetFromSelf.test.ts index 3f0abf847a9..f5b0ca50715 100644 --- a/packages/effect/test/Schema/Schema/Set/SetFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/Set/SetFromSelf.test.ts @@ -1,8 +1,9 @@ import * as S from "effect/Schema" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("SetFromSelf", () => { it("description", () => { - expect(String(S.SetFromSelf(S.Number))).toStrictEqual("Set") + strictEqual(String(S.SetFromSelf(S.Number)), "Set") }) }) diff --git a/packages/effect/test/Schema/Schema/SortedSet/SortedSetFromSelf.test.ts b/packages/effect/test/Schema/Schema/SortedSet/SortedSetFromSelf.test.ts index f7448da66e4..8a666431f2d 100644 --- a/packages/effect/test/Schema/Schema/SortedSet/SortedSetFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/SortedSet/SortedSetFromSelf.test.ts @@ -5,7 +5,8 @@ import * as Schema from "effect/Schema" import * as SortedSet from "effect/SortedSet" import * as S from "effect/String" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("SortedSetFromSelf", () => { it("test roundtrip consistency", () => { @@ -59,21 +60,19 @@ describe("SortedSetFromSelf", () => { it("is", () => { const schema = Schema.SortedSetFromSelf(Schema.String, S.Order, S.Order) const is = P.is(schema) - expect(is(SortedSet.fromIterable([], S.Order))).toEqual(true) - expect(is(SortedSet.fromIterable(["a", "b", "c"], S.Order))).toEqual(true) + assertTrue(is(SortedSet.fromIterable([], S.Order))) + assertTrue(is(SortedSet.fromIterable(["a", "b", "c"], S.Order))) - expect(is(new Set(["a", "b", 1]))).toEqual(false) - expect(is(null)).toEqual(false) - expect(is(undefined)).toEqual(false) + assertFalse(is(new Set(["a", "b", 1]))) + assertFalse(is(null)) + assertFalse(is(undefined)) }) it("pretty", () => { const schema = Schema.SortedSetFromSelf(Schema.String, S.Order, S.Order) const pretty = Pretty.make(schema) - expect(pretty(SortedSet.fromIterable([] as Array, S.Order))).toEqual("new SortedSet([])") - expect(pretty(SortedSet.fromIterable(["a", "b"], S.Order))).toEqual( - `new SortedSet(["a", "b"])` - ) + strictEqual(pretty(SortedSet.fromIterable([] as Array, S.Order)), "new SortedSet([])") + strictEqual(pretty(SortedSet.fromIterable(["a", "b"], S.Order)), `new SortedSet(["a", "b"])`) }) it("equivalence", () => { @@ -83,9 +82,9 @@ describe("SortedSetFromSelf", () => { const a = SortedSet.fromIterable([] as Array, S.Order) const b = SortedSet.fromIterable(["a"] as Array, S.Order) - expect(eq(a, a)).toBeTruthy() - expect(eq(a, b)).toBeFalsy() - expect(eq(b, a)).toBeFalsy() - expect(eq(b, b)).toBeTruthy() + assertTrue(eq(a, a)) + assertFalse(eq(a, b)) + assertFalse(eq(b, a)) + assertTrue(eq(b, b)) }) }) diff --git a/packages/effect/test/Schema/Schema/String/endsWith.test.ts b/packages/effect/test/Schema/Schema/String/endsWith.test.ts index d9f8439e9da..c2062d73d2f 100644 --- a/packages/effect/test/Schema/Schema/String/endsWith.test.ts +++ b/packages/effect/test/Schema/Schema/String/endsWith.test.ts @@ -1,17 +1,18 @@ import * as P from "effect/ParseResult" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue } from "effect/test/util" +import { describe, it } from "vitest" describe("endsWith", () => { it("is", () => { const schema = S.String.pipe(S.endsWith("a")) const is = P.is(schema) - expect(is("a")).toEqual(true) - expect(is("ba")).toEqual(true) + assertTrue(is("a")) + assertTrue(is("ba")) - expect(is("")).toEqual(false) - expect(is("b")).toEqual(false) + assertFalse(is("")) + assertFalse(is("b")) }) it("decoding", async () => { diff --git a/packages/effect/test/Schema/Schema/String/includes.test.ts b/packages/effect/test/Schema/Schema/String/includes.test.ts index eac837c1c62..379a1c3e733 100644 --- a/packages/effect/test/Schema/Schema/String/includes.test.ts +++ b/packages/effect/test/Schema/Schema/String/includes.test.ts @@ -2,7 +2,8 @@ import * as P from "effect/ParseResult" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("includes", () => { const schema = S.includes("a")(S.String) @@ -13,11 +14,11 @@ describe("includes", () => { it("is", () => { const is = P.is(schema) - expect(is("")).toEqual(false) - expect(is("a")).toEqual(true) - expect(is("aa")).toEqual(true) - expect(is("bac")).toEqual(true) - expect(is("ba")).toEqual(true) + assertFalse(is("")) + assertTrue(is("a")) + assertTrue(is("aa")) + assertTrue(is("bac")) + assertTrue(is("ba")) }) it("decoding", async () => { @@ -36,6 +37,6 @@ describe("includes", () => { it("Pretty", () => { const pretty = Pretty.make(schema) - expect(pretty("a")).toEqual(`"a"`) + strictEqual(pretty("a"), `"a"`) }) }) diff --git a/packages/effect/test/Schema/Schema/String/maxLength.test.ts b/packages/effect/test/Schema/Schema/String/maxLength.test.ts index 6d01b0c4624..bbc9df65beb 100644 --- a/packages/effect/test/Schema/Schema/String/maxLength.test.ts +++ b/packages/effect/test/Schema/Schema/String/maxLength.test.ts @@ -2,7 +2,8 @@ import * as P from "effect/ParseResult" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("maxLength", () => { it("test roundtrip consistency", () => { @@ -11,9 +12,9 @@ describe("maxLength", () => { it("is", () => { const is = P.is(S.maxLength(1)(S.String)) - expect(is("")).toEqual(true) - expect(is("a")).toEqual(true) - expect(is("aa")).toEqual(false) + assertTrue(is("")) + assertTrue(is("a")) + assertFalse(is("aa")) }) it("decoding", async () => { @@ -31,6 +32,6 @@ describe("maxLength", () => { it("pretty", () => { const pretty = Pretty.make(S.maxLength(0)(S.String)) - expect(pretty("a")).toEqual(`"a"`) + strictEqual(pretty("a"), `"a"`) }) }) diff --git a/packages/effect/test/Schema/Schema/String/minLength.test.ts b/packages/effect/test/Schema/Schema/String/minLength.test.ts index 9213249d2b3..369f65b74f1 100644 --- a/packages/effect/test/Schema/Schema/String/minLength.test.ts +++ b/packages/effect/test/Schema/Schema/String/minLength.test.ts @@ -2,7 +2,8 @@ import * as P from "effect/ParseResult" import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("minLength", () => { it("test roundtrip consistency", () => { @@ -11,9 +12,9 @@ describe("minLength", () => { it("is", () => { const is = P.is(S.minLength(1)(S.String)) - expect(is("")).toEqual(false) - expect(is("a")).toEqual(true) - expect(is("aa")).toEqual(true) + assertFalse(is("")) + assertTrue(is("a")) + assertTrue(is("aa")) }) it("decoding", async () => { @@ -31,6 +32,6 @@ describe("minLength", () => { it("pretty", () => { const pretty = Pretty.make(S.minLength(0)(S.String)) - expect(pretty("a")).toEqual(`"a"`) + strictEqual(pretty("a"), `"a"`) }) }) diff --git a/packages/effect/test/Schema/Schema/String/pattern.test.ts b/packages/effect/test/Schema/Schema/String/pattern.test.ts index 35fe0cb4889..586fd59a0ef 100644 --- a/packages/effect/test/Schema/Schema/String/pattern.test.ts +++ b/packages/effect/test/Schema/Schema/String/pattern.test.ts @@ -1,23 +1,24 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("pattern", () => { it("is", () => { const schema = S.String.pipe(S.pattern(/^abb+$/)) const is = S.is(schema) - expect(is("abb")).toEqual(true) - expect(is("abbb")).toEqual(true) + assertTrue(is("abb")) + assertTrue(is("abbb")) - expect(is("ab")).toEqual(false) - expect(is("a")).toEqual(false) + assertFalse(is("ab")) + assertFalse(is("a")) }) it("should reset lastIndex to 0 before each `test` call (#88)", () => { const regexp = /^(A|B)$/g const schema = S.String.pipe(S.pattern(regexp)) - expect(S.decodeSync(schema)("A")).toEqual("A") - expect(S.decodeSync(schema)("A")).toEqual("A") + strictEqual(S.decodeSync(schema)("A"), "A") + strictEqual(S.decodeSync(schema)("A"), "A") }) it("decoding", async () => { diff --git a/packages/effect/test/Schema/Schema/String/startsWith.test.ts b/packages/effect/test/Schema/Schema/String/startsWith.test.ts index 792fe8a5163..dd50658332e 100644 --- a/packages/effect/test/Schema/Schema/String/startsWith.test.ts +++ b/packages/effect/test/Schema/Schema/String/startsWith.test.ts @@ -1,17 +1,18 @@ import * as P from "effect/ParseResult" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue } from "effect/test/util" +import { describe, it } from "vitest" describe("startsWith", () => { it("is", () => { const schema = S.String.pipe(S.startsWith("a")) const is = P.is(schema) - expect(is("a")).toEqual(true) - expect(is("ab")).toEqual(true) + assertTrue(is("a")) + assertTrue(is("ab")) - expect(is("")).toEqual(false) - expect(is("b")).toEqual(false) + assertFalse(is("")) + assertFalse(is("b")) }) it("decoding", async () => { diff --git a/packages/effect/test/Schema/Schema/Struct/Struct.test.ts b/packages/effect/test/Schema/Schema/Struct/Struct.test.ts index 564a92785ae..94b0d29b0c1 100644 --- a/packages/effect/test/Schema/Schema/Struct/Struct.test.ts +++ b/packages/effect/test/Schema/Schema/Struct/Struct.test.ts @@ -1,12 +1,13 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Struct", () => { it("annotations()", () => { const schema = S.Struct({}).annotations({ identifier: "X" }).annotations({ title: "Y" }) - expect(schema.ast.annotations).toStrictEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.IdentifierAnnotationId]: "X", [AST.TitleAnnotationId]: "Y" }) @@ -17,7 +18,7 @@ describe("Struct", () => { a: S.String, b: S.Number }) - expect(schema.fields).toStrictEqual({ + deepStrictEqual(schema.fields, { a: S.String, b: S.Number }) @@ -28,8 +29,8 @@ describe("Struct", () => { a: S.String, b: S.Number }).annotations({ identifier: "struct test" }) - expect(schema.ast.annotations).toStrictEqual({ [AST.IdentifierAnnotationId]: "struct test" }) - expect(schema.fields).toStrictEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.IdentifierAnnotationId]: "struct test" }) + deepStrictEqual(schema.fields, { a: S.String, b: S.Number }) @@ -37,7 +38,7 @@ describe("Struct", () => { it(`should allow a "constructor" field name`, () => { const schema = S.Struct({ constructor: S.String }) - expect(schema.ast._tag).toEqual("TypeLiteral") + strictEqual(schema.ast._tag, "TypeLiteral") }) describe("decoding", () => { diff --git a/packages/effect/test/Schema/Schema/Struct/make.test.ts b/packages/effect/test/Schema/Schema/Struct/make.test.ts index 3cb4fcfc459..ac9287a838f 100644 --- a/packages/effect/test/Schema/Schema/Struct/make.test.ts +++ b/packages/effect/test/Schema/Schema/Struct/make.test.ts @@ -1,6 +1,7 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("make", () => { it("required fields", () => { @@ -29,16 +30,16 @@ describe("make", () => { it("validation can be disabled", () => { const schema = S.Struct({ a: S.NonEmptyString }) - expect(schema.make({ a: "" }, true)).toStrictEqual({ a: "" }) - expect(schema.make({ a: "" }, { disableValidation: true })).toStrictEqual({ a: "" }) + deepStrictEqual(schema.make({ a: "" }, true), { a: "" }) + deepStrictEqual(schema.make({ a: "" }, { disableValidation: true }), { a: "" }) }) it("should support defaults", () => { const schema = S.Struct({ a: S.propertySignature(S.Number).pipe(S.withConstructorDefault(() => 0)) }) - expect(schema.make({})).toStrictEqual({ a: 0 }) - expect(schema.make({ a: 1 })).toStrictEqual({ a: 1 }) + deepStrictEqual(schema.make({}), { a: 0 }) + deepStrictEqual(schema.make({ a: 1 }), { a: 1 }) }) it("should support lazy defaults", () => { @@ -46,38 +47,38 @@ describe("make", () => { const schema = S.Struct({ a: S.propertySignature(S.Number).pipe(S.withConstructorDefault(() => ++i)) }) - expect(schema.make({})).toStrictEqual({ a: 1 }) - expect(schema.make({})).toStrictEqual({ a: 2 }) + deepStrictEqual(schema.make({}), { a: 1 }) + deepStrictEqual(schema.make({}), { a: 2 }) schema.make({ a: 10 }) - expect(schema.make({})).toStrictEqual({ a: 3 }) + deepStrictEqual(schema.make({}), { a: 3 }) }) it("should treat `undefined` as missing field", () => { const schema = S.Struct({ a: S.propertySignature(S.UndefinedOr(S.Number)).pipe(S.withConstructorDefault(() => 0)) }) - expect(schema.make({})).toStrictEqual({ a: 0 }) - expect(schema.make({ a: undefined })).toStrictEqual({ a: 0 }) + deepStrictEqual(schema.make({}), { a: 0 }) + deepStrictEqual(schema.make({ a: undefined }), { a: 0 }) }) it("should accept void if the struct has no fields", () => { const schema = S.Struct({}) - expect(schema.make({})).toStrictEqual({}) - expect(schema.make(undefined)).toStrictEqual({}) - expect(schema.make(undefined, true)).toStrictEqual({}) - expect(schema.make(undefined, false)).toStrictEqual({}) - expect(schema.make()).toStrictEqual({}) + deepStrictEqual(schema.make({}), {}) + deepStrictEqual(schema.make(undefined), {}) + deepStrictEqual(schema.make(undefined, true), {}) + deepStrictEqual(schema.make(undefined, false), {}) + deepStrictEqual(schema.make(), {}) }) it("should accept void if the Class has all the fields with a default", () => { const schema = S.Struct({ a: S.propertySignature(S.Number).pipe(S.withConstructorDefault(() => 0)) }) - expect(schema.make({})).toStrictEqual({ a: 0 }) - expect(schema.make(undefined)).toStrictEqual({ a: 0 }) - expect(schema.make(undefined, true)).toStrictEqual({ a: 0 }) - expect(schema.make(undefined, false)).toStrictEqual({ a: 0 }) - expect(schema.make()).toStrictEqual({ a: 0 }) + deepStrictEqual(schema.make({}), { a: 0 }) + deepStrictEqual(schema.make(undefined), { a: 0 }) + deepStrictEqual(schema.make(undefined, true), { a: 0 }) + deepStrictEqual(schema.make(undefined, false), { a: 0 }) + deepStrictEqual(schema.make(), { a: 0 }) }) it("props declarations with defaults (data last)", () => { diff --git a/packages/effect/test/Schema/Schema/Struct/omit.test.ts b/packages/effect/test/Schema/Schema/Struct/omit.test.ts index 3a24e191544..7b317d39f2c 100644 --- a/packages/effect/test/Schema/Schema/Struct/omit.test.ts +++ b/packages/effect/test/Schema/Schema/Struct/omit.test.ts @@ -1,9 +1,10 @@ import * as S from "effect/Schema" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("omit", () => { it("should work", () => { const schema = S.Struct({ a: S.String, b: S.Number, c: S.Boolean }).omit("c") - expect(schema.fields).toStrictEqual({ a: S.String, b: S.Number }) + deepStrictEqual(schema.fields, { a: S.String, b: S.Number }) }) }) diff --git a/packages/effect/test/Schema/Schema/Struct/pick.test.ts b/packages/effect/test/Schema/Schema/Struct/pick.test.ts index 2dbd2c0f1e6..74355316e8a 100644 --- a/packages/effect/test/Schema/Schema/Struct/pick.test.ts +++ b/packages/effect/test/Schema/Schema/Struct/pick.test.ts @@ -1,9 +1,10 @@ import * as S from "effect/Schema" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("pick", () => { it("should work", () => { const schema = S.Struct({ a: S.String, b: S.Number, c: S.Boolean }).pick("a", "b") - expect(schema.fields).toStrictEqual({ a: S.String, b: S.Number }) + deepStrictEqual(schema.fields, { a: S.String, b: S.Number }) }) }) diff --git a/packages/effect/test/Schema/Schema/TaggedStruct/make.test.ts b/packages/effect/test/Schema/Schema/TaggedStruct/make.test.ts index 4889c13451f..9a7e0b11c62 100644 --- a/packages/effect/test/Schema/Schema/TaggedStruct/make.test.ts +++ b/packages/effect/test/Schema/Schema/TaggedStruct/make.test.ts @@ -1,16 +1,17 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("make", () => { it("tag should be optional", () => { const schema = S.TaggedStruct("A", { value: S.String }) - expect(schema.make({ value: "a" })).toStrictEqual({ _tag: "A", value: "a" }) + deepStrictEqual(schema.make({ value: "a" }), { _tag: "A", value: "a" }) }) it("should support empty fields", () => { const schema = S.TaggedStruct("A", {}) - expect(schema.make({})).toStrictEqual({ _tag: "A" }) + deepStrictEqual(schema.make({}), { _tag: "A" }) }) it("should expose the fields", () => { @@ -20,6 +21,6 @@ describe("make", () => { it("should support multiple tags", () => { const schema = S.TaggedStruct("A", { category: S.tag("B"), value: S.String }) - expect(schema.make({ value: "a" })).toStrictEqual({ _tag: "A", category: "B", value: "a" }) + deepStrictEqual(schema.make({ value: "a" }), { _tag: "A", category: "B", value: "a" }) }) }) diff --git a/packages/effect/test/Schema/Schema/TemplateLiteral/TemplateLiteral.test.ts b/packages/effect/test/Schema/Schema/TemplateLiteral/TemplateLiteral.test.ts index 449736e41c4..0e47d3634ad 100644 --- a/packages/effect/test/Schema/Schema/TemplateLiteral/TemplateLiteral.test.ts +++ b/packages/effect/test/Schema/Schema/TemplateLiteral/TemplateLiteral.test.ts @@ -3,8 +3,9 @@ import type * as array_ from "effect/Array" import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" +import { deepStrictEqual, strictEqual, throws } from "effect/test/util" import * as fc from "fast-check" -import { describe, expect, it } from "vitest" +import { describe, it } from "vitest" type TemplateLiteralParameter = S.Schema.AnyNoContext | AST.LiteralValue @@ -13,7 +14,7 @@ const expectPattern = ( expectedPattern: string ) => { const ast = S.TemplateLiteral(...params).ast as AST.TemplateLiteral - expect(AST.getTemplateLiteralRegExp(ast).source).toEqual(expectedPattern) + strictEqual(AST.getTemplateLiteralRegExp(ast).source, expectedPattern) } const expectAST = ( @@ -22,8 +23,8 @@ const expectAST = ( expectedString: string ) => { const ast = S.TemplateLiteral(...params).ast - expect(ast).toEqual(expectedAST) - expect(String(ast)).toEqual(expectedString) + deepStrictEqual(ast, expectedAST) + strictEqual(String(ast), expectedString) } const expectProperty = ( @@ -39,12 +40,14 @@ const expectProperty = ( describe("TemplateLiteral", () => { it("should throw on unsupported template literal spans", () => { - expect(() => S.TemplateLiteral(S.Boolean)).toThrow( + throws( + () => S.TemplateLiteral(S.Boolean), new Error(`Unsupported template literal span schema (BooleanKeyword): boolean`) ) - expect(() => S.TemplateLiteral(S.Union(S.Boolean, S.SymbolFromSelf))).toThrow( + throws( + () => S.TemplateLiteral(S.Union(S.Boolean, S.SymbolFromSelf)), new Error(`Unsupported template literal span schema (Union): boolean | symbol`) ) diff --git a/packages/effect/test/Schema/Schema/TemplateLiteralParser.test.ts b/packages/effect/test/Schema/Schema/TemplateLiteralParser.test.ts index 69c0be1c450..078694ecaca 100644 --- a/packages/effect/test/Schema/Schema/TemplateLiteralParser.test.ts +++ b/packages/effect/test/Schema/Schema/TemplateLiteralParser.test.ts @@ -2,7 +2,8 @@ import type * as array_ from "effect/Array" import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual, strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" type TemplateLiteralParameter = S.Schema.AnyNoContext | AST.LiteralValue @@ -11,17 +12,19 @@ const expectPattern = ( expectedPattern: string ) => { const ast = S.TemplateLiteral(...params).ast as AST.TemplateLiteral - expect(AST.getTemplateLiteralCapturingRegExp(ast).source).toEqual(expectedPattern) + strictEqual(AST.getTemplateLiteralCapturingRegExp(ast).source, expectedPattern) } describe("TemplateLiteralParser", () => { it("should throw on unsupported template literal spans", () => { - expect(() => S.TemplateLiteralParser(S.Boolean)).toThrow( + throws( + () => S.TemplateLiteralParser(S.Boolean), new Error(`Unsupported template literal span schema (BooleanKeyword): boolean`) ) - expect(() => S.TemplateLiteralParser(S.Union(S.Boolean, S.SymbolFromSelf))).toThrow( + throws( + () => S.TemplateLiteralParser(S.Union(S.Boolean, S.SymbolFromSelf)), new Error(`Unsupported template literal span schema (Union): boolean | symbol`) ) @@ -62,7 +65,7 @@ schema (Union): boolean | symbol`) it("should expose the params", () => { const params = ["/", S.Int, "/", S.String] as const const schema = S.TemplateLiteralParser(...params) - expect(schema.params).toStrictEqual(params) + deepStrictEqual(schema.params, params) }) describe("decoding", () => { diff --git a/packages/effect/test/Schema/Schema/Trimmed/Trimmed.test.ts b/packages/effect/test/Schema/Schema/Trimmed/Trimmed.test.ts index 530d791f021..9682226efef 100644 --- a/packages/effect/test/Schema/Schema/Trimmed/Trimmed.test.ts +++ b/packages/effect/test/Schema/Schema/Trimmed/Trimmed.test.ts @@ -4,7 +4,8 @@ import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Trimmed", () => { const schema = S.Trimmed @@ -14,20 +15,20 @@ describe("Trimmed", () => { if (Option.isSome(annotation) && "pattern" in annotation.value && Predicate.isString(annotation.value.pattern)) { const regexp = new RegExp(annotation.value.pattern) const is = (s: string) => regexp.test(s) - expect(is("hello")).toBe(true) - expect(is(" hello")).toBe(false) - expect(is("hello ")).toBe(false) - expect(is(" hello ")).toBe(false) - expect(is("h")).toBe(true) - expect(is(" a b")).toBe(false) - expect(is("a b ")).toBe(false) - expect(is("a b")).toBe(true) - expect(is("a b")).toBe(true) - expect(is("")).toBe(true) - expect(is("\n")).toEqual(false) - expect(is("a\nb")).toEqual(true) - expect(is("a\nb ")).toEqual(false) - expect(is(" a\nb")).toEqual(false) + assertTrue(is("hello")) + assertFalse(is(" hello")) + assertFalse(is("hello ")) + assertFalse(is(" hello ")) + assertTrue(is("h")) + assertFalse(is(" a b")) + assertFalse(is("a b ")) + assertTrue(is("a b")) + assertTrue(is("a b")) + assertTrue(is("")) + assertFalse(is("\n")) + assertTrue(is("a\nb")) + assertFalse(is("a\nb ")) + assertFalse(is(" a\nb")) } }) @@ -37,16 +38,16 @@ describe("Trimmed", () => { it("is", () => { const is = P.is(schema) - expect(is("a")).toEqual(true) - expect(is("")).toEqual(true) - expect(is("a ")).toEqual(false) - expect(is(" a")).toEqual(false) - expect(is(" a ")).toEqual(false) - expect(is(" ")).toEqual(false) - expect(is("\n")).toEqual(false) - expect(is("a\nb")).toEqual(true) - expect(is("a\nb ")).toEqual(false) - expect(is(" a\nb")).toEqual(false) + assertTrue(is("a")) + assertTrue(is("")) + assertFalse(is("a ")) + assertFalse(is(" a")) + assertFalse(is(" a ")) + assertFalse(is(" ")) + assertFalse(is("\n")) + assertTrue(is("a\nb")) + assertFalse(is("a\nb ")) + assertFalse(is(" a\nb")) }) it("decoding", async () => { @@ -103,7 +104,7 @@ describe("Trimmed", () => { it("pretty", () => { const pretty = Pretty.make(schema) - expect(pretty("a")).toEqual(`"a"`) - expect(pretty("")).toEqual(`""`) + strictEqual(pretty("a"), `"a"`) + strictEqual(pretty(""), `""`) }) }) diff --git a/packages/effect/test/Schema/Schema/Tuple/Tuple.test.ts b/packages/effect/test/Schema/Schema/Tuple/Tuple.test.ts index 048da31cfa2..9093bff8981 100644 --- a/packages/effect/test/Schema/Schema/Tuple/Tuple.test.ts +++ b/packages/effect/test/Schema/Schema/Tuple/Tuple.test.ts @@ -1,12 +1,13 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Tuple", () => { it("annotations()", () => { const schema = S.Tuple(S.String, S.Number).annotations({ identifier: "X" }).annotations({ title: "Y" }) - expect(schema.ast.annotations).toStrictEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.IdentifierAnnotationId]: "X", [AST.TitleAnnotationId]: "Y" }) @@ -14,7 +15,7 @@ describe("Tuple", () => { it("should expose the elements", () => { const schema = S.Tuple(S.String, S.Number) - expect(schema.elements).toStrictEqual([S.String, S.Number]) + deepStrictEqual(schema.elements, [S.String, S.Number]) }) describe("decoding", () => { diff --git a/packages/effect/test/Schema/Schema/URL/URL.test.ts b/packages/effect/test/Schema/Schema/URL/URL.test.ts index 93a82af939b..1df4acfb7c1 100644 --- a/packages/effect/test/Schema/Schema/URL/URL.test.ts +++ b/packages/effect/test/Schema/Schema/URL/URL.test.ts @@ -1,7 +1,8 @@ import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("URL", () => { const schema = S.URL @@ -41,6 +42,6 @@ describe("URL", () => { const pretty = Pretty.make(schema) const input = "https://effecty.website:443" const prettified = "https://effecty.website/" - expect(pretty(new URL(input))).toEqual(prettified) + strictEqual(pretty(new URL(input)), prettified) }) }) diff --git a/packages/effect/test/Schema/Schema/URL/URLFromSelf.test.ts b/packages/effect/test/Schema/Schema/URL/URLFromSelf.test.ts index bff6e5a15dd..248fdf69f3e 100644 --- a/packages/effect/test/Schema/Schema/URL/URLFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/URL/URLFromSelf.test.ts @@ -1,7 +1,8 @@ import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("URLFromSelf", () => { const schema = S.URLFromSelf @@ -32,6 +33,6 @@ describe("URLFromSelf", () => { it("Pretty", () => { const pretty = Pretty.make(schema) - expect(pretty(new URL("https://effect.website"))).toEqual(`https://effect.website/`) + strictEqual(pretty(new URL("https://effect.website")), `https://effect.website/`) }) }) diff --git a/packages/effect/test/Schema/Schema/Uint8Array/Uint8Array.test.ts b/packages/effect/test/Schema/Schema/Uint8Array/Uint8Array.test.ts index 889971d7725..6ef95ee8984 100644 --- a/packages/effect/test/Schema/Schema/Uint8Array/Uint8Array.test.ts +++ b/packages/effect/test/Schema/Schema/Uint8Array/Uint8Array.test.ts @@ -1,6 +1,7 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertTrue } from "effect/test/util" +import { describe, it } from "vitest" describe("Uint8Array > Uint8Array", () => { const schema = S.Uint8Array @@ -10,7 +11,7 @@ describe("Uint8Array > Uint8Array", () => { }) it("isSchema", () => { - expect(S.isSchema(schema)).toEqual(true) + assertTrue(S.isSchema(schema)) }) it("decoding", async () => { diff --git a/packages/effect/test/Schema/Schema/Uint8Array/Uint8ArrayFromSelf.test.ts b/packages/effect/test/Schema/Schema/Uint8Array/Uint8ArrayFromSelf.test.ts index a516eb0bebb..59051872f91 100644 --- a/packages/effect/test/Schema/Schema/Uint8Array/Uint8ArrayFromSelf.test.ts +++ b/packages/effect/test/Schema/Schema/Uint8Array/Uint8ArrayFromSelf.test.ts @@ -1,7 +1,8 @@ import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Uint8Array > Uint8ArrayFromSelf", () => { it("test roundtrip consistency", () => { @@ -24,6 +25,6 @@ describe("Uint8Array > Uint8ArrayFromSelf", () => { it("pretty", () => { const pretty = Pretty.make(S.Uint8ArrayFromSelf) - expect(pretty(Uint8Array.from([0, 1, 2, 3]))).toEqual("new Uint8Array([0,1,2,3])") + strictEqual(pretty(Uint8Array.from([0, 1, 2, 3])), "new Uint8Array([0,1,2,3])") }) }) diff --git a/packages/effect/test/Schema/Schema/Union/Union.test.ts b/packages/effect/test/Schema/Schema/Union/Union.test.ts index bdd5a4c966b..0e56544419e 100644 --- a/packages/effect/test/Schema/Schema/Union/Union.test.ts +++ b/packages/effect/test/Schema/Schema/Union/Union.test.ts @@ -1,12 +1,13 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Union", () => { it("should allow annotations to be applied", () => { const schema = S.Union(S.String, S.Number).annotations({ identifier: "X" }).annotations({ title: "Y" }) - expect(schema.ast.annotations).toStrictEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.IdentifierAnnotationId]: "X", [AST.TitleAnnotationId]: "Y" }) @@ -14,7 +15,7 @@ describe("Union", () => { it("should expose the union members", () => { const schema = S.Union(S.String, S.Number) - expect(schema.members).toStrictEqual([S.String, S.Number]) + deepStrictEqual(schema.members, [S.String, S.Number]) }) it("should return a `Never` schema when no members are provided", async () => { diff --git a/packages/effect/test/Schema/Schema/annotations.test.ts b/packages/effect/test/Schema/Schema/annotations.test.ts index 1028a8bda44..ac591d383dd 100644 --- a/packages/effect/test/Schema/Schema/annotations.test.ts +++ b/packages/effect/test/Schema/Schema/annotations.test.ts @@ -3,7 +3,8 @@ import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe(".annotations()", () => { it("should return a Schema", () => { @@ -11,71 +12,71 @@ describe(".annotations()", () => { [AST.TitleAnnotationId]: "MyString", [AST.DescriptionAnnotationId]: "a string" }) - expect(schema.ast.annotations).toEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.TitleAnnotationId]: "MyString", [AST.DescriptionAnnotationId]: "a string" }) - expect(S.isSchema(schema)).toEqual(true) + assertTrue(S.isSchema(schema)) }) it("title", () => { const schema = S.String.annotations({ title: "MyString" }) - expect(schema.ast.annotations).toEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.TitleAnnotationId]: "MyString", [AST.DescriptionAnnotationId]: "a string" }) - expect(S.isSchema(schema)).toEqual(true) + assertTrue(S.isSchema(schema)) }) it("description", () => { const schema = S.String.annotations({ description: "description" }) - expect(schema.ast.annotations).toEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.DescriptionAnnotationId]: "description", [AST.TitleAnnotationId]: "string" }) - expect(S.isSchema(schema)).toEqual(true) + assertTrue(S.isSchema(schema)) }) it("examples", () => { const schema = S.String.annotations({ examples: ["example"] }) - expect(schema.ast.annotations).toEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.ExamplesAnnotationId]: ["example"], [AST.TitleAnnotationId]: "string", [AST.DescriptionAnnotationId]: "a string" }) - expect(S.isSchema(schema)).toEqual(true) + assertTrue(S.isSchema(schema)) }) it("default", () => { const schema = S.String.annotations({ default: "a" }) - expect(schema.ast.annotations).toEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.DefaultAnnotationId]: "a", [AST.TitleAnnotationId]: "string", [AST.DescriptionAnnotationId]: "a string" }) - expect(S.isSchema(schema)).toEqual(true) + assertTrue(S.isSchema(schema)) }) it("documentation", () => { const schema = S.String.annotations({ documentation: "documentation" }) - expect(schema.ast.annotations).toEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.DocumentationAnnotationId]: "documentation", [AST.TitleAnnotationId]: "string", [AST.DescriptionAnnotationId]: "a string" }) - expect(S.isSchema(schema)).toEqual(true) + assertTrue(S.isSchema(schema)) }) it("concurrency", () => { const schema = S.Struct({ a: S.String }).annotations({ concurrency: 1 }) - expect(schema.ast.annotations).toEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.ConcurrencyAnnotationId]: 1 }) }) it("batching", () => { const schema = S.Struct({ a: S.String }).annotations({ batching: "inherit" }) - expect(schema.ast.annotations).toEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.BatchingAnnotationId]: "inherit" }) }) @@ -124,7 +125,7 @@ describe(".annotations()", () => { S.maxLength(10, { message: (issue) => `${issue.actual} is too long` }) ) - expect(S.isSchema(schema)).toEqual(true) + assertTrue(S.isSchema(schema)) await Util.assertions.decoding.fail(schema, null, "not a string") await Util.assertions.decoding.fail(schema, "", "required") await Util.assertions.decoding.succeed(schema, "a", "a") @@ -139,7 +140,7 @@ describe(".annotations()", () => { const AFromSelf = S.instanceOf(A, { pretty: prettyA }) - expect(Pretty.make(AFromSelf)(new A("value"))).toEqual(`new A("value")`) + strictEqual(Pretty.make(AFromSelf)(new A("value")), `new A("value")`) }) }) @@ -153,5 +154,5 @@ declare module "effect/Schema" { it("should support custom annotations", () => { const schema = S.String.annotations({ formName: "a" }) - expect(schema.ast.annotations["formName"]).toEqual("a") + strictEqual(schema.ast.annotations["formName"], "a") }) diff --git a/packages/effect/test/Schema/Schema/asserts.test.ts b/packages/effect/test/Schema/Schema/asserts.test.ts index 4f190a3344d..6bb50283a58 100644 --- a/packages/effect/test/Schema/Schema/asserts.test.ts +++ b/packages/effect/test/Schema/Schema/asserts.test.ts @@ -1,7 +1,8 @@ import * as ParseResult from "effect/ParseResult" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("asserts", () => { it("the returned error should be a ParseError", () => { @@ -9,25 +10,26 @@ describe("asserts", () => { try { asserts(1) } catch (e) { - expect(ParseResult.isParseError(e)).toBe(true) + assertTrue(ParseResult.isParseError(e)) } }) it("should respect outer/inner options", () => { const schema = S.Struct({ a: Util.NumberFromChar }) const input = { a: 1, b: "b" } - expect(() => S.asserts(schema)(input, { onExcessProperty: "error" })).toThrow( - new Error(`{ readonly a: number } + Util.assertParseError( + () => S.asserts(schema)(input, { onExcessProperty: "error" }), + `{ readonly a: number } └─ ["b"] - └─ is unexpected, expected: "a"`) + └─ is unexpected, expected: "a"` ) - expect(() => S.asserts(schema, { onExcessProperty: "error" })(input)).toThrow( - new Error(`{ readonly a: number } + Util.assertParseError( + () => S.asserts(schema, { onExcessProperty: "error" })(input), + `{ readonly a: number } └─ ["b"] - └─ is unexpected, expected: "a"`) + └─ is unexpected, expected: "a"` ) - expect(S.asserts(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" })) - .toEqual(undefined) + strictEqual(S.asserts(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" }), undefined) }) describe("struct", () => { diff --git a/packages/effect/test/Schema/Schema/brand.test.ts b/packages/effect/test/Schema/Schema/brand.test.ts index a6347240f55..73766b4d087 100644 --- a/packages/effect/test/Schema/Schema/brand.test.ts +++ b/packages/effect/test/Schema/Schema/brand.test.ts @@ -1,11 +1,12 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("brand", () => { it("toString", () => { - expect(String(S.String.pipe(S.brand("my-brand")))).toStrictEqual(`string & Brand<"my-brand">`) + strictEqual(String(S.String.pipe(S.brand("my-brand"))), `string & Brand<"my-brand">`) }) it("the constructor should validate the input by default", () => { @@ -22,8 +23,8 @@ describe("brand", () => { it("the constructor validation can be disabled", () => { const schema = S.NonEmptyString.pipe(S.brand("A")) - expect(schema.make("", true)).toStrictEqual("") - expect(schema.make("", { disableValidation: true })).toStrictEqual("") + strictEqual(schema.make("", true), "") + strictEqual(schema.make("", { disableValidation: true }), "") }) describe("annotations", () => { @@ -32,7 +33,7 @@ describe("brand", () => { const annotatedSchema = schema.annotations({ description: "description" }).annotations({ title: "title" }) - expect(annotatedSchema.ast.annotations).toEqual({ + deepStrictEqual(annotatedSchema.ast.annotations, { [AST.BrandAnnotationId]: ["A"], [AST.TitleAnnotationId]: "title", [AST.DescriptionAnnotationId]: "description" @@ -47,7 +48,7 @@ describe("brand", () => { const annotatedSchema = schema.annotations({ description: "description" }).annotations({ title: "title" }) - expect(typeof annotatedSchema.make).toBe("function") + strictEqual(typeof annotatedSchema.make, "function") }) it("brand as string (1 brand)", () => { @@ -57,9 +58,9 @@ describe("brand", () => { description: "description" }) ) - expect(String(schema)).toBe(`int & Brand<"A">`) + strictEqual(String(schema), `int & Brand<"A">`) - expect(schema.ast.annotations).toEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.SchemaIdAnnotationId]: S.IntSchemaId, [AST.BrandAnnotationId]: ["A"], [AST.TitleAnnotationId]: "int", @@ -77,9 +78,9 @@ describe("brand", () => { }) ) - expect(String(schema)).toBe(`int & Brand<"A"> & Brand<"B">`) + strictEqual(String(schema), `int & Brand<"A"> & Brand<"B">`) - expect(schema.ast.annotations).toEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.SchemaIdAnnotationId]: S.IntSchemaId, [AST.BrandAnnotationId]: ["A", "B"], [AST.TitleAnnotationId]: "int", @@ -99,9 +100,9 @@ describe("brand", () => { }) ) - expect(String(schema)).toBe("int & Brand & Brand") + strictEqual(String(schema), "int & Brand & Brand") - expect(schema.ast.annotations).toEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.SchemaIdAnnotationId]: S.IntSchemaId, [AST.BrandAnnotationId]: [A, B], [AST.TitleAnnotationId]: "int", @@ -119,9 +120,9 @@ describe("brand", () => { const PositiveInt = S.NumberFromString.pipe(int, positive) const is = S.is(PositiveInt) - expect(is(1)).toEqual(true) - expect(is(-1)).toEqual(false) - expect(is(1.2)).toEqual(false) + assertTrue(is(1)) + assertFalse(is(-1)) + assertFalse(is(1.2)) }) describe("decoding", () => { diff --git a/packages/effect/test/Schema/Schema/decodeOption.test.ts b/packages/effect/test/Schema/Schema/decodeOption.test.ts index 38b18c9d16a..8d143b0ef2d 100644 --- a/packages/effect/test/Schema/Schema/decodeOption.test.ts +++ b/packages/effect/test/Schema/Schema/decodeOption.test.ts @@ -1,25 +1,24 @@ -import { Option, Schema as S } from "effect" +import { Schema as S } from "effect" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertNone, assertSome } from "effect/test/util" +import { describe, it } from "vitest" describe("decodeOption", () => { it("should return none on async", () => { - expect(S.decodeOption(Util.AsyncString)("a")).toStrictEqual(Option.none()) + assertNone(S.decodeOption(Util.AsyncString)("a")) }) const schema = S.Struct({ a: Util.NumberFromChar }) it("should return None on invalid values", () => { - expect(S.decodeOption(schema)({ a: "1" })).toStrictEqual(Option.some({ a: 1 })) - expect(S.decodeOption(schema)({ a: "10" })).toStrictEqual(Option.none()) + assertSome(S.decodeOption(schema)({ a: "1" }), { a: 1 }) + assertNone(S.decodeOption(schema)({ a: "10" })) }) it("should respect outer/inner options", () => { const input = { a: "1", b: "b" } - expect(S.decodeOption(schema)(input, { onExcessProperty: "error" })).toStrictEqual(Option.none()) - expect(S.decodeOption(schema, { onExcessProperty: "error" })(input)).toStrictEqual(Option.none()) - expect(S.decodeOption(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" })).toStrictEqual( - Option.some({ a: 1 }) - ) + assertNone(S.decodeOption(schema)(input, { onExcessProperty: "error" })) + assertNone(S.decodeOption(schema, { onExcessProperty: "error" })(input)) + assertSome(S.decodeOption(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" }), { a: 1 }) }) }) diff --git a/packages/effect/test/Schema/Schema/decodePromise.test.ts b/packages/effect/test/Schema/Schema/decodePromise.test.ts index 61fcda1cfa1..f0f02dda2b6 100644 --- a/packages/effect/test/Schema/Schema/decodePromise.test.ts +++ b/packages/effect/test/Schema/Schema/decodePromise.test.ts @@ -1,12 +1,13 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("decodePromise", () => { const schema = S.Struct({ a: Util.NumberFromChar }) it("should return None on invalid values", async () => { - expect(await S.decodePromise(schema)({ a: "1" })).toStrictEqual({ a: 1 }) + deepStrictEqual(await S.decodePromise(schema)({ a: "1" }), { a: 1 }) await Util.assertions.promise.fail( S.decodePromise(schema)({ a: "10" }), @@ -23,8 +24,10 @@ describe("decodePromise", () => { it("should respect outer/inner options", async () => { const input = { a: "1", b: "b" } - expect(await S.decodePromise(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" })) - .toStrictEqual({ a: 1 }) + deepStrictEqual( + await S.decodePromise(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" }), + { a: 1 } + ) await Util.assertions.promise.fail( S.decodePromise(schema)(input, { onExcessProperty: "error" }), diff --git a/packages/effect/test/Schema/Schema/decodeSync.test.ts b/packages/effect/test/Schema/Schema/decodeSync.test.ts index 09cc7fbfa24..73c59e95e27 100644 --- a/packages/effect/test/Schema/Schema/decodeSync.test.ts +++ b/packages/effect/test/Schema/Schema/decodeSync.test.ts @@ -1,45 +1,49 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("decodeSync", () => { const schema = S.Struct({ a: Util.NumberFromChar }) it("should throw on invalid values", () => { - expect(S.decodeSync(schema)({ a: "1" })).toEqual({ a: 1 }) - expect(() => S.decodeSync(schema)({ a: "10" })).toThrow( - new Error(`{ readonly a: NumberFromChar } + deepStrictEqual(S.decodeSync(schema)({ a: "1" }), { a: 1 }) + Util.assertParseError( + () => S.decodeSync(schema)({ a: "10" }), + `{ readonly a: NumberFromChar } └─ ["a"] └─ NumberFromChar └─ Encoded side transformation failure └─ Char └─ Predicate refinement failure - └─ Expected a single character, actual "10"`) + └─ Expected a single character, actual "10"` ) }) it("should throw on async", () => { - expect(() => S.decodeSync(Util.AsyncString)("a")).toThrow( - new Error( - `AsyncString + Util.assertParseError( + () => S.decodeSync(Util.AsyncString)("a"), + `AsyncString └─ cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work` - ) ) }) it("should respect outer/inner options", () => { const input = { a: "1", b: "b" } - expect(() => S.decodeSync(schema)(input, { onExcessProperty: "error" })).toThrow( - new Error(`{ readonly a: NumberFromChar } + Util.assertParseError( + () => S.decodeSync(schema)(input, { onExcessProperty: "error" }), + `{ readonly a: NumberFromChar } └─ ["b"] - └─ is unexpected, expected: "a"`) + └─ is unexpected, expected: "a"` ) - expect(() => S.decodeSync(schema, { onExcessProperty: "error" })(input)).toThrow( - new Error(`{ readonly a: NumberFromChar } + Util.assertParseError( + () => S.decodeSync(schema, { onExcessProperty: "error" })(input), + `{ readonly a: NumberFromChar } └─ ["b"] - └─ is unexpected, expected: "a"`) + └─ is unexpected, expected: "a"` ) - expect(S.decodeSync(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" })) - .toEqual({ a: 1 }) + deepStrictEqual(S.decodeSync(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" }), { + a: 1 + }) }) }) diff --git a/packages/effect/test/Schema/Schema/decodeUnknownOption.test.ts b/packages/effect/test/Schema/Schema/decodeUnknownOption.test.ts index 954057a1f9b..77837c1b00c 100644 --- a/packages/effect/test/Schema/Schema/decodeUnknownOption.test.ts +++ b/packages/effect/test/Schema/Schema/decodeUnknownOption.test.ts @@ -1,9 +1,10 @@ -import { Option, Schema as S } from "effect" +import { Schema as S } from "effect" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertNone } from "effect/test/util" +import { describe, it } from "vitest" describe("decodeUnknownOption", () => { it("should return none on async", () => { - expect(S.decodeUnknownOption(Util.AsyncString)("a")).toStrictEqual(Option.none()) + assertNone(S.decodeUnknownOption(Util.AsyncString)("a")) }) }) diff --git a/packages/effect/test/Schema/Schema/decodeUnknownSync.test.ts b/packages/effect/test/Schema/Schema/decodeUnknownSync.test.ts index a0968fc0a08..62a05823d09 100644 --- a/packages/effect/test/Schema/Schema/decodeUnknownSync.test.ts +++ b/packages/effect/test/Schema/Schema/decodeUnknownSync.test.ts @@ -1,23 +1,23 @@ import * as ParseResult from "effect/ParseResult" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertTrue } from "effect/test/util" +import { describe, it } from "vitest" describe("decodeUnknownSync", () => { it("the returned error should be a ParseError", () => { try { S.decodeUnknownSync(S.String)(1) } catch (e) { - expect(ParseResult.isParseError(e)).toBe(true) + assertTrue(ParseResult.isParseError(e)) } }) it("should throw on async", () => { - expect(() => S.decodeUnknownSync(Util.AsyncString)("a")).toThrow( - new Error( - `AsyncString + Util.assertParseError( + () => S.decodeUnknownSync(Util.AsyncString)("a"), + `AsyncString └─ cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work` - ) ) }) @@ -26,8 +26,7 @@ describe("decodeUnknownSync", () => { S.decodeUnknownSync(Util.DependencyString as any)("a") throw new Error("unexpected success") } catch (e: any) { - expect((e.message as string).startsWith(`DependencyString -└─ Service not found`)) + assertTrue((e.message as string).includes("Service not found: Name")) } }) }) diff --git a/packages/effect/test/Schema/Schema/encodeOption.test.ts b/packages/effect/test/Schema/Schema/encodeOption.test.ts index 0e0665ebe11..9d2c7f7f274 100644 --- a/packages/effect/test/Schema/Schema/encodeOption.test.ts +++ b/packages/effect/test/Schema/Schema/encodeOption.test.ts @@ -1,25 +1,24 @@ -import { Option, Schema as S } from "effect" +import { Schema as S } from "effect" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertNone, assertSome } from "effect/test/util" +import { describe, it } from "vitest" describe("encodeOption", () => { it("should return none on async", () => { - expect(S.encodeOption(Util.AsyncString)("a")).toStrictEqual(Option.none()) + assertNone(S.encodeOption(Util.AsyncString)("a")) }) const schema = S.Struct({ a: Util.NumberFromChar }) it("should return None on invalid values", () => { - expect(S.encodeOption(schema)({ a: 1 })).toStrictEqual(Option.some({ a: "1" })) - expect(S.encodeOption(schema)({ a: 10 })).toStrictEqual(Option.none()) + assertSome(S.encodeOption(schema)({ a: 1 }), { a: "1" }) + assertNone(S.encodeOption(schema)({ a: 10 })) }) it("should respect outer/inner options", () => { const input = { a: 1, b: "b" } - expect(S.encodeOption(schema)(input, { onExcessProperty: "error" })).toStrictEqual(Option.none()) - expect(S.encodeOption(schema, { onExcessProperty: "error" })(input)).toStrictEqual(Option.none()) - expect(S.encodeOption(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" })).toStrictEqual( - Option.some({ a: "1" }) - ) + assertNone(S.encodeOption(schema)(input, { onExcessProperty: "error" })) + assertNone(S.encodeOption(schema, { onExcessProperty: "error" })(input)) + assertSome(S.encodeOption(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" }), { a: "1" }) }) }) diff --git a/packages/effect/test/Schema/Schema/encodePromise.test.ts b/packages/effect/test/Schema/Schema/encodePromise.test.ts index 7a5ed5081c9..7df84a8778f 100644 --- a/packages/effect/test/Schema/Schema/encodePromise.test.ts +++ b/packages/effect/test/Schema/Schema/encodePromise.test.ts @@ -1,12 +1,13 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("encodePromise", () => { const schema = S.Struct({ a: Util.NumberFromChar }) it("should return None on invalid values", async () => { - expect(await S.encodePromise(schema)({ a: 1 })).toStrictEqual({ a: "1" }) + deepStrictEqual(await S.encodePromise(schema)({ a: 1 }), { a: "1" }) await Util.assertions.promise.fail( S.encodePromise(schema)({ a: 10 }), @@ -23,8 +24,10 @@ describe("encodePromise", () => { it("should respect outer/inner options", async () => { const input = { a: 1, b: "b" } - expect(await S.encodePromise(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" })) - .toStrictEqual({ a: "1" }) + deepStrictEqual( + await S.encodePromise(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" }), + { a: "1" } + ) await Util.assertions.promise.fail( S.encodePromise(schema)(input, { onExcessProperty: "error" }), diff --git a/packages/effect/test/Schema/Schema/encodeSync.test.ts b/packages/effect/test/Schema/Schema/encodeSync.test.ts index 1c02089d822..97d6cd1f5f6 100644 --- a/packages/effect/test/Schema/Schema/encodeSync.test.ts +++ b/packages/effect/test/Schema/Schema/encodeSync.test.ts @@ -1,45 +1,49 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("encodeSync", () => { const schema = S.Struct({ a: Util.NumberFromChar }) it("should throw on invalid values", () => { - expect(S.encodeSync(schema)({ a: 1 })).toEqual({ a: "1" }) - expect(() => S.encodeSync(schema)({ a: 10 })).toThrow( - new Error(`{ readonly a: NumberFromChar } + deepStrictEqual(S.encodeSync(schema)({ a: 1 }), { a: "1" }) + Util.assertParseError( + () => S.encodeSync(schema)({ a: 10 }), + `{ readonly a: NumberFromChar } └─ ["a"] └─ NumberFromChar └─ Encoded side transformation failure └─ Char └─ Predicate refinement failure - └─ Expected a single character, actual "10"`) + └─ Expected a single character, actual "10"` ) }) it("should throw on async", () => { - expect(() => S.encodeSync(Util.AsyncString)("a")).toThrow( - new Error( - `AsyncString + Util.assertParseError( + () => S.encodeSync(Util.AsyncString)("a"), + `AsyncString └─ cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work` - ) ) }) it("should respect outer/inner options", () => { const input = { a: 1, b: "b" } - expect(() => S.encodeSync(schema)(input, { onExcessProperty: "error" })).toThrow( - new Error(`{ readonly a: NumberFromChar } + Util.assertParseError( + () => S.encodeSync(schema)(input, { onExcessProperty: "error" }), + `{ readonly a: NumberFromChar } └─ ["b"] - └─ is unexpected, expected: "a"`) + └─ is unexpected, expected: "a"` ) - expect(() => S.encodeSync(schema, { onExcessProperty: "error" })(input)).toThrow( - new Error(`{ readonly a: NumberFromChar } + Util.assertParseError( + () => S.encodeSync(schema, { onExcessProperty: "error" })(input), + `{ readonly a: NumberFromChar } └─ ["b"] - └─ is unexpected, expected: "a"`) + └─ is unexpected, expected: "a"` ) - expect(S.encodeSync(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" })) - .toEqual({ a: "1" }) + deepStrictEqual(S.encodeSync(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" }), { + a: "1" + }) }) }) diff --git a/packages/effect/test/Schema/Schema/encodeUnknownOption.test.ts b/packages/effect/test/Schema/Schema/encodeUnknownOption.test.ts index 83dae835682..03d33e87d56 100644 --- a/packages/effect/test/Schema/Schema/encodeUnknownOption.test.ts +++ b/packages/effect/test/Schema/Schema/encodeUnknownOption.test.ts @@ -1,9 +1,10 @@ -import { Option, Schema as S } from "effect" +import { Schema as S } from "effect" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertNone } from "effect/test/util" +import { describe, it } from "vitest" describe("encodeUnknownOption", () => { it("should return none on async", () => { - expect(S.encodeUnknownOption(Util.AsyncString)("a")).toStrictEqual(Option.none()) + assertNone(S.encodeUnknownOption(Util.AsyncString)("a")) }) }) diff --git a/packages/effect/test/Schema/Schema/encodeUnknownSync.test.ts b/packages/effect/test/Schema/Schema/encodeUnknownSync.test.ts index 95d39f3106d..60efad77c58 100644 --- a/packages/effect/test/Schema/Schema/encodeUnknownSync.test.ts +++ b/packages/effect/test/Schema/Schema/encodeUnknownSync.test.ts @@ -1,14 +1,13 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { describe, it } from "vitest" describe("encodeUnknownSync", () => { it("should throw on async", () => { - expect(() => S.encodeUnknownSync(Util.AsyncString)("a")).toThrow( - new Error( - `AsyncString + Util.assertParseError( + () => S.encodeUnknownSync(Util.AsyncString)("a"), + `AsyncString └─ cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work` - ) ) }) }) diff --git a/packages/effect/test/Schema/Schema/equivalence.test.ts b/packages/effect/test/Schema/Schema/equivalence.test.ts index 50f7c28a6a2..d1bf42d42db 100644 --- a/packages/effect/test/Schema/Schema/equivalence.test.ts +++ b/packages/effect/test/Schema/Schema/equivalence.test.ts @@ -8,8 +8,9 @@ import * as Hash from "effect/Hash" import * as Option from "effect/Option" import { isUnknown } from "effect/Predicate" import * as S from "effect/Schema" +import { assertFalse, assertTrue, strictEqual, throws } from "effect/test/util" import * as fc from "fast-check" -import { describe, expect, it } from "vitest" +import { describe, it } from "vitest" /** * Tests that the generated Eq is a valid Eq @@ -72,13 +73,15 @@ const MySymbol = S.SymbolFromSelf.annotations({ describe("equivalence", () => { it("the errors should display a path", () => { - expect(() => S.equivalence(S.Tuple(S.Never as any))).toThrow( + throws( + () => S.equivalence(S.Tuple(S.Never as any)), new Error(`Unsupported schema at path: [0] details: Cannot build an Equivalence schema (NeverKeyword): never`) ) - expect(() => S.equivalence(S.Struct({ a: S.Never as any }))).toThrow( + throws( + () => S.equivalence(S.Struct({ a: S.Never as any })), new Error(`Unsupported schema at path: ["a"] details: Cannot build an Equivalence @@ -90,22 +93,23 @@ schema (NeverKeyword): never`) const schema = S.NumberFromString const equivalence = S.equivalence(schema) - expect(equivalence(1, 1)).toBe(true) + assertTrue(equivalence(1, 1)) - expect(equivalence(1, 2)).toBe(false) + assertFalse(equivalence(1, 2)) }) it("S.equivalence(S.encodedSchema(schema))", () => { const schema = S.NumberFromString const equivalence = S.equivalence(S.encodedSchema(schema)) - expect(equivalence("a", "a")).toBe(true) + assertTrue(equivalence("a", "a")) - expect(equivalence("a", "b")).toBe(false) + assertFalse(equivalence("a", "b")) }) it("never", () => { - expect(() => S.equivalence(S.Never)).toThrow( + throws( + () => S.equivalence(S.Never), new Error(`Unsupported schema details: Cannot build an Equivalence schema (NeverKeyword): never`) @@ -116,9 +120,9 @@ schema (NeverKeyword): never`) const schema = MyString const equivalence = S.equivalence(schema) - expect(equivalence("a", "a")).toBe(true) + assertTrue(equivalence("a", "a")) - expect(equivalence("a", "b")).toBe(false) + assertFalse(equivalence("a", "b")) // propertyType(schema) }) @@ -127,9 +131,9 @@ schema (NeverKeyword): never`) const schema = S.NonEmptyString const equivalence = S.equivalence(schema) - expect(equivalence("a", "a")).toBe(true) + assertTrue(equivalence("a", "a")) - expect(equivalence("a", "b")).toBe(false) + assertFalse(equivalence("a", "b")) // propertyType(schema) }) @@ -138,7 +142,7 @@ schema (NeverKeyword): never`) it("should return Equal.equals when an annotation doesn't exist", () => { const schema = S.declare(isUnknown) const equivalence = S.equivalence(schema) - expect(equivalence).toStrictEqual(Equal.equals) + strictEqual(equivalence, Equal.equals) const make = (id: number, s: string) => { return { @@ -153,20 +157,20 @@ schema (NeverKeyword): never`) } } - expect(equivalence(make(1, "a"), make(1, "a"))).toBe(true) - expect(equivalence(make(1, "a"), make(1, "b"))).toBe(true) - expect(equivalence(make(1, "a"), make(2, "a"))).toBe(false) + assertTrue(equivalence(make(1, "a"), make(1, "a"))) + assertTrue(equivalence(make(1, "a"), make(1, "b"))) + assertFalse(equivalence(make(1, "a"), make(2, "a"))) }) it("Chunk", () => { const schema = S.ChunkFromSelf(MyNumber) const equivalence = S.equivalence(schema) - expect(equivalence(Chunk.empty(), Chunk.empty())).toBe(true) - expect(equivalence(Chunk.make(1, 2, 3), Chunk.make(1, 2, 3))).toBe(true) + assertTrue(equivalence(Chunk.empty(), Chunk.empty())) + assertTrue(equivalence(Chunk.make(1, 2, 3), Chunk.make(1, 2, 3))) - expect(equivalence(Chunk.make(1, 2, 3), Chunk.make(1, 2))).toBe(false) - expect(equivalence(Chunk.make(1, 2, 3), Chunk.make(1, 2, 4))).toBe(false) + assertFalse(equivalence(Chunk.make(1, 2, 3), Chunk.make(1, 2))) + assertFalse(equivalence(Chunk.make(1, 2, 3), Chunk.make(1, 2, 4))) // propertyType(schema) }) @@ -176,10 +180,10 @@ schema (NeverKeyword): never`) const equivalence = S.equivalence(schema) const now = new Date() - expect(equivalence(now, now)).toBe(true) - expect(equivalence(new Date(0), new Date(0))).toBe(true) + assertTrue(equivalence(now, now)) + assertTrue(equivalence(new Date(0), new Date(0))) - expect(equivalence(new Date(0), new Date(1))).toBe(false) + assertFalse(equivalence(new Date(0), new Date(1))) // propertyType(schema) }) @@ -188,7 +192,7 @@ schema (NeverKeyword): never`) const schema = S.DataFromSelf(S.Struct({ a: MyString, b: MyNumber })) const equivalence = S.equivalence(schema) - expect(equivalence(Data.struct({ a: "ok", b: 0 }), Data.struct({ a: "ok", b: 0 }))).toBe(true) + assertTrue(equivalence(Data.struct({ a: "ok", b: 0 }), Data.struct({ a: "ok", b: 0 }))) // propertyType(schema) }) @@ -197,11 +201,11 @@ schema (NeverKeyword): never`) const schema = S.EitherFromSelf({ left: MyString, right: MyNumber }) const equivalence = S.equivalence(schema) - expect(equivalence(Either.right(1), Either.right(1))).toBe(true) - expect(equivalence(Either.left("a"), Either.left("a"))).toBe(true) + assertTrue(equivalence(Either.right(1), Either.right(1))) + assertTrue(equivalence(Either.left("a"), Either.left("a"))) - expect(equivalence(Either.right(1), Either.right(2))).toBe(false) - expect(equivalence(Either.left("a"), Either.left("b"))).toBe(false) + assertFalse(equivalence(Either.right(1), Either.right(2))) + assertFalse(equivalence(Either.left("a"), Either.left("b"))) // propertyType(schema) }) @@ -210,10 +214,10 @@ schema (NeverKeyword): never`) const schema = S.OptionFromSelf(MyNumber) const equivalence = S.equivalence(schema) - expect(equivalence(Option.none(), Option.none())).toBe(true) - expect(equivalence(Option.some(1), Option.some(1))).toBe(true) + assertTrue(equivalence(Option.none(), Option.none())) + assertTrue(equivalence(Option.some(1), Option.some(1))) - expect(equivalence(Option.some(1), Option.some(2))).toBe(false) + assertFalse(equivalence(Option.some(1), Option.some(2))) // propertyType(schema) }) @@ -222,10 +226,10 @@ schema (NeverKeyword): never`) const schema = S.ReadonlySetFromSelf(MyNumber) const equivalence = S.equivalence(schema) - expect(equivalence(new Set(), new Set())).toBe(true) - expect(equivalence(new Set([1, 2, 3]), new Set([1, 2, 3]))).toBe(true) + assertTrue(equivalence(new Set(), new Set())) + assertTrue(equivalence(new Set([1, 2, 3]), new Set([1, 2, 3]))) - expect(equivalence(new Set([1, 2, 3]), new Set([1, 2]))).toBe(false) + assertFalse(equivalence(new Set([1, 2, 3]), new Set([1, 2]))) // propertyType(schema) }) @@ -234,11 +238,11 @@ schema (NeverKeyword): never`) const schema = S.ReadonlyMapFromSelf({ key: MyString, value: MyNumber }) const equivalence = S.equivalence(schema) - expect(equivalence(new Map(), new Map())).toBe(true) - expect(equivalence(new Map([["a", 1], ["b", 2]]), new Map([["a", 1], ["b", 2]]))).toBe(true) + assertTrue(equivalence(new Map(), new Map())) + assertTrue(equivalence(new Map([["a", 1], ["b", 2]]), new Map([["a", 1], ["b", 2]]))) - expect(equivalence(new Map([["a", 1], ["b", 2]]), new Map([["a", 3], ["b", 2]]))).toBe(false) - expect(equivalence(new Map([["a", 1], ["b", 2]]), new Map([["a", 1], ["b", 4]]))).toBe(false) + assertFalse(equivalence(new Map([["a", 1], ["b", 2]]), new Map([["a", 3], ["b", 2]]))) + assertFalse(equivalence(new Map([["a", 1], ["b", 2]]), new Map([["a", 1], ["b", 4]]))) // propertyType(schema) }) @@ -247,14 +251,14 @@ schema (NeverKeyword): never`) const schema = S.Uint8ArrayFromSelf const equivalence = S.equivalence(schema) - expect(equivalence(new Uint8Array(), new Uint8Array())).toBe(true) - expect( + assertTrue(equivalence(new Uint8Array(), new Uint8Array())) + assertTrue( equivalence(new Uint8Array([10, 20, 30, 40, 50]), new Uint8Array([10, 20, 30, 40, 50])) - ).toBe(true) + ) - expect( + assertFalse( equivalence(new Uint8Array([10, 20, 30, 40, 50]), new Uint8Array([10, 20, 30, 30, 50])) - ).toBe(false) + ) // propertyType(schema) }) @@ -265,11 +269,9 @@ schema (NeverKeyword): never`) }) const equivalence = S.equivalence(schema) - expect(equivalence(new URL("https://example.com/page"), new URL("https://example.com/page"))) - .toBe(true) + assertTrue(equivalence(new URL("https://example.com/page"), new URL("https://example.com/page"))) - expect(equivalence(new URL("https://example.com/page"), new URL("https://google.come"))) - .toBe(false) + assertFalse(equivalence(new URL("https://example.com/page"), new URL("https://google.come"))) }) }) @@ -278,11 +280,11 @@ schema (NeverKeyword): never`) const schema = S.Union(MyString, MyNumber) const equivalence = S.equivalence(schema) - expect(equivalence("a", "a")).toBe(true) - expect(equivalence(1, 1)).toBe(true) + assertTrue(equivalence("a", "a")) + assertTrue(equivalence(1, 1)) - expect(equivalence("a", "b")).toBe(false) - expect(equivalence(1, 2)).toBe(false) + assertFalse(equivalence("a", "b")) + assertFalse(equivalence(1, 2)) // propertyType(schema) }) @@ -293,10 +295,10 @@ schema (NeverKeyword): never`) const schema = S.Union(a, ab) const equivalence = S.equivalence(schema) - expect(equivalence({ a: "a", b: 1 }, { a: "a", b: 1 })).toBe(true) - expect(equivalence({ a: "a", b: 1 }, { a: "a", b: 2 })).toBe(true) + assertTrue(equivalence({ a: "a", b: 1 }, { a: "a", b: 1 })) + assertTrue(equivalence({ a: "a", b: 1 }, { a: "a", b: 2 })) - expect(equivalence({ a: "a", b: 1 }, { a: "c", b: 1 })).toBe(false) + assertFalse(equivalence({ a: "a", b: 1 }, { a: "c", b: 1 })) // propertyType(schema) }) @@ -308,12 +310,12 @@ schema (NeverKeyword): never`) ) const equivalence = S.equivalence(schema) - expect(equivalence({ tag: "a", a: "a" }, { tag: "a", a: "a" })).toBe(true) - expect(equivalence({ tag: "b", b: 1 }, { tag: "b", b: 1 })).toBe(true) + assertTrue(equivalence({ tag: "a", a: "a" }, { tag: "a", a: "a" })) + assertTrue(equivalence({ tag: "b", b: 1 }, { tag: "b", b: 1 })) - expect(equivalence({ tag: "a", a: "a" }, { tag: "a", a: "b" })).toBe(false) - expect(equivalence({ tag: "b", b: 1 }, { tag: "b", b: 2 })).toBe(false) - expect(equivalence({ tag: "a", a: "a" }, { tag: "b", b: 1 })).toBe(false) + assertFalse(equivalence({ tag: "a", a: "a" }, { tag: "a", a: "b" })) + assertFalse(equivalence({ tag: "b", b: 1 }, { tag: "b", b: 2 })) + assertFalse(equivalence({ tag: "a", a: "a" }, { tag: "b", b: 1 })) }) it("discriminated tuples", () => { @@ -323,13 +325,13 @@ schema (NeverKeyword): never`) ) const equivalence = S.equivalence(schema) - expect(equivalence(["a", "x"], ["a", "x"])).toBe(true) - expect(equivalence(["a", "x"], ["a", "y"])).toBe(false) + assertTrue(equivalence(["a", "x"], ["a", "x"])) + assertFalse(equivalence(["a", "x"], ["a", "y"])) - expect(equivalence(["b", 1], ["b", 1])).toBe(true) - expect(equivalence(["b", 1], ["b", 2])).toBe(false) + assertTrue(equivalence(["b", 1], ["b", 1])) + assertFalse(equivalence(["b", 1], ["b", 2])) - expect(equivalence(["a", "x"], ["b", 1])).toBe(false) + assertFalse(equivalence(["a", "x"], ["b", 1])) }) }) @@ -338,17 +340,17 @@ schema (NeverKeyword): never`) const schema = S.Tuple() const equivalence = S.equivalence(schema) - expect(equivalence([], [])).toBe(true) + assertTrue(equivalence([], [])) }) it("e", () => { const schema = S.Tuple(MyString, MyNumber) const equivalence = S.equivalence(schema) - expect(equivalence(["a", 1], ["a", 1])).toBe(true) + assertTrue(equivalence(["a", 1], ["a", 1])) - expect(equivalence(["a", 1], ["b", 1])).toBe(false) - expect(equivalence(["a", 1], ["a", 2])).toBe(false) + assertFalse(equivalence(["a", 1], ["b", 1])) + assertFalse(equivalence(["a", 1], ["a", 2])) // propertyType(schema) }) @@ -357,12 +359,12 @@ schema (NeverKeyword): never`) const schema = S.Tuple([S.String], S.Number) const equivalence = S.equivalence(schema) - expect(equivalence(["a"], ["a"])).toBe(true) - expect(equivalence(["a", 1], ["a", 1])).toBe(true) - expect(equivalence(["a", 1, 2], ["a", 1, 2])).toBe(true) + assertTrue(equivalence(["a"], ["a"])) + assertTrue(equivalence(["a", 1], ["a", 1])) + assertTrue(equivalence(["a", 1, 2], ["a", 1, 2])) - expect(equivalence(["a", 1], ["a", 2])).toBe(false) - expect(equivalence(["a", 1, 2], ["a", 1, 3])).toBe(false) + assertFalse(equivalence(["a", 1], ["a", 2])) + assertFalse(equivalence(["a", 1, 2], ["a", 1, 3])) // propertyType(schema) }) @@ -371,12 +373,12 @@ schema (NeverKeyword): never`) const schema = S.Array(MyNumber) const equivalence = S.equivalence(schema) - expect(equivalence([], [])).toBe(true) - expect(equivalence([1], [1])).toBe(true) - expect(equivalence([1, 2], [1, 2])).toBe(true) + assertTrue(equivalence([], [])) + assertTrue(equivalence([1], [1])) + assertTrue(equivalence([1, 2], [1, 2])) - expect(equivalence([1, 2], [1, 2, 3])).toBe(false) - expect(equivalence([1, 2, 3], [1, 2])).toBe(false) + assertFalse(equivalence([1, 2], [1, 2, 3])) + assertFalse(equivalence([1, 2, 3], [1, 2])) // propertyType(schema) }) @@ -385,13 +387,13 @@ schema (NeverKeyword): never`) const schema = S.Tuple([], MyString, MyNumber) const equivalence = S.equivalence(schema) - expect(equivalence([1], [1])).toBe(true) - expect(equivalence(["a", 1], ["a", 1])).toBe(true) - expect(equivalence(["a", "b", 1], ["a", "b", 1])).toBe(true) + assertTrue(equivalence([1], [1])) + assertTrue(equivalence(["a", 1], ["a", 1])) + assertTrue(equivalence(["a", "b", 1], ["a", "b", 1])) - expect(equivalence([1], [2])).toBe(false) - expect(equivalence([2], [1])).toBe(false) - expect(equivalence(["a", "b", 1], ["a", "c", 1])).toBe(false) + assertFalse(equivalence([1], [2])) + assertFalse(equivalence([2], [1])) + assertFalse(equivalence(["a", "b", 1], ["a", "c", 1])) // propertyType(schema) }) @@ -401,12 +403,12 @@ schema (NeverKeyword): never`) const schema = S.Tuple(S.optionalElement(MyString)) const equivalence = S.equivalence(schema) - expect(equivalence([], [])).toBe(true) - expect(equivalence(["a"], ["a"])).toBe(true) + assertTrue(equivalence([], [])) + assertTrue(equivalence(["a"], ["a"])) - expect(equivalence(["a"], ["b"])).toBe(false) - expect(equivalence([], ["a"])).toBe(false) - expect(equivalence(["a"], [])).toBe(false) + assertFalse(equivalence(["a"], ["b"])) + assertFalse(equivalence([], ["a"])) + assertFalse(equivalence(["a"], [])) // propertyType(schema) }) @@ -415,16 +417,16 @@ schema (NeverKeyword): never`) const schema = S.Tuple(S.optionalElement(MyString), S.optionalElement(MyNumber)) const equivalence = S.equivalence(schema) - expect(equivalence([], [])).toBe(true) - expect(equivalence(["a"], ["a"])).toBe(true) - expect(equivalence(["a"], ["a"])).toBe(true) - expect(equivalence(["a", 1], ["a", 1])).toBe(true) + assertTrue(equivalence([], [])) + assertTrue(equivalence(["a"], ["a"])) + assertTrue(equivalence(["a"], ["a"])) + assertTrue(equivalence(["a", 1], ["a", 1])) - expect(equivalence(["a"], ["b"])).toBe(false) - expect(equivalence(["a", 1], ["a", 2])).toBe(false) - expect(equivalence(["a", 1], ["a"])).toBe(false) - expect(equivalence([], ["a"])).toBe(false) - expect(equivalence(["a"], [])).toBe(false) + assertFalse(equivalence(["a"], ["b"])) + assertFalse(equivalence(["a", 1], ["a", 2])) + assertFalse(equivalence(["a", 1], ["a"])) + assertFalse(equivalence([], ["a"])) + assertFalse(equivalence(["a"], [])) // propertyType(schema) }) @@ -433,12 +435,12 @@ schema (NeverKeyword): never`) const schema = S.Tuple(MyString, S.optionalElement(MyNumber)) const equivalence = S.equivalence(schema) - expect(equivalence(["a"], ["a"])).toBe(true) - expect(equivalence(["a", 1], ["a", 1])).toBe(true) + assertTrue(equivalence(["a"], ["a"])) + assertTrue(equivalence(["a", 1], ["a", 1])) - expect(equivalence(["a", 1], ["a", 2])).toBe(false) - expect(equivalence(["a"], ["a", 1])).toBe(false) - expect(equivalence(["a", 1], ["a"])).toBe(false) + assertFalse(equivalence(["a", 1], ["a", 2])) + assertFalse(equivalence(["a"], ["a", 1])) + assertFalse(equivalence(["a", 1], ["a"])) // propertyType(schema) }) @@ -447,14 +449,14 @@ schema (NeverKeyword): never`) const schema = S.Tuple([S.optionalElement(S.String)], S.Number) const equivalence = S.equivalence(schema) - expect(equivalence([], [])).toBe(true) - expect(equivalence(["a"], ["a"])).toBe(true) - expect(equivalence(["a", 1], ["a", 1])).toBe(true) + assertTrue(equivalence([], [])) + assertTrue(equivalence(["a"], ["a"])) + assertTrue(equivalence(["a", 1], ["a", 1])) - expect(equivalence([], ["a"])).toBe(false) - expect(equivalence(["a"], [])).toBe(false) - expect(equivalence(["a"], ["b"])).toBe(false) - expect(equivalence(["a", 1], ["a", 2])).toBe(false) + assertFalse(equivalence([], ["a"])) + assertFalse(equivalence(["a"], [])) + assertFalse(equivalence(["a"], ["b"])) + assertFalse(equivalence(["a", 1], ["a", 2])) // propertyType(schema) }) @@ -466,14 +468,14 @@ schema (NeverKeyword): never`) const schema = S.Struct({}) const equivalence = S.equivalence(schema) - expect(equivalence({}, {})).toBe(false) + assertFalse(equivalence({}, {})) }) it("string keys", () => { const schema = S.Struct({ a: MyString, b: MyNumber }) const equivalence = S.equivalence(schema) - expect(equivalence({ a: "a", b: 1 }, { a: "a", b: 1 })).toBe(true) + assertTrue(equivalence({ a: "a", b: 1 }, { a: "a", b: 1 })) // should ignore excess properties const d = Symbol.for("effect/Schema/test/d") const excess = { @@ -482,10 +484,10 @@ schema (NeverKeyword): never`) c: true, [d]: "d" } - expect(equivalence({ a: "a", b: 1 }, excess)).toBe(true) + assertTrue(equivalence({ a: "a", b: 1 }, excess)) - expect(equivalence({ a: "a", b: 1 }, { a: "c", b: 1 })).toBe(false) - expect(equivalence({ a: "a", b: 1 }, { a: "a", b: 2 })).toBe(false) + assertFalse(equivalence({ a: "a", b: 1 }, { a: "c", b: 1 })) + assertFalse(equivalence({ a: "a", b: 1 }, { a: "a", b: 2 })) // propertyType(schema) }) @@ -496,7 +498,7 @@ schema (NeverKeyword): never`) const schema = S.Struct({ [a]: MyString, [b]: MyNumber }) const equivalence = S.equivalence(schema) - expect(equivalence({ [a]: "a", [b]: 1 }, { [a]: "a", [b]: 1 })).toBe(true) + assertTrue(equivalence({ [a]: "a", [b]: 1 }, { [a]: "a", [b]: 1 })) // should ignore excess properties const d = Symbol.for("effect/Schema/test/d") const excess = { @@ -505,10 +507,10 @@ schema (NeverKeyword): never`) c: true, [d]: "d" } - expect(equivalence({ [a]: "a", [b]: 1 }, excess)).toBe(true) + assertTrue(equivalence({ [a]: "a", [b]: 1 }, excess)) - expect(equivalence({ [a]: "a", [b]: 1 }, { [a]: "c", [b]: 1 })).toBe(false) - expect(equivalence({ [a]: "a", [b]: 1 }, { [a]: "a", [b]: 2 })).toBe(false) + assertFalse(equivalence({ [a]: "a", [b]: 1 }, { [a]: "c", [b]: 1 })) + assertFalse(equivalence({ [a]: "a", [b]: 1 }, { [a]: "a", [b]: 2 })) // propertyType(schema) }) @@ -520,18 +522,18 @@ schema (NeverKeyword): never`) }) const equivalence = S.equivalence(schema) - expect(equivalence({ a: "a", b: 1 }, { a: "a", b: 1 })).toBe(true) - expect(equivalence({ b: 1 }, { b: 1 })).toBe(true) - expect(equivalence({ a: "a" }, { a: "a" })).toBe(true) - expect(equivalence({ a: "a", b: undefined }, { a: "a", b: undefined })).toBe(true) + assertTrue(equivalence({ a: "a", b: 1 }, { a: "a", b: 1 })) + assertTrue(equivalence({ b: 1 }, { b: 1 })) + assertTrue(equivalence({ a: "a" }, { a: "a" })) + assertTrue(equivalence({ a: "a", b: undefined }, { a: "a", b: undefined })) - expect(equivalence({ a: "a" }, { b: 1 })).toBe(false) - expect(equivalence({ a: "a", b: 1 }, { a: "a" })).toBe(false) - expect(equivalence({ a: "a", b: undefined }, { a: "a" })).toBe(false) - expect(equivalence({ a: "a" }, { a: "a", b: 1 })).toBe(false) - expect(equivalence({ a: "a" }, { a: "a", b: undefined })).toBe(false) - expect(equivalence({ a: "a", b: 1 }, { a: "c", b: 1 })).toBe(false) - expect(equivalence({ a: "a", b: 1 }, { a: "a", b: 2 })).toBe(false) + assertFalse(equivalence({ a: "a" }, { b: 1 })) + assertFalse(equivalence({ a: "a", b: 1 }, { a: "a" })) + assertFalse(equivalence({ a: "a", b: undefined }, { a: "a" })) + assertFalse(equivalence({ a: "a" }, { a: "a", b: 1 })) + assertFalse(equivalence({ a: "a" }, { a: "a", b: undefined })) + assertFalse(equivalence({ a: "a", b: 1 }, { a: "c", b: 1 })) + assertFalse(equivalence({ a: "a", b: 1 }, { a: "a", b: 2 })) // propertyType(schema) }) @@ -543,25 +545,25 @@ schema (NeverKeyword): never`) const equivalence = S.equivalence(schema) const input = {} - expect(equivalence(input, input)).toBe(true) - expect(equivalence({}, {})).toBe(false) + assertTrue(equivalence(input, input)) + assertFalse(equivalence({}, {})) }) it("record(string, number)", () => { const schema = S.Record({ key: MyString, value: MyNumber }) const equivalence = S.equivalence(schema) - expect(equivalence({}, {})).toBe(true) - expect(equivalence({ a: 1 }, { a: 1 })).toBe(true) - expect(equivalence({ a: 1, b: 2 }, { a: 1, b: 2 })).toBe(true) + assertTrue(equivalence({}, {})) + assertTrue(equivalence({ a: 1 }, { a: 1 })) + assertTrue(equivalence({ a: 1, b: 2 }, { a: 1, b: 2 })) // should ignore symbol excess properties const d = Symbol.for("effect/Schema/test/d") - expect(equivalence({ a: 1, b: 2 }, { a: 1, b: 2, [d]: "d" })).toBe(true) + assertTrue(equivalence({ a: 1, b: 2 }, { a: 1, b: 2, [d]: "d" })) - expect(equivalence({ a: 1 }, { a: 2 })).toBe(false) - expect(equivalence({ a: 1, b: 2 }, { a: 1 })).toBe(false) - expect(equivalence({ a: 1 }, { a: 1, b: 2 })).toBe(false) - expect(equivalence({ a: 1 }, { b: 1 })).toBe(false) + assertFalse(equivalence({ a: 1 }, { a: 2 })) + assertFalse(equivalence({ a: 1, b: 2 }, { a: 1 })) + assertFalse(equivalence({ a: 1 }, { a: 1, b: 2 })) + assertFalse(equivalence({ a: 1 }, { b: 1 })) // propertyType(schema) }) @@ -572,17 +574,17 @@ schema (NeverKeyword): never`) const a = Symbol.for("effect/Schema/test/a") const b = Symbol.for("effect/Schema/test/b") - expect(equivalence({}, {})).toBe(true) - expect(equivalence({ [a]: 1 }, { [a]: 1 })).toBe(true) - expect(equivalence({ [a]: 1, [b]: 2 }, { [a]: 1, [b]: 2 })).toBe(true) + assertTrue(equivalence({}, {})) + assertTrue(equivalence({ [a]: 1 }, { [a]: 1 })) + assertTrue(equivalence({ [a]: 1, [b]: 2 }, { [a]: 1, [b]: 2 })) // should ignore string excess properties const excess = { [a]: 1, [b]: 2, c: "c" } - expect(equivalence({ [a]: 1, [b]: 2 }, excess)).toBe(true) + assertTrue(equivalence({ [a]: 1, [b]: 2 }, excess)) - expect(equivalence({ [a]: 1 }, { [a]: 2 })).toBe(false) - expect(equivalence({ [a]: 1, [b]: 2 }, { [a]: 1 })).toBe(false) - expect(equivalence({ [a]: 1 }, { [a]: 1, [b]: 2 })).toBe(false) - expect(equivalence({ [a]: 1 }, { [b]: 1 })).toBe(false) + assertFalse(equivalence({ [a]: 1 }, { [a]: 2 })) + assertFalse(equivalence({ [a]: 1, [b]: 2 }, { [a]: 1 })) + assertFalse(equivalence({ [a]: 1 }, { [a]: 1, [b]: 2 })) + assertFalse(equivalence({ [a]: 1 }, { [b]: 1 })) // propertyType(schema) }) @@ -591,12 +593,12 @@ schema (NeverKeyword): never`) const schema = S.Struct({ a: MyString, b: MyString }, S.Record({ key: MyString, value: MyString })) const equivalence = S.equivalence(schema) - expect(equivalence({ a: "a", b: "b" }, { a: "a", b: "b" })).toBe(true) - expect(equivalence({ a: "a", b: "b", c: "c" }, { a: "a", b: "b", c: "c" })).toBe(true) + assertTrue(equivalence({ a: "a", b: "b" }, { a: "a", b: "b" })) + assertTrue(equivalence({ a: "a", b: "b", c: "c" }, { a: "a", b: "b", c: "c" })) - expect(equivalence({ a: "a", b: "b" }, { a: "c", b: "b" })).toBe(false) - expect(equivalence({ a: "a", b: "b" }, { a: "a", b: "c" })).toBe(false) - expect(equivalence({ a: "a", b: "b", c: "c1" }, { a: "a", b: "b", c: "c2" })).toBe(false) + assertFalse(equivalence({ a: "a", b: "b" }, { a: "c", b: "b" })) + assertFalse(equivalence({ a: "a", b: "b" }, { a: "a", b: "c" })) + assertFalse(equivalence({ a: "a", b: "b", c: "c1" }, { a: "a", b: "b", c: "c2" })) // propertyType(schema) }) @@ -607,10 +609,10 @@ schema (NeverKeyword): never`) }) const equivalence = S.equivalence(schema) - expect(equivalence({ a: "a", b: "b" }, { a: "a", b: "b" })).toBe(true) - expect(equivalence({ a: "a", b: "b" }, { a: "a", b: "c" })).toBe(true) + assertTrue(equivalence({ a: "a", b: "b" }, { a: "a", b: "b" })) + assertTrue(equivalence({ a: "a", b: "b" }, { a: "a", b: "c" })) - expect(equivalence({ a: "a", b: "b" }, { a: "c", b: "b" })).toBe(false) + assertFalse(equivalence({ a: "a", b: "b" }, { a: "c", b: "b" })) // propertyType(schema) }) @@ -630,15 +632,15 @@ schema (NeverKeyword): never`) const equivalence = S.equivalence(schema) const a1: A = { a: "a1", as: [] } - expect(equivalence(a1, a1)).toBe(true) + assertTrue(equivalence(a1, a1)) const a2: A = { a: "a1", as: [{ a: "a2", as: [] }] } - expect(equivalence(a2, a2)).toBe(true) + assertTrue(equivalence(a2, a2)) const a3: A = { a: "a1", as: [{ a: "a2", as: [] }, { a: "a3", as: [{ a: "a4", as: [] }] }] } - expect(equivalence(a3, a3)).toBe(true) + assertTrue(equivalence(a3, a3)) const a4: A = { a: "a1", as: [{ a: "a2", as: [] }, { a: "a3", as: [{ a: "a4", as: [] }] }] } const a5: A = { a: "a1", as: [{ a: "a2", as: [] }, { a: "a3", as: [{ a: "a5", as: [] }] }] } - expect(equivalence(a4, a5)).toBe(false) + assertFalse(equivalence(a4, a5)) // propertyType(schema, { numRuns: 5 }) }) @@ -693,7 +695,7 @@ schema (NeverKeyword): never`) } } } - expect(equivalence(a1, a1)).toBe(true) + assertTrue(equivalence(a1, a1)) const a2: Operation = { type: "operation", @@ -718,7 +720,7 @@ schema (NeverKeyword): never`) } } } - expect(equivalence(a1, a2)).toBe(false) + assertFalse(equivalence(a1, a2)) // propertyType(Operation, { numRuns: 5 }) }) @@ -728,7 +730,7 @@ schema (NeverKeyword): never`) const expectHook = (source: S.Schema) => { const schema = source.annotations({ equivalence: () => () => true }) const eq = S.equivalence(schema) - expect(eq("a" as any, "b" as any)).toEqual(true) + assertTrue(eq("a" as any, "b" as any)) } it("void", () => { diff --git a/packages/effect/test/Schema/Schema/exports.test.ts b/packages/effect/test/Schema/Schema/exports.test.ts deleted file mode 100644 index c982f96eda4..00000000000 --- a/packages/effect/test/Schema/Schema/exports.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -import * as S from "effect/Schema" -import { expect, it } from "vitest" - -it("exports", () => { - expect(S.decodeUnknown).exist - expect(S.decodeUnknownSync).exist - expect(S.decodeUnknownOption).exist - expect(S.decodeUnknownEither).exist - - expect(S.decode).exist - expect(S.decodeSync).exist - expect(S.decodeOption).exist - expect(S.decodeEither).exist - - expect(S.encode).exist - expect(S.encodeSync).exist - expect(S.encodeOption).exist - expect(S.encodeEither).exist - - expect(S.validate).exist - expect(S.validateSync).exist - expect(S.validateOption).exist - expect(S.validateEither).exist - - expect(S.GreaterThanBigIntSchemaId).exist - expect(S.GreaterThanOrEqualToBigIntSchemaId).exist - expect(S.LessThanBigIntSchemaId).exist - expect(S.LessThanOrEqualToBigIntSchemaId).exist - expect(S.BetweenBigIntSchemaId).exist - expect(S.BrandSchemaId).exist - expect(S.FiniteSchemaId).exist - expect(S.GreaterThanSchemaId).exist - expect(S.GreaterThanOrEqualToSchemaId).exist - expect(S.MultipleOfSchemaId).exist - expect(S.IntSchemaId).exist - expect(S.LessThanSchemaId).exist - expect(S.LessThanOrEqualToSchemaId).exist - expect(S.BetweenSchemaId).exist - expect(S.NonNaNSchemaId).exist - expect(S.InstanceOfSchemaId).exist - expect(S.MinItemsSchemaId).exist - expect(S.MaxItemsSchemaId).exist - expect(S.ItemsCountSchemaId).exist - expect(S.TrimmedSchemaId).exist - expect(S.PatternSchemaId).exist - expect(S.StartsWithSchemaId).exist - expect(S.EndsWithSchemaId).exist - expect(S.IncludesSchemaId).exist - expect(S.UUIDSchemaId).exist - expect(S.ULIDSchemaId).exist -}) diff --git a/packages/effect/test/Schema/Schema/extend.test.ts b/packages/effect/test/Schema/Schema/extend.test.ts index 3f4121403be..dcf868acb38 100644 --- a/packages/effect/test/Schema/Schema/extend.test.ts +++ b/packages/effect/test/Schema/Schema/extend.test.ts @@ -3,31 +3,32 @@ import * as FastCheck from "effect/FastCheck" import * as Schema from "effect/Schema" import * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertTrue, deepStrictEqual, strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" describe("extend", () => { describe("String", () => { it("String and String", () => { const schema = Schema.extend(Schema.String, Schema.String) - expect(schema.ast).toStrictEqual(Schema.String.ast) + deepStrictEqual(schema.ast, Schema.String.ast) }) it("String and Literal", () => { const literal = Schema.Literal("a") const schema = Schema.extend(Schema.String, literal) - expect(schema.ast).toStrictEqual(literal.ast) + deepStrictEqual(schema.ast, literal.ast) }) it("Literal and String", () => { const literal = Schema.Literal("a") const schema = Schema.extend(literal, Schema.String) - expect(schema.ast).toStrictEqual(literal.ast) + deepStrictEqual(schema.ast, literal.ast) }) it("(String and annotations) and String", () => { const A = Schema.String.annotations({ identifier: "A" }) const schema = Schema.extend(A, Schema.String) - expect(schema.ast === A.ast).toBe(true) + assertTrue(schema.ast === A.ast) }) it("String and Refinement", () => { @@ -35,45 +36,45 @@ describe("extend", () => { Schema.String, Schema.String.pipe(Schema.startsWith("start:")) ) - expect(schema.ast._tag).toBe("Refinement") - expect((schema.ast as AST.Refinement).from === AST.stringKeyword).toBe(true) + strictEqual(schema.ast._tag, "Refinement") + assertTrue((schema.ast as AST.Refinement).from === AST.stringKeyword) }) it("should support two refined brands", () => { const startsWith = Schema.String.pipe(Schema.startsWith("start:"), Schema.brand("start:")) const endsWith = Schema.String.pipe(Schema.endsWith(":end"), Schema.brand(":end")) const schema = Schema.extend(startsWith, endsWith) - expect(String(schema.ast)).toBe(`startsWith("start:") & Brand<"start:"> & endsWith(":end") & Brand<":end">`) - expect(schema.ast.annotations[AST.BrandAnnotationId]).toStrictEqual([":end"]) + strictEqual(String(schema.ast), `startsWith("start:") & Brand<"start:"> & endsWith(":end") & Brand<":end">`) + deepStrictEqual(schema.ast.annotations[AST.BrandAnnotationId], [":end"]) const from = (schema.ast as AST.Refinement).from - expect(from.annotations[AST.BrandAnnotationId]).toStrictEqual(["start:"]) + deepStrictEqual(from.annotations[AST.BrandAnnotationId], ["start:"]) const fromfrom = (from as AST.Refinement).from - expect(fromfrom === AST.stringKeyword).toBe(true) + assertTrue(fromfrom === AST.stringKeyword) }) }) describe("Number", () => { it("Number and Number", () => { const schema = Schema.extend(Schema.Number, Schema.Number) - expect(schema.ast).toStrictEqual(Schema.Number.ast) + deepStrictEqual(schema.ast, Schema.Number.ast) }) it("Number and Literal", () => { const literal = Schema.Literal(1) const schema = Schema.extend(Schema.Number, literal) - expect(schema.ast).toStrictEqual(literal.ast) + deepStrictEqual(schema.ast, literal.ast) }) it("Literal and Number", () => { const literal = Schema.Literal(1) const schema = Schema.extend(literal, Schema.Number) - expect(schema.ast).toStrictEqual(literal.ast) + deepStrictEqual(schema.ast, literal.ast) }) it("(Number and annotations) and Number", () => { const A = Schema.Number.annotations({ identifier: "A" }) const schema = Schema.extend(A, Schema.Number) - expect(schema.ast === A.ast).toBe(true) + assertTrue(schema.ast === A.ast) }) it("Number and Refinement", () => { @@ -81,46 +82,46 @@ describe("extend", () => { Schema.Number, Schema.Number.pipe(Schema.greaterThan(0)) ) - expect(schema.ast._tag).toBe("Refinement") - expect((schema.ast as AST.Refinement).from === AST.numberKeyword).toBe(true) + strictEqual(schema.ast._tag, "Refinement") + assertTrue((schema.ast as AST.Refinement).from === AST.numberKeyword) }) it("should support two refined brands", () => { const gt0 = Schema.Number.pipe(Schema.greaterThan(0), Schema.brand("> 0")) const lt2 = Schema.Number.pipe(Schema.lessThan(2), Schema.brand("< 2")) const schema = Schema.extend(gt0, lt2) - expect(String(schema.ast)).toBe(`greaterThan(0) & Brand<"> 0"> & lessThan(2) & Brand<"< 2">`) - expect(schema.ast.annotations[AST.BrandAnnotationId]).toStrictEqual(["< 2"]) + strictEqual(String(schema.ast), `greaterThan(0) & Brand<"> 0"> & lessThan(2) & Brand<"< 2">`) + deepStrictEqual(schema.ast.annotations[AST.BrandAnnotationId], ["< 2"]) const from = (schema.ast as AST.Refinement).from - expect(from.annotations[AST.BrandAnnotationId]).toStrictEqual(["> 0"]) + deepStrictEqual(from.annotations[AST.BrandAnnotationId], ["> 0"]) const fromfrom = (from as AST.Refinement).from - expect(fromfrom === AST.numberKeyword).toBe(true) + assertTrue(fromfrom === AST.numberKeyword) }) }) describe("Boolean", () => { it("Boolean and Boolean", () => { const schema = Schema.extend(Schema.Boolean, Schema.Boolean) - expect(schema.ast).toStrictEqual(Schema.Boolean.ast) + deepStrictEqual(schema.ast, Schema.Boolean.ast) }) it("Boolean and Literal", () => { const literal = Schema.Literal(true) const schema = Schema.extend(Schema.Boolean, literal) - expect(schema.ast).toStrictEqual(literal.ast) + deepStrictEqual(schema.ast, literal.ast) }) it("Literal and Boolean", () => { const literal = Schema.Literal(true) const schema = Schema.extend(literal, Schema.Boolean) - expect(schema.ast).toStrictEqual(literal.ast) + deepStrictEqual(schema.ast, literal.ast) }) }) describe("Struct", () => { it("extend struct", async () => { const schema = Schema.extend(Schema.Struct({ a: Schema.String }), Schema.Struct({ b: Schema.Number })) - expect(String(schema)).toBe("{ readonly a: string; readonly b: number }") + strictEqual(String(schema), "{ readonly a: string; readonly b: number }") }) it("extend TypeLiteralTransformation", async () => { @@ -129,7 +130,8 @@ describe("extend", () => { Schema.Struct({ b: Schema.String, c: Schema.optionalWith(Schema.String, { exact: true, default: () => "" }) }) ) ) - expect(String(schema)).toBe( + strictEqual( + String(schema), "({ readonly a: number; readonly b: string; readonly c?: string } <-> { readonly a: number; readonly b: string; readonly c: string })" ) }) @@ -141,14 +143,14 @@ describe("extend", () => { Schema.Struct({ a: Schema.Literal("b") }) )) ) - expect(String(schema)).toBe(`{ readonly b: boolean; readonly a: "a" } | { readonly b: boolean; readonly a: "b" }`) + strictEqual(String(schema), `{ readonly b: boolean; readonly a: "a" } | { readonly b: boolean; readonly a: "b" }`) }) it("extend Record(string, string)", async () => { const schema = Schema.Struct({ a: Schema.String }).pipe( Schema.extend(Schema.Record({ key: Schema.String, value: Schema.String })) ) - expect(String(schema)).toBe(`{ readonly a: string; readonly [x: string]: string }`) + strictEqual(String(schema), `{ readonly a: string; readonly [x: string]: string }`) }) it("extend Record(templateLiteral, string)", async () => { @@ -169,28 +171,28 @@ describe("extend", () => { // readonly a: string // } // const a: A = { a: "a" } // OK - expect(String(schema)).toBe("{ readonly a: string; readonly [x: `${string}-${number}`]: string }") + strictEqual(String(schema), "{ readonly a: string; readonly [x: `${string}-${number}`]: string }") }) it("extend Record(string, NumberFromChar)", async () => { const schema = Schema.Struct({ a: Schema.Number }).pipe( Schema.extend(Schema.Record({ key: Schema.String, value: Util.NumberFromChar })) ) - expect(String(schema)).toBe(`{ readonly a: number; readonly [x: string]: NumberFromChar }`) + strictEqual(String(schema), `{ readonly a: number; readonly [x: string]: NumberFromChar }`) }) it("extend Record(symbol, NumberFromChar)", async () => { const schema = Schema.Struct({ a: Schema.Number }).pipe( Schema.extend(Schema.Record({ key: Schema.SymbolFromSelf, value: Util.NumberFromChar })) ) - expect(String(schema)).toBe(`{ readonly a: number; readonly [x: symbol]: NumberFromChar }`) + strictEqual(String(schema), `{ readonly a: number; readonly [x: symbol]: NumberFromChar }`) }) it("nested extend nested Struct", async () => { const A = Schema.Struct({ a: Schema.Struct({ b: Schema.String }) }) const B = Schema.Struct({ a: Schema.Struct({ c: Schema.Number }) }) const schema = Schema.extend(A, B) - expect(String(schema)).toBe(`{ readonly a: { readonly b: string; readonly c: number } }`) + strictEqual(String(schema), `{ readonly a: { readonly b: string; readonly c: number } }`) }) it("nested with refinements extend nested struct with refinements", async () => { @@ -207,7 +209,8 @@ describe("extend", () => { }) }) const schema = Schema.extend(A, B) - expect(String(schema)).toBe( + strictEqual( + String(schema), `{ readonly nested: { readonly same: startsWith("start:") & endsWith(":end"); readonly different1: string; readonly different2: string } }` ) await Util.assertions.decoding.succeed( @@ -265,7 +268,8 @@ describe("extend", () => { a: Schema.optionalWith(Schema.String, { exact: true, default: () => "" }), b: Schema.String }).pipe(Schema.extend(Schema.Struct({ c: Schema.Number }))) - expect(String(schema)).toBe( + strictEqual( + String(schema), "({ readonly a?: string; readonly b: string; readonly c: number } <-> { readonly a: string; readonly b: string; readonly c: number })" ) }) @@ -280,7 +284,8 @@ describe("extend", () => { Schema.Struct({ c: Schema.String }) ) ) - expect(String(schema)).toBe( + strictEqual( + String(schema), "({ readonly a?: string | undefined; readonly b: string } <-> { readonly a: string; readonly b: string }) | ({ readonly a?: string | undefined; readonly c: string } <-> { readonly a: string; readonly c: string })" ) }) @@ -292,7 +297,8 @@ describe("extend", () => { }), Schema.Struct({ b: Schema.String }).pipe(Schema.filter(() => true)) ) - expect(String(schema)).toBe( + strictEqual( + String(schema), "{ ({ readonly a?: string | undefined; readonly b: string } <-> { readonly a: string; readonly b: string }) | filter }" ) }) @@ -305,7 +311,8 @@ describe("extend", () => { }), suspend ) - expect(String((schema.ast as AST.Suspend).f())).toBe( + strictEqual( + String((schema.ast as AST.Suspend).f()), "({ readonly a?: string | undefined; readonly b: string } <-> { readonly a: string; readonly b: string })" ) }) @@ -322,7 +329,8 @@ describe("extend", () => { }) ) ) - expect(String(schema)).toBe( + strictEqual( + String(schema), "({ readonly a?: string; readonly b: string; readonly c?: number; readonly d: boolean } <-> { readonly a: string; readonly b: string; readonly c: number; readonly d: boolean })" ) }) @@ -334,7 +342,7 @@ describe("extend", () => { Schema.Struct({ a: Schema.Literal("a") }), Schema.Struct({ b: Schema.Literal("b") }) ).pipe(Schema.extend(Schema.Struct({ c: Schema.Boolean }))) - expect(String(schema)).toBe(`{ readonly a: "a"; readonly c: boolean } | { readonly b: "b"; readonly c: boolean }`) + strictEqual(String(schema), `{ readonly a: "a"; readonly c: boolean } | { readonly b: "b"; readonly c: boolean }`) }) it("with defaults extend Union with defaults", async () => { @@ -361,7 +369,8 @@ describe("extend", () => { ) ) ) - expect(String(schema)).toBe( + strictEqual( + String(schema), "({ readonly a?: string; readonly b: string; readonly e?: string; readonly f: string } <-> { readonly a: string; readonly b: string; readonly e: string; readonly f: string }) | ({ readonly a?: string; readonly b: string; readonly g?: string; readonly h: string } <-> { readonly a: string; readonly b: string; readonly g: string; readonly h: string }) | ({ readonly c?: string; readonly d: string; readonly e?: string; readonly f: string } <-> { readonly c: string; readonly d: string; readonly e: string; readonly f: string }) | ({ readonly c?: string; readonly d: string; readonly g?: string; readonly h: string } <-> { readonly c: string; readonly d: string; readonly g: string; readonly h: string })" ) }) @@ -378,7 +387,8 @@ describe("extend", () => { ) ) ) - expect(String(schema)).toBe( + strictEqual( + String(schema), `{ readonly a: "a"; readonly c: boolean } | { readonly a: "a"; readonly d: number } | { readonly a: "b"; readonly c: boolean } | { readonly a: "b"; readonly d: number }` ) }) @@ -393,7 +403,8 @@ describe("extend", () => { ).pipe( Schema.extend(Schema.Struct({ c: Schema.Boolean })) ) - expect(String(schema)).toBe( + strictEqual( + String(schema), `{ readonly a: "a"; readonly c: boolean } | { readonly a: "b"; readonly c: boolean } | { readonly b: "b"; readonly c: boolean }` ) }) @@ -406,7 +417,7 @@ describe("extend", () => { Schema.filter((input) => input.b > 0, { message: () => "R filter" }) ) const schema = Schema.extend(S, R) - expect(String(schema)).toBe(`{ { readonly a: string; readonly b: number } | filter }`) + strictEqual(String(schema), `{ { readonly a: string; readonly b: number } | filter }`) await Util.assertions.decoding.fail( schema, { a: "a", b: -1 }, @@ -421,7 +432,7 @@ describe("extend", () => { Schema.filter((input) => input.b < 10, { message: () => "filter2" }) ) const schema = Schema.extend(S, RR) - expect(String(schema)).toBe(`{ { { readonly a: string; readonly b: number } | filter } | filter }`) + strictEqual(String(schema), `{ { { readonly a: string; readonly b: number } | filter } | filter }`) await Util.assertions.decoding.fail( schema, { a: "a", b: -1 }, @@ -442,7 +453,7 @@ describe("extend", () => { Schema.filter((input) => input.b > 0, { message: () => "R2 filter" }) ) const schema = Schema.extend(R1, R2) - expect(String(schema)).toBe(`{ { { readonly a: string; readonly b: number } | filter } | filter }`) + strictEqual(String(schema), `{ { { readonly a: string; readonly b: number } | filter } | filter }`) await Util.assertions.decoding.fail( schema, { a: "", b: 1 }, @@ -462,7 +473,8 @@ describe("extend", () => { Schema.filter((input) => input.c === true, { message: () => "R filter" }) ) const schema = Schema.extend(Schema.Union(S1, S2), R) - expect(String(schema)).toBe( + strictEqual( + String(schema), `{ { readonly a: string; readonly c: boolean } | filter } | { { readonly b: number; readonly c: boolean } | filter }` ) await Util.assertions.decoding.fail( @@ -500,7 +512,8 @@ describe("extend", () => { Schema.filter((input) => input.c === true, { message: () => "R3 filter" }) ) const schema = Schema.extend(Schema.Union(R1, R2), R3) - expect(String(schema)).toBe( + strictEqual( + String(schema), `{ { { readonly a: string; readonly c: boolean } | filter } | filter } | { { { readonly b: number; readonly c: boolean } | filter } | filter }` ) await Util.assertions.decoding.fail( @@ -578,7 +591,8 @@ describe("extend", () => { ) }) ) - expect(String(List)).toStrictEqual( + strictEqual( + String(List), `{ readonly type: "nil" } | { readonly type: "cons"; readonly tail: }` ) await Util.assertions.decoding.succeed(List, { type: "nil" }) @@ -599,46 +613,46 @@ describe("extend", () => { }) it("errors", () => { - expect(() => Schema.String.pipe(Schema.extend(Schema.Number))).toThrow( + throws( + () => Schema.String.pipe(Schema.extend(Schema.Number)), new Error(`Unsupported schema or overlapping types details: cannot extend string with number`) ) - expect(() => - Schema.Record({ key: Schema.String, value: Schema.Number }).pipe( - Schema.extend(Schema.Record({ key: Schema.String, value: Schema.Boolean })) - ) - ).toThrow( + throws( + () => + Schema.Record({ key: Schema.String, value: Schema.Number }).pipe( + Schema.extend(Schema.Record({ key: Schema.String, value: Schema.Boolean })) + ), new Error(`Duplicate index signature details: string index signature`) ) - expect(() => - Schema.Record({ key: Schema.SymbolFromSelf, value: Schema.Number }).pipe( - Schema.extend(Schema.Record({ key: Schema.SymbolFromSelf, value: Schema.Boolean })) - ) - ).toThrow( + throws( + () => + Schema.Record({ key: Schema.SymbolFromSelf, value: Schema.Number }).pipe( + Schema.extend(Schema.Record({ key: Schema.SymbolFromSelf, value: Schema.Boolean })) + ), new Error(`Duplicate index signature details: symbol index signature`) ) - expect(() => - Schema.Record({ key: Schema.String, value: Schema.Number }).pipe( - Schema.extend(Schema.Record({ key: Schema.String.pipe(Schema.minLength(2)), value: Schema.Boolean })) - ) - ).toThrow( + throws( + () => + Schema.Record({ key: Schema.String, value: Schema.Number }).pipe( + Schema.extend(Schema.Record({ key: Schema.String.pipe(Schema.minLength(2)), value: Schema.Boolean })) + ), new Error(`Duplicate index signature details: string index signature`) ) - expect(() => - Schema.extend( - Schema.Struct({ a: Schema.Struct({ b: Schema.String }) }), - Schema.Struct({ a: Schema.Struct({ b: Schema.Number }) }) - ) - ) - .toThrow( - new Error( - `Unsupported schema or overlapping types + throws( + () => + Schema.extend( + Schema.Struct({ a: Schema.Struct({ b: Schema.String }) }), + Schema.Struct({ a: Schema.Struct({ b: Schema.Number }) }) + ), + new Error( + `Unsupported schema or overlapping types at path: ["a"]["b"] details: cannot extend string with number` - ) ) + ) }) }) diff --git a/packages/effect/test/Schema/Schema/filter.test.ts b/packages/effect/test/Schema/Schema/filter.test.ts index 1ed3ab0fb15..6195a1f139b 100644 --- a/packages/effect/test/Schema/Schema/filter.test.ts +++ b/packages/effect/test/Schema/Schema/filter.test.ts @@ -2,7 +2,8 @@ import * as ParseResult from "effect/ParseResult" import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("filter", () => { describe("error messages", () => { @@ -79,7 +80,7 @@ describe("filter", () => { title: "title" }) ) - expect(schema.ast.annotations).toEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.SchemaIdAnnotationId]: Symbol.for("Char"), [AST.DescriptionAnnotationId]: "description", [AST.DocumentationAnnotationId]: "documentation", @@ -109,8 +110,8 @@ describe("filter", () => { it("the constructor validation can be disabled", () => { const schema = S.NonEmptyString - expect(schema.make("", true)).toStrictEqual("") - expect(schema.make("", { disableValidation: true })).toStrictEqual("") + strictEqual(schema.make("", true), "") + strictEqual(schema.make("", { disableValidation: true }), "") }) describe("ParseIssue overloading", () => { diff --git a/packages/effect/test/Schema/Schema/filterEffect.test.ts b/packages/effect/test/Schema/Schema/filterEffect.test.ts index 986bbbd15ed..b42b31fd6dc 100644 --- a/packages/effect/test/Schema/Schema/filterEffect.test.ts +++ b/packages/effect/test/Schema/Schema/filterEffect.test.ts @@ -2,13 +2,14 @@ import * as Effect from "effect/Effect" import * as ParseResult from "effect/ParseResult" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("filterEffect", () => { it("shoudl expose the original schema as `from`", async () => { const schema = S.filterEffect(S.String, () => Effect.succeed(true)) - expect(schema.from).toBe(S.String) - expect(schema.to.ast).toBe(S.String.ast) + strictEqual(schema.from, S.String) + strictEqual(schema.to.ast, S.String.ast) }) describe("ParseIssue overloading", () => { diff --git a/packages/effect/test/Schema/Schema/fromBrand.test.ts b/packages/effect/test/Schema/Schema/fromBrand.test.ts index 9708f3937cb..4cc03909ef6 100644 --- a/packages/effect/test/Schema/Schema/fromBrand.test.ts +++ b/packages/effect/test/Schema/Schema/fromBrand.test.ts @@ -1,7 +1,7 @@ import * as Brand from "effect/Brand" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { describe, it } from "vitest" type Int = number & Brand.Brand<"Int"> const Int = Brand.refined( @@ -49,10 +49,11 @@ describe("fromBrand", () => { └─ Predicate refinement failure └─ Expected -0.5 to be positive, Expected -0.5 to be an integer` ) - expect(() => S.decodeUnknownSync(schema)(-0.5)).toThrow( - new Error(`{ number | filter } + Util.assertParseError( + () => S.decodeUnknownSync(schema)(-0.5), + `{ number | filter } └─ Predicate refinement failure - └─ Expected -0.5 to be positive, Expected -0.5 to be an integer`) + └─ Expected -0.5 to be positive, Expected -0.5 to be an integer` ) await Util.assertions.decoding.fail( schema, diff --git a/packages/effect/test/Schema/Schema/instanceOf.test.ts b/packages/effect/test/Schema/Schema/instanceOf.test.ts index 40f1351ca39..28d8e258732 100644 --- a/packages/effect/test/Schema/Schema/instanceOf.test.ts +++ b/packages/effect/test/Schema/Schema/instanceOf.test.ts @@ -3,21 +3,22 @@ import * as Pretty from "effect/Pretty" import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("instanceOf", () => { it("is", () => { const schema = S.instanceOf(Set) const is = P.is(schema) - expect(is(new Set())).toEqual(true) - expect(is(1)).toEqual(false) - expect(is({})).toEqual(false) + assertTrue(is(new Set())) + assertFalse(is(1)) + assertFalse(is({})) }) it("annotations", () => { const schema = S.instanceOf(Set, { description: "my description" }) - expect(schema.ast.annotations[AST.DescriptionAnnotationId]).toEqual("my description") - expect(schema.ast.annotations[S.InstanceOfSchemaId]).toEqual({ constructor: Set }) + strictEqual(schema.ast.annotations[AST.DescriptionAnnotationId], "my description") + deepStrictEqual(schema.ast.annotations[S.InstanceOfSchemaId], { constructor: Set }) }) it("decoding", async () => { @@ -39,7 +40,7 @@ describe("instanceOf", () => { it("default", () => { const schema = S.instanceOf(Set) const pretty = Pretty.make(schema) - expect(pretty(new Set())).toEqual("[object Set]") + strictEqual(pretty(new Set()), "[object Set]") }) it("override", () => { @@ -47,7 +48,7 @@ describe("instanceOf", () => { pretty: () => (set) => `new Set(${JSON.stringify(Array.from(set.values()))})` }) const pretty = Pretty.make(schema) - expect(pretty(new Set([1, 2, 3]))).toEqual("new Set([1,2,3])") + strictEqual(pretty(new Set([1, 2, 3])), "new Set([1,2,3])") }) }) }) diff --git a/packages/effect/test/Schema/Schema/is.test.ts b/packages/effect/test/Schema/Schema/is.test.ts index 372d543338c..bd76b8f3d48 100644 --- a/packages/effect/test/Schema/Schema/is.test.ts +++ b/packages/effect/test/Schema/Schema/is.test.ts @@ -1,85 +1,86 @@ import * as P from "effect/ParseResult" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue } from "effect/test/util" +import { describe, it } from "vitest" describe("is", () => { it("never", () => { const is = P.is(S.Never) - expect(is(1)).toEqual(false) + assertFalse(is(1)) }) it("string", () => { const is = P.is(S.String) - expect(is("a")).toEqual(true) - expect(is(1)).toEqual(false) + assertTrue(is("a")) + assertFalse(is(1)) }) it("number", () => { const is = P.is(S.Number) - expect(is(1)).toEqual(true) - expect(is(NaN)).toEqual(true) - expect(is(Infinity)).toEqual(true) - expect(is(-Infinity)).toEqual(true) - expect(is("a")).toEqual(false) + assertTrue(is(1)) + assertTrue(is(NaN)) + assertTrue(is(Infinity)) + assertTrue(is(-Infinity)) + assertFalse(is("a")) }) it("boolean", () => { const is = P.is(S.Boolean) - expect(is(true)).toEqual(true) - expect(is(false)).toEqual(true) - expect(is(1)).toEqual(false) + assertTrue(is(true)) + assertTrue(is(false)) + assertFalse(is(1)) }) it("bigint", () => { const is = P.is(S.BigIntFromSelf) - expect(is(0n)).toEqual(true) - expect(is(1n)).toEqual(true) - expect(is(BigInt("1"))).toEqual(true) - expect(is(null)).toEqual(false) - expect(is(1.2)).toEqual(false) + assertTrue(is(0n)) + assertTrue(is(1n)) + assertTrue(is(BigInt("1"))) + assertFalse(is(null)) + assertFalse(is(1.2)) }) it("symbol", () => { const a = Symbol.for("effect/Schema/test/a") const is = P.is(S.SymbolFromSelf) - expect(is(a)).toEqual(true) - expect(is("effect/Schema/test/a")).toEqual(false) + assertTrue(is(a)) + assertFalse(is("effect/Schema/test/a")) }) it("object", () => { const is = P.is(S.Object) - expect(is({})).toEqual(true) - expect(is([])).toEqual(true) - expect(is(null)).toEqual(false) - expect(is("a")).toEqual(false) - expect(is(1)).toEqual(false) - expect(is(true)).toEqual(false) + assertTrue(is({})) + assertTrue(is([])) + assertFalse(is(null)) + assertFalse(is("a")) + assertFalse(is(1)) + assertFalse(is(true)) }) it("literal 1 member", () => { const schema = S.Literal(1) const is = P.is(schema) - expect(is(1)).toEqual(true) - expect(is("a")).toEqual(false) - expect(is(null)).toEqual(false) + assertTrue(is(1)) + assertFalse(is("a")) + assertFalse(is(null)) }) it("literal 2 members", () => { const schema = S.Literal(1, "a") const is = P.is(schema) - expect(is(1)).toEqual(true) - expect(is("a")).toEqual(true) - expect(is(null)).toEqual(false) + assertTrue(is(1)) + assertTrue(is("a")) + assertFalse(is(null)) }) it("uniqueSymbolFromSelf", () => { const a = Symbol.for("effect/Schema/test/a") const schema = S.UniqueSymbolFromSelf(a) const is = P.is(schema) - expect(is(a)).toEqual(true) - expect(is(Symbol.for("effect/Schema/test/a"))).toEqual(true) - expect(is("Symbol(effect/Schema/test/a)")).toEqual(false) + assertTrue(is(a)) + assertTrue(is(Symbol.for("effect/Schema/test/a"))) + assertFalse(is("Symbol(effect/Schema/test/a)")) }) it("Numeric enums", () => { @@ -89,11 +90,11 @@ describe("is", () => { } const schema = S.Enums(Fruits) const is = P.is(schema) - expect(is(Fruits.Apple)).toEqual(true) - expect(is(Fruits.Banana)).toEqual(true) - expect(is(0)).toEqual(true) - expect(is(1)).toEqual(true) - expect(is(3)).toEqual(false) + assertTrue(is(Fruits.Apple)) + assertTrue(is(Fruits.Banana)) + assertTrue(is(0)) + assertTrue(is(1)) + assertFalse(is(3)) }) it("String enums", () => { @@ -104,12 +105,12 @@ describe("is", () => { } const schema = S.Enums(Fruits) const is = P.is(schema) - expect(is(Fruits.Apple)).toEqual(true) - expect(is(Fruits.Cantaloupe)).toEqual(true) - expect(is("apple")).toEqual(true) - expect(is("banana")).toEqual(true) - expect(is(0)).toEqual(true) - expect(is("Cantaloupe")).toEqual(false) + assertTrue(is(Fruits.Apple)) + assertTrue(is(Fruits.Cantaloupe)) + assertTrue(is("apple")) + assertTrue(is("banana")) + assertTrue(is(0)) + assertFalse(is("Cantaloupe")) }) it("Const enums", () => { @@ -120,197 +121,197 @@ describe("is", () => { } as const const schema = S.Enums(Fruits) const is = P.is(schema) - expect(is("apple")).toEqual(true) - expect(is("banana")).toEqual(true) - expect(is(3)).toEqual(true) - expect(is("Cantaloupe")).toEqual(false) + assertTrue(is("apple")) + assertTrue(is("banana")) + assertTrue(is(3)) + assertFalse(is("Cantaloupe")) }) it("tuple. empty", () => { const schema = S.Tuple() const is = P.is(schema) - expect(is([])).toEqual(true) + assertTrue(is([])) - expect(is(null)).toEqual(false) - expect(is([undefined])).toEqual(false) - expect(is([1])).toEqual(false) - expect(is({})).toEqual(false) + assertFalse(is(null)) + assertFalse(is([undefined])) + assertFalse(is([1])) + assertFalse(is({})) }) it("tuple. required element", () => { const schema = S.Tuple(S.Number) const is = P.is(schema) - expect(is([1])).toEqual(true) + assertTrue(is([1])) - expect(is(null)).toEqual(false) - expect(is([])).toEqual(false) - expect(is([undefined])).toEqual(false) - expect(is(["a"])).toEqual(false) - expect(is([1, "b"])).toEqual(false) + assertFalse(is(null)) + assertFalse(is([])) + assertFalse(is([undefined])) + assertFalse(is(["a"])) + assertFalse(is([1, "b"])) }) it("tuple. required element with undefined", () => { const schema = S.Tuple(S.Union(S.Number, S.Undefined)) const is = P.is(schema) - expect(is([1])).toEqual(true) - expect(is([undefined])).toEqual(true) + assertTrue(is([1])) + assertTrue(is([undefined])) - expect(is(null)).toEqual(false) - expect(is([])).toEqual(false) - expect(is(["a"])).toEqual(false) - expect(is([1, "b"])).toEqual(false) + assertFalse(is(null)) + assertFalse(is([])) + assertFalse(is(["a"])) + assertFalse(is([1, "b"])) }) it("tuple. optional element", () => { const schema = S.Tuple(S.optionalElement(S.Number)) const is = P.is(schema) - expect(is([])).toEqual(true) - expect(is([1])).toEqual(true) + assertTrue(is([])) + assertTrue(is([1])) - expect(is(null)).toEqual(false) - expect(is(["a"])).toEqual(false) - expect(is([undefined])).toEqual(false) - expect(is([1, "b"])).toEqual(false) + assertFalse(is(null)) + assertFalse(is(["a"])) + assertFalse(is([undefined])) + assertFalse(is([1, "b"])) }) it("tuple. optional element with undefined", () => { const schema = S.Tuple(S.optionalElement(S.Union(S.Number, S.Undefined))) const is = P.is(schema) - expect(is([])).toEqual(true) - expect(is([1])).toEqual(true) - expect(is([undefined])).toEqual(true) + assertTrue(is([])) + assertTrue(is([1])) + assertTrue(is([undefined])) - expect(is(null)).toEqual(false) - expect(is(["a"])).toEqual(false) - expect(is([1, "b"])).toEqual(false) + assertFalse(is(null)) + assertFalse(is(["a"])) + assertFalse(is([1, "b"])) }) it("tuple. e + e?", () => { const schema = S.Tuple(S.String, S.optionalElement(S.Number)) const is = P.is(schema) - expect(is(["a"])).toEqual(true) - expect(is(["a", 1])).toEqual(true) + assertTrue(is(["a"])) + assertTrue(is(["a", 1])) - expect(is([1])).toEqual(false) - expect(is(["a", "b"])).toEqual(false) + assertFalse(is([1])) + assertFalse(is(["a", "b"])) }) it("tuple. e + r", () => { const schema = S.Tuple([S.String], S.Number) const is = P.is(schema) - expect(is(["a"])).toEqual(true) - expect(is(["a", 1])).toEqual(true) - expect(is(["a", 1, 2])).toEqual(true) + assertTrue(is(["a"])) + assertTrue(is(["a", 1])) + assertTrue(is(["a", 1, 2])) - expect(is([])).toEqual(false) + assertFalse(is([])) }) it("tuple. e? + r", () => { const schema = S.Tuple([S.optionalElement(S.String)], S.Number) const is = P.is(schema) - expect(is([])).toEqual(true) - expect(is(["a"])).toEqual(true) - expect(is(["a", 1])).toEqual(true) - expect(is(["a", 1, 2])).toEqual(true) + assertTrue(is([])) + assertTrue(is(["a"])) + assertTrue(is(["a", 1])) + assertTrue(is(["a", 1, 2])) - expect(is([1])).toEqual(false) + assertFalse(is([1])) }) it("tuple. r", () => { const schema = S.Array(S.Number) const is = P.is(schema) - expect(is([])).toEqual(true) - expect(is([1])).toEqual(true) - expect(is([1, 2])).toEqual(true) + assertTrue(is([])) + assertTrue(is([1])) + assertTrue(is([1, 2])) - expect(is(["a"])).toEqual(false) - expect(is([1, "a"])).toEqual(false) + assertFalse(is(["a"])) + assertFalse(is([1, "a"])) }) it("tuple. r + e", () => { const schema = S.Tuple([], S.String, S.Number) const is = P.is(schema) - expect(is([1])).toEqual(true) - expect(is(["a", 1])).toEqual(true) - expect(is(["a", "b", 1])).toEqual(true) + assertTrue(is([1])) + assertTrue(is(["a", 1])) + assertTrue(is(["a", "b", 1])) - expect(is([])).toEqual(false) - expect(is(["a"])).toEqual(false) - expect(is([1, 2])).toEqual(false) + assertFalse(is([])) + assertFalse(is(["a"])) + assertFalse(is([1, 2])) }) it("tuple. e + r + e", () => { const schema = S.Tuple([S.String], S.Number, S.Boolean) const is = P.is(schema) - expect(is(["a", true])).toEqual(true) - expect(is(["a", 1, true])).toEqual(true) - expect(is(["a", 1, 2, true])).toEqual(true) + assertTrue(is(["a", true])) + assertTrue(is(["a", 1, true])) + assertTrue(is(["a", 1, 2, true])) - expect(is([])).toEqual(false) - expect(is(["a"])).toEqual(false) - expect(is([true])).toEqual(false) - expect(is(["a", 1])).toEqual(false) - expect(is([1, true])).toEqual(false) + assertFalse(is([])) + assertFalse(is(["a"])) + assertFalse(is([true])) + assertFalse(is(["a", 1])) + assertFalse(is([1, true])) }) it("struct. empty", () => { const schema = S.Struct({}) const is = P.is(schema) - expect(is({})).toEqual(true) - expect(is({ a: 1 })).toEqual(true) - expect(is([])).toEqual(true) + assertTrue(is({})) + assertTrue(is({ a: 1 })) + assertTrue(is([])) - expect(is(null)).toEqual(false) - expect(is(undefined)).toEqual(false) + assertFalse(is(null)) + assertFalse(is(undefined)) }) describe("struct", () => { it("required property signature", () => { const schema = S.Struct({ a: S.Number }) const is = P.is(schema) - expect(is({ a: 1 })).toEqual(true) - expect(is({ a: 1, b: "b" })).toEqual(true) + assertTrue(is({ a: 1 })) + assertTrue(is({ a: 1, b: "b" })) - expect(is(null)).toEqual(false) - expect(is({})).toEqual(false) - expect(is({ a: undefined })).toEqual(false) - expect(is({ a: "a" })).toEqual(false) + assertFalse(is(null)) + assertFalse(is({})) + assertFalse(is({ a: undefined })) + assertFalse(is({ a: "a" })) }) it("required property signature with undefined", () => { const schema = S.Struct({ a: S.Union(S.Number, S.Undefined) }) const is = P.is(schema) - expect(is({ a: 1 })).toEqual(true) - expect(is({ a: undefined })).toEqual(true) - expect(is({ a: 1, b: "b" })).toEqual(true) + assertTrue(is({ a: 1 })) + assertTrue(is({ a: undefined })) + assertTrue(is({ a: 1, b: "b" })) - expect(is({})).toEqual(false) - expect(is(null)).toEqual(false) - expect(is({ a: "a" })).toEqual(false) + assertFalse(is({})) + assertFalse(is(null)) + assertFalse(is({ a: "a" })) }) it("exact optional property signature", () => { const schema = S.Struct({ a: S.optionalWith(S.Number, { exact: true }) }) const is = P.is(schema) - expect(is({})).toEqual(true) - expect(is({ a: 1 })).toEqual(true) - expect(is({ a: 1, b: "b" })).toEqual(true) + assertTrue(is({})) + assertTrue(is({ a: 1 })) + assertTrue(is({ a: 1, b: "b" })) - expect(is(null)).toEqual(false) - expect(is({ a: "a" })).toEqual(false) - expect(is({ a: undefined })).toEqual(false) + assertFalse(is(null)) + assertFalse(is({ a: "a" })) + assertFalse(is({ a: undefined })) }) it("exact optional property signature with undefined", () => { const schema = S.Struct({ a: S.optionalWith(S.Union(S.Number, S.Undefined), { exact: true }) }) const is = P.is(schema) - expect(is({})).toEqual(true) - expect(is({ a: 1 })).toEqual(true) - expect(is({ a: undefined })).toEqual(true) - expect(is({ a: 1, b: "b" })).toEqual(true) + assertTrue(is({})) + assertTrue(is({ a: 1 })) + assertTrue(is({ a: undefined })) + assertTrue(is({ a: 1, b: "b" })) - expect(is(null)).toEqual(false) - expect(is({ a: "a" })).toEqual(false) + assertFalse(is(null)) + assertFalse(is({ a: "a" })) }) }) @@ -318,14 +319,14 @@ describe("is", () => { const a = Symbol.for("effect/Schema/test/a") const schema = S.Record({ key: S.String, value: S.String }) const is = P.is(schema) - expect(is(null)).toEqual(false) - expect(is({})).toEqual(true) - expect(is({ a: "a" })).toEqual(true) - expect(is({ a: 1 })).toEqual(false) - expect(is({ [a]: 1 })).toEqual(true) - expect(is({ a: "a", b: "b" })).toEqual(true) - expect(is({ a: "a", b: 1 })).toEqual(false) - expect(is({ [a]: 1, b: "b" })).toEqual(true) + assertFalse(is(null)) + assertTrue(is({})) + assertTrue(is({ a: "a" })) + assertFalse(is({ a: 1 })) + assertTrue(is({ [a]: 1 })) + assertTrue(is({ a: "a", b: "b" })) + assertFalse(is({ a: "a", b: 1 })) + assertTrue(is({ [a]: 1, b: "b" })) }) it("record(symbol, string)", () => { @@ -333,42 +334,42 @@ describe("is", () => { const b = Symbol.for("effect/Schema/test/b") const schema = S.Record({ key: S.SymbolFromSelf, value: S.String }) const is = P.is(schema) - expect(is(null)).toEqual(false) - expect(is({})).toEqual(true) - expect(is({ [a]: "a" })).toEqual(true) - expect(is({ [a]: 1 })).toEqual(false) - expect(is({ a: 1 })).toEqual(true) - expect(is({ [a]: "a", [b]: "b" })).toEqual(true) - expect(is({ [a]: "a", [b]: 1 })).toEqual(false) - expect(is({ a: 1, [b]: "b" })).toEqual(true) + assertFalse(is(null)) + assertTrue(is({})) + assertTrue(is({ [a]: "a" })) + assertFalse(is({ [a]: 1 })) + assertTrue(is({ a: 1 })) + assertTrue(is({ [a]: "a", [b]: "b" })) + assertFalse(is({ [a]: "a", [b]: 1 })) + assertTrue(is({ a: 1, [b]: "b" })) }) it("record(never, number)", () => { const schema = S.Record({ key: S.Never, value: S.Number }) const is = P.is(schema) - expect(is({})).toEqual(true) - expect(is({ a: 1 })).toEqual(true) + assertTrue(is({})) + assertTrue(is({ a: 1 })) }) it("record('a' | 'b', number)", () => { const schema = S.Record({ key: S.Union(S.Literal("a"), S.Literal("b")), value: S.Number }) const is = P.is(schema) - expect(is({ a: 1, b: 2 })).toEqual(true) + assertTrue(is({ a: 1, b: 2 })) - expect(is({})).toEqual(false) - expect(is({ a: 1 })).toEqual(false) - expect(is({ b: 2 })).toEqual(false) + assertFalse(is({})) + assertFalse(is({ a: 1 })) + assertFalse(is({ b: 2 })) }) it("record(keyof struct({ a, b }), number)", () => { const schema = S.Record({ key: S.keyof(S.Struct({ a: S.String, b: S.String })), value: S.Number }) const is = P.is(schema) - expect(is({ a: 1, b: 2 })).toEqual(true) + assertTrue(is({ a: 1, b: 2 })) - expect(is({})).toEqual(false) - expect(is({ a: 1 })).toEqual(false) - expect(is({ b: 2 })).toEqual(false) - expect(is({ a: "a" })).toEqual(false) + assertFalse(is({})) + assertFalse(is({ a: 1 })) + assertFalse(is({ b: 2 })) + assertFalse(is({ a: "a" })) }) it("record(Symbol('a') | Symbol('b'), number)", () => { @@ -376,41 +377,41 @@ describe("is", () => { const b = Symbol.for("effect/Schema/test/b") const schema = S.Record({ key: S.Union(S.UniqueSymbolFromSelf(a), S.UniqueSymbolFromSelf(b)), value: S.Number }) const is = P.is(schema) - expect(is({ [a]: 1, [b]: 2 })).toEqual(true) + assertTrue(is({ [a]: 1, [b]: 2 })) - expect(is({})).toEqual(false) - expect(is({ a: 1 })).toEqual(false) - expect(is({ b: 2 })).toEqual(false) + assertFalse(is({})) + assertFalse(is({ a: 1 })) + assertFalse(is({ b: 2 })) }) it("record(${string}-${string}, number)", () => { const schema = S.Record({ key: S.TemplateLiteral(S.String, S.Literal("-"), S.String), value: S.Number }) const is = P.is(schema) - expect(is({})).toEqual(true) - expect(is({ "-": 1 })).toEqual(true) - expect(is({ "a-": 1 })).toEqual(true) - expect(is({ "-b": 1 })).toEqual(true) - expect(is({ "a-b": 1 })).toEqual(true) - expect(is({ "": 1 })).toEqual(true) - expect(is({ "a": 1 })).toEqual(true) - expect(is({ "a": "a" })).toEqual(true) + assertTrue(is({})) + assertTrue(is({ "-": 1 })) + assertTrue(is({ "a-": 1 })) + assertTrue(is({ "-b": 1 })) + assertTrue(is({ "a-b": 1 })) + assertTrue(is({ "": 1 })) + assertTrue(is({ "a": 1 })) + assertTrue(is({ "a": "a" })) - expect(is({ "-": "a" })).toEqual(false) - expect(is({ "a-": "a" })).toEqual(false) - expect(is({ "-b": "b" })).toEqual(false) - expect(is({ "a-b": "ab" })).toEqual(false) + assertFalse(is({ "-": "a" })) + assertFalse(is({ "a-": "a" })) + assertFalse(is({ "-b": "b" })) + assertFalse(is({ "a-b": "ab" })) }) it("record(minLength(2), number)", () => { const schema = S.Record({ key: S.String.pipe(S.minLength(2)), value: S.Number }) const is = P.is(schema) - expect(is({})).toEqual(true) - expect(is({ "a": 1 })).toEqual(true) - expect(is({ "a": "a" })).toEqual(true) - expect(is({ "aa": 1 })).toEqual(true) - expect(is({ "aaa": 1 })).toEqual(true) + assertTrue(is({})) + assertTrue(is({ "a": 1 })) + assertTrue(is({ "a": "a" })) + assertTrue(is({ "aa": 1 })) + assertTrue(is({ "aaa": 1 })) - expect(is({ "aa": "aa" })).toEqual(false) + assertFalse(is({ "aa": "aa" })) }) it("record(${string}-${string}, number) & record(string, string | number)", () => { @@ -420,20 +421,20 @@ describe("is", () => { S.Record({ key: S.String, value: S.Union(S.String, S.Number) }) ) const is = P.is(schema) - expect(is({})).toEqual(true) - expect(is({ "a": "a" })).toEqual(true) - expect(is({ "a-": 1 })).toEqual(true) + assertTrue(is({})) + assertTrue(is({ "a": "a" })) + assertTrue(is({ "a-": 1 })) - expect(is({ "a-": "a" })).toEqual(false) - expect(is({ "a": true })).toEqual(false) + assertFalse(is({ "a-": "a" })) + assertFalse(is({ "a": true })) }) it("union", () => { const schema = S.Union(S.String, S.Number) const is = P.is(schema) - expect(is(null)).toEqual(false) - expect(is(1)).toEqual(true) - expect(is("a")).toEqual(true) + assertFalse(is(null)) + assertTrue(is(1)) + assertTrue(is("a")) }) describe("suspend", () => { @@ -447,8 +448,8 @@ describe("is", () => { categories: S.Array(S.suspend((): S.Schema => schema)) }) const is = P.is(schema) - expect(is({ name: "a", categories: [] })).toEqual(true) - expect( + assertTrue(is({ name: "a", categories: [] })) + assertTrue( is({ name: "a", categories: [{ @@ -456,8 +457,8 @@ describe("is", () => { categories: [{ name: "c", categories: [] }] }] }) - ).toEqual(true) - expect(is({ name: "a", categories: [1] })).toEqual(false) + ) + assertFalse(is({ name: "a", categories: [1] })) }) it("mutually suspended", () => { @@ -478,34 +479,34 @@ describe("is", () => { as: S.Array(S.suspend(() => schemaA)) }) const isA = P.is(schemaA) - expect(isA({ a: "a1", bs: [] })).toEqual(true) - expect(isA({ a: "a1", bs: [{ b: 1, as: [] }] })).toEqual(true) - expect( + assertTrue(isA({ a: "a1", bs: [] })) + assertTrue(isA({ a: "a1", bs: [{ b: 1, as: [] }] })) + assertTrue( isA({ a: "a1", bs: [{ b: 1, as: [{ a: "a2", bs: [] }] }] }) - ).toEqual(true) - expect( + ) + assertFalse( isA({ a: "a1", bs: [{ b: 1, as: [{ a: "a2", bs: [null] }] }] }) - ).toEqual(false) + ) }) }) it("union", () => { const schema = S.Union(S.String, S.Number) const is = P.is(schema) - expect(is(null)).toEqual(false) - expect(is(1)).toEqual(true) - expect(is("a")).toEqual(true) + assertFalse(is(null)) + assertTrue(is(1)) + assertTrue(is("a")) }) describe("rest", () => { it("baseline", () => { const schema = S.Tuple([S.String, S.Number], S.Boolean) const is = P.is(schema) - expect(is(["a", 1])).toEqual(true) - expect(is(["a", 1, true])).toEqual(true) - expect(is(["a", 1, true, false])).toEqual(true) - expect(is(["a", 1, true, "a"])).toEqual(false) - expect(is(["a", 1, true, "a", true])).toEqual(false) + assertTrue(is(["a", 1])) + assertTrue(is(["a", 1, true])) + assertTrue(is(["a", 1, true, false])) + assertFalse(is(["a", 1, true, "a"])) + assertFalse(is(["a", 1, true, "a", true])) }) }) @@ -515,40 +516,39 @@ describe("is", () => { S.extend(S.Struct({ b: S.Number })) ) const is = P.is(schema) - expect(is({ a: "a", b: 1 })).toEqual(true) + assertTrue(is({ a: "a", b: 1 })) - expect(is({})).toEqual(false) - expect(is({ a: "a" })).toEqual(false) + assertFalse(is({})) + assertFalse(is({ a: "a" })) }) it("record(string, string)", () => { const schema = S.Struct({ a: S.String }, S.Record({ key: S.String, value: S.String })) const is = P.is(schema) - expect(is({ a: "a" })).toEqual(true) - expect(is({ a: "a", b: "b" })).toEqual(true) + assertTrue(is({ a: "a" })) + assertTrue(is({ a: "a", b: "b" })) - expect(is({})).toEqual(false) - expect(is({ b: "b" })).toEqual(false) - expect(is({ a: 1 })).toEqual(false) - expect(is({ a: "a", b: 2 })).toEqual(false) + assertFalse(is({})) + assertFalse(is({ b: "b" })) + assertFalse(is({ a: 1 })) + assertFalse(is({ a: "a", b: 2 })) }) }) it("nonEmptyString", () => { const schema = S.String.pipe(S.nonEmptyString()) const is = P.is(schema) - expect(is("a")).toEqual(true) - expect(is("aa")).toEqual(true) + assertTrue(is("a")) + assertTrue(is("aa")) - expect(is("")).toEqual(false) + assertFalse(is("")) }) it("should respect outer/inner options", () => { const schema = S.Struct({ a: Util.NumberFromChar }) const input = { a: 1, b: "b" } - expect(S.is(schema)(input, { onExcessProperty: "error" })).toEqual(false) - expect(S.is(schema, { onExcessProperty: "error" })(input)).toEqual(false) - expect(S.is(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" })) - .toEqual(true) + assertFalse(S.is(schema)(input, { onExcessProperty: "error" })) + assertFalse(S.is(schema, { onExcessProperty: "error" })(input)) + assertTrue(S.is(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" })) }) }) diff --git a/packages/effect/test/Schema/Schema/isSchema.test.ts b/packages/effect/test/Schema/Schema/isSchema.test.ts index 0ed96dcb707..e989bcb17b3 100644 --- a/packages/effect/test/Schema/Schema/isSchema.test.ts +++ b/packages/effect/test/Schema/Schema/isSchema.test.ts @@ -1,19 +1,20 @@ import * as S from "effect/Schema" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue } from "effect/test/util" +import { describe, it } from "vitest" describe("isSchema", () => { it("Schema", () => { - expect(S.isSchema(S.String)).toBe(true) - expect(S.isSchema(S.parseJson)).toBe(false) + assertTrue(S.isSchema(S.String)) + assertFalse(S.isSchema(S.parseJson)) }) it("BrandSchema", () => { - expect(S.isSchema(S.String.pipe(S.brand("my-brand")))).toBe(true) + assertTrue(S.isSchema(S.String.pipe(S.brand("my-brand")))) }) it("PropertySignature", () => { - expect(S.isSchema(S.propertySignature(S.String))).toBe(false) - expect(S.isSchema(S.optionalWith(S.String, { exact: true }))).toBe(false) - expect(S.isSchema(S.optionalWith(S.String, { default: () => "" }))).toBe(false) + assertFalse(S.isSchema(S.propertySignature(S.String))) + assertFalse(S.isSchema(S.optionalWith(S.String, { exact: true }))) + assertFalse(S.isSchema(S.optionalWith(S.String, { default: () => "" }))) }) }) diff --git a/packages/effect/test/Schema/Schema/keyof.test.ts b/packages/effect/test/Schema/Schema/keyof.test.ts index 5b23669547a..d6e1abb9a52 100644 --- a/packages/effect/test/Schema/Schema/keyof.test.ts +++ b/packages/effect/test/Schema/Schema/keyof.test.ts @@ -1,20 +1,21 @@ import * as P from "effect/ParseResult" import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, deepStrictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" describe("keyof", () => { it("should unify string literals with string", () => { const schema = S.Struct({ a: S.String }, S.Record({ key: S.String, value: S.String })) const keyof = S.keyof(schema) - expect(keyof.ast).toEqual(S.String.ast) + deepStrictEqual(keyof.ast, S.String.ast) }) it("should unify symbol literals with symbol", () => { const a = Symbol.for("effect/Schema/test/a") const schema = S.Struct({ [a]: S.String }, S.Record({ key: S.SymbolFromSelf, value: S.String })) const keyof = S.keyof(schema) - expect(keyof.ast).toEqual(S.SymbolFromSelf.ast) + deepStrictEqual(keyof.ast, S.SymbolFromSelf.ast) }) describe("struct", () => { @@ -26,9 +27,9 @@ describe("keyof", () => { // type K = keyof S.Schema.Type // "a" | "b" const keyOf = S.keyof(schema) const is = P.is(keyOf) - expect(is("a")).toEqual(true) - expect(is("b")).toEqual(true) - expect(is("c")).toEqual(false) + assertTrue(is("a")) + assertTrue(is("b")) + assertFalse(is("c")) }) it("symbol keys", () => { @@ -40,10 +41,10 @@ describe("keyof", () => { }) const keyOf = S.keyof(schema) const is = P.is(keyOf) - expect(is(a)).toEqual(true) - expect(is(b)).toEqual(true) - expect(is("a")).toEqual(false) - expect(is("b")).toEqual(false) + assertTrue(is(a)) + assertTrue(is(b)) + assertFalse(is("a")) + assertFalse(is("b")) }) }) @@ -51,19 +52,19 @@ describe("keyof", () => { it("string", () => { const schema = S.Record({ key: S.String, value: S.Number }) // type K = keyof S.Schema.Type // string - expect(AST.keyof(schema.ast)).toEqual(S.String.ast) + deepStrictEqual(AST.keyof(schema.ast), S.String.ast) }) it("symbol", () => { const schema = S.Record({ key: S.SymbolFromSelf, value: S.Number }) // type K = keyof S.Schema.Type // symbol - expect(AST.keyof(schema.ast)).toEqual(S.SymbolFromSelf.ast) + deepStrictEqual(AST.keyof(schema.ast), S.SymbolFromSelf.ast) }) it("template literal", () => { const schema = S.Record({ key: S.TemplateLiteral(S.Literal("a"), S.String), value: S.Number }) // type K = keyof S.Schema.Type // `a${string}` - expect(AST.keyof(schema.ast)).toEqual(S.TemplateLiteral(S.Literal("a"), S.String).ast) + deepStrictEqual(AST.keyof(schema.ast), S.TemplateLiteral(S.Literal("a"), S.String).ast) }) }) @@ -79,14 +80,14 @@ describe("keyof", () => { categories: S.Array(schema) }) ) - expect(AST.keyof(schema.ast)).toEqual(S.Literal("name", "categories").ast) + deepStrictEqual(AST.keyof(schema.ast), S.Literal("name", "categories").ast) }) describe("union", () => { it("union of structs", () => { const schema = S.Union(S.Struct({ a: S.String }), S.Struct({ a: S.Number })) // type K = keyof S.Schema.Type // "a" - expect(AST.keyof(schema.ast)).toEqual(S.Literal("a").ast) + deepStrictEqual(AST.keyof(schema.ast), S.Literal("a").ast) }) it("union of records", () => { @@ -95,7 +96,7 @@ describe("keyof", () => { S.Record({ key: S.String, value: S.Boolean }) ) // type K = keyof S.Schema.Type // string - expect(AST.keyof(schema.ast)).toEqual(S.String.ast) + deepStrictEqual(AST.keyof(schema.ast), S.String.ast) }) it("union of structs and records", () => { @@ -104,18 +105,19 @@ describe("keyof", () => { S.Struct({ a: S.Number }, S.Record({ key: S.String, value: S.Boolean })) ) // type K = keyof S.Schema.Type // string - expect(AST.keyof(schema.ast)).toEqual(S.String.ast) + deepStrictEqual(AST.keyof(schema.ast), S.String.ast) }) }) it("should support Class", () => { class A extends S.Class("A")({ a: S.String }) {} // type K = keyof S.Schema.Type // "a" - expect(AST.keyof(A.ast)).toEqual(S.Literal("a").ast) + deepStrictEqual(AST.keyof(A.ast), S.Literal("a").ast) }) it("should throw on unsupported schemas", () => { - expect(() => S.keyof(S.Option(S.String))).toThrow( + throws( + () => S.keyof(S.Option(S.String)), new Error(`Unsupported schema schema (Declaration): Option`) ) diff --git a/packages/effect/test/Schema/Schema/mutable.test.ts b/packages/effect/test/Schema/Schema/mutable.test.ts index ea7c6c5eb11..63247e435e2 100644 --- a/packages/effect/test/Schema/Schema/mutable.test.ts +++ b/packages/effect/test/Schema/Schema/mutable.test.ts @@ -1,16 +1,18 @@ import { identity } from "effect" import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("mutable", () => { it("string", () => { - expect(S.mutable(S.String).ast).toEqual(S.String.ast) + deepStrictEqual(S.mutable(S.String).ast, S.String.ast) }) it("struct", () => { const schema = S.mutable(S.Struct({ a: S.Number })) - expect(schema.ast).toEqual( + deepStrictEqual( + schema.ast, new AST.TypeLiteral([ new AST.PropertySignature("a", S.Number.ast, false, false) ], []) @@ -19,21 +21,18 @@ describe("mutable", () => { it("record", () => { const schema = S.mutable(S.Record({ key: S.String, value: S.Number })) - expect(schema.ast).toEqual( - new AST.TypeLiteral([], [new AST.IndexSignature(S.String.ast, S.Number.ast, false)]) - ) + deepStrictEqual(schema.ast, new AST.TypeLiteral([], [new AST.IndexSignature(S.String.ast, S.Number.ast, false)])) }) it("array", () => { const schema = S.mutable(S.Array(S.String)) - expect(schema.ast).toEqual( - new AST.TupleType([], [new AST.Type(S.String.ast)], false) - ) + deepStrictEqual(schema.ast, new AST.TupleType([], [new AST.Type(S.String.ast)], false)) }) it("union", () => { const schema = S.mutable(S.Union(S.Struct({ a: S.Number }), S.Array(S.String))) - expect(schema.ast).toEqual( + deepStrictEqual( + schema.ast, AST.Union.make([ new AST.TypeLiteral([ new AST.PropertySignature("a", S.Number.ast, false, false) @@ -46,9 +45,7 @@ describe("mutable", () => { it("refinement", () => { const schema = S.mutable(S.Array(S.String).pipe(S.maxItems(2))) if (AST.isRefinement(schema.ast)) { - expect(schema.ast.from).toEqual( - new AST.TupleType([], [new AST.Type(S.String.ast)], false) - ) + deepStrictEqual(schema.ast.from, new AST.TupleType([], [new AST.Type(S.String.ast)], false)) } }) @@ -57,9 +54,7 @@ describe("mutable", () => { () => S.Array(S.String) )) if (AST.isSuspend(schema.ast)) { - expect(schema.ast.f()).toEqual( - new AST.TupleType([], [new AST.Type(S.String.ast)], false) - ) + deepStrictEqual(schema.ast.f(), new AST.TupleType([], [new AST.Type(S.String.ast)], false)) } }) @@ -68,12 +63,8 @@ describe("mutable", () => { S.transform(S.Array(S.String), S.Array(S.String), { strict: true, decode: identity, encode: identity }) ) if (AST.isTransformation(schema.ast)) { - expect(schema.ast.from).toEqual( - new AST.TupleType([], [new AST.Type(S.String.ast)], false) - ) - expect(schema.ast.to).toEqual( - new AST.TupleType([], [new AST.Type(S.String.ast)], false) - ) + deepStrictEqual(schema.ast.from, new AST.TupleType([], [new AST.Type(S.String.ast)], false)) + deepStrictEqual(schema.ast.to, new AST.TupleType([], [new AST.Type(S.String.ast)], false)) } }) }) diff --git a/packages/effect/test/Schema/Schema/nonEmptyArray.test.ts b/packages/effect/test/Schema/Schema/nonEmptyArray.test.ts index f22978eca81..b3e06af0b84 100644 --- a/packages/effect/test/Schema/Schema/nonEmptyArray.test.ts +++ b/packages/effect/test/Schema/Schema/nonEmptyArray.test.ts @@ -1,11 +1,12 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("nonEmptyArray", () => { it("annotations()", () => { const schema = S.NonEmptyArray(S.String).annotations({ identifier: "X" }).annotations({ title: "Y" }) - expect(schema.ast.annotations).toStrictEqual({ + deepStrictEqual(schema.ast.annotations, { [AST.IdentifierAnnotationId]: "X", [AST.TitleAnnotationId]: "Y" }) @@ -13,6 +14,6 @@ describe("nonEmptyArray", () => { it("should expose the value", () => { const schema = S.NonEmptyArray(S.String) - expect(schema.value).toStrictEqual(S.String) + strictEqual(schema.value, S.String) }) }) diff --git a/packages/effect/test/Schema/Schema/omit.test.ts b/packages/effect/test/Schema/Schema/omit.test.ts index b58d305213a..ef4bab187fa 100644 --- a/packages/effect/test/Schema/Schema/omit.test.ts +++ b/packages/effect/test/Schema/Schema/omit.test.ts @@ -1,6 +1,7 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("omit", () => { it("Struct", async () => { @@ -101,13 +102,13 @@ describe("omit", () => { it("typeSchema(Class)", () => { class A extends S.Class("A")({ a: S.String, b: S.NumberFromString }) {} const schema = A.pipe(S.typeSchema, S.omit("a")) - expect(schema.ast).toStrictEqual(S.Struct({ b: S.Number }).ast) + deepStrictEqual(schema.ast, S.Struct({ b: S.Number }).ast) }) it("Class", () => { class A extends S.Class("A")({ a: S.String, b: S.NumberFromString }) {} const schema = A.pipe(S.omit("a")) - expect(schema.ast).toStrictEqual(S.Struct({ b: S.NumberFromString }).ast) + deepStrictEqual(schema.ast, S.Struct({ b: S.NumberFromString }).ast) }) it("struct with key rename", async () => { diff --git a/packages/effect/test/Schema/Schema/optional.test.ts b/packages/effect/test/Schema/Schema/optional.test.ts index c4a8eace1d7..c5340bb797f 100644 --- a/packages/effect/test/Schema/Schema/optional.test.ts +++ b/packages/effect/test/Schema/Schema/optional.test.ts @@ -1,26 +1,27 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("optional", () => { it("should expose a from property", () => { const schema = S.optional(S.String) - expect(schema.from).toStrictEqual(S.String) + strictEqual(schema.from, S.String) }) it("if the input is Schema.Undefined should not duplicate the schema", () => { const schema = S.optional(S.Undefined) - expect((schema.ast as any as S.PropertySignatureDeclaration).type).toStrictEqual(S.Undefined.ast) + strictEqual((schema.ast as any as S.PropertySignatureDeclaration).type, S.Undefined.ast) }) it("if the input is Schema.Never should include the input in the schema", () => { const schema = S.optional(S.Never) - expect((schema.ast as any as S.PropertySignatureDeclaration).type).toStrictEqual(S.Undefined.ast) + strictEqual((schema.ast as any as S.PropertySignatureDeclaration).type, S.Undefined.ast) }) it("should expose a from property after an annotations call", () => { const schema = S.optional(S.String).annotations({}) - expect(schema.from).toStrictEqual(S.String) + strictEqual(schema.from, S.String) }) it("decoding / encoding", async () => { diff --git a/packages/effect/test/Schema/Schema/optionalElement.test.ts b/packages/effect/test/Schema/Schema/optionalElement.test.ts index c5fac2175b4..adcf8c4ddb9 100644 --- a/packages/effect/test/Schema/Schema/optionalElement.test.ts +++ b/packages/effect/test/Schema/Schema/optionalElement.test.ts @@ -1,8 +1,9 @@ import * as S from "effect/Schema" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("optionalElement", () => { it("toString", () => { - expect(String(S.optionalElement(S.String))).toStrictEqual("string?") + strictEqual(String(S.optionalElement(S.String)), "string?") }) }) diff --git a/packages/effect/test/Schema/Schema/optionalWith.test.ts b/packages/effect/test/Schema/Schema/optionalWith.test.ts index f7a40c5116b..f489b476b38 100644 --- a/packages/effect/test/Schema/Schema/optionalWith.test.ts +++ b/packages/effect/test/Schema/Schema/optionalWith.test.ts @@ -2,7 +2,8 @@ import * as O from "effect/Option" import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("optionalWith", () => { it("annotations", async () => { @@ -11,7 +12,7 @@ describe("optionalWith", () => { exact: true }).annotations({ description: "my description" }) }) - expect((schema.ast as any).propertySignatures[0].annotations).toStrictEqual({ + deepStrictEqual((schema.ast as any).propertySignatures[0].annotations, { [AST.DescriptionAnnotationId]: "my description" }) }) @@ -19,12 +20,12 @@ describe("optionalWith", () => { describe("{ exact: true }", () => { it("should expose a from property", () => { const schema = S.optionalWith(S.String, { exact: true }) - expect(schema.from).toStrictEqual(S.String) + strictEqual(schema.from, S.String) }) it("should expose a from property after an annotations call", () => { const schema = S.optionalWith(S.String, { exact: true }).annotations({}) - expect(schema.from).toStrictEqual(S.String) + strictEqual(schema.from, S.String) }) it("decoding / encoding", async () => { @@ -48,7 +49,7 @@ describe("optionalWith", () => { }) it("never", async () => { - expect(S.optionalWith(S.Never, { exact: true }).from.ast).toStrictEqual(AST.neverKeyword) + strictEqual(S.optionalWith(S.Never, { exact: true }).from.ast, AST.neverKeyword) const schema = S.Struct({ a: S.optionalWith(S.Never, { exact: true }), b: S.Number }) await Util.assertions.decoding.succeed(schema, { b: 1 }) await Util.assertions.decoding.fail( @@ -409,7 +410,7 @@ describe("optionalWith", () => { const schema = S.Struct({ a: S.optionalWith(S.NumberFromString, { exact: true, default: () => 0 }) }) - expect(schema.make({})).toStrictEqual({ a: 0 }) + deepStrictEqual(schema.make({}), { a: 0 }) }) }) @@ -443,7 +444,7 @@ describe("optionalWith", () => { const schema = S.Struct({ a: S.optionalWith(S.NumberFromString, { default: () => 0 }) }) - expect(schema.make({})).toStrictEqual({ a: 0 }) + deepStrictEqual(schema.make({}), { a: 0 }) }) }) @@ -479,7 +480,7 @@ describe("optionalWith", () => { const schema = S.Struct({ a: S.optionalWith(S.NumberFromString, { nullable: true, default: () => 0 }) }) - expect(schema.make({})).toStrictEqual({ a: 0 }) + deepStrictEqual(schema.make({}), { a: 0 }) }) }) @@ -513,7 +514,7 @@ describe("optionalWith", () => { const schema = S.Struct({ a: S.optionalWith(S.NumberFromString, { exact: true, nullable: true, default: () => 0 }) }) - expect(schema.make({})).toStrictEqual({ a: 0 }) + deepStrictEqual(schema.make({}), { a: 0 }) }) }) }) diff --git a/packages/effect/test/Schema/Schema/partial.test.ts b/packages/effect/test/Schema/Schema/partial.test.ts index a4844583e5a..b847a3a706a 100644 --- a/packages/effect/test/Schema/Schema/partial.test.ts +++ b/packages/effect/test/Schema/Schema/partial.test.ts @@ -1,6 +1,7 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" describe("partial", () => { it("Struct", async () => { @@ -64,14 +65,16 @@ describe("partial", () => { describe("unsupported schemas", () => { it("declarations should throw", () => { - expect(() => S.partial(S.OptionFromSelf(S.String))).toThrow( + throws( + () => S.partial(S.OptionFromSelf(S.String)), new Error(`Unsupported schema schema (Declaration): Option`) ) }) it("refinements should throw", () => { - expect(() => S.partial(S.String.pipe(S.minLength(2)))).toThrow( + throws( + () => S.partial(S.String.pipe(S.minLength(2))), new Error(`Unsupported schema schema (Refinement): minLength(2)`) ) @@ -84,7 +87,8 @@ schema (Refinement): minLength(2)`) b: S.propertySignature(S.String).pipe(S.fromKey("c")) }) const schema = S.partial(original) - expect(S.format(schema)).toBe( + strictEqual( + S.format(schema), "({ readonly a?: string | undefined; readonly c?: string | undefined } <-> { readonly a?: string | undefined; readonly b?: string | undefined })" ) await Util.assertions.decoding.succeed(schema, {}) diff --git a/packages/effect/test/Schema/Schema/partialWith.test.ts b/packages/effect/test/Schema/Schema/partialWith.test.ts index c7c7837f2a3..c9e1870769e 100644 --- a/packages/effect/test/Schema/Schema/partialWith.test.ts +++ b/packages/effect/test/Schema/Schema/partialWith.test.ts @@ -1,7 +1,8 @@ import { identity } from "effect/Function" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" describe("partialWith", () => { describe("{ exact: true }", () => { @@ -130,14 +131,16 @@ describe("partialWith", () => { describe("unsupported schemas", () => { it("declarations should throw", () => { - expect(() => S.partialWith(S.OptionFromSelf(S.String), { exact: true })).toThrow( + throws( + () => S.partialWith(S.OptionFromSelf(S.String), { exact: true }), new Error(`Unsupported schema schema (Declaration): Option`) ) }) it("refinements should throw", () => { - expect(() => S.partialWith(S.String.pipe(S.minLength(2)), { exact: true })).toThrow( + throws( + () => S.partialWith(S.String.pipe(S.minLength(2)), { exact: true }), new Error(`Unsupported schema schema (Refinement): minLength(2)`) ) @@ -150,7 +153,8 @@ schema (Refinement): minLength(2)`) b: S.propertySignature(S.String).pipe(S.fromKey("c")) }) const schema = S.partialWith(original, { exact: true }) - expect(S.format(schema)).toBe( + strictEqual( + S.format(schema), "({ readonly a?: string; readonly c?: string } <-> { readonly a?: string; readonly b?: string })" ) await Util.assertions.decoding.succeed(schema, {}) @@ -160,11 +164,11 @@ schema (Refinement): minLength(2)`) }) it("transformations should throw", () => { - expect(() => - S.partialWith(S.transform(S.String, S.String, { strict: true, decode: identity, encode: identity }), { - exact: true - }) - ).toThrow( + throws( + () => + S.partialWith(S.transform(S.String, S.String, { strict: true, decode: identity, encode: identity }), { + exact: true + }), new Error(`Unsupported schema schema (Transformation): (string <-> string)`) ) diff --git a/packages/effect/test/Schema/Schema/pick.test.ts b/packages/effect/test/Schema/Schema/pick.test.ts index 19e51db7c4b..c940d5a5bff 100644 --- a/packages/effect/test/Schema/Schema/pick.test.ts +++ b/packages/effect/test/Schema/Schema/pick.test.ts @@ -1,6 +1,7 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("pick", () => { it("Struct", async () => { @@ -145,12 +146,12 @@ describe("pick", () => { it("typeSchema(Class)", () => { class A extends S.Class("A")({ a: S.String, b: S.NumberFromString }) {} const schema = A.pipe(S.typeSchema, S.pick("b")) - expect(schema.ast).toStrictEqual(S.Struct({ b: S.Number }).ast) + deepStrictEqual(schema.ast, S.Struct({ b: S.Number }).ast) }) it("Class", () => { class A extends S.Class("A")({ a: S.String, b: S.NumberFromString }) {} const schema = A.pipe(S.pick("b")) - expect(schema.ast).toStrictEqual(S.Struct({ b: S.NumberFromString }).ast) + deepStrictEqual(schema.ast, S.Struct({ b: S.NumberFromString }).ast) }) }) diff --git a/packages/effect/test/Schema/Schema/pickLiteral.test.ts b/packages/effect/test/Schema/Schema/pickLiteral.test.ts index 0afecc51f91..5c785a1c244 100644 --- a/packages/effect/test/Schema/Schema/pickLiteral.test.ts +++ b/packages/effect/test/Schema/Schema/pickLiteral.test.ts @@ -1,15 +1,17 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("pickLiteral", () => { it("should return an unwrapped AST with exactly one literal", () => { - expect(S.Literal("a").pipe(S.pickLiteral("a")).ast).toEqual(new AST.Literal("a")) + deepStrictEqual(S.Literal("a").pipe(S.pickLiteral("a")).ast, new AST.Literal("a")) }) it("should return a union with more than one literal", () => { - expect(S.Literal("a", "b", "c").pipe(S.pickLiteral("a", "b")).ast).toEqual( + deepStrictEqual( + S.Literal("a", "b", "c").pipe(S.pickLiteral("a", "b")).ast, AST.Union.make([new AST.Literal("a"), new AST.Literal("b")]) ) }) diff --git a/packages/effect/test/Schema/Schema/pipe.test.ts b/packages/effect/test/Schema/Schema/pipe.test.ts index c430d910a82..c0aaac4fc4f 100644 --- a/packages/effect/test/Schema/Schema/pipe.test.ts +++ b/packages/effect/test/Schema/Schema/pipe.test.ts @@ -1,5 +1,6 @@ import * as S from "effect/Schema" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue } from "effect/test/util" +import { describe, it } from "vitest" describe("pipe", () => { it("schemas should be pipeable", () => { @@ -10,8 +11,8 @@ describe("pipe", () => { const PositiveInt = S.NumberFromString.pipe(int, positive) const is = S.is(PositiveInt) - expect(is(1)).toEqual(true) - expect(is(-1)).toEqual(false) - expect(is(1.2)).toEqual(false) + assertTrue(is(1)) + assertFalse(is(-1)) + assertFalse(is(1.2)) }) }) diff --git a/packages/effect/test/Schema/Schema/pluck.test.ts b/packages/effect/test/Schema/Schema/pluck.test.ts index 5b0bdda8c9a..bbca109edf2 100644 --- a/packages/effect/test/Schema/Schema/pluck.test.ts +++ b/packages/effect/test/Schema/Schema/pluck.test.ts @@ -97,7 +97,7 @@ describe("pluck", () => { it("struct with optional key", async () => { const origin = S.Struct({ a: S.optional(S.String) }) const schema = S.pluck(origin, "a") - await Util.assertions.encoding.succeed(schema, undefined, { a: undefined }) + await Util.assertions.encoding.succeed(schema, undefined, {}) await Util.assertions.encoding.succeed(schema, "a", { a: "a" }) }) diff --git a/packages/effect/test/Schema/Schema/rename.test.ts b/packages/effect/test/Schema/Schema/rename.test.ts index e163e715ae1..8a197a9ca26 100644 --- a/packages/effect/test/Schema/Schema/rename.test.ts +++ b/packages/effect/test/Schema/Schema/rename.test.ts @@ -1,6 +1,7 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("rename", () => { describe("Struct", () => { @@ -86,7 +87,7 @@ describe("rename", () => { it("should return the same ast if there are no mappings", () => { const schema = S.Struct({ a: S.String }) const renamed = S.rename(schema, {}) - expect(schema.ast === renamed.ast).toBe(true) + strictEqual(schema.ast, renamed.ast) }) it("field transformation", async () => { diff --git a/packages/effect/test/Schema/Schema/required.test.ts b/packages/effect/test/Schema/Schema/required.test.ts index a04e899aedc..0cd379171f0 100644 --- a/packages/effect/test/Schema/Schema/required.test.ts +++ b/packages/effect/test/Schema/Schema/required.test.ts @@ -1,11 +1,12 @@ import { identity } from "effect/Function" import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" describe("required", () => { it("string", () => { - expect(S.required(S.String).ast).toEqual(S.String.ast) + strictEqual(S.required(S.String).ast, S.String.ast) }) it("Struct", async () => { @@ -189,14 +190,16 @@ describe("required", () => { describe("unsupported schemas", () => { it("declarations should throw", async () => { - expect(() => S.required(S.OptionFromSelf(S.String))).toThrow( + throws( + () => S.required(S.OptionFromSelf(S.String)), new Error(`Unsupported schema schema (Declaration): Option`) ) }) it("refinements should throw", async () => { - expect(() => S.required(S.String.pipe(S.minLength(2)))).toThrow( + throws( + () => S.required(S.String.pipe(S.minLength(2))), new Error(`Unsupported schema schema (Refinement): minLength(2)`) ) @@ -209,17 +212,18 @@ schema (Refinement): minLength(2)`) b: S.propertySignature(S.String).pipe(S.fromKey("c")) }) const schema = S.required(S.partial(original)) - expect(S.format(schema)).toBe( + strictEqual( + S.format(schema), "({ readonly a: string | undefined; readonly c: string | undefined } <-> { readonly a: string | undefined; readonly b: string | undefined })" ) }) it("transformations should throw", async () => { - expect(() => S.required(S.transform(S.String, S.String, { strict: true, decode: identity, encode: identity }))) - .toThrow( - new Error(`Unsupported schema + throws( + () => S.required(S.transform(S.String, S.String, { strict: true, decode: identity, encode: identity })), + new Error(`Unsupported schema schema (Transformation): (string <-> string)`) - ) + ) }) }) }) diff --git a/packages/effect/test/Schema/Schema/suspend.test.ts b/packages/effect/test/Schema/Schema/suspend.test.ts index 9e8c76f50fd..e521255b2cb 100644 --- a/packages/effect/test/Schema/Schema/suspend.test.ts +++ b/packages/effect/test/Schema/Schema/suspend.test.ts @@ -1,6 +1,7 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("suspend", () => { describe("toString", () => { @@ -9,12 +10,12 @@ describe("suspend", () => { const schema: S.Schema = S.suspend( // intended outer suspend () => S.Tuple(S.Number, S.Union(schema, S.Literal(null))) ) - expect(String(schema)).toEqual("") + strictEqual(String(schema), "") }) it("should handle before initialization error", () => { const schema = S.suspend(() => string) - expect(String(schema)).toEqual("") + strictEqual(String(schema), "") const string = S.String }) }) diff --git a/packages/effect/test/Schema/Schema/typeSchema.test.ts b/packages/effect/test/Schema/Schema/typeSchema.test.ts index 7fad1c5f583..aaa24903442 100644 --- a/packages/effect/test/Schema/Schema/typeSchema.test.ts +++ b/packages/effect/test/Schema/Schema/typeSchema.test.ts @@ -1,6 +1,7 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("typeSchema", () => { it("transformation", () => { @@ -11,7 +12,7 @@ describe("typeSchema", () => { ), S.typeSchema ) - expect(S.decodeUnknownSync(schema)([1, 2])).toEqual([1, 2]) + deepStrictEqual(S.decodeUnknownSync(schema)([1, 2]), [1, 2]) }) it("refinement", () => { @@ -20,10 +21,10 @@ describe("typeSchema", () => { S.lessThanOrEqualTo(2), S.typeSchema ) - expect(S.is(schema)(0)).toEqual(false) - expect(S.is(schema)(1)).toEqual(true) - expect(S.is(schema)(2)).toEqual(true) - expect(S.is(schema)(3)).toEqual(false) + assertFalse(S.is(schema)(0)) + assertTrue(S.is(schema)(1)) + assertTrue(S.is(schema)(2)) + assertFalse(S.is(schema)(3)) }) it("suspend", async () => { diff --git a/packages/effect/test/Schema/Schema/validateOption.test.ts b/packages/effect/test/Schema/Schema/validateOption.test.ts index 146d3144b7b..59c6532d2c5 100644 --- a/packages/effect/test/Schema/Schema/validateOption.test.ts +++ b/packages/effect/test/Schema/Schema/validateOption.test.ts @@ -1,24 +1,24 @@ -import { Option, Schema as S } from "effect" +import { Schema as S } from "effect" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertNone, assertSome } from "effect/test/util" +import { describe, it } from "vitest" describe("validateOption", () => { it("should return none on async", () => { - expect(S.validateOption(Util.AsyncDeclaration)("a")).toStrictEqual(Option.none()) + assertNone(S.validateOption(Util.AsyncDeclaration)("a")) }) const schema = S.Struct({ a: Util.NumberFromChar }) it("should return None on invalid values", () => { - expect(S.validateOption(schema)({ a: 1 })).toStrictEqual(Option.some({ a: 1 })) - expect(S.validateOption(schema)({ a: null })).toStrictEqual(Option.none()) + assertSome(S.validateOption(schema)({ a: 1 }), { a: 1 }) + assertNone(S.validateOption(schema)({ a: null })) }) it("should respect outer/inner options", () => { const input = { a: 1, b: "b" } - expect(S.validateOption(schema)(input, { onExcessProperty: "error" })).toStrictEqual(Option.none()) - expect(S.validateOption(schema, { onExcessProperty: "error" })(input)).toStrictEqual(Option.none()) - expect(S.validateOption(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" })) - .toStrictEqual(Option.some({ a: 1 })) + assertNone(S.validateOption(schema)(input, { onExcessProperty: "error" })) + assertNone(S.validateOption(schema, { onExcessProperty: "error" })(input)) + assertSome(S.validateOption(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" }), { a: 1 }) }) }) diff --git a/packages/effect/test/Schema/Schema/validatePromise.test.ts b/packages/effect/test/Schema/Schema/validatePromise.test.ts index 3767f788c73..494e869bc94 100644 --- a/packages/effect/test/Schema/Schema/validatePromise.test.ts +++ b/packages/effect/test/Schema/Schema/validatePromise.test.ts @@ -1,12 +1,13 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("validatePromise", () => { const schema = S.Struct({ a: Util.NumberFromChar }) it("should return None on invalid values", async () => { - expect(await S.validatePromise(schema)({ a: 1 })).toStrictEqual({ a: 1 }) + deepStrictEqual(await S.validatePromise(schema)({ a: 1 }), { a: 1 }) await Util.assertions.promise.fail( S.validatePromise(schema)({ a: null }), @@ -19,8 +20,10 @@ describe("validatePromise", () => { it("should respect outer/inner options", async () => { const input = { a: 1, b: "b" } - expect(await S.validatePromise(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" })) - .toStrictEqual({ a: 1 }) + deepStrictEqual( + await S.validatePromise(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" }), + { a: 1 } + ) await Util.assertions.promise.fail( S.validatePromise(schema)(input, { onExcessProperty: "error" }), diff --git a/packages/effect/test/Schema/Schema/validateSync.test.ts b/packages/effect/test/Schema/Schema/validateSync.test.ts index 6fac05c2791..38dff6e036e 100644 --- a/packages/effect/test/Schema/Schema/validateSync.test.ts +++ b/packages/effect/test/Schema/Schema/validateSync.test.ts @@ -1,41 +1,45 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("validateSync", () => { const schema = S.Struct({ a: Util.NumberFromChar }) it("should throw on invalid values", () => { - expect(S.validateSync(schema)({ a: 1 })).toEqual({ a: 1 }) - expect(() => S.validateSync(schema)({ a: null })).toThrow( - new Error(`{ readonly a: number } + deepStrictEqual(S.validateSync(schema)({ a: 1 }), { a: 1 }) + Util.assertParseError( + () => S.validateSync(schema)({ a: null }), + `{ readonly a: number } └─ ["a"] - └─ Expected number, actual null`) + └─ Expected number, actual null` ) }) it("should throw on async", () => { - expect(() => S.validateSync(Util.AsyncDeclaration)("a")).toThrow( - new Error( - `AsyncDeclaration + Util.assertParseError( + () => S.validateSync(Util.AsyncDeclaration)("a"), + `AsyncDeclaration └─ cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work` - ) ) }) it("should respect outer/inner options", () => { const input = { a: 1, b: "b" } - expect(() => S.validateSync(schema)(input, { onExcessProperty: "error" })).toThrow( - new Error(`{ readonly a: number } + Util.assertParseError( + () => S.validateSync(schema)(input, { onExcessProperty: "error" }), + `{ readonly a: number } └─ ["b"] - └─ is unexpected, expected: "a"`) + └─ is unexpected, expected: "a"` ) - expect(() => S.validateSync(schema, { onExcessProperty: "error" })(input)).toThrow( - new Error(`{ readonly a: number } + Util.assertParseError( + () => S.validateSync(schema, { onExcessProperty: "error" })(input), + `{ readonly a: number } └─ ["b"] - └─ is unexpected, expected: "a"`) + └─ is unexpected, expected: "a"` ) - expect(S.validateSync(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" })) - .toEqual({ a: 1 }) + deepStrictEqual(S.validateSync(schema, { onExcessProperty: "error" })(input, { onExcessProperty: "ignore" }), { + a: 1 + }) }) }) diff --git a/packages/effect/test/Schema/Schema/withConstructorDefault.test.ts b/packages/effect/test/Schema/Schema/withConstructorDefault.test.ts index d94cd59a822..d86c3250639 100644 --- a/packages/effect/test/Schema/Schema/withConstructorDefault.test.ts +++ b/packages/effect/test/Schema/Schema/withConstructorDefault.test.ts @@ -1,21 +1,22 @@ import * as S from "effect/Schema" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("withConstructorDefault", () => { it("annotating a PropertySignatureDeclaration should repect existing defaultValues", () => { const prop: any = S.propertySignature(S.String).pipe(S.withConstructorDefault(() => "")).annotations({}) - expect(prop.ast.defaultValue()).toBe("") + strictEqual(prop.ast.defaultValue(), "") }) it("annotating a PropertySignatureTransformation should repect existing defaultValues", () => { const prop: any = S.optionalWith(S.String, { nullable: true }).pipe(S.withConstructorDefault(() => "")).annotations( {} ) - expect(prop.ast.to.defaultValue()).toBe("") + strictEqual(prop.ast.to.defaultValue(), "") }) it("using fromKey should repect existing defaultValues", () => { const prop: any = S.propertySignature(S.String).pipe(S.withConstructorDefault(() => ""), S.fromKey("a")) - expect(prop.ast.to.defaultValue()).toBe("") + strictEqual(prop.ast.to.defaultValue(), "") }) }) diff --git a/packages/effect/test/Schema/Schema/withDecodingDefault.test.ts b/packages/effect/test/Schema/Schema/withDecodingDefault.test.ts index d735c782a36..39f31c3baa3 100644 --- a/packages/effect/test/Schema/Schema/withDecodingDefault.test.ts +++ b/packages/effect/test/Schema/Schema/withDecodingDefault.test.ts @@ -1,6 +1,7 @@ import * as S from "effect/Schema" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("withDecodingDefault", () => { describe("PropertySignatureDeclaration", () => { @@ -21,10 +22,10 @@ describe("withDecodingDefault", () => { it("should prune undefined from the type", () => { const prop1 = S.optional(S.String).pipe(S.withDecodingDefault(() => "")) - expect(String(prop1)).toBe(`PropertySignature<":", string, never, "?:", string | undefined>`) + strictEqual(String(prop1), `PropertySignature<":", string, never, "?:", string | undefined>`) const prop2 = S.optional(S.NumberFromString).pipe(S.withDecodingDefault(() => 0)) - expect(String(prop2)).toBe(`PropertySignature<":", number, never, "?:", NumberFromString | undefined>`) + strictEqual(String(prop2), `PropertySignature<":", number, never, "?:", NumberFromString | undefined>`) }) }) @@ -49,10 +50,10 @@ describe("withDecodingDefault", () => { it("should prune undefined from the type", () => { const prop1 = S.optional(S.String).pipe(S.fromKey("a"), S.withDecodingDefault(() => "")) - expect(String(prop1)).toBe(`PropertySignature<":", string, "a", "?:", string | undefined>`) + strictEqual(String(prop1), `PropertySignature<":", string, "a", "?:", string | undefined>`) const prop2 = S.optional(S.NumberFromString).pipe(S.fromKey("a"), S.withDecodingDefault(() => 0)) - expect(String(prop2)).toBe(`PropertySignature<":", number, "a", "?:", NumberFromString | undefined>`) + strictEqual(String(prop2), `PropertySignature<":", number, "a", "?:", NumberFromString | undefined>`) }) }) }) diff --git a/packages/effect/test/Schema/SchemaAST/IndexSignature.test.ts b/packages/effect/test/Schema/SchemaAST/IndexSignature.test.ts index d6d3c8b8868..8968649f783 100644 --- a/packages/effect/test/Schema/SchemaAST/IndexSignature.test.ts +++ b/packages/effect/test/Schema/SchemaAST/IndexSignature.test.ts @@ -1,14 +1,15 @@ import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { throws } from "effect/test/util" +import { describe, it } from "vitest" describe("AST.IndexSignature", () => { it("new IndexSignature should throw on unsupported ASTs", () => { - expect(() => new AST.IndexSignature(AST.booleanKeyword, AST.stringKeyword, true)) - .toThrow( - new Error( - `Unsupported index signature parameter + throws( + () => new AST.IndexSignature(AST.booleanKeyword, AST.stringKeyword, true), + new Error( + `Unsupported index signature parameter details: An index signature parameter type must be \`string\`, \`symbol\`, a template literal type or a refinement of the previous types` - ) ) + ) }) }) diff --git a/packages/effect/test/Schema/SchemaAST/Refinement.test.ts b/packages/effect/test/Schema/SchemaAST/Refinement.test.ts index cc67807e467..b12ca78d03f 100644 --- a/packages/effect/test/Schema/SchemaAST/Refinement.test.ts +++ b/packages/effect/test/Schema/SchemaAST/Refinement.test.ts @@ -1,11 +1,12 @@ import * as S from "effect/Schema" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("AST.Refinement", () => { it("toString", () => { - expect(String(S.Number.pipe(S.filter(() => true)))).toBe("{ number | filter }") - expect(String(S.Number.pipe(S.int()))).toBe("int") - expect(String(S.Number.pipe(S.int(), S.positive()))).toBe("int & positive") - expect(String(S.Int.pipe(S.positive()))).toBe("Int & positive") + strictEqual(String(S.Number.pipe(S.filter(() => true))), "{ number | filter }") + strictEqual(String(S.Number.pipe(S.int())), "int") + strictEqual(String(S.Number.pipe(S.int(), S.positive())), "int & positive") + strictEqual(String(S.Int.pipe(S.positive())), "Int & positive") }) }) diff --git a/packages/effect/test/Schema/SchemaAST/Tuple.test.ts b/packages/effect/test/Schema/SchemaAST/Tuple.test.ts index 7907a514155..8f4c7da8c09 100644 --- a/packages/effect/test/Schema/SchemaAST/Tuple.test.ts +++ b/packages/effect/test/Schema/SchemaAST/Tuple.test.ts @@ -1,33 +1,34 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" describe("AST.Tuple", () => { it("toString", () => { - expect(String(S.Tuple(S.String, S.optionalElement(S.Number)))).toStrictEqual("readonly [string, number?]") + strictEqual(String(S.Tuple(S.String, S.optionalElement(S.Number))), "readonly [string, number?]") }) it("A required element cannot follow an optional element", () => { - expect(() => - new AST.TupleType( - [new AST.OptionalType(AST.stringKeyword, true), new AST.OptionalType(AST.stringKeyword, false)], - [], - true - ) - ).toThrow( + throws( + () => + new AST.TupleType( + [new AST.OptionalType(AST.stringKeyword, true), new AST.OptionalType(AST.stringKeyword, false)], + [], + true + ), new Error(`Invalid element details: A required element cannot follow an optional element. ts(1257)`) ) }) it("A required rest element cannot follow an optional element", () => { - expect(() => - new AST.TupleType( - [new AST.OptionalType(AST.stringKeyword, true)], - [new AST.Type(AST.stringKeyword), new AST.Type(AST.stringKeyword)], - true - ) - ).toThrow( + throws( + () => + new AST.TupleType( + [new AST.OptionalType(AST.stringKeyword, true)], + [new AST.Type(AST.stringKeyword), new AST.Type(AST.stringKeyword)], + true + ), new Error(`Invalid element details: A required element cannot follow an optional element. ts(1257)`) ) diff --git a/packages/effect/test/Schema/SchemaAST/TypeLiteral.test.ts b/packages/effect/test/Schema/SchemaAST/TypeLiteral.test.ts index c8af4afb310..8e82048f17a 100644 --- a/packages/effect/test/Schema/SchemaAST/TypeLiteral.test.ts +++ b/packages/effect/test/Schema/SchemaAST/TypeLiteral.test.ts @@ -1,10 +1,12 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { strictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" describe("AST.TypeLiteral", () => { it("should throw on onvalid index signature parameters", () => { - expect(() => new AST.IndexSignature(S.NumberFromString.ast, AST.stringKeyword, true)).toThrow( + throws( + () => new AST.IndexSignature(S.NumberFromString.ast, AST.stringKeyword, true), new Error( `Unsupported index signature parameter details: An index signature parameter type must be \`string\`, \`symbol\`, a template literal type or a refinement of the previous types` @@ -14,23 +16,19 @@ details: An index signature parameter type must be \`string\`, \`symbol\`, a tem describe("toString", () => { it("Struct (immutable)", () => { - expect(S.Struct({ a: S.String, b: S.Number }).ast.toString()).toBe(`{ readonly a: string; readonly b: number }`) + strictEqual(S.Struct({ a: S.String, b: S.Number }).ast.toString(), `{ readonly a: string; readonly b: number }`) }) it("Struct (mutable)", () => { - expect(S.mutable(S.Struct({ a: S.String, b: S.Number })).ast.toString()).toBe( - `{ a: string; b: number }` - ) + strictEqual(S.mutable(S.Struct({ a: S.String, b: S.Number })).ast.toString(), `{ a: string; b: number }`) }) it("Record (immutable)", () => { - expect(S.Record({ key: S.String, value: S.Number }).ast.toString()).toBe(`{ readonly [x: string]: number }`) + strictEqual(S.Record({ key: S.String, value: S.Number }).ast.toString(), `{ readonly [x: string]: number }`) }) it("Record (mutable)", () => { - expect(S.mutable(S.Record({ key: S.String, value: S.Number })).ast.toString()).toBe( - `{ [x: string]: number }` - ) + strictEqual(S.mutable(S.Record({ key: S.String, value: S.Number })).ast.toString(), `{ [x: string]: number }`) }) }) }) diff --git a/packages/effect/test/Schema/SchemaAST/TypeLiteralTransformation.test.ts b/packages/effect/test/Schema/SchemaAST/TypeLiteralTransformation.test.ts index 00407feee31..12aa56981af 100644 --- a/packages/effect/test/Schema/SchemaAST/TypeLiteralTransformation.test.ts +++ b/packages/effect/test/Schema/SchemaAST/TypeLiteralTransformation.test.ts @@ -1,24 +1,25 @@ import { identity } from "effect/Function" import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { throws } from "effect/test/util" +import { describe, it } from "vitest" describe("AST.TypeLiteralTransformation", () => { it("Duplicate property signature transformation", () => { - expect(() => - new AST.TypeLiteralTransformation([ - new AST.PropertySignatureTransformation("a", "b", identity, identity), - new AST.PropertySignatureTransformation("a", "c", identity, identity) - ]) - ).toThrow( + throws( + () => + new AST.TypeLiteralTransformation([ + new AST.PropertySignatureTransformation("a", "b", identity, identity), + new AST.PropertySignatureTransformation("a", "c", identity, identity) + ]), new Error(`Duplicate property signature transformation details: Duplicate key "a"`) ) - expect(() => - new AST.TypeLiteralTransformation([ - new AST.PropertySignatureTransformation("a", "c", identity, identity), - new AST.PropertySignatureTransformation("b", "c", identity, identity) - ]) - ).toThrow( + throws( + () => + new AST.TypeLiteralTransformation([ + new AST.PropertySignatureTransformation("a", "c", identity, identity), + new AST.PropertySignatureTransformation("b", "c", identity, identity) + ]), new Error(`Duplicate property signature transformation details: Duplicate key "c"`) ) diff --git a/packages/effect/test/Schema/SchemaAST/Union.test.ts b/packages/effect/test/Schema/SchemaAST/Union.test.ts index e330a4f36fb..c284770ed5a 100644 --- a/packages/effect/test/Schema/SchemaAST/Union.test.ts +++ b/packages/effect/test/Schema/SchemaAST/Union.test.ts @@ -1,32 +1,32 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("AST.Union", () => { it("flatten should un-nest union members", () => { const asts = AST.flatten([S.Union(S.Literal("a", "b"), S.Literal("c", "d")).ast]) - expect(asts.length).toBe(4) + strictEqual(asts.length, 4) }) it("unify should remove never from members", () => { - expect(AST.Union.unify([AST.neverKeyword, AST.neverKeyword])).toEqual( - AST.neverKeyword - ) - expect(AST.Union.unify([AST.neverKeyword, AST.stringKeyword])).toEqual(AST.stringKeyword) - expect(AST.Union.unify([AST.stringKeyword, AST.neverKeyword])).toEqual(AST.stringKeyword) - expect( + strictEqual(AST.Union.unify([AST.neverKeyword, AST.neverKeyword]), AST.neverKeyword) + strictEqual(AST.Union.unify([AST.neverKeyword, AST.stringKeyword]), AST.stringKeyword) + strictEqual(AST.Union.unify([AST.stringKeyword, AST.neverKeyword]), AST.stringKeyword) + deepStrictEqual( AST.Union.unify([ AST.neverKeyword, AST.stringKeyword, AST.neverKeyword, AST.numberKeyword - ]) - ).toEqual(AST.Union.unify([AST.stringKeyword, AST.numberKeyword])) + ]), + AST.Union.unify([AST.stringKeyword, AST.numberKeyword]) + ) }) describe("toString", () => { it("string | number", () => { - expect(String(S.Union(S.String, S.Number))).toEqual("string | number") + strictEqual(String(S.Union(S.String, S.Number)), "string | number") }) it("should support suspended schemas", () => { @@ -42,7 +42,7 @@ describe("AST.Union", () => { }) ) ) - expect(String(schema)).toStrictEqual("") + strictEqual(String(schema), "") }) it("descriptions of nested unions should be preserved", () => { @@ -50,12 +50,12 @@ describe("AST.Union", () => { const nested1 = u.annotations({ identifier: "nested1" }) const nested2 = u.annotations({ identifier: "nested2" }) - expect(String(u)).toStrictEqual("string | number") - expect(String(S.Union(nested1, nested1))).toStrictEqual("nested1 | nested1") - expect(String(S.Union(nested1, S.String))).toStrictEqual("nested1 | string") - expect(String(S.Union(nested1, u))).toStrictEqual("nested1 | string | number") - expect(String(S.Union(nested1, nested2))).toStrictEqual("nested1 | nested2") - expect(String(S.Union(nested1, nested2, S.String))).toStrictEqual("nested1 | nested2 | string") + strictEqual(String(u), "string | number") + strictEqual(String(S.Union(nested1, nested1)), "nested1 | nested1") + strictEqual(String(S.Union(nested1, S.String)), "nested1 | string") + strictEqual(String(S.Union(nested1, u)), "nested1 | string | number") + strictEqual(String(S.Union(nested1, nested2)), "nested1 | nested2") + strictEqual(String(S.Union(nested1, nested2, S.String)), "nested1 | nested2 | string") }) }) }) diff --git a/packages/effect/test/Schema/SchemaAST/annotations.test.ts b/packages/effect/test/Schema/SchemaAST/annotations.test.ts index 6506f24bbef..6ede2cfdaf0 100644 --- a/packages/effect/test/Schema/SchemaAST/annotations.test.ts +++ b/packages/effect/test/Schema/SchemaAST/annotations.test.ts @@ -1,19 +1,22 @@ import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { assertTrue, deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("annotations", () => { it("should add annotations", () => { const symA = Symbol.for("a") const ast = AST.annotations(AST.stringKeyword, { [symA]: "A" }) - expect(ast instanceof AST.StringKeyword).toBe(true) - expect(ast).toStrictEqual( + assertTrue(ast instanceof AST.StringKeyword) + deepStrictEqual( + ast, new AST.StringKeyword({ [AST.TitleAnnotationId]: "string", [AST.DescriptionAnnotationId]: "a string", [symA]: "A" }) ) - expect(AST.stringKeyword).toStrictEqual( + deepStrictEqual( + AST.stringKeyword, new AST.StringKeyword({ [AST.TitleAnnotationId]: "string", [AST.DescriptionAnnotationId]: "a string" diff --git a/packages/effect/test/Schema/SchemaAST/encodedAST.test.ts b/packages/effect/test/Schema/SchemaAST/encodedAST.test.ts index c1d416250aa..f79930746b5 100644 --- a/packages/effect/test/Schema/SchemaAST/encodedAST.test.ts +++ b/packages/effect/test/Schema/SchemaAST/encodedAST.test.ts @@ -1,73 +1,74 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("encodedAST", () => { it("refinements", () => { const ast = S.String.pipe(S.minLength(2)).ast const encodedAST = AST.encodedAST(ast) - expect(encodedAST).toBe(S.String.ast) + strictEqual(encodedAST, S.String.ast) }) describe(`should return the same reference if the AST doesn't represent a transformation`, () => { it("declaration (true)", () => { const schema = S.OptionFromSelf(S.String) - expect(AST.encodedAST(schema.ast) === schema.ast).toBe(true) + assertTrue(AST.encodedAST(schema.ast) === schema.ast) }) it("declaration (false)", () => { const schema = S.OptionFromSelf(S.NumberFromString) - expect(AST.encodedAST(schema.ast) === schema.ast).toBe(false) + assertFalse(AST.encodedAST(schema.ast) === schema.ast) }) it("tuple (true)", () => { const schema = S.Tuple(S.String, S.Number) - expect(AST.encodedAST(schema.ast) === schema.ast).toBe(true) + assertTrue(AST.encodedAST(schema.ast) === schema.ast) }) it("tuple (false)", () => { const schema = S.Tuple(S.String, S.NumberFromString) - expect(AST.encodedAST(schema.ast) === schema.ast).toBe(false) + assertFalse(AST.encodedAST(schema.ast) === schema.ast) }) it("array (true)", () => { const schema = S.Array(S.Number) - expect(AST.encodedAST(schema.ast) === schema.ast).toBe(true) + assertTrue(AST.encodedAST(schema.ast) === schema.ast) }) it("array (false)", () => { const schema = S.Array(S.NumberFromString) - expect(AST.encodedAST(schema.ast) === schema.ast).toBe(false) + assertFalse(AST.encodedAST(schema.ast) === schema.ast) }) it("union (true)", () => { const schema = S.Union(S.String, S.Number) - expect(AST.encodedAST(schema.ast) === schema.ast).toBe(true) + assertTrue(AST.encodedAST(schema.ast) === schema.ast) }) it("union (false)", () => { const schema = S.Union(S.String, S.NumberFromString) - expect(AST.encodedAST(schema.ast) === schema.ast).toBe(false) + assertFalse(AST.encodedAST(schema.ast) === schema.ast) }) it("struct (true)", () => { const schema = S.Struct({ a: S.String, b: S.Number }) - expect(AST.encodedAST(schema.ast) === schema.ast).toBe(true) + assertTrue(AST.encodedAST(schema.ast) === schema.ast) }) it("struct (false)", () => { const schema = S.Struct({ a: S.String, b: S.NumberFromString }) - expect(AST.encodedAST(schema.ast) === schema.ast).toBe(false) + assertFalse(AST.encodedAST(schema.ast) === schema.ast) }) it("record (true)", () => { const schema = S.Record({ key: S.String, value: S.Number }) - expect(AST.encodedAST(schema.ast) === schema.ast).toBe(true) + assertTrue(AST.encodedAST(schema.ast) === schema.ast) }) it("record (false)", () => { const schema = S.Record({ key: S.String, value: S.NumberFromString }) - expect(AST.encodedAST(schema.ast) === schema.ast).toBe(false) + assertFalse(AST.encodedAST(schema.ast) === schema.ast) }) }) }) diff --git a/packages/effect/test/Schema/SchemaAST/encodedBoundAST.test.ts b/packages/effect/test/Schema/SchemaAST/encodedBoundAST.test.ts index 630a3463e75..a440babf9a4 100644 --- a/packages/effect/test/Schema/SchemaAST/encodedBoundAST.test.ts +++ b/packages/effect/test/Schema/SchemaAST/encodedBoundAST.test.ts @@ -1,73 +1,74 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue } from "effect/test/util" +import { describe, it } from "vitest" describe("encodedBoundAST", () => { it("refinements", () => { const ast = S.String.pipe(S.minLength(2)).ast const encodedAST = AST.encodedBoundAST(ast) - expect(encodedAST === ast).toBe(true) + assertTrue(encodedAST === ast) }) describe(`should return the same reference if the AST doesn't represent a transformation`, () => { it("declaration (true)", () => { const schema = S.OptionFromSelf(S.String) - expect(AST.encodedBoundAST(schema.ast) === schema.ast).toBe(true) + assertTrue(AST.encodedBoundAST(schema.ast) === schema.ast) }) it("declaration (false)", () => { const schema = S.OptionFromSelf(S.NumberFromString) - expect(AST.encodedBoundAST(schema.ast) === schema.ast).toBe(false) + assertFalse(AST.encodedBoundAST(schema.ast) === schema.ast) }) it("tuple (true)", () => { const schema = S.Tuple(S.String, S.Number) - expect(AST.encodedBoundAST(schema.ast) === schema.ast).toBe(true) + assertTrue(AST.encodedBoundAST(schema.ast) === schema.ast) }) it("tuple (false)", () => { const schema = S.Tuple(S.String, S.NumberFromString) - expect(AST.encodedBoundAST(schema.ast) === schema.ast).toBe(false) + assertFalse(AST.encodedBoundAST(schema.ast) === schema.ast) }) it("array (true)", () => { const schema = S.Array(S.Number) - expect(AST.encodedBoundAST(schema.ast) === schema.ast).toBe(true) + assertTrue(AST.encodedBoundAST(schema.ast) === schema.ast) }) it("array (false)", () => { const schema = S.Array(S.NumberFromString) - expect(AST.encodedBoundAST(schema.ast) === schema.ast).toBe(false) + assertFalse(AST.encodedBoundAST(schema.ast) === schema.ast) }) it("union (true)", () => { const schema = S.Union(S.String, S.Number) - expect(AST.encodedBoundAST(schema.ast) === schema.ast).toBe(true) + assertTrue(AST.encodedBoundAST(schema.ast) === schema.ast) }) it("union (false)", () => { const schema = S.Union(S.String, S.NumberFromString) - expect(AST.encodedBoundAST(schema.ast) === schema.ast).toBe(false) + assertFalse(AST.encodedBoundAST(schema.ast) === schema.ast) }) it("struct (true)", () => { const schema = S.Struct({ a: S.String, b: S.Number }) - expect(AST.encodedBoundAST(schema.ast) === schema.ast).toBe(true) + assertTrue(AST.encodedBoundAST(schema.ast) === schema.ast) }) it("struct (false)", () => { const schema = S.Struct({ a: S.String, b: S.NumberFromString }) - expect(AST.encodedBoundAST(schema.ast) === schema.ast).toBe(false) + assertFalse(AST.encodedBoundAST(schema.ast) === schema.ast) }) it("record (true)", () => { const schema = S.Record({ key: S.String, value: S.Number }) - expect(AST.encodedBoundAST(schema.ast) === schema.ast).toBe(true) + assertTrue(AST.encodedBoundAST(schema.ast) === schema.ast) }) it("record (false)", () => { const schema = S.Record({ key: S.String, value: S.NumberFromString }) - expect(AST.encodedBoundAST(schema.ast) === schema.ast).toBe(false) + assertFalse(AST.encodedBoundAST(schema.ast) === schema.ast) }) }) }) diff --git a/packages/effect/test/Schema/SchemaAST/equals.test.ts b/packages/effect/test/Schema/SchemaAST/equals.test.ts index 5145b0fb078..c4be28781b0 100644 --- a/packages/effect/test/Schema/SchemaAST/equals.test.ts +++ b/packages/effect/test/Schema/SchemaAST/equals.test.ts @@ -1,14 +1,15 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue } from "effect/test/util" +import { describe, it } from "vitest" describe("equals", () => { describe("TemplateLiteral", () => { it(`("a" | "b") + string + ("d" | "e")`, () => { const schema1 = S.TemplateLiteral(S.Literal("a", "b"), S.String, S.Literal("d", "e")) const schema2 = S.TemplateLiteral(S.Literal("a", "b"), S.String, S.Literal("d", "f")) - expect(AST.equals(schema1.ast, schema1.ast)).toBe(true) - expect(AST.equals(schema1.ast, schema2.ast)).toBe(false) + assertTrue(AST.equals(schema1.ast, schema1.ast)) + assertFalse(AST.equals(schema1.ast, schema2.ast)) }) }) }) diff --git a/packages/effect/test/Schema/SchemaAST/getPropertySignatures.test.ts b/packages/effect/test/Schema/SchemaAST/getPropertySignatures.test.ts index 239b5a4996a..af8bfb3af25 100644 --- a/packages/effect/test/Schema/SchemaAST/getPropertySignatures.test.ts +++ b/packages/effect/test/Schema/SchemaAST/getPropertySignatures.test.ts @@ -1,11 +1,12 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("getPropertySignatures", () => { it("struct", () => { const schema = S.Struct({ a: S.String, b: S.Number }) - expect(AST.getPropertySignatures(schema.ast)).toEqual([ + deepStrictEqual(AST.getPropertySignatures(schema.ast), [ new AST.PropertySignature("a", S.String.ast, false, true), new AST.PropertySignature("b", S.Number.ast, false, true) ]) @@ -13,7 +14,7 @@ describe("getPropertySignatures", () => { it("union", () => { const schema = S.Union(S.Struct({ _tag: S.Literal("A") }), S.Struct({ _tag: S.Literal("B") })) - expect(AST.getPropertySignatures(schema.ast)).toEqual([ + deepStrictEqual(AST.getPropertySignatures(schema.ast), [ new AST.PropertySignature("_tag", S.Literal("A", "B").ast, false, true) ]) }) @@ -21,7 +22,7 @@ describe("getPropertySignatures", () => { it("Class", () => { class A extends S.Class("A")({ a: S.String, b: S.Number }) {} const schema = A.pipe(S.typeSchema) - expect(AST.getPropertySignatures(schema.ast)).toEqual([ + deepStrictEqual(AST.getPropertySignatures(schema.ast), [ new AST.PropertySignature("a", S.String.ast, false, true), new AST.PropertySignature("b", S.Number.ast, false, true) ]) diff --git a/packages/effect/test/Schema/SchemaAST/guards.test.ts b/packages/effect/test/Schema/SchemaAST/guards.test.ts index f78f351447f..c4b7c87fe86 100644 --- a/packages/effect/test/Schema/SchemaAST/guards.test.ts +++ b/packages/effect/test/Schema/SchemaAST/guards.test.ts @@ -1,16 +1,17 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue } from "effect/test/util" +import { describe, it } from "vitest" describe("guards", () => { it("isDeclaration", () => { - expect(AST.isDeclaration(S.OptionFromSelf(S.Number).ast)).toEqual(true) - expect(AST.isDeclaration(S.Number.ast)).toEqual(false) + assertTrue(AST.isDeclaration(S.OptionFromSelf(S.Number).ast)) + assertFalse(AST.isDeclaration(S.Number.ast)) }) it("isTemplateLiteral", () => { - expect(AST.isTemplateLiteral(S.TemplateLiteral(S.Literal("a"), S.String).ast)).toEqual(true) - expect(AST.isTemplateLiteral(S.Number.ast)).toEqual(false) + assertTrue(AST.isTemplateLiteral(S.TemplateLiteral(S.Literal("a"), S.String).ast)) + assertFalse(AST.isTemplateLiteral(S.Number.ast)) }) it("isSuspend", () => { @@ -18,33 +19,33 @@ describe("guards", () => { const schema: S.Schema = S.suspend( // intended outer suspend () => S.Tuple(S.Number, S.Union(schema, S.Literal(null))) ) - expect(AST.isSuspend(schema.ast)).toEqual(true) - expect(AST.isSuspend(S.Number.ast)).toEqual(false) + assertTrue(AST.isSuspend(schema.ast)) + assertFalse(AST.isSuspend(S.Number.ast)) }) it("isTransform", () => { - expect(AST.isTransformation(S.Trim.ast)).toEqual(true) - expect(AST.isTransformation(S.Number.ast)).toEqual(false) + assertTrue(AST.isTransformation(S.Trim.ast)) + assertFalse(AST.isTransformation(S.Number.ast)) }) it("isUndefinedKeyword", () => { - expect(AST.isUndefinedKeyword(S.Undefined.ast)).toEqual(true) - expect(AST.isUndefinedKeyword(S.Number.ast)).toEqual(false) + assertTrue(AST.isUndefinedKeyword(S.Undefined.ast)) + assertFalse(AST.isUndefinedKeyword(S.Number.ast)) }) it("isVoidKeyword", () => { - expect(AST.isVoidKeyword(S.Void.ast)).toEqual(true) - expect(AST.isVoidKeyword(S.Unknown.ast)).toEqual(false) + assertTrue(AST.isVoidKeyword(S.Void.ast)) + assertFalse(AST.isVoidKeyword(S.Unknown.ast)) }) it("isSymbolKeyword", () => { - expect(AST.isSymbolKeyword(S.SymbolFromSelf.ast)).toEqual(true) - expect(AST.isSymbolKeyword(S.Unknown.ast)).toEqual(false) + assertTrue(AST.isSymbolKeyword(S.SymbolFromSelf.ast)) + assertFalse(AST.isSymbolKeyword(S.Unknown.ast)) }) it("isObjectKeyword", () => { - expect(AST.isObjectKeyword(S.Object.ast)).toEqual(true) - expect(AST.isObjectKeyword(S.Unknown.ast)).toEqual(false) + assertTrue(AST.isObjectKeyword(S.Object.ast)) + assertFalse(AST.isObjectKeyword(S.Unknown.ast)) }) it("isEnums", () => { @@ -52,53 +53,48 @@ describe("guards", () => { Apple, Banana } - expect(AST.isEnums(S.Enums(Fruits).ast)).toEqual(true) - expect(AST.isEnums(S.Unknown.ast)).toEqual(false) + assertTrue(AST.isEnums(S.Enums(Fruits).ast)) + assertFalse(AST.isEnums(S.Unknown.ast)) }) it("isNeverKeyword", () => { - expect(AST.isNeverKeyword(S.Never.ast)).toEqual(true) - expect(AST.isNeverKeyword(S.Unknown.ast)).toEqual(false) + assertTrue(AST.isNeverKeyword(S.Never.ast)) + assertFalse(AST.isNeverKeyword(S.Unknown.ast)) }) it("isUniqueSymbol", () => { - expect(AST.isUniqueSymbol(S.UniqueSymbolFromSelf(Symbol.for("effect/Schema/test/a")).ast)).toEqual( - true - ) - expect(AST.isUniqueSymbol(S.Unknown.ast)).toEqual(false) + assertTrue(AST.isUniqueSymbol(S.UniqueSymbolFromSelf(Symbol.for("effect/Schema/test/a")).ast)) + assertFalse(AST.isUniqueSymbol(S.Unknown.ast)) }) it("isUnknownKeyword", () => { - expect(AST.isUnknownKeyword(S.Unknown.ast)).toEqual(true) - expect(AST.isUnknownKeyword(S.Any.ast)).toEqual(false) + assertTrue(AST.isUnknownKeyword(S.Unknown.ast)) + assertFalse(AST.isUnknownKeyword(S.Any.ast)) }) it("isAnyKeyword", () => { - expect(AST.isAnyKeyword(S.Any.ast)).toEqual(true) - expect(AST.isAnyKeyword(S.Unknown.ast)).toEqual(false) + assertTrue(AST.isAnyKeyword(S.Any.ast)) + assertFalse(AST.isAnyKeyword(S.Unknown.ast)) }) it("isBooleanKeyword", () => { - expect(AST.isBooleanKeyword(S.Boolean.ast)).toEqual(true) - expect(AST.isBooleanKeyword(S.Unknown.ast)).toEqual(false) + assertTrue(AST.isBooleanKeyword(S.Boolean.ast)) + assertFalse(AST.isBooleanKeyword(S.Unknown.ast)) }) it("isBigIntKeyword", () => { - expect(AST.isBigIntKeyword(S.BigIntFromSelf.ast)).toEqual(true) - expect(AST.isBigIntKeyword(S.Unknown.ast)).toEqual(false) + assertTrue(AST.isBigIntKeyword(S.BigIntFromSelf.ast)) + assertFalse(AST.isBigIntKeyword(S.Unknown.ast)) }) it("isParameter", () => { - expect(AST.isParameter(AST.stringKeyword)).toEqual(true) - expect(AST.isParameter(AST.symbolKeyword)).toEqual(true) - expect(AST.isParameter(S.TemplateLiteral(S.String, S.Literal("-"), S.String).ast)) - .toEqual(true) - expect(AST.isParameter(S.String.pipe(S.minLength(2)).ast)).toEqual(true) - expect(AST.isParameter(S.TemplateLiteral(S.Literal("a", "b"), S.Literal("c")).ast)).toEqual( - true - ) - expect(AST.isParameter(S.Number.pipe(S.int()).ast)).toEqual(false) - expect(AST.isParameter(S.NumberFromString.ast)).toEqual(false) - expect(AST.isParameter(S.NumberFromString.pipe(S.int()).ast)).toEqual(false) + assertTrue(AST.isParameter(AST.stringKeyword)) + assertTrue(AST.isParameter(AST.symbolKeyword)) + assertTrue(AST.isParameter(S.TemplateLiteral(S.String, S.Literal("-"), S.String).ast)) + assertTrue(AST.isParameter(S.String.pipe(S.minLength(2)).ast)) + assertTrue(AST.isParameter(S.TemplateLiteral(S.Literal("a", "b"), S.Literal("c")).ast)) + assertFalse(AST.isParameter(S.Number.pipe(S.int()).ast)) + assertFalse(AST.isParameter(S.NumberFromString.ast)) + assertFalse(AST.isParameter(S.NumberFromString.pipe(S.int()).ast)) }) }) diff --git a/packages/effect/test/Schema/SchemaAST/mutable.test.ts b/packages/effect/test/Schema/SchemaAST/mutable.test.ts index 43c14e0d4e4..8ee5bf0a789 100644 --- a/packages/effect/test/Schema/SchemaAST/mutable.test.ts +++ b/packages/effect/test/Schema/SchemaAST/mutable.test.ts @@ -1,12 +1,13 @@ import { identity } from "effect" import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { strictEqual } from "effect/test/util" +import { describe, it } from "vitest" const expectSameReference = (schema: S.Schema.Any) => { const mutable = AST.mutable(AST.isSuspend(schema.ast) ? schema.ast.f() : schema.ast) const mutable2 = AST.mutable(mutable) - expect(mutable === mutable2).toBe(true) + strictEqual(mutable, mutable2) } describe("mutable", () => { diff --git a/packages/effect/test/Schema/SchemaAST/partial.test.ts b/packages/effect/test/Schema/SchemaAST/partial.test.ts index 9f9c8b249ef..61c6a23e889 100644 --- a/packages/effect/test/Schema/SchemaAST/partial.test.ts +++ b/packages/effect/test/Schema/SchemaAST/partial.test.ts @@ -1,6 +1,7 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("partial", () => { describe("{ exact: false }", () => { @@ -9,7 +10,7 @@ describe("partial", () => { // type B = Partial const schema = S.partial(S.Struct({ a: S.String })) const expected = S.Struct({ a: S.optional(S.String) }) - expect(schema.ast).toStrictEqual(expected.ast) + deepStrictEqual(schema.ast, expected.ast) }) describe("tuple", () => { @@ -21,7 +22,8 @@ describe("partial", () => { [], true ) - expect(AST.partial(tuple)).toEqual( + deepStrictEqual( + AST.partial(tuple), new AST.TupleType([new AST.OptionalType(AST.orUndefined(AST.stringKeyword), true)], [], true) ) }) @@ -34,7 +36,8 @@ describe("partial", () => { [new AST.Type(AST.numberKeyword)], true ) - expect(AST.partial(tuple)).toEqual( + deepStrictEqual( + AST.partial(tuple), new AST.TupleType( [new AST.OptionalType(AST.orUndefined(AST.stringKeyword), true)], [new AST.Type(AST.orUndefined(AST.numberKeyword))], @@ -51,7 +54,8 @@ describe("partial", () => { [new AST.Type(AST.numberKeyword), new AST.Type(AST.booleanKeyword)], true ) - expect(AST.partial(tuple)).toEqual( + deepStrictEqual( + AST.partial(tuple), new AST.TupleType( [new AST.OptionalType(AST.orUndefined(AST.stringKeyword), true)], [ @@ -70,7 +74,7 @@ describe("partial", () => { // type B = Partial const schema = S.partialWith(S.Struct({ a: S.String }), { exact: true }) const expected = S.Struct({ a: S.optionalWith(S.String, { exact: true }) }) - expect(schema.ast).toStrictEqual(expected.ast) + deepStrictEqual(schema.ast, expected.ast) }) describe("tuple", () => { @@ -82,7 +86,8 @@ describe("partial", () => { [], true ) - expect(AST.partial(tuple, { exact: true })).toEqual( + deepStrictEqual( + AST.partial(tuple, { exact: true }), new AST.TupleType([new AST.OptionalType(AST.stringKeyword, true)], [], true) ) }) @@ -95,7 +100,8 @@ describe("partial", () => { [new AST.Type(AST.numberKeyword)], true ) - expect(AST.partial(tuple, { exact: true })).toEqual( + deepStrictEqual( + AST.partial(tuple, { exact: true }), new AST.TupleType( [new AST.OptionalType(AST.stringKeyword, true)], [new AST.Type(AST.orUndefined(AST.numberKeyword))], @@ -112,7 +118,8 @@ describe("partial", () => { [new AST.Type(AST.numberKeyword), new AST.Type(AST.booleanKeyword)], true ) - expect(AST.partial(tuple, { exact: true })).toEqual( + deepStrictEqual( + AST.partial(tuple, { exact: true }), new AST.TupleType( [new AST.OptionalType(AST.stringKeyword, true)], [ diff --git a/packages/effect/test/Schema/SchemaAST/pick.test.ts b/packages/effect/test/Schema/SchemaAST/pick.test.ts index 7ff262af088..7c764e3e628 100644 --- a/packages/effect/test/Schema/SchemaAST/pick.test.ts +++ b/packages/effect/test/Schema/SchemaAST/pick.test.ts @@ -1,18 +1,19 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { deepStrictEqual, doesNotThrow } from "effect/test/util" +import { describe, it } from "vitest" describe("pick", () => { it("refinement", async () => { const schema = S.Struct({ a: S.NumberFromString, b: S.Number }).pipe(S.filter(() => true)) const ast = schema.pipe(S.pick("a")).ast - expect(ast).toStrictEqual(S.Struct({ a: S.NumberFromString }).ast) + deepStrictEqual(ast, S.Struct({ a: S.NumberFromString }).ast) }) it("struct", async () => { const schema = S.Struct({ a: S.NumberFromString, b: S.Number }) const ast = schema.pipe(S.pick("a")).ast - expect(ast).toStrictEqual(S.Struct({ a: S.NumberFromString }).ast) + deepStrictEqual(ast, S.Struct({ a: S.NumberFromString }).ast) }) it("struct + record", async () => { @@ -21,7 +22,7 @@ describe("pick", () => { S.Record({ key: S.String, value: S.Union(S.String, S.Number) }) ) const ast = schema.pipe(S.pick("a", "c")).ast - expect(ast).toStrictEqual(S.Struct({ a: S.NumberFromString, c: S.Union(S.String, S.Number) }).ast) + deepStrictEqual(ast, S.Struct({ a: S.NumberFromString, c: S.Union(S.String, S.Number) }).ast) }) it("union", async () => { @@ -30,7 +31,7 @@ describe("pick", () => { const schema = S.Union(A, B) const pick = schema.pipe(S.pick("a")) const ast = pick.ast - expect(ast).toStrictEqual(S.Struct({ a: S.Union(S.String, S.Number) }).ast) + deepStrictEqual(ast, S.Struct({ a: S.Union(S.String, S.Number) }).ast) }) describe("transformation", () => { @@ -40,7 +41,7 @@ describe("pick", () => { S.Struct({ a: S.Number, b: S.Number }) ) const ast = schema.pipe(S.pick("a")).ast - expect(ast).toStrictEqual(S.compose(S.Struct({ a: S.NumberFromString }), S.Struct({ a: S.Number })).ast) + deepStrictEqual(ast, S.compose(S.Struct({ a: S.NumberFromString }), S.Struct({ a: S.Number })).ast) }) describe("TypeLiteralTransformation", () => { @@ -48,20 +49,20 @@ describe("pick", () => { const schema = S.Struct({ a: S.optionalWith(S.NumberFromString, { default: () => 0 }), b: S.Number }) const pick = schema.pipe(S.pick("a")) const ast = pick.ast as AST.Transformation - expect(ast.from).toStrictEqual(S.Struct({ a: S.optional(S.NumberFromString) }).ast) - expect(ast.to).toStrictEqual(S.Struct({ a: S.Number }).ast) - expect(ast.transformation).toStrictEqual((schema.ast as AST.Transformation).transformation) - expect(() => pick.pipe(S.extend(S.Struct({ c: S.Boolean })))).not.Throw() + deepStrictEqual(ast.from, S.Struct({ a: S.optional(S.NumberFromString) }).ast) + deepStrictEqual(ast.to, S.Struct({ a: S.Number }).ast) + deepStrictEqual(ast.transformation, (schema.ast as AST.Transformation).transformation) + doesNotThrow(() => pick.pipe(S.extend(S.Struct({ c: S.Boolean })))) }) it("picking keys without associated PropertySignatureTransformations", async () => { const schema = S.Struct({ a: S.optionalWith(S.NumberFromString, { default: () => 0 }), b: S.NumberFromString }) const pick = schema.pipe(S.pick("b")) const ast = pick.ast as AST.TypeLiteral - expect(ast.propertySignatures).toStrictEqual([ + deepStrictEqual(ast.propertySignatures, [ new AST.PropertySignature("b", S.NumberFromString.ast, false, true) ]) - expect(() => pick.pipe(S.extend(S.Struct({ c: S.Boolean })))).not.Throw() + doesNotThrow(() => pick.pipe(S.extend(S.Struct({ c: S.Boolean })))) }) }) @@ -70,7 +71,7 @@ describe("pick", () => { class A extends S.Class("A")({ a: S.NumberFromString, b: S.Number }) {} const schema = A const ast = schema.pipe(S.pick("a")).ast - expect(ast).toStrictEqual(S.Struct({ a: S.NumberFromString }).ast) + deepStrictEqual(ast, S.Struct({ a: S.NumberFromString }).ast) }) it("a union of Classes", async () => { @@ -79,7 +80,7 @@ describe("pick", () => { const schema = S.Union(A, B) const pick = schema.pipe(S.pick("a")) const ast = pick.ast - expect(ast).toStrictEqual(S.Struct({ a: S.Union(S.Number, S.String) }).ast) + deepStrictEqual(ast, S.Struct({ a: S.Union(S.Number, S.String) }).ast) }) }) }) diff --git a/packages/effect/test/Schema/SchemaAST/record.test.ts b/packages/effect/test/Schema/SchemaAST/record.test.ts index 3325649518d..f4693fb8f9f 100644 --- a/packages/effect/test/Schema/SchemaAST/record.test.ts +++ b/packages/effect/test/Schema/SchemaAST/record.test.ts @@ -1,24 +1,27 @@ import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { deepStrictEqual, throws } from "effect/test/util" +import { describe, it } from "vitest" describe("record", () => { it("should throw on unsupported keys", () => { - expect(() => AST.record(AST.undefinedKeyword, AST.numberKeyword)).toThrow( + throws( + () => AST.record(AST.undefinedKeyword, AST.numberKeyword), new Error(`Unsupported key schema schema (UndefinedKeyword): undefined`) ) }) it("should throw on unsupported literals", () => { - expect(() => AST.record(new AST.Literal(true), AST.numberKeyword)).toThrow( + throws( + () => AST.record(new AST.Literal(true), AST.numberKeyword), new Error(`Unsupported literal details: literal value: true`) ) }) it("should support numeric literals as keys", () => { - expect(AST.record(new AST.Literal(1), AST.numberKeyword).propertySignatures).toEqual( - [new AST.PropertySignature(1, AST.numberKeyword, false, true)] - ) + deepStrictEqual(AST.record(new AST.Literal(1), AST.numberKeyword).propertySignatures, [ + new AST.PropertySignature(1, AST.numberKeyword, false, true) + ]) }) }) diff --git a/packages/effect/test/Schema/SchemaAST/suspend.test.ts b/packages/effect/test/Schema/SchemaAST/suspend.test.ts index 8116a16736b..f3804084d5c 100644 --- a/packages/effect/test/Schema/SchemaAST/suspend.test.ts +++ b/packages/effect/test/Schema/SchemaAST/suspend.test.ts @@ -1,7 +1,8 @@ import * as S from "effect/Schema" import type * as AST from "effect/SchemaAST" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { assertTrue, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("AST.Suspend", () => { it("should memoize the thunk", async () => { @@ -19,7 +20,7 @@ describe("AST.Suspend", () => { }) await Util.assertions.decoding.succeed(schema, { a: "a1", as: [] }) await Util.assertions.decoding.succeed(schema, { a: "a1", as: [{ a: "a2", as: [] }] }) - expect(log).toEqual(1) + strictEqual(log, 1) }) it("should memoize the AST", () => { @@ -28,6 +29,6 @@ describe("AST.Suspend", () => { () => S.Tuple(S.Number, S.Union(schema, S.Literal(null))) ) const ast = schema.ast as AST.Suspend - expect(ast.f() === ast.f()).toBe(true) + assertTrue(ast.f() === ast.f()) }) }) diff --git a/packages/effect/test/Schema/SchemaAST/typeAST.test.ts b/packages/effect/test/Schema/SchemaAST/typeAST.test.ts index 937ba1879fd..e924be79b88 100644 --- a/packages/effect/test/Schema/SchemaAST/typeAST.test.ts +++ b/packages/effect/test/Schema/SchemaAST/typeAST.test.ts @@ -1,77 +1,78 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue } from "effect/test/util" +import { describe, it } from "vitest" describe("typeAST", () => { describe(`should return the same reference if the AST doesn't represent a transformation`, () => { it("declaration (true)", () => { const schema = S.OptionFromSelf(S.String) - expect(AST.typeAST(schema.ast) === schema.ast).toBe(true) + assertTrue(AST.typeAST(schema.ast) === schema.ast) }) it("declaration (false)", () => { const schema = S.OptionFromSelf(S.NumberFromString) - expect(AST.typeAST(schema.ast) === schema.ast).toBe(false) + assertFalse(AST.typeAST(schema.ast) === schema.ast) }) it("tuple (true)", () => { const schema = S.Tuple(S.String, S.Number) - expect(AST.typeAST(schema.ast) === schema.ast).toBe(true) + assertTrue(AST.typeAST(schema.ast) === schema.ast) }) it("tuple (false)", () => { const schema = S.Tuple(S.String, S.NumberFromString) - expect(AST.typeAST(schema.ast) === schema.ast).toBe(false) + assertFalse(AST.typeAST(schema.ast) === schema.ast) }) it("array (true)", () => { const schema = S.Array(S.Number) - expect(AST.typeAST(schema.ast) === schema.ast).toBe(true) + assertTrue(AST.typeAST(schema.ast) === schema.ast) }) it("array (false)", () => { const schema = S.Array(S.NumberFromString) - expect(AST.typeAST(schema.ast) === schema.ast).toBe(false) + assertFalse(AST.typeAST(schema.ast) === schema.ast) }) it("union (true)", () => { const schema = S.Union(S.String, S.Number) - expect(AST.typeAST(schema.ast) === schema.ast).toBe(true) + assertTrue(AST.typeAST(schema.ast) === schema.ast) }) it("union (false)", () => { const schema = S.Union(S.String, S.NumberFromString) - expect(AST.typeAST(schema.ast) === schema.ast).toBe(false) + assertFalse(AST.typeAST(schema.ast) === schema.ast) }) it("struct (true)", () => { const schema = S.Struct({ a: S.String, b: S.Number }) - expect(AST.typeAST(schema.ast) === schema.ast).toBe(true) + assertTrue(AST.typeAST(schema.ast) === schema.ast) }) it("struct (false)", () => { const schema = S.Struct({ a: S.String, b: S.NumberFromString }) - expect(AST.typeAST(schema.ast) === schema.ast).toBe(false) + assertFalse(AST.typeAST(schema.ast) === schema.ast) }) it("record (true)", () => { const schema = S.Record({ key: S.String, value: S.Number }) - expect(AST.typeAST(schema.ast) === schema.ast).toBe(true) + assertTrue(AST.typeAST(schema.ast) === schema.ast) }) it("record (false)", () => { const schema = S.Record({ key: S.String, value: S.NumberFromString }) - expect(AST.typeAST(schema.ast) === schema.ast).toBe(false) + assertFalse(AST.typeAST(schema.ast) === schema.ast) }) it("refinement (true)", () => { const schema = S.Number.pipe(S.filter((n) => n > 0)) - expect(AST.typeAST(schema.ast) === schema.ast).toBe(true) + assertTrue(AST.typeAST(schema.ast) === schema.ast) }) it("refinement (false)", () => { const schema = S.NumberFromString.pipe(S.filter((n) => n > 0)) - expect(AST.typeAST(schema.ast) === schema.ast).toBe(false) + assertFalse(AST.typeAST(schema.ast) === schema.ast) }) }) }) diff --git a/packages/effect/test/Schema/SchemaAST/unify.test.ts b/packages/effect/test/Schema/SchemaAST/unify.test.ts index 65a5d1a0514..4afadc11f3c 100644 --- a/packages/effect/test/Schema/SchemaAST/unify.test.ts +++ b/packages/effect/test/Schema/SchemaAST/unify.test.ts @@ -1,10 +1,11 @@ import * as S from "effect/Schema" import * as AST from "effect/SchemaAST" -import { describe, expect, it } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, it } from "vitest" const expectUnify = (input: Array, expected: Array) => { const actual = AST.unify(input.map((schema) => schema.ast)) - expect(actual).toStrictEqual(expected.map((e) => e.ast)) + deepStrictEqual(actual, expected.map((e) => e.ast)) } describe("AST.unify", () => { diff --git a/packages/effect/test/Schema/SchemaInternal.test.ts b/packages/effect/test/Schema/SchemaInternal.test.ts index 612e2e7bd87..6d44ba35325 100644 --- a/packages/effect/test/Schema/SchemaInternal.test.ts +++ b/packages/effect/test/Schema/SchemaInternal.test.ts @@ -1,39 +1,40 @@ import * as util from "effect/internal/schema/util" -import { describe, expect, it } from "vitest" +import { deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("effect/internal/schema/util", () => { it("ownKeys", () => { - expect(util.ownKeys({})).toStrictEqual([]) - expect(util.ownKeys({ a: 1 })).toStrictEqual(["a"]) - expect(util.ownKeys({ a: 1, b: 2 })).toStrictEqual(["a", "b"]) + deepStrictEqual(util.ownKeys({}), []) + deepStrictEqual(util.ownKeys({ a: 1 }), ["a"]) + deepStrictEqual(util.ownKeys({ a: 1, b: 2 }), ["a", "b"]) const a = Symbol.for("effect/Schema/test/a") const b = Symbol.for("effect/Schema/test/b") - expect(util.ownKeys({ [a]: 3, [b]: 4 })).toStrictEqual([a, b]) - expect(util.ownKeys({ a: 1, [a]: 3, b: 2, [b]: 4 })).toStrictEqual(["a", "b", a, b]) + deepStrictEqual(util.ownKeys({ [a]: 3, [b]: 4 }), [a, b]) + deepStrictEqual(util.ownKeys({ a: 1, [a]: 3, b: 2, [b]: 4 }), ["a", "b", a, b]) }) describe("formatUnknown", () => { it("should format symbol property signatures", () => { - expect(util.formatUnknown({ [Symbol.for("a")]: 1 })).toEqual("{Symbol(a):1}") + strictEqual(util.formatUnknown({ [Symbol.for("a")]: 1 }), "{Symbol(a):1}") }) it("should handle unexpected errors", () => { const circular: any = { a: null } circular.a = circular - expect(util.formatUnknown(circular)).toEqual("[object Object]") + strictEqual(util.formatUnknown(circular), "[object Object]") }) it("should detect data types with a custom `toString` implementation", () => { const noToString = { a: 1 } - expect(util.formatUnknown(noToString)).toEqual(`{"a":1}`) + strictEqual(util.formatUnknown(noToString), `{"a":1}`) const ToString = Object.create({ toString() { return "toString custom implementation" } }) - expect(util.formatUnknown(ToString)).toEqual("toString custom implementation") + strictEqual(util.formatUnknown(ToString), "toString custom implementation") // should not detect arrays - expect(util.formatUnknown([1, 2, 3])).toEqual("[1,2,3]") + strictEqual(util.formatUnknown([1, 2, 3]), "[1,2,3]") }) }) }) diff --git a/packages/effect/test/Schema/SchemaTest.ts b/packages/effect/test/Schema/SchemaTest.ts index b4580ef5d9e..f218e00ffcf 100644 --- a/packages/effect/test/Schema/SchemaTest.ts +++ b/packages/effect/test/Schema/SchemaTest.ts @@ -22,7 +22,7 @@ export class AssertConfig extends Context.Tag("AssertConfig") void readonly throws: (fn: () => unknown, message: string) => void - readonly fail: (fmessage: string) => void + readonly fail: (message: string) => void }>() {} // Provides various assertions for Schema testing diff --git a/packages/effect/test/Schema/SchemaUserland.test.ts b/packages/effect/test/Schema/SchemaUserland.test.ts index 7d794638cfe..ae5827b72f8 100644 --- a/packages/effect/test/Schema/SchemaUserland.test.ts +++ b/packages/effect/test/Schema/SchemaUserland.test.ts @@ -3,7 +3,8 @@ */ import { Record, Schema, SchemaAST as AST } from "effect" import * as Util from "effect/test/Schema/TestUtils" -import { describe, expect, it } from "vitest" +import { deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" const structTypeSchema = ( schema: Schema.Struct @@ -30,11 +31,11 @@ describe("SchemaUserland", () => { b: Schema.propertySignature(Schema.NumberFromString), c: Schema.optionalWith(Schema.NumberFromString, { as: "Option" }) })) - expect(schema.fields.a.ast).toStrictEqual(Schema.Number.ast) - expect(schema.fields.b.ast).toStrictEqual(Schema.Number.ast) + deepStrictEqual(schema.fields.a.ast, Schema.Number.ast) + deepStrictEqual(schema.fields.b.ast, Schema.Number.ast) const c = schema.fields.c.ast - expect(c._tag).toStrictEqual("Declaration") - expect((c as AST.Declaration).typeParameters).toStrictEqual([Schema.Number.ast]) + strictEqual(c._tag, "Declaration") + deepStrictEqual((c as AST.Declaration).typeParameters, [Schema.Number.ast]) }) it("detect that a struct does not contain a specific field", async () => { diff --git a/packages/effect/test/Schema/Serializable.test.ts b/packages/effect/test/Schema/Serializable.test.ts index df403bc1e31..31e869d2367 100644 --- a/packages/effect/test/Schema/Serializable.test.ts +++ b/packages/effect/test/Schema/Serializable.test.ts @@ -1,6 +1,7 @@ import { Effect, Exit } from "effect" import * as S from "effect/Schema" -import { assert, describe, test } from "vitest" +import { deepStrictEqual } from "effect/test/util" +import { describe, test } from "vitest" class Person extends S.Class("Person")({ id: S.Number, @@ -25,14 +26,14 @@ class GetPersonById extends S.Class("GetPersonById")({ describe("Serializable", () => { test("serialize", () => { const req = new GetPersonById({ id: 123 }) - assert.deepStrictEqual(Effect.runSync(S.serialize(req)), { + deepStrictEqual(Effect.runSync(S.serialize(req)), { id: 123 }) }) test("deserialize", () => { const req = new GetPersonById({ id: 123 }) - assert.deepStrictEqual( + deepStrictEqual( Effect.runSync(S.deserialize(req, { id: 456 })), @@ -42,7 +43,7 @@ describe("Serializable", () => { test("serializeFailure", () => { const req = new GetPersonById({ id: 123 }) - assert.deepStrictEqual( + deepStrictEqual( Effect.runSync( S.serializeFailure(req, "fail") ), @@ -52,7 +53,7 @@ describe("Serializable", () => { test("serializeSuccess", () => { const req = new GetPersonById({ id: 123 }) - assert.deepStrictEqual( + deepStrictEqual( Effect.runSync( S.serializeSuccess(req, new Person({ id: 123, name: "foo" })) ), @@ -62,13 +63,13 @@ describe("Serializable", () => { test("serializeExit", () => { const req = new GetPersonById({ id: 123 }) - assert.deepStrictEqual( + deepStrictEqual( Effect.runSync( S.serializeExit(req, Exit.succeed(new Person({ id: 123, name: "foo" }))) ), { _tag: "Success", value: { id: 123, name: "foo" } } ) - assert.deepStrictEqual( + deepStrictEqual( Effect.runSync( S.serializeExit(req, Exit.fail("fail")) ), @@ -78,7 +79,7 @@ describe("Serializable", () => { test("deserializeFailure", () => { const req = new GetPersonById({ id: 123 }) - assert.deepStrictEqual( + deepStrictEqual( Effect.runSync( S.deserializeFailure(req, "fail") ), @@ -88,7 +89,7 @@ describe("Serializable", () => { test("deserializeSuccess", () => { const req = new GetPersonById({ id: 123 }) - assert.deepStrictEqual( + deepStrictEqual( Effect.runSync( S.deserializeSuccess(req, { id: 123, name: "foo" }) ), @@ -98,13 +99,13 @@ describe("Serializable", () => { test("deserializeExit", () => { const req = new GetPersonById({ id: 123 }) - assert.deepStrictEqual( + deepStrictEqual( Effect.runSync( S.deserializeExit(req, { _tag: "Success", value: { id: 123, name: "foo" } }) ), Exit.succeed(new Person({ id: 123, name: "foo" })) ) - assert.deepStrictEqual( + deepStrictEqual( Effect.runSync( S.deserializeExit(req, { _tag: "Failure", diff --git a/packages/effect/test/Schema/TestUtils.ts b/packages/effect/test/Schema/TestUtils.ts index b862833695c..991c4add7b3 100644 --- a/packages/effect/test/Schema/TestUtils.ts +++ b/packages/effect/test/Schema/TestUtils.ts @@ -5,15 +5,15 @@ import * as ParseResult from "effect/ParseResult" import * as S from "effect/Schema" import type { ParseOptions } from "effect/SchemaAST" import * as AST from "effect/SchemaAST" -import { assert, expect } from "vitest" +import { deepStrictEqual, fail, throws } from "effect/test/util" import * as SchemaTest from "./SchemaTest.js" export const assertions = Effect.runSync( SchemaTest.assertions.pipe( Effect.provideService(SchemaTest.Assert, { - deepStrictEqual: (actual, expected) => expect(actual).toStrictEqual(expected), - throws: (fn, message) => expect(fn).toThrow(new Error(message)), - fail: (message) => assert.fail(message) + deepStrictEqual, + throws: (fn, message) => throws(fn, (e) => e instanceof Error && e.message === message), + fail }), Effect.provideService(SchemaTest.AssertConfig, { arbitrary: { @@ -28,6 +28,10 @@ export const assertions = Effect.runSync( ) ) +export const assertParseError = (f: () => void, message: string) => { + throws(f, (e) => e instanceof ParseResult.ParseError && e.message === message) +} + export const onExcessPropertyError: ParseOptions = { onExcessProperty: "error" } @@ -68,7 +72,7 @@ export const DependencyString = S.transformOrFail( export const expectFields = (f1: S.Struct.Fields, f2: S.Struct.Fields) => { const ks1 = Reflect.ownKeys(f1).sort().map((k) => [k, f1[k].ast.toString()]) const ks2 = Reflect.ownKeys(f2).sort().map((k) => [k, f2[k].ast.toString()]) - expect(ks1).toStrictEqual(ks2) + deepStrictEqual(ks1, ks2) } export const Defect = S.transform(S.String, S.Object, { diff --git a/packages/effect/test/Scope.test.ts b/packages/effect/test/Scope.test.ts index 36c3fb26de8..25a859281aa 100644 --- a/packages/effect/test/Scope.test.ts +++ b/packages/effect/test/Scope.test.ts @@ -1,10 +1,7 @@ -import * as Deferred from "effect/Deferred" -import * as Effect from "effect/Effect" -import { identity, pipe } from "effect/Function" -import * as Ref from "effect/Ref" -import * as Scope from "effect/Scope" +import { Deferred, Effect, identity, pipe, Ref, Scope } from "effect" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe, expect } from "vitest" +import { describe } from "vitest" type Action = Acquire | Use | Release @@ -59,7 +56,7 @@ describe("Scope", () => { Effect.flatMap((id) => Ref.update(ref, (actions) => [...actions, use(id)])) ))) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(result, [acquire(1), use(1), release(1)]) + deepStrictEqual(result, [acquire(1), use(1), release(1)]) })) it.effect("runs finalizers in parallel", () => Effect.gen(function*($) { @@ -73,7 +70,7 @@ describe("Scope", () => { Effect.scoped, Effect.asVoid ) - assert.isUndefined(result) + strictEqual(result, undefined) })) it.effect("runs finalizers in parallel when the scope is closed", () => Effect.gen(function*($) { @@ -93,12 +90,12 @@ describe("Scope", () => { ) ) const result = yield* $(Ref.get(ref)) - assert.isTrue(result.slice(0, 2).some((action) => isAcquire(action) && action.id === 1)) - assert.isTrue(result.slice(0, 2).some((action) => isAcquire(action) && action.id === 2)) - assert.isTrue(result.slice(2, 4).some((action) => isUse(action) && action.id === 1)) - assert.isTrue(result.slice(2, 4).some((action) => isUse(action) && action.id === 2)) - assert.isTrue(result.slice(4, 6).some((action) => isRelease(action) && action.id === 1)) - assert.isTrue(result.slice(4, 6).some((action) => isRelease(action) && action.id === 2)) + assertTrue(result.slice(0, 2).some((action) => isAcquire(action) && action.id === 1)) + assertTrue(result.slice(0, 2).some((action) => isAcquire(action) && action.id === 2)) + assertTrue(result.slice(2, 4).some((action) => isUse(action) && action.id === 1)) + assertTrue(result.slice(2, 4).some((action) => isUse(action) && action.id === 2)) + assertTrue(result.slice(4, 6).some((action) => isRelease(action) && action.id === 1)) + assertTrue(result.slice(4, 6).some((action) => isRelease(action) && action.id === 2)) })) it.effect("preserves order of nested sequential finalizers", () => Effect.gen(function*($) { @@ -111,8 +108,8 @@ describe("Scope", () => { const action2Index = actions.findIndex((action) => action.op === OP_RELEASE && action.id === 2) const action3Index = actions.findIndex((action) => action.op === OP_RELEASE && action.id === 3) const action4Index = actions.findIndex((action) => action.op === OP_RELEASE && action.id === 4) - assert.isBelow(action2Index, action1Index) - assert.isBelow(action4Index, action3Index) + assertTrue(action2Index < action1Index) + assertTrue(action4Index < action3Index) })) it.scoped("withEarlyRelease", () => Effect.gen(function*($) { @@ -121,9 +118,9 @@ describe("Scope", () => { const right = Effect.withEarlyRelease(resource(2, ref)) yield* $(left, Effect.zipRight(pipe(right, Effect.flatMap(([release, _]) => release)))) const actions = yield* $(Ref.get(ref)) - assert.deepStrictEqual(actions[0], acquire(1)) - assert.deepStrictEqual(actions[1], acquire(2)) - assert.deepStrictEqual(actions[2], release(2)) + deepStrictEqual(actions[0], acquire(1)) + deepStrictEqual(actions[1], acquire(2)) + deepStrictEqual(actions[2], release(2)) })) it.effect("using", () => Effect.gen(function*($) { @@ -139,15 +136,15 @@ describe("Scope", () => { ) const actions1 = yield* $(Ref.get(ref1)) const actions2 = yield* $(Ref.get(ref2)) - assert.deepStrictEqual(actions1, [acquire(1), use(1), release(1)]) - assert.deepStrictEqual(actions2, [acquire(2), use(2), release(2)]) + deepStrictEqual(actions1, [acquire(1), use(1), release(1)]) + deepStrictEqual(actions2, [acquire(2), use(2), release(2)]) })) it.effect( ".pipe", () => Effect.gen(function*(_) { const scope = yield* _(Scope.make()) - expect(scope.pipe(identity)).toBe(scope) + strictEqual(scope.pipe(identity), scope) }) ) }) diff --git a/packages/effect/test/ScopedCache.test.ts b/packages/effect/test/ScopedCache.test.ts index 21ce6db34a7..6c254265c67 100644 --- a/packages/effect/test/ScopedCache.test.ts +++ b/packages/effect/test/ScopedCache.test.ts @@ -1,26 +1,39 @@ -import * as Array from "effect/Array" -import * as Cause from "effect/Cause" -import * as Chunk from "effect/Chunk" -import * as Context from "effect/Context" -import * as Duration from "effect/Duration" -import * as Effect from "effect/Effect" -import * as Either from "effect/Either" -import * as Exit from "effect/Exit" -import * as Fiber from "effect/Fiber" -import { dual, identity, pipe } from "effect/Function" -import * as Hash from "effect/Hash" -import * as HashMap from "effect/HashMap" -import * as Ref from "effect/Ref" -import * as Schedule from "effect/Schedule" -import * as Scope from "effect/Scope" -import * as ScopedCache from "effect/ScopedCache" +import { + Array, + Cause, + Chunk, + Context, + Duration, + Effect, + Exit, + FastCheck as fc, + Fiber, + Hash, + HashMap, + identity, + pipe, + Ref, + Schedule, + Scope, + ScopedCache, + TestClock, + TestServices +} from "effect" +import { dual } from "effect/Function" +import { + assertFalse, + assertLeft, + assertNone, + assertRight, + assertSome, + assertTrue, + deepStrictEqual, + strictEqual +} from "effect/test/util" import * as ObservableResource from "effect/test/utils/cache/ObservableResource" import * as WatchableLookup from "effect/test/utils/cache/WatchableLookup" import * as it from "effect/test/utils/extend" -import * as TestClock from "effect/TestClock" -import * as TestServices from "effect/TestServices" -import * as fc from "fast-check" -import { describe, expect } from "vitest" +import { describe } from "vitest" const hash = dual< (y: number) => (x: number) => number, @@ -56,9 +69,9 @@ describe("ScopedCache", () => { ) ) ) - expect(hits).toBe(4) - expect(misses).toBe(6) - expect(size).toBe(6) + strictEqual(hits, 4) + strictEqual(misses, 6) + strictEqual(size, 6) }) return Effect.runPromise(Effect.scoped(program)) }) @@ -96,10 +109,10 @@ describe("ScopedCache", () => { ), (observableResource) => observableResource.assertAcquiredOnceAndNotCleaned() )) - expect(cacheContainsKey42).toBe(false) - expect(hits).toBe(0) - expect(misses).toBe(100) - expect(size).toBe(99) + assertFalse(cacheContainsKey42) + strictEqual(hits, 0) + strictEqual(misses, 100) + strictEqual(size, 99) }))) })) @@ -121,8 +134,8 @@ describe("ScopedCache", () => { yield* $(invalidateEffect) const cacheContainsKey42AfterInvalidate = yield* $(cache.contains(void 0)) yield* $(observablesResource.assertAcquiredOnceAndCleaned()) - expect(cacheContainsKey42BeforeInvalidate).toBe(true) - expect(cacheContainsKey42AfterInvalidate).toBe(false) + assertTrue(cacheContainsKey42BeforeInvalidate) + assertFalse(cacheContainsKey42AfterInvalidate) }))) })) @@ -161,10 +174,10 @@ describe("ScopedCache", () => { observablesResources, (observableResource) => observableResource.assertAcquiredOnceAndCleaned() )) - expect(contains).toBe(false) - expect(hits).toBe(0) - expect(misses).toBe(100) - expect(size).toBe(0) + assertFalse(contains) + strictEqual(hits, 0) + strictEqual(misses, 100) + strictEqual(size, 0) }))) })) @@ -183,7 +196,7 @@ describe("ScopedCache", () => { cache.get(void 0) yield* $(observablesResource.assertNotAcquired()) const contains = yield* $(cache.contains(void 0)) - expect(contains).toBe(false) + assertFalse(contains) }))) })) @@ -204,7 +217,7 @@ describe("ScopedCache", () => { ) ) const expected = Array.map(Array.range(1, 10), hash(salt)) - expect(actual).toEqual(expected) + deepStrictEqual(actual, expected) }))) }) return Effect.runPromise(program) @@ -228,7 +241,7 @@ describe("ScopedCache", () => { ) ) const expected = Array.map(Array.range(1, 10), hash(salt)) - expect(actual).toEqual(expected) + deepStrictEqual(actual, expected) }))) }) return Effect.runPromise(program) @@ -252,8 +265,8 @@ describe("ScopedCache", () => { ) const expected = Array.map(Array.range(1, 10), hash(salt)) const cacheStats = yield* $(cache.cacheStats) - expect(actual).toEqual(expected) - expect(cacheStats.size).toBe(5) + deepStrictEqual(actual, expected) + strictEqual(cacheStats.size, 5) }))) }) return Effect.runPromise(program) @@ -313,13 +326,13 @@ describe("ScopedCache", () => { }) yield* $(Effect.scoped(Effect.gen(function*($) { const cache = yield* $(scopedCache) - yield* $(watchableLookup.assertCalledTimes(void 0, (n) => expect(n).toBe(0))) + yield* $(watchableLookup.assertCalledTimes(void 0, (n) => strictEqual(n, 0))) const resourceScopedProxy = cache.get(void 0) - yield* $(watchableLookup.assertCalledTimes(void 0, (n) => expect(n).toBe(0))) + yield* $(watchableLookup.assertCalledTimes(void 0, (n) => strictEqual(n, 0))) yield* $(Effect.either(Effect.scoped(resourceScopedProxy))) yield* $(watchableLookup.assertAllCleanedForKey(void 0)) yield* $(Effect.either(Effect.scoped(resourceScopedProxy))) - yield* $(watchableLookup.assertCalledTimes(void 0, (n) => expect(n).toBe(1))) + yield* $(watchableLookup.assertCalledTimes(void 0, (n) => strictEqual(n, 1))) }))) })) @@ -366,16 +379,16 @@ describe("ScopedCache", () => { }) yield* $(Effect.scoped(Effect.gen(function*($) { const cache = yield* $(scopedCache) - yield* $(watchableLookup.assertCalledTimes(void 0, (n) => expect(n).toBe(0))) + yield* $(watchableLookup.assertCalledTimes(void 0, (n) => strictEqual(n, 0))) const resourceScopedProxy = cache.get(void 0) - yield* $(watchableLookup.assertCalledTimes(void 0, (n) => expect(n).toBe(0))) + yield* $(watchableLookup.assertCalledTimes(void 0, (n) => strictEqual(n, 0))) yield* $(Effect.zip( Effect.either(Effect.scoped(resourceScopedProxy)), Effect.either(Effect.scoped(resourceScopedProxy)), { concurrent: true } )) yield* $(watchableLookup.assertAllCleanedForKey(void 0)) - yield* $(watchableLookup.assertCalledTimes(void 0, (n) => expect(n).toBe(1))) + yield* $(watchableLookup.assertCalledTimes(void 0, (n) => strictEqual(n, 1))) }))) })) @@ -493,13 +506,13 @@ describe("ScopedCache", () => { yield* $(Effect.scoped(Effect.asVoid(scoped))) yield* $(TestClock.adjust(Duration.seconds(5))) yield* $(Effect.scoped(Effect.asVoid(scoped))) - yield* $(watchableLookup.assertCalledTimes(void 0, (n) => expect(n).toBe(1))) + yield* $(watchableLookup.assertCalledTimes(void 0, (n) => strictEqual(n, 1))) yield* $(TestClock.adjust(Duration.seconds(4))) yield* $(Effect.scoped(Effect.asVoid(scoped))) - yield* $(watchableLookup.assertCalledTimes(void 0, (n) => expect(n).toBe(1))) + yield* $(watchableLookup.assertCalledTimes(void 0, (n) => strictEqual(n, 1))) yield* $(TestClock.adjust(Duration.seconds(2))) yield* $(Effect.scoped(Effect.asVoid(scoped))) - yield* $(watchableLookup.assertCalledTimes(void 0, (n) => expect(n).toBe(2))) + yield* $(watchableLookup.assertCalledTimes(void 0, (n) => strictEqual(n, 2))) yield* $(watchableLookup.assertFirstNCreatedResourcesCleaned(void 0, 1)) }))) })) @@ -517,13 +530,13 @@ describe("ScopedCache", () => { yield* $(scoped) yield* $(TestClock.adjust(Duration.seconds(5))) yield* $(scoped) - yield* $(watchableLookup.assertCalledTimes(void 0, (n) => expect(n).toBe(1))) + yield* $(watchableLookup.assertCalledTimes(void 0, (n) => strictEqual(n, 1))) yield* $(TestClock.adjust(Duration.seconds(4))) yield* $(scoped) - yield* $(watchableLookup.assertCalledTimes(void 0, (n) => expect(n).toBe(1))) + yield* $(watchableLookup.assertCalledTimes(void 0, (n) => strictEqual(n, 1))) yield* $(TestClock.adjust(Duration.seconds(2))) yield* $(scoped) - yield* $(watchableLookup.assertCalledTimes(void 0, (n) => expect(n).toBe(2))) + yield* $(watchableLookup.assertCalledTimes(void 0, (n) => strictEqual(n, 2))) yield* $(watchableLookup.assertFirstNCreatedResourcesCleaned(void 0, 1)) }))) })) @@ -546,7 +559,7 @@ describe("ScopedCache", () => { yield* $(acquire) yield* $(TestClock.adjust(Duration.seconds(11))) yield* $(Effect.scoped(Effect.asVoid(cache.get(void 0)))) - yield* $(watchableLookup.assertCalledTimes(void 0, (n) => expect(n).toBe(2))) + yield* $(watchableLookup.assertCalledTimes(void 0, (n) => strictEqual(n, 2))) const firstCreatedResource = yield* $(watchableLookup.firstCreatedResource(void 0)) yield* $(firstCreatedResource.assertAcquiredOnceAndNotCleaned()) yield* $(release(Exit.void)) @@ -562,7 +575,7 @@ describe("ScopedCache", () => { lookup: (i: number) => Effect.succeed(i) })) const option = yield* _(scopedCache.getOption(1)) - expect(option._tag).toEqual("None") + assertNone(option) }))) it.effect("getOption - should return Some if pending", () => @@ -575,7 +588,7 @@ describe("ScopedCache", () => { yield* _(scopedCache.get(1), Effect.scoped, Effect.fork) yield* _(TestServices.provideLive(Effect.sleep(Duration.millis(5)))) const option = yield* _(scopedCache.getOption(1), Effect.scoped) - expect(option._tag).toEqual("Some") + assertSome(option, 1) }))) it.effect("getOptionComplete - should return None if pending", () => @@ -588,7 +601,7 @@ describe("ScopedCache", () => { yield* _(scopedCache.get(1), Effect.scoped, Effect.fork) yield* _(TestClock.adjust(Duration.millis(9))) const option = yield* _(scopedCache.getOptionComplete(1), Effect.scoped) - expect(option._tag).toEqual("None") + assertNone(option) }))) it.effect("getOptionComplete - should return Some if complete", () => @@ -600,7 +613,7 @@ describe("ScopedCache", () => { })) yield* _(scopedCache.get(1), Effect.scoped) const option = yield* _(scopedCache.getOptionComplete(1), Effect.scoped) - expect(option._tag).toEqual("Some") + assertSome(option, 1) }))) it.effect("refresh - should update the cache with a new value", () => @@ -627,8 +640,8 @@ describe("ScopedCache", () => { const val3 = yield* $(cache.get(key)) return [val1, val2, val3] as const }))) - expect(val2).toBe(val3) - expect(val2).toBe(inc(val1)) + strictEqual(val2, val3) + strictEqual(val2, inc(val1)) })) it.effect("refresh - should clean old resource when making a new one", () => @@ -684,10 +697,10 @@ describe("ScopedCache", () => { const value2 = yield* $(Effect.either(cache.get(key))) return { failure1, value1, failure2, value2 } }))) - expect(result.failure1).toEqual(Either.left(error)) - expect(result.failure2).toEqual(Either.left(error)) - expect(result.value1).toEqual(Either.right(4)) - expect(result.value2).toEqual(Either.right(7)) + assertLeft(result.failure1, error) + assertLeft(result.failure2, error) + assertRight(result.value1, 4) + assertRight(result.value2, 7) })) it.effect("refresh - should create and acquire subresource if the key doesn't exist in the cache", () => @@ -703,8 +716,8 @@ describe("ScopedCache", () => { const count0 = yield* $(cache.size) yield* $(Effect.forEach(Array.range(1, capacity), (key) => cache.refresh(key), { discard: true })) const count1 = yield* $(cache.size) - expect(count0).toBe(0) - expect(count1).toBe(capacity) + strictEqual(count0, 0) + strictEqual(count1, capacity) }))) })) @@ -772,7 +785,7 @@ describe("ScopedCache", () => { )) ) yield* $(TestServices.provideLive(Effect.sleep(Duration.millis(100)))) - yield* $(watchableLookup.assertCalledTimes(void 0, (n) => expect(n).toBe(2))) + yield* $(watchableLookup.assertCalledTimes(void 0, (n) => strictEqual(n, 2))) const firstCreatedResource = yield* $(watchableLookup.firstCreatedResource(void 0)) yield* $(firstCreatedResource.assertAcquiredOnceAndNotCleaned()) yield* $(watchableLookup.unlock()) @@ -803,7 +816,7 @@ describe("ScopedCache", () => { )) ) yield* $(TestServices.provideLive(Effect.sleep(Duration.millis(100)))) - yield* $(watchableLookup.assertCalledTimes(void 0, (n) => expect(n).toBe(2))) + yield* $(watchableLookup.assertCalledTimes(void 0, (n) => strictEqual(n, 2))) yield* $(watchableLookup.assertFirstNCreatedResourcesCleaned(void 0, 1)) yield* $(watchableLookup.unlock()) yield* $(Fiber.join(refreshFiber)) @@ -828,7 +841,7 @@ describe("ScopedCache", () => { yield* $(acquire) yield* $(TestClock.adjust(Duration.seconds(11))) yield* $(cache.refresh(void 0)) - yield* $(watchableLookup.assertCalledTimes(void 0, (n) => expect(n).toBe(2))) + yield* $(watchableLookup.assertCalledTimes(void 0, (n) => strictEqual(n, 2))) const firstCreatedResource = yield* $(watchableLookup.firstCreatedResource(void 0)) yield* $(firstCreatedResource.assertAcquiredOnceAndNotCleaned()) yield* $(release(Exit.void)) @@ -845,6 +858,6 @@ describe("ScopedCache", () => { }), Effect.scoped ) - expect(cache.pipe(identity)).toBe(cache) + strictEqual(cache.pipe(identity), cache) })) }) diff --git a/packages/effect/test/ScopedRef.test.ts b/packages/effect/test/ScopedRef.test.ts index f4c942c9221..7c5a4c81bd1 100644 --- a/packages/effect/test/ScopedRef.test.ts +++ b/packages/effect/test/ScopedRef.test.ts @@ -1,9 +1,8 @@ -import * as Effect from "effect/Effect" -import { identity, pipe } from "effect/Function" -import * as ScopedRef from "effect/ScopedRef" +import { Effect, identity, pipe, ScopedRef } from "effect" +import { strictEqual } from "effect/test/util" import * as Counter from "effect/test/utils/counter" import * as it from "effect/test/utils/extend" -import { assert, describe, expect } from "vitest" +import { describe } from "vitest" describe("ScopedRef", () => { it.scoped("single set", () => @@ -12,7 +11,7 @@ describe("ScopedRef", () => { const ref = yield* $(ScopedRef.make(() => 0)) yield* $(ScopedRef.set(ref, counter.acquire())) const result = yield* $(ScopedRef.get(ref)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.scoped("dual set", () => Effect.gen(function*($) { @@ -23,7 +22,7 @@ describe("ScopedRef", () => { Effect.zipRight(ScopedRef.set(ref, counter.acquire())) ) const result = yield* $(ScopedRef.get(ref)) - assert.strictEqual(result, 2) + strictEqual(result, 2) })) it.scoped("release on swap", () => Effect.gen(function*($) { @@ -36,8 +35,8 @@ describe("ScopedRef", () => { const acquired = yield* $(counter.acquired()) const released = yield* $(counter.released()) - assert.strictEqual(acquired, 2) - assert.strictEqual(released, 1) + strictEqual(acquired, 2) + strictEqual(released, 1) })) it.scoped("double release on double swap", () => Effect.gen(function*($) { @@ -52,8 +51,8 @@ describe("ScopedRef", () => { ) const acquired = yield* $(counter.acquired()) const released = yield* $(counter.released()) - assert.strictEqual(acquired, 3) - assert.strictEqual(released, 2) + strictEqual(acquired, 3) + strictEqual(released, 2) })) it.effect("full release", () => Effect.gen(function*($) { @@ -71,18 +70,18 @@ describe("ScopedRef", () => { ) const acquired = yield* $(counter.acquired()) const released = yield* $(counter.released()) - assert.strictEqual(acquired, 3) - assert.strictEqual(released, 3) + strictEqual(acquired, 3) + strictEqual(released, 3) })) it.effect("full release", () => Effect.gen(function*(_) { const ref = yield* _(Effect.scoped(ScopedRef.make(() => 0))) - expect(ref.pipe(identity)).toBe(ref) + strictEqual(ref.pipe(identity), ref) })) it.scoped("subtype of Effect", () => Effect.gen(function*() { const ref = yield* ScopedRef.make(() => 0) const result = yield* ref - assert.strictEqual(result, 0) + strictEqual(result, 0) })) }) diff --git a/packages/effect/test/Sink/collecting.test.ts b/packages/effect/test/Sink/collecting.test.ts index c7452a0bc26..f62ca6dffbc 100644 --- a/packages/effect/test/Sink/collecting.test.ts +++ b/packages/effect/test/Sink/collecting.test.ts @@ -4,8 +4,9 @@ import { constTrue, pipe } from "effect/Function" import * as Option from "effect/Option" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Sink", () => { it.effect("collectAllN - respects the given limit", () => @@ -15,7 +16,7 @@ describe("Sink", () => { Stream.transduce(Sink.collectAllN(3)) ) const result = yield* $(Stream.runCollect(stream)) - assert.deepStrictEqual( + deepStrictEqual( Array.from(Chunk.map(result, (chunk) => Array.from(chunk))), [[1, 2, 3], [4]] ) @@ -28,7 +29,7 @@ describe("Sink", () => { Stream.transduce(Sink.collectAllN(4)) ) const result = yield* $(Stream.runCollect(stream)) - assert.deepStrictEqual( + deepStrictEqual( Array.from(Chunk.map(result, (chunk) => Array.from(chunk))), [[1, 2, 3, 4], []] ) @@ -41,7 +42,7 @@ describe("Sink", () => { Stream.transduce(Sink.collectAllN(3)) ) const result = yield* $(Stream.runCollect(stream)) - assert.deepStrictEqual( + deepStrictEqual( Array.from(Chunk.map(result, (chunk) => Array.from(chunk))), [[]] ) @@ -51,7 +52,7 @@ describe("Sink", () => { Effect.gen(function*($) { const stream = Stream.make(1, 2, 3, 3, 4) const result = yield* $(stream, Stream.run(Sink.collectAllToSet())) - assert.deepStrictEqual(Array.from(result), [1, 2, 3, 4]) + deepStrictEqual(Array.from(result), [1, 2, 3, 4]) })) it.effect("collectAllToSetN - respects the given limit", () => @@ -61,7 +62,7 @@ describe("Sink", () => { Stream.transduce(Sink.collectAllToSetN(3)) ) const result = yield* $(Stream.runCollect(stream)) - assert.deepStrictEqual( + deepStrictEqual( Array.from(Chunk.map(result, (set) => Array.from(set))), [[1, 2, 3], [4]] ) @@ -74,7 +75,7 @@ describe("Sink", () => { Stream.transduce(Sink.collectAllToSetN(3)) ) const result = yield* $(Stream.runCollect(stream)) - assert.deepStrictEqual( + deepStrictEqual( Array.from(Chunk.map(result, (set) => Array.from(set))), [[]] ) @@ -89,7 +90,7 @@ describe("Sink", () => { (x, y) => x + y )) ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result), [[0, 18], [1, 12], [2, 15]] ) @@ -106,7 +107,7 @@ describe("Sink", () => { )), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(Chunk.map(result, (chunk) => Array.from(chunk))), [[[1, 2], [2, 4]], [[0, 3], [2, 2]], [[1, 4], [2, 5]]] ) @@ -123,7 +124,7 @@ describe("Sink", () => { )), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(Chunk.map(result, (chunk) => Array.from(chunk))), [[[0, 18], [1, 12], [2, 15]]] ) @@ -140,7 +141,7 @@ describe("Sink", () => { )), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(Chunk.map(result, (chunk) => Array.from(chunk))), [[]] ) @@ -156,7 +157,7 @@ describe("Sink", () => { Chunk.empty() ) const result = yield* $(Stream.fromChunks(...input), Stream.transduce(sink), Stream.runCollect) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[3, 4, 5], [6], [7], [2, 3, 4, 5], [6], [5], [4, 3, 2]] ) @@ -172,7 +173,7 @@ describe("Sink", () => { Chunk.empty() ) const result = yield* $(Stream.fromChunks(...input), Stream.transduce(sink), Stream.runCollect) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[3, 4, 5], [6], [7], [2, 3, 4, 5], [6], [5], [4, 3, 2]] ) @@ -191,7 +192,7 @@ describe("Sink", () => { Chunk.empty() ) const result = yield* $(Stream.fromChunks(...input), Stream.transduce(sink), Stream.runCollect) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[3, 4], [2, 3, 4], [4, 3, 2]] ) @@ -210,7 +211,7 @@ describe("Sink", () => { Chunk.empty() ) const result = yield* $(Stream.fromChunks(...input), Stream.transduce(sink), Stream.runCollect) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[3, 4], [2, 3, 4], [4, 3, 2]] ) @@ -234,9 +235,9 @@ describe("Sink", () => { const result1 = yield* $(program(1)) const result2 = yield* $(program(3)) const result3 = yield* $(program(20)) - assert.strictEqual(result1, 54) - assert.strictEqual(result2, 54) - assert.strictEqual(result3, 54) + strictEqual(result1, 54) + strictEqual(result2, 54) + strictEqual(result3, 54) })) it.effect("collectAllWhileWith - example 2", () => @@ -259,6 +260,6 @@ describe("Sink", () => { Stream.rechunk(3), Stream.run(sink) ) - assert.deepStrictEqual(Array.from(result), [1, 2, 3, 4]) + deepStrictEqual(Array.from(result), [1, 2, 3, 4]) })) }) diff --git a/packages/effect/test/Sink/constructors.test.ts b/packages/effect/test/Sink/constructors.test.ts index ca758f3fdd6..6d473aceccb 100644 --- a/packages/effect/test/Sink/constructors.test.ts +++ b/packages/effect/test/Sink/constructors.test.ts @@ -14,8 +14,9 @@ import * as PubSub from "effect/PubSub" import * as Queue from "effect/Queue" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { assertTrue, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Sink", () => { it.effect("drain - fails if upstream fails", () => @@ -25,14 +26,14 @@ describe("Sink", () => { Stream.mapEffect(() => Effect.fail("boom!")) ) const result = yield* $(stream, Stream.run(Sink.drain), Effect.exit) - assert.deepStrictEqual(result, Exit.fail("boom!")) + deepStrictEqual(result, Exit.fail("boom!")) })) it.effect("fromEffect", () => Effect.gen(function*($) { const sink = Sink.fromEffect(Effect.succeed("ok")) const result = yield* $(Stream.make(1, 2, 3), Stream.run(sink)) - assert.deepStrictEqual(result, "ok") + deepStrictEqual(result, "ok") })) it.effect("fromQueue - should enqueue all elements", () => @@ -40,7 +41,7 @@ describe("Sink", () => { const queue = yield* $(Queue.unbounded()) yield* $(Stream.make(1, 2, 3), Stream.run(Sink.fromQueue(queue))) const result = yield* $(Queue.takeAll(queue)) - assert.deepStrictEqual(Array.from(result), [1, 2, 3]) + deepStrictEqual(Array.from(result), [1, 2, 3]) })) it.effect("fromQueueWithShutdown - should enqueue all elements and shutdown the queue", () => @@ -49,8 +50,8 @@ describe("Sink", () => { yield* $(Stream.make(1, 2, 3), Stream.run(Sink.fromQueue(queue, { shutdown: true }))) const enqueuedValues = yield* $(Queue.takeAll(queue)) const isShutdown = yield* $(Queue.isShutdown(queue)) - assert.deepStrictEqual(Array.from(enqueuedValues), [1, 2, 3]) - assert.isTrue(isShutdown) + deepStrictEqual(Array.from(enqueuedValues), [1, 2, 3]) + assertTrue(isShutdown) })) it.effect("fromPubSub - should publish all elements", () => @@ -74,7 +75,7 @@ describe("Sink", () => { yield* $(Stream.make(1, 2, 3), Stream.run(Sink.fromPubSub(pubsub))) yield* $(Deferred.succeed(deferred2, void 0)) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Array.from(result), [1, 2, 3]) + deepStrictEqual(Array.from(result), [1, 2, 3]) })) it.effect("fromPubSub(_, { shutdown: true }) - should shutdown the pubsub", () => @@ -82,7 +83,7 @@ describe("Sink", () => { const pubsub = yield* $(PubSub.unbounded()) yield* $(Stream.make(1, 2, 3), Stream.run(Sink.fromPubSub(pubsub, { shutdown: true }))) const isShutdown = yield* $(PubSub.isShutdown(pubsub)) - assert.isTrue(isShutdown) + assertTrue(isShutdown) })) }) diff --git a/packages/effect/test/Sink/dropping.test.ts b/packages/effect/test/Sink/dropping.test.ts index 8b51853b13c..d12d95578d5 100644 --- a/packages/effect/test/Sink/dropping.test.ts +++ b/packages/effect/test/Sink/dropping.test.ts @@ -2,8 +2,9 @@ import * as Effect from "effect/Effect" import * as Either from "effect/Either" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Sink", () => { it.effect("dropUntil", () => @@ -13,7 +14,7 @@ describe("Sink", () => { Stream.pipeThrough(Sink.dropUntil((n) => n >= 3)), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [4, 5, 1, 2, 3, 4, 5]) + deepStrictEqual(Array.from(result), [4, 5, 1, 2, 3, 4, 5]) })) it.effect("dropUntilEffect - happy path", () => @@ -23,7 +24,7 @@ describe("Sink", () => { Stream.pipeThrough(Sink.dropUntilEffect((n) => Effect.succeed(n >= 3))), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [4, 5, 1, 2, 3, 4, 5]) + deepStrictEqual(Array.from(result), [4, 5, 1, 2, 3, 4, 5]) })) it.effect("dropUntilEffect - error", () => @@ -36,7 +37,7 @@ describe("Sink", () => { Stream.either, Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [Either.right(3), Either.left("Aie")]) + deepStrictEqual(Array.from(result), [Either.right(3), Either.left("Aie")]) })) it.effect("dropWhile", () => @@ -46,7 +47,7 @@ describe("Sink", () => { Stream.pipeThrough(Sink.dropWhile((n) => n < 3)), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [3, 4, 5, 1, 2, 3, 4, 5]) + deepStrictEqual(Array.from(result), [3, 4, 5, 1, 2, 3, 4, 5]) })) it.effect("dropWhileEffect - happy path", () => @@ -56,7 +57,7 @@ describe("Sink", () => { Stream.pipeThrough(Sink.dropWhileEffect((n) => Effect.succeed(n < 3))), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [3, 4, 5, 1, 2, 3, 4, 5]) + deepStrictEqual(Array.from(result), [3, 4, 5, 1, 2, 3, 4, 5]) })) it.effect("dropWhileEffect - error", () => @@ -71,6 +72,6 @@ describe("Sink", () => { Stream.either, Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [Either.right(3), Either.left("Aie")]) + deepStrictEqual(Array.from(result), [Either.right(3), Either.left("Aie")]) })) }) diff --git a/packages/effect/test/Sink/elements.test.ts b/packages/effect/test/Sink/elements.test.ts index cf9c30da9ec..e8180628092 100644 --- a/packages/effect/test/Sink/elements.test.ts +++ b/packages/effect/test/Sink/elements.test.ts @@ -1,11 +1,11 @@ import * as Chunk from "effect/Chunk" import * as Effect from "effect/Effect" import { pipe } from "effect/Function" -import * as Option from "effect/Option" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { assertSome, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Sink", () => { it.effect("every", () => @@ -16,7 +16,7 @@ describe("Sink", () => { Stream.fromChunk(chunk), Stream.run(Sink.every(predicate)) ) - assert.isTrue(result) + assertTrue(result) })) it.effect("head", () => @@ -25,7 +25,7 @@ describe("Sink", () => { Stream.fromChunks(Chunk.range(1, 10), Chunk.range(1, 3), Chunk.range(2, 5)), Stream.run(Sink.head()) ) - assert.deepStrictEqual(result, Option.some(1)) + assertSome(result, 1) })) it.effect("last", () => @@ -34,7 +34,7 @@ describe("Sink", () => { Stream.fromChunks(Chunk.range(1, 10), Chunk.range(1, 3), Chunk.range(2, 5)), Stream.run(Sink.last()) ) - assert.deepStrictEqual(result, Option.some(5)) + assertSome(result, 5) })) it.effect("take - repeats until the source is exhausted", () => @@ -49,7 +49,7 @@ describe("Sink", () => { ), Stream.run(Sink.collectAllFrom(Sink.take(3))) ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1, 2, 3], [4, 5, 6], [7, 8, 9], []] ) @@ -63,7 +63,7 @@ describe("Sink", () => { Stream.fromChunk(chunk), Stream.run(Sink.some(predicate)) ) - assert.isTrue(result) + assertTrue(result) })) it.effect("sum", () => @@ -81,7 +81,7 @@ describe("Sink", () => { Sink.map(Chunk.reduce(0, (x, y) => x + y)) )) ) - assert.strictEqual(result, 45) + strictEqual(result, 45) })) it.effect("take", () => @@ -105,11 +105,11 @@ describe("Sink", () => { ), Effect.scoped ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(chunk), Array.from(pipe(Chunk.flatten(chunks), Chunk.take(n))) ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(leftover), Array.from(pipe(Chunk.flatten(chunks), Chunk.drop(n))) ) diff --git a/packages/effect/test/Sink/environment.test.ts b/packages/effect/test/Sink/environment.test.ts index 6230cde8915..f330cee07d3 100644 --- a/packages/effect/test/Sink/environment.test.ts +++ b/packages/effect/test/Sink/environment.test.ts @@ -3,8 +3,9 @@ import * as Effect from "effect/Effect" import { pipe } from "effect/Function" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Sink", () => { it.effect("contextWithSink", () => @@ -15,6 +16,6 @@ describe("Sink", () => { Sink.provideContext(pipe(Context.empty(), Context.add(tag, "use this"))) ) const result = yield* $(Stream.make("ignore this"), Stream.run(sink)) - assert.strictEqual(result, "use this") + strictEqual(result, "use this") })) }) diff --git a/packages/effect/test/Sink/error-handling.test.ts b/packages/effect/test/Sink/error-handling.test.ts index c0849dce8be..d23da226da7 100644 --- a/packages/effect/test/Sink/error-handling.test.ts +++ b/packages/effect/test/Sink/error-handling.test.ts @@ -3,8 +3,9 @@ import * as Exit from "effect/Exit" import { pipe } from "effect/Function" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Sink", () => { it.effect("propagates errors", () => @@ -24,6 +25,6 @@ describe("Sink", () => { ), Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(ErrorMapped)) + deepStrictEqual(result, Exit.fail(ErrorMapped)) })) }) diff --git a/packages/effect/test/Sink/filtering.test.ts b/packages/effect/test/Sink/filtering.test.ts index b3f4548404d..577e6511513 100644 --- a/packages/effect/test/Sink/filtering.test.ts +++ b/packages/effect/test/Sink/filtering.test.ts @@ -2,8 +2,9 @@ import * as Effect from "effect/Effect" import { pipe } from "effect/Function" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Sink", () => { it.effect("filterInput", () => @@ -12,7 +13,7 @@ describe("Sink", () => { Stream.range(1, 9), Stream.run(pipe(Sink.collectAll(), Sink.filterInput((n) => n % 2 === 0))) ) - assert.deepStrictEqual(Array.from(result), [2, 4, 6, 8]) + deepStrictEqual(Array.from(result), [2, 4, 6, 8]) })) it.effect("filterInputEffect - happy path", () => @@ -24,7 +25,7 @@ describe("Sink", () => { Sink.filterInputEffect((n) => Effect.succeed(n % 2 === 0)) )) ) - assert.deepStrictEqual(Array.from(result), [2, 4, 6, 8]) + deepStrictEqual(Array.from(result), [2, 4, 6, 8]) })) it.effect("filterInputEffect - error", () => @@ -37,6 +38,6 @@ describe("Sink", () => { )), Effect.flip ) - assert.strictEqual(result, "fail") + strictEqual(result, "fail") })) }) diff --git a/packages/effect/test/Sink/finalization.test.ts b/packages/effect/test/Sink/finalization.test.ts index 9016af0e937..2c12c641a46 100644 --- a/packages/effect/test/Sink/finalization.test.ts +++ b/packages/effect/test/Sink/finalization.test.ts @@ -3,8 +3,9 @@ import { pipe } from "effect/Function" import * as Ref from "effect/Ref" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { assertTrue } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Sink", () => { it.effect("ensuring - happy path", () => @@ -15,7 +16,7 @@ describe("Sink", () => { Stream.run(pipe(Sink.drain, Sink.ensuring(Ref.set(ref, true)))) ) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("ensuring - error", () => @@ -27,6 +28,6 @@ describe("Sink", () => { Effect.ignore ) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) }) diff --git a/packages/effect/test/Sink/folding.test.ts b/packages/effect/test/Sink/folding.test.ts index 8d47282d1fc..9b72ed29394 100644 --- a/packages/effect/test/Sink/folding.test.ts +++ b/packages/effect/test/Sink/folding.test.ts @@ -5,8 +5,9 @@ import { absurd, constTrue, pipe } from "effect/Function" import * as Ref from "effect/Ref" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Sink", () => { it.effect("fold - empty", () => @@ -16,7 +17,7 @@ describe("Sink", () => { Stream.transduce(Sink.fold(0, constTrue, (x, y) => x + y)), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [0]) + deepStrictEqual(Array.from(result), [0]) })) it.effect("fold - termination in the middle", () => @@ -25,7 +26,7 @@ describe("Sink", () => { Stream.range(1, 9), Stream.run(Sink.fold(0, (n) => n <= 5, (x, y) => x + y)) ) - assert.strictEqual(result, 6) + strictEqual(result, 6) })) it.effect("fold - immediate termination", () => @@ -34,7 +35,7 @@ describe("Sink", () => { Stream.range(1, 9), Stream.run(Sink.fold(0, (n) => n <= -1, (x, y) => x + y)) ) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("fold - no termination", () => @@ -43,7 +44,7 @@ describe("Sink", () => { Stream.range(1, 9), Stream.run(Sink.fold(0, (n) => n <= 500, (x, y) => x + y)) ) - assert.strictEqual(result, 45) + strictEqual(result, 45) })) it.effect("foldLeft equivalence with Chunk.reduce", () => @@ -51,14 +52,14 @@ describe("Sink", () => { const stream = Stream.range(1, 9) const result1 = yield* $(stream, Stream.run(Sink.foldLeft("", (s, n) => s + `${n}`))) const result2 = yield* $(stream, Stream.runCollect, Effect.map(Chunk.reduce("", (s, n) => s + `${n}`))) - assert.strictEqual(result1, result2) + strictEqual(result1, result2) })) it.effect("foldEffect - empty", () => Effect.gen(function*($) { const sink = Sink.foldEffect(0, constTrue, (x, y: number) => Effect.succeed(x + y)) const result = yield* $(Stream.empty, Stream.transduce(sink), Stream.runCollect) - assert.deepStrictEqual(Array.from(result), [0]) + deepStrictEqual(Array.from(result), [0]) })) it.effect("foldEffect - short circuits", () => @@ -93,10 +94,10 @@ describe("Sink", () => { const result2 = yield* $(run(single)) const result3 = yield* $(run(double)) const result4 = yield* $(run(failed)) - assert.deepStrictEqual(result1, Exit.succeed([[0], []])) - assert.deepStrictEqual(result2, Exit.succeed([[30], [1]])) - assert.deepStrictEqual(result3, Exit.succeed([[30], [1, 2]])) - assert.deepStrictEqual(result4, Exit.fail("Ouch")) + deepStrictEqual(result1, Exit.succeed([[0], []])) + deepStrictEqual(result2, Exit.succeed([[30], [1]])) + deepStrictEqual(result3, Exit.succeed([[30], [1, 2]])) + deepStrictEqual(result4, Exit.fail("Ouch")) })) it.effect("foldUntil", () => @@ -106,7 +107,7 @@ describe("Sink", () => { Stream.transduce(Sink.foldUntil(0, 3, (x, y) => x + y)), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [3, 3, 0]) + deepStrictEqual(Array.from(result), [3, 3, 0]) })) it.effect("foldUntilEffect", () => @@ -116,7 +117,7 @@ describe("Sink", () => { Stream.transduce(Sink.foldUntilEffect(0, 3, (x, y) => Effect.succeed(x + y))), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [3, 3, 0]) + deepStrictEqual(Array.from(result), [3, 3, 0]) })) it.effect("foldWeighted", () => @@ -131,7 +132,7 @@ describe("Sink", () => { })), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1, 5], [2, 3]] ) @@ -150,7 +151,7 @@ describe("Sink", () => { })), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [0]) + deepStrictEqual(Array.from(result), [0]) })) it.effect("foldWeightedDecompose - simple", () => @@ -166,7 +167,7 @@ describe("Sink", () => { })), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1, 3], [1, 1, 1]] ) @@ -184,7 +185,7 @@ describe("Sink", () => { })), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1, 5], [2, 3]] ) @@ -203,7 +204,7 @@ describe("Sink", () => { })), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [0]) + deepStrictEqual(Array.from(result), [0]) })) it.effect("foldWeightedDecomposeEffect - simple", () => @@ -219,7 +220,7 @@ describe("Sink", () => { })), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1, 3], [1, 1, 1]] ) @@ -242,6 +243,6 @@ describe("Sink", () => { Stream.make(1, 2, 3), Stream.run(sink) ) - assert.deepStrictEqual(result, [[1, 2, 3], "boom"]) + deepStrictEqual(result, [[1, 2, 3], "boom"]) })) }) diff --git a/packages/effect/test/Sink/foreign.test.ts b/packages/effect/test/Sink/foreign.test.ts index ed3b753709f..3466affb6cd 100644 --- a/packages/effect/test/Sink/foreign.test.ts +++ b/packages/effect/test/Sink/foreign.test.ts @@ -6,9 +6,10 @@ import * as Option from "effect/Option" import * as Random from "effect/Random" import type * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import { unify } from "effect/Unify" -import { assert, describe } from "vitest" +import { describe } from "vitest" const runSink = (sink: Sink.Sink) => Stream.run(Effect.void, sink) @@ -17,7 +18,7 @@ describe("Channel.Foreign", () => { Effect.gen(function*($) { const tag = Context.GenericTag("number") const result = yield* $(tag, runSink, Effect.provideService(tag, 10)) - assert.deepEqual(result, 10) + deepStrictEqual(result, 10) })) it.effect("Unify", () => @@ -26,9 +27,9 @@ describe("Channel.Foreign", () => { const unifiedExit = unify((yield* $(Random.nextInt)) > 1 ? Exit.succeed(0) : Exit.fail(1)) const unifiedEither = unify((yield* $(Random.nextInt)) > 1 ? Either.right(0) : Either.left(1)) const unifiedOption = unify((yield* $(Random.nextInt)) > 1 ? Option.some(0) : Option.none()) - assert.deepEqual(yield* $(runSink(unifiedEffect)), 0) - assert.deepEqual(yield* $(runSink(unifiedExit)), 0) - assert.deepEqual(yield* $(runSink(unifiedEither)), 0) - assert.deepEqual(yield* $(runSink(unifiedOption)), 0) + deepStrictEqual(yield* $(runSink(unifiedEffect)), 0) + deepStrictEqual(yield* $(runSink(unifiedExit)), 0) + deepStrictEqual(yield* $(runSink(unifiedEither)), 0) + deepStrictEqual(yield* $(runSink(unifiedOption)), 0) })) }) diff --git a/packages/effect/test/Sink/mapping.test.ts b/packages/effect/test/Sink/mapping.test.ts index 0eb6038762a..f45d324f47e 100644 --- a/packages/effect/test/Sink/mapping.test.ts +++ b/packages/effect/test/Sink/mapping.test.ts @@ -1,12 +1,12 @@ import * as Cause from "effect/Cause" import * as Chunk from "effect/Chunk" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import { pipe } from "effect/Function" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { assertLeft, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Sink", () => { it.effect("as", () => @@ -15,7 +15,7 @@ describe("Sink", () => { Stream.range(1, 9), Stream.run(pipe(Sink.succeed(1), Sink.as("as"))) ) - assert.strictEqual(result, "as") + strictEqual(result, "as") })) it.effect("mapInput - happy path", () => @@ -25,7 +25,7 @@ describe("Sink", () => { Sink.mapInput((input: string) => Number.parseInt(input)) ) const result = yield* $(Stream.make("1", "2", "3"), Stream.run(sink)) - assert.deepStrictEqual(Array.from(result), [1, 2, 3]) + deepStrictEqual(Array.from(result), [1, 2, 3]) })) it.effect("mapInput - error", () => @@ -35,7 +35,7 @@ describe("Sink", () => { Sink.mapInput((input: string) => Number.parseInt(input)) ) const result = yield* $(Stream.make("1", "2", "3"), Stream.run(sink), Effect.either) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) it.effect("mapInputChunks - happy path", () => @@ -45,7 +45,7 @@ describe("Sink", () => { Sink.mapInputChunks(Chunk.map((_) => Number.parseInt(_))) ) const result = yield* $(Stream.make("1", "2", "3"), Stream.run(sink)) - assert.deepStrictEqual(Array.from(result), [1, 2, 3]) + deepStrictEqual(Array.from(result), [1, 2, 3]) })) it.effect("mapInputChunks - error", () => @@ -55,7 +55,7 @@ describe("Sink", () => { Sink.mapInputChunks(Chunk.map(Number.parseInt)) ) const result = yield* $(Stream.make("1", "2", "3"), Stream.run(sink), Effect.either) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) it.effect("mapInputEffect - happy path", () => @@ -65,7 +65,7 @@ describe("Sink", () => { Sink.mapInputEffect((s: string) => Effect.try(() => Number.parseInt(s))) ) const result = yield* $(Stream.make("1", "2", "3"), Stream.run(sink)) - assert.deepStrictEqual(Array.from(result), [1, 2, 3]) + deepStrictEqual(Array.from(result), [1, 2, 3]) })) it.effect("mapInputEffect - error", () => @@ -75,7 +75,7 @@ describe("Sink", () => { Sink.mapInputEffect((s: string) => Effect.try(() => Number.parseInt(s))) ) const result = yield* $(Stream.make("1", "2", "3"), Stream.run(sink), Effect.either) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) it.effect("mapInputEffect - error in transformation", () => @@ -93,7 +93,7 @@ describe("Sink", () => { ) ) const result = yield* $(Stream.make("1", "a"), Stream.run(sink), Effect.flip) - assert.deepStrictEqual(result.error, new Cause.RuntimeException("Cannot parse \"a\" to an integer")) + deepStrictEqual(result.error, new Cause.RuntimeException("Cannot parse \"a\" to an integer")) })) it.effect("mapInputChunksEffect - happy path", () => @@ -109,7 +109,7 @@ describe("Sink", () => { ) ) const result = yield* $(Stream.make("1", "2", "3"), Stream.run(sink)) - assert.deepStrictEqual(Array.from(result), [1, 2, 3]) + deepStrictEqual(Array.from(result), [1, 2, 3]) })) it.effect("mapInputChunksEffect - error", () => @@ -125,7 +125,7 @@ describe("Sink", () => { ) ) const result = yield* $(Stream.make("1", "2", "3"), Stream.run(sink), Effect.either) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) it.effect("mapInputChunksEffect - error in transformation", () => @@ -149,7 +149,7 @@ describe("Sink", () => { ) ) const result = yield* $(Stream.make("1", "a"), Stream.run(sink), Effect.flip) - assert.deepStrictEqual(result.error, new Cause.RuntimeException("Cannot parse \"a\" to an integer")) + deepStrictEqual(result.error, new Cause.RuntimeException("Cannot parse \"a\" to an integer")) })) it.effect("map", () => @@ -158,7 +158,7 @@ describe("Sink", () => { Stream.range(1, 9), Stream.run(pipe(Sink.succeed(1), Sink.map((n) => `${n}`))) ) - assert.strictEqual(result, "1") + strictEqual(result, "1") })) it.effect("mapEffect - happy path", () => @@ -167,7 +167,7 @@ describe("Sink", () => { Stream.range(1, 9), Stream.run(pipe(Sink.succeed(1), Sink.mapEffect((n) => Effect.succeed(n + 1)))) ) - assert.strictEqual(result, 2) + strictEqual(result, 2) })) it.effect("mapEffect - error", () => @@ -177,7 +177,7 @@ describe("Sink", () => { Stream.run(pipe(Sink.succeed(1), Sink.mapEffect(() => Effect.fail("fail")))), Effect.flip ) - assert.strictEqual(result, "fail") + strictEqual(result, "fail") })) it.effect("mapError", () => @@ -187,6 +187,6 @@ describe("Sink", () => { Stream.run(pipe(Sink.fail("fail"), Sink.mapError((s) => s + "!"))), Effect.either ) - assert.deepStrictEqual(result, Either.left("fail!")) + assertLeft(result, "fail!") })) }) diff --git a/packages/effect/test/Sink/racing.test.ts b/packages/effect/test/Sink/racing.test.ts index 4702159ad0c..c7a12ebf915 100644 --- a/packages/effect/test/Sink/racing.test.ts +++ b/packages/effect/test/Sink/racing.test.ts @@ -6,9 +6,10 @@ import * as Option from "effect/Option" import * as Random from "effect/Random" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { assertTrue } from "effect/test/util" import * as it from "effect/test/utils/extend" import { unfoldEffect } from "effect/test/utils/unfoldEffect" -import { assert, describe } from "vitest" +import { describe } from "vitest" const findSink = (a: A): Sink.Sink => pipe( @@ -73,6 +74,6 @@ describe("Sink", () => { findSink(40) ) ) - assert.isTrue(result) + assertTrue(result) })) }) diff --git a/packages/effect/test/Sink/refining.test.ts b/packages/effect/test/Sink/refining.test.ts index d9f7d005c43..0fe7f1eb0db 100644 --- a/packages/effect/test/Sink/refining.test.ts +++ b/packages/effect/test/Sink/refining.test.ts @@ -5,8 +5,9 @@ import { pipe } from "effect/Function" import * as Option from "effect/Option" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Sink", () => { it.effect("refineOrDie", () => @@ -22,7 +23,7 @@ describe("Sink", () => { ) ) const result = yield* $(Stream.make(1, 2, 3), Stream.run(sink), Effect.exit) - assert.deepStrictEqual(result, Exit.fail(refinedTo)) + deepStrictEqual(result, Exit.fail(refinedTo)) })) it.effect("refineOrDieWith - refines", () => @@ -37,7 +38,7 @@ describe("Sink", () => { Option.none(), (error) => error.message) ) const result = yield* $(Stream.make(1, 2, 3), Stream.run(sink), Effect.exit) - assert.deepStrictEqual(result, Exit.fail(refinedTo)) + deepStrictEqual(result, Exit.fail(refinedTo)) })) it.effect("refineOrDieWith - dies", () => @@ -52,6 +53,6 @@ describe("Sink", () => { Option.none(), (error) => error.message) ) const result = yield* $(Stream.make(1, 2, 3), Stream.run(sink), Effect.exit) - assert.deepStrictEqual(result, Exit.die("")) + deepStrictEqual(result, Exit.die("")) })) }) diff --git a/packages/effect/test/Sink/scoping.test.ts b/packages/effect/test/Sink/scoping.test.ts index e00b910ce5a..58d47d6674b 100644 --- a/packages/effect/test/Sink/scoping.test.ts +++ b/packages/effect/test/Sink/scoping.test.ts @@ -3,8 +3,9 @@ import { pipe } from "effect/Function" import * as Ref from "effect/Ref" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { assertFalse, assertTrue, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Sink", () => { it.effect("unwrapScoped - happy path", () => @@ -31,9 +32,9 @@ describe("Sink", () => { ) const [result, state] = yield* $(Stream.make(1, 2, 3), Stream.run(sink)) const finalState = yield* $(Ref.get(ref)) - assert.strictEqual(result, 103) - assert.isFalse(state) - assert.isTrue(finalState) + strictEqual(result, 103) + assertFalse(state) + assertTrue(finalState) })) it.effect("unwrapScoped - error", () => @@ -46,7 +47,7 @@ describe("Sink", () => { const sink = pipe(resource, Effect.as(Sink.succeed("ok")), Sink.unwrapScoped) const result = yield* $(Stream.fail("fail"), Stream.run(sink)) const finalState = yield* $(Ref.get(ref)) - assert.strictEqual(result, "ok") - assert.isTrue(finalState) + strictEqual(result, "ok") + assertTrue(finalState) })) }) diff --git a/packages/effect/test/Sink/sequencing.test.ts b/packages/effect/test/Sink/sequencing.test.ts index 1bf19a459a4..b4afd88956d 100644 --- a/packages/effect/test/Sink/sequencing.test.ts +++ b/packages/effect/test/Sink/sequencing.test.ts @@ -4,22 +4,23 @@ import { pipe } from "effect/Function" import * as Option from "effect/Option" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { assertNone, assertSome, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Sink", () => { it.effect("flatMap - empty input", () => Effect.gen(function*($) { const sink = pipe(Sink.head(), Sink.flatMap(Sink.succeed)) const result = yield* $(Stream.empty, Stream.run(sink)) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("flatMap - non-empty input", () => Effect.gen(function*($) { const sink = pipe(Sink.head(), Sink.flatMap(Sink.succeed)) const result = yield* $(Stream.make(1, 2, 3), Stream.run(sink)) - assert.deepStrictEqual(result, Option.some(1)) + assertSome(result, 1) })) it.effect("flatMap - with leftovers", () => @@ -40,8 +41,8 @@ describe("Sink", () => { ) ) const [option, count] = yield* $(Stream.fromChunks(...chunks), Stream.run(sink)) - assert.deepStrictEqual(option, Chunk.head(Chunk.flatten(chunks))) - assert.strictEqual( + deepStrictEqual(option, Chunk.head(Chunk.flatten(chunks))) + strictEqual( count + Option.match(option, { onNone: () => 0, onSome: () => 1 diff --git a/packages/effect/test/Sink/traversing.test.ts b/packages/effect/test/Sink/traversing.test.ts index 132b93f5964..f530085224d 100644 --- a/packages/effect/test/Sink/traversing.test.ts +++ b/packages/effect/test/Sink/traversing.test.ts @@ -5,8 +5,9 @@ import { identity, pipe } from "effect/Function" import * as Option from "effect/Option" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { assertNone, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Sink", () => { it.effect("findEffect - with head sink", () => @@ -29,7 +30,7 @@ describe("Sink", () => { ) ) ) - assert.isTrue(result.every(identity)) + assertTrue(result.every(identity)) })) it.effect("findEffect - take sink across multiple chunks", () => @@ -44,7 +45,7 @@ describe("Sink", () => { Stream.run(sink), Effect.map(Option.getOrElse(() => Chunk.empty())) ) - assert.deepStrictEqual(Array.from(result), [5, 6, 7, 8]) + deepStrictEqual(Array.from(result), [5, 6, 7, 8]) })) it.effect("findEffect - empty stream terminates with none", () => @@ -57,7 +58,7 @@ describe("Sink", () => { Stream.fromIterable([]), Stream.run(sink) ) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findEffect - unsatisfied condition terminates with none", () => @@ -73,7 +74,7 @@ describe("Sink", () => { Stream.fromIterable([1, 2]), Stream.run(sink) ) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("forEachWhile - handles leftovers", () => @@ -85,8 +86,8 @@ describe("Sink", () => { Sink.collectLeftover )) ) - assert.isUndefined(result) - assert.deepStrictEqual(Array.from(value), [4]) + strictEqual(result, undefined) + deepStrictEqual(Array.from(value), [4]) })) it.effect("splitWhere - should split a stream on a predicate and run each part into the sink", () => @@ -97,7 +98,7 @@ describe("Sink", () => { Stream.transduce(pipe(Sink.collectAll(), Sink.splitWhere((n) => n % 2 === 0))), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1], [2, 3], [4, 5], [6, 7], [8]] ) @@ -111,7 +112,7 @@ describe("Sink", () => { Stream.transduce(pipe(Sink.collectAll(), Sink.splitWhere((n) => n % 2 === 0))), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1], [2, 3], [4, 5], [6, 7], [8]] ) @@ -125,7 +126,7 @@ describe("Sink", () => { Stream.transduce(pipe(Sink.collectAll(), Sink.splitWhere((n) => n % 2 !== 0))), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1, 2], [3, 4], [5, 6], [7, 8]] ) diff --git a/packages/effect/test/Sink/zipping.test.ts b/packages/effect/test/Sink/zipping.test.ts index fc1221d01a5..2a3dc4e1d85 100644 --- a/packages/effect/test/Sink/zipping.test.ts +++ b/packages/effect/test/Sink/zipping.test.ts @@ -6,10 +6,10 @@ import * as Option from "effect/Option" import * as Random from "effect/Random" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { assertSome, assertTrue, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import { unfoldEffect } from "effect/test/utils/unfoldEffect" - -import { assert, describe } from "vitest" +import { describe } from "vitest" const findSink = (a: A): Sink.Sink => pipe( @@ -53,7 +53,7 @@ describe("Sink", () => { Sink.zipLeft(Sink.succeed("hello"), { concurrent: true }) )) ) - assert.deepStrictEqual(result, Option.some(1)) + assertSome(result, 1) })) it.effect("zipParRight", () => @@ -65,7 +65,7 @@ describe("Sink", () => { Sink.zipRight(Sink.succeed("hello"), { concurrent: true }) )) ) - assert.strictEqual(result, "hello") + strictEqual(result, "hello") })) it.effect("zipWithPar - coherence", () => @@ -89,6 +89,6 @@ describe("Sink", () => { findSink(40) ) ) - assert.isTrue(result) + assertTrue(result) })) }) diff --git a/packages/effect/test/SortedMap.test.ts b/packages/effect/test/SortedMap.test.ts index 9c3002c46c1..b26254af1ed 100644 --- a/packages/effect/test/SortedMap.test.ts +++ b/packages/effect/test/SortedMap.test.ts @@ -1,31 +1,27 @@ -import * as Eq from "effect/Equal" -import { pipe } from "effect/Function" -import * as Hash from "effect/Hash" -import * as N from "effect/Number" -import * as O from "effect/Option" -import * as SM from "effect/SortedMap" -import { assert, describe, expect, it } from "vitest" - -class Key implements Eq.Equal { +import { Equal, Hash, Number as N, pipe, SortedMap as SM } from "effect" +import { assertFalse, assertNone, assertSome, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" + +class Key implements Equal.Equal { constructor(readonly id: number) {} [Hash.symbol](): number { return Hash.hash(this.id) } - [Eq.symbol](u: unknown): boolean { + [Equal.symbol](u: unknown): boolean { return u instanceof Key && this.id === u.id } } -class Value implements Eq.Equal { +class Value implements Equal.Equal { constructor(readonly id: number) {} [Hash.symbol](): number { return Hash.hash(this.id) } - [Eq.symbol](u: unknown): boolean { + [Equal.symbol](u: unknown): boolean { return u instanceof Value && this.id === u.id } } @@ -53,7 +49,9 @@ describe("SortedMap", () => { it("toString", () => { const map = makeNumericSortedMap([0, 10], [1, 20], [2, 30]) - expect(String(map)).toEqual(`{ + strictEqual( + String(map), + `{ "_id": "SortedMap", "values": [ [ @@ -69,15 +67,14 @@ describe("SortedMap", () => { 30 ] ] -}`) +}` + ) }) it("toJSON", () => { const map = makeNumericSortedMap([0, 10], [1, 20], [2, 30]) - expect(map.toJSON()).toEqual( - { _id: "SortedMap", values: [[0, 10], [1, 20], [2, 30]] } - ) + deepStrictEqual(map.toJSON(), { _id: "SortedMap", values: [[0, 10], [1, 20], [2, 30]] }) }) it("inspect", () => { @@ -89,9 +86,7 @@ describe("SortedMap", () => { const map = makeNumericSortedMap([0, 10], [1, 20], [2, 30]) - expect(inspect(map)).toEqual( - inspect({ _id: "SortedMap", values: [[0, 10], [1, 20], [2, 30]] }) - ) + deepStrictEqual(inspect(map), inspect({ _id: "SortedMap", values: [[0, 10], [1, 20], [2, 30]] })) }) it("entries", () => { @@ -99,57 +94,57 @@ describe("SortedMap", () => { const result = Array.from(map) - expect([ + deepStrictEqual([ [key(0), value(10)], [key(1), value(20)], [key(2), value(30)] - ]).toEqual(result) + ], result) }) it("get", () => { const map = makeSortedMap([0, 10], [1, 20], [2, 30]) - assert.deepEqual(pipe(map, SM.get(key(0))), O.some(value(10))) - assert.deepEqual(pipe(map, SM.get(key(4))), O.none()) + assertSome(pipe(map, SM.get(key(0))), value(10)) + assertNone(pipe(map, SM.get(key(4)))) }) it("has", () => { const map = makeSortedMap([0, 10], [1, 20], [2, 30]) - assert.isTrue(pipe(map, SM.has(key(0)))) - assert.isFalse(pipe(map, SM.has(key(4)))) + assertTrue(pipe(map, SM.has(key(0)))) + assertFalse(pipe(map, SM.has(key(4)))) }) it("headOption", () => { const map1 = makeSortedMap([0, 10], [1, 20], [2, 30]) const map2 = SM.empty(N.Order) - assert.deepEqual(SM.headOption(map1), O.some([key(0), value(10)] as const)) - assert.deepEqual(SM.headOption(map2), O.none()) + assertSome(SM.headOption(map1), [key(0), value(10)]) + assertNone(SM.headOption(map2)) }) it("lastOption", () => { const map1 = makeSortedMap([0, 10], [1, 20], [2, 30]) const map2 = SM.empty(N.Order) - assert.deepEqual(SM.lastOption(map1), O.some([key(2), value(30)] as const)) - assert.deepEqual(SM.lastOption(map2), O.none()) + assertSome(SM.lastOption(map1), [key(2), value(30)]) + assertNone(SM.lastOption(map2)) }) it("isEmpty", () => { const map1 = makeSortedMap([0, 10], [1, 20], [2, 30]) const map2 = SM.empty(N.Order) - assert.isFalse(SM.isEmpty(map1)) - assert.isTrue(SM.isEmpty(map2)) + assertFalse(SM.isEmpty(map1)) + assertTrue(SM.isEmpty(map2)) }) it("isNonEmpty", () => { const map1 = makeSortedMap([0, 10], [1, 20], [2, 30]) const map2 = SM.empty(N.Order) - assert.isTrue(SM.isNonEmpty(map1)) - assert.isFalse(SM.isNonEmpty(map2)) + assertTrue(SM.isNonEmpty(map1)) + assertFalse(SM.isNonEmpty(map2)) }) it("map", () => { @@ -157,7 +152,7 @@ describe("SortedMap", () => { const result1 = Array.from(pipe(map1, SM.map((value) => value.id))) - assert.deepEqual( + deepStrictEqual( result1, [ [key(0), 10], @@ -170,7 +165,7 @@ describe("SortedMap", () => { const result2 = Array.from(pipe(map2, SM.map((key, value) => key.id + value.id))) - assert.deepEqual( + deepStrictEqual( result2, [ [key(0), 10], @@ -188,7 +183,7 @@ describe("SortedMap", () => { SM.partition((member) => member.id <= 3) ) - assert.deepEqual( + deepStrictEqual( Array.from(satisfying), [ [key(1), value(10)], @@ -196,7 +191,7 @@ describe("SortedMap", () => { [key(3), value(30)] ] ) - assert.deepEqual( + deepStrictEqual( Array.from(excl), [ [key(4), value(40)], @@ -209,7 +204,7 @@ describe("SortedMap", () => { SM.partition((member) => member.id <= 6) ) - assert.deepEqual( + deepStrictEqual( Array.from(satisfying2), [ [key(1), value(10)], @@ -220,7 +215,7 @@ describe("SortedMap", () => { ] ) - assert.deepEqual( + deepStrictEqual( Array.from(excl2), [] ) @@ -230,7 +225,7 @@ describe("SortedMap", () => { SM.partition((member) => member.id === 0) ) - assert.deepEqual( + deepStrictEqual( Array.from(excl3), [ [key(1), value(10)], @@ -241,7 +236,7 @@ describe("SortedMap", () => { ] ) - assert.deepEqual( + deepStrictEqual( Array.from(satisfying3), [] ) @@ -250,37 +245,37 @@ describe("SortedMap", () => { it("reduce", () => { const map1 = makeSortedMap([0, 10], [1, 20], [2, 30]) const result1 = pipe(map1, SM.reduce("", (acc, value) => acc + value.id)) - assert.strictEqual(result1, "102030") + strictEqual(result1, "102030") const map2 = makeSortedMap([0, 10], [1, 20], [2, 30]) const result2 = pipe(map2, SM.reduce("", (acc, value, key) => acc + key.id + value.id)) - assert.strictEqual(result2, "010120230") + strictEqual(result2, "010120230") }) it("remove", () => { const map = makeSortedMap([0, 10], [1, 20], [2, 30]) - assert.isTrue(pipe(map, SM.has(key(0)))) + assertTrue(pipe(map, SM.has(key(0)))) const result1 = pipe(map, SM.remove(key(0))) - assert.isFalse(pipe(result1, SM.has(key(0)))) + assertFalse(pipe(result1, SM.has(key(0)))) }) it("set", () => { const map = makeSortedMap([0, 10], [1, 20], [2, 30]) - assert.isFalse(pipe(map, SM.has(key(4)))) + assertFalse(pipe(map, SM.has(key(4)))) const result1 = pipe(map, SM.set(key(4), value(40))) - assert.isTrue(pipe(result1, SM.has(key(4)))) + assertTrue(pipe(result1, SM.has(key(4)))) }) it("size", () => { const map = makeSortedMap([0, 10], [1, 20], [2, 30]) - assert.strictEqual(SM.size(map), 3) + strictEqual(SM.size(map), 3) }) it("keys", () => { @@ -288,7 +283,7 @@ describe("SortedMap", () => { const result = Array.from(SM.keys(map)) - assert.deepEqual(result, [key(0), key(1), key(2)]) + deepStrictEqual(result, [key(0), key(1), key(2)]) }) it("values", () => { @@ -296,7 +291,7 @@ describe("SortedMap", () => { const result = Array.from(SM.values(map)) - assert.deepEqual(result, [value(10), value(20), value(30)]) + deepStrictEqual(result, [value(10), value(20), value(30)]) }) it("entries", () => { @@ -304,6 +299,6 @@ describe("SortedMap", () => { const result = Array.from(SM.entries(map)) - assert.deepEqual(result, [[key(0), value(10)], [key(1), value(20)], [key(2), value(30)]]) + deepStrictEqual(result, [[key(0), value(10)], [key(1), value(20)], [key(2), value(30)]]) }) }) diff --git a/packages/effect/test/SortedSet.test.ts b/packages/effect/test/SortedSet.test.ts index 400c3530c3c..9ee2f912384 100644 --- a/packages/effect/test/SortedSet.test.ts +++ b/packages/effect/test/SortedSet.test.ts @@ -1,19 +1,15 @@ -import * as Eq from "effect/Equal" -import { pipe } from "effect/Function" -import * as Hash from "effect/Hash" -import * as Order from "effect/Order" -import * as SortedSet from "effect/SortedSet" -import * as Str from "effect/String" -import { assert, describe, expect, it } from "vitest" - -class Member implements Eq.Equal { +import { Equal, Hash, Order, pipe, SortedSet, String as Str } from "effect" +import { assertFalse, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" + +class Member implements Equal.Equal { constructor(readonly id: string) {} [Hash.symbol](): number { return Hash.hash(this.id) } - [Eq.symbol](u: unknown): boolean { + [Equal.symbol](u: unknown): boolean { return u instanceof Member && this.id === u.id } } @@ -28,32 +24,35 @@ function makeNumericSortedSet( describe("SortedSet", () => { it("fromIterable", () => { - expect(Array.from(SortedSet.fromIterable(["c", "a", "b"], Str.Order))).toStrictEqual(["a", "b", "c"]) - expect(Array.from(pipe(["c", "a", "b"], SortedSet.fromIterable(Str.Order)))).toStrictEqual(["a", "b", "c"]) + deepStrictEqual(Array.from(SortedSet.fromIterable(["c", "a", "b"], Str.Order)), ["a", "b", "c"]) + deepStrictEqual(Array.from(pipe(["c", "a", "b"], SortedSet.fromIterable(Str.Order))), ["a", "b", "c"]) }) it("is", () => { const set = makeNumericSortedSet(0, 1, 2) const arr = Array.from(set) - expect(SortedSet.isSortedSet(set)).toBe(true) - expect(SortedSet.isSortedSet(arr)).toBe(false) + assertTrue(SortedSet.isSortedSet(set)) + assertFalse(SortedSet.isSortedSet(arr)) }) it("toString", () => { const set = makeNumericSortedSet(0, 1, 2) - expect(String(set)).toEqual(`{ + strictEqual( + String(set), + `{ "_id": "SortedSet", "values": [ 0, 1, 2 ] -}`) +}` + ) }) it("toJSON", () => { const set = makeNumericSortedSet(0, 1, 2) - expect(set.toJSON()).toEqual({ _id: "SortedSet", values: [0, 1, 2] }) + deepStrictEqual(set.toJSON(), { _id: "SortedSet", values: [0, 1, 2] }) }) it("inspect", () => { @@ -63,7 +62,7 @@ describe("SortedSet", () => { // eslint-disable-next-line @typescript-eslint/no-var-requires const { inspect } = require("node:util") const set = makeNumericSortedSet(0, 1, 2) - expect(inspect(set)).toEqual(inspect({ _id: "SortedSet", values: [0, 1, 2] })) + deepStrictEqual(inspect(set), inspect({ _id: "SortedSet", values: [0, 1, 2] })) }) it("add", () => { @@ -76,7 +75,7 @@ describe("SortedSet", () => { SortedSet.add(new Member("worker_000001")) ) - assert.deepEqual( + deepStrictEqual( Array.from(set), [ new Member("worker_000000"), @@ -106,14 +105,14 @@ describe("SortedSet", () => { new Member("worker_000002") ] - assert.deepEqual( + deepStrictEqual( Array.from(pipe( set1, SortedSet.difference(set2) )), [new Member("worker_000000")] ) - assert.deepEqual( + deepStrictEqual( Array.from(pipe(set1, SortedSet.difference(set3))), [] ) @@ -132,8 +131,8 @@ describe("SortedSet", () => { const result1 = pipe(set, SortedSet.every(isWorker)) const result2 = pipe(set, SortedSet.every(isWorker1)) - assert.isTrue(result1) - assert.isFalse(result2) + assertTrue(result1) + assertFalse(result2) }) it("some", () => { @@ -149,8 +148,8 @@ describe("SortedSet", () => { const result1 = pipe(set, SortedSet.some(isWorker1)) const result2 = pipe(set, SortedSet.some(isWorker4)) - assert.isTrue(result1) - assert.isFalse(result2) + assertTrue(result1) + assertFalse(result2) }) it("filter", () => { @@ -164,7 +163,7 @@ describe("SortedSet", () => { const result = pipe(set, SortedSet.filter(isWorker1)) - assert.deepEqual(Array.from(result), [new Member("worker_000001")]) + deepStrictEqual(Array.from(result), [new Member("worker_000001")]) }) it("flatMap", () => { @@ -183,7 +182,7 @@ describe("SortedSet", () => { const result = pipe(set1, SortedSet.flatMap(OrdMember, (a) => [...set2, a])) - assert.deepEqual( + deepStrictEqual( Array.from(result), [ new Member("worker_000000"), @@ -211,7 +210,7 @@ describe("SortedSet", () => { }) ) - assert.deepEqual(result, ["worker_000000", "worker_000001", "worker_000002"]) + deepStrictEqual(result, ["worker_000000", "worker_000001", "worker_000002"]) }) it("has", () => { @@ -222,8 +221,8 @@ describe("SortedSet", () => { SortedSet.add(new Member("worker_000002")) ) - assert.isTrue(pipe(set, SortedSet.has(new Member("worker_000000")))) - assert.isFalse(pipe(set, SortedSet.has(new Member("worker_000004")))) + assertTrue(pipe(set, SortedSet.has(new Member("worker_000000")))) + assertFalse(pipe(set, SortedSet.has(new Member("worker_000004")))) }) it("intersection", () => { @@ -247,14 +246,14 @@ describe("SortedSet", () => { const result1 = pipe(set1, SortedSet.intersection(set2)) const result2 = pipe(set1, SortedSet.intersection(set3)) - assert.deepEqual( + deepStrictEqual( Array.from(result1), [ new Member("worker_000001"), new Member("worker_000002") ] ) - assert.deepEqual(Array.from(result2), []) + deepStrictEqual(Array.from(result2), []) }) it("isSubset", () => { @@ -276,8 +275,8 @@ describe("SortedSet", () => { SortedSet.add(new Member("worker_000005")) ) - assert.isTrue(pipe(set2, SortedSet.isSubset(set1))) - assert.isFalse(pipe(set3, SortedSet.isSubset(set1))) + assertTrue(pipe(set2, SortedSet.isSubset(set1))) + assertFalse(pipe(set3, SortedSet.isSubset(set1))) }) it("map", () => { @@ -293,7 +292,7 @@ describe("SortedSet", () => { SortedSet.map(Str.Order, (member) => member.id.replace(/_\d+/g, "")) ) - assert.deepEqual(Array.from(result), ["worker"]) + deepStrictEqual(Array.from(result), ["worker"]) }) it("partition", () => { @@ -310,14 +309,14 @@ describe("SortedSet", () => { SortedSet.partition((member) => member.id.endsWith("1") || member.id.endsWith("3")) ) - assert.deepEqual( + deepStrictEqual( Array.from(result[0]), [ new Member("worker_000000"), new Member("worker_000002") ] ) - assert.deepEqual( + deepStrictEqual( Array.from(result[1]), [ new Member("worker_000001"), @@ -336,7 +335,7 @@ describe("SortedSet", () => { const result = pipe(set, SortedSet.remove(new Member("worker_000000"))) - assert.deepEqual( + deepStrictEqual( Array.from(result), [ new Member("worker_000001"), @@ -353,7 +352,7 @@ describe("SortedSet", () => { SortedSet.add(new Member("worker_000002")) ) - assert.strictEqual(SortedSet.size(set), 3) + strictEqual(SortedSet.size(set), 3) }) it("toggle", () => { @@ -365,15 +364,15 @@ describe("SortedSet", () => { SortedSet.add(new Member("worker_000002")) ) - assert.isTrue(pipe(set, SortedSet.has(member))) + assertTrue(pipe(set, SortedSet.has(member))) set = pipe(set, SortedSet.toggle(member)) - assert.isFalse(pipe(set, SortedSet.has(member))) + assertFalse(pipe(set, SortedSet.has(member))) set = pipe(set, SortedSet.toggle(member)) - assert.isTrue(pipe(set, SortedSet.has(member))) + assertTrue(pipe(set, SortedSet.has(member))) }) it("union", () => { @@ -396,7 +395,7 @@ describe("SortedSet", () => { const result1 = pipe(set1, SortedSet.union(set2)) const result2 = pipe(set1, SortedSet.union(set3)) - assert.deepEqual( + deepStrictEqual( Array.from(result1), [ new Member("worker_000000"), @@ -405,27 +404,27 @@ describe("SortedSet", () => { new Member("worker_000003") ] ) - expect(result2).toEqual(set1) + deepStrictEqual(result2, set1) }) it("values", () => { const set = SortedSet.make(Str.Order)("c", "a", "b") const values = SortedSet.values(set) - expect(Array.from(values)).toStrictEqual(["a", "b", "c"]) + deepStrictEqual(Array.from(values), ["a", "b", "c"]) }) it("pipe()", () => { - expect(SortedSet.make(Str.Order)("c", "a", "b").pipe(SortedSet.size)).toStrictEqual(3) + strictEqual(SortedSet.make(Str.Order)("c", "a", "b").pipe(SortedSet.size), 3) }) it("Equal.symbol", () => { - expect(Eq.equals(SortedSet.empty(Str.Order), SortedSet.empty(Str.Order))).toBe(true) + assertTrue(Equal.equals(SortedSet.empty(Str.Order), SortedSet.empty(Str.Order))) const set1 = SortedSet.make(Str.Order)("c", "a", "b") const set2 = SortedSet.make(Str.Order)("c", "a", "b") const set3 = SortedSet.make(Str.Order)("d", "b", "a") - expect(Eq.equals(set1, set2)).toBe(true) - expect(Eq.equals(set2, set1)).toBe(true) - expect(Eq.equals(set1, set3)).toBe(false) - expect(Eq.equals(set3, set1)).toBe(false) + assertTrue(Equal.equals(set1, set2)) + assertTrue(Equal.equals(set2, set1)) + assertFalse(Equal.equals(set1, set3)) + assertFalse(Equal.equals(set3, set1)) }) }) diff --git a/packages/effect/test/Stream/aggregation.test.ts b/packages/effect/test/Stream/aggregation.test.ts index 6679fee42cc..a3de13a7815 100644 --- a/packages/effect/test/Stream/aggregation.test.ts +++ b/packages/effect/test/Stream/aggregation.test.ts @@ -14,13 +14,12 @@ import * as Schedule from "effect/Schedule" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" import * as Take from "effect/Take" +import { assertTrue, deepStrictEqual } from "effect/test/util" import { chunkCoordination } from "effect/test/utils/coordination" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" import * as TestServices from "effect/TestServices" -import { assert, describe } from "vitest" - -Stream.onError +import { describe } from "vitest" describe("Stream", () => { it.effect("aggregate - simple example", () => @@ -32,8 +31,8 @@ describe("Stream", () => { ), Stream.runCollect ) - assert.deepStrictEqual(Array.from(Chunk.flatten(result)), [1, 1, 1, 1]) - assert.isTrue(Array.from(result).every((chunk) => chunk.length <= 3)) + deepStrictEqual(Array.from(Chunk.flatten(result)), [1, 1, 1, 1]) + assertTrue(Array.from(result).every((chunk) => chunk.length <= 3)) })) it.effect("aggregate - error propagation #1", () => @@ -45,7 +44,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.die(error)) + deepStrictEqual(result, Exit.die(error)) })) it.effect("aggregate - error propagation #2", () => @@ -59,7 +58,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.die(error)) + deepStrictEqual(result, Exit.die(error)) })) it.effect("aggregate - interruption propagation #1", () => @@ -85,7 +84,7 @@ describe("Stream", () => { yield* $(Deferred.await(latch)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("aggregate - interruption propagation #2", () => @@ -106,7 +105,7 @@ describe("Stream", () => { yield* $(Deferred.await(latch)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("aggregate - leftover handling", () => @@ -122,7 +121,7 @@ describe("Stream", () => { })), Stream.runCollect ) - assert.deepStrictEqual(Array.from(Chunk.flatten(result)), input) + deepStrictEqual(Array.from(Chunk.flatten(result)), input) })) it.effect("aggregate - ZIO issue 6395", () => @@ -132,7 +131,7 @@ describe("Stream", () => { Stream.aggregate(Sink.collectAllN(2)), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1, 2], [3]] ) @@ -162,7 +161,7 @@ describe("Stream", () => { Fiber.join(fiber), Effect.map(Chunk.filter(Chunk.isNonEmpty)) ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]] ) @@ -196,7 +195,7 @@ describe("Stream", () => { Effect.repeatN(3) ) const results = yield* $(Fiber.join(fiber), Effect.map(Chunk.compact)) - assert.deepStrictEqual(Array.from(results), [2, 3]) + deepStrictEqual(Array.from(results), [2, 3]) })) it.effect("aggregateWithinEither - simple example", () => @@ -221,7 +220,7 @@ describe("Stream", () => { ), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result), [Either.right([2, 1, 1, 1, 1]), Either.right([2])] ) @@ -248,7 +247,7 @@ describe("Stream", () => { ) const result = yield* $(Queue.takeAll(queue)) yield* $(Queue.shutdown(queue)) - assert.deepStrictEqual(Array.from(result), [1, 2, 3, 4, 5]) + deepStrictEqual(Array.from(result), [1, 2, 3, 4, 5]) })) it.effect("aggregateWithinEither - error propagation #1", () => @@ -263,7 +262,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.die(error)) + deepStrictEqual(result, Exit.die(error)) })) it.effect("aggregateWithinEither - error propagation #2", () => @@ -278,7 +277,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.die(error)) + deepStrictEqual(result, Exit.die(error)) })) it.effect("aggregateWithinEither - interruption propagation #1", () => @@ -304,7 +303,7 @@ describe("Stream", () => { yield* $(Deferred.await(latch)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("aggregateWithinEither - interruption propagation #2", () => @@ -325,7 +324,7 @@ describe("Stream", () => { yield* $(Deferred.await(latch)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("aggregateWithinEither - leftover handling", () => @@ -353,6 +352,6 @@ describe("Stream", () => { ) yield* $(TestClock.adjust(Duration.minutes(31))) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Array.from(result), input) + deepStrictEqual(Array.from(result), input) })) }) diff --git a/packages/effect/test/Stream/async.test.ts b/packages/effect/test/Stream/async.test.ts index 7b7e979f6d0..1e32039ea10 100644 --- a/packages/effect/test/Stream/async.test.ts +++ b/packages/effect/test/Stream/async.test.ts @@ -9,8 +9,9 @@ import * as Option from "effect/Option" import * as Ref from "effect/Ref" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { assertFalse, assertTrue, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("async", () => @@ -25,7 +26,7 @@ describe("Stream", () => { Stream.take(array.length), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), array) + deepStrictEqual(Array.from(result), array) })) it.effect("async - with cleanup", () => @@ -44,7 +45,7 @@ describe("Stream", () => { yield* $(Deferred.await(latch)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("async - signals the end of the stream", () => @@ -56,7 +57,7 @@ describe("Stream", () => { }), Stream.runCollect ) - assert.isTrue(Chunk.isEmpty(result)) + assertTrue(Chunk.isEmpty(result)) })) it.effect("async - handles errors", () => @@ -70,7 +71,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) it.effect("async - handles defects", () => @@ -83,7 +84,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.die(error)) + deepStrictEqual(result, Exit.die(error)) })) it.effect("async - backpressure", () => @@ -116,7 +117,7 @@ describe("Stream", () => { yield* $(Ref.get(refCount), Effect.repeat({ while: (n) => n !== 7 })) const result = yield* $(Ref.get(refDone)) yield* $(Fiber.interrupt(fiber), Effect.exit) - assert.isFalse(result) + assertFalse(result) })) it.effect("asyncEffect - simple example", () => @@ -139,7 +140,7 @@ describe("Stream", () => { ) yield* $(Deferred.await(latch)) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Array.from(result), array) + deepStrictEqual(Array.from(result), array) })) it.effect("asyncEffect - handles errors", () => @@ -153,7 +154,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) it.effect("asyncEffect - handles defects", () => @@ -166,7 +167,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.die(error)) + deepStrictEqual(result, Exit.die(error)) })) it.effect("asyncEffect - signals the end of the stream", () => @@ -178,7 +179,7 @@ describe("Stream", () => { }), Stream.runCollect ) - assert.isTrue(Chunk.isEmpty(result)) + assertTrue(Chunk.isEmpty(result)) })) it.effect("asyncEffect - backpressure", () => @@ -211,7 +212,7 @@ describe("Stream", () => { yield* $(Ref.get(refCount), Effect.repeat({ while: (n) => n !== 7 })) const result = yield* $(Ref.get(refDone)) yield* $(Fiber.interrupt(fiber)) - assert.isFalse(result) + assertFalse(result) })) // it.effect("asyncOption - signals the end of the stream", () => @@ -223,7 +224,7 @@ describe("Stream", () => { // }), // Stream.runCollect // ) - // assert.isTrue(Chunk.isEmpty(result)) + // assertTrue(Chunk.isEmpty(result)) // })) // it.effect("asyncOption - some", () => @@ -233,7 +234,7 @@ describe("Stream", () => { // Stream.asyncOption(() => Option.some(Stream.fromChunk(chunk))), // Stream.runCollect // ) - // assert.deepStrictEqual(Array.from(result), Array.from(chunk)) + // deepStrictEqual(Array.from(result), Array.from(chunk)) // })) // it.effect("asyncOption - none", () => @@ -249,7 +250,7 @@ describe("Stream", () => { // Stream.take(array.length), // Stream.runCollect // ) - // assert.deepStrictEqual(Array.from(result), array) + // deepStrictEqual(Array.from(result), array) // })) // it.effect("asyncOption - handles errors", () => @@ -263,7 +264,7 @@ describe("Stream", () => { // Stream.runCollect, // Effect.exit // ) - // assert.deepStrictEqual(result, Exit.fail(error)) + // deepStrictEqual(result, Exit.fail(error)) // })) // it.effect("asyncOption - handles defects", () => @@ -276,7 +277,7 @@ describe("Stream", () => { // Stream.runCollect, // Effect.exit // ) - // assert.deepStrictEqual(result, Exit.die(error)) + // deepStrictEqual(result, Exit.die(error)) // })) // it.effect("asyncOption - backpressure", () => @@ -309,7 +310,7 @@ describe("Stream", () => { // yield* $(Ref.get(refCount), Effect.repeat({ while: (n) => n !== 7 })) // const result = yield* $(Ref.get(refDone)) // yield* $(Fiber.interrupt(fiber), Effect.exit) - // assert.isFalse(result) + // assertFalse(result) // })) it.effect("asyncScoped", () => @@ -332,7 +333,7 @@ describe("Stream", () => { ) yield* $(Deferred.await(latch)) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Array.from(result), array) + deepStrictEqual(Array.from(result), array) })) it.effect("asyncScoped - signals the end of the stream", () => @@ -344,7 +345,7 @@ describe("Stream", () => { }), Stream.runCollect ) - assert.isTrue(Chunk.isEmpty(result)) + assertTrue(Chunk.isEmpty(result)) })) it.effect("asyncScoped - handles errors", () => @@ -358,7 +359,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) it.effect("asyncScoped - handles defects", () => @@ -371,7 +372,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.die(error)) + deepStrictEqual(result, Exit.die(error)) })) it.effect("asyncScoped - backpressure", () => @@ -404,7 +405,7 @@ describe("Stream", () => { yield* $(Ref.get(refCount), Effect.repeat({ while: (n) => n !== 7 })) const result = yield* $(Ref.get(refDone)) yield* $(Fiber.interrupt(fiber), Effect.exit) - assert.isFalse(result) + assertFalse(result) })) it.effect("asyncPush", () => @@ -426,7 +427,7 @@ describe("Stream", () => { ) yield* Deferred.await(latch) const result = yield* Fiber.join(fiber) - assert.deepStrictEqual(Array.from(result), array) + deepStrictEqual(Array.from(result), array) })) it.effect("asyncPush - signals the end of the stream", () => @@ -435,7 +436,7 @@ describe("Stream", () => { emit.end() return Effect.void }).pipe(Stream.runCollect) - assert.isTrue(Chunk.isEmpty(result)) + assertTrue(Chunk.isEmpty(result)) })) it.effect("asyncPush - handles errors", () => @@ -448,7 +449,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) it.effect("asyncPush - handles defects", () => @@ -460,6 +461,6 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.die(error)) + deepStrictEqual(result, Exit.die(error)) })) }) diff --git a/packages/effect/test/Stream/broadcasting.test.ts b/packages/effect/test/Stream/broadcasting.test.ts index e83cb7b220e..4867b2b9ed7 100644 --- a/packages/effect/test/Stream/broadcasting.test.ts +++ b/packages/effect/test/Stream/broadcasting.test.ts @@ -1,16 +1,16 @@ import * as Chunk from "effect/Chunk" import * as Deferred from "effect/Deferred" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import * as Fiber from "effect/Fiber" import { pipe } from "effect/Function" import * as Ref from "effect/Ref" import * as Schedule from "effect/Schedule" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { assertLeft, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("broadcast - values", () => @@ -27,8 +27,8 @@ describe("Stream", () => { Effect.scoped ) const expected = [0, 1, 2, 3, 4] - assert.deepStrictEqual(Array.from(result1), expected) - assert.deepStrictEqual(Array.from(result2), expected) + deepStrictEqual(Array.from(result1), expected) + deepStrictEqual(Array.from(result2), expected) })) it.effect("broadcast - errors", () => @@ -45,8 +45,8 @@ describe("Stream", () => { ), Effect.scoped ) - assert.deepStrictEqual(result1, Either.left("boom")) - assert.deepStrictEqual(result2, Either.left("boom")) + assertLeft(result1, "boom") + assertLeft(result2, "boom") })) it.effect("broadcast - backpressure", () => @@ -83,8 +83,8 @@ describe("Stream", () => { ), Effect.scoped ) - assert.deepStrictEqual(Array.from(result1), [0, 1]) - assert.deepStrictEqual(Array.from(result2), [0, 1, 2, 3, 4]) + deepStrictEqual(Array.from(result1), [0, 1]) + deepStrictEqual(Array.from(result2), [0, 1, 2, 3, 4]) })) it.effect("broadcast - unsubscribe", () => @@ -102,7 +102,7 @@ describe("Stream", () => { ), Effect.scoped ) - assert.deepStrictEqual(Array.from(result), [0, 1, 2, 3, 4]) + deepStrictEqual(Array.from(result), [0, 1, 2, 3, 4]) })) it.scoped("share sequenced", () => @@ -121,7 +121,7 @@ describe("Stream", () => { yield* TestClock.adjust("1 second") const first = yield* Fiber.join(firstFiber) - assert.deepStrictEqual(first, [0]) + deepStrictEqual(first, [0]) const secondFiber = yield* sharedStream.pipe( Stream.take(1), @@ -133,7 +133,7 @@ describe("Stream", () => { yield* TestClock.adjust("1 second") const second = yield* Fiber.join(secondFiber) - assert.deepStrictEqual(second, [0]) + deepStrictEqual(second, [0]) })) it.scoped("share sequenced with idleTimeToLive", () => @@ -155,7 +155,7 @@ describe("Stream", () => { yield* TestClock.adjust("1 second") const first = yield* Fiber.join(firstFiber) - assert.deepStrictEqual(first, [0]) + deepStrictEqual(first, [0]) const secondFiber = yield* sharedStream.pipe( Stream.take(1), @@ -167,7 +167,7 @@ describe("Stream", () => { yield* TestClock.adjust("1 second") const second = yield* Fiber.join(secondFiber) - assert.deepStrictEqual(second, [1]) + deepStrictEqual(second, [1]) })) it.scoped("share parallel", () => @@ -192,7 +192,7 @@ describe("Stream", () => { yield* TestClock.adjust("2 second") const [result1, result2] = yield* Fiber.joinAll([fiber1, fiber2]) - assert.deepStrictEqual(result1, [0]) - assert.deepStrictEqual(result2, [0, 1]) + deepStrictEqual(result1, [0]) + deepStrictEqual(result2, [0, 1]) })) }) diff --git a/packages/effect/test/Stream/buffering.test.ts b/packages/effect/test/Stream/buffering.test.ts index 7c1f6d5a8ba..f030a194318 100644 --- a/packages/effect/test/Stream/buffering.test.ts +++ b/packages/effect/test/Stream/buffering.test.ts @@ -6,8 +6,9 @@ import * as Exit from "effect/Exit" import { pipe } from "effect/Function" import * as Ref from "effect/Ref" import * as Stream from "effect/Stream" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("buffer - maintains elements and ordering", () => @@ -22,7 +23,7 @@ describe("Stream", () => { Stream.buffer({ capacity: 2 }), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), Array.from(Chunk.flatten(chunks))) + deepStrictEqual(Array.from(result), Array.from(Chunk.flatten(chunks))) })) it.effect("buffer - buffers a stream with a failure", () => @@ -35,7 +36,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) it.effect("buffer - fast producer progresses independently", () => @@ -58,8 +59,8 @@ describe("Stream", () => { const result1 = yield* $(stream, Stream.take(2), Stream.runCollect) yield* $(Deferred.await(latch)) const result2 = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result1), [1, 2]) - assert.deepStrictEqual(Array.from(result2), [1, 2, 3, 4]) + deepStrictEqual(Array.from(result1), [1, 2]) + deepStrictEqual(Array.from(result2), [1, 2, 3, 4]) })) it.effect("bufferChunks - maintains elements and ordering", () => @@ -74,7 +75,7 @@ describe("Stream", () => { Stream.bufferChunks({ capacity: 2 }), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), Array.from(Chunk.flatten(chunks))) + deepStrictEqual(Array.from(result), Array.from(Chunk.flatten(chunks))) })) it.effect("bufferChunks - buffers a stream with a failure", () => @@ -87,7 +88,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) it.effect("bufferChunks - fast producer progresses independently", () => @@ -110,8 +111,8 @@ describe("Stream", () => { const result1 = yield* $(stream, Stream.take(2), Stream.runCollect) yield* $(Deferred.await(latch)) const result2 = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result1), [1, 2]) - assert.deepStrictEqual(Array.from(result2), [1, 2, 3, 4]) + deepStrictEqual(Array.from(result1), [1, 2]) + deepStrictEqual(Array.from(result2), [1, 2, 3, 4]) })) it.effect("bufferChunksDropping - buffers a stream with a failure", () => @@ -125,7 +126,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) it.effect("bufferChunksDropping - fast producer progress independently", () => @@ -200,9 +201,9 @@ describe("Stream", () => { const expected1 = [0] const expected2 = [1, 2, 3, 4, 5, 6, 7, 8] const expected3 = [1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20, 21, 22, 23, 24] - assert.deepStrictEqual(Array.from(result1), expected1) - assert.deepStrictEqual(Array.from(result2), expected2) - assert.deepStrictEqual(Array.from(result3), expected3) + deepStrictEqual(Array.from(result1), expected1) + deepStrictEqual(Array.from(result2), expected2) + deepStrictEqual(Array.from(result3), expected3) })) it.effect("bufferChunksSliding - buffers a stream with a failure", () => @@ -216,7 +217,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) it.effect("bufferChunksSliding - fast producer progress independently", () => @@ -291,9 +292,9 @@ describe("Stream", () => { const expected1 = [0] const expected2 = [9, 10, 11, 12, 13, 14, 15, 16] const expected3 = [9, 10, 11, 12, 13, 14, 15, 16, 18, 19, 20, 21, 22, 23, 24, 25] - assert.deepStrictEqual(Array.from(result1), expected1) - assert.deepStrictEqual(Array.from(result2), expected2) - assert.deepStrictEqual(Array.from(result3), expected3) + deepStrictEqual(Array.from(result1), expected1) + deepStrictEqual(Array.from(result2), expected2) + deepStrictEqual(Array.from(result3), expected3) })) it.effect("bufferDropping - buffers a stream with a failure", () => @@ -307,7 +308,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) it.effect("bufferDropping - fast producer progress independently", () => @@ -382,9 +383,9 @@ describe("Stream", () => { const expected1 = [0] const expected2 = [1, 2, 3, 4, 5, 6, 7, 8] const expected3 = [1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20, 21, 22, 23, 24] - assert.deepStrictEqual(Array.from(result1), expected1) - assert.deepStrictEqual(Array.from(result2), expected2) - assert.deepStrictEqual(Array.from(result3), expected3) + deepStrictEqual(Array.from(result1), expected1) + deepStrictEqual(Array.from(result2), expected2) + deepStrictEqual(Array.from(result3), expected3) })) it.effect("bufferSliding - buffers a stream with a failure", () => @@ -398,7 +399,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) it.effect("bufferSliding - fast producer progress independently", () => @@ -469,9 +470,9 @@ describe("Stream", () => { const expected1 = [0] const expected2 = [9, 10, 11, 12, 13, 14, 15, 16] const expected3 = [9, 10, 11, 12, 13, 14, 15, 16, 18, 19, 20, 21, 22, 23, 24, -1] - assert.deepStrictEqual(Array.from(result1), expected1) - assert.deepStrictEqual(Array.from(result2), expected2) - assert.deepStrictEqual(Array.from(result3), expected3) + deepStrictEqual(Array.from(result1), expected1) + deepStrictEqual(Array.from(result2), expected2) + deepStrictEqual(Array.from(result3), expected3) })) it.effect("bufferSliding - propagates defects", () => @@ -482,7 +483,7 @@ describe("Stream", () => { Stream.runDrain, Effect.exit ) - assert.deepStrictEqual(result, Exit.die(new Cause.RuntimeException("boom"))) + deepStrictEqual(result, Exit.die(new Cause.RuntimeException("boom"))) })) it.effect("bufferUnbounded - buffers the stream", () => @@ -493,7 +494,7 @@ describe("Stream", () => { Stream.buffer({ capacity: "unbounded" }), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), Array.from(chunk)) + deepStrictEqual(Array.from(result), Array.from(chunk)) })) it.effect("bufferUnbounded - buffers a stream with a failure", () => @@ -506,7 +507,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) it.effect("bufferUnbounded - fast producer progress independently", () => @@ -527,7 +528,7 @@ describe("Stream", () => { const result1 = yield* $(stream, Stream.take(2), Stream.runCollect) yield* $(Deferred.await(latch)) const result2 = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result1), [1, 2]) - assert.deepStrictEqual(Array.from(result2), Array.from(Chunk.range(1, 999))) + deepStrictEqual(Array.from(result1), [1, 2]) + deepStrictEqual(Array.from(result2), Array.from(Chunk.range(1, 999))) })) }) diff --git a/packages/effect/test/Stream/changing.test.ts b/packages/effect/test/Stream/changing.test.ts index 1aecfcb9ece..96211cfd98c 100644 --- a/packages/effect/test/Stream/changing.test.ts +++ b/packages/effect/test/Stream/changing.test.ts @@ -1,8 +1,9 @@ import * as Chunk from "effect/Chunk" import * as Effect from "effect/Effect" import * as Stream from "effect/Stream" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("changes", () => @@ -19,7 +20,7 @@ describe("Stream", () => { Effect.map(Chunk.reduce(Chunk.empty(), (acc, n) => acc.length === 0 || Chunk.unsafeGet(acc, 0) !== n ? Chunk.append(acc, n) : acc)) ) - assert.deepStrictEqual(Array.from(result), Array.from(expected)) + deepStrictEqual(Array.from(result), Array.from(expected)) })) it.effect("changesWithEffect", () => @@ -36,6 +37,6 @@ describe("Stream", () => { Effect.map(Chunk.reduce(Chunk.empty(), (acc, n) => acc.length === 0 || Chunk.unsafeGet(acc, 0) !== n ? Chunk.append(acc, n) : acc)) ) - assert.deepStrictEqual(Array.from(result), Array.from(expected)) + deepStrictEqual(Array.from(result), Array.from(expected)) })) }) diff --git a/packages/effect/test/Stream/collecting.test.ts b/packages/effect/test/Stream/collecting.test.ts index 739b3994fa4..bc7d3c4714c 100644 --- a/packages/effect/test/Stream/collecting.test.ts +++ b/packages/effect/test/Stream/collecting.test.ts @@ -4,8 +4,9 @@ import * as Either from "effect/Either" import { identity } from "effect/Function" import * as Option from "effect/Option" import * as Stream from "effect/Stream" +import { assertLeft, assertRight, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("collect", () => @@ -19,7 +20,7 @@ describe("Stream", () => { ), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [2]) + deepStrictEqual(Array.from(result), [2]) })) it.effect("collectEffect - simple example", () => @@ -33,7 +34,7 @@ describe("Stream", () => { ), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [4]) + deepStrictEqual(Array.from(result), [4]) })) it.effect("collectEffect - multiple chunks", () => @@ -51,7 +52,7 @@ describe("Stream", () => { ), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [20, 30]) + deepStrictEqual(Array.from(result), [20, 30]) })) it.effect("collectEffect - handles failures", () => @@ -62,7 +63,7 @@ describe("Stream", () => { Stream.runDrain, Effect.either ) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) it.effect("collectEffect - laziness on chunks", () => @@ -77,7 +78,7 @@ describe("Stream", () => { Stream.either, Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result), [Either.right(1), Either.right(2), Either.left("boom")] ) @@ -90,7 +91,7 @@ describe("Stream", () => { Stream.filterMapWhile(identity), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 2]) + deepStrictEqual(Array.from(result), [1, 2]) })) it.effect("collectWhile - short circuits", () => @@ -102,7 +103,7 @@ describe("Stream", () => { Stream.runDrain, Effect.either ) - assert.deepStrictEqual(result, Either.right(void 0)) + assertRight(result, void 0) })) it.effect("collectWhileEffect - simple example", () => @@ -116,7 +117,7 @@ describe("Stream", () => { ), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [2, 4]) + deepStrictEqual(Array.from(result), [2, 4]) })) it.effect("collectWhileEffect - short circuits", () => @@ -132,7 +133,7 @@ describe("Stream", () => { Stream.runDrain, Effect.either ) - assert.deepStrictEqual(result, Either.right(void 0)) + assertRight(result, void 0) })) it.effect("collectWhileEffect - fails", () => @@ -143,7 +144,7 @@ describe("Stream", () => { Stream.runDrain, Effect.either ) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) it.effect("collectWhileEffect - laziness on chunks", () => @@ -158,7 +159,7 @@ describe("Stream", () => { Stream.either, Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result), [Either.right(1), Either.right(2), Either.left("boom")] ) diff --git a/packages/effect/test/Stream/concatenation.test.ts b/packages/effect/test/Stream/concatenation.test.ts index a37568e7b78..5decc52d036 100644 --- a/packages/effect/test/Stream/concatenation.test.ts +++ b/packages/effect/test/Stream/concatenation.test.ts @@ -3,8 +3,9 @@ import * as Effect from "effect/Effect" import { pipe } from "effect/Function" import * as Ref from "effect/Ref" import * as Stream from "effect/Stream" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("concat - simple example", () => @@ -26,7 +27,7 @@ describe("Stream", () => { Stream.runCollect ) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("concat - finalizer ordering", () => @@ -38,6 +39,6 @@ describe("Stream", () => { Stream.runDrain ) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), ["Second", "First"]) + deepStrictEqual(Array.from(result), ["Second", "First"]) })) }) diff --git a/packages/effect/test/Stream/conditionals.test.ts b/packages/effect/test/Stream/conditionals.test.ts index 1c2be90892b..126a71675fe 100644 --- a/packages/effect/test/Stream/conditionals.test.ts +++ b/packages/effect/test/Stream/conditionals.test.ts @@ -1,14 +1,12 @@ import * as Cause from "effect/Cause" import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" -import * as Stream from "effect/Stream" -import * as it from "effect/test/utils/extend" -// import * as Chunk from "effect/Chunk" -// import * as Either from "effect/Either" import { constFalse, constTrue, constVoid, pipe } from "effect/Function" import * as Option from "effect/Option" -// import * as fc from "fast-check" -import { assert, describe } from "vitest" +import * as Stream from "effect/Stream" +import { deepStrictEqual } from "effect/test/util" +import * as it from "effect/test/utils/extend" +import { describe } from "vitest" describe("Stream", () => { it.effect("when - returns the stream if the condition is satisfied", () => @@ -18,7 +16,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.when(constTrue), Stream.runCollect), result2: Stream.runCollect(stream) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("when - returns an empty stream if the condition is not satisfied", () => @@ -28,7 +26,7 @@ describe("Stream", () => { Stream.when(constFalse), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), []) + deepStrictEqual(Array.from(result), []) })) it.effect("when - dies if the condition throws an exception", () => @@ -42,7 +40,7 @@ describe("Stream", () => { Stream.runDrain, Effect.exit ) - assert.deepStrictEqual(result, Exit.die(error)) + deepStrictEqual(result, Exit.die(error)) })) it.effect("whenCase - returns the resulting stream if the given partial function is defined for the given value", () => @@ -57,7 +55,7 @@ describe("Stream", () => { ), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1]) + deepStrictEqual(Array.from(result), [1]) })) it.effect("whenCase - returns an empty stream if the given partial function is not defined for the given value", () => @@ -72,7 +70,7 @@ describe("Stream", () => { ), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), []) + deepStrictEqual(Array.from(result), []) })) it.effect("whenCase - dies if evaluating the given value throws an exception", () => @@ -88,7 +86,7 @@ describe("Stream", () => { Stream.runDrain, Effect.exit ) - assert.deepStrictEqual(result, Exit.die(error)) + deepStrictEqual(result, Exit.die(error)) })) it.effect("whenCase - dies if the partial function throws an exception", () => @@ -104,7 +102,7 @@ describe("Stream", () => { Stream.runDrain, Effect.exit ) - assert.deepStrictEqual(result, Exit.die(error)) + deepStrictEqual(result, Exit.die(error)) })) it.effect("whenCaseEffect - returns the resulting stream if the given partial function is defined for the given effectful value", () => @@ -119,7 +117,7 @@ describe("Stream", () => { ), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1]) + deepStrictEqual(Array.from(result), [1]) })) it.effect("whenCaseEffect - returns an empty stream if the given partial function is not defined for the given effectful value", () => @@ -134,7 +132,7 @@ describe("Stream", () => { ), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), []) + deepStrictEqual(Array.from(result), []) })) it.effect("whenCaseEffect - fails if the effectful value is a failure", () => @@ -146,7 +144,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) it.effect("whenCaseEffect - dies if the given partial function throws an exception", () => @@ -160,7 +158,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.die(error)) + deepStrictEqual(result, Exit.die(error)) })) it.effect("whenEffect - returns the stream if the effectful condition is satisfied", () => @@ -170,7 +168,7 @@ describe("Stream", () => { Stream.whenEffect(Effect.succeed(true)), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 2, 3, 4, 5]) + deepStrictEqual(Array.from(result), [1, 2, 3, 4, 5]) })) it.effect("whenEffect - returns an empty stream if the effectful condition is not satisfied", () => @@ -180,7 +178,7 @@ describe("Stream", () => { Stream.whenEffect(Effect.succeed(false)), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), []) + deepStrictEqual(Array.from(result), []) })) it.effect("whenEffect - fails if the effectful condition fails", () => @@ -192,6 +190,6 @@ describe("Stream", () => { Stream.runDrain, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) }) diff --git a/packages/effect/test/Stream/constructors.test.ts b/packages/effect/test/Stream/constructors.test.ts index f5aea08fec4..5190be9cb82 100644 --- a/packages/effect/test/Stream/constructors.test.ts +++ b/packages/effect/test/Stream/constructors.test.ts @@ -10,11 +10,12 @@ import * as Queue from "effect/Queue" import * as Ref from "effect/Ref" import * as Schedule from "effect/Schedule" import * as Stream from "effect/Stream" +import { assertFalse, assertLeft, assertTrue, deepStrictEqual } from "effect/test/util" import { chunkCoordination } from "effect/test/utils/coordination" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" import * as fc from "fast-check" -import { assert, describe, expect } from "vitest" +import { describe } from "vitest" const chunkArb = ( arb: fc.Arbitrary, @@ -39,7 +40,7 @@ describe("Stream", () => { ) const actual = await Effect.runPromise(Stream.runCollect(stream)) const expected = Chunk.flatten(Chunk.fromIterable(chunks)) - assert.deepStrictEqual(Array.from(actual), Array.from(expected)) + deepStrictEqual(Array.from(actual), Array.from(expected)) }))) it.effect("finalizer - happy path", () => @@ -55,7 +56,7 @@ describe("Stream", () => { Stream.runDrain ) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), ["Acquire", "Use", "Release", "Ensuring"]) + deepStrictEqual(Array.from(result), ["Acquire", "Use", "Release", "Ensuring"]) })) it.effect("finalizer - finalizer is not run if stream is not pulled", () => @@ -67,21 +68,21 @@ describe("Stream", () => { Effect.scoped ) const result = yield* $(Ref.get(ref)) - assert.isFalse(result) + assertFalse(result) })) it.it("fromChunk", () => fc.assert(fc.asyncProperty(chunkArb(fc.integer()), async (chunk) => { const stream = Stream.fromChunk(chunk) const result = await Effect.runPromise(Stream.runCollect(stream)) - assert.deepStrictEqual(Array.from(result), Array.from(chunk)) + deepStrictEqual(Array.from(result), Array.from(chunk)) }))) it.it("fromChunks", () => fc.assert(fc.asyncProperty(fc.array(chunkArb(fc.integer())), async (chunks) => { const stream = Stream.fromChunks(...chunks) const result = await Effect.runPromise(Stream.runCollect(stream)) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result), Array.from(Chunk.flatten(Chunk.fromIterable(chunks))) ) @@ -101,7 +102,7 @@ describe("Stream", () => { ), Effect.scoped ) - assert.deepStrictEqual(Array.from(result), [ + deepStrictEqual(Array.from(result), [ Either.right([1]), Either.right([1]), Either.left(Option.none()) @@ -115,7 +116,7 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left("error")) + assertLeft(result, "error") })) it.effect("fromEffectOption - emit one element with success", () => @@ -124,7 +125,7 @@ describe("Stream", () => { Stream.fromEffectOption(Effect.succeed(5)), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [5]) + deepStrictEqual(Array.from(result), [5]) })) it.effect("fromEffectOption - emit one element with failure", () => @@ -134,7 +135,7 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left(5)) + assertLeft(result, 5) })) it.effect("fromEffectOption - do not emit any element", () => @@ -143,7 +144,7 @@ describe("Stream", () => { Stream.fromEffectOption(Effect.fail(Option.none())), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), []) + deepStrictEqual(Array.from(result), []) })) it.effect("fromSchedule", () => @@ -166,7 +167,7 @@ describe("Stream", () => { Duration.seconds(8), Duration.seconds(16) ] - assert.deepStrictEqual(Array.from(result), expected) + deepStrictEqual(Array.from(result), expected) })) it.effect("fromQueue - emits queued elements", () => @@ -185,7 +186,7 @@ describe("Stream", () => { ) yield* $(coordination.offer) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Array.from(result), [1, 2]) + deepStrictEqual(Array.from(result), [1, 2]) })) it.effect("fromQueue - chunks up to the max chunk size", () => @@ -198,7 +199,7 @@ describe("Stream", () => { Stream.take(3), Stream.runCollect ) - assert.isTrue(Array.from(result).every((array) => array.length <= 2)) + assertTrue(Array.from(result).every((array) => array.length <= 2)) })) it.effect("fromAsyncIterable", () => @@ -211,7 +212,7 @@ describe("Stream", () => { const stream = Stream.fromAsyncIterable(asyncIterable(), identity) const result = yield* $(Stream.runCollect(stream)) - assert.deepStrictEqual(Array.from(result), [1, 2, 3]) + deepStrictEqual(Array.from(result), [1, 2, 3]) })) it.effect("fromReadableStream", () => @@ -237,7 +238,7 @@ describe("Stream", () => { Stream.runCollect ) - expect(Array.from(result)).toEqual(Array.from({ length: 10 }, (_, i) => i)) + deepStrictEqual(Array.from(result), Array.from({ length: 10 }, (_, i) => i)) })) it.effect("iterate", () => @@ -247,13 +248,13 @@ describe("Stream", () => { Stream.take(10), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), Array.from(Chunk.range(1, 10))) + deepStrictEqual(Array.from(result), Array.from(Chunk.range(1, 10))) })) it.effect("range - includes both endpoints", () => Effect.gen(function*($) { const result = yield* $(Stream.runCollect(Stream.range(1, 2))) - assert.deepStrictEqual(Array.from(result), [1, 2]) + deepStrictEqual(Array.from(result), [1, 2]) })) it.effect("range - two large ranges can be concatenated", () => @@ -263,7 +264,7 @@ describe("Stream", () => { Stream.concat(Stream.range(1_001, 2_000)), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), Array.from(Chunk.range(1, 2000))) + deepStrictEqual(Array.from(result), Array.from(Chunk.range(1, 2000))) })) it.effect("range - two small ranges can be concatenated", () => @@ -273,7 +274,7 @@ describe("Stream", () => { Stream.concat(Stream.range(11, 20)), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), Array.from(Chunk.range(1, 20))) + deepStrictEqual(Array.from(result), Array.from(Chunk.range(1, 20))) })) it.effect("range - emits no values when start > end", () => @@ -282,7 +283,7 @@ describe("Stream", () => { Stream.range(2, 1), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), []) + deepStrictEqual(Array.from(result), []) })) it.effect("range - emits 1 value when start === end", () => @@ -291,7 +292,7 @@ describe("Stream", () => { Stream.range(1, 1), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1]) + deepStrictEqual(Array.from(result), [1]) })) it.effect("range - emits values in chunks of chunkSize", () => @@ -301,7 +302,7 @@ describe("Stream", () => { Stream.mapChunks((chunk) => Chunk.make(pipe(chunk, Chunk.reduce(0, (x, y) => x + y)))), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result), [1 + 2, 3 + 4, 5 + 6, 7 + 8, 9] ) @@ -317,7 +318,7 @@ describe("Stream", () => { ) const actual = await Effect.runPromise(Stream.runCollect(stream)) const expected = chunks.map((chunk) => Array.from(chunk)).flat() - assert.deepStrictEqual( + deepStrictEqual( Array.from(actual).map((chunk) => Array.from(chunk)), grouped(expected, n) ) @@ -333,7 +334,7 @@ describe("Stream", () => { Option.none()), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), Array.from(Chunk.range(0, 9))) + deepStrictEqual(Array.from(result), Array.from(Chunk.range(0, 9))) })) it.effect("unfoldChunk", () => @@ -345,7 +346,7 @@ describe("Stream", () => { Option.none()), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), Array.from(Chunk.range(0, 9))) + deepStrictEqual(Array.from(result), Array.from(Chunk.range(0, 9))) })) it.effect("unfoldChunkEffect", () => @@ -357,7 +358,7 @@ describe("Stream", () => { Effect.succeed(Option.none())), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), Array.from(Chunk.range(0, 9))) + deepStrictEqual(Array.from(result), Array.from(Chunk.range(0, 9))) })) it.effect("unfoldEffect", () => @@ -369,6 +370,6 @@ describe("Stream", () => { Effect.succeed(Option.none())), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), Array.from(Chunk.range(0, 9))) + deepStrictEqual(Array.from(result), Array.from(Chunk.range(0, 9))) })) }) diff --git a/packages/effect/test/Stream/conversions.test.ts b/packages/effect/test/Stream/conversions.test.ts index cda19870210..3d720045086 100644 --- a/packages/effect/test/Stream/conversions.test.ts +++ b/packages/effect/test/Stream/conversions.test.ts @@ -6,8 +6,9 @@ import { pipe } from "effect/Function" import * as Queue from "effect/Queue" import * as Stream from "effect/Stream" import * as Take from "effect/Take" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("toQueue", () => @@ -34,7 +35,7 @@ describe("Stream", () => { Chunk.map(Take.of), Chunk.append(Take.end) ) - assert.deepStrictEqual(Array.from(result), Array.from(expected)) + deepStrictEqual(Array.from(result), Array.from(expected)) })) it.effect("toQueueUnbounded", () => @@ -60,7 +61,7 @@ describe("Stream", () => { Chunk.map(Take.of), Chunk.append(Take.end) ) - assert.deepStrictEqual(Array.from(result), Array.from(expected)) + deepStrictEqual(Array.from(result), Array.from(expected)) })) it.effect("toQueueOfElements - propagates defects", () => @@ -71,6 +72,6 @@ describe("Stream", () => { Effect.flatMap(Queue.take), Effect.scoped ) - assert.deepStrictEqual(queue, Exit.die(new Cause.RuntimeException("die"))) + deepStrictEqual(queue, Exit.die(new Cause.RuntimeException("die"))) })) }) diff --git a/packages/effect/test/Stream/distributing.test.ts b/packages/effect/test/Stream/distributing.test.ts index 030e56d92dc..772dbcc29da 100644 --- a/packages/effect/test/Stream/distributing.test.ts +++ b/packages/effect/test/Stream/distributing.test.ts @@ -4,8 +4,9 @@ import * as Exit from "effect/Exit" import { constTrue, pipe } from "effect/Function" import * as Option from "effect/Option" import * as Stream from "effect/Stream" +import { strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("distributedWithDynamic - ensures no race between subscription and stream end", () => @@ -46,6 +47,6 @@ describe("Stream", () => { }), Effect.scoped ) - assert.isUndefined(result) + strictEqual(result, undefined) })) }) diff --git a/packages/effect/test/Stream/draining.test.ts b/packages/effect/test/Stream/draining.test.ts index 2616efdde7f..03a2ceb06fc 100644 --- a/packages/effect/test/Stream/draining.test.ts +++ b/packages/effect/test/Stream/draining.test.ts @@ -2,13 +2,13 @@ import * as Cause from "effect/Cause" import * as Chunk from "effect/Chunk" import * as Deferred from "effect/Deferred" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import * as Exit from "effect/Exit" import { pipe } from "effect/Function" import * as Ref from "effect/Ref" import * as Stream from "effect/Stream" +import { assertLeft, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("drain - simple example", () => @@ -21,7 +21,7 @@ describe("Stream", () => { Stream.runDrain ) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), Array.from(Chunk.range(0, 9))) + deepStrictEqual(Array.from(result), Array.from(Chunk.range(0, 9))) })) it.effect("drain - is not too eager", () => @@ -35,8 +35,8 @@ describe("Stream", () => { Effect.either ) const result2 = yield* $(Ref.get(ref)) - assert.deepStrictEqual(result1, Either.left("fail")) - assert.strictEqual(result2, 1) + assertLeft(result1, "fail") + strictEqual(result2, 1) })) it.effect("drainFork - runs the other stream in the background", () => @@ -47,7 +47,7 @@ describe("Stream", () => { Stream.drainFork(Stream.fromEffect(Deferred.succeed(latch, void 0))), Stream.runDrain ) - assert.isUndefined(result) + strictEqual(result, undefined) })) it.effect("drainFork - interrupts the background stream when the foreground exits", () => @@ -68,7 +68,7 @@ describe("Stream", () => { Stream.runDrain ) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("drainFork - fails the foreground stream if the background fails with a typed error", () => @@ -79,7 +79,7 @@ describe("Stream", () => { Stream.runDrain, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail("boom")) + deepStrictEqual(result, Exit.fail("boom")) })) it.effect("drainFork - fails the foreground stream if the background fails with a defect", () => @@ -91,6 +91,6 @@ describe("Stream", () => { Stream.runDrain, Effect.exit ) - assert.deepStrictEqual(result, Exit.die(error)) + deepStrictEqual(result, Exit.die(error)) })) }) diff --git a/packages/effect/test/Stream/dropping.test.ts b/packages/effect/test/Stream/dropping.test.ts index 3cc9010b075..954c36a55fa 100644 --- a/packages/effect/test/Stream/dropping.test.ts +++ b/packages/effect/test/Stream/dropping.test.ts @@ -1,10 +1,10 @@ import * as Chunk from "effect/Chunk" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import { constTrue, pipe } from "effect/Function" import * as Stream from "effect/Stream" +import { assertLeft, assertRight, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("drop - simple example", () => @@ -15,7 +15,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.drop(n), Stream.runCollect), result2: pipe(stream, Stream.runCollect, Effect.map(Chunk.drop(n))) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("drop - does not swallow errors", () => @@ -27,7 +27,7 @@ describe("Stream", () => { Stream.runDrain, Effect.either ) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) it.effect("dropRight - simple example", () => @@ -38,7 +38,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.dropRight(n), Stream.runCollect), result2: pipe(stream, Stream.runCollect, Effect.map(Chunk.dropRight(n))) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("dropRight - does not swallow errors", () => @@ -50,7 +50,7 @@ describe("Stream", () => { Stream.runDrain, Effect.either ) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) it.effect("dropUntil", () => @@ -64,7 +64,7 @@ describe("Stream", () => { Effect.map((chunk) => pipe(chunk, Chunk.dropWhile((n) => !f(n)), Chunk.drop(1))) ) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("dropWhile", () => @@ -75,7 +75,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.dropWhile(f), Stream.runCollect), result2: pipe(stream, Stream.runCollect, Effect.map(Chunk.dropWhile(f))) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("dropWhile - short circuits", () => @@ -88,6 +88,6 @@ describe("Stream", () => { Stream.runDrain, Effect.either ) - assert.deepStrictEqual(result, Either.right(void 0)) + assertRight(result, void 0) })) }) diff --git a/packages/effect/test/Stream/encoding.test.ts b/packages/effect/test/Stream/encoding.test.ts index 836e24e52a2..c8414f1c491 100644 --- a/packages/effect/test/Stream/encoding.test.ts +++ b/packages/effect/test/Stream/encoding.test.ts @@ -1,8 +1,9 @@ import * as Chunk from "effect/Chunk" import * as Effect from "effect/Effect" import * as Stream from "effect/Stream" +import { deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { describe, expect } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("decodeText/encodeText round trip", () => @@ -13,12 +14,12 @@ describe("Stream", () => { Stream.encodeText, Stream.runCollect ) - expect(encoded.length).toEqual(9) + strictEqual(encoded.length, 9) const decoded = yield* _( Stream.fromChunk(encoded), Stream.decodeText(), Stream.runCollect ) - expect(Chunk.toReadonlyArray(decoded)).toEqual(items) + deepStrictEqual(Chunk.toReadonlyArray(decoded), items) })) }) diff --git a/packages/effect/test/Stream/environment.test.ts b/packages/effect/test/Stream/environment.test.ts index cdda7838b18..3bf02404000 100644 --- a/packages/effect/test/Stream/environment.test.ts +++ b/packages/effect/test/Stream/environment.test.ts @@ -6,9 +6,10 @@ import * as Exit from "effect/Exit" import { pipe } from "effect/Function" import * as Layer from "effect/Layer" import * as Stream from "effect/Stream" +import { deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import type * as Tracer from "effect/Tracer" -import { assert, describe, expect } from "vitest" +import { describe } from "vitest" interface StringService { readonly string: string @@ -29,7 +30,7 @@ describe("Stream", () => { Stream.provideContext(context), Stream.runCollect ) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [{ string: "test" }]) + deepStrictEqual(Chunk.toReadonlyArray(result), [{ string: "test" }]) })) it.effect("contextWith", () => @@ -45,7 +46,7 @@ describe("Stream", () => { Stream.runHead, Effect.flatten ) - assert.deepStrictEqual(result, { string: "test" }) + deepStrictEqual(result, { string: "test" }) })) it.effect("contextWithEffect - success", () => @@ -63,7 +64,7 @@ describe("Stream", () => { Stream.runHead, Effect.flatten ) - assert.deepStrictEqual(result, { string: "test" }) + deepStrictEqual(result, { string: "test" }) })) it.effect("contextWithEffect - fails", () => @@ -79,7 +80,7 @@ describe("Stream", () => { Stream.runHead, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail("boom")) + deepStrictEqual(result, Exit.fail("boom")) })) it.effect("contextWithStream - success", () => @@ -97,7 +98,7 @@ describe("Stream", () => { Stream.runHead, Effect.flatten ) - assert.deepStrictEqual(result, { string: "test" }) + deepStrictEqual(result, { string: "test" }) })) it.effect("contextWithStream - fails", () => @@ -113,7 +114,7 @@ describe("Stream", () => { Stream.runHead, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail("boom")) + deepStrictEqual(result, Exit.fail("boom")) })) it.effect("provide", () => @@ -126,7 +127,7 @@ describe("Stream", () => { Stream.map((s) => s.string), Stream.runCollect ) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), ["test"]) + deepStrictEqual(Chunk.toReadonlyArray(result), ["test"]) })) it.effect("provideServiceStream", () => @@ -139,7 +140,7 @@ describe("Stream", () => { Stream.map((s) => s.string), Stream.runCollect ) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), ["test"]) + deepStrictEqual(Chunk.toReadonlyArray(result), ["test"]) })) it.effect("serviceWith", () => @@ -149,7 +150,7 @@ describe("Stream", () => { Stream.provideLayer(Layer.succeed(StringService, { string: "test" })), Stream.runCollect ) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), ["test"]) + deepStrictEqual(Chunk.toReadonlyArray(result), ["test"]) })) it.effect("serviceWithEffect", () => @@ -159,7 +160,7 @@ describe("Stream", () => { Stream.provideLayer(Layer.succeed(StringService, { string: "test" })), Stream.runCollect ) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), ["test"]) + deepStrictEqual(Chunk.toReadonlyArray(result), ["test"]) })) it.effect("serviceWithStream", () => @@ -169,7 +170,7 @@ describe("Stream", () => { Stream.provideLayer(Layer.succeed(StringService, { string: "test" })), Stream.runCollect ) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), ["test"]) + deepStrictEqual(Chunk.toReadonlyArray(result), ["test"]) })) it.effect("deep provide", () => @@ -189,7 +190,7 @@ describe("Stream", () => { Stream.provideSomeLayer(L0) ) yield* $(Stream.runDrain(stream)) - assert.deepStrictEqual(messages, ["test1", "test1", "test2", "test2"]) + deepStrictEqual(messages, ["test1", "test1", "test2", "test2"]) })) it.effect("withSpan", () => @@ -206,13 +207,16 @@ describe("Stream", () => { Stream.runCollect, Effect.map(Chunk.toReadonlyArray) ) - expect(spans.length).toEqual(3) - expect(pipe( - Array.map(spans, (s) => s.parent), - Array.getSomes, - Array.filter((s): s is Tracer.Span => s._tag === "Span"), - Array.map((s) => s.name) - )).toEqual(["span", "span", "span"]) - expect(Array.map(spans, (s) => s.name)).toEqual(["span.1", "span.2", "span.3"]) + strictEqual(spans.length, 3) + deepStrictEqual( + pipe( + Array.map(spans, (s) => s.parent), + Array.getSomes, + Array.filter((s): s is Tracer.Span => s._tag === "Span"), + Array.map((s) => s.name) + ), + ["span", "span", "span"] + ) + deepStrictEqual(Array.map(spans, (s) => s.name), ["span.1", "span.2", "span.3"]) })) }) diff --git a/packages/effect/test/Stream/error-handling.test.ts b/packages/effect/test/Stream/error-handling.test.ts index 90b0b94538a..d7e66f9142c 100644 --- a/packages/effect/test/Stream/error-handling.test.ts +++ b/packages/effect/test/Stream/error-handling.test.ts @@ -7,8 +7,9 @@ import { identity, pipe } from "effect/Function" import * as Option from "effect/Option" import * as Ref from "effect/Ref" import * as Stream from "effect/Stream" +import { assertLeft, assertTrue, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe, expect } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("absolve - happy path", () => @@ -21,7 +22,7 @@ describe("Stream", () => { Stream.mapEffect(identity), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), Array.from(chunk)) + deepStrictEqual(Array.from(result), Array.from(chunk)) })) it.effect("absolve - failure", () => @@ -33,7 +34,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail("Ouch")) + deepStrictEqual(result, Exit.fail("Ouch")) })) it.effect("absolve - round trip #1", () => @@ -44,7 +45,7 @@ describe("Stream", () => { result1: Stream.runCollect(stream), result2: pipe(Stream.mapEffect(stream, identity), Stream.either, Stream.runCollect) })) - assert.deepStrictEqual( + deepStrictEqual( Array.from(pipe(result1, Chunk.take(result2.length))), Array.from(result2) ) @@ -58,8 +59,8 @@ describe("Stream", () => { result1: Effect.exit(Stream.runCollect(stream)), result2: pipe(stream, Stream.either, Stream.mapEffect(identity), Stream.runCollect, Effect.exit) })) - assert.deepStrictEqual(result1, Exit.fail("Ouch")) - assert.deepStrictEqual(result2, Exit.fail("Ouch")) + deepStrictEqual(result1, Exit.fail("Ouch")) + deepStrictEqual(result2, Exit.fail("Ouch")) })) it.effect("catchAllCause - recovery from errors", () => @@ -71,7 +72,7 @@ describe("Stream", () => { Stream.catchAllCause(() => stream2), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 2, 3, 4]) + deepStrictEqual(Array.from(result), [1, 2, 3, 4]) })) it.effect("catchAllCause - recovery from defects", () => @@ -83,7 +84,7 @@ describe("Stream", () => { Stream.catchAllCause(() => stream2), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 2, 3, 4]) + deepStrictEqual(Array.from(result), [1, 2, 3, 4]) })) it.effect("catchAllCause - happy path", () => @@ -95,7 +96,7 @@ describe("Stream", () => { Stream.catchAllCause(() => stream2), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 2]) + deepStrictEqual(Array.from(result), [1, 2]) })) it.effect("catchAllCause - executes finalizers", () => @@ -118,7 +119,7 @@ describe("Stream", () => { Effect.exit ) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), ["s1", "s2"]) + deepStrictEqual(Array.from(result), ["s1", "s2"]) })) it.effect("catchAllCause - releases all resources by the time the failover stream has started", () => @@ -135,7 +136,7 @@ describe("Stream", () => { Stream.catchAllCause(() => Stream.fromEffect(Ref.get(ref))), Stream.runCollect ) - assert.deepStrictEqual(Array.from(Chunk.flatten(result)), [3, 2, 1]) + deepStrictEqual(Array.from(Chunk.flatten(result)), [3, 2, 1]) })) it.effect("catchAllCause - propagates the right Exit value to the failing stream (ZIO #3609)", () => @@ -152,7 +153,7 @@ describe("Stream", () => { Effect.exit ) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(result, Exit.fail("boom")) + deepStrictEqual(result, Exit.fail("boom")) })) it.effect("catchSome - recovery from some errors", () => @@ -167,7 +168,7 @@ describe("Stream", () => { Stream.catchSome((error) => error === "boom" ? Option.some(stream2) : Option.none()), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 2, 3, 4]) + deepStrictEqual(Array.from(result), [1, 2, 3, 4]) })) it.effect("catchSome - fails stream when partial function does not match", () => @@ -183,7 +184,7 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left("boom")) + assertLeft(result, "boom") })) it.effect("catchSomeCause - recovery from some errors", () => @@ -202,7 +203,7 @@ describe("Stream", () => { ), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 2, 3, 4]) + deepStrictEqual(Array.from(result), [1, 2, 3, 4]) })) it.effect("catchSomeCause - fails stream when partial function does not match", () => @@ -222,7 +223,7 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left("boom")) + assertLeft(result, "boom") })) it.effect("catchTag", () => @@ -248,8 +249,8 @@ describe("Stream", () => { Effect.either ) - expect(Chunk.toReadonlyArray(result1)).toEqual([1, 2]) - assert(Either.isLeft(result2) && result2.left._tag === "ErrorA") + deepStrictEqual(Chunk.toReadonlyArray(result1), [1, 2]) + assertTrue(Either.isLeft(result2) && result2.left._tag === "ErrorA") })) it.effect("onError", () => @@ -262,8 +263,8 @@ describe("Stream", () => { Effect.exit ) const called = yield* $(Ref.get(ref)) - assert.deepStrictEqual(exit, Exit.fail("boom")) - assert.isTrue(called) + deepStrictEqual(exit, Exit.fail("boom")) + assertTrue(called) })) it.effect("orElse", () => @@ -278,7 +279,7 @@ describe("Stream", () => { Stream.orElse(() => stream2), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 2, 3, 4, 5, 6]) + deepStrictEqual(Array.from(result), [1, 2, 3, 4, 5, 6]) })) it.effect("orElseEither", () => @@ -293,7 +294,7 @@ describe("Stream", () => { Stream.orElseEither(() => stream2), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [Either.left(1), Either.right(2)]) + deepStrictEqual(Array.from(result), [Either.left(1), Either.right(2)]) })) it.effect("orElseFail", () => @@ -305,7 +306,7 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left("boomer")) + assertLeft(result, "boomer") })) it.effect("orElseIfEmpty - produce default value if stream is empty", () => @@ -315,7 +316,7 @@ describe("Stream", () => { Stream.orElseIfEmpty(() => 0), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [0]) + deepStrictEqual(Array.from(result), [0]) })) it.effect("orElseIfEmpty - ignores default value when stream is not empty", () => @@ -325,7 +326,7 @@ describe("Stream", () => { Stream.orElseIfEmpty(() => 0), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1]) + deepStrictEqual(Array.from(result), [1]) })) it.effect("orElseIfEmptyStream - consume default stream if stream is empty", () => @@ -335,7 +336,7 @@ describe("Stream", () => { Stream.orElseIfEmptyStream(() => Stream.range(0, 4)), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [0, 1, 2, 3, 4]) + deepStrictEqual(Array.from(result), [0, 1, 2, 3, 4]) })) it.effect("orElseIfEmptyStream - should throw the correct error from the default stream", () => @@ -346,7 +347,7 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) it.effect("orElseSucceed", () => @@ -357,6 +358,6 @@ describe("Stream", () => { Stream.orElseSucceed(() => 2), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 2]) + deepStrictEqual(Array.from(result), [1, 2]) })) }) diff --git a/packages/effect/test/Stream/filtering.test.ts b/packages/effect/test/Stream/filtering.test.ts index bffdd54559f..0e275f546a5 100644 --- a/packages/effect/test/Stream/filtering.test.ts +++ b/packages/effect/test/Stream/filtering.test.ts @@ -3,8 +3,9 @@ import * as Effect from "effect/Effect" import * as Either from "effect/Either" import { pipe } from "effect/Function" import * as Stream from "effect/Stream" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("filter", () => @@ -15,7 +16,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.filter(f), Stream.runCollect), result2: pipe(stream, Stream.runCollect, Effect.map(Chunk.filter(f))) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("filterEffect - simple example", () => @@ -26,7 +27,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.filterEffect(f), Stream.runCollect), result2: pipe(stream, Stream.runCollect, Effect.flatMap(Effect.filter(f))) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("filterEffect - laziness on chunks", () => @@ -41,7 +42,7 @@ describe("Stream", () => { Stream.either, Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result), [Either.right(1), Either.right(2), Either.left("boom")] ) diff --git a/packages/effect/test/Stream/finding.test.ts b/packages/effect/test/Stream/finding.test.ts index ff540b4398d..4fd2ae97820 100644 --- a/packages/effect/test/Stream/finding.test.ts +++ b/packages/effect/test/Stream/finding.test.ts @@ -4,8 +4,9 @@ import * as Either from "effect/Either" import { pipe } from "effect/Function" import * as Option from "effect/Option" import * as Stream from "effect/Stream" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("find", () => @@ -24,7 +25,7 @@ describe("Stream", () => { })) ) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("findEffect - simple example", () => @@ -46,7 +47,7 @@ describe("Stream", () => { ) ) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("findEffect - throws correct error", () => @@ -61,7 +62,7 @@ describe("Stream", () => { Stream.either, Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result), [Either.left("boom")] ) diff --git a/packages/effect/test/Stream/foreign.test.ts b/packages/effect/test/Stream/foreign.test.ts index b82a7924ccb..f3c7f1a2464 100644 --- a/packages/effect/test/Stream/foreign.test.ts +++ b/packages/effect/test/Stream/foreign.test.ts @@ -7,9 +7,10 @@ import * as Exit from "effect/Exit" import * as Option from "effect/Option" import * as Random from "effect/Random" import * as Stream from "effect/Stream" +import { assertLeft, assertRight, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import { unify } from "effect/Unify" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream.Foreign", () => { it.effect("Tag", () => @@ -21,7 +22,7 @@ describe("Stream.Foreign", () => { Effect.map(Chunk.toReadonlyArray), Effect.provideService(tag, 10) ) - assert.deepEqual(result, [10]) + deepStrictEqual(result, [10]) })) it.effect("Unify", () => @@ -30,10 +31,10 @@ describe("Stream.Foreign", () => { const unifiedExit = unify((yield* $(Random.nextInt)) > 1 ? Exit.succeed(0) : Exit.fail(1)) const unifiedEither = unify((yield* $(Random.nextInt)) > 1 ? Either.right(0) : Either.left(1)) const unifiedOption = unify((yield* $(Random.nextInt)) > 1 ? Option.some(0) : Option.none()) - assert.deepEqual(Chunk.toReadonlyArray(yield* $(Stream.runCollect(unifiedEffect))), [0]) - assert.deepEqual(Chunk.toReadonlyArray(yield* $(Stream.runCollect(unifiedExit))), [0]) - assert.deepEqual(Chunk.toReadonlyArray(yield* $(Stream.runCollect(unifiedEither))), [0]) - assert.deepEqual(Chunk.toReadonlyArray(yield* $(Stream.runCollect(unifiedOption))), [0]) + deepStrictEqual(Chunk.toReadonlyArray(yield* $(Stream.runCollect(unifiedEffect))), [0]) + deepStrictEqual(Chunk.toReadonlyArray(yield* $(Stream.runCollect(unifiedExit))), [0]) + deepStrictEqual(Chunk.toReadonlyArray(yield* $(Stream.runCollect(unifiedEither))), [0]) + deepStrictEqual(Chunk.toReadonlyArray(yield* $(Stream.runCollect(unifiedOption))), [0]) })) it.effect("Either.right", () => @@ -46,7 +47,7 @@ describe("Stream.Foreign", () => { Effect.map(Chunk.toReadonlyArray), Effect.provideService(tag, 10) ) - assert.deepEqual(result, [10]) + deepStrictEqual(result, [10]) })) it.effect("Either.left", () => @@ -58,7 +59,7 @@ describe("Stream.Foreign", () => { Effect.either, Effect.provideService(tag, 10) ) - assert.deepEqual(result, Either.left(10)) + assertLeft(result, 10) })) it.effect("Option.some", () => @@ -70,7 +71,7 @@ describe("Stream.Foreign", () => { Effect.map(Chunk.toReadonlyArray), Effect.provideService(tag, 10) ) - assert.deepEqual(result, [10]) + deepStrictEqual(result, [10]) })) it.effect("Option.none", () => @@ -82,7 +83,7 @@ describe("Stream.Foreign", () => { Effect.either, Effect.provideService(tag, 10) ) - assert.deepEqual(result, Either.left(new Cause.NoSuchElementException())) + assertLeft(result, new Cause.NoSuchElementException()) })) it.effect("Effect.fail", () => @@ -94,7 +95,7 @@ describe("Stream.Foreign", () => { Effect.either, Effect.provideService(tag, 10) ) - assert.deepEqual(result, Either.left("ok")) + assertLeft(result, "ok") })) it.effect("Effect.succeed", () => @@ -107,6 +108,6 @@ describe("Stream.Foreign", () => { Effect.either, Effect.provideService(tag, 10) ) - assert.deepEqual(result, Either.right(["ok"])) + assertRight(result, ["ok"]) })) }) diff --git a/packages/effect/test/Stream/getters.test.ts b/packages/effect/test/Stream/getters.test.ts index 022949c9791..a026c9bd20a 100644 --- a/packages/effect/test/Stream/getters.test.ts +++ b/packages/effect/test/Stream/getters.test.ts @@ -1,9 +1,9 @@ import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import * as Option from "effect/Option" import * as Stream from "effect/Stream" +import { assertLeft, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("some", () => @@ -15,7 +15,7 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left(Option.none())) + assertLeft(result, Option.none()) })) it.effect("some", () => @@ -26,7 +26,7 @@ describe("Stream", () => { Stream.someOrElse(() => -1), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, -1]) + deepStrictEqual(Array.from(result), [1, -1]) })) it.effect("someOrFail", () => @@ -38,6 +38,6 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left(-1)) + assertLeft(result, -1) })) }) diff --git a/packages/effect/test/Stream/grouping.test.ts b/packages/effect/test/Stream/grouping.test.ts index caffa2e1d1e..9a77f907481 100644 --- a/packages/effect/test/Stream/grouping.test.ts +++ b/packages/effect/test/Stream/grouping.test.ts @@ -1,7 +1,6 @@ import * as Chunk from "effect/Chunk" import * as Duration from "effect/Duration" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import * as Exit from "effect/Exit" import * as Fiber from "effect/Fiber" import { identity, pipe } from "effect/Function" @@ -11,10 +10,11 @@ import * as Option from "effect/Option" import * as Ref from "effect/Ref" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { assertLeft, deepStrictEqual, strictEqual } from "effect/test/util" import { chunkCoordination } from "effect/test/utils/coordination" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("groupBy - values", () => @@ -36,7 +36,7 @@ describe("Stream", () => { ), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result), Array.from({ length: 100 }, (_, i) => i).map((n) => [String(n), 100] as const) ) @@ -62,7 +62,7 @@ describe("Stream", () => { ), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [["0", 1_000], ["1", 1_000]]) + deepStrictEqual(Array.from(result), [["0", 1_000], ["1", 1_000]]) })) it.effect("groupBy - filter", () => @@ -81,7 +81,7 @@ describe("Stream", () => { ), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [ + deepStrictEqual(Array.from(result), [ [0, 100], [1, 100], [2, 100], @@ -102,7 +102,7 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left("boom")) + assertLeft(result, "boom") })) it.effect("grouped - sanity check", () => @@ -112,7 +112,7 @@ describe("Stream", () => { Stream.grouped(2), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1, 2], [3, 4], [5]] ) @@ -126,7 +126,7 @@ describe("Stream", () => { Stream.map(Chunk.size), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result), Array.from({ length: 10 }, () => 10) ) @@ -139,7 +139,7 @@ describe("Stream", () => { Stream.grouped(5), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), []) + deepStrictEqual(Array.from(result), []) })) it.effect("grouped - emits elements properly when a failure occurs", () => @@ -158,8 +158,8 @@ describe("Stream", () => { Effect.either ) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(either, Either.left("Ouch")) - assert.deepStrictEqual(Array.from(result), [[1, 2, 3], [4, 5, 6], [7, 8]]) + assertLeft(either, "Ouch") + deepStrictEqual(Array.from(result), [[1, 2, 3], [4, 5, 6], [7, 8]]) })) it.effect("groupedWithin - group based on time passed", () => @@ -192,7 +192,7 @@ describe("Stream", () => { ) yield* $(coordination.offer) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1, 2], [3, 4], [5]] ) @@ -315,7 +315,7 @@ describe("Stream", () => { Effect.zipRight(Ref.get(ref)) ) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [ [1, 2, 3], @@ -325,11 +325,11 @@ describe("Stream", () => { [20, 21, 22, 23, 24, 25, 26, 27, 28, 29] ] ) - assert.strictEqual(result1, 3) - assert.strictEqual(result2, 6) - assert.strictEqual(result3, 9) - assert.strictEqual(result4, 19) - assert.strictEqual(result5, 29) + strictEqual(result1, 3) + strictEqual(result2, 6) + strictEqual(result3, 9) + strictEqual(result4, 19) + strictEqual(result5, 29) })) it.effect("groupedWithin - group immediately when chunk size is reached", () => @@ -339,7 +339,7 @@ describe("Stream", () => { Stream.groupedWithin(2, Duration.seconds(10)), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1, 2], [3, 4]] ) @@ -357,7 +357,7 @@ describe("Stream", () => { Stream.groupAdjacentBy((x) => x.code), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map(([, chunk]) => Array.from(chunk)), [ [ @@ -384,7 +384,7 @@ describe("Stream", () => { Stream.groupAdjacentBy((x) => x.code), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map(([, chunk]) => Array.from(chunk)), [ [ @@ -409,7 +409,7 @@ describe("Stream", () => { Stream.groupAdjacentBy((x) => x.code), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map(([, chunk]) => Array.from(chunk)), [ [ diff --git a/packages/effect/test/Stream/halting.test.ts b/packages/effect/test/Stream/halting.test.ts index f1a846e2cfc..2d37c7d3dc4 100644 --- a/packages/effect/test/Stream/halting.test.ts +++ b/packages/effect/test/Stream/halting.test.ts @@ -2,17 +2,17 @@ import * as Chunk from "effect/Chunk" import * as Deferred from "effect/Deferred" import * as Duration from "effect/Duration" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import * as Exit from "effect/Exit" import * as Fiber from "effect/Fiber" import * as Option from "effect/Option" import * as Queue from "effect/Queue" import * as Ref from "effect/Ref" import * as Stream from "effect/Stream" +import { assertFalse, assertLeft, deepStrictEqual } from "effect/test/util" import { chunkCoordination } from "effect/test/utils/coordination" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("haltWhen - halts after the current element", () => @@ -31,7 +31,7 @@ describe("Stream", () => { yield* $(Deferred.succeed(halt, void 0)) yield* $(Deferred.succeed(latch, void 0)) const result = yield* $(Ref.get(ref)) - assert.isFalse(result) + assertFalse(result) })) it.effect("haltWhen - propagates errors", () => @@ -45,7 +45,7 @@ describe("Stream", () => { Stream.runDrain, Effect.either ) - assert.deepStrictEqual(result, Either.left("fail")) + assertLeft(result, "fail") })) it.effect("haltWhenDeferred - halts after the current element", () => @@ -64,7 +64,7 @@ describe("Stream", () => { yield* $(Deferred.succeed(halt, void 0)) yield* $(Deferred.succeed(latch, void 0)) const result = yield* $(Ref.get(ref)) - assert.isFalse(result) + assertFalse(result) })) it.effect("haltWhenDeferred - propagates errors", () => @@ -77,7 +77,7 @@ describe("Stream", () => { Stream.runDrain, Effect.either ) - assert.deepStrictEqual(result, Either.left("fail")) + assertLeft(result, "fail") })) it.effect("haltAfter - halts after the given duration", () => @@ -116,7 +116,7 @@ describe("Stream", () => { ) yield* $(coordination.offer) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1], [2], [3]] ) @@ -134,6 +134,6 @@ describe("Stream", () => { yield* $(TestClock.adjust(Duration.seconds(6))) yield* $(Queue.offer(queue, 1)) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Array.from(result), [1]) + deepStrictEqual(Array.from(result), [1]) })) }) diff --git a/packages/effect/test/Stream/interleaving.test.ts b/packages/effect/test/Stream/interleaving.test.ts index 092b07c72ec..faa851fdc9a 100644 --- a/packages/effect/test/Stream/interleaving.test.ts +++ b/packages/effect/test/Stream/interleaving.test.ts @@ -3,8 +3,9 @@ import * as Effect from "effect/Effect" import { pipe } from "effect/Function" import * as Option from "effect/Option" import * as Stream from "effect/Stream" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("interleave", () => @@ -16,7 +17,7 @@ describe("Stream", () => { Stream.interleave(stream2), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [2, 5, 3, 6, 7]) + deepStrictEqual(Array.from(result), [2, 5, 3, 6, 7]) })) it.effect("interleaveWith", () => @@ -70,6 +71,6 @@ describe("Stream", () => { const numbers1 = yield* $(Stream.runCollect(stream1)) const numbers2 = yield* $(Stream.runCollect(stream2)) const interleavedChunks = interleave(bools, numbers1, numbers2) - assert.deepStrictEqual(Array.from(interleavedStream), Array.from(interleavedChunks)) + deepStrictEqual(Array.from(interleavedStream), Array.from(interleavedChunks)) })) }) diff --git a/packages/effect/test/Stream/interrupting.test.ts b/packages/effect/test/Stream/interrupting.test.ts index bf27d15ec09..e19089ab8db 100644 --- a/packages/effect/test/Stream/interrupting.test.ts +++ b/packages/effect/test/Stream/interrupting.test.ts @@ -3,7 +3,6 @@ import * as Chunk from "effect/Chunk" import * as Deferred from "effect/Deferred" import * as Duration from "effect/Duration" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import * as Exit from "effect/Exit" import * as Fiber from "effect/Fiber" import { pipe } from "effect/Function" @@ -11,10 +10,11 @@ import * as Option from "effect/Option" import * as Queue from "effect/Queue" import * as Ref from "effect/Ref" import * as Stream from "effect/Stream" +import { assertLeft, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import { chunkCoordination } from "effect/test/utils/coordination" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("interruptWhen - preserves the scope of inner fibers", () => @@ -35,7 +35,7 @@ describe("Stream", () => { Stream.take(3) ) const result = yield* $(Stream.runDrain(stream)) - assert.isUndefined(result) + strictEqual(result, undefined) })) it.effect("interruptWhen - interrupts the current element", () => @@ -60,7 +60,7 @@ describe("Stream", () => { ) yield* $(Fiber.await(fiber)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("interruptWhen - propagates errors", () => @@ -73,7 +73,7 @@ describe("Stream", () => { Stream.runDrain, Effect.either ) - assert.deepStrictEqual(result, Either.left("fail")) + assertLeft(result, "fail") })) it.effect("interruptWhenDeferred - interrupts the current element", () => @@ -98,7 +98,7 @@ describe("Stream", () => { ) yield* $(Fiber.await(fiber)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("interruptWhenDeferred - propagates errors", () => @@ -111,7 +111,7 @@ describe("Stream", () => { Stream.runDrain, Effect.either ) - assert.deepStrictEqual(result, Either.left("fail")) + assertLeft(result, "fail") })) it.effect("interruptAfter - halts after the given duration", () => @@ -145,7 +145,7 @@ describe("Stream", () => { ) yield* $(coordination.offer) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1], [2]] ) @@ -163,7 +163,7 @@ describe("Stream", () => { yield* $(TestClock.adjust(Duration.seconds(6))) yield* $(Queue.offer(queue, 1)) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Array.from(result), []) + deepStrictEqual(Array.from(result), []) })) it.effect("interruptWhen - interrupts the effect", () => @@ -186,7 +186,7 @@ describe("Stream", () => { yield* TestClock.adjust("1 seconds") yield* fiber.await - assert.strictEqual(interrupted, true) + assertTrue(interrupted) })) it.effect("forked children are not interrupted early by interruptWhen", () => @@ -209,6 +209,6 @@ describe("Stream", () => { const result = yield* Ref.get(ref).pipe( Effect.repeat({ until: (n) => n >= 10 }) ) - assert.strictEqual(result, 10) + strictEqual(result, 10) })) }) diff --git a/packages/effect/test/Stream/interspersing.test.ts b/packages/effect/test/Stream/interspersing.test.ts index 822ecaabeab..74b867e114b 100644 --- a/packages/effect/test/Stream/interspersing.test.ts +++ b/packages/effect/test/Stream/interspersing.test.ts @@ -1,8 +1,9 @@ import * as Chunk from "effect/Chunk" import * as Effect from "effect/Effect" import * as Stream from "effect/Stream" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("intersperse - several values", () => @@ -13,7 +14,7 @@ describe("Stream", () => { Stream.intersperse("."), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), ["1", ".", "2", ".", "3", ".", "4"]) + deepStrictEqual(Array.from(result), ["1", ".", "2", ".", "3", ".", "4"]) })) it.effect("intersperseAffixes - several values", () => @@ -24,7 +25,7 @@ describe("Stream", () => { Stream.intersperseAffixes({ start: "[", middle: ".", end: "]" }), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), ["[", "1", ".", "2", ".", "3", ".", "4", "]"]) + deepStrictEqual(Array.from(result), ["[", "1", ".", "2", ".", "3", ".", "4", "]"]) })) it.effect("intersperse - single value", () => @@ -35,7 +36,7 @@ describe("Stream", () => { Stream.intersperse("."), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), ["1"]) + deepStrictEqual(Array.from(result), ["1"]) })) it.effect("intersperseAffixes - single value", () => @@ -46,7 +47,7 @@ describe("Stream", () => { Stream.intersperseAffixes({ start: "[", middle: ".", end: "]" }), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), ["[", "1", "]"]) + deepStrictEqual(Array.from(result), ["[", "1", "]"]) })) it.effect("intersperse - several from repeat effect (ZIO #3729)", () => @@ -58,7 +59,7 @@ describe("Stream", () => { Stream.intersperse("."), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), ["42", ".", "42", ".", "42", ".", "42"]) + deepStrictEqual(Array.from(result), ["42", ".", "42", ".", "42", ".", "42"]) })) it.effect("intersperse - several from repeat effect chunk single element (ZIO #3729)", () => @@ -70,6 +71,6 @@ describe("Stream", () => { Stream.take(4), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), ["42", ".", "42", "."]) + deepStrictEqual(Array.from(result), ["42", ".", "42", "."]) })) }) diff --git a/packages/effect/test/Stream/lifecycle.test.ts b/packages/effect/test/Stream/lifecycle.test.ts index 9685d5abca9..84910c98771 100644 --- a/packages/effect/test/Stream/lifecycle.test.ts +++ b/packages/effect/test/Stream/lifecycle.test.ts @@ -1,7 +1,8 @@ import * as Effect from "effect/Effect" import * as Stream from "effect/Stream" +import { deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("onStart", () => @@ -12,8 +13,8 @@ describe("Stream", () => { Stream.onStart(Effect.sync(() => counter++)), Stream.runCollect ) - assert.strictEqual(counter, 1) - assert.deepStrictEqual(Array.from(result), [1, 1]) + strictEqual(counter, 1) + deepStrictEqual(Array.from(result), [1, 1]) })) it.effect("onEnd", () => @@ -24,7 +25,7 @@ describe("Stream", () => { Stream.onEnd(Effect.sync(() => counter++)), Stream.runCollect ) - assert.strictEqual(counter, 1) - assert.deepStrictEqual(Array.from(result), [1, 2, 3]) + strictEqual(counter, 1) + deepStrictEqual(Array.from(result), [1, 2, 3]) })) }) diff --git a/packages/effect/test/Stream/mapping.test.ts b/packages/effect/test/Stream/mapping.test.ts index 538024f30e7..0e0f6ea4c0e 100644 --- a/packages/effect/test/Stream/mapping.test.ts +++ b/packages/effect/test/Stream/mapping.test.ts @@ -10,9 +10,10 @@ import { identity, pipe } from "effect/Function" import * as Queue from "effect/Queue" import * as Ref from "effect/Ref" import * as Stream from "effect/Stream" +import { assertFalse, assertLeft, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("map", () => @@ -23,7 +24,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.map(f), Stream.runCollect), result2: pipe(Stream.runCollect(stream), Effect.map(Chunk.map(f))) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("mapAccum", () => @@ -33,7 +34,7 @@ describe("Stream", () => { Stream.mapAccum(0, (acc, curr) => [acc + curr, acc + curr]), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 2, 3]) + deepStrictEqual(Array.from(result), [1, 2, 3]) })) it.effect("mapAccumEffect - happy path", () => @@ -43,7 +44,7 @@ describe("Stream", () => { Stream.mapAccumEffect(0, (acc, curr) => Effect.succeed([acc + curr, acc + curr])), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 2, 3]) + deepStrictEqual(Array.from(result), [1, 2, 3]) })) it.effect("mapAccumEffect - error", () => @@ -54,7 +55,7 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) it.effect("mapAccumEffect - laziness on chunks", () => @@ -68,7 +69,7 @@ describe("Stream", () => { Stream.either, Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result), [Either.right(1), Either.right(2), Either.left("boom")] ) @@ -82,7 +83,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.mapConcat(f), Stream.runCollect), result2: pipe(Stream.runCollect(stream), Effect.map(Chunk.flatMap((n) => f(n)))) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("mapConcatChunk", () => @@ -93,7 +94,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.mapConcatChunk(f), Stream.runCollect), result2: pipe(Stream.runCollect(stream), Effect.map(Chunk.flatMap((n) => f(n)))) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("mapConcatChunkEffect - happy path", () => @@ -104,7 +105,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.mapConcatChunkEffect((n) => Effect.succeed(f(n))), Stream.runCollect), result2: pipe(Stream.runCollect(stream), Effect.map(Chunk.flatMap((n) => f(n)))) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("mapConcatChunkEffect - error", () => @@ -115,7 +116,7 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) it.effect("mapConcatEffect - happy path", () => @@ -126,7 +127,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.mapConcatEffect((n) => Effect.succeed(f(n))), Stream.runCollect), result2: pipe(Stream.runCollect(stream), Effect.map(Chunk.flatMap((n) => f(n)))) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("mapConcatEffect - error", () => @@ -137,7 +138,7 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) it.effect("mapError", () => @@ -148,7 +149,7 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left(123)) + assertLeft(result, 123) })) it.effect("mapErrorCause", () => @@ -159,7 +160,7 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left(123)) + assertLeft(result, 123) })) it.effect("mapEffect - Effect.forEach equivalence", () => @@ -171,7 +172,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.mapEffect(f), Stream.runCollect), result2: pipe(chunk, Effect.forEach(f)) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("mapEffect - laziness on chunks", () => @@ -186,7 +187,7 @@ describe("Stream", () => { Stream.either, Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result), [Either.right(1), Either.right(2), Either.left("boom")] ) @@ -202,7 +203,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.mapEffect(f, { concurrency }), Stream.runCollect), result2: Effect.forEach(chunk, f, { concurrency }) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("mapEffectPar - ordering when parallelism is 1", () => @@ -214,7 +215,7 @@ describe("Stream", () => { Stream.runDrain ) const result = yield* $(Queue.takeAll(queue)) - assert.deepStrictEqual(Array.from(result), [0, 1, 2, 3, 4, 5, 6, 7, 8]) + deepStrictEqual(Array.from(result), [0, 1, 2, 3, 4, 5, 6, 7, 8]) })) it.effect("mapEffectPar - interruption propagation", () => @@ -235,7 +236,7 @@ describe("Stream", () => { yield* $(Deferred.await(latch)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("mapEffectPar - guarantees ordering", () => @@ -247,7 +248,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.mapEffect(Effect.succeed), Stream.runCollect), result2: pipe(stream, Stream.mapEffect(Effect.succeed, { concurrency: n }), Stream.runCollect) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("mapEffectPar - awaits child fibers properly", () => @@ -259,7 +260,7 @@ describe("Stream", () => { Stream.runDrain, Effect.exit ) - assert.isFalse(Exit.isInterrupted(result)) + assertFalse(Exit.isInterrupted(result)) })) it.effect("mapEffectPar - interrupts pending tasks when one of the tasks fails", () => @@ -294,8 +295,8 @@ describe("Stream", () => { Effect.exit ) const count = yield* $(Ref.get(ref)) - assert.strictEqual(count, 2) - assert.deepStrictEqual(result, Exit.fail("boom")) + strictEqual(count, 2) + deepStrictEqual(result, Exit.fail("boom")) })) it.effect("mapEffectPar - propagates the correct error with subsequent calls to mapEffectPar (ZIO #4514)", () => @@ -307,7 +308,7 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left("boom")) + assertLeft(result, "boom") })) it.effect("mapEffectPar - propagates the error of the original stream", () => @@ -321,7 +322,7 @@ describe("Stream", () => { ) yield* $(TestClock.adjust(Duration.seconds(5))) const exit = yield* $(Fiber.await(fiber)) - assert.deepStrictEqual(exit, Exit.fail(new Cause.RuntimeException("boom"))) + deepStrictEqual(exit, Exit.fail(new Cause.RuntimeException("boom"))) })) it.effect("mapEffectParUnordered - mapping with failure is failure", () => @@ -332,7 +333,7 @@ describe("Stream", () => { Stream.runDrain, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail("fail")) + deepStrictEqual(result, Exit.fail("fail")) })) it.effect("mapEffect with key", () => @@ -345,8 +346,8 @@ describe("Stream", () => { ) yield* _(TestClock.adjust(40)) const exit = fiber.unsafePoll() - assert(Exit.isExit(exit)) - assert(Exit.isSuccess(exit)) - assert.deepStrictEqual(Chunk.toReadonlyArray(exit.value), [10, 20, 30, 40]) + assertTrue(Exit.isExit(exit)) + assertTrue(Exit.isSuccess(exit)) + deepStrictEqual(Chunk.toReadonlyArray(exit.value), [10, 20, 30, 40]) })) }) diff --git a/packages/effect/test/Stream/merging.test.ts b/packages/effect/test/Stream/merging.test.ts index 1592b8111ed..8cdc4c9b2f3 100644 --- a/packages/effect/test/Stream/merging.test.ts +++ b/packages/effect/test/Stream/merging.test.ts @@ -1,17 +1,17 @@ import * as Chunk from "effect/Chunk" import * as Duration from "effect/Duration" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import * as Exit from "effect/Exit" import * as Fiber from "effect/Fiber" import { constVoid, pipe } from "effect/Function" import * as HashSet from "effect/HashSet" import * as Queue from "effect/Queue" import * as Stream from "effect/Stream" +import { assertLeft, assertTrue, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" import * as TestServices from "effect/TestServices" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("merge - slower stream", () => @@ -25,7 +25,7 @@ describe("Stream", () => { Stream.merge(stream1, stream2), Stream.runCollect ) - assert.deepStrictEqual([...result], [1, 2, 3, 4, 5, 6, 7, 8]) + deepStrictEqual([...result], [1, 2, 3, 4, 5, 6, 7, 8]) })) it.effect("mergeAll - short circuiting", () => @@ -35,7 +35,7 @@ describe("Stream", () => { Stream.take(1), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1]) + deepStrictEqual(Array.from(result), [1]) })) it.effect("mergeWithTag", (ctx) => @@ -69,7 +69,7 @@ describe("Stream", () => { yield* $(Queue.shutdown(queue1), Effect.zipRight(TestClock.adjust(Duration.seconds(1)))) yield* $(Queue.offer(queue2, 3)) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Array.from(result), [1, 2]) + deepStrictEqual(Array.from(result), [1, 2]) })) it.effect("mergeHaltEither - interrupts pulling on finish", () => @@ -81,7 +81,7 @@ describe("Stream", () => { Stream.merge(stream2, { haltStrategy: "left" }), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 2, 3]) + deepStrictEqual(Array.from(result), [1, 2, 3]) })) it.effect("mergeHaltRight - terminates as soon as the second stream terminates", () => @@ -101,7 +101,7 @@ describe("Stream", () => { yield* $(Queue.shutdown(queue2), Effect.zipRight(TestClock.adjust(Duration.seconds(1)))) yield* $(Queue.offer(queue1, 3)) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Array.from(result), [1, 2]) + deepStrictEqual(Array.from(result), [1, 2]) })) it.effect("mergeHaltEither - terminates as soon as either stream terminates", () => @@ -120,7 +120,7 @@ describe("Stream", () => { yield* $(TestClock.adjust(Duration.seconds(1))) yield* $(Queue.offer(queue2, 1)) const result = yield* $(Fiber.join(fiber)) - assert.isTrue(Chunk.isEmpty(result)) + assertTrue(Chunk.isEmpty(result)) })) it.effect("merge - equivalence with set union", () => @@ -143,7 +143,7 @@ describe("Stream", () => { Effect.map(HashSet.fromIterable) ) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("merge - fails as soon as one stream fails", () => @@ -154,7 +154,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.isTrue(Exit.isFailure(result)) + assertTrue(Exit.isFailure(result)) })) it.effect("mergeWith - prioritizes failures", () => @@ -167,6 +167,6 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) }) diff --git a/packages/effect/test/Stream/pagination.test.ts b/packages/effect/test/Stream/pagination.test.ts index 4d83e983bcd..aeb845a0bdb 100644 --- a/packages/effect/test/Stream/pagination.test.ts +++ b/packages/effect/test/Stream/pagination.test.ts @@ -2,8 +2,9 @@ import * as Chunk from "effect/Chunk" import * as Effect from "effect/Effect" import * as Option from "effect/Option" import * as Stream from "effect/Stream" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("paginate", () => @@ -16,7 +17,7 @@ describe("Stream", () => { [n, Option.some([nums[0], nums.slice(1)] as const)] as const), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [0, 1, 2, 3]) + deepStrictEqual(Array.from(result), [0, 1, 2, 3]) })) it.effect("paginateEffect", () => @@ -34,7 +35,7 @@ describe("Stream", () => { ), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [0, 1, 2, 3]) + deepStrictEqual(Array.from(result), [0, 1, 2, 3]) })) it.effect("paginateChunk", () => @@ -56,7 +57,7 @@ describe("Stream", () => { ] as const), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [0, 1, 2, 3, 4, 5]) + deepStrictEqual(Array.from(result), [0, 1, 2, 3, 4, 5]) })) it.effect("paginateChunkEffect", () => @@ -80,6 +81,6 @@ describe("Stream", () => { )), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [0, 1, 2, 3, 4, 5]) + deepStrictEqual(Array.from(result), [0, 1, 2, 3, 4, 5]) })) }) diff --git a/packages/effect/test/Stream/partitioning.test.ts b/packages/effect/test/Stream/partitioning.test.ts index 863e8e8b2ce..040c858cade 100644 --- a/packages/effect/test/Stream/partitioning.test.ts +++ b/packages/effect/test/Stream/partitioning.test.ts @@ -6,8 +6,9 @@ import * as Fiber from "effect/Fiber" import { pipe } from "effect/Function" import * as Ref from "effect/Ref" import * as Stream from "effect/Stream" +import { assertLeft, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("partitionEither - allows repeated runs without hanging", () => @@ -23,7 +24,7 @@ describe("Stream", () => { Effect.all(Array.from({ length: 100 }, () => stream)), Effect.as(0) ) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("partition - values", () => @@ -39,8 +40,8 @@ describe("Stream", () => { ), Effect.scoped ) - assert.deepStrictEqual(Array.from(result1), [0, 2, 4]) - assert.deepStrictEqual(Array.from(result2), [1, 3, 5]) + deepStrictEqual(Array.from(result1), [0, 2, 4]) + deepStrictEqual(Array.from(result2), [1, 3, 5]) })) it.effect("partition - errors", () => @@ -57,8 +58,8 @@ describe("Stream", () => { ), Effect.scoped ) - assert.deepStrictEqual(result1, Either.left("boom")) - assert.deepStrictEqual(result2, Either.left("boom")) + assertLeft(result1, "boom") + assertLeft(result2, "boom") })) it.effect("partition - backpressure", () => @@ -96,8 +97,8 @@ describe("Stream", () => { ), Effect.scoped ) - assert.deepStrictEqual(Array.from(result1), [2, 0]) - assert.deepStrictEqual(Array.from(result2), [1, 3, 5]) - assert.deepStrictEqual(Array.from(result3), [4, 2, 0]) + deepStrictEqual(Array.from(result1), [2, 0]) + deepStrictEqual(Array.from(result2), [1, 3, 5]) + deepStrictEqual(Array.from(result3), [4, 2, 0]) })) }) diff --git a/packages/effect/test/Stream/peeling.test.ts b/packages/effect/test/Stream/peeling.test.ts index 137cf89d3bb..6410a6af27d 100644 --- a/packages/effect/test/Stream/peeling.test.ts +++ b/packages/effect/test/Stream/peeling.test.ts @@ -4,8 +4,9 @@ import * as Exit from "effect/Exit" import { constTrue, pipe } from "effect/Function" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("peel", () => @@ -22,8 +23,8 @@ describe("Stream", () => { ), Effect.scoped ) - assert.deepStrictEqual(Array.from(peeled), [1, 2, 3]) - assert.deepStrictEqual(Array.from(rest), [4, 5, 6]) + deepStrictEqual(Array.from(peeled), [1, 2, 3]) + deepStrictEqual(Array.from(rest), [4, 5, 6]) })) it.effect("peel - propagates errors", () => @@ -40,6 +41,6 @@ describe("Stream", () => { Effect.exit, Effect.scoped ) - assert.deepStrictEqual(result, Exit.fail("fail")) + deepStrictEqual(result, Exit.fail("fail")) })) }) diff --git a/packages/effect/test/Stream/racing.test.ts b/packages/effect/test/Stream/racing.test.ts index dbd7b58a42e..cd5c44e4c21 100644 --- a/packages/effect/test/Stream/racing.test.ts +++ b/packages/effect/test/Stream/racing.test.ts @@ -3,9 +3,10 @@ import * as Effect from "effect/Effect" import * as Fiber from "effect/Fiber" import * as Schedule from "effect/Schedule" import * as Stream from "effect/Stream" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("raceAll sync", () => @@ -19,7 +20,7 @@ describe("Stream", () => { Stream.runCollect, Effect.map(Chunk.toReadonlyArray) ) - assert.deepStrictEqual(result, [0, 1, 2, 3]) + deepStrictEqual(result, [0, 1, 2, 3]) })) it.effect("raceAll async", () => @@ -36,7 +37,7 @@ describe("Stream", () => { ) yield* TestClock.adjust("5 second") const result = yield* Fiber.join(fiber) - assert.deepStrictEqual(result, [0, 1, 2, 3, 4]) + deepStrictEqual(result, [0, 1, 2, 3, 4]) })) it.effect("raceAll combined async + sync", () => @@ -49,7 +50,7 @@ describe("Stream", () => { Stream.runCollect, Effect.map(Chunk.toReadonlyArray) ) - assert.deepStrictEqual(result, [0, 1, 2, 3]) + deepStrictEqual(result, [0, 1, 2, 3]) })) it.effect("raceAll combined sync + async", () => @@ -62,6 +63,6 @@ describe("Stream", () => { Stream.runCollect, Effect.map(Chunk.toReadonlyArray) ) - assert.deepStrictEqual(result, [0, 1, 2, 3]) + deepStrictEqual(result, [0, 1, 2, 3]) })) }) diff --git a/packages/effect/test/Stream/repeating.test.ts b/packages/effect/test/Stream/repeating.test.ts index 530bdac9261..026cfeb5611 100644 --- a/packages/effect/test/Stream/repeating.test.ts +++ b/packages/effect/test/Stream/repeating.test.ts @@ -10,10 +10,11 @@ import * as Option from "effect/Option" import * as Ref from "effect/Ref" import * as Schedule from "effect/Schedule" import * as Stream from "effect/Stream" +import { deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" import * as TestEnvironment from "effect/TestContext" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("forever", () => @@ -25,7 +26,7 @@ describe("Stream", () => { Stream.runForEachWhile(() => Ref.modify(ref, (sum) => [sum >= 9 ? false : true, sum + 1] as const)) ) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 10) + strictEqual(result, 10) })) it.effect("repeat", () => @@ -35,7 +36,7 @@ describe("Stream", () => { Stream.repeat(Schedule.recurs(4)), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 1, 1, 1, 1]) + deepStrictEqual(Array.from(result), [1, 1, 1, 1, 1]) })) it.effect("tick", () => @@ -48,7 +49,7 @@ describe("Stream", () => { ) yield* $(TestClock.adjust(Duration.millis(50))) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Array.from(result), [undefined, undefined]) + deepStrictEqual(Array.from(result), [undefined, undefined]) })) it.effect("repeat - short circuits", () => @@ -64,7 +65,7 @@ describe("Stream", () => { yield* $(TestClock.adjust(Duration.millis(50))) yield* $(Fiber.join(fiber)) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [1, 1]) + deepStrictEqual(Array.from(result), [1, 1]) })) it.effect("repeat - does not swallow errors on a repetition", () => @@ -79,7 +80,7 @@ describe("Stream", () => { Stream.runDrain, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail("boom")) + deepStrictEqual(result, Exit.fail("boom")) })) it.effect("repeatEither", () => @@ -89,7 +90,7 @@ describe("Stream", () => { Stream.repeatEither(Schedule.recurs(4)), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [ + deepStrictEqual(Array.from(result), [ Either.right(1), Either.right(1), Either.left(0), @@ -109,7 +110,7 @@ describe("Stream", () => { Stream.take(2), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 1]) + deepStrictEqual(Array.from(result), [1, 1]) })) it.effect("repeatEffectOption - emit elements until pull fails with None", () => @@ -129,7 +130,7 @@ describe("Stream", () => { Stream.take(10), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 2, 3, 4]) + deepStrictEqual(Array.from(result), [1, 2, 3, 4]) })) it.effect("repeatEffectOption - stops evaluating the effect once it fails with None", () => @@ -150,7 +151,7 @@ describe("Stream", () => { Effect.scoped ) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("repeatEffectWithSchedule", () => @@ -168,7 +169,7 @@ describe("Stream", () => { yield* $(TestClock.adjust(Duration.millis(50))) yield* $(Fiber.join(fiber)) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [1, 1]) + deepStrictEqual(Array.from(result), [1, 1]) }), 10000) it.it("repeatEffectWithSchedule - allow schedule to rely on effect value", () => @@ -193,7 +194,7 @@ describe("Stream", () => { ) }) const result = await Effect.runPromise(effect) - assert.deepStrictEqual(Array.from(result), Array.from(Chunk.range(0, length))) + deepStrictEqual(Array.from(result), Array.from(Chunk.range(0, length))) }))) it.effect("repeatEffectWithSchedule - should perform repetitions in addition to the first execution (one repetition)", () => @@ -202,7 +203,7 @@ describe("Stream", () => { Stream.repeatEffectWithSchedule(Effect.succeed(1), Schedule.once), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 1]) + deepStrictEqual(Array.from(result), [1, 1]) })) it.effect("repeatEffectWithSchedule - should perform repetitions in addition to the first execution (zero repetitions)", () => @@ -211,7 +212,7 @@ describe("Stream", () => { Stream.repeatEffectWithSchedule(Effect.succeed(1), Schedule.stop), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1]) + deepStrictEqual(Array.from(result), [1]) })) it.effect("repeatEffectWithSchedule - emits before delaying according to the schedule", () => @@ -229,8 +230,8 @@ describe("Stream", () => { yield* $(TestClock.adjust(Duration.seconds(1))) const result2 = yield* $(Ref.get(ref)) yield* $(Fiber.interrupt(fiber)) - assert.strictEqual(result1, 1) - assert.strictEqual(result2, 2) + strictEqual(result1, 1) + strictEqual(result2, 2) })) it.effect("repeatEither - short circuits", () => @@ -246,7 +247,7 @@ describe("Stream", () => { yield* $(TestClock.adjust(Duration.millis(50))) yield* $(Fiber.join(fiber)) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [1, 1]) + deepStrictEqual(Array.from(result), [1, 1]) })) it.effect("repeatElements - simple", () => @@ -256,7 +257,7 @@ describe("Stream", () => { Stream.repeatElements(Schedule.once), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), ["A", "A", "B", "B", "C", "C"]) + deepStrictEqual(Array.from(result), ["A", "A", "B", "B", "C", "C"]) })) it.effect("repeatElements - short circuits in a schedule", () => @@ -267,7 +268,7 @@ describe("Stream", () => { Stream.take(4), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), ["A", "A", "B", "B"]) + deepStrictEqual(Array.from(result), ["A", "A", "B", "B"]) })) it.effect("repeatElements - short circuits after schedule", () => @@ -278,7 +279,7 @@ describe("Stream", () => { Stream.take(3), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), ["A", "A", "B"]) + deepStrictEqual(Array.from(result), ["A", "A", "B"]) })) it.effect("repeatElementsWith", () => @@ -292,6 +293,6 @@ describe("Stream", () => { Stream.repeatElementsWith(schedule, { onElement: identity, onSchedule: String }), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), ["A", "123", "B", "123", "C", "123"]) + deepStrictEqual(Array.from(result), ["A", "123", "B", "123", "C", "123"]) })) }) diff --git a/packages/effect/test/Stream/retrying.test.ts b/packages/effect/test/Stream/retrying.test.ts index 139974dc23f..4e6b73c8cf2 100644 --- a/packages/effect/test/Stream/retrying.test.ts +++ b/packages/effect/test/Stream/retrying.test.ts @@ -8,9 +8,10 @@ import * as Option from "effect/Option" import * as Ref from "effect/Ref" import * as Schedule from "effect/Schedule" import * as Stream from "effect/Stream" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("retry - retries a failing stream", () => @@ -26,7 +27,7 @@ describe("Stream", () => { Stream.take(2), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [0, 1]) + deepStrictEqual(Array.from(result), [0, 1]) })) it.effect("retry - cleans up resources before restarting the stream", () => @@ -48,7 +49,7 @@ describe("Stream", () => { Stream.take(2), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [0, 1]) + deepStrictEqual(Array.from(result), [0, 1]) })) it.effect("retry - retries a failing stream according to a schedule", () => @@ -74,7 +75,7 @@ describe("Stream", () => { yield* $(TestClock.adjust(Duration.seconds(2))) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref), Effect.map(Chunk.map((n) => new Date(n).getSeconds()))) - assert.deepStrictEqual(Array.from(result), [3, 1, 0]) + deepStrictEqual(Array.from(result), [3, 1, 0]) })) it.effect("retry - reset the schedule after a successful pull", () => @@ -111,6 +112,6 @@ describe("Stream", () => { yield* $(TestClock.adjust(Duration.seconds(1))) yield* $(Fiber.join(fiber)) const result = yield* $(Ref.get(times)) - assert.deepStrictEqual(Array.from(result), [4, 3, 3, 1, 0]) + deepStrictEqual(Array.from(result), [4, 3, 3, 1, 0]) })) }) diff --git a/packages/effect/test/Stream/running.test.ts b/packages/effect/test/Stream/running.test.ts index c4bf851a13e..bf27482da77 100644 --- a/packages/effect/test/Stream/running.test.ts +++ b/packages/effect/test/Stream/running.test.ts @@ -1,12 +1,12 @@ import * as Chunk from "effect/Chunk" import * as Effect from "effect/Effect" import { pipe } from "effect/Function" -import * as Option from "effect/Option" import * as Ref from "effect/Ref" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { assertFalse, assertNone, assertSome, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("runFoldWhile", () => @@ -15,7 +15,7 @@ describe("Stream", () => { Stream.make(1, 1, 1, 1, 1), Stream.runFoldWhile(0, (n) => n < 3, (x, y) => x + y) ) - assert.strictEqual(result, 3) + strictEqual(result, 3) })) it.effect("runForEach - with a small data set", () => @@ -26,7 +26,7 @@ describe("Stream", () => { Stream.runForEach((i) => Ref.update(ref, (n) => n + i)) ) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 5) + strictEqual(result, 5) })) it.effect("runForEach - with a bigger data set", () => @@ -37,7 +37,7 @@ describe("Stream", () => { Stream.runForEach((i) => Ref.update(ref, (n) => n + i)) ) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 1_000) + strictEqual(result, 1_000) })) it.effect("runForEachWhile - with a small data set", () => @@ -56,7 +56,7 @@ describe("Stream", () => { ) ) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, expected) + strictEqual(result, expected) })) it.effect("runForEachWhile - with a bigger data set", () => @@ -73,7 +73,7 @@ describe("Stream", () => { ) ) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, expected) + strictEqual(result, expected) })) it.effect("runForEachWhile - short circuits", () => @@ -85,19 +85,19 @@ describe("Stream", () => { Stream.runForEachWhile(Effect.succeed) ) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("runHead - non-empty stream", () => Effect.gen(function*($) { const result = yield* $(Stream.runHead(Stream.make(1, 2, 3, 4))) - assert.deepStrictEqual(result, Option.some(1)) + assertSome(result, 1) })) it.effect("runHead - empty stream", () => Effect.gen(function*($) { const result = yield* $(Stream.runHead(Stream.empty)) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("runHead - pulls up to the first non-empty chunk", () => @@ -114,8 +114,8 @@ describe("Stream", () => { Stream.runHead ) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(head, Option.some(1)) - assert.deepStrictEqual(Array.from(result), [2, 1]) + assertSome(head, 1) + deepStrictEqual(Array.from(result), [2, 1]) })) it.effect("runLast - non-empty stream", () => @@ -124,13 +124,13 @@ describe("Stream", () => { Stream.make(1, 2, 3, 4), Stream.runLast ) - assert.deepStrictEqual(result, Option.some(4)) + assertSome(result, 4) })) it.effect("runLast - empty stream", () => Effect.gen(function*($) { const result = yield* $(Stream.empty, Stream.runLast) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("runScoped - properly closes resources", () => @@ -148,8 +148,8 @@ describe("Stream", () => { Effect.scoped ) const finalState = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [1, 1, 1]) - assert.isFalse(state) - assert.isTrue(finalState) + deepStrictEqual(Array.from(result), [1, 1, 1]) + assertFalse(state) + assertTrue(finalState) })) }) diff --git a/packages/effect/test/Stream/scanning.test.ts b/packages/effect/test/Stream/scanning.test.ts index c32a8587fe9..30605b33c54 100644 --- a/packages/effect/test/Stream/scanning.test.ts +++ b/packages/effect/test/Stream/scanning.test.ts @@ -3,8 +3,9 @@ import * as Chunk from "effect/Chunk" import * as Effect from "effect/Effect" import { pipe } from "effect/Function" import * as Stream from "effect/Stream" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("scan", () => @@ -22,7 +23,7 @@ describe("Stream", () => { ) ) })) - assert.deepStrictEqual(Chunk.toReadonlyArray(result1), result2) + deepStrictEqual(Chunk.toReadonlyArray(result1), result2) })) it.effect("scanReduce", () => @@ -33,6 +34,6 @@ describe("Stream", () => { Stream.scanReduce((acc, curr) => acc + curr), Stream.runCollect ) - assert.deepStrictEqual(Chunk.toReadonlyArray(result), [1, 3, 6, 10, 15]) + deepStrictEqual(Chunk.toReadonlyArray(result), [1, 3, 6, 10, 15]) })) }) diff --git a/packages/effect/test/Stream/scheduling.test.ts b/packages/effect/test/Stream/scheduling.test.ts index 1deca1cafd2..da4d0d2e4d3 100644 --- a/packages/effect/test/Stream/scheduling.test.ts +++ b/packages/effect/test/Stream/scheduling.test.ts @@ -5,9 +5,10 @@ import * as Fiber from "effect/Fiber" import { identity, pipe } from "effect/Function" import * as Schedule from "effect/Schedule" import * as Stream from "effect/Stream" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("schedule", () => @@ -27,7 +28,7 @@ describe("Stream", () => { ) yield* $(TestClock.adjust(Duration.millis(800))) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Array.from(result), [ + deepStrictEqual(Array.from(result), [ [1, 100], [2, 200], [3, 300], @@ -50,6 +51,6 @@ describe("Stream", () => { Stream.scheduleWith(schedule, { onElement: (s) => s.toLowerCase(), onSchedule: identity }), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), ["a", "b", "c", "Done", "a", "b", "c", "Done"]) + deepStrictEqual(Array.from(result), ["a", "b", "c", "Done", "a", "b", "c", "Done"]) })) }) diff --git a/packages/effect/test/Stream/scoping.test.ts b/packages/effect/test/Stream/scoping.test.ts index d7c8ea813d3..1863908dc6d 100644 --- a/packages/effect/test/Stream/scoping.test.ts +++ b/packages/effect/test/Stream/scoping.test.ts @@ -3,16 +3,15 @@ import * as Cause from "effect/Cause" import * as Chunk from "effect/Chunk" import * as Deferred from "effect/Deferred" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import * as Exit from "effect/Exit" import * as Fiber from "effect/Fiber" import * as FiberId from "effect/FiberId" -import * as Option from "effect/Option" import * as Ref from "effect/Ref" import * as Scope from "effect/Scope" import * as Stream from "effect/Stream" +import { assertFalse, assertLeft, assertSome, assertTrue, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("acquireRelease - simple example", () => @@ -24,8 +23,8 @@ describe("Stream", () => { ).pipe(Stream.flatMap(Stream.fromIterable)) const result = yield* Stream.runCollect(stream) const released = yield* Ref.get(ref) - assert.isTrue(released) - assert.deepStrictEqual(Chunk.toArray(result), [0, 1, 2]) + assertTrue(released) + deepStrictEqual(Chunk.toArray(result), [0, 1, 2]) })) it.effect("acquireRelease - short circuits", () => @@ -40,8 +39,8 @@ describe("Stream", () => { ) const result = yield* Stream.runCollect(stream) const released = yield* Ref.get(ref) - assert.isTrue(released) - assert.deepStrictEqual(Chunk.toArray(result), [0, 1]) + assertTrue(released) + deepStrictEqual(Chunk.toArray(result), [0, 1]) })) it.effect("acquireRelease - no acquisition when short circuiting", () => @@ -58,7 +57,7 @@ describe("Stream", () => { ) yield* Stream.runDrain(stream) const result = yield* Ref.get(ref) - assert.isFalse(result) + assertFalse(result) })) it.effect("acquireRelease - releases when there are defects", () => @@ -73,7 +72,7 @@ describe("Stream", () => { Effect.exit ) const result = yield* Ref.get(ref) - assert.isTrue(result) + assertTrue(result) })) it.effect("acquireRelease - flatMap associativity does not effect lifetime", () => @@ -99,8 +98,8 @@ describe("Stream", () => { Stream.runCollect, Effect.map(Chunk.head) ) - assert.deepStrictEqual(leftAssoc, Option.some(true)) - assert.deepStrictEqual(rightAssoc, Option.some(true)) + assertSome(leftAssoc, true) + assertSome(rightAssoc, true) })) it.effect("acquireRelease - propagates errors", () => @@ -112,7 +111,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.die(new Cause.RuntimeException("die"))) + deepStrictEqual(result, Exit.die(new Cause.RuntimeException("die"))) })) it.effect("ensuring", () => @@ -127,7 +126,7 @@ describe("Stream", () => { Stream.runDrain ) const result = yield* Ref.get(ref) - assert.deepStrictEqual(Chunk.toArray(result), ["Acquire", "Use", "Release", "Ensuring"]) + deepStrictEqual(Chunk.toArray(result), ["Acquire", "Use", "Release", "Ensuring"]) })) it.effect("scoped - preserves the failure of an effect", () => @@ -136,7 +135,7 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left("fail")) + assertLeft(result, "fail") })) it.effect("scoped - preserves the interruptibility of an effect", () => @@ -148,8 +147,8 @@ describe("Stream", () => { const isInterruptible2 = yield* Effect.uninterruptible( Effect.checkInterruptible(Effect.succeed) ).pipe(Stream.scoped, Stream.runHead) - assert.deepStrictEqual(isInterruptible1, Option.some(true)) - assert.deepStrictEqual(isInterruptible2, Option.some(false)) + assertSome(isInterruptible1, true) + assertSome(isInterruptible2, false) })) it.it("unwrapScoped", async () => { @@ -174,7 +173,7 @@ describe("Stream", () => { }) const result = await Effect.runPromise(program) await Effect.runPromise(Deferred.succeed(awaiter, void 0)) - assert.deepStrictEqual(result, ["acquire outer", "release outer"]) + deepStrictEqual(result, ["acquire outer", "release outer"]) }) it.effect("preserves the scope", () => @@ -193,7 +192,7 @@ describe("Stream", () => { const before = yield* Ref.getAndSet(ref, Array.empty()) yield* Scope.close(scope, Exit.void) const after = yield* Ref.get(ref) - assert.deepStrictEqual(before, ["Acquire: 1", "Acquire: 2"]) - assert.deepStrictEqual(after, ["Release: 2", "Release: 1"]) + deepStrictEqual(before, ["Acquire: 1", "Acquire: 2"]) + deepStrictEqual(after, ["Release: 2", "Release: 1"]) })) }) diff --git a/packages/effect/test/Stream/sequencing.test.ts b/packages/effect/test/Stream/sequencing.test.ts index 3cc31336e1f..bacdbd3796e 100644 --- a/packages/effect/test/Stream/sequencing.test.ts +++ b/packages/effect/test/Stream/sequencing.test.ts @@ -2,7 +2,6 @@ import * as Cause from "effect/Cause" import * as Chunk from "effect/Chunk" import * as Deferred from "effect/Deferred" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import * as Equal from "effect/Equal" import * as Exit from "effect/Exit" import * as Fiber from "effect/Fiber" @@ -11,8 +10,9 @@ import * as Ref from "effect/Ref" import * as Scope from "effect/Scope" import * as Stream from "effect/Stream" import * as Take from "effect/Take" +import { assertLeft, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" const withPermitsScoped = (permits: number) => (semaphore: Effect.Semaphore) => Effect.acquireRelease( @@ -33,7 +33,7 @@ describe("Stream", () => { }), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 2, 3, 4, 5]) + deepStrictEqual(Array.from(result), [1, 2, 3, 4, 5]) })) it.effect("branchAfter - emits data if less than n elements are collected", () => @@ -43,7 +43,7 @@ describe("Stream", () => { Stream.branchAfter(6, (chunk) => Stream.prepend(Stream.identity(), chunk)), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 2, 3, 4, 5]) + deepStrictEqual(Array.from(result), [1, 2, 3, 4, 5]) })) it.effect("branchAfter - applies the new stream once on remaining upstream", () => @@ -54,7 +54,7 @@ describe("Stream", () => { Stream.branchAfter(1, (chunk) => Stream.prepend(Stream.identity(), chunk)), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 2, 3, 4, 5]) + deepStrictEqual(Array.from(result), [1, 2, 3, 4, 5]) })) it.effect("execute", () => @@ -62,7 +62,7 @@ describe("Stream", () => { const ref = yield* $(Ref.make(Chunk.empty())) yield* $(Stream.runDrain(Stream.execute(Ref.set(ref, Chunk.fromIterable([1]))))) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [1]) + deepStrictEqual(Array.from(result), [1]) })) it.effect("flatMap - deep flatMap stack safety", () => @@ -80,7 +80,7 @@ describe("Stream", () => { ) ) const result = yield* $(Stream.runCollect(fib(10))) - assert.deepStrictEqual(Array.from(result), [55]) + deepStrictEqual(Array.from(result), [55]) })) it.effect("flatMap - left identity", () => @@ -90,7 +90,7 @@ describe("Stream", () => { result1: pipe(Stream.make(1), Stream.flatMap(f), Stream.runCollect), result2: Stream.runCollect(f(1)) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("flatMap - right identity", () => @@ -99,7 +99,7 @@ describe("Stream", () => { result1: pipe(Stream.make(1), Stream.flatMap((n) => Stream.make(n)), Stream.runCollect), result2: Stream.runCollect(Stream.make(1)) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("flatMap - associativity", () => @@ -111,7 +111,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.flatMap(f), Stream.flatMap(g), Stream.runCollect), result2: pipe(stream, Stream.flatMap((n) => pipe(f(n), Stream.flatMap(g))), Stream.runCollect) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("flatMap - inner finalizers", () => @@ -138,7 +138,7 @@ describe("Stream", () => { yield* $(Deferred.await(latch)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [1, 1, 2, 3, 3]) + deepStrictEqual(Array.from(result), [1, 1, 2, 3, 3]) })) it.effect("flatMap - finalizer ordering #1", () => @@ -170,7 +170,7 @@ describe("Stream", () => { Stream.runDrain ) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [ + deepStrictEqual(Array.from(result), [ "open 1", "use 2", "open 3", @@ -201,7 +201,7 @@ describe("Stream", () => { Stream.runDrain ) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [ + deepStrictEqual(Array.from(result), [ "use 1", "open 2", "close 2", @@ -229,7 +229,7 @@ describe("Stream", () => { Effect.either ) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("flatMap - finalizers are registered in the proper order", () => @@ -244,7 +244,7 @@ describe("Stream", () => { Effect.scoped ) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [1, 2]) + deepStrictEqual(Array.from(result), [1, 2]) })) it.effect("flatMap - early release finalizer concatenation is preserved", () => @@ -270,7 +270,7 @@ describe("Stream", () => { ) ) ) - assert.deepStrictEqual(Array.from(result), [1, 2]) + deepStrictEqual(Array.from(result), [1, 2]) })) it.effect("flatMapPar - guarantee ordering", () => @@ -280,7 +280,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.flatMap((n) => Stream.make(n, n)), Stream.runCollect), result2: pipe(stream, Stream.flatMap((n) => Stream.make(n, n), { concurrency: 2 }), Stream.runCollect) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("flatMapPar - consistency with flatMap", () => @@ -298,7 +298,7 @@ describe("Stream", () => { Stream.runCollect ) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("flatMapPar - interruption propagation", () => @@ -320,7 +320,7 @@ describe("Stream", () => { yield* $(Deferred.await(latch)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("flatMap - inner errors interrupt all fibers", () => @@ -348,8 +348,8 @@ describe("Stream", () => { Effect.either ) const cancelled = yield* $(Ref.get(ref)) - assert.isTrue(cancelled) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertTrue(cancelled) + assertLeft(result, "Ouch") })) it.effect("flatMapPar - outer errors interrupt all fiberrs", () => @@ -373,8 +373,8 @@ describe("Stream", () => { Effect.either ) const cancelled = yield* $(Ref.get(ref)) - assert.isTrue(cancelled) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertTrue(cancelled) + assertLeft(result, "Ouch") })) it.effect("flatMapPar - inner defects interrupt all fibers", () => @@ -399,8 +399,8 @@ describe("Stream", () => { Effect.exit ) const cancelled = yield* $(Ref.get(ref)) - assert.isTrue(cancelled) - assert.deepStrictEqual(result, Exit.die(defect)) + assertTrue(cancelled) + deepStrictEqual(result, Exit.die(defect)) })) it.effect("flatMapPar - outer defects interrupt all fibers", () => @@ -425,8 +425,8 @@ describe("Stream", () => { Effect.exit ) const cancelled = yield* $(Ref.get(ref)) - assert.isTrue(cancelled) - assert.deepStrictEqual(result, Exit.die(defect)) + assertTrue(cancelled) + deepStrictEqual(result, Exit.die(defect)) })) it.effect("flatMapPar - finalizer ordering", () => @@ -446,7 +446,7 @@ describe("Stream", () => { Stream.runDrain ) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [ + deepStrictEqual(Array.from(result), [ "Outer Acquire", "Inner Acquire", "Inner Release", @@ -475,7 +475,7 @@ describe("Stream", () => { Stream.runDrain ) const result = yield* $(semaphore.withPermits(1)(Ref.get(ref))) - assert.isTrue(result) + assertTrue(result) })) it.effect("flatMapParSwitch - guarantee ordering with parallelism", () => @@ -505,7 +505,7 @@ describe("Stream", () => { Ref.get(ref), semaphore.withPermits(4) ) - assert.strictEqual(result, 4) + strictEqual(result, 4) })) it.effect("flatMapParSwitch - short circuiting", () => @@ -516,7 +516,7 @@ describe("Stream", () => { Stream.take(1), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1]) + deepStrictEqual(Array.from(result), [1]) })) it.effect("flatMapParSwitch - interruption propagation", () => @@ -538,7 +538,7 @@ describe("Stream", () => { yield* $(Deferred.await(latch)) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) it.effect("flatMapParSwitch - inner errors interrupt all fibers", () => @@ -566,8 +566,8 @@ describe("Stream", () => { Effect.either ) const cancelled = yield* $(Ref.get(ref)) - assert.isTrue(cancelled) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertTrue(cancelled) + assertLeft(result, "Ouch") })) it.effect("flatMapParSwitch - outer errors interrupt all fibers", () => @@ -591,8 +591,8 @@ describe("Stream", () => { Effect.either ) const cancelled = yield* $(Ref.get(ref)) - assert.isTrue(cancelled) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertTrue(cancelled) + assertLeft(result, "Ouch") })) it.effect("flatMapParSwitch - inner defects interrupt all fibers", () => @@ -621,8 +621,8 @@ describe("Stream", () => { Effect.exit ) const cancelled = yield* $(Ref.get(ref)) - assert.isTrue(cancelled) - assert.deepStrictEqual(result, Exit.die(error)) + assertTrue(cancelled) + deepStrictEqual(result, Exit.die(error)) })) it.effect("flatMapParSwitch - outer defects interrupt all fibers", () => @@ -647,8 +647,8 @@ describe("Stream", () => { Effect.exit ) const cancelled = yield* $(Ref.get(ref)) - assert.isTrue(cancelled) - assert.deepStrictEqual(result, Exit.die(error)) + assertTrue(cancelled) + deepStrictEqual(result, Exit.die(error)) })) it.effect("flatMapParSwitch - finalizer ordering", () => @@ -668,7 +668,7 @@ describe("Stream", () => { Stream.runDrain ) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(Array.from(result), [ + deepStrictEqual(Array.from(result), [ "Outer Acquire", "Inner Acquire", "Inner Release", @@ -685,7 +685,7 @@ describe("Stream", () => { Stream.chunks, Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), Array.from(chunks).map((chunk) => Array.from(chunk)) ) @@ -706,7 +706,7 @@ describe("Stream", () => { ), Effect.scoped ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(Chunk.flatten(result)), Array.from(Chunk.range(0, 9)) ) @@ -730,7 +730,7 @@ describe("Stream", () => { Effect.scoped, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(error)) + deepStrictEqual(result, Exit.fail(error)) })) it.effect("flattenIterables", () => @@ -741,7 +741,7 @@ describe("Stream", () => { Stream.flattenIterables, Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), iterables.flatMap(identity)) + deepStrictEqual(Array.from(result), iterables.flatMap(identity)) })) it.effect("flattenTake - happy path", () => @@ -753,7 +753,7 @@ describe("Stream", () => { Stream.flattenTake, Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), Array.from(Chunk.flatten(chunks))) + deepStrictEqual(Array.from(result), Array.from(Chunk.flatten(chunks))) })) it.effect("flattenTake - stop collecting on Exit.Failure", () => @@ -767,7 +767,7 @@ describe("Stream", () => { Stream.flattenTake, Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 2, 3]) + deepStrictEqual(Array.from(result), [1, 2, 3]) })) it.effect("flattenTake - works with empty chunks", () => @@ -780,7 +780,7 @@ describe("Stream", () => { Stream.flattenTake, Stream.runCollect ) - assert.isTrue(Chunk.isEmpty(result)) + assertTrue(Chunk.isEmpty(result)) })) it.effect("flattenTake - works with empty streams", () => @@ -790,6 +790,6 @@ describe("Stream", () => { Stream.flattenTake, Stream.runCollect ) - assert.isTrue(Chunk.isEmpty(result)) + assertTrue(Chunk.isEmpty(result)) })) }) diff --git a/packages/effect/test/Stream/sliding.test.ts b/packages/effect/test/Stream/sliding.test.ts index 73e67580a0d..474a72a5362 100644 --- a/packages/effect/test/Stream/sliding.test.ts +++ b/packages/effect/test/Stream/sliding.test.ts @@ -1,11 +1,11 @@ import * as Chunk from "effect/Chunk" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import { pipe } from "effect/Function" import * as Ref from "effect/Ref" import * as Stream from "effect/Stream" +import { assertLeft, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("sliding - returns a sliding window", () => @@ -61,11 +61,11 @@ describe("Stream", () => { Stream.runCollect ) const expected = [[1, 2], [2, 3], [3, 4], [4, 5]] - assert.deepStrictEqual(Array.from(result1).map((chunk) => Array.from(chunk)), expected) - assert.deepStrictEqual(Array.from(result2).map((chunk) => Array.from(chunk)), expected) - assert.deepStrictEqual(Array.from(result3).map((chunk) => Array.from(chunk)), expected) - assert.deepStrictEqual(Array.from(result4).map((chunk) => Array.from(chunk)), expected) - assert.deepStrictEqual(Array.from(result5).map((chunk) => Array.from(chunk)), expected) + deepStrictEqual(Array.from(result1).map((chunk) => Array.from(chunk)), expected) + deepStrictEqual(Array.from(result2).map((chunk) => Array.from(chunk)), expected) + deepStrictEqual(Array.from(result3).map((chunk) => Array.from(chunk)), expected) + deepStrictEqual(Array.from(result4).map((chunk) => Array.from(chunk)), expected) + deepStrictEqual(Array.from(result5).map((chunk) => Array.from(chunk)), expected) })) it.effect("sliding - returns all elements if chunkSize is greater than the size of the stream", () => @@ -75,7 +75,7 @@ describe("Stream", () => { Stream.sliding(6), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result).map((chunk) => Array.from(chunk)), [[1, 2, 3, 4, 5]]) + deepStrictEqual(Array.from(result).map((chunk) => Array.from(chunk)), [[1, 2, 3, 4, 5]]) })) it.effect("sliding - is mostly equivalent to ZStream#grouped when stepSize and chunkSize are equal", () => @@ -85,7 +85,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.slidingSize(3, 3), Stream.runCollect), result2: pipe(stream, Stream.grouped(3), Stream.runCollect) })) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result1).map((chunk) => Array.from(chunk)), Array.from(result2).map((chunk) => Array.from(chunk)) ) @@ -101,13 +101,13 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) it.effect("sliding - should return an empty chunk when the stream is empty", () => Effect.gen(function*($) { const result = yield* $(Stream.empty, Stream.sliding(2), Stream.runCollect) - assert.deepStrictEqual(Array.from(result), []) + deepStrictEqual(Array.from(result), []) })) it.effect("sliding - emits elements properly when a failure occurs", () => @@ -130,8 +130,8 @@ describe("Stream", () => { Effect.either ) const result = yield* $(Ref.get(ref)) - assert.deepStrictEqual(either, Either.left("Ouch")) - assert.deepStrictEqual( + assertLeft(either, "Ouch") + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1, 2, 3], [4, 5, 6], [7, 8]] ) diff --git a/packages/effect/test/Stream/splitting.test.ts b/packages/effect/test/Stream/splitting.test.ts index fa2d310d37c..58ac7b6f9a5 100644 --- a/packages/effect/test/Stream/splitting.test.ts +++ b/packages/effect/test/Stream/splitting.test.ts @@ -2,9 +2,10 @@ import * as Chunk from "effect/Chunk" import * as Effect from "effect/Effect" import { pipe } from "effect/Function" import * as Stream from "effect/Stream" +import { deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as fc from "fast-check" -import { assert, describe } from "vitest" +import { describe } from "vitest" const weirdStringForSplitLines: fc.Arbitrary> = fc.array( fc.string().filter((s) => s !== "\n" && s !== "\r") @@ -50,11 +51,11 @@ describe("Stream", () => { Stream.runCollect ) })) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result1).map((chunk) => Array.from(chunk)), [[1, 2, 3], [5, 6, 7], [9]] ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result2).map((chunk) => Array.from(chunk)), [[1, 2], [4, 5], [7, 8], [10]] ) @@ -70,11 +71,11 @@ describe("Stream", () => { Effect.map((chunk) => pipe(Chunk.of(chunk), Chunk.filter(Chunk.isNonEmpty))) ) })) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result1).map((chunk) => Array.from(chunk)), [Array.from(Chunk.range(1, 10))] ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result1).map((chunk) => Array.from(chunk)), Array.from(result2).map((chunk) => Array.from(chunk)) ) @@ -87,7 +88,7 @@ describe("Stream", () => { Stream.split((n: number) => n % 11 === 0), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), []) + deepStrictEqual(Array.from(result), []) })) it.effect("splitOnChunk - consecutive delimiter yields empty Chunk", () => @@ -105,7 +106,7 @@ describe("Stream", () => { Stream.map(Chunk.size), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [0, 0, 0, 1, 0]) + deepStrictEqual(Array.from(result), [0, 0, 0, 1, 0]) })) it.effect("splitOnChunk - preserves data", () => @@ -118,7 +119,7 @@ describe("Stream", () => { Stream.runCollect, Effect.map(Chunk.flatten) ) - assert.deepStrictEqual(Array.from(result), [1, 1, 1, 1, 1, 1]) + deepStrictEqual(Array.from(result), [1, 1, 1, 1, 1, 1]) })) it.effect("splitOnChunk - handles leftovers", () => @@ -129,7 +130,7 @@ describe("Stream", () => { Stream.splitOnChunk(splitSequence), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1, 0, 2], [2, 2]] ) @@ -143,7 +144,7 @@ describe("Stream", () => { Stream.splitOnChunk(splitSequence), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1, 2], [3, 4], [5, 6, 5, 6]] ) @@ -164,7 +165,7 @@ describe("Stream", () => { Stream.splitOnChunk(splitSequence), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1, 2], [3, 4], [5, 6, 5, 6]] ) @@ -177,7 +178,7 @@ describe("Stream", () => { Stream.splitOnChunk(Chunk.make(0)), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[]] ) @@ -190,7 +191,7 @@ describe("Stream", () => { Stream.splitOnChunk(Chunk.make(1, 1)), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1, 2, 1, 2, 1, 2]] ) @@ -203,7 +204,7 @@ describe("Stream", () => { Stream.splitOnChunk(Chunk.make(2, 1)), Stream.runCollect ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[1], [2]] ) @@ -219,7 +220,7 @@ describe("Stream", () => { Effect.map((chunk) => Chunk.toReadonlyArray(chunk).join("\n")) ) const result = await Effect.runPromise(program) - assert.strictEqual(result, data) + strictEqual(result, data) }))) // it("splitLines - preserves data in chunks", () => @@ -238,7 +239,7 @@ describe("Stream", () => { Effect.gen(function*($) { const chunks = [Chunk.of("abc\nbc")] const [expected, result] = yield* $(testSplitLines(chunks)) - assert.deepStrictEqual(expected, result) + deepStrictEqual(expected, result) })) it.effect("splitLines - handles leftovers 2", () => @@ -250,14 +251,14 @@ describe("Stream", () => { Chunk.of("abc") ] const [expected, result] = yield* $(testSplitLines(chunks)) - assert.deepStrictEqual(expected, result) + deepStrictEqual(expected, result) })) it.effect("splitLines - aggregates chunks", () => Effect.gen(function*($) { const chunks = [Chunk.make("abc", "\n", "bc", "\n", "bcd", "bcd")] const [expected, result] = yield* $(testSplitLines(chunks)) - assert.deepStrictEqual(expected, result) + deepStrictEqual(expected, result) })) it.effect("splitLines - single newline edge case", () => @@ -266,27 +267,27 @@ describe("Stream", () => { const [, result] = yield* $(testSplitLines(chunks)) // JavaScript arrays split `"\n"` into `["", ""]`, so we manually assert // that the output should be the empty string here - assert.deepStrictEqual([""], result) + deepStrictEqual([""], result) })) it.effect("splitLines - no newlines", () => Effect.gen(function*($) { const chunks = [Chunk.make("abc", "abc", "abc")] const [expected, result] = yield* $(testSplitLines(chunks)) - assert.deepStrictEqual(expected, result) + deepStrictEqual(expected, result) })) it.effect("splitLines - \\r\\n on the boundary", () => Effect.gen(function*($) { const chunks = [Chunk.make("abc\r", "\nabc")] const [expected, result] = yield* $(testSplitLines(chunks)) - assert.deepStrictEqual(expected, result) + deepStrictEqual(expected, result) })) it.effect("splitLines - ZIO issue #6360", () => Effect.gen(function*($) { const chunks = [Chunk.make("AAAAABBBB#\r\r\r\n", "test")] const [_, result] = yield* $(testSplitLines(chunks)) - assert.deepStrictEqual(["AAAAABBBB#\r\r", "test"], result) + deepStrictEqual(["AAAAABBBB#\r\r", "test"], result) })) }) diff --git a/packages/effect/test/Stream/streamable.test.ts b/packages/effect/test/Stream/streamable.test.ts index 7f6bed7f9ff..1d772f46f10 100644 --- a/packages/effect/test/Stream/streamable.test.ts +++ b/packages/effect/test/Stream/streamable.test.ts @@ -1,8 +1,9 @@ import * as Effect from "effect/Effect" import * as Stream from "effect/Stream" import * as Streamable from "effect/Streamable" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { describe, expect } from "vitest" +import { describe } from "vitest" describe("Streamable", () => { it.effect( @@ -18,7 +19,7 @@ describe("Streamable", () => { const values = Array.from(yield* $(Stream.runCollect(stream))) - expect(values).toEqual([1, 2, 3]) + deepStrictEqual(values, [1, 2, 3]) }) ) }) diff --git a/packages/effect/test/Stream/taking.test.ts b/packages/effect/test/Stream/taking.test.ts index 42dbe0df4e2..10ed90cf6e9 100644 --- a/packages/effect/test/Stream/taking.test.ts +++ b/packages/effect/test/Stream/taking.test.ts @@ -4,8 +4,9 @@ import * as Either from "effect/Either" import { constFalse, pipe } from "effect/Function" import * as Ref from "effect/Ref" import * as Stream from "effect/Stream" +import { assertFalse, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("take", () => @@ -16,7 +17,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.take(take), Stream.runCollect), result2: pipe(Stream.runCollect(stream), Effect.map(Chunk.take(take))) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("take - short circuits", () => @@ -29,13 +30,13 @@ describe("Stream", () => { ) yield* $(Stream.runDrain(stream)) const result = yield* $(Ref.get(ref)) - assert.isFalse(result) + assertFalse(result) })) it.effect("take - taking 0 short circuits", () => Effect.gen(function*($) { const result = yield* $(Stream.never, Stream.take(0), Stream.runCollect) - assert.deepStrictEqual(Array.from(result), []) + deepStrictEqual(Array.from(result), []) })) it.effect("take - taking 1 short circuits", () => @@ -46,7 +47,7 @@ describe("Stream", () => { Stream.take(1), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1]) + deepStrictEqual(Array.from(result), [1]) })) it.effect("takeRight", () => @@ -57,7 +58,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.takeRight(take), Stream.runCollect), result2: pipe(Stream.runCollect(stream), Effect.map(Chunk.takeRight(take))) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("takeUntil", () => @@ -77,7 +78,7 @@ describe("Stream", () => { ) ) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("takeUntilEffect", () => @@ -106,7 +107,7 @@ describe("Stream", () => { ) ) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("takeUntilEffect - laziness on chunks", () => @@ -121,7 +122,7 @@ describe("Stream", () => { Stream.either, Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [Either.right(1), Either.left("boom")]) + deepStrictEqual(Array.from(result), [Either.right(1), Either.left("boom")]) })) it.effect("takeWhile", () => @@ -132,7 +133,7 @@ describe("Stream", () => { result1: pipe(stream, Stream.takeWhile(f), Stream.runCollect), result2: pipe(Stream.runCollect(stream), Effect.map(Chunk.takeWhile(f))) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("takeWhile - does not stop when hitting an empty chunk (ZIO #4272)", () => @@ -147,7 +148,7 @@ describe("Stream", () => { Stream.takeWhile((n) => n !== 4), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 3]) + deepStrictEqual(Array.from(result), [1, 3]) })) it.effect("takeWhile - short circuits", () => @@ -158,6 +159,6 @@ describe("Stream", () => { Stream.takeWhile(constFalse), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), []) + deepStrictEqual(Array.from(result), []) })) }) diff --git a/packages/effect/test/Stream/tapping.test.ts b/packages/effect/test/Stream/tapping.test.ts index 37bea2cbe91..2d2879eb119 100644 --- a/packages/effect/test/Stream/tapping.test.ts +++ b/packages/effect/test/Stream/tapping.test.ts @@ -5,8 +5,9 @@ import { pipe } from "effect/Function" import * as Ref from "effect/Ref" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { assertLeft, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("tap", () => @@ -18,8 +19,8 @@ describe("Stream", () => { Stream.runCollect ) const sum = yield* $(Ref.get(ref)) - assert.strictEqual(sum, 2) - assert.deepStrictEqual(Array.from(result), [1, 1]) + strictEqual(sum, 2) + deepStrictEqual(Array.from(result), [1, 1]) })) it.effect("tap - laziness on chunks", () => @@ -30,7 +31,7 @@ describe("Stream", () => { Stream.either, Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [ + deepStrictEqual(Array.from(result), [ Either.right(1), Either.right(2), Either.left("error") @@ -50,8 +51,8 @@ describe("Stream", () => { Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), Array.from(values)) - assert.strictEqual(yield* $(Ref.get(ref)), 2) + deepStrictEqual(Array.from(result), Array.from(values)) + strictEqual(yield* $(Ref.get(ref)), 2) })) it.effect("tapBoth - just tap an error", () => @@ -67,8 +68,8 @@ describe("Stream", () => { Effect.either ) - assert.deepStrictEqual(result, Either.left("Ouch")) - assert.strictEqual(yield* $(Ref.get(ref)), "Ouch") + assertLeft(result, "Ouch") + strictEqual(yield* $(Ref.get(ref)), "Ouch") })) it.effect("tapBoth - tap values and then error", () => @@ -87,9 +88,9 @@ describe("Stream", () => { Effect.either ) - assert.deepStrictEqual(result, Either.left("Ouch")) - assert.strictEqual(yield* $(Ref.get(error)), "Ouch") - assert.strictEqual(yield* $(Ref.get(sum)), 2) + assertLeft(result, "Ouch") + strictEqual(yield* $(Ref.get(error)), "Ouch") + strictEqual(yield* $(Ref.get(sum)), 2) })) it.effect("tapBoth - tap chunks lazily", () => @@ -108,7 +109,7 @@ describe("Stream", () => { Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [ + deepStrictEqual(Array.from(result), [ Either.right(1), Either.right(2), Either.left("error") @@ -125,7 +126,7 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) it.effect("tapSink - sink that is done after stream", () => @@ -138,8 +139,8 @@ describe("Stream", () => { Stream.runCollect ) const sum = yield* $(Ref.get(ref)) - assert.strictEqual(sum, 20) - assert.deepStrictEqual(Array.from(result), [1, 1, 2, 3, 5, 8]) + strictEqual(sum, 20) + deepStrictEqual(Array.from(result), [1, 1, 2, 3, 5, 8]) })) it.effect("tapSink - sink that is done before stream", () => @@ -157,8 +158,8 @@ describe("Stream", () => { Stream.runCollect ) const sum = yield* $(Ref.get(ref)) - assert.strictEqual(sum, 4) - assert.deepStrictEqual(Array.from(result), [1, 1, 2, 3, 5, 8]) + strictEqual(sum, 4) + deepStrictEqual(Array.from(result), [1, 1, 2, 3, 5, 8]) })) it.effect("tapSink - sink that fails before stream", () => @@ -170,7 +171,7 @@ describe("Stream", () => { Stream.runCollect, Effect.flip ) - assert.strictEqual(result, "error") + strictEqual(result, "error") })) it.effect("tapSink - does not read ahead", () => @@ -186,6 +187,6 @@ describe("Stream", () => { Stream.runDrain ) const result = yield* $(Ref.get(ref)) - assert.strictEqual(result, 6) + strictEqual(result, 6) })) }) diff --git a/packages/effect/test/Stream/throttling.test.ts b/packages/effect/test/Stream/throttling.test.ts index a8fd3dadc0c..0594662cd95 100644 --- a/packages/effect/test/Stream/throttling.test.ts +++ b/packages/effect/test/Stream/throttling.test.ts @@ -1,3 +1,4 @@ +import * as Cause from "effect/Cause" import * as Chunk from "effect/Chunk" import * as Clock from "effect/Clock" import * as Duration from "effect/Duration" @@ -10,10 +11,11 @@ import * as Queue from "effect/Queue" import * as Ref from "effect/Ref" import * as Schedule from "effect/Schedule" import * as Stream from "effect/Stream" +import { assertFailure, assertTrue, deepStrictEqual } from "effect/test/util" import { chunkCoordination } from "effect/test/utils/coordination" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("throttleEnforce - free elements", () => @@ -23,7 +25,7 @@ describe("Stream", () => { Stream.throttle({ cost: () => 0, units: 0, duration: Duration.infinity, strategy: "enforce" }), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 2, 3, 4]) + deepStrictEqual(Array.from(result), [1, 2, 3, 4]) })) it.effect("throttleEnforce - no bandwidth", () => @@ -33,7 +35,7 @@ describe("Stream", () => { Stream.throttle({ cost: () => 1, units: 0, duration: Duration.infinity, strategy: "enforce" }), Stream.runCollect ) - assert.isTrue(Chunk.isEmpty(result)) + assertTrue(Chunk.isEmpty(result)) })) it.effect("throttleEnforce - refill bucket tokens", () => @@ -47,7 +49,7 @@ describe("Stream", () => { ) yield* _(TestClock.adjust(Duration.seconds(1))) const result = yield* _(Fiber.join(fiber)) - assert.deepStrictEqual(Array.from(result), [0, 2, 4, 6, 8]) + deepStrictEqual(Array.from(result), [0, 2, 4, 6, 8]) })) it.effect("throttleShape", () => @@ -79,7 +81,7 @@ describe("Stream", () => { ) yield* $(TestClock.adjust(Duration.seconds(8))) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(result, [[1], [2], [3]]) + deepStrictEqual(result, [[1], [2], [3]]) })) it.effect("throttleShape - infinite bandwidth", () => @@ -106,7 +108,7 @@ describe("Stream", () => { ), Effect.scoped ) - assert.deepStrictEqual(result, [[1], [2], 0]) + deepStrictEqual(result, [[1], [2], 0]) })) it.effect("throttleShape - with burst", () => @@ -139,7 +141,7 @@ describe("Stream", () => { Effect.fork ) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(result, [[1], [2], [3]]) + deepStrictEqual(result, [[1], [2], [3]]) })) it.effect("throttleShape - free elements", () => @@ -154,7 +156,7 @@ describe("Stream", () => { }), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 2, 3, 4]) + deepStrictEqual(Array.from(result), [1, 2, 3, 4]) })) it.effect("debounce - should drop earlier chunks within waitTime", () => @@ -193,7 +195,7 @@ describe("Stream", () => { ) yield* $(TestClock.adjust(Duration.millis(3500))) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[3, 4], [6, 7]] ) @@ -220,7 +222,7 @@ describe("Stream", () => { ) yield* $(TestClock.adjust(Duration.seconds(1))) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[5, 6]] ) @@ -247,7 +249,7 @@ describe("Stream", () => { ], { concurrency: 3, discard: true })) yield* $(TestClock.adjust(Duration.seconds(1))) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result).map((chunk) => Array.from(chunk)), [[3]] ) @@ -264,7 +266,7 @@ describe("Stream", () => { ) yield* $(TestClock.adjust(Duration.seconds(3))) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Array.from(result), [3]) + deepStrictEqual(Array.from(result), [3]) })) it.effect("debounce - should fail immediately", () => @@ -275,7 +277,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(Option.none())) + assertFailure(result, Cause.fail(Option.none())) })) it.effect("debounce - should work with empty streams", () => @@ -285,7 +287,7 @@ describe("Stream", () => { Stream.debounce(Duration.seconds(5)), Stream.runCollect ) - assert.isTrue(Chunk.isEmpty(result)) + assertTrue(Chunk.isEmpty(result)) })) it.effect("debounce - should pick last element from every chunk", () => @@ -298,7 +300,7 @@ describe("Stream", () => { ) yield* $(TestClock.adjust(Duration.seconds(1))) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Array.from(result), [3]) + deepStrictEqual(Array.from(result), [3]) })) it.effect("debounce - should interrupt fibers properly", () => @@ -328,7 +330,7 @@ describe("Stream", () => { ) yield* $(TestClock.adjust(Duration.millis(100))) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Array.from(result), [3]) + deepStrictEqual(Array.from(result), [3]) })) it.effect("debounce - should interrupt children fiber on stream interruption", () => @@ -347,6 +349,6 @@ describe("Stream", () => { yield* $(TestClock.adjust(Duration.minutes(1))) yield* $(Fiber.interrupt(fiber)) const result = yield* $(Ref.get(ref)) - assert.isTrue(result) + assertTrue(result) })) }) diff --git a/packages/effect/test/Stream/timeouts.test.ts b/packages/effect/test/Stream/timeouts.test.ts index 4445698af78..17f97a8d698 100644 --- a/packages/effect/test/Stream/timeouts.test.ts +++ b/packages/effect/test/Stream/timeouts.test.ts @@ -2,16 +2,16 @@ import * as Cause from "effect/Cause" import * as Chunk from "effect/Chunk" import * as Duration from "effect/Duration" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import * as Exit from "effect/Exit" import * as Fiber from "effect/Fiber" import * as Option from "effect/Option" import * as Queue from "effect/Queue" import * as Stream from "effect/Stream" +import { assertLeft, deepStrictEqual } from "effect/test/util" import { chunkCoordination } from "effect/test/utils/coordination" import * as it from "effect/test/utils/extend" import * as TestClock from "effect/TestClock" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("timeout - succeed", () => @@ -21,7 +21,7 @@ describe("Stream", () => { Stream.timeout(Duration.infinity), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1]) + deepStrictEqual(Array.from(result), [1]) })) it.effect("timeout - should end the stream", () => @@ -32,7 +32,7 @@ describe("Stream", () => { Stream.timeout(Duration.zero), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), []) + deepStrictEqual(Array.from(result), []) })) it.effect("timeoutFail - succeed", () => @@ -45,7 +45,7 @@ describe("Stream", () => { Effect.map(() => true), Effect.either ) - assert.deepStrictEqual(result, Either.left(false)) + assertLeft(result, false) })) it.effect("timeoutFail - failures", () => @@ -56,7 +56,7 @@ describe("Stream", () => { Stream.runDrain, Effect.flip ) - assert.deepStrictEqual(result, "original") + deepStrictEqual(result, "original") })) it.effect("timeoutFailCause", () => @@ -70,7 +70,7 @@ describe("Stream", () => { Effect.sandbox, Effect.either ) - assert.deepStrictEqual(result, Either.left(Cause.die(error))) + assertLeft(result, Cause.die(error)) })) it.effect("timeoutTo - succeed", () => @@ -80,7 +80,7 @@ describe("Stream", () => { Stream.timeoutTo(Duration.infinity, Stream.succeed(-1)), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [0, 1, 2, 3, 4]) + deepStrictEqual(Array.from(result), [0, 1, 2, 3, 4]) })) it.effect("timeoutTo - should switch streams", () => @@ -111,7 +111,7 @@ describe("Stream", () => { ) yield* $(coordination.offer) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Array.from(result), [1, 2, 4]) + deepStrictEqual(Array.from(result), [1, 2, 4]) })) it.effect("timeoutTo - should not apply timeout after switch", () => @@ -144,6 +144,6 @@ describe("Stream", () => { Effect.zipRight(Queue.shutdown(queue2)) ) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Array.from(result), [1, 2, 4, 5]) + deepStrictEqual(Array.from(result), [1, 2, 4, 5]) })) }) diff --git a/packages/effect/test/Stream/transducing.test.ts b/packages/effect/test/Stream/transducing.test.ts index 5ce5828660e..b11c392ef81 100644 --- a/packages/effect/test/Stream/transducing.test.ts +++ b/packages/effect/test/Stream/transducing.test.ts @@ -1,11 +1,11 @@ import * as Chunk from "effect/Chunk" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import { constTrue, pipe } from "effect/Function" import * as Sink from "effect/Sink" import * as Stream from "effect/Stream" +import { assertLeft, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Stream", () => { it.effect("transduce - simple example", () => @@ -21,7 +21,7 @@ describe("Stream", () => { Stream.map(Chunk.join("")), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), ["12", "34"]) + deepStrictEqual(Array.from(result), ["12", "34"]) })) it.effect("transduce - no remainder", () => @@ -31,7 +31,7 @@ describe("Stream", () => { Stream.transduce(Sink.fold(100, (n) => n % 2 === 0, (acc, n) => acc + n)), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [101, 105, 104]) + deepStrictEqual(Array.from(result), [101, 105, 104]) })) it.effect("transduce - with a sink that always signals more", () => @@ -41,7 +41,7 @@ describe("Stream", () => { Stream.transduce(Sink.fold(0, constTrue, (acc, n) => acc + n)), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [6]) + deepStrictEqual(Array.from(result), [6]) })) it.effect("transduce - propagates scope error", () => @@ -52,6 +52,6 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left("Woops")) + assertLeft(result, "Woops") })) }) diff --git a/packages/effect/test/Stream/zipping.test.ts b/packages/effect/test/Stream/zipping.test.ts index cba23b9b95d..9cd7d1c3407 100644 --- a/packages/effect/test/Stream/zipping.test.ts +++ b/packages/effect/test/Stream/zipping.test.ts @@ -2,7 +2,6 @@ import * as Cause from "effect/Cause" import * as Chunk from "effect/Chunk" import * as Deferred from "effect/Deferred" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import * as Exit from "effect/Exit" import * as Fiber from "effect/Fiber" import { identity, pipe } from "effect/Function" @@ -12,9 +11,10 @@ import * as Order from "effect/Order" import * as Queue from "effect/Queue" import * as Stream from "effect/Stream" import * as Take from "effect/Take" +import { assertLeft, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as fc from "fast-check" -import { assert, describe } from "vitest" +import { describe } from "vitest" const chunkArb = ( arb: fc.Arbitrary, @@ -75,7 +75,7 @@ describe("Stream", () => { Chunk.sort(OrderByKey) ) const result = await Effect.runPromise(Stream.runCollect(actual)) - assert.deepStrictEqual(Array.from(result), Array.from(expected)) + deepStrictEqual(Array.from(result), Array.from(expected)) })) }) @@ -87,7 +87,7 @@ describe("Stream", () => { ) const right = Stream.fromChunks(Chunk.make("a", "b"), Chunk.of("c")) const result = yield* $(left, Stream.zip(right), Stream.runCollect) - assert.deepStrictEqual(Array.from(result), [[1, "a"], [2, "b"], [3, "c"]]) + deepStrictEqual(Array.from(result), [[1, "a"], [2, "b"], [3, "c"]]) })) it.it("zip - equivalence with Chunk.zip", () => @@ -102,7 +102,7 @@ describe("Stream", () => { Chunk.zip(Chunk.flatten(Chunk.unsafeFromArray(right))) ) const actual = await Effect.runPromise(Stream.runCollect(stream)) - assert.deepStrictEqual(Array.from(actual), Array.from(expected)) + deepStrictEqual(Array.from(actual), Array.from(expected)) }) )) @@ -114,7 +114,7 @@ describe("Stream", () => { Stream.runDrain, Effect.uninterruptible ) - assert.isUndefined(result) + strictEqual(result, undefined) })) it.effect("zipWith - prioritizes failures", () => @@ -125,7 +125,7 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) it.effect("zipWith - dies if one of the streams throws an exception", () => @@ -141,7 +141,7 @@ describe("Stream", () => { Stream.runCollect, Effect.exit ) - assert.deepStrictEqual( + deepStrictEqual( result, Exit.failCause(Cause.die(new Cause.RuntimeException("Ouch"))) ) @@ -172,7 +172,7 @@ describe("Stream", () => { // (b) => [Option.none(), Option.some(b)] as const // ) // ) - // assert.deepStrictEqual(Array.from(actual), Array.from(expected)) + // deepStrictEqual(Array.from(actual), Array.from(expected)) // } // ))) @@ -188,7 +188,7 @@ describe("Stream", () => { Stream.runCollect, Effect.either ) - assert.deepStrictEqual(result, Either.left("Ouch")) + assertLeft(result, "Ouch") })) it.effect("zipWithIndex", () => @@ -198,7 +198,7 @@ describe("Stream", () => { result1: Stream.runCollect(Stream.zipWithIndex(stream)), result2: pipe(Stream.runCollect(stream), Effect.map(Chunk.map((a, i) => [a, i] as const))) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) })) it.effect("zipLatest", () => @@ -229,8 +229,8 @@ describe("Stream", () => { Effect.map(Chunk.unsafeFromArray), Effect.map(Chunk.flatten) ) - assert.deepStrictEqual(Array.from(chunk1), [[0, 0], [0, 1]]) - assert.deepStrictEqual(Array.from(chunk2), [[1, 1], [2, 1]]) + deepStrictEqual(Array.from(chunk1), [[0, 0], [0, 1]]) + deepStrictEqual(Array.from(chunk2), [[1, 1], [2, 1]]) })) it.effect("zipLatestWith - handles empty pulls properly", () => @@ -262,7 +262,7 @@ describe("Stream", () => { yield* $(Deferred.await(latch)) yield* $(Deferred.succeed(deferred, 2)) const result = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(Array.from(result), [1, 1, 1]) + deepStrictEqual(Array.from(result), [1, 1, 1]) })) it.effect("zipLatestWith - handles empty pulls properly (JVM Only - LOL)", () => @@ -281,7 +281,7 @@ describe("Stream", () => { Stream.take(3), Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [1, 1, 1]) + deepStrictEqual(Array.from(result), [1, 1, 1]) })) it.it("zipLatestWith - preserves partial ordering of stream elements", () => { @@ -302,7 +302,7 @@ describe("Stream", () => { ([isSorted, last], curr) => [isSorted && last <= curr, curr] as const ) ) - assert.isTrue(isSorted) + assertTrue(isSorted) })) }) @@ -313,7 +313,7 @@ describe("Stream", () => { Stream.zipWithNext, Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [ + deepStrictEqual(Array.from(result), [ [1, Option.some(2)], [2, Option.some(3)], [3, Option.none()] @@ -327,7 +327,7 @@ describe("Stream", () => { Stream.zipWithNext, Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [ + deepStrictEqual(Array.from(result), [ [1, Option.some(2)], [2, Option.some(3)], [3, Option.none()] @@ -341,7 +341,7 @@ describe("Stream", () => { Stream.zipWithNext, Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), []) + deepStrictEqual(Array.from(result), []) })) it.it("zipWithNext - should output the same values as zipping with the tail plus the last element", () => @@ -361,7 +361,7 @@ describe("Stream", () => { }) ) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) }))) it.effect("zipWithPrevious - should zip with previous element for a single chunk", () => @@ -371,7 +371,7 @@ describe("Stream", () => { Stream.zipWithPrevious, Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [ + deepStrictEqual(Array.from(result), [ [Option.none(), 1], [Option.some(1), 2], [Option.some(2), 3] @@ -385,7 +385,7 @@ describe("Stream", () => { Stream.zipWithPrevious, Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [ + deepStrictEqual(Array.from(result), [ [Option.none(), 1], [Option.some(1), 2], [Option.some(2), 3] @@ -399,7 +399,7 @@ describe("Stream", () => { Stream.zipWithPrevious, Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), []) + deepStrictEqual(Array.from(result), []) })) it.it("zipWithPrevious - should output same values as first element plus zipping with init", () => @@ -418,7 +418,7 @@ describe("Stream", () => { Stream.runCollect ) })) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) }))) it.effect("zipWithPreviousAndNext", () => @@ -428,7 +428,7 @@ describe("Stream", () => { Stream.zipWithPreviousAndNext, Stream.runCollect ) - assert.deepStrictEqual(Array.from(result), [ + deepStrictEqual(Array.from(result), [ [Option.none(), 1, Option.some(2)], [Option.some(1), 2, Option.some(3)], [Option.some(2), 3, Option.none()] @@ -464,7 +464,7 @@ describe("Stream", () => { }), Effect.runPromise ) - assert.deepStrictEqual(Array.from(result1), Array.from(result2)) + deepStrictEqual(Array.from(result1), Array.from(result2)) }))) it.effect("zipLatestAll", () => @@ -478,7 +478,7 @@ describe("Stream", () => { Stream.runCollect, Effect.map(Chunk.toReadonlyArray) ) - assert.deepStrictEqual(result, [ + deepStrictEqual(result, [ [1, "a", true], [2, "a", true], [3, "a", true], diff --git a/packages/effect/test/String.test.ts b/packages/effect/test/String.test.ts index 0d50cd135f8..be34ff0cb39 100644 --- a/packages/effect/test/String.test.ts +++ b/packages/effect/test/String.test.ts @@ -1,76 +1,73 @@ -import { pipe } from "effect/Function" -import * as Option from "effect/Option" -import * as Order from "effect/Order" -import * as S from "effect/String" -import { deepStrictEqual } from "effect/test/util" -import { describe, expect, it } from "vitest" +import { Order, pipe, String as S } from "effect" +import { assertFalse, assertNone, assertSome, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("String", () => { it("isString", () => { - expect(S.isString("a")).toEqual(true) - expect(S.isString(1)).toEqual(false) - expect(S.isString(true)).toEqual(false) + assertTrue(S.isString("a")) + assertFalse(S.isString(1)) + assertFalse(S.isString(true)) }) it("empty", () => { - expect(S.empty).toEqual("") + strictEqual(S.empty, "") }) it("Equivalence", () => { - expect(S.Equivalence("a", "a")).toBe(true) - expect(S.Equivalence("a", "b")).toBe(false) + assertTrue(S.Equivalence("a", "a")) + assertFalse(S.Equivalence("a", "b")) }) it("Order", () => { const lessThan = Order.lessThan(S.Order) const lessThanOrEqualTo = Order.lessThanOrEqualTo(S.Order) - expect(pipe("a", lessThan("b"))).toEqual(true) - expect(pipe("a", lessThan("a"))).toEqual(false) - expect(pipe("a", lessThanOrEqualTo("a"))).toEqual(true) - expect(pipe("b", lessThan("a"))).toEqual(false) - expect(pipe("b", lessThanOrEqualTo("a"))).toEqual(false) + assertTrue(pipe("a", lessThan("b"))) + assertFalse(pipe("a", lessThan("a"))) + assertTrue(pipe("a", lessThanOrEqualTo("a"))) + assertFalse(pipe("b", lessThan("a"))) + assertFalse(pipe("b", lessThanOrEqualTo("a"))) }) it("concat", () => { - expect(pipe("a", S.concat("b"))).toBe("ab") + strictEqual(pipe("a", S.concat("b")), "ab") }) it("isEmpty", () => { - expect(S.isEmpty("")).toBe(true) - expect(S.isEmpty("a")).toBe(false) + assertTrue(S.isEmpty("")) + assertFalse(S.isEmpty("a")) }) it("isNonEmpty", () => { - expect(S.isNonEmpty("")).toBe(false) - expect(S.isNonEmpty("a")).toBe(true) + assertFalse(S.isNonEmpty("")) + assertTrue(S.isNonEmpty("a")) }) it("length", () => { - expect(S.length("")).toBe(0) - expect(S.length("a")).toBe(1) - expect(S.length("aaa")).toBe(3) + strictEqual(S.length(""), 0) + strictEqual(S.length("a"), 1) + strictEqual(S.length("aaa"), 3) }) it("toUpperCase", () => { - expect(S.toUpperCase("a")).toBe("A") + strictEqual(S.toUpperCase("a"), "A") }) it("toLowerCase", () => { - expect(S.toLowerCase("A")).toBe("a") + strictEqual(S.toLowerCase("A"), "a") }) it("capitalize", () => { - expect(S.capitalize("")).toBe("") - expect(S.capitalize("abc")).toBe("Abc") + strictEqual(S.capitalize(""), "") + strictEqual(S.capitalize("abc"), "Abc") }) it("uncapitalize", () => { - expect(S.uncapitalize("")).toBe("") - expect(S.uncapitalize("Abc")).toBe("abc") + strictEqual(S.uncapitalize(""), "") + strictEqual(S.uncapitalize("Abc"), "abc") }) it("replace", () => { - expect(pipe("abc", S.replace("b", "d"))).toBe("adc") + strictEqual(pipe("abc", S.replace("b", "d")), "adc") }) it("split", () => { @@ -79,36 +76,36 @@ describe("String", () => { }) it("trim", () => { - expect(pipe(" a ", S.trim)).toBe("a") + strictEqual(pipe(" a ", S.trim), "a") }) it("trimStart", () => { - expect(pipe(" a ", S.trimStart)).toBe("a ") + strictEqual(pipe(" a ", S.trimStart), "a ") }) it("trimEnd", () => { - expect(pipe(" a ", S.trimEnd)).toBe(" a") + strictEqual(pipe(" a ", S.trimEnd), " a") }) it("includes", () => { - expect(pipe("abc", S.includes("b"))).toBe(true) - expect(pipe("abc", S.includes("d"))).toBe(false) - expect(pipe("abc", S.includes("b", 1))).toBe(true) - expect(pipe("abc", S.includes("a", 1))).toBe(false) + assertTrue(pipe("abc", S.includes("b"))) + assertFalse(pipe("abc", S.includes("d"))) + assertTrue(pipe("abc", S.includes("b", 1))) + assertFalse(pipe("abc", S.includes("a", 1))) }) it("startsWith", () => { - expect(pipe("abc", S.startsWith("a"))).toBe(true) - expect(pipe("bc", S.startsWith("a"))).toBe(false) - expect(pipe("abc", S.startsWith("b", 1))).toBe(true) - expect(pipe("bc", S.startsWith("a", 1))).toBe(false) + assertTrue(pipe("abc", S.startsWith("a"))) + assertFalse(pipe("bc", S.startsWith("a"))) + assertTrue(pipe("abc", S.startsWith("b", 1))) + assertFalse(pipe("bc", S.startsWith("a", 1))) }) it("endsWith", () => { - expect(pipe("abc", S.endsWith("c"))).toBe(true) - expect(pipe("ab", S.endsWith("c"))).toBe(false) - expect(pipe("abc", S.endsWith("b", 2))).toBe(true) - expect(pipe("abc", S.endsWith("c", 2))).toBe(false) + assertTrue(pipe("abc", S.endsWith("c"))) + assertFalse(pipe("ab", S.endsWith("c"))) + assertTrue(pipe("abc", S.endsWith("b", 2))) + assertFalse(pipe("abc", S.endsWith("c", 2))) }) it("slice", () => { @@ -116,135 +113,135 @@ describe("String", () => { }) it("charCodeAt", () => { - expect(pipe("abc", S.charCodeAt(1))).toStrictEqual(Option.some(98)) - expect(pipe("abc", S.charCodeAt(4))).toStrictEqual(Option.none()) + assertSome(pipe("abc", S.charCodeAt(1)), 98) + assertNone(pipe("abc", S.charCodeAt(4))) }) it("substring", () => { - expect(pipe("abcd", S.substring(1))).toBe("bcd") - expect(pipe("abcd", S.substring(1, 3))).toBe("bc") + strictEqual(pipe("abcd", S.substring(1)), "bcd") + strictEqual(pipe("abcd", S.substring(1, 3)), "bc") }) it("at", () => { - expect(pipe("abc", S.at(1))).toStrictEqual(Option.some("b")) - expect(pipe("abc", S.at(4))).toStrictEqual(Option.none()) + assertSome(pipe("abc", S.at(1)), "b") + assertNone(pipe("abc", S.at(4))) }) it("charAt", () => { - expect(pipe("abc", S.charAt(1))).toStrictEqual(Option.some("b")) - expect(pipe("abc", S.charAt(4))).toStrictEqual(Option.none()) + assertSome(pipe("abc", S.charAt(1)), "b") + assertNone(pipe("abc", S.charAt(4))) }) it("codePointAt", () => { - expect(pipe("abc", S.codePointAt(1))).toStrictEqual(Option.some(98)) - expect(pipe("abc", S.codePointAt(4))).toStrictEqual(Option.none()) + assertSome(pipe("abc", S.codePointAt(1)), 98) + assertNone(pipe("abc", S.codePointAt(4))) }) it("indexOf", () => { - expect(pipe("abbbc", S.indexOf("b"))).toStrictEqual(Option.some(1)) - expect(pipe("abbbc", S.indexOf("d"))).toStrictEqual(Option.none()) + assertSome(pipe("abbbc", S.indexOf("b")), 1) + assertNone(pipe("abbbc", S.indexOf("d"))) }) it("lastIndexOf", () => { - expect(pipe("abbbc", S.lastIndexOf("b"))).toStrictEqual(Option.some(3)) - expect(pipe("abbbc", S.lastIndexOf("d"))).toStrictEqual(Option.none()) + assertSome(pipe("abbbc", S.lastIndexOf("b")), 3) + assertNone(pipe("abbbc", S.lastIndexOf("d"))) }) it("localeCompare", () => { - expect(pipe("a", S.localeCompare("b"))).toBe(-1) - expect(pipe("b", S.localeCompare("a"))).toBe(1) - expect(pipe("a", S.localeCompare("a"))).toBe(0) + strictEqual(pipe("a", S.localeCompare("b")), -1) + strictEqual(pipe("b", S.localeCompare("a")), 1) + strictEqual(pipe("a", S.localeCompare("a")), 0) }) it("match", () => { - expect(pipe("a", S.match(/a/))).toStrictEqual(Option.some(expect.arrayContaining(["a"]))) - expect(pipe("a", S.match(/b/))).toStrictEqual(Option.none()) + assertSome(pipe("a", S.match(/a/)), "a".match(/a/)) + assertNone(pipe("a", S.match(/b/))) }) it("matchAll", () => { - expect(Array.from(pipe("apple, banana", S.matchAll(/a[pn]/g)))).toHaveLength(3) - expect(Array.from(pipe("apple, banana", S.matchAll(/c/g)))).toHaveLength(0) + strictEqual(Array.from(pipe("apple, banana", S.matchAll(/a[pn]/g))).length, 3) + strictEqual(Array.from(pipe("apple, banana", S.matchAll(/c/g))).length, 0) }) it("normalize", () => { const str = "\u1E9B\u0323" - expect(pipe(str, S.normalize())).toBe("\u1E9B\u0323") - expect(pipe(str, S.normalize("NFC"))).toBe("\u1E9B\u0323") - expect(pipe(str, S.normalize("NFD"))).toBe("\u017F\u0323\u0307") - expect(pipe(str, S.normalize("NFKC"))).toBe("\u1E69") - expect(pipe(str, S.normalize("NFKD"))).toBe("\u0073\u0323\u0307") + strictEqual(pipe(str, S.normalize()), "\u1E9B\u0323") + strictEqual(pipe(str, S.normalize("NFC")), "\u1E9B\u0323") + strictEqual(pipe(str, S.normalize("NFD")), "\u017F\u0323\u0307") + strictEqual(pipe(str, S.normalize("NFKC")), "\u1E69") + strictEqual(pipe(str, S.normalize("NFKD")), "\u0073\u0323\u0307") }) it("padEnd", () => { - expect(pipe("a", S.padEnd(5))).toBe("a ") - expect(pipe("a", S.padEnd(5, "_"))).toBe("a____") + strictEqual(pipe("a", S.padEnd(5)), "a ") + strictEqual(pipe("a", S.padEnd(5, "_")), "a____") }) it("padStart", () => { - expect(pipe("a", S.padStart(5))).toBe(" a") - expect(pipe("a", S.padStart(5, "_"))).toBe("____a") + strictEqual(pipe("a", S.padStart(5)), " a") + strictEqual(pipe("a", S.padStart(5, "_")), "____a") }) it("repeat", () => { - expect(pipe("a", S.repeat(3))).toBe("aaa") + strictEqual(pipe("a", S.repeat(3)), "aaa") }) it("replaceAll", () => { - expect(pipe("ababb", S.replaceAll("b", "c"))).toBe("acacc") - expect(pipe("ababb", S.replaceAll(/ba/g, "cc"))).toBe("accbb") + strictEqual(pipe("ababb", S.replaceAll("b", "c")), "acacc") + strictEqual(pipe("ababb", S.replaceAll(/ba/g, "cc")), "accbb") }) it("search", () => { - expect(pipe("ababb", S.search("b"))).toStrictEqual(Option.some(1)) - expect(pipe("ababb", S.search(/abb/))).toStrictEqual(Option.some(2)) - expect(pipe("ababb", S.search(/c/))).toStrictEqual(Option.none()) + assertSome(pipe("ababb", S.search("b")), 1) + assertSome(pipe("ababb", S.search(/abb/)), 2) + assertNone(pipe("ababb", S.search(/c/))) }) it("toLocaleLowerCase", () => { const locales = ["tr", "TR", "tr-TR", "tr-u-co-search", "tr-x-turkish"] - expect(pipe("\u0130", S.toLocaleLowerCase(locales))).toBe("i") + strictEqual(pipe("\u0130", S.toLocaleLowerCase(locales)), "i") }) it("toLocaleUpperCase", () => { const locales = ["lt", "LT", "lt-LT", "lt-u-co-phonebk", "lt-x-lietuva"] - expect(pipe("i\u0307", S.toLocaleUpperCase(locales))).toBe("I") + strictEqual(pipe("i\u0307", S.toLocaleUpperCase(locales)), "I") }) describe("takeLeft", () => { it("should take the specified number of characters from the left side of a string", () => { - expect(S.takeLeft("Hello, World!", 7)).toBe("Hello, ") + strictEqual(S.takeLeft("Hello, World!", 7), "Hello, ") }) it("should return the string for `n` larger than the string length", () => { const string = "Hello, World!" - expect(S.takeLeft(string, 100)).toBe(string) + strictEqual(S.takeLeft(string, 100), string) }) it("should return the empty string for a negative `n`", () => { - expect(S.takeLeft("Hello, World!", -1)).toBe("") + strictEqual(S.takeLeft("Hello, World!", -1), "") }) it("should round down if `n` is a float", () => { - expect(S.takeLeft("Hello, World!", 5.5)).toBe("Hello") + strictEqual(S.takeLeft("Hello, World!", 5.5), "Hello") }) }) describe("takeRight", () => { it("should take the specified number of characters from the right side of a string", () => { - expect(S.takeRight("Hello, World!", 7)).toBe(" World!") + strictEqual(S.takeRight("Hello, World!", 7), " World!") }) it("should return the string for `n` larger than the string length", () => { const string = "Hello, World!" - expect(S.takeRight(string, 100)).toBe(string) + strictEqual(S.takeRight(string, 100), string) }) it("should return the empty string for a negative `n`", () => { - expect(S.takeRight("Hello, World!", -1)).toBe("") + strictEqual(S.takeRight("Hello, World!", -1), "") }) it("should round down if `n` is a float", () => { - expect(S.takeRight("Hello, World!", 6.5)).toBe("World!") + strictEqual(S.takeRight("Hello, World!", 6.5), "World!") }) }) @@ -255,13 +252,13 @@ describe("String", () => { |World! |` const result = S.stripMargin(string) - expect(result).toBe("\nHello,\nWorld!\n") + strictEqual(result, "\nHello,\nWorld!\n") }) it("should strip a leading prefix from each line using a margin character", () => { const string = "\n$\n $Hello,\r\n $World!\n $" const result = S.stripMarginWith(string, "$") - expect(result).toBe("\n\nHello,\r\nWorld!\n") + strictEqual(result, "\n\nHello,\r\nWorld!\n") }) }) diff --git a/packages/effect/test/Struct.test.ts b/packages/effect/test/Struct.test.ts index b1653e7a351..a606d450381 100644 --- a/packages/effect/test/Struct.test.ts +++ b/packages/effect/test/Struct.test.ts @@ -1,35 +1,29 @@ -import { pipe } from "effect/Function" -import * as Number from "effect/Number" -import * as String from "effect/String" -import * as Struct from "effect/Struct" -import { assert, describe, expect, it } from "vitest" +import { Number, pipe, String, Struct } from "effect" +import { deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Struct", () => { - it("exports", () => { - expect(Struct.getOrder).exist // alias of `Order.ts#struct` - }) - it("pick", () => { - expect(pipe({ a: "a", b: 1, c: true }, Struct.pick("a", "b"))).toEqual({ a: "a", b: 1 }) - expect(Struct.pick({ a: "a", b: 1, c: true }, "a", "b")).toEqual({ a: "a", b: 1 }) + deepStrictEqual(pipe({ a: "a", b: 1, c: true }, Struct.pick("a", "b")), { a: "a", b: 1 }) + deepStrictEqual(Struct.pick({ a: "a", b: 1, c: true }, "a", "b"), { a: "a", b: 1 }) const record1: Record = {} - expect(pipe(record1, Struct.pick("a", "b"))).toStrictEqual({}) + deepStrictEqual(pipe(record1, Struct.pick("a", "b")), {}) const record2: Record = { b: 1 } - expect(pipe(record2, Struct.pick("a", "b"))).toStrictEqual({ b: 1 }) + deepStrictEqual(pipe(record2, Struct.pick("a", "b")), { b: 1 }) const optionalStringStruct1: { a?: string b: number c: boolean } = { b: 1, c: true } - expect(pipe(optionalStringStruct1, Struct.pick("a", "b"))).toStrictEqual({ b: 1 }) + deepStrictEqual(pipe(optionalStringStruct1, Struct.pick("a", "b")), { b: 1 }) const optionalStringStruct2: { a?: string b: number c: boolean } = { a: "a", b: 1, c: true } - expect(pipe(optionalStringStruct2, Struct.pick("a", "b"))).toStrictEqual({ a: "a", b: 1 }) + deepStrictEqual(pipe(optionalStringStruct2, Struct.pick("a", "b")), { a: "a", b: 1 }) const a = Symbol.for("a") const optionalSymbolStruct1: { @@ -37,36 +31,36 @@ describe("Struct", () => { b: number c: boolean } = { b: 1, c: true } - expect(pipe(optionalSymbolStruct1, Struct.pick(a, "b"))).toStrictEqual({ b: 1 }) + deepStrictEqual(pipe(optionalSymbolStruct1, Struct.pick(a, "b")), { b: 1 }) const optionalSymbolStruct2: { [a]?: string b: number c: boolean } = { [a]: "a", b: 1, c: true } - expect(pipe(optionalSymbolStruct2, Struct.pick(a, "b"))).toStrictEqual({ [a]: "a", b: 1 }) + deepStrictEqual(pipe(optionalSymbolStruct2, Struct.pick(a, "b")), { [a]: "a", b: 1 }) }) it("omit", () => { - expect(pipe({ a: "a", b: 1, c: true }, Struct.omit("c"))).toEqual({ a: "a", b: 1 }) - expect(pipe(Struct.omit({ a: "a", b: 1, c: true }, "c"))).toEqual({ a: "a", b: 1 }) + deepStrictEqual(pipe({ a: "a", b: 1, c: true }, Struct.omit("c")), { a: "a", b: 1 }) + deepStrictEqual(pipe(Struct.omit({ a: "a", b: 1, c: true }, "c")), { a: "a", b: 1 }) const record1: Record = {} - expect(pipe(record1, Struct.omit("a", "c"))).toStrictEqual({}) + deepStrictEqual(pipe(record1, Struct.omit("a", "c")), {}) const record2: Record = { b: 1 } - expect(pipe(record2, Struct.omit("a", "c"))).toStrictEqual({ b: 1 }) + deepStrictEqual(pipe(record2, Struct.omit("a", "c")), { b: 1 }) const optionalStringStruct1: { a?: string b: number c: boolean } = { b: 1, c: true } - expect(pipe(optionalStringStruct1, Struct.omit("c"))).toStrictEqual({ b: 1 }) + deepStrictEqual(pipe(optionalStringStruct1, Struct.omit("c")), { b: 1 }) const optionalStringStruct2: { a?: string b: number c: boolean } = { a: "a", b: 1, c: true } - expect(pipe(optionalStringStruct2, Struct.omit("c"))).toStrictEqual({ a: "a", b: 1 }) + deepStrictEqual(pipe(optionalStringStruct2, Struct.omit("c")), { a: "a", b: 1 }) const a = Symbol.for("a") const optionalSymbolStruct1: { @@ -74,13 +68,13 @@ describe("Struct", () => { b: number c: boolean } = { b: 1, c: true } - expect(pipe(optionalSymbolStruct1, Struct.omit("c"))).toStrictEqual({ b: 1 }) + deepStrictEqual(pipe(optionalSymbolStruct1, Struct.omit("c")), { b: 1 }) const optionalSymbolStruct2: { [a]?: string b: number c: boolean } = { [a]: "a", b: 1, c: true } - expect(pipe(optionalSymbolStruct2, Struct.omit("c"))).toStrictEqual({ [a]: "a", b: 1 }) + deepStrictEqual(pipe(optionalSymbolStruct2, Struct.omit("c")), { [a]: "a", b: 1 }) }) it("evolve", () => { @@ -93,17 +87,17 @@ describe("Struct", () => { }) ) - expect(res1).toEqual({ a: 1, b: true, c: false, d: "extra" }) + deepStrictEqual(res1, { a: 1, b: true, c: false, d: "extra" }) const x: Record<"b", number> = Object.create({ a: 1 }) x.b = 1 const res2 = pipe(x, Struct.evolve({ b: (b) => b > 0 })) - expect(res2).toEqual({ b: true }) + deepStrictEqual(res2, { b: true }) // dual const res3 = Struct.evolve({ a: 1 }, { a: (x) => x > 0 }) - expect(res3).toEqual({ a: true }) + deepStrictEqual(res3, { a: true }) }) it("struct", () => { @@ -112,18 +106,18 @@ describe("Struct", () => { age: Number.Equivalence }) - assert.deepStrictEqual( + deepStrictEqual( PersonEquivalence({ name: "John", age: 25 }, { name: "John", age: 25 }), true ) - assert.deepStrictEqual( + deepStrictEqual( PersonEquivalence({ name: "John", age: 25 }, { name: "John", age: 40 }), false ) }) it("get", () => { - expect(pipe({ a: 1 }, Struct.get("a"))).toStrictEqual(1) - expect(pipe({}, Struct.get("a"))).toStrictEqual(undefined) + strictEqual(pipe({ a: 1 }, Struct.get("a")), 1) + strictEqual(pipe({}, Struct.get("a")), undefined) }) }) diff --git a/packages/effect/test/SubscriptionRef.test.ts b/packages/effect/test/SubscriptionRef.test.ts index bfbfe57e80d..e4101d02f53 100644 --- a/packages/effect/test/SubscriptionRef.test.ts +++ b/packages/effect/test/SubscriptionRef.test.ts @@ -1,16 +1,7 @@ -import * as Chunk from "effect/Chunk" -import * as Deferred from "effect/Deferred" -import * as Effect from "effect/Effect" -import * as Equal from "effect/Equal" -import * as Exit from "effect/Exit" -import * as Fiber from "effect/Fiber" -import { pipe } from "effect/Function" -import * as Number from "effect/Number" -import * as Random from "effect/Random" -import * as Stream from "effect/Stream" -import * as SubscriptionRef from "effect/SubscriptionRef" +import { Chunk, Deferred, Effect, Equal, Exit, Fiber, Number, pipe, Random, Stream, SubscriptionRef } from "effect" +import { assertTrue, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("SubscriptionRef", () => { it.effect("multiple subscribers can receive changes", () => @@ -38,8 +29,8 @@ describe("SubscriptionRef", () => { yield* $(SubscriptionRef.update(subscriptionRef, (n) => n + 1)) const result1 = yield* $(Fiber.join(subscriber1)) const result2 = yield* $(Fiber.join(subscriber2)) - assert.deepStrictEqual(Array.from(result1), [0, 1, 2]) - assert.deepStrictEqual(Array.from(result2), [1, 2]) + deepStrictEqual(Array.from(result1), [0, 1, 2]) + deepStrictEqual(Array.from(result2), [1, 2]) })) it.effect("subscriptions are interruptible", () => @@ -67,8 +58,8 @@ describe("SubscriptionRef", () => { yield* $(SubscriptionRef.update(subscriptionRef, (n) => n + 1)) const result1 = yield* $(Fiber.interrupt(subscriber1)) const result2 = yield* $(Fiber.join(subscriber2)) - assert.isTrue(Exit.isInterrupted(result1)) - assert.deepStrictEqual(Array.from(result2), [1, 2]) + assertTrue(Exit.isInterrupted(result1)) + deepStrictEqual(Array.from(result2), [1, 2]) })) it.effect("concurrent subscribes and unsubscribes are handled correctly", () => @@ -101,6 +92,6 @@ describe("SubscriptionRef", () => { ) yield* $(Fiber.interrupt(fiber)) const isSorted = Chunk.every(result, (chunk) => Equal.equals(chunk, Chunk.sort(chunk, Number.Order))) - assert.isTrue(isSorted) + assertTrue(isSorted) })) }) diff --git a/packages/effect/test/Symbol.test.ts b/packages/effect/test/Symbol.test.ts index 451835de459..5f6306888fe 100644 --- a/packages/effect/test/Symbol.test.ts +++ b/packages/effect/test/Symbol.test.ts @@ -1,18 +1,19 @@ import * as S from "effect/Symbol" -import { describe, expect, it } from "vitest" +import { assertFalse, assertTrue } from "effect/test/util" +import { describe, it } from "vitest" describe("Symbol", () => { it("isSymbol", () => { - expect(S.isSymbol(Symbol.for("effect/test/a"))).toEqual(true) - expect(S.isSymbol(1n)).toEqual(false) - expect(S.isSymbol(1)).toEqual(false) - expect(S.isSymbol("a")).toEqual(false) - expect(S.isSymbol(true)).toEqual(false) + assertTrue(S.isSymbol(Symbol.for("effect/test/a"))) + assertFalse(S.isSymbol(1n)) + assertFalse(S.isSymbol(1)) + assertFalse(S.isSymbol("a")) + assertFalse(S.isSymbol(true)) }) it("Equivalence", () => { const eq = S.Equivalence - expect(eq(Symbol.for("effect/test/a"), Symbol.for("effect/test/a"))).toBe(true) - expect(eq(Symbol.for("effect/test/a"), Symbol.for("effect/test/b"))).toBe(false) + assertTrue(eq(Symbol.for("effect/test/a"), Symbol.for("effect/test/a"))) + assertFalse(eq(Symbol.for("effect/test/a"), Symbol.for("effect/test/b"))) }) }) diff --git a/packages/effect/test/Synchronized.test.ts b/packages/effect/test/SynchronizedRef.test.ts similarity index 53% rename from packages/effect/test/Synchronized.test.ts rename to packages/effect/test/SynchronizedRef.test.ts index 80f98d743c1..504058dbd00 100644 --- a/packages/effect/test/Synchronized.test.ts +++ b/packages/effect/test/SynchronizedRef.test.ts @@ -1,11 +1,7 @@ -import * as Deferred from "effect/Deferred" -import * as Effect from "effect/Effect" -import * as Exit from "effect/Exit" -import * as Fiber from "effect/Fiber" -import * as Option from "effect/Option" -import * as Synchronized from "effect/SynchronizedRef" +import { Deferred, Effect, Exit, Fiber, Option, SynchronizedRef } from "effect" +import { deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import { assert, describe } from "vitest" +import { describe } from "vitest" const current = "value" const update = "new value" @@ -36,75 +32,75 @@ const isClosed = (self: State): boolean => self._tag === "Closed" describe("SynchronizedRef", () => { it.effect("get", () => Effect.gen(function*($) { - const result = yield* $(Synchronized.make(current), Effect.flatMap(Synchronized.get)) - assert.strictEqual(result, current) + const result = yield* $(SynchronizedRef.make(current), Effect.flatMap(SynchronizedRef.get)) + strictEqual(result, current) })) it.effect("getAndUpdateEffect - happy path", () => Effect.gen(function*() { - const ref = yield* Synchronized.make(current) - const result1 = yield* Synchronized.getAndUpdateEffect(ref, () => Effect.succeed(update)) + const ref = yield* SynchronizedRef.make(current) + const result1 = yield* SynchronizedRef.getAndUpdateEffect(ref, () => Effect.succeed(update)) const result2 = yield* ref - assert.strictEqual(result1, current) - assert.strictEqual(result2, update) + strictEqual(result1, current) + strictEqual(result2, update) })) it.effect("getAndUpdateEffect - with failure", () => Effect.gen(function*($) { - const ref = yield* $(Synchronized.make(current)) - const result = yield* $(Synchronized.getAndUpdateEffect(ref, (_) => Effect.fail(failure)), Effect.exit) - assert.deepStrictEqual(result, Exit.fail(failure)) + const ref = yield* $(SynchronizedRef.make(current)) + const result = yield* $(SynchronizedRef.getAndUpdateEffect(ref, (_) => Effect.fail(failure)), Effect.exit) + deepStrictEqual(result, Exit.fail(failure)) })) it.effect("getAndUpdateSomeEffect - happy path", () => Effect.gen(function*($) { - const ref = yield* $(Synchronized.make(Active)) - const result1 = yield* $(Synchronized.getAndUpdateSomeEffect(ref, (state) => + const ref = yield* $(SynchronizedRef.make(Active)) + const result1 = yield* $(SynchronizedRef.getAndUpdateSomeEffect(ref, (state) => isClosed(state) ? Option.some(Effect.succeed(Changed)) : Option.none())) - const result2 = yield* $(Synchronized.get(ref)) - assert.deepStrictEqual(result1, Active) - assert.deepStrictEqual(result2, Active) + const result2 = yield* $(SynchronizedRef.get(ref)) + deepStrictEqual(result1, Active) + deepStrictEqual(result2, Active) })) it.effect("getAndUpdateSomeEffect - twice", () => Effect.gen(function*($) { - const ref = yield* $(Synchronized.make(Active)) - const result1 = yield* $(Synchronized.getAndUpdateSomeEffect(ref, (state) => + const ref = yield* $(SynchronizedRef.make(Active)) + const result1 = yield* $(SynchronizedRef.getAndUpdateSomeEffect(ref, (state) => isActive(state) ? Option.some(Effect.succeed(Changed)) : Option.none())) - const result2 = yield* $(Synchronized.getAndUpdateSomeEffect(ref, (state) => + const result2 = yield* $(SynchronizedRef.getAndUpdateSomeEffect(ref, (state) => isClosed(state) ? Option.some(Effect.succeed(Active)) : isChanged(state) ? Option.some(Effect.succeed(Closed)) : Option.none())) const result3 = yield* ref - assert.deepStrictEqual(result1, Active) - assert.deepStrictEqual(result2, Changed) - assert.deepStrictEqual(result3, Closed) + deepStrictEqual(result1, Active) + deepStrictEqual(result2, Changed) + deepStrictEqual(result3, Closed) })) it.effect("getAndUpdateSomeEffect - with failure", () => Effect.gen(function*($) { - const ref = yield* $(Synchronized.make(Active)) + const ref = yield* $(SynchronizedRef.make(Active)) const result = yield* $( - Synchronized.getAndUpdateSomeEffect(ref, (state) => + SynchronizedRef.getAndUpdateSomeEffect(ref, (state) => isActive(state) ? Option.some(Effect.fail(failure)) : Option.none()), Effect.exit ) - assert.deepStrictEqual(result, Exit.fail(failure)) + deepStrictEqual(result, Exit.fail(failure)) })) it.effect("getAndUpdateSomeEffect - interrupt parent fiber and update", () => Effect.gen(function*($) { - const deferred = yield* $(Deferred.make>()) + const deferred = yield* $(Deferred.make>()) const latch = yield* $(Deferred.make()) - const makeAndWait = Deferred.complete(deferred, Synchronized.make(Active)).pipe( + const makeAndWait = Deferred.complete(deferred, SynchronizedRef.make(Active)).pipe( Effect.zipRight(Deferred.await(latch)) ) const fiber = yield* $(Effect.fork(makeAndWait)) const ref = yield* $(Deferred.await(deferred)) yield* $(Fiber.interrupt(fiber)) - const result = yield* $(Synchronized.updateAndGetEffect(ref, (_) => Effect.succeed(Closed))) - assert.deepStrictEqual(result, Closed) + const result = yield* $(SynchronizedRef.updateAndGetEffect(ref, (_) => Effect.succeed(Closed))) + deepStrictEqual(result, Closed) })) }) diff --git a/packages/effect/test/TArray.test.ts b/packages/effect/test/TArray.test.ts index 9bcae4de285..cfe8efe5e1f 100644 --- a/packages/effect/test/TArray.test.ts +++ b/packages/effect/test/TArray.test.ts @@ -1,17 +1,16 @@ -import * as Cause from "effect/Cause" -import * as Chunk from "effect/Chunk" -import * as Effect from "effect/Effect" -import * as Either from "effect/Either" -import * as Exit from "effect/Exit" -import * as Fiber from "effect/Fiber" -import { constFalse, constTrue, identity, pipe } from "effect/Function" -import * as Number from "effect/Number" -import * as Option from "effect/Option" -import * as STM from "effect/STM" -import * as TArray from "effect/TArray" +import { Cause, Chunk, Effect, Exit, Fiber, identity, Number, Option, pipe, STM, TArray, TRef } from "effect" +import { constFalse, constTrue } from "effect/Function" +import { + assertFalse, + assertLeft, + assertNone, + assertSome, + assertTrue, + deepStrictEqual, + strictEqual +} from "effect/test/util" import * as it from "effect/test/utils/extend" -import * as TRef from "effect/TRef" -import { assert, describe } from "vitest" +import { describe } from "vitest" const largePrime = 223 @@ -43,14 +42,14 @@ describe("TArray", () => { Option.none() ) )) - assert.deepStrictEqual(result, Option.some("4")) + assertSome(result, "4") })) it.effect("collectFirst - succeeds for empty array", () => Effect.gen(function*($) { const array = yield* $(makeTArray>(0, Option.none())) const result = yield* $(pipe(array, TArray.collectFirst(identity))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("collectFirst - fails to find absent", () => @@ -65,7 +64,7 @@ describe("TArray", () => { Option.none() ) )) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("collectFirst - is atomic", () => @@ -86,7 +85,7 @@ describe("TArray", () => { STM.forEach((n) => pipe(array, TArray.update(n, () => Option.some(1)))) )) const result = yield* $(Fiber.join(fiber)) - assert.isTrue( + assertTrue( (Option.isSome(result) && result.value === String(largePrime)) || Option.isNone(result) ) @@ -104,7 +103,7 @@ describe("TArray", () => { Option.none() ) )) - assert.deepStrictEqual(result, Option.some("4")) + assertSome(result, "4") })) it.effect("collectFirstSTM - succeeds for empty array", () => @@ -118,7 +117,7 @@ describe("TArray", () => { Option.none() ) )) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("collectFirstSTM - fails to find absent", () => @@ -133,7 +132,7 @@ describe("TArray", () => { Option.none() ) )) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("collectFirstSTM - is atomic", () => @@ -154,7 +153,7 @@ describe("TArray", () => { STM.forEach((n) => pipe(array, TArray.update(n, () => Option.some(1)))) )) const result = yield* $(Fiber.join(fiber)) - assert.isTrue( + assertTrue( (Option.isSome(result) && result.value === String(largePrime)) || Option.isNone(result) ) @@ -173,7 +172,7 @@ describe("TArray", () => { ), STM.flip )) - assert.strictEqual(result, "boom") + strictEqual(result, "boom") })) it.effect("collectFirstSTM - succeeds on errors after result found", () => @@ -192,7 +191,7 @@ describe("TArray", () => { Option.none() ) )) - assert.deepStrictEqual(result, Option.some("4")) + assertSome(result, "4") })) it.effect("contains - true when in the array", () => @@ -200,7 +199,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.contains(3))) - assert.isTrue(result) + assertTrue(result) })) it.effect("contains - false when not in the array", () => @@ -208,14 +207,14 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.contains(n + 1))) - assert.isFalse(result) + assertFalse(result) })) it.effect("contains - false for empty array", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(pipe(array, TArray.contains(0))) - assert.isFalse(result) + assertFalse(result) })) it.effect("count - computes correct sum", () => @@ -223,7 +222,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.count((n) => n % 2 === 0))) - assert.strictEqual(result, 5) + strictEqual(result, 5) })) it.effect("count - zero when the predicate does not match", () => @@ -231,14 +230,14 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.count((i) => i > n))) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("count - zero for empty array", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(pipe(array, TArray.count(constTrue))) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("countSTM - computes correct sum", () => @@ -246,7 +245,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.countSTM((n) => STM.succeed(n % 2 === 0)))) - assert.strictEqual(result, 5) + strictEqual(result, 5) })) it.effect("countSTM - zero when the predicate does not match", () => @@ -254,14 +253,14 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.countSTM((i) => STM.succeed(i > n)))) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("countSTM - zero for empty array", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(pipe(array, TArray.countSTM(() => STM.succeed(true)))) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("every - detects satisfaction", () => @@ -269,7 +268,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.every((i) => i < n + 1))) - assert.isTrue(result) + assertTrue(result) })) it.effect("every - detects lack of satisfaction", () => @@ -277,14 +276,14 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.every((i) => i < n - 1))) - assert.isFalse(result) + assertFalse(result) })) it.effect("every - detects lack of satisfaction", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(pipe(array, TArray.every(constFalse))) - assert.isTrue(result) + assertTrue(result) })) it.effect("everySTM - detects satisfaction", () => @@ -292,7 +291,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.everySTM((i) => STM.succeed(i < n + 1)))) - assert.isTrue(result) + assertTrue(result) })) it.effect("everySTM - detects lack of satisfaction", () => @@ -300,14 +299,14 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.everySTM((i) => STM.succeed(i < n - 1)))) - assert.isFalse(result) + assertFalse(result) })) it.effect("everySTM - detects lack of satisfaction", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(pipe(array, TArray.everySTM(() => STM.succeed(false)))) - assert.isTrue(result) + assertTrue(result) })) it.effect("everySTM - fails for errors before counterexample", () => @@ -319,7 +318,7 @@ describe("TArray", () => { TArray.everySTM((n) => n === 4 ? STM.fail("boom") : STM.succeed(n !== 5)), STM.flip )) - assert.strictEqual(result, "boom") + strictEqual(result, "boom") })) it.effect("everySTM - fails for errors after counterexample", () => @@ -331,7 +330,7 @@ describe("TArray", () => { TArray.everySTM((n) => n === 6 ? STM.fail("boom") : STM.succeed(n === 5)), STM.flip )) - assert.strictEqual(result, "boom") + strictEqual(result, "boom") })) it.effect("get - happy path", () => @@ -340,7 +339,7 @@ describe("TArray", () => { makeTArray(1, 42), STM.flatMap(TArray.get(0)) )) - assert.strictEqual(result, 42) + strictEqual(result, 42) })) it.effect("findFirst - is correct", () => @@ -348,14 +347,14 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findFirst((n) => n % 5 === 0))) - assert.deepStrictEqual(result, Option.some(5)) + assertSome(result, 5) })) it.effect("findFirst - succeeds for empty array", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(pipe(array, TArray.findFirst(constTrue))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findFirst - fails to find absent", () => @@ -363,7 +362,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findFirst((i) => i > n))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findFirst - is atomic", () => @@ -380,7 +379,7 @@ describe("TArray", () => { STM.forEach((n) => pipe(array, TArray.update(n, () => 1))) )) const result = yield* $(Fiber.join(fiber)) - assert.isTrue( + assertTrue( (Option.isSome(result) && result.value === largePrime) || Option.isNone(result) ) @@ -390,49 +389,49 @@ describe("TArray", () => { Effect.gen(function*($) { const array = yield* $(makeRepeats(3, 3)) const result = yield* $(pipe(array, TArray.findFirstIndex(2))) - assert.deepStrictEqual(result, Option.some(1)) + assertSome(result, 1) })) it.effect("findFirstIndex - none for empty array", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(pipe(array, TArray.findFirstIndex(1))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findFirstIndex - none if absent", () => Effect.gen(function*($) { const array = yield* $(makeRepeats(3, 3)) const result = yield* $(pipe(array, TArray.findFirstIndex(4))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findFirstIndexFrom - correct index if in array, with offset", () => Effect.gen(function*($) { const array = yield* $(makeRepeats(3, 3)) const result = yield* $(pipe(array, TArray.findFirstIndexFrom(2, 2))) - assert.deepStrictEqual(result, Option.some(4)) + assertSome(result, 4) })) it.effect("findFirstIndexFrom - none if absent after offset", () => Effect.gen(function*($) { const array = yield* $(makeRepeats(3, 3)) const result = yield* $(pipe(array, TArray.findFirstIndexFrom(1, 7))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findFirstIndexFrom - none for a negative offset", () => Effect.gen(function*($) { const array = yield* $(makeRepeats(3, 3)) const result = yield* $(pipe(array, TArray.findFirstIndexFrom(1, -1))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findFirstIndexFrom - none for an offset that is too large", () => Effect.gen(function*($) { const array = yield* $(makeRepeats(3, 3)) const result = yield* $(pipe(array, TArray.findFirstIndexFrom(1, 9))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findFirstIndexWhere - determines the correct index", () => @@ -440,14 +439,14 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findFirstIndexWhere((n) => n % 5 === 0))) - assert.deepStrictEqual(result, Option.some(4)) + assertSome(result, 4) })) it.effect("findFirstIndexWhere - none for empty array", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(pipe(array, TArray.findFirstIndexWhere(constTrue))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findFirstIndexWhere - none for empty array", () => @@ -455,7 +454,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findFirstIndexWhere((i) => i > n))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findFirstIndexWhere - is atomic", () => @@ -472,7 +471,7 @@ describe("TArray", () => { STM.forEach((n) => pipe(array, TArray.update(n, () => 1))) )) const result = yield* $(Fiber.join(fiber)) - assert.isTrue( + assertTrue( (Option.isSome(result) && result.value === largePrime - 1) || Option.isNone(result) ) @@ -483,7 +482,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findFirstIndexWhereFrom((n) => n % 2 === 0, 5))) - assert.deepStrictEqual(result, Option.some(5)) + assertSome(result, 5) })) it.effect("findFirstIndexWhereFrom - none if absent after offset", () => @@ -491,7 +490,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findFirstIndexWhereFrom((n) => n % 7 === 0, 7))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findFirstIndexWhereFrom - none for a negative offset", () => @@ -499,7 +498,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findFirstIndexWhereFrom(constTrue, -1))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findFirstIndexWhereFrom - none for an offset that is too large", () => @@ -507,7 +506,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findFirstIndexWhereFrom(constTrue, n + 1))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findFirstIndexWhereSTM - determines the correct index", () => @@ -515,14 +514,14 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findFirstIndexWhereSTM((n) => STM.succeed(n % 5 === 0)))) - assert.deepStrictEqual(result, Option.some(4)) + assertSome(result, 4) })) it.effect("findFirstIndexWhereSTM - none for empty array", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(pipe(array, TArray.findFirstIndexWhereSTM(() => STM.succeed(true)))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findFirstIndexWhereSTM - none for empty array", () => @@ -530,7 +529,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findFirstIndexWhereSTM((i) => STM.succeed(i > n)))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findFirstIndexWhereSTM - is atomic", () => @@ -547,7 +546,7 @@ describe("TArray", () => { STM.forEach((n) => pipe(array, TArray.update(n, () => 1))) )) const result = yield* $(Fiber.join(fiber)) - assert.isTrue( + assertTrue( (Option.isSome(result) && result.value === largePrime - 1) || Option.isNone(result) ) @@ -562,7 +561,7 @@ describe("TArray", () => { TArray.findFirstIndexWhereSTM((n) => n === 4 ? STM.fail("boom") : STM.succeed(n % 5 === 0)), STM.flip )) - assert.strictEqual(result, "boom") + strictEqual(result, "boom") })) it.effect("findFirstIndexWhereSTM - succeeds on errors after result found", () => @@ -573,7 +572,7 @@ describe("TArray", () => { array, TArray.findFirstIndexWhereSTM((n) => n === 6 ? STM.fail("boom") : STM.succeed(n % 5 === 0)) )) - assert.deepStrictEqual(result, Option.some(4)) + assertSome(result, 4) })) it.effect("findFirstIndexWhereFromSTM - determines the correct index, with offset", () => @@ -581,7 +580,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findFirstIndexWhereFromSTM((n) => STM.succeed(n % 2 === 0), 5))) - assert.deepStrictEqual(result, Option.some(5)) + assertSome(result, 5) })) it.effect("findFirstIndexWhereFromSTM - none if absent after offset", () => @@ -589,7 +588,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findFirstIndexWhereFromSTM((n) => STM.succeed(n % 7 === 0), 7))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findFirstIndexWhereFromSTM - none for a negative offset", () => @@ -597,7 +596,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findFirstIndexWhereFromSTM(() => STM.succeed(true), -1))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findFirstIndexWherFromeSTM - none for an offset that is too large", () => @@ -605,7 +604,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findFirstIndexWhereFromSTM(() => STM.succeed(true), n + 1))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findFirstIndexWhereFromSTM - succeeds when error excluded by offset", () => @@ -619,7 +618,7 @@ describe("TArray", () => { ? STM.fail("boom") : STM.succeed(n % 5 === 0), 2) )) - assert.deepStrictEqual(result, Option.some(4)) + assertSome(result, 4) })) it.effect("findFirstSTM - is correct", () => @@ -627,14 +626,14 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findFirstSTM((n) => STM.succeed(n % 5 === 0)))) - assert.deepStrictEqual(result, Option.some(5)) + assertSome(result, 5) })) it.effect("findFirstSTM - succeeds for empty array", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(pipe(array, TArray.findFirstSTM(() => STM.succeed(true)))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findFirstSTM - fails to find absent", () => @@ -642,7 +641,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findFirstSTM((i) => STM.succeed(i > n)))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findFirstSTM - is atomic", () => @@ -659,7 +658,7 @@ describe("TArray", () => { STM.forEach((n) => pipe(array, TArray.update(n, () => 1))) )) const result = yield* $(Fiber.join(fiber)) - assert.isTrue( + assertTrue( (Option.isSome(result) && result.value === largePrime) || Option.isNone(result) ) @@ -674,7 +673,7 @@ describe("TArray", () => { TArray.findFirstSTM((n) => n === 4 ? STM.fail("boom") : STM.succeed(n % 5 === 0)), STM.flip )) - assert.strictEqual(result, "boom") + strictEqual(result, "boom") })) it.effect("findFirstSTM - succeeds on errors after result found", () => @@ -685,7 +684,7 @@ describe("TArray", () => { array, TArray.findFirstSTM((n) => n === 6 ? STM.fail("boom") : STM.succeed(n % 5 === 0)) )) - assert.deepStrictEqual(result, Option.some(5)) + assertSome(result, 5) })) it.effect("findLast - is correct", () => @@ -693,14 +692,14 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findLast((n) => n % 5 === 0))) - assert.deepStrictEqual(result, Option.some(10)) + assertSome(result, 10) })) it.effect("findLast - succeeds for empty array", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(pipe(array, TArray.findLast(constTrue))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findLast - fails to find absent", () => @@ -708,7 +707,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findLast((i) => i > n))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findLast - is atomic", () => @@ -725,7 +724,7 @@ describe("TArray", () => { STM.forEach((n) => pipe(array, TArray.update(n, () => 1))) )) const result = yield* $(Fiber.join(fiber)) - assert.isTrue( + assertTrue( (Option.isSome(result) && result.value === largePrime) || Option.isNone(result) ) @@ -735,49 +734,49 @@ describe("TArray", () => { Effect.gen(function*($) { const array = yield* $(makeRepeats(3, 3)) const result = yield* $(pipe(array, TArray.findLastIndex(2))) - assert.deepStrictEqual(result, Option.some(7)) + assertSome(result, 7) })) it.effect("findLastIndex - none for empty array", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(pipe(array, TArray.findLastIndex(1))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findLastIndex - none if absent", () => Effect.gen(function*($) { const array = yield* $(makeRepeats(3, 3)) const result = yield* $(pipe(array, TArray.findLastIndex(4))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findLastIndexFrom - correct index if in array, with limit", () => Effect.gen(function*($) { const array = yield* $(makeRepeats(3, 3)) const result = yield* $(pipe(array, TArray.findLastIndexFrom(2, 6))) - assert.deepStrictEqual(result, Option.some(4)) + assertSome(result, 4) })) it.effect("findLastIndexFrom - none if absent before limit", () => Effect.gen(function*($) { const array = yield* $(makeRepeats(3, 3)) const result = yield* $(pipe(array, TArray.findLastIndexFrom(3, 1))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findLastIndexFrom - none for a negative limit", () => Effect.gen(function*($) { const array = yield* $(makeRepeats(3, 3)) const result = yield* $(pipe(array, TArray.findLastIndexFrom(2, -1))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findLastIndexFrom - none for a limit that is too large", () => Effect.gen(function*($) { const array = yield* $(makeRepeats(3, 3)) const result = yield* $(pipe(array, TArray.findLastIndexFrom(2, 9))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findLastSTM - is correct", () => @@ -785,14 +784,14 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findLastSTM((n) => STM.succeed(n % 5 === 0)))) - assert.deepStrictEqual(result, Option.some(10)) + assertSome(result, 10) })) it.effect("findLastSTM - succeeds for empty array", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(pipe(array, TArray.findLastSTM(() => STM.succeed(true)))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findLastSTM - fails to find absent", () => @@ -800,7 +799,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.findLastSTM((i) => STM.succeed(i > n)))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("findLastSTM - is atomic", () => @@ -817,7 +816,7 @@ describe("TArray", () => { STM.forEach((n) => pipe(array, TArray.update(n, () => 1))) )) const result = yield* $(Fiber.join(fiber)) - assert.isTrue( + assertTrue( (Option.isSome(result) && result.value === largePrime) || Option.isNone(result) ) @@ -831,7 +830,7 @@ describe("TArray", () => { array, TArray.findLastSTM((n) => n === 4 ? STM.fail("boom") : STM.succeed(n % 7 === 0)) )) - assert.deepStrictEqual(result, Option.some(7)) + assertSome(result, 7) })) it.effect("findLastSTM - fails on errors after result found", () => @@ -843,7 +842,7 @@ describe("TArray", () => { TArray.findLastSTM((n) => n === 8 ? STM.fail("boom") : STM.succeed(n % 7 === 0)), STM.flip )) - assert.strictEqual(result, "boom") + strictEqual(result, "boom") })) it.effect("forEach - side-effect is transactional", () => @@ -858,7 +857,7 @@ describe("TArray", () => { )) const result = yield* $(TRef.get(ref)) yield* $(Fiber.join(fiber)) - assert.isTrue(result === 0 || result === n) + assertTrue(result === 0 || result === n) })) it.effect("get - should fail when the index is out of bounds", () => @@ -868,7 +867,7 @@ describe("TArray", () => { STM.flatMap(TArray.get(-1)), Effect.exit )) - assert.deepStrictEqual(result, Exit.die(new Cause.RuntimeException("Index out of bounds"))) + deepStrictEqual(result, Exit.die(new Cause.RuntimeException("Index out of bounds"))) })) it.effect("headOption - retrieves the first item in the array", () => @@ -876,14 +875,14 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(TArray.headOption(array)) - assert.deepStrictEqual(result, Option.some(1)) + assertSome(result, 1) })) it.effect("headOption - is none for an empty array", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(TArray.headOption(array)) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("lastOption - retrieves the last entry", () => @@ -891,14 +890,14 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(TArray.lastOption(array)) - assert.deepStrictEqual(result, Option.some(n)) + assertSome(result, n) })) it.effect("lastOption - is none for an empty array", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(TArray.lastOption(array)) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("maxOption - computes correct maximum", () => @@ -906,14 +905,14 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.maxOption(Number.Order))) - assert.deepStrictEqual(result, Option.some(n)) + assertSome(result, n) })) it.effect("maxOption - returns none for an empty array", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(pipe(array, TArray.maxOption(Number.Order))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("minOption - computes correct minimum", () => @@ -921,14 +920,14 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.minOption(Number.Order))) - assert.deepStrictEqual(result, Option.some(1)) + assertSome(result, 1) })) it.effect("minOption - returns none for an empty array", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(pipe(array, TArray.maxOption(Number.Order))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("reduce - is atomic", () => @@ -941,7 +940,7 @@ describe("TArray", () => { STM.forEach((n) => pipe(array, TArray.update(n, (n) => n + 1))) )) const result = yield* $(Fiber.join(fiber)) - assert.isTrue(result === 0 || result === n) + assertTrue(result === 0 || result === n) })) it.effect("reduceOption - reduces correctly", () => @@ -949,21 +948,21 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.reduceOption((x, y) => x + y))) - assert.deepStrictEqual(result, Option.some((n * (n + 1)) / 2)) + assertSome(result, (n * (n + 1)) / 2) })) it.effect("reduceOption - single entry", () => Effect.gen(function*($) { const array = yield* $(makeTArray(1, 1)) const result = yield* $(pipe(array, TArray.reduceOption((x, y) => x + y))) - assert.deepStrictEqual(result, Option.some(1)) + assertSome(result, 1) })) it.effect("reduceOption - none for empty array", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(pipe(array, TArray.reduceOption((x, y) => x + y))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("reduceOption - is atomic", () => @@ -976,7 +975,7 @@ describe("TArray", () => { STM.forEach((n) => pipe(array, TArray.update(n, () => 1))) )) const result = yield* $(Fiber.join(fiber)) - assert.isTrue( + assertTrue( Option.isSome(result) && (result.value === (n * (n + 1)) / 2 || result.value === n) ) @@ -987,21 +986,21 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.reduceOptionSTM((x, y) => STM.succeed(x + y)))) - assert.deepStrictEqual(result, Option.some((n * (n + 1)) / 2)) + assertSome(result, (n * (n + 1)) / 2) })) it.effect("reduceOptionSTM - single entry", () => Effect.gen(function*($) { const array = yield* $(makeTArray(1, 1)) const result = yield* $(pipe(array, TArray.reduceOptionSTM((x, y) => STM.succeed(x + y)))) - assert.deepStrictEqual(result, Option.some(1)) + assertSome(result, 1) })) it.effect("reduceOptionSTM - none for empty array", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(pipe(array, TArray.reduceOptionSTM((x, y) => STM.succeed(x + y)))) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("reduceOptionSTM - is atomic", () => @@ -1014,7 +1013,7 @@ describe("TArray", () => { STM.forEach((n) => pipe(array, TArray.update(n, () => 1))) )) const result = yield* $(Fiber.join(fiber)) - assert.isTrue( + assertTrue( Option.isSome(result) && (result.value === (n * (n + 1)) / 2 || result.value === n) ) @@ -1029,7 +1028,7 @@ describe("TArray", () => { TArray.reduceOptionSTM((x, y) => y === 4 ? STM.fail("boom") : STM.succeed(x + y)), STM.flip )) - assert.strictEqual(result, "boom") + strictEqual(result, "boom") })) it.effect("reduceSTM - is atomic", () => @@ -1042,7 +1041,7 @@ describe("TArray", () => { STM.forEach((n) => pipe(array, TArray.update(n, (n) => n + 1))) )) const result = yield* $(Fiber.join(fiber)) - assert.isTrue(result === 0 || result === n) + assertTrue(result === 0 || result === n) })) it.effect("reduceSTM - returns failures", () => @@ -1052,7 +1051,7 @@ describe("TArray", () => { acc === Math.floor(n / 2) ? STM.fail("boom") : STM.succeed(acc + n) const array = yield* $(makeTArray(n, 1)) const result = yield* $(pipe(array, TArray.reduceSTM(0, failInTheMiddle), STM.either)) - assert.deepStrictEqual(result, Either.left("boom")) + assertLeft(result, "boom") })) it.effect("size - returns the correct size", () => @@ -1060,7 +1059,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = TArray.size(array) - assert.strictEqual(result, n) + strictEqual(result, n) })) it.effect("some - detects satisfaction", () => @@ -1068,7 +1067,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.some((n) => n % 2 === 0))) - assert.isTrue(result) + assertTrue(result) })) it.effect("some - detects lack of satisfaction", () => @@ -1076,14 +1075,14 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.some((n) => n % 11 === 0))) - assert.isFalse(result) + assertFalse(result) })) it.effect("some - false for empty array", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(pipe(array, TArray.some(constTrue))) - assert.isFalse(result) + assertFalse(result) })) it.effect("someSTM - detects satisfaction", () => @@ -1091,7 +1090,7 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.someSTM((n) => STM.succeed(n % 2 === 0)))) - assert.isTrue(result) + assertTrue(result) })) it.effect("someSTM - detects lack of satisfaction", () => @@ -1099,14 +1098,14 @@ describe("TArray", () => { const n = 10 const array = yield* $(makeStair(n)) const result = yield* $(pipe(array, TArray.someSTM((n) => STM.succeed(n % 11 === 0)))) - assert.isFalse(result) + assertFalse(result) })) it.effect("someSTM - false for empty array", () => Effect.gen(function*($) { const array = yield* $(TArray.empty()) const result = yield* $(pipe(array, TArray.someSTM(() => STM.succeed(true)))) - assert.isFalse(result) + assertFalse(result) })) it.effect("someSTM - fails for errors before witness", () => @@ -1118,7 +1117,7 @@ describe("TArray", () => { TArray.someSTM((n) => n === 4 ? STM.fail("boom") : STM.succeed(n === 5)), STM.flip )) - assert.strictEqual(result, "boom") + strictEqual(result, "boom") })) it.effect("someSTM - fails for errors after witness", () => @@ -1130,7 +1129,7 @@ describe("TArray", () => { TArray.someSTM((n) => n === 6 ? STM.fail("boom") : STM.succeed(n === 5)), STM.flip )) - assert.strictEqual(result, "boom") + strictEqual(result, "boom") })) it.effect("transform - updates values atomically", () => @@ -1145,7 +1144,7 @@ describe("TArray", () => { yield* $(Fiber.join(fiber)) const first = yield* $(pipe(array, TArray.get(0))) const last = yield* $(pipe(array, TArray.get(n - 1))) - assert.isTrue( + assertTrue( (first === "a+b+c" && last === "a+b+c") || (first === "a+c+b" && last === "a+c+b") ) @@ -1163,7 +1162,7 @@ describe("TArray", () => { yield* $(Fiber.join(fiber)) const first = yield* $(pipe(array, TArray.get(0))) const last = yield* $(pipe(array, TArray.get(n - 1))) - assert.isTrue( + assertTrue( (first === "a+b+c" && last === "a+b+c") || (first === "a+c+b" && last === "a+c+b") ) @@ -1180,8 +1179,8 @@ describe("TArray", () => { STM.either )) const first = yield* $(pipe(array, TArray.get(0))) - assert.strictEqual(first, 0) - assert.deepStrictEqual(result, Either.left("boom")) + strictEqual(first, 0) + assertLeft(result, "boom") })) it.effect("update - happy path", () => @@ -1192,14 +1191,14 @@ describe("TArray", () => { TArray.update(0, (n) => -n), STM.zipRight(valuesOf(array)) )) - assert.deepStrictEqual(result, [-42]) + deepStrictEqual(result, [-42]) })) it.effect("update - dies with index out of bounds", () => Effect.gen(function*($) { const array = yield* $(makeTArray(1, 42)) const result = yield* $(pipe(array, TArray.update(-1, identity), Effect.exit)) - assert.deepStrictEqual(result, Exit.die(new Cause.RuntimeException("Index out of bounds"))) + deepStrictEqual(result, Exit.die(new Cause.RuntimeException("Index out of bounds"))) })) it.effect("updateSTM - happy path", () => @@ -1210,14 +1209,14 @@ describe("TArray", () => { TArray.updateSTM(0, (n) => STM.succeed(-n)), STM.zipRight(valuesOf(array)) )) - assert.deepStrictEqual(result, [-42]) + deepStrictEqual(result, [-42]) })) it.effect("updateSTM - dies with index out of bounds", () => Effect.gen(function*($) { const array = yield* $(makeTArray(1, 42)) const result = yield* $(pipe(array, TArray.updateSTM(-1, (n) => STM.succeed(n)), Effect.exit)) - assert.deepStrictEqual(result, Exit.die(new Cause.RuntimeException("Index out of bounds"))) + deepStrictEqual(result, Exit.die(new Cause.RuntimeException("Index out of bounds"))) })) it.effect("updateSTM - handles failures", () => @@ -1230,13 +1229,13 @@ describe("TArray", () => { STM.commit, Effect.either )) - assert.deepStrictEqual(result, Either.left("boom")) + assertLeft(result, "boom") })) it.effect("toChunk", () => Effect.gen(function*($) { const array = yield* $(TArray.make(1, 2, 3, 4, 5)) const result = yield* $(TArray.toArray(array)) - assert.deepStrictEqual(Array.from(result), [1, 2, 3, 4, 5]) + deepStrictEqual(Array.from(result), [1, 2, 3, 4, 5]) })) }) diff --git a/packages/effect/test/TMap.test.ts b/packages/effect/test/TMap.test.ts index 57742764526..0f12f84fd52 100644 --- a/packages/effect/test/TMap.test.ts +++ b/packages/effect/test/TMap.test.ts @@ -1,17 +1,8 @@ -import * as Array from "effect/Array" -import * as Chunk from "effect/Chunk" -import * as Effect from "effect/Effect" -import * as Equal from "effect/Equal" -import * as Exit from "effect/Exit" -import { pipe } from "effect/Function" -import * as Hash from "effect/Hash" -import * as Option from "effect/Option" -import * as STM from "effect/STM" +import { Array, Chunk, Effect, Equal, Exit, FastCheck as fc, Hash, Option, pipe, STM, TMap } from "effect" +import { assertFalse, assertNone, assertSome, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import { equivalentElements } from "effect/test/utils/equals" import * as it from "effect/test/utils/extend" -import * as TMap from "effect/TMap" -import * as fc from "fast-check" -import { assert, describe, expect } from "vitest" +import { describe } from "vitest" class HashContainer implements Equal.Equal { constructor(readonly i: number) {} @@ -37,7 +28,7 @@ describe("TMap", () => { STM.flatMap(TMap.isEmpty) ) const result = yield* $(STM.commit(transaction)) - assert.isTrue(result) + assertTrue(result) })) it.effect("fromIterable", () => @@ -47,7 +38,7 @@ describe("TMap", () => { STM.flatMap(TMap.toArray) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [["a", 1], ["b", 3], ["c", 2]]) + deepStrictEqual(result, [["a", 1], ["b", 3], ["c", 2]]) })) it.effect("get - existing element", () => @@ -57,7 +48,7 @@ describe("TMap", () => { STM.flatMap(TMap.get("a")) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, Option.some(1)) + assertSome(result, 1) })) it.effect("get - non-existing element", () => @@ -67,7 +58,7 @@ describe("TMap", () => { STM.flatMap(TMap.get("a")) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("getOrElse - existing element", () => @@ -77,7 +68,7 @@ describe("TMap", () => { STM.flatMap(TMap.getOrElse("a", () => 10)) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, 1) + deepStrictEqual(result, 1) })) it.effect("getOrElse - non-existing element", () => @@ -87,7 +78,7 @@ describe("TMap", () => { STM.flatMap(TMap.getOrElse("a", () => 10)) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, 10) + deepStrictEqual(result, 10) })) it.effect("has - existing element", () => @@ -97,7 +88,7 @@ describe("TMap", () => { STM.flatMap(TMap.has("a")) ) const result = yield* $(STM.commit(transaction)) - assert.isTrue(result) + assertTrue(result) })) it.effect("has - non-existing element", () => @@ -107,7 +98,7 @@ describe("TMap", () => { STM.flatMap(TMap.has("a")) ) const result = yield* $(STM.commit(transaction)) - assert.isFalse(result) + assertFalse(result) })) it.it("keys - collect all keys", () => @@ -118,8 +109,8 @@ describe("TMap", () => { ) const result = await Effect.runPromise(STM.commit(transaction)) const keys = entries.map((entry) => entry[0]) - assert.lengthOf(pipe(result, Array.differenceWith(equivalentElements())(keys)), 0) - assert.lengthOf(pipe(keys, Array.differenceWith(equivalentElements())(result)), 0) + strictEqual(pipe(result, Array.differenceWith(equivalentElements())(keys)).length, 0) + strictEqual(pipe(keys, Array.differenceWith(equivalentElements())(result)).length, 0) }))) it.effect("merge", () => @@ -134,8 +125,8 @@ describe("TMap", () => { ) ) const { result1, result2 } = yield* $(STM.commit(transaction)) - assert.strictEqual(result1, 3) - assert.strictEqual(result2, 2) + strictEqual(result1, 3) + strictEqual(result2, 2) })) it.effect("reduce - non-empty map", () => @@ -145,7 +136,7 @@ describe("TMap", () => { STM.flatMap(TMap.reduce(0, (acc, value) => acc + value)) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 6) + strictEqual(result, 6) })) it.effect("reduce - empty map", () => @@ -155,7 +146,7 @@ describe("TMap", () => { STM.flatMap(TMap.reduce(0, (acc, value) => acc + value)) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("reduceSTM - non-empty map", () => @@ -165,7 +156,7 @@ describe("TMap", () => { STM.flatMap(TMap.reduceSTM(0, (acc, value) => STM.succeed(acc + value))) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 6) + strictEqual(result, 6) })) it.effect("reduceSTM - empty map", () => @@ -175,7 +166,7 @@ describe("TMap", () => { STM.flatMap(TMap.reduceSTM(0, (acc, value) => STM.succeed(acc + value))) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("remove - remove an existing element", () => @@ -186,7 +177,7 @@ describe("TMap", () => { STM.flatMap(TMap.get("a")) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("remove - remove an non-existing element", () => @@ -197,7 +188,7 @@ describe("TMap", () => { STM.flatMap(TMap.get("a")) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("removeIf", () => @@ -211,7 +202,7 @@ describe("TMap", () => { return [removed, a, aa, aaa] as const }) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [[["aaa", 3], ["aa", 2]], true, false, false]) + deepStrictEqual(result, [[["aaa", 3], ["aa", 2]], true, false, false]) })) it.effect("removeIf > { discard: true }", () => @@ -225,7 +216,7 @@ describe("TMap", () => { return [a, aa, aaa] as const }) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [true, false, true]) + deepStrictEqual(result, [true, false, true]) })) it.effect("retainIf", () => @@ -239,7 +230,7 @@ describe("TMap", () => { return [removed, a, aa, aaa] as const }) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [[["aaa", 3], ["a", 1]], false, true, false]) + deepStrictEqual(result, [[["aaa", 3], ["a", 1]], false, true, false]) })) it.effect("retainIf > { discard: true }", () => @@ -253,7 +244,7 @@ describe("TMap", () => { return [a, aa, aaa] as const }) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [false, true, false]) + deepStrictEqual(result, [false, true, false]) })) it.effect("set - adds new element", () => @@ -264,7 +255,7 @@ describe("TMap", () => { STM.flatMap(TMap.get("a")) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, Option.some(1)) + assertSome(result, 1) })) it.effect("set - overwrites an existing element", () => @@ -275,7 +266,7 @@ describe("TMap", () => { STM.flatMap(TMap.get("a")) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, Option.some(10)) + assertSome(result, 10) })) it.effect("set - add many keys with negative hash codes", () => @@ -288,8 +279,8 @@ describe("TMap", () => { STM.flatMap(TMap.toArray) ) const result = yield* $(STM.commit(transaction)) - assert.lengthOf(pipe(result, Array.differenceWith(equivalentElements())(entries)), 0) - assert.lengthOf(pipe(entries, Array.differenceWith(equivalentElements())(result)), 0) + strictEqual(pipe(result, Array.differenceWith(equivalentElements())(entries)).length, 0) + strictEqual(pipe(entries, Array.differenceWith(equivalentElements())(result)).length, 0) })) it.effect("setIfAbsent", () => @@ -302,8 +293,8 @@ describe("TMap", () => { ) const result = yield* $(STM.commit(transaction)) const expected = [["a", 1], ["b", 2]] - assert.lengthOf(pipe(result, Array.differenceWith(equivalentElements())(expected)), 0) - assert.lengthOf(pipe(expected, Array.differenceWith(equivalentElements())(result)), 0) + strictEqual(pipe(result, Array.differenceWith(equivalentElements())(expected)).length, 0) + strictEqual(pipe(expected, Array.differenceWith(equivalentElements())(result)).length, 0) })) it.effect("size", () => @@ -313,7 +304,7 @@ describe("TMap", () => { STM.flatMap(TMap.size) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 2) + strictEqual(result, 2) })) it.it("toChunk - collect all elements", () => @@ -323,9 +314,9 @@ describe("TMap", () => { STM.flatMap(TMap.toChunk) ) const result = await Effect.runPromise(STM.commit(transaction)) - expect(Chunk.isChunk(result)).toBe(true) - assert.lengthOf(pipe(Chunk.toReadonlyArray(result), Array.differenceWith(equivalentElements())(entries)), 0) - assert.lengthOf(pipe(entries, Array.differenceWith(equivalentElements())(Chunk.toReadonlyArray(result))), 0) + assertTrue(Chunk.isChunk(result)) + strictEqual(pipe(Chunk.toReadonlyArray(result), Array.differenceWith(equivalentElements())(entries)).length, 0) + strictEqual(pipe(entries, Array.differenceWith(equivalentElements())(Chunk.toReadonlyArray(result))).length, 0) }))) it.it("toReadonlyArray - collect all elements", () => @@ -335,8 +326,8 @@ describe("TMap", () => { STM.flatMap(TMap.toArray) ) const result = await Effect.runPromise(STM.commit(transaction)) - assert.lengthOf(pipe(result, Array.differenceWith(equivalentElements())(entries)), 0) - assert.lengthOf(pipe(entries, Array.differenceWith(equivalentElements())(result)), 0) + strictEqual(pipe(result, Array.differenceWith(equivalentElements())(entries)).length, 0) + strictEqual(pipe(entries, Array.differenceWith(equivalentElements())(result)).length, 0) }))) it.it("toMap - collect all elements", () => @@ -346,8 +337,8 @@ describe("TMap", () => { STM.flatMap(TMap.toMap) ) const result = await Effect.runPromise(STM.commit(transaction)) - assert.lengthOf(pipe(Array.fromIterable(result), Array.differenceWith(equivalentElements())(entries)), 0) - assert.lengthOf(pipe(entries, Array.differenceWith(equivalentElements())(Array.fromIterable(result))), 0) + strictEqual(pipe(Array.fromIterable(result), Array.differenceWith(equivalentElements())(entries)).length, 0) + strictEqual(pipe(entries, Array.differenceWith(equivalentElements())(Array.fromIterable(result))).length, 0) }))) it.effect("transform", () => @@ -359,8 +350,8 @@ describe("TMap", () => { ) const result = yield* $(STM.commit(transaction)) const expected = [["b", 2], ["bb", 4], ["bbb", 6]] - assert.lengthOf(pipe(result, Array.differenceWith(equivalentElements())(expected)), 0) - assert.lengthOf(pipe(expected, Array.differenceWith(equivalentElements())(result)), 0) + strictEqual(pipe(result, Array.differenceWith(equivalentElements())(expected)).length, 0) + strictEqual(pipe(expected, Array.differenceWith(equivalentElements())(result)).length, 0) })) it.effect("transform - handles keys with negative hash codes", () => @@ -372,8 +363,8 @@ describe("TMap", () => { ) const result = yield* $(STM.commit(transaction)) const expected = [[new HashContainer(2), 2], [new HashContainer(4), 4], [new HashContainer(6), 6]] - assert.lengthOf(pipe(result, Array.differenceWith(equivalentElements())(expected)), 0) - assert.lengthOf(pipe(expected, Array.differenceWith(equivalentElements())(result)), 0) + strictEqual(pipe(result, Array.differenceWith(equivalentElements())(expected)).length, 0) + strictEqual(pipe(expected, Array.differenceWith(equivalentElements())(result)).length, 0) })) it.effect("transform - and shrink", () => @@ -384,7 +375,7 @@ describe("TMap", () => { STM.flatMap(TMap.toArray) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [["key", 6]]) + deepStrictEqual(result, [["key", 6]]) })) it.effect("transformSTM", () => @@ -396,8 +387,8 @@ describe("TMap", () => { ) const result = yield* $(STM.commit(transaction)) const expected = [["b", 2], ["bb", 4], ["bbb", 6]] - assert.lengthOf(pipe(result, Array.differenceWith(equivalentElements())(expected)), 0) - assert.lengthOf(pipe(expected, Array.differenceWith(equivalentElements())(result)), 0) + strictEqual(pipe(result, Array.differenceWith(equivalentElements())(expected)).length, 0) + strictEqual(pipe(expected, Array.differenceWith(equivalentElements())(result)).length, 0) })) it.effect("transformSTM - and shrink", () => @@ -408,7 +399,7 @@ describe("TMap", () => { STM.flatMap(TMap.toArray) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [["key", 6]]) + deepStrictEqual(result, [["key", 6]]) })) it.effect("transformValues", () => @@ -420,8 +411,8 @@ describe("TMap", () => { ) const result = yield* $(STM.commit(transaction)) const expected = [["a", 2], ["aa", 4], ["aaa", 6]] - assert.lengthOf(pipe(result, Array.differenceWith(equivalentElements())(expected)), 0) - assert.lengthOf(pipe(expected, Array.differenceWith(equivalentElements())(result)), 0) + strictEqual(pipe(result, Array.differenceWith(equivalentElements())(expected)).length, 0) + strictEqual(pipe(expected, Array.differenceWith(equivalentElements())(result)).length, 0) })) it.effect("transformValues - parallel", () => @@ -435,7 +426,7 @@ describe("TMap", () => { ) yield* $(Effect.replicateEffect(effect, 2)) const result = yield* $(pipe(map, TMap.get("a"))) - assert.deepStrictEqual(result, Option.some(2_000)) + assertSome(result, 2_000) })) it.effect("transformValuesSTM", () => @@ -447,8 +438,8 @@ describe("TMap", () => { ) const result = yield* $(STM.commit(transaction)) const expected = [["a", 2], ["aa", 4], ["aaa", 6]] - assert.lengthOf(pipe(result, Array.differenceWith(equivalentElements())(expected)), 0) - assert.lengthOf(pipe(expected, Array.differenceWith(equivalentElements())(result)), 0) + strictEqual(pipe(result, Array.differenceWith(equivalentElements())(expected)).length, 0) + strictEqual(pipe(expected, Array.differenceWith(equivalentElements())(result)).length, 0) })) it.effect("updateWith", () => @@ -462,7 +453,7 @@ describe("TMap", () => { return yield* $(TMap.toArray(map)) }) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [["a", 2], ["c", 3]]) + deepStrictEqual(result, [["a", 2], ["c", 3]]) })) it.it("values - collect all values", () => @@ -473,8 +464,8 @@ describe("TMap", () => { ) const result = await Effect.runPromise(STM.commit(transaction)) const values = entries.map((entry) => entry[1]) - assert.lengthOf(pipe(result, Array.differenceWith(equivalentElements())(values)), 0) - assert.lengthOf(pipe(values, Array.differenceWith(equivalentElements())(result)), 0) + strictEqual(pipe(result, Array.differenceWith(equivalentElements())(values)).length, 0) + strictEqual(pipe(values, Array.differenceWith(equivalentElements())(result)).length, 0) }))) it.effect("avoid issues due to race conditions (ZIO Issue #4648)", () => @@ -492,6 +483,6 @@ describe("TMap", () => { ), { discard: true }), Effect.exit )) - assert.deepStrictEqual(result, Exit.void) + deepStrictEqual(result, Exit.void) })) }) diff --git a/packages/effect/test/TPriorityQueue.test.ts b/packages/effect/test/TPriorityQueue.test.ts index 09c6c175c24..d68f9759aeb 100644 --- a/packages/effect/test/TPriorityQueue.test.ts +++ b/packages/effect/test/TPriorityQueue.test.ts @@ -1,15 +1,18 @@ -import * as RA from "effect/Array" -import * as Effect from "effect/Effect" -import { pipe } from "effect/Function" -import * as number from "effect/Number" -import * as Option from "effect/Option" -import * as Order from "effect/Order" -import * as STM from "effect/STM" +import { + Array as Arr, + Effect, + FastCheck as fc, + Number as number, + Option, + Order, + pipe, + STM, + TPriorityQueue +} from "effect" +import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import { equivalentElements } from "effect/test/utils/equals" import * as it from "effect/test/utils/extend" -import * as TPriorityQueue from "effect/TPriorityQueue" -import * as fc from "fast-check" -import { assert, describe } from "vitest" +import { describe } from "vitest" interface Event { readonly time: number @@ -39,7 +42,7 @@ describe("TPriorityQueue", () => { STM.flatMap(TPriorityQueue.isEmpty) ) const result = await Effect.runPromise(STM.commit(transaction)) - assert.strictEqual(result, events.length === 0) + strictEqual(result, events.length === 0) }))) it.it("isNonEmpty", () => @@ -50,7 +53,7 @@ describe("TPriorityQueue", () => { STM.flatMap(TPriorityQueue.isNonEmpty) ) const result = await Effect.runPromise(STM.commit(transaction)) - assert.strictEqual(result, events.length > 0) + strictEqual(result, events.length > 0) }))) it.it("offerAll and takeAll", () => @@ -62,9 +65,9 @@ describe("TPriorityQueue", () => { STM.map((chunk) => Array.from(chunk)) ) const result = await Effect.runPromise(STM.commit(transaction)) - assert.lengthOf(pipe(result, RA.differenceWith(equivalentElements())(events)), 0) - assert.lengthOf(pipe(events, RA.differenceWith(equivalentElements())(result)), 0) - assert.deepStrictEqual(result, pipe(result, RA.sort(orderByTime))) + strictEqual(pipe(result, Arr.differenceWith(equivalentElements())(events)).length, 0) + strictEqual(pipe(events, Arr.differenceWith(equivalentElements())(result)).length, 0) + deepStrictEqual(result, pipe(result, Arr.sort(orderByTime))) }))) it.it("removeIf", () => @@ -75,10 +78,10 @@ describe("TPriorityQueue", () => { STM.flatMap(TPriorityQueue.toArray) ) const result = await Effect.runPromise(STM.commit(transaction)) - const filtered = RA.filter(events, (a) => !f(a)) - assert.lengthOf(RA.differenceWith(equivalentElements())(result, filtered), 0) - assert.lengthOf(RA.differenceWith(equivalentElements())(filtered, result), 0) - assert.deepStrictEqual(result, RA.sort(orderByTime)(result)) + const filtered = Arr.filter(events, (a) => !f(a)) + strictEqual(Arr.differenceWith(equivalentElements())(result, filtered).length, 0) + strictEqual(Arr.differenceWith(equivalentElements())(filtered, result).length, 0) + deepStrictEqual(result, Arr.sort(orderByTime)(result)) }))) it.it("retainIf", () => @@ -89,10 +92,10 @@ describe("TPriorityQueue", () => { STM.flatMap(TPriorityQueue.toArray) ) const result = await Effect.runPromise(STM.commit(transaction)) - const filtered = RA.filter(events, f) - assert.lengthOf(RA.differenceWith(equivalentElements())(result, filtered), 0) - assert.lengthOf(RA.differenceWith(equivalentElements())(filtered, result), 0) - assert.deepStrictEqual(result, RA.sort(orderByTime)(result)) + const filtered = Arr.filter(events, f) + strictEqual(Arr.differenceWith(equivalentElements())(result, filtered).length, 0) + strictEqual(Arr.differenceWith(equivalentElements())(filtered, result).length, 0) + deepStrictEqual(result, Arr.sort(orderByTime)(result)) }))) it.it("take", () => @@ -108,9 +111,9 @@ describe("TPriorityQueue", () => { STM.map((chunk) => Array.from(chunk)) ) const result = await Effect.runPromise(STM.commit(transaction)) - assert.lengthOf(pipe(result, RA.differenceWith(equivalentElements())(events)), 0) - assert.lengthOf(pipe(events, RA.differenceWith(equivalentElements())(result)), 0) - assert.deepStrictEqual(result, pipe(result, RA.sort(orderByTime))) + strictEqual(pipe(result, Arr.differenceWith(equivalentElements())(events)).length, 0) + strictEqual(pipe(events, Arr.differenceWith(equivalentElements())(result)).length, 0) + deepStrictEqual(result, pipe(result, Arr.sort(orderByTime))) }))) it.it("takeOption", () => @@ -132,8 +135,8 @@ describe("TPriorityQueue", () => { ) ) const result = await Effect.runPromise(STM.commit(transaction)) - assert.isTrue(Option.isSome(result[0])) - assert.isTrue(Option.isNone(result[1])) + assertTrue(Option.isSome(result[0])) + assertTrue(Option.isNone(result[1])) }) )) @@ -158,9 +161,9 @@ describe("TPriorityQueue", () => { ) ) const result = await Effect.runPromise(STM.commit(transaction)) - assert.lengthOf(pipe(result, RA.differenceWith(equivalentElements())(events)), 0) - assert.lengthOf(pipe(events, RA.differenceWith(equivalentElements())(result)), 0) - assert.deepStrictEqual(result, pipe(result, RA.sort(orderByTime))) + strictEqual(pipe(result, Arr.differenceWith(equivalentElements())(events)).length, 0) + strictEqual(pipe(events, Arr.differenceWith(equivalentElements())(result)).length, 0) + deepStrictEqual(result, pipe(result, Arr.sort(orderByTime))) } ) )) @@ -173,9 +176,9 @@ describe("TPriorityQueue", () => { STM.map((chunk) => Array.from(chunk)) ) const result = await Effect.runPromise(STM.commit(transaction)) - assert.lengthOf(pipe(result, RA.differenceWith(equivalentElements())(events)), 0) - assert.lengthOf(pipe(events, RA.differenceWith(equivalentElements())(result)), 0) - assert.deepStrictEqual(result, pipe(result, RA.sort(orderByTime))) + strictEqual(pipe(result, Arr.differenceWith(equivalentElements())(events)).length, 0) + strictEqual(pipe(events, Arr.differenceWith(equivalentElements())(result)).length, 0) + deepStrictEqual(result, pipe(result, Arr.sort(orderByTime))) }))) it.it("toReadonlyArray", () => @@ -185,8 +188,8 @@ describe("TPriorityQueue", () => { STM.flatMap(TPriorityQueue.toArray) ) const result = await Effect.runPromise(STM.commit(transaction)) - assert.lengthOf(pipe(result, RA.differenceWith(equivalentElements())(events)), 0) - assert.lengthOf(pipe(events, RA.differenceWith(equivalentElements())(result)), 0) - assert.deepStrictEqual(result, pipe(result, RA.sort(orderByTime))) + strictEqual(pipe(result, Arr.differenceWith(equivalentElements())(events)).length, 0) + strictEqual(pipe(events, Arr.differenceWith(equivalentElements())(result)).length, 0) + deepStrictEqual(result, pipe(result, Arr.sort(orderByTime))) }))) }) diff --git a/packages/effect/test/TPubSub.test.ts b/packages/effect/test/TPubSub.test.ts index e33c602e391..7c185271a7f 100644 --- a/packages/effect/test/TPubSub.test.ts +++ b/packages/effect/test/TPubSub.test.ts @@ -1,17 +1,20 @@ -import * as RA from "effect/Array" -import * as Deferred from "effect/Deferred" -import * as Effect from "effect/Effect" -import * as Fiber from "effect/Fiber" -import { pipe } from "effect/Function" -import * as number from "effect/Number" -import * as STM from "effect/STM" +import { + Array as Arr, + Deferred, + Effect, + FastCheck as fc, + Fiber, + Number as number, + pipe, + STM, + TPubSub, + TQueue +} from "effect" +import { deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import * as TPubSub from "effect/TPubSub" -import * as TQueue from "effect/TQueue" -import * as fc from "fast-check" -import { assert, describe } from "vitest" +import { describe } from "vitest" -const sort: (array: ReadonlyArray) => ReadonlyArray = RA.sort(number.Order) +const sort: (array: ReadonlyArray) => ReadonlyArray = Arr.sort(number.Order) describe("TPubSub", () => { it.it("sequential publishers and subscribers - with one publisher and one subscriber", () => @@ -45,7 +48,7 @@ describe("TPubSub", () => { return yield* $(Fiber.join(subscriber)) }) const result = await Effect.runPromise(program) - assert.deepStrictEqual(Array.from(result), as.slice(0, n)) + deepStrictEqual(Array.from(result), as.slice(0, n)) }))) it.it("sequential publishers and subscribers - with one publisher and two subscribers", () => @@ -99,8 +102,8 @@ describe("TPubSub", () => { return { result1, result2 } }) const { result1, result2 } = await Effect.runPromise(program) - assert.deepStrictEqual(Array.from(result1), as.slice(0, n)) - assert.deepStrictEqual(Array.from(result2), as.slice(0, n)) + deepStrictEqual(Array.from(result1), as.slice(0, n)) + deepStrictEqual(Array.from(result2), as.slice(0, n)) }))) it.it("concurrent publishers and subscribers - one to one", () => @@ -128,7 +131,7 @@ describe("TPubSub", () => { return yield* $(Fiber.join(subscriber)) }) const result = await Effect.runPromise(Effect.scoped(program)) - assert.deepStrictEqual(Array.from(result), as.slice(0, n)) + deepStrictEqual(Array.from(result), as.slice(0, n)) }))) it.it("concurrent publishers and subscribers - one to many", () => @@ -171,8 +174,8 @@ describe("TPubSub", () => { return { result1, result2 } }) const { result1, result2 } = await Effect.runPromise(Effect.scoped(program)) - assert.deepStrictEqual(Array.from(result1), as.slice(0, n)) - assert.deepStrictEqual(Array.from(result2), as.slice(0, n)) + deepStrictEqual(Array.from(result1), as.slice(0, n)) + deepStrictEqual(Array.from(result2), as.slice(0, n)) }))) it.it("concurrent publishers and subscribers - many to many", () => @@ -228,19 +231,19 @@ describe("TPubSub", () => { return { result1, result2 } }) const { result1, result2 } = await Effect.runPromise(program) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result1).filter((n) => n > 0), as.slice(0, n) ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result1).filter((n) => n < 0), as.slice(0, n).map((n) => -n) ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result2).filter((n) => n > 0), as.slice(0, n) ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result2).filter((n) => n < 0), as.slice(0, n).map((n) => -n) ) @@ -268,7 +271,7 @@ describe("TPubSub", () => { return yield* $(Fiber.join(subscriber)) }) const result = await Effect.runPromise(program) - assert.deepStrictEqual(Array.from(result), as) + deepStrictEqual(Array.from(result), as) }))) it.it("back pressure - one to many", () => @@ -309,8 +312,8 @@ describe("TPubSub", () => { return { result1, result2 } }) const { result1, result2 } = await Effect.runPromise(program) - assert.deepStrictEqual(Array.from(result1), as) - assert.deepStrictEqual(Array.from(result2), as) + deepStrictEqual(Array.from(result1), as) + deepStrictEqual(Array.from(result2), as) }))) it.it("back pressure - many to many", () => @@ -366,10 +369,10 @@ describe("TPubSub", () => { return { result1, result2 } }) const { result1, result2 } = await Effect.runPromise(program) - assert.deepStrictEqual(Array.from(result1).filter((n) => n > 0), as) - assert.deepStrictEqual(Array.from(result1).filter((n) => n < 0), as.map((n) => -n)) - assert.deepStrictEqual(Array.from(result2).filter((n) => n > 0), as) - assert.deepStrictEqual(Array.from(result2).filter((n) => n < 0), as.map((n) => -n)) + deepStrictEqual(Array.from(result1).filter((n) => n > 0), as) + deepStrictEqual(Array.from(result1).filter((n) => n < 0), as.map((n) => -n)) + deepStrictEqual(Array.from(result2).filter((n) => n > 0), as) + deepStrictEqual(Array.from(result2).filter((n) => n < 0), as.map((n) => -n)) }))) it.it("dropping - one to one", () => @@ -397,7 +400,7 @@ describe("TPubSub", () => { return yield* $(Fiber.join(subscriber)) }) const result = await Effect.runPromise(program) - assert.deepStrictEqual(Array.from(result), as.slice(0, n)) + deepStrictEqual(Array.from(result), as.slice(0, n)) }))) it.it("dropping - one to many", () => @@ -444,8 +447,8 @@ describe("TPubSub", () => { return { result1, result2 } }) const { result1, result2 } = await Effect.runPromise(program) - assert.deepStrictEqual(Array.from(result1), as.slice(0, n)) - assert.deepStrictEqual(Array.from(result2), as.slice(0, n)) + deepStrictEqual(Array.from(result1), as.slice(0, n)) + deepStrictEqual(Array.from(result2), as.slice(0, n)) }))) it.it("dropping - many to many", () => @@ -501,19 +504,19 @@ describe("TPubSub", () => { return { result1, result2 } }) const { result1, result2 } = await Effect.runPromise(program) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result1).filter((n) => n > 0), as.slice(0, Array.from(result1).filter((n) => n > 0).length) ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result1).filter((n) => n < 0), as.slice(0, n).map((n) => -n).slice(0, Array.from(result1).filter((n) => n < 0).length) ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result2).filter((n) => n > 0), as.slice(0, Array.from(result2).filter((n) => n > 0).length) ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result2).filter((n) => n < 0), as.slice(0, n).map((n) => -n).slice(0, Array.from(result2).filter((n) => n < 0).length) ) @@ -545,7 +548,7 @@ describe("TPubSub", () => { return yield* $(Fiber.join(subscriber)) }) const result = await Effect.runPromise(program) - assert.deepStrictEqual(Array.from(result), sort(Array.from(result))) + deepStrictEqual(Array.from(result), sort(Array.from(result))) }))) it.it("sliding - one to many", () => @@ -592,8 +595,8 @@ describe("TPubSub", () => { return { result1, result2 } }) const { result1, result2 } = await Effect.runPromise(program) - assert.deepStrictEqual(Array.from(result1), sort(Array.from(result1))) - assert.deepStrictEqual(Array.from(result2), sort(Array.from(result2))) + deepStrictEqual(Array.from(result1), sort(Array.from(result1))) + deepStrictEqual(Array.from(result2), sort(Array.from(result2))) }))) it.it("sliding - many to many", () => @@ -649,19 +652,19 @@ describe("TPubSub", () => { return { result1, result2 } }) const { result1, result2 } = await Effect.runPromise(program) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result1).filter((n) => n > 0), sort(Array.from(result1).filter((n) => n > 0)) ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result1).filter((n) => n < 0), sort(Array.from(result1).filter((n) => n < 0)) ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result2).filter((n) => n > 0), sort(Array.from(result2).filter((n) => n > 0)) ) - assert.deepStrictEqual( + deepStrictEqual( Array.from(result2).filter((n) => n < 0), sort(Array.from(result2).filter((n) => n < 0)) ) @@ -689,7 +692,7 @@ describe("TPubSub", () => { return yield* $(Fiber.join(subscriber)) }) const result = await Effect.runPromise(program) - assert.deepStrictEqual(Array.from(result), as) + deepStrictEqual(Array.from(result), as) }))) it.it("unbounded - one to many", () => @@ -730,8 +733,8 @@ describe("TPubSub", () => { return { result1, result2 } }) const { result1, result2 } = await Effect.runPromise(program) - assert.deepStrictEqual(Array.from(result1), as) - assert.deepStrictEqual(Array.from(result2), as) + deepStrictEqual(Array.from(result1), as) + deepStrictEqual(Array.from(result2), as) }))) it.it("unbounded - many to many", () => @@ -787,10 +790,10 @@ describe("TPubSub", () => { return { result1, result2 } }) const { result1, result2 } = await Effect.runPromise(program) - assert.deepStrictEqual(Array.from(result1).filter((n) => n > 0), as) - assert.deepStrictEqual(Array.from(result1).filter((n) => n < 0), as.map((n) => -n)) - assert.deepStrictEqual(Array.from(result2).filter((n) => n > 0), as) - assert.deepStrictEqual(Array.from(result2).filter((n) => n < 0), as.map((n) => -n)) + deepStrictEqual(Array.from(result1).filter((n) => n > 0), as) + deepStrictEqual(Array.from(result1).filter((n) => n < 0), as.map((n) => -n)) + deepStrictEqual(Array.from(result2).filter((n) => n > 0), as) + deepStrictEqual(Array.from(result2).filter((n) => n < 0), as.map((n) => -n)) }))) it.effect("unbounded - undefined/null values", () => @@ -828,8 +831,8 @@ describe("TPubSub", () => { yield* $(pipe(as, Effect.forEach((n) => pipe(pubsub, TPubSub.publish(n))), Effect.fork)) const result1 = yield* $(Fiber.join(subscriber1)) const result2 = yield* $(Fiber.join(subscriber2)) - assert.deepStrictEqual(result1, as) - assert.deepStrictEqual(result2, as) + deepStrictEqual(result1, as) + deepStrictEqual(result2, as) })) it.effect("bounded - undefined/null values", () => @@ -867,8 +870,8 @@ describe("TPubSub", () => { yield* $(pipe(as, Effect.forEach((n) => pipe(pubsub, TPubSub.publish(n))), Effect.fork)) const result1 = yield* $(Fiber.join(subscriber1)) const result2 = yield* $(Fiber.join(subscriber2)) - assert.deepStrictEqual(result1, as) - assert.deepStrictEqual(result2, as) + deepStrictEqual(result1, as) + deepStrictEqual(result2, as) })) it.effect("dropping - undefined/null values", () => @@ -895,6 +898,6 @@ describe("TPubSub", () => { yield* $(Deferred.await(deferred)) yield* $(pipe(as, Effect.forEach((n) => pipe(pubsub, TPubSub.publish(n))), Effect.fork)) const result = yield* $(Fiber.join(subscriber)) - assert.deepStrictEqual(result, as.slice(0, n)) + deepStrictEqual(result, as.slice(0, n)) })) }) diff --git a/packages/effect/test/TQueue.test.ts b/packages/effect/test/TQueue.test.ts index f06ef33770b..4856eb1f9ac 100644 --- a/packages/effect/test/TQueue.test.ts +++ b/packages/effect/test/TQueue.test.ts @@ -1,17 +1,14 @@ -import * as Effect from "effect/Effect" -import { pipe } from "effect/Function" -import * as Option from "effect/Option" -import * as STM from "effect/STM" +import { Effect, pipe, STM, TQueue } from "effect" +import { assertFalse, assertNone, assertSome, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import * as TQueue from "effect/TQueue" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("TQueue", () => { it.effect("bounded", () => Effect.gen(function*($) { const capacity = 5 const result = yield* $(pipe(TQueue.bounded(capacity), STM.map(TQueue.capacity))) - assert.strictEqual(result, capacity) + strictEqual(result, capacity) })) it.effect("unbounded", () => @@ -21,7 +18,7 @@ describe("TQueue", () => { STM.map(TQueue.capacity), STM.commit )) - assert.strictEqual(result, Number.MAX_SAFE_INTEGER) + strictEqual(result, Number.MAX_SAFE_INTEGER) })) it.effect("offer & take", () => @@ -33,9 +30,9 @@ describe("TQueue", () => { const result1 = yield* $(TQueue.take(queue)) const result2 = yield* $(TQueue.take(queue)) const result3 = yield* $(TQueue.take(queue)) - assert.strictEqual(result1, 1) - assert.strictEqual(result2, 2) - assert.strictEqual(result3, 3) + strictEqual(result1, 1) + strictEqual(result2, 2) + strictEqual(result3, 3) })) it.effect("offer & take undefined", () => @@ -45,8 +42,8 @@ describe("TQueue", () => { yield* $(pipe(queue, TQueue.offer(undefined))) const result1 = yield* $(TQueue.take(queue)) const result2 = yield* $(TQueue.take(queue)) - assert.strictEqual(result1, undefined) - assert.strictEqual(result2, undefined) + strictEqual(result1, undefined) + strictEqual(result2, undefined) })) it.effect("offerAll & takeAll", () => @@ -55,7 +52,7 @@ describe("TQueue", () => { const queue = yield* $(TQueue.bounded(5)) yield* $(pipe(queue, TQueue.offerAll(array))) const result = yield* $(TQueue.takeAll(queue)) - assert.deepStrictEqual(Array.from(result), array) + deepStrictEqual(Array.from(result), array) })) it.effect("takeUpTo", () => @@ -64,8 +61,8 @@ describe("TQueue", () => { yield* $(pipe(queue, TQueue.offerAll([1, 2, 3, 4, 5]))) const result = yield* $(pipe(queue, TQueue.takeUpTo(3))) const size = yield* $(TQueue.size(queue)) - assert.deepStrictEqual(Array.from(result), [1, 2, 3]) - assert.strictEqual(size, 2) + deepStrictEqual(Array.from(result), [1, 2, 3]) + strictEqual(size, 2) })) it.effect("takeUpTo - larger than queue", () => @@ -75,8 +72,8 @@ describe("TQueue", () => { yield* $(pipe(queue, TQueue.offerAll(array))) const result = yield* $(pipe(queue, TQueue.takeUpTo(7))) const size = yield* $(TQueue.size(queue)) - assert.deepStrictEqual(Array.from(result), array) - assert.strictEqual(size, 0) + deepStrictEqual(Array.from(result), array) + strictEqual(size, 0) })) it.effect("poll", () => @@ -84,7 +81,7 @@ describe("TQueue", () => { const queue = yield* $(TQueue.bounded(5)) yield* $(pipe(queue, TQueue.offerAll([1, 2, 3]))) const result = yield* $(TQueue.poll(queue)) - assert.deepStrictEqual(result, Option.some(1)) + assertSome(result, 1) })) it.effect("poll undefined", () => @@ -92,14 +89,14 @@ describe("TQueue", () => { const queue = yield* $(TQueue.bounded(5)) yield* $(pipe(queue, TQueue.offerAll([undefined, undefined, undefined]))) const result = yield* $(TQueue.poll(queue)) - assert.deepStrictEqual(result, Option.some(undefined)) + assertSome(result, undefined) })) it.effect("poll - empty queue", () => Effect.gen(function*($) { const queue = yield* $(TQueue.bounded(5)) const result = yield* $(TQueue.poll(queue)) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("seek", () => @@ -108,8 +105,8 @@ describe("TQueue", () => { yield* $(pipe(queue, TQueue.offerAll([1, 2, 3, 4, 5]))) const result = yield* $(pipe(queue, TQueue.seek((n) => n === 3))) const size = yield* $(TQueue.size(queue)) - assert.strictEqual(result, 3) - assert.strictEqual(size, 2) + strictEqual(result, 3) + strictEqual(size, 2) })) it.effect("size", () => @@ -117,7 +114,7 @@ describe("TQueue", () => { const queue = yield* $(TQueue.unbounded()) yield* $(pipe(queue, TQueue.offerAll([1, 2, 3, 4, 5]))) const result = yield* $(TQueue.size(queue)) - assert.strictEqual(result, 5) + strictEqual(result, 5) })) it.effect("peek", () => @@ -126,8 +123,8 @@ describe("TQueue", () => { yield* $(pipe(queue, TQueue.offerAll([1, 2, 3, 4, 5]))) const result = yield* $(TQueue.peek(queue)) const size = yield* $(TQueue.size(queue)) - assert.strictEqual(result, 1) - assert.strictEqual(size, 5) + strictEqual(result, 1) + strictEqual(size, 5) })) it.effect("peekOption", () => @@ -136,15 +133,15 @@ describe("TQueue", () => { yield* $(pipe(queue, TQueue.offerAll([1, 2, 3, 4, 5]))) const result = yield* $(TQueue.peekOption(queue)) const size = yield* $(TQueue.size(queue)) - assert.deepStrictEqual(result, Option.some(1)) - assert.strictEqual(size, 5) + assertSome(result, 1) + strictEqual(size, 5) })) it.effect("peekOption - empty queu", () => Effect.gen(function*($) { const queue = yield* $(TQueue.unbounded()) const result = yield* $(TQueue.peekOption(queue)) - assert.deepStrictEqual(result, Option.none()) + assertNone(result) })) it.effect("isEmpty", () => @@ -154,8 +151,8 @@ describe("TQueue", () => { yield* $(pipe(queue1, TQueue.offerAll([1, 2, 3, 4, 5]))) const result1 = yield* $(TQueue.isEmpty(queue1)) const result2 = yield* $(TQueue.isEmpty(queue2)) - assert.isFalse(result1) - assert.isTrue(result2) + assertFalse(result1) + assertTrue(result2) })) it.effect("isFull", () => @@ -165,7 +162,7 @@ describe("TQueue", () => { yield* $(pipe(queue1, TQueue.offerAll([1, 2, 3, 4, 5]))) const result1 = yield* $(TQueue.isFull(queue1)) const result2 = yield* $(TQueue.isFull(queue2)) - assert.isTrue(result1) - assert.isFalse(result2) + assertTrue(result1) + assertFalse(result2) })) }) diff --git a/packages/effect/test/TRandom.test.ts b/packages/effect/test/TRandom.test.ts index 84dcdaf3613..117c147270f 100644 --- a/packages/effect/test/TRandom.test.ts +++ b/packages/effect/test/TRandom.test.ts @@ -1,10 +1,11 @@ import * as Effect from "effect/Effect" import { pipe } from "effect/Function" import * as STM from "effect/STM" +import { assertTrue } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TRandom from "effect/TRandom" import * as fc from "fast-check" -import { assert, describe } from "vitest" +import { describe } from "vitest" const floatsArb: fc.Arbitrary = fc.tuple( fc.float({ noDefaultInfinity: true, noNaN: true }), @@ -25,8 +26,8 @@ describe("TRandom", () => { Effect.provide(TRandom.live), Effect.runPromise ) - assert.isAtLeast(result, min) - assert.isBelow(result, max) + assertTrue(result >= min) + assertTrue(result < max) }))) it.it("nextRange - generates numbers in the specified range", () => @@ -36,7 +37,7 @@ describe("TRandom", () => { Effect.provide(TRandom.live), Effect.runPromise ) - assert.isAtLeast(result, min) - assert.isBelow(result, max) + assertTrue(result >= min) + assertTrue(result < max) }))) }) diff --git a/packages/effect/test/TReentrantLock.test.ts b/packages/effect/test/TReentrantLock.test.ts index 3a46a09a1d3..dc9e25c9560 100644 --- a/packages/effect/test/TReentrantLock.test.ts +++ b/packages/effect/test/TReentrantLock.test.ts @@ -7,9 +7,10 @@ import * as Option from "effect/Option" import * as Ref from "effect/Ref" import * as Schedule from "effect/Schedule" import * as STM from "effect/STM" +import { assertNone, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TReentrantLock from "effect/TReentrantLock" -import { assert, describe } from "vitest" +import { describe } from "vitest" const pollSchedule = (): Schedule.Schedule>, Option.Option>> => pipe( @@ -31,7 +32,7 @@ describe("TReentrantLock", () => { Effect.flatMap(Effect.succeed), Effect.scoped )) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("two read locks from the same fiber", () => @@ -48,7 +49,7 @@ describe("TReentrantLock", () => { ), Effect.scoped )) - assert.strictEqual(result, 2) + strictEqual(result, 2) })) it.effect("two read locks from different fibers", () => @@ -85,7 +86,7 @@ describe("TReentrantLock", () => { )) yield* $(Deferred.await(wLatch)) const result = yield* $(Fiber.join(fiber)) - assert.strictEqual(result, 1) + strictEqual(result, 1) })) it.effect("one write lock, then one read lock, different fibers", () => @@ -126,9 +127,9 @@ describe("TReentrantLock", () => { )) yield* $(pipe(wLatch, Deferred.succeed(void 0))) const readerCount = yield* $(Fiber.join(fiber)) - assert.strictEqual(locks, 1) - assert.deepStrictEqual(option, Option.none()) - assert.strictEqual(readerCount, 1) + strictEqual(locks, 1) + assertNone(option) + strictEqual(readerCount, 1) })) it.effect("write lock followed by read lock from the same fiber", () => @@ -153,8 +154,8 @@ describe("TReentrantLock", () => { Effect.scoped )) const writerCount = yield* $(Ref.get(ref)) - assert.strictEqual(readerCount, 1) - assert.strictEqual(writerCount, 1) + strictEqual(readerCount, 1) + strictEqual(writerCount, 1) })) it.effect("upgrade read lock to write lock from the same fiber", () => @@ -179,8 +180,8 @@ describe("TReentrantLock", () => { Effect.scoped )) const writerCount = yield* $(Ref.get(ref)) - assert.strictEqual(readerCount, 1) - assert.strictEqual(writerCount, 1) + strictEqual(readerCount, 1) + strictEqual(writerCount, 1) })) it.effect("read to writer upgrade with other readers", () => @@ -225,7 +226,7 @@ describe("TReentrantLock", () => { const option = yield* $(pipe(Fiber.poll(fiber), Effect.repeat(pollSchedule()))) yield* $(pipe(rLatch, Deferred.succeed(void 0))) const count = yield* $(Fiber.join(fiber)) - assert.deepStrictEqual(option, Option.none()) - assert.strictEqual(count, 1) + assertNone(option) + strictEqual(count, 1) })) }) diff --git a/packages/effect/test/TSet.test.ts b/packages/effect/test/TSet.test.ts index 6b3b4a19909..ddb6782fe09 100644 --- a/packages/effect/test/TSet.test.ts +++ b/packages/effect/test/TSet.test.ts @@ -2,9 +2,10 @@ import * as Chunk from "effect/Chunk" import * as Effect from "effect/Effect" import { pipe } from "effect/Function" import * as STM from "effect/STM" +import { assertFalse, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TSet from "effect/TSet" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("TSet", () => { it.effect("add - new element", () => @@ -15,7 +16,7 @@ describe("TSet", () => { STM.flatMap(TSet.toReadonlySet) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, new Set([1])) + deepStrictEqual(result, new Set([1])) })) it.effect("add - duplicate element", () => @@ -26,7 +27,7 @@ describe("TSet", () => { STM.flatMap(TSet.toReadonlySet) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, new Set([1])) + deepStrictEqual(result, new Set([1])) })) it.effect("difference", () => @@ -38,7 +39,7 @@ describe("TSet", () => { return yield* $(TSet.toArray(set1)) }) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [2, 3]) + deepStrictEqual(result, [2, 3]) })) it.effect("empty", () => @@ -48,7 +49,7 @@ describe("TSet", () => { STM.flatMap(TSet.isEmpty) ) const result = yield* $(STM.commit(transaction)) - assert.isTrue(result) + assertTrue(result) })) it.effect("fromIterable", () => @@ -58,7 +59,7 @@ describe("TSet", () => { STM.flatMap(TSet.toReadonlySet) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, new Set([1, 2, 3])) + deepStrictEqual(result, new Set([1, 2, 3])) })) it.effect("has - existing element", () => @@ -68,7 +69,7 @@ describe("TSet", () => { STM.flatMap(TSet.has(1)) ) const result = yield* $(STM.commit(transaction)) - assert.isTrue(result) + assertTrue(result) })) it.effect("has - non-existing element", () => @@ -78,7 +79,7 @@ describe("TSet", () => { STM.flatMap(TSet.has(1)) ) const result = yield* $(STM.commit(transaction)) - assert.isFalse(result) + assertFalse(result) })) it.effect("intersection", () => @@ -90,7 +91,7 @@ describe("TSet", () => { return yield* $(TSet.toArray(set1)) }) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [1]) + deepStrictEqual(result, [1]) })) it.effect("make", () => @@ -100,7 +101,7 @@ describe("TSet", () => { STM.flatMap(TSet.toReadonlySet) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, new Set([1, 2, 3])) + deepStrictEqual(result, new Set([1, 2, 3])) })) it.effect("reduce - non-empty set", () => @@ -110,7 +111,7 @@ describe("TSet", () => { STM.flatMap(TSet.reduce(0, (x, y) => x + y)) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 6) + strictEqual(result, 6) })) it.effect("reduce - empty set", () => @@ -120,7 +121,7 @@ describe("TSet", () => { STM.flatMap(TSet.reduce(0, (x, y) => x + y)) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("reduceSTM - non-empty set", () => @@ -130,7 +131,7 @@ describe("TSet", () => { STM.flatMap(TSet.reduceSTM(0, (x, y) => STM.succeed(x + y))) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 6) + strictEqual(result, 6) })) it.effect("reduceSTM - empty set", () => @@ -140,7 +141,7 @@ describe("TSet", () => { STM.flatMap(TSet.reduceSTM(0, (x, y) => STM.succeed(x + y))) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 0) + strictEqual(result, 0) })) it.effect("remove - existing element", () => @@ -151,7 +152,7 @@ describe("TSet", () => { STM.flatMap(TSet.toReadonlySet) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, new Set([2])) + deepStrictEqual(result, new Set([2])) })) it.effect("remove - non-existing element", () => @@ -162,7 +163,7 @@ describe("TSet", () => { STM.flatMap(TSet.toReadonlySet) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, new Set([1, 2])) + deepStrictEqual(result, new Set([1, 2])) })) it.effect("retainIf", () => @@ -176,7 +177,7 @@ describe("TSet", () => { return [Array.from(removed), a, aa, aaa] }) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [["aaa", "a"], false, true, false]) + deepStrictEqual(result, [["aaa", "a"], false, true, false]) })) it.effect("retainIf > { discard: true }", () => @@ -190,7 +191,7 @@ describe("TSet", () => { return [a, aa, aaa] }) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [false, true, false]) + deepStrictEqual(result, [false, true, false]) })) it.effect("removeIf", () => @@ -204,7 +205,7 @@ describe("TSet", () => { return [Array.from(removed), a, aa, aaa] }) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [["aa"], true, false, true]) + deepStrictEqual(result, [["aa"], true, false, true]) })) it.effect("removeIf > { discard: true }", () => @@ -218,7 +219,7 @@ describe("TSet", () => { return [a, aa, aaa] }) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [true, false, true]) + deepStrictEqual(result, [true, false, true]) })) it.effect("transform", () => @@ -229,7 +230,7 @@ describe("TSet", () => { STM.flatMap(TSet.toArray) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [2, 4, 6]) + deepStrictEqual(result, [2, 4, 6]) })) it.effect("transform - and shrink", () => @@ -240,7 +241,7 @@ describe("TSet", () => { STM.flatMap(TSet.toArray) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [1]) + deepStrictEqual(result, [1]) })) it.effect("transformSTM", () => @@ -251,7 +252,7 @@ describe("TSet", () => { STM.flatMap(TSet.toArray) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [2, 4, 6]) + deepStrictEqual(result, [2, 4, 6]) })) it.effect("transformSTM - and shrink", () => @@ -262,7 +263,7 @@ describe("TSet", () => { STM.flatMap(TSet.toArray) ) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [1]) + deepStrictEqual(result, [1]) })) it.effect("size", () => @@ -272,7 +273,7 @@ describe("TSet", () => { STM.flatMap(TSet.size) ) const result = yield* $(STM.commit(transaction)) - assert.strictEqual(result, 4) + strictEqual(result, 4) })) it.effect("union", () => @@ -284,7 +285,7 @@ describe("TSet", () => { return yield* $(TSet.toArray(set1)) }) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, [1, 2, 3, 4, 5]) + deepStrictEqual(result, [1, 2, 3, 4, 5]) })) it.effect("toChunk", () => @@ -294,6 +295,6 @@ describe("TSet", () => { return yield* $(TSet.toChunk(set)) }) const result = yield* $(STM.commit(transaction)) - assert.deepStrictEqual(result, Chunk.make(1, 2, 3)) + deepStrictEqual(result, Chunk.make(1, 2, 3)) })) }) diff --git a/packages/effect/test/TSubscriptionRef.test.ts b/packages/effect/test/TSubscriptionRef.test.ts index 2cc54e89b92..324bc89b909 100644 --- a/packages/effect/test/TSubscriptionRef.test.ts +++ b/packages/effect/test/TSubscriptionRef.test.ts @@ -1,8 +1,9 @@ import { Chunk, Deferred, Effect, Equal, Exit, Fiber, pipe, Random, STM, Stream } from "effect" import * as Number from "effect/Number" +import { assertTrue, deepStrictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" import * as TSubscriptionRef from "effect/TSubscriptionRef" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe.concurrent("TSubscriptionRef", () => { it.effect("only emits comitted values", () => @@ -26,7 +27,7 @@ describe.concurrent("TSubscriptionRef", () => { yield* $(Effect.yieldNow()) const result = yield* $(Fiber.join(subscriber)) - assert.deepStrictEqual(Array.from(result), [2]) + deepStrictEqual(Array.from(result), [2]) })) it.effect("emits every comitted value", () => @@ -52,7 +53,7 @@ describe.concurrent("TSubscriptionRef", () => { yield* $(transaction) const result = yield* $(Fiber.join(subscriber)) - assert.deepStrictEqual(Array.from(result), [1, 2]) + deepStrictEqual(Array.from(result), [1, 2]) })) it.effect("multiple subscribers can receive committed values", () => @@ -80,8 +81,8 @@ describe.concurrent("TSubscriptionRef", () => { yield* $(TSubscriptionRef.update(subscriptionRef, (n) => n + 1)) const result1 = yield* $(Fiber.join(subscriber1)) const result2 = yield* $(Fiber.join(subscriber2)) - assert.deepStrictEqual(Array.from(result1), [0, 1, 2]) - assert.deepStrictEqual(Array.from(result2), [1, 2]) + deepStrictEqual(Array.from(result1), [0, 1, 2]) + deepStrictEqual(Array.from(result2), [1, 2]) })) it.effect("subscriptions are interruptible", () => @@ -109,8 +110,8 @@ describe.concurrent("TSubscriptionRef", () => { yield* $(TSubscriptionRef.update(ref, (n) => n + 1)) const result1 = yield* $(Fiber.interrupt(subscriber1)) const result2 = yield* $(Fiber.join(subscriber2)) - assert.isTrue(Exit.isInterrupted(result1)) - assert.deepStrictEqual(Array.from(result2), [1, 2]) + assertTrue(Exit.isInterrupted(result1)) + deepStrictEqual(Array.from(result2), [1, 2]) })) it.effect("concurrent subscribes and unsubscribes are handled correctly", () => @@ -143,6 +144,6 @@ describe.concurrent("TSubscriptionRef", () => { ) yield* $(Fiber.interrupt(fiber)) const isSorted = Chunk.every(result, (chunk) => Equal.equals(chunk, Chunk.sort(chunk, Number.Order))) - assert.isTrue(isSorted) + assertTrue(isSorted) })) }) diff --git a/packages/effect/test/Tracer.test.ts b/packages/effect/test/Tracer.test.ts index 3d99d47eb5b..68af7cc9573 100644 --- a/packages/effect/test/Tracer.test.ts +++ b/packages/effect/test/Tracer.test.ts @@ -1,25 +1,47 @@ -import { Cause, Tracer } from "effect" -import * as Context from "effect/Context" -import { millis, seconds } from "effect/Duration" -import * as Effect from "effect/Effect" -import * as Fiber from "effect/Fiber" -import * as FiberId from "effect/FiberId" +import { Cause, Context, Duration, Effect, Fiber, FiberId, Layer, Option, TestClock, Tracer } from "effect" import type { NativeSpan } from "effect/internal/tracer" -import * as Layer from "effect/Layer" -import * as Option from "effect/Option" +import { assertNone, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util" import * as it from "effect/test/utils/extend" -import * as TestClock from "effect/TestClock" import type { Span } from "effect/Tracer" -import { assert, describe } from "vitest" +import { describe } from "vitest" describe("Tracer", () => { + it.effect("includes trace when errored", () => + Effect.gen(function*() { + let maybeSpan: undefined | Span + const getSpan = Effect.functionWithSpan({ + body: (_id: string) => + Effect.currentSpan.pipe(Effect.flatMap((span) => { + maybeSpan = span + return Effect.fail("error") + })), + options: (id) => ({ + name: `span-${id}`, + attributes: { id } + }) + }) + yield* Effect.flip(getSpan("fail")) + assertTrue(maybeSpan !== undefined) + assertTrue((maybeSpan!.attributes.get("code.stacktrace") as string).includes("Tracer.test.ts:23:26")) + })) + + it.effect("captures stack", () => + Effect.gen(function*() { + const cause = yield* Effect.die(new Error("boom")).pipe( + Effect.withSpan("C", { context: Tracer.DisablePropagation.context(true) }), + Effect.sandbox, + Effect.flip + ) + assertTrue(Cause.pretty(cause).includes("Tracer.test.ts:30:39")) + })) + describe("withSpan", () => { it.effect("no parent", () => Effect.gen(function*() { const span = yield* Effect.withSpan("A")(Effect.currentSpan) - assert.deepEqual(span.name, "A") - assert.deepEqual(span.parent, Option.none()) - assert.strictEqual(span.attributes.get("code.stacktrace"), undefined) + deepStrictEqual(span.name, "A") + assertNone(span.parent) + strictEqual(span.attributes.get("code.stacktrace"), undefined) })) it.effect("parent", () => @@ -30,8 +52,8 @@ describe("Tracer", () => { ) ) - assert.deepEqual(span.name, "A") - assert.deepEqual(Option.map(span.parent, (span) => (span as Span).name), Option.some("B")) + deepStrictEqual(span.name, "A") + deepStrictEqual(Option.map(span.parent, (span) => (span as Span).name), Option.some("B")) })) it.effect("parent when root is set", () => @@ -40,8 +62,8 @@ describe("Tracer", () => { Effect.withSpan("B")(Effect.withSpan("A", { root: true })(Effect.currentSpan)) ) - assert.deepEqual(span.name, "A") - assert.deepEqual(span.parent, Option.none()) + deepStrictEqual(span.name, "A") + assertNone(span.parent) })) it.effect("external parent", () => @@ -57,24 +79,24 @@ describe("Tracer", () => { } })(Effect.currentSpan) ) - assert.deepEqual(span.name, "A") - assert.deepEqual(Option.map(span.parent, (span) => span.spanId), Option.some("000")) + deepStrictEqual(span.name, "A") + deepStrictEqual(Option.map(span.parent, (span) => span.spanId), Option.some("000")) })) it.effect("correct time", () => Effect.gen(function*($) { const spanFiber = yield* $( - Effect.fork(Effect.withSpan("A")(Effect.delay(seconds(1))(Effect.currentSpan))) + Effect.fork(Effect.withSpan("A")(Effect.delay(Duration.seconds(1))(Effect.currentSpan))) ) - yield* $(TestClock.adjust(seconds(2))) + yield* $(TestClock.adjust(Duration.seconds(2))) const span = yield* $(Fiber.join(spanFiber)) - assert.deepEqual(span.name, "A") - assert.deepEqual(span.status.startTime, 0n) - assert.deepEqual((span.status as any)["endTime"], 1000000000n) - assert.deepEqual(span.status._tag, "Ended") + deepStrictEqual(span.name, "A") + deepStrictEqual(span.status.startTime, 0n) + deepStrictEqual((span.status as any)["endTime"], 1000000000n) + deepStrictEqual(span.status._tag, "Ended") })) }) @@ -88,9 +110,9 @@ describe("Tracer", () => { ) ) - assert.deepEqual(span.name, "A") - assert.deepEqual(span.parent, Option.none()) - assert.deepEqual(span.attributes.get("key"), "value") + deepStrictEqual(span.name, "A") + assertNone(span.parent) + deepStrictEqual(span.attributes.get("key"), "value") })) it.effect("annotateSpans record", () => @@ -102,13 +124,13 @@ describe("Tracer", () => { ) ) - assert.deepEqual(span.attributes.get("key"), "value") - assert.deepEqual(span.attributes.get("key2"), "value2") + deepStrictEqual(span.attributes.get("key"), "value") + deepStrictEqual(span.attributes.get("key2"), "value2") })) it.effect("logger", () => Effect.gen(function*($) { - yield* $(TestClock.adjust(millis(0.01))) + yield* $(TestClock.adjust(Duration.millis(0.01))) const [span, fiberId] = yield* $( Effect.log("event"), @@ -116,9 +138,9 @@ describe("Tracer", () => { Effect.withSpan("A") ) - assert.deepEqual(span.name, "A") - assert.deepEqual(span.parent, Option.none()) - assert.deepEqual((span as NativeSpan).events, [["event", 10000n, { + deepStrictEqual(span.name, "A") + assertNone(span.parent) + deepStrictEqual((span as NativeSpan).events, [["event", 10000n, { "effect.fiberId": FiberId.threadName(fiberId), "effect.logLevel": "INFO" }]]) @@ -126,28 +148,28 @@ describe("Tracer", () => { it.effect("withTracerTiming false", () => Effect.gen(function*($) { - yield* $(TestClock.adjust(millis(1))) + yield* $(TestClock.adjust(Duration.millis(1))) const span = yield* $( Effect.withSpan("A")(Effect.currentSpan), Effect.withTracerTiming(false) ) - assert.deepEqual(span.status.startTime, 0n) + deepStrictEqual(span.status.startTime, 0n) })) it.effect("useSpanScoped", () => Effect.gen(function*() { const span = yield* Effect.scoped(Effect.makeSpanScoped("A")) - assert.deepEqual(span.status._tag, "Ended") - assert.strictEqual(span.attributes.get("code.stacktrace"), undefined) + deepStrictEqual(span.status._tag, "Ended") + strictEqual(span.attributes.get("code.stacktrace"), undefined) })) it.effect("annotateCurrentSpan", () => Effect.gen(function*(_) { yield* _(Effect.annotateCurrentSpan("key", "value")) const span = yield* _(Effect.currentSpan) - assert.deepEqual(span.attributes.get("key"), "value") + deepStrictEqual(span.attributes.get("key"), "value") }).pipe( Effect.withSpan("A") )) @@ -155,7 +177,7 @@ describe("Tracer", () => { it.effect("withParentSpan", () => Effect.gen(function*(_) { const span = yield* _(Effect.currentSpan) - assert.deepEqual( + deepStrictEqual( span.parent.pipe( Option.map((_) => _.spanId) ), @@ -176,9 +198,9 @@ describe("Tracer", () => { Effect.gen(function*() { const span = yield* Effect.makeSpan("child") const parent = yield* Option.filter(span.parent, (span): span is Span => span._tag === "Span") - assert.deepEqual(parent.name, "parent") - assert.strictEqual(span.attributes.get("code.stacktrace"), undefined) - assert.strictEqual(parent.attributes.get("code.stacktrace"), undefined) + deepStrictEqual(parent.name, "parent") + strictEqual(span.attributes.get("code.stacktrace"), undefined) + strictEqual(parent.attributes.get("code.stacktrace"), undefined) }).pipe( Effect.provide(Layer.unwrapScoped( Effect.map( @@ -195,8 +217,8 @@ describe("Tracer", () => { Option.filter((span): span is Span => span._tag === "Span"), Option.getOrThrow ) - assert.strictEqual(parent.name, "parent") - assert.strictEqual(parent.attributes.get("code.stacktrace"), undefined) + strictEqual(parent.name, "parent") + strictEqual(parent.attributes.get("code.stacktrace"), undefined) }).pipe( Effect.provide(Layer.span("parent")) )) @@ -209,13 +231,13 @@ describe("Tracer", () => { Effect.provide(Layer.span("span", { onEnd: (span, _exit) => Effect.sync(() => { - assert.strictEqual(span.name, "span") + strictEqual(span.name, "span") onEndCalled = true }) })) ) - assert.strictEqual(span.name, "span") - assert.strictEqual(onEndCalled, true) + strictEqual(span.name, "span") + strictEqual(onEndCalled, true) })) it.effect("linkSpans", () => @@ -227,9 +249,9 @@ describe("Tracer", () => { Effect.withSpan("A", { links: [{ _tag: "SpanLink", span: childB, attributes: {} }] }), Effect.linkSpans(childA) ) - assert.includeMembers( + deepStrictEqual( currentSpan.links.map((_) => _.span), - [childB, childA] + [childA, childB] ) })) @@ -238,13 +260,13 @@ describe("Tracer", () => { let onEndCalled = false const layer = Layer.effectDiscard(Effect.gen(function*() { const span = yield* Effect.currentSpan - assert.strictEqual(span.name, "span") - assert.strictEqual(span.attributes.get("code.stacktrace"), undefined) + strictEqual(span.name, "span") + strictEqual(span.attributes.get("code.stacktrace"), undefined) })).pipe( Layer.withSpan("span", { onEnd: (span, _exit) => Effect.sync(() => { - assert.strictEqual(span.name, "span") + strictEqual(span.name, "span") onEndCalled = true }) }) @@ -252,8 +274,8 @@ describe("Tracer", () => { const span = yield* _(Effect.currentSpan, Effect.provide(layer), Effect.option) - assert.deepEqual(span, Option.none()) - assert.strictEqual(onEndCalled, true) + assertNone(span) + strictEqual(onEndCalled, true) })) }) @@ -270,9 +292,9 @@ it.effect("withTracerEnabled", () => Effect.withTracerEnabled(true) ) - assert.deepEqual(span.name, "A") - assert.deepEqual(span.spanId, "noop") - assert.deepEqual(spanB.name, "B") + deepStrictEqual(span.name, "A") + deepStrictEqual(span.spanId, "noop") + deepStrictEqual(spanB.name, "B") })) describe("Tracer.DisablePropagation", () => { @@ -285,19 +307,9 @@ describe("Tracer.DisablePropagation", () => { Effect.withSpan("B") ) - assert.deepEqual(span.name, "A") - assert.deepEqual(span.spanId, "noop") - assert.deepEqual(spanB.name, "B") - })) - - it.effect("captures stack", () => - Effect.gen(function*() { - const cause = yield* Effect.die(new Error("boom")).pipe( - Effect.withSpan("C", { context: Tracer.DisablePropagation.context(true) }), - Effect.sandbox, - Effect.flip - ) - assert.include(Cause.pretty(cause), "Tracer.test.ts:295") + deepStrictEqual(span.name, "A") + deepStrictEqual(span.spanId, "noop") + deepStrictEqual(spanB.name, "B") })) it.effect("isnt used as parent span", () => @@ -307,31 +319,12 @@ describe("Tracer.DisablePropagation", () => { Effect.withSpan("disabled", { context: Tracer.DisablePropagation.context(true) }), Effect.withSpan("parent") ) - assert.strictEqual(span.name, "child") - assert(span.parent._tag === "Some" && span.parent.value._tag === "Span") - assert.strictEqual(span.parent.value.name, "parent") + strictEqual(span.name, "child") + assertTrue(span.parent._tag === "Some" && span.parent.value._tag === "Span") + strictEqual(span.parent.value.name, "parent") })) }) -it.effect("includes trace when errored", () => - Effect.gen(function*() { - let maybeSpan: undefined | Span - const getSpan = Effect.functionWithSpan({ - body: (_id: string) => - Effect.currentSpan.pipe(Effect.flatMap((span) => { - maybeSpan = span - return Effect.fail("error") - })), - options: (id) => ({ - name: `span-${id}`, - attributes: { id } - }) - }) - yield* Effect.flip(getSpan("fail")) - assert.isDefined(maybeSpan) - assert.include(maybeSpan!.attributes.get("code.stacktrace"), "Tracer.test.ts:330:24") - })) - describe("functionWithSpan", () => { const getSpan = Effect.functionWithSpan({ body: (_id: string) => Effect.currentSpan, @@ -344,15 +337,15 @@ describe("functionWithSpan", () => { it.effect("no parent", () => Effect.gen(function*() { const span = yield* getSpan("A") - assert.deepEqual(span.name, "span-A") - assert.deepEqual(span.parent, Option.none()) - assert.strictEqual(span.attributes.get("code.stacktrace"), undefined) + deepStrictEqual(span.name, "span-A") + assertNone(span.parent) + strictEqual(span.attributes.get("code.stacktrace"), undefined) })) it.effect("parent", () => Effect.gen(function*() { const span = yield* Effect.withSpan("B")(getSpan("A")) - assert.deepEqual(span.name, "span-A") - assert.deepEqual(Option.map(span.parent, (span) => (span as Span).name), Option.some("B")) + deepStrictEqual(span.name, "span-A") + deepStrictEqual(Option.map(span.parent, (span) => (span as Span).name), Option.some("B")) })) }) diff --git a/packages/effect/test/Trie.test.ts b/packages/effect/test/Trie.test.ts index 3861db10585..b1a23c59158 100644 --- a/packages/effect/test/Trie.test.ts +++ b/packages/effect/test/Trie.test.ts @@ -1,9 +1,9 @@ import * as Equal from "effect/Equal" import { pipe } from "effect/Function" import * as Option from "effect/Option" -import { deepStrictEqual } from "effect/test/util" +import { assertNone, assertSome, deepStrictEqual, strictEqual, throws } from "effect/test/util" import * as Trie from "effect/Trie" -import { assert, describe, expect, it } from "vitest" +import { describe, it } from "vitest" describe("Trie", () => { it("toString", () => { @@ -13,7 +13,9 @@ describe("Trie", () => { Trie.insert("b", 1) ) - expect(String(trie)).toEqual(`{ + strictEqual( + String(trie), + `{ "_id": "Trie", "values": [ [ @@ -25,7 +27,8 @@ describe("Trie", () => { 1 ] ] -}`) +}` + ) }) it("toJSON", () => { @@ -35,9 +38,7 @@ describe("Trie", () => { Trie.insert("b", 1) ) - expect(trie.toJSON()).toEqual( - { _id: "Trie", values: [["a", 0], ["b", 1]] } - ) + deepStrictEqual(trie.toJSON(), { _id: "Trie", values: [["a", 0], ["b", 1]] }) }) it("inspect", () => { @@ -53,13 +54,13 @@ describe("Trie", () => { Trie.insert("b", 1) ) - expect(inspect(trie)).toEqual(inspect({ _id: "Trie", values: [["a", 0], ["b", 1]] })) + deepStrictEqual(inspect(trie), inspect({ _id: "Trie", values: [["a", 0], ["b", 1]] })) }) it("iterable empty", () => { const trie = pipe(Trie.empty()) - assert.equal(Trie.size(trie), 0) + strictEqual(Trie.size(trie), 0) deepStrictEqual(Array.from(trie), []) }) @@ -87,14 +88,14 @@ describe("Trie", () => { it("make", () => { const trie = Trie.make(["ca", 0], ["me", 1]) deepStrictEqual(Array.from(trie), [["ca", 0], ["me", 1]]) - assert.equal(Equal.equals(Trie.fromIterable([["ca", 0], ["me", 1]]), trie), true) + strictEqual(Equal.equals(Trie.fromIterable([["ca", 0], ["me", 1]]), trie), true) }) it("fromIterable [1]", () => { const iterable: Array<[string, number]> = [["ca", 0], ["me", 1]] const trie = Trie.fromIterable(iterable) deepStrictEqual(Array.from(trie), iterable) - assert.equal(Equal.equals(Trie.make(["ca", 0], ["me", 1]), trie), true) + strictEqual(Equal.equals(Trie.make(["ca", 0], ["me", 1]), trie), true) }) it("fromIterable [2]", () => { @@ -127,14 +128,14 @@ describe("Trie", () => { Trie.insert("b", 1) ) - assert.equal(Trie.size(trie), 2) + strictEqual(Trie.size(trie), 2) }) it("isEmpty", () => { const trie = Trie.empty() const trie1 = trie.pipe(Trie.insert("ma", 0)) - assert.equal(Trie.isEmpty(trie), true) - assert.equal(Trie.isEmpty(trie1), false) + strictEqual(Trie.isEmpty(trie), true) + strictEqual(Trie.isEmpty(trie1), false) }) it("get [1]", () => { @@ -144,14 +145,14 @@ describe("Trie", () => { Trie.insert("mind", 2), Trie.insert("mid", 3) ) - deepStrictEqual(Trie.get(trie, "call"), Option.some(0)) - deepStrictEqual(Trie.get(trie, "me"), Option.some(1)) - deepStrictEqual(Trie.get(trie, "mind"), Option.some(2)) - deepStrictEqual(Trie.get(trie, "mid"), Option.some(3)) - deepStrictEqual(Trie.get(trie, "cale"), Option.none()) - deepStrictEqual(Trie.get(trie, "ma"), Option.none()) - deepStrictEqual(Trie.get(trie, "midn"), Option.none()) - deepStrictEqual(Trie.get(trie, "mea"), Option.none()) + assertSome(Trie.get(trie, "call"), 0) + assertSome(Trie.get(trie, "me"), 1) + assertSome(Trie.get(trie, "mind"), 2) + assertSome(Trie.get(trie, "mid"), 3) + assertNone(Trie.get(trie, "cale")) + assertNone(Trie.get(trie, "ma")) + assertNone(Trie.get(trie, "midn")) + assertNone(Trie.get(trie, "mea")) }) it("get [2]", () => { @@ -161,10 +162,10 @@ describe("Trie", () => { Trie.insert("she", 2) ) - deepStrictEqual(Trie.get(trie, "sell"), Option.none()) - deepStrictEqual(Trie.get(trie, "sells"), Option.some(1)) - deepStrictEqual(Trie.get(trie, "shell"), Option.none()) - deepStrictEqual(Trie.get(trie, "she"), Option.some(2)) + assertNone(Trie.get(trie, "sell")) + assertSome(Trie.get(trie, "sells"), 1) + assertNone(Trie.get(trie, "shell")) + assertSome(Trie.get(trie, "she"), 2) }) it("has", () => { @@ -174,14 +175,14 @@ describe("Trie", () => { Trie.insert("mind", 2), Trie.insert("mid", 3) ) - assert.equal(Trie.has(trie, "call"), true) - assert.equal(Trie.has(trie, "me"), true) - assert.equal(Trie.has(trie, "mind"), true) - assert.equal(Trie.has(trie, "mid"), true) - assert.equal(Trie.has(trie, "cale"), false) - assert.equal(Trie.has(trie, "ma"), false) - assert.equal(Trie.has(trie, "midn"), false) - assert.equal(Trie.has(trie, "mea"), false) + strictEqual(Trie.has(trie, "call"), true) + strictEqual(Trie.has(trie, "me"), true) + strictEqual(Trie.has(trie, "mind"), true) + strictEqual(Trie.has(trie, "mid"), true) + strictEqual(Trie.has(trie, "cale"), false) + strictEqual(Trie.has(trie, "ma"), false) + strictEqual(Trie.has(trie, "midn"), false) + strictEqual(Trie.has(trie, "mea"), false) }) it("unsafeGet", () => { @@ -189,7 +190,7 @@ describe("Trie", () => { Trie.insert("call", 0), Trie.insert("me", 1) ) - assert.throws(() => Trie.unsafeGet(trie, "mae")) + throws(() => Trie.unsafeGet(trie, "mae")) }) it("remove", () => { @@ -377,8 +378,8 @@ describe("Trie", () => { Trie.insert("she", 3) ) - assert.equal(Equal.equals(Trie.map(trie, (v) => v + 1), trieMapV), true) - assert.equal(Equal.equals(Trie.map(trie, (_, k) => k.length), trieMapK), true) + strictEqual(Equal.equals(Trie.map(trie, (v) => v + 1), trieMapV), true) + strictEqual(Equal.equals(Trie.map(trie, (_, k) => k.length), trieMapK), true) }) it("filter", () => { @@ -397,8 +398,8 @@ describe("Trie", () => { Trie.insert("sells", 1) ) - assert.equal(Equal.equals(Trie.filter(trie, (v) => v > 1), trieMapV), true) - assert.equal(Equal.equals(Trie.filter(trie, (_, k) => k.length > 3), trieMapK), true) + strictEqual(Equal.equals(Trie.filter(trie, (v) => v > 1), trieMapV), true) + strictEqual(Equal.equals(Trie.filter(trie, (_, k) => k.length > 3), trieMapK), true) }) it("filterMap", () => { @@ -417,8 +418,8 @@ describe("Trie", () => { Trie.insert("sells", 1) ) - assert.equal(Equal.equals(Trie.filterMap(trie, (v) => v > 1 ? Option.some(v) : Option.none()), trieMapV), true) - assert.equal( + strictEqual(Equal.equals(Trie.filterMap(trie, (v) => v > 1 ? Option.some(v) : Option.none()), trieMapV), true) + strictEqual( Equal.equals(Trie.filterMap(trie, (v, k) => k.length > 3 ? Option.some(v) : Option.none()), trieMapK), true ) @@ -436,7 +437,7 @@ describe("Trie", () => { Trie.insert("she", 2) ) - assert.equal(Equal.equals(Trie.compact(trie), trieMapV), true) + strictEqual(Equal.equals(Trie.compact(trie), trieMapV), true) }) it("modify", () => { @@ -447,7 +448,7 @@ describe("Trie", () => { ) deepStrictEqual(trie.pipe(Trie.modify("she", (v) => v + 10), Trie.get("she")), Option.some(12)) - assert.equal(Equal.equals(trie.pipe(Trie.modify("me", (v) => v)), trie), true) + strictEqual(Equal.equals(trie.pipe(Trie.modify("me", (v) => v)), trie), true) }) it("removeMany", () => { @@ -457,7 +458,7 @@ describe("Trie", () => { Trie.insert("she", 2) ) - assert.equal( + strictEqual( Equal.equals(trie.pipe(Trie.removeMany(["she", "sells"])), Trie.empty().pipe(Trie.insert("shells", 0))), true ) @@ -477,7 +478,7 @@ describe("Trie", () => { ) ) - assert.equal( + strictEqual( Equal.equals(trie, trieInsert), true ) @@ -490,19 +491,19 @@ describe("Trie", () => { Trie.insert("she", 2) ) - assert.equal( + strictEqual( trie.pipe( Trie.reduce(0, (acc, n) => acc + n) ), 3 ) - assert.equal( + strictEqual( trie.pipe( Trie.reduce(10, (acc, n) => acc + n) ), 13 ) - assert.equal( + strictEqual( trie.pipe( Trie.reduce("", (acc, _, key) => acc + key) ), @@ -522,15 +523,15 @@ describe("Trie", () => { }) ) - assert.equal(value, 17) + strictEqual(value, 17) }) it("Equal.symbol", () => { - assert.equal( + strictEqual( Equal.equals(Trie.empty(), Trie.empty()), true ) - assert.equal( + strictEqual( Equal.equals( Trie.make(["call", 0], ["me", 1]), Trie.make(["call", 0], ["me", 1]) diff --git a/packages/effect/test/Tuple.test.ts b/packages/effect/test/Tuple.test.ts index 1af9d900800..427f1da3e75 100644 --- a/packages/effect/test/Tuple.test.ts +++ b/packages/effect/test/Tuple.test.ts @@ -1,45 +1,43 @@ -import { pipe } from "effect/Function" -import * as T from "effect/Tuple" -import { describe, expect, it } from "vitest" +import { pipe, Tuple } from "effect" +import { deepStrictEqual, strictEqual } from "effect/test/util" +import { describe, it } from "vitest" describe("Tuple", () => { - it("exports", () => { - expect(T.getOrder).exist - expect(T.getEquivalence).exist - }) - it("make", () => { - expect(T.make("a", 1, true)).toEqual(["a", 1, true]) + deepStrictEqual(Tuple.make("a", 1, true), ["a", 1, true]) }) it("appendElement", () => { - expect(pipe(T.make("a", 1), T.appendElement(true))).toEqual(["a", 1, true]) + deepStrictEqual(pipe(Tuple.make("a", 1), Tuple.appendElement(true)), ["a", 1, true]) }) it("getFirst", () => { - expect(T.getFirst(T.make("a", 1))).toEqual("a") + strictEqual(Tuple.getFirst(Tuple.make("a", 1)), "a") }) it("getSecond", () => { - expect(T.getSecond(T.make("a", 1))).toEqual(1) + strictEqual(Tuple.getSecond(Tuple.make("a", 1)), 1) }) it("mapBoth", () => { - expect(T.mapBoth(T.make("a", 1), { - onFirst: (s) => s + "!", - onSecond: (n) => n * 2 - })).toEqual(["a!", 2]) + deepStrictEqual( + Tuple.mapBoth(Tuple.make("a", 1), { + onFirst: (s) => s + "!", + onSecond: (n) => n * 2 + }), + ["a!", 2] + ) }) it("map", () => { - expect(T.map(["a", 1, false], (x) => x.toString().toUpperCase())).toEqual(["A", "1", "FALSE"]) + deepStrictEqual(Tuple.map(["a", 1, false], (x) => x.toString().toUpperCase()), ["A", "1", "FALSE"]) }) it("swap", () => { - expect(T.swap(T.make("a", 1))).toEqual([1, "a"]) + deepStrictEqual(Tuple.swap(Tuple.make("a", 1)), [1, "a"]) }) it("at", () => { - expect(T.at([1, "hello", true], 1)).toEqual("hello") + deepStrictEqual(Tuple.at([1, "hello", true], 1), "hello") }) }) diff --git a/packages/effect/test/util.ts b/packages/effect/test/util.ts index e6a92004809..aa12863a3c6 100644 --- a/packages/effect/test/util.ts +++ b/packages/effect/test/util.ts @@ -1,22 +1,87 @@ -import { assert } from "vitest" +import type { Cause } from "effect" +import { Either, Equal, Exit, Option, Predicate } from "effect" +import * as assert from "node:assert" -export const assertTrue = (self: boolean) => { +export const fail = assert.fail + +export function assertTrue(self: unknown, ..._: Array): asserts self { assert.strictEqual(self, true) } -export const assertFalse = (self: boolean) => { +export const assertFalse = (self: boolean, ..._: Array) => { assert.strictEqual(self, false) } -export const deepStrictEqual = (actual: A, expected: A) => { +export const deepStrictEqual = (actual: A, expected: A, ..._: Array) => { assert.deepStrictEqual(actual, expected) } -export const strictEqual = (actual: A, expected: A) => { - assert.strictEqual(actual, expected) +export const notDeepStrictEqual = (actual: A, expected: A, ..._: Array) => { + assert.notDeepStrictEqual(actual, expected) +} + +export const strictEqual = (actual: A, expected: A, message?: string, ..._: Array) => { + assert.strictEqual(actual, expected, message) +} + +export const equals = (actual: A, expected: A, ..._: Array) => { + if (!Equal.equals(actual, expected)) { + deepStrictEqual(actual, expected) // show diff + assert.fail("should be equal") + } +} + +export const doesNotThrow = (thunk: () => void, ..._: Array) => { + assert.doesNotThrow(thunk) +} + +export const throws = (thunk: () => void, error?: object | ((e: unknown) => boolean), ..._: Array) => { + try { + thunk() + assert.fail("expected to throw an error") + } catch (e) { + if (error !== undefined) { + if (Predicate.isFunction(error)) { + assertTrue(error(e)) + } else { + deepStrictEqual(e, error) + } + } + } +} + +// ---------------------------- +// Option +// ---------------------------- + +export const assertNone = (option: Option.Option, ..._: Array) => { + deepStrictEqual(option, Option.none()) +} + +export const assertSome = (option: Option.Option, expected: A, ..._: Array) => { + deepStrictEqual(option, Option.some(expected)) } -export const double = (n: number): number => n * 2 +// ---------------------------- +// Either +// ---------------------------- -export const ownKeys = (o: object): ReadonlyArray => - (Object.keys(o) as ReadonlyArray).concat(Object.getOwnPropertySymbols(o)) +export const assertLeft = (either: Either.Either, expected: L, ..._: Array) => { + deepStrictEqual(either, Either.left(expected)) +} + +export const assertRight = (either: Either.Either, expected: R, ..._: Array) => { + deepStrictEqual(either, Either.right(expected)) +} + +// ---------------------------- +// Exit +// ---------------------------- + +export const assertFailure = (exit: Exit.Exit, expected: Cause.Cause, ..._: Array) => { + deepStrictEqual(exit, Exit.failCause(expected)) +} + +export const assertSuccess = (exit: Exit.Exit, expected: A, ..._: Array) => { + deepStrictEqual(exit, Exit.succeed(expected)) +} diff --git a/packages/effect/test/utils/cache/ObservableResource.ts b/packages/effect/test/utils/cache/ObservableResource.ts index b07fb7d4491..601273ba5e2 100644 --- a/packages/effect/test/utils/cache/ObservableResource.ts +++ b/packages/effect/test/utils/cache/ObservableResource.ts @@ -3,7 +3,7 @@ import * as ExecutionStrategy from "effect/ExecutionStrategy" import { pipe } from "effect/Function" import * as Ref from "effect/Ref" import * as Scope from "effect/Scope" -import { expect } from "vitest" +import { strictEqual } from "effect/test/util" export interface ObservableResource { readonly scoped: Effect.Effect @@ -20,22 +20,22 @@ class ObservableResourceImpl implements ObservableResource { assertNotAcquired(): Effect.Effect { return Effect.map(this.getState, ([numAcquisition, numCleaned]) => { - expect(numAcquisition, "Resource acquired when it should not have").toBe(0) - expect(numCleaned, "Resource cleaned when it should not have").toBe(0) + strictEqual(numAcquisition, 0, "Resource acquired when it should not have") + strictEqual(numCleaned, 0, "Resource cleaned when it should not have") }) } assertAcquiredOnceAndCleaned(): Effect.Effect { return Effect.map(this.getState, ([numAcquisition, numCleaned]) => { - expect(numAcquisition, "Resource not acquired once").toBe(1) - expect(numCleaned, "Resource not cleaned when it should have").toBe(1) + strictEqual(numAcquisition, 1, "Resource not acquired once") + strictEqual(numCleaned, 1, "Resource not cleaned when it should have") }) } assertAcquiredOnceAndNotCleaned(): Effect.Effect { return Effect.map(this.getState, ([numAcquisition, numCleaned]) => { - expect(numAcquisition, "Resource not acquired once").toBe(1) - expect(numCleaned, "Resource cleaned when it should not have").toBe(0) + strictEqual(numAcquisition, 1, "Resource not acquired once") + strictEqual(numCleaned, 0, "Resource cleaned when it should not have") }) } } diff --git a/packages/effect/test/utils/cache/WatchableLookup.ts b/packages/effect/test/utils/cache/WatchableLookup.ts index dd81edff208..3fa48dcecb9 100644 --- a/packages/effect/test/utils/cache/WatchableLookup.ts +++ b/packages/effect/test/utils/cache/WatchableLookup.ts @@ -7,9 +7,9 @@ import * as Option from "effect/Option" import * as Ref from "effect/Ref" import * as Schedule from "effect/Schedule" import type * as Scope from "effect/Scope" +import { assertTrue } from "effect/test/util" import * as ObservableResource from "effect/test/utils/cache/ObservableResource" import * as TestServices from "effect/TestServices" -import { expect } from "vitest" export interface WatchableLookup { (key: Key): Effect.Effect @@ -121,7 +121,7 @@ export const makeEffect = ( Effect.isSuccess, Effect.map((isSuccess) => acc || isSuccess) )), - Effect.map((atLeastOneNotCleaned) => Effect.sync(() => expect(atLeastOneNotCleaned).toBe(true))) + Effect.map((atLeastOneNotCleaned) => Effect.sync(() => assertTrue(atLeastOneNotCleaned))) ) }) return Object.assign(lookup, { diff --git a/packages/effect/vitest.config.ts b/packages/effect/vitest.config.ts index c97c0d37009..df4cfb5a4b3 100644 --- a/packages/effect/vitest.config.ts +++ b/packages/effect/vitest.config.ts @@ -2,12 +2,12 @@ import { mergeConfig, type UserConfigExport } from "vitest/config" import shared from "../../vitest.shared.js" const config: UserConfigExport = { - // test: { - // coverage: { - // reporter: ["html"], - // include: ["src/Cause.ts", "src/internal/cause.ts"] - // } - // } + test: { + coverage: { + reporter: ["html"], + include: ["src/**/*ts"] + } + } } export default mergeConfig(shared, config)