Skip to content

Commit

Permalink
remove assert
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Jan 29, 2025
1 parent ef145d3 commit c6a32ea
Show file tree
Hide file tree
Showing 63 changed files with 779 additions and 722 deletions.
39 changes: 20 additions & 19 deletions packages/effect/test/Sink/collecting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () =>
Expand All @@ -15,7 +16,7 @@ describe("Sink", () => {
Stream.transduce(Sink.collectAllN<number>(3))
)
const result = yield* $(Stream.runCollect(stream))
assert.deepStrictEqual(
deepStrictEqual(
Array.from(Chunk.map(result, (chunk) => Array.from(chunk))),
[[1, 2, 3], [4]]
)
Expand All @@ -28,7 +29,7 @@ describe("Sink", () => {
Stream.transduce(Sink.collectAllN<number>(4))
)
const result = yield* $(Stream.runCollect(stream))
assert.deepStrictEqual(
deepStrictEqual(
Array.from(Chunk.map(result, (chunk) => Array.from(chunk))),
[[1, 2, 3, 4], []]
)
Expand All @@ -41,7 +42,7 @@ describe("Sink", () => {
Stream.transduce(Sink.collectAllN<number>(3))
)
const result = yield* $(Stream.runCollect(stream))
assert.deepStrictEqual(
deepStrictEqual(
Array.from(Chunk.map(result, (chunk) => Array.from(chunk))),
[[]]
)
Expand All @@ -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", () =>
Expand All @@ -61,7 +62,7 @@ describe("Sink", () => {
Stream.transduce(Sink.collectAllToSetN<number>(3))
)
const result = yield* $(Stream.runCollect(stream))
assert.deepStrictEqual(
deepStrictEqual(
Array.from(Chunk.map(result, (set) => Array.from(set))),
[[1, 2, 3], [4]]
)
Expand All @@ -74,7 +75,7 @@ describe("Sink", () => {
Stream.transduce(Sink.collectAllToSetN<number>(3))
)
const result = yield* $(Stream.runCollect(stream))
assert.deepStrictEqual(
deepStrictEqual(
Array.from(Chunk.map(result, (set) => Array.from(set))),
[[]]
)
Expand All @@ -89,7 +90,7 @@ describe("Sink", () => {
(x, y) => x + y
))
)
assert.deepStrictEqual(
deepStrictEqual(
Array.from(result),
[[0, 18], [1, 12], [2, 15]]
)
Expand All @@ -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]]]
)
Expand All @@ -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]]]
)
Expand All @@ -140,7 +141,7 @@ describe("Sink", () => {
)),
Stream.runCollect
)
assert.deepStrictEqual(
deepStrictEqual(
Array.from(Chunk.map(result, (chunk) => Array.from(chunk))),
[[]]
)
Expand All @@ -156,7 +157,7 @@ describe("Sink", () => {
Chunk.empty<number>()
)
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]]
)
Expand All @@ -172,7 +173,7 @@ describe("Sink", () => {
Chunk.empty<number>()
)
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]]
)
Expand All @@ -191,7 +192,7 @@ describe("Sink", () => {
Chunk.empty<number>()
)
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]]
)
Expand All @@ -210,7 +211,7 @@ describe("Sink", () => {
Chunk.empty<number>()
)
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]]
)
Expand All @@ -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", () =>
Expand All @@ -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])
}))
})
17 changes: 9 additions & 8 deletions packages/effect/test/Sink/constructors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () =>
Expand All @@ -25,22 +26,22 @@ 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", () =>
Effect.gen(function*($) {
const queue = yield* $(Queue.unbounded<number>())
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", () =>
Expand All @@ -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", () =>
Expand All @@ -74,15 +75,15 @@ 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", () =>
Effect.gen(function*($) {
const pubsub = yield* $(PubSub.unbounded<number>())
yield* $(Stream.make(1, 2, 3), Stream.run(Sink.fromPubSub(pubsub, { shutdown: true })))
const isShutdown = yield* $(PubSub.isShutdown(pubsub))
assert.isTrue(isShutdown)
assertTrue(isShutdown)
}))
})

Expand Down
15 changes: 8 additions & 7 deletions packages/effect/test/Sink/dropping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () =>
Expand All @@ -13,7 +14,7 @@ describe("Sink", () => {
Stream.pipeThrough(Sink.dropUntil<number>((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", () =>
Expand All @@ -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", () =>
Expand All @@ -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", () =>
Expand All @@ -46,7 +47,7 @@ describe("Sink", () => {
Stream.pipeThrough(Sink.dropWhile<number>((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", () =>
Expand All @@ -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", () =>
Expand All @@ -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")])
}))
})
19 changes: 10 additions & 9 deletions packages/effect/test/Sink/elements.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,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 { 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", () =>
Expand All @@ -16,7 +17,7 @@ describe("Sink", () => {
Stream.fromChunk(chunk),
Stream.run(Sink.every(predicate))
)
assert.isTrue(result)
assertTrue(result)
}))

it.effect("head", () =>
Expand All @@ -25,7 +26,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))
deepStrictEqual(result, Option.some(1))
}))

it.effect("last", () =>
Expand All @@ -34,7 +35,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))
deepStrictEqual(result, Option.some(5))
}))

it.effect("take - repeats until the source is exhausted", () =>
Expand All @@ -49,7 +50,7 @@ describe("Sink", () => {
),
Stream.run(Sink.collectAllFrom(Sink.take<number>(3)))
)
assert.deepStrictEqual(
deepStrictEqual(
Array.from(result).map((chunk) => Array.from(chunk)),
[[1, 2, 3], [4, 5, 6], [7, 8, 9], []]
)
Expand All @@ -63,7 +64,7 @@ describe("Sink", () => {
Stream.fromChunk(chunk),
Stream.run(Sink.some(predicate))
)
assert.isTrue(result)
assertTrue(result)
}))

it.effect("sum", () =>
Expand All @@ -81,7 +82,7 @@ describe("Sink", () => {
Sink.map(Chunk.reduce(0, (x, y) => x + y))
))
)
assert.strictEqual(result, 45)
strictEqual(result, 45)
}))

it.effect("take", () =>
Expand All @@ -105,11 +106,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)))
)
Expand Down
5 changes: 3 additions & 2 deletions packages/effect/test/Sink/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () =>
Expand All @@ -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")
}))
})
Loading

0 comments on commit c6a32ea

Please sign in to comment.