-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=anyhow.test.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import test from "ava"; | ||
import { AnyHow } from "./index.js"; | ||
test("Sink error", (t) => { | ||
const anyhowErr = AnyHow.msg("Hi"); | ||
const wrappedErr = anyhowErr.wrapWith(() => "Context"); | ||
t.is(wrappedErr.toString(), ["Hi", "Context"].join("\n")); | ||
}); | ||
test("Separated context", (t) => { | ||
const anyhowErr = AnyHow.msg("Hi"); | ||
const wrappedErr = anyhowErr.wrapWith(() => "Context"); | ||
const a = wrappedErr.wrapWith(() => "a"); | ||
const b = wrappedErr.wrapWith(() => "b"); | ||
t.is(wrappedErr.toString(), ["Hi", "Context"].join("\n")); | ||
t.is(a.toString(), ["Hi", "Context", "a"].join("\n")); | ||
t.is(b.toString(), ["Hi", "Context", "b"].join("\n")); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=dependency.test.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import test from "ava"; | ||
import { Err, Ok } from "./result/index.js"; | ||
import { NewOption, None, Some } from "./option/index.js"; | ||
import { OptionFrom, OptionTo, ResultFrom, ResultTo, } from "./convert/result-option.js"; | ||
test(`Circular dependencies resolving`, (t) => { | ||
// Apis | ||
t.true(NewOption.Some(3) | ||
.do(OptionTo.ok(() => 4)) | ||
.eq(Ok(3))); | ||
t.true(Err(3).do(ResultTo.option()).eq(None())); | ||
// Froms | ||
t.true(OptionFrom.result(Err(3)).eq(None())); | ||
t.true(ResultFrom.ok(Some(3), () => 4).eq(Ok(3))); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=all.test.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import test from "ava"; | ||
import { Iter } from "../index.js"; | ||
import { all } from "./all.js"; | ||
test(`all() truthy if everything valid`, (t) => { | ||
const numbers = Iter.from([1, 2, 3, 4]); | ||
t.true(numbers.do(all((v) => typeof v === "number"))); | ||
}); | ||
test(`all() falsy if at least one is invalid`, (t) => { | ||
const firstInvalid = Iter.from(["1", 2, 3, 4]); | ||
const middleInvalid = Iter.from([1, "2", 3, 4]); | ||
const lastInvalid = Iter.from([1, 2, 3, "4"]); | ||
const isNumber = all((v) => typeof v === "number"); | ||
t.false(firstInvalid.do(isNumber)); | ||
t.false(middleInvalid.do(isNumber)); | ||
t.false(lastInvalid.do(isNumber)); | ||
}); | ||
test(`all() truthy on empty sets`, (t) => { | ||
const notAllNumbers = Iter.from([]); | ||
t.true(notAllNumbers.do(all((_) => false))); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=any.test.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import test from "ava"; | ||
import { Iter } from "../index.js"; | ||
import { any } from "./any.js"; | ||
test(`any() falsy if everything invalid`, (t) => { | ||
const numbers = Iter.from(["1", "2", "3", "4"]); | ||
t.false(numbers.do(any((v) => typeof v === "number"))); | ||
}); | ||
test(`any() truthy if at least one is valid`, (t) => { | ||
const firstValid = Iter.from([1, "2", "3", "4"]); | ||
const middleValid = Iter.from(["1", 2, "3", "4"]); | ||
const lastValid = Iter.from(["1", "2", "3", 4]); | ||
const isNumber = any((v) => typeof v === "number"); | ||
t.true(firstValid.do(isNumber)); | ||
t.true(middleValid.do(isNumber)); | ||
t.true(lastValid.do(isNumber)); | ||
}); | ||
test(`any() falsy on empty sets`, (t) => { | ||
const notAllNumbers = Iter.from([]); | ||
t.false(notAllNumbers.do(any((_) => true))); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=chain.test.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import test from "ava"; | ||
import { Iter } from "../index.js"; | ||
import { chain } from "./chain.js"; | ||
import { toArray } from "./to_array.js"; | ||
test(`chain() concats two iterables`, (t) => { | ||
const values = Iter.from([1, 2, 3]); | ||
const extraValues = [4, 5, 6]; | ||
t.deepEqual(values.do(chain(extraValues)).do(toArray()), [1, 2, 3, 4, 5, 6]); | ||
}); | ||
test(`chain() works with empty iterables`, (t) => { | ||
t.deepEqual(Iter.from([1, 2, 3]).do(chain([])).do(toArray()), [1, 2, 3]); | ||
t.deepEqual(Iter.from([]) | ||
.do(chain([1, 2, 3])) | ||
.do(toArray()), [1, 2, 3]); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=cycle.test.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import test from "ava"; | ||
import { Iter } from "../index.js"; | ||
import { cycle } from "./cycle.js"; | ||
import { NewOption } from "../../option/index.js"; | ||
test(`cycle() creates repeated iterator from non-empty iterators`, (t) => { | ||
const iter = Iter.from([1, 2]).do(cycle()); | ||
for (const _ of [1, 2, 3, 4, 5]) { | ||
t.true(NewOption.Some(1).eq(iter.next())); | ||
t.true(NewOption.Some(2).eq(iter.next())); | ||
} | ||
}); | ||
test(`cycle() creates empty iterator from empty iterator`, (t) => { | ||
const emptyIter = Iter.from([]).do(cycle()); | ||
for (const _ of [1, 2, 3, 4, 5]) { | ||
t.true(NewOption.None().eq(emptyIter.next())); | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=enumerate.test.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import test from "ava"; | ||
import { Iter } from "../index.js"; | ||
import { enumerate } from "./enumerate.js"; | ||
test(`enumerate() does not mutate original iter`, (t) => { | ||
const numbers = [3, 4, 5, 6]; | ||
const iter = Iter.from(numbers); | ||
// Clone test: initial iter should be untouched | ||
const enumeratedIter = iter.do(enumerate()); | ||
const enumeratedValues = numbers.map((item, index) => ({ item, index })); | ||
t.deepEqual(Array.from(iter), [3, 4, 5, 6]); | ||
t.deepEqual(Array.from(enumeratedIter), enumeratedValues); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=eq.test.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import test from "ava"; | ||
import { Iter } from "../index.js"; | ||
import { eq } from "./eq.js"; | ||
test(`eq() truthy on equal iterators`, (t) => { | ||
t.true(Iter.from([1, 2]).do(eq(Iter.from([1, 2])))); | ||
t.false(Iter.from([1, 2]).do(eq(Iter.from([1, 2, 3])))); | ||
t.false(Iter.from([1, 2, 3]).do(eq(Iter.from([1, 2])))); | ||
t.false(Iter.from([1]).do(eq(Iter.from([2])))); | ||
t.true(Iter.from([]).do(eq(Iter.from([])))); | ||
}); | ||
test(`eq(by) remaps values if "by" provided`, (t) => { | ||
const iterOne = Iter.from([{ a: 1 }, { a: 2 }]); | ||
const iterTwo = Iter.from([{ a: 1 }, { a: 2 }]); | ||
const iterThree = Iter.from([{ a: 1 }, { a: 2 }, { a: 3 }]); | ||
t.true(iterOne.do(eq(iterTwo, (v) => v.a))); | ||
t.false(iterOne.do(eq(iterThree, (v) => v.a))); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=filter.test.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import test from "ava"; | ||
import { Iter } from "../index.js"; | ||
import { nativeRange } from "../iter-test-tools.js"; | ||
import { filter } from "./filter.js"; | ||
test(`filter() should return only elements that satisfy the condition`, (t) => { | ||
const evenValues = nativeRange(0, 10).filter((v) => v % 2 === 0); | ||
const oddValues = nativeRange(0, 10).filter((v) => v % 2 !== 0); | ||
const iter = Iter.fromRange(0, 10); | ||
// Clone test: initial iter should be untouched | ||
const evenIter = iter.do(filter((v) => v % 2 === 0)); | ||
const oddIter = iter.do(filter((v) => v % 2 !== 0)); | ||
t.deepEqual([...evenIter], evenValues); | ||
t.deepEqual([...oddIter], oddValues); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=filter_map.test.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import test from "ava"; | ||
import { Iter } from "../index.js"; | ||
import { nativeRange } from "../iter-test-tools.js"; | ||
import { filterMap } from "./filter_map.js"; | ||
import { NewOption } from "../../option/index.js"; | ||
test(`.filterMap()`, (t) => { | ||
const evenValues = nativeRange(0, 10).filter((v) => v % 2 === 0); | ||
const oddValues = nativeRange(0, 10).filter((v) => v % 2 !== 0); | ||
const iter = Iter.fromRange(0, 10); | ||
function even(v) { | ||
return v % 2 === 0 ? NewOption.Some(v) : NewOption.None(); | ||
} | ||
function odd(v) { | ||
return v % 2 !== 0 ? NewOption.Some(v) : NewOption.None(); | ||
} | ||
// Clone test: initial iter should be untouched | ||
const evenIter = iter.do(filterMap(even)); | ||
const oddIter = iter.do(filterMap(odd)); | ||
t.deepEqual([...evenIter], evenValues); | ||
t.deepEqual([...oddIter], oddValues); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=find.test.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import test from "ava"; | ||
import { useSpy } from "../../testutils/spy.js"; | ||
import { Iter } from "../index.js"; | ||
import { enumerate } from "./enumerate.js"; | ||
import { find } from "./find.js"; | ||
test("find() should return first element found by condition", (t) => { | ||
const condition = useSpy((v) => v.item === 2); | ||
const iter = Iter.from([1, 2, 3, 4, 2]).do(enumerate()); | ||
t.deepEqual(iter.do(find(condition.spy)).unwrap(), { item: 2, index: 1 }); | ||
t.is(condition.calledTimes(), 2); | ||
}); | ||
test("find() should return none if element not found", (t) => { | ||
const iter = Iter.from([1, 2, 3, 4, 2]); | ||
t.truthy(iter.do(find((v) => v === 7)).isNone()); | ||
}); | ||
test("find() should return none on empty iter", (t) => { | ||
const iter = Iter.from([]); | ||
t.truthy(iter.do(find((_) => true)).isNone()); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=find_map.test.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import test from "ava"; | ||
import { Iter } from "../index.js"; | ||
import { findMap } from "./find_map.js"; | ||
import { NewOption } from "../../option/index.js"; | ||
test(`.findMap()`, (t) => { | ||
const iter = Iter.fromRange(0, 10); | ||
const valueIfEq = (to) => { | ||
return (v) => { | ||
return v === to ? NewOption.Some("value") : NewOption.None(); | ||
}; | ||
}; | ||
t.true(iter.do(findMap(valueIfEq(5))).eq(NewOption.Some("value"))); | ||
t.true(iter.do(findMap(valueIfEq(100))).eq(NewOption.None())); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=first.test.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import test from "ava"; | ||
import { Iter } from "../index.js"; | ||
import { first } from "./first.js"; | ||
import { cycle } from "./cycle.js"; | ||
import { NewOption } from "../../option/index.js"; | ||
test(`first() should return first element`, (t) => { | ||
t.true(Iter.from([1, 2, 3]).do(first()).eq(NewOption.Some(1))); | ||
}); | ||
test(`first() should return none on empty iter`, (t) => { | ||
t.true(Iter.from([]).do(first()).isNone()); | ||
}); | ||
test(`first() should return first-element on infinite iter`, (t) => { | ||
t.true(Iter.from([1, 2, 3]).do(cycle()).do(first()).eq(NewOption.Some(1))); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=flat_map.test.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import test from "ava"; | ||
import { Iter } from "../index.js"; | ||
import { flatMap } from "./flat_map.js"; | ||
import { toArray } from "./to_array.js"; | ||
test(`flatMap() flattens inner iterable by 1 level`, (t) => { | ||
const iter = Iter.from([1, 2, [3]]); | ||
t.deepEqual(iter.do(flatMap((v) => [v])).do(toArray()), [1, 2, [3]]); | ||
}); | ||
test(`flatMap() flattens inner Iter`, (t) => { | ||
const iter = Iter.from([[1], [2], [3]]); | ||
t.deepEqual(iter.do(flatMap(Iter.from)).do(toArray()), [1, 2, 3]); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=flatten.test.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import test from "ava"; | ||
import { Iter } from "../index.js"; | ||
import { toArray } from "./to_array.js"; | ||
import { flatten } from "./flatten.js"; | ||
test(`flatten() flattens inner iterable`, (t) => { | ||
const iter = Iter.from([[1], [2], [3]]); | ||
t.deepEqual(iter.do(flatten()).do(toArray()), [1, 2, 3]); | ||
}); | ||
test(`flatten() flattens inner Iter`, (t) => { | ||
const iter = Iter.from([[1], [2], [3]]).do(Iter.from); | ||
t.deepEqual(iter.do(flatten()).do(toArray()), [1, 2, 3]); | ||
}); | ||
test(`flatten() works on empty iters`, (t) => { | ||
const iter = Iter.from([[1], [], [3]]); | ||
t.deepEqual(iter.do(flatten()).do(toArray()), [1, 3]); | ||
}); | ||
test(`flatten() typecheck: should work only on Iter<Iterable<T>>`, (t) => { | ||
const iter = Iter.from([[1], 2, [3]]); | ||
// @ts-expect-error | ||
iter.do(flatten()); | ||
t.pass(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=fold.test.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.