-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fromnodestream-spec
- Loading branch information
Showing
9 changed files
with
295 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import * as Ix from '../Ix'; | ||
import * as test from 'tape-async'; | ||
const { as } = Ix.AsyncIterable; | ||
const { map } = Ix.asynciterable; | ||
import { hasNext, noNext } from '../asynciterablehelpers'; | ||
|
||
test('AsyncIterable#as from non-iterable', async t => { | ||
const xs = {}; | ||
const res = as(xs); | ||
|
||
const it = res[Symbol.asyncIterator](); | ||
await hasNext(t, it, xs); | ||
await noNext(t, it); | ||
t.end(); | ||
}); | ||
|
||
test('AsyncIterable#as from string emits the string, not chars', async t => { | ||
const x = 'foo'; | ||
const res = as(x); | ||
const it = res[Symbol.asyncIterator](); | ||
await hasNext(t, it, x); | ||
await noNext(t, it); | ||
t.end(); | ||
}); | ||
|
||
test('AsyncIterable#as from promise list', async t => { | ||
const xs: Iterable<Promise<number>> = [ | ||
Promise.resolve(1), | ||
Promise.resolve(2), | ||
Promise.resolve(3) | ||
]; | ||
const res = as(xs); | ||
|
||
const it = res[Symbol.asyncIterator](); | ||
await hasNext(t, it, 1); | ||
await hasNext(t, it, 2); | ||
await hasNext(t, it, 3); | ||
await noNext(t, it); | ||
t.end(); | ||
}); | ||
|
||
async function* getData(): AsyncIterable<number> { | ||
yield 1; | ||
yield 2; | ||
yield 3; | ||
} | ||
|
||
test('AsyncIterable#as from async generator', async t => { | ||
const xs = getData(); | ||
const res = as(xs); | ||
|
||
const it = res[Symbol.asyncIterator](); | ||
await hasNext(t, it, 1); | ||
await hasNext(t, it, 2); | ||
await hasNext(t, it, 3); | ||
await noNext(t, it); | ||
t.end(); | ||
}); | ||
|
||
test('AsyncIterable#as from array/iterable', async t => { | ||
const xs = [1, 2, 3]; | ||
const res = as(xs); | ||
|
||
const it = res[Symbol.asyncIterator](); | ||
await hasNext(t, it, 1); | ||
await hasNext(t, it, 2); | ||
await hasNext(t, it, 3); | ||
await noNext(t, it); | ||
t.end(); | ||
}); | ||
|
||
test('AsyncIterable#as from array/iterable with selector', async t => { | ||
const xs = [1, 2, 3]; | ||
const res = map(as(xs), async (x, i) => x + i); | ||
|
||
const it = res[Symbol.asyncIterator](); | ||
await hasNext(t, it, 1); | ||
await hasNext(t, it, 3); | ||
await hasNext(t, it, 5); | ||
await noNext(t, it); | ||
t.end(); | ||
}); | ||
|
||
test('AsyncIterable#as from async generator with selector', async t => { | ||
const xs = getData(); | ||
const res = map(as(xs), async (x, i) => x + i); | ||
|
||
const it = res[Symbol.asyncIterator](); | ||
await hasNext(t, it, 1); | ||
await hasNext(t, it, 3); | ||
await hasNext(t, it, 5); | ||
await noNext(t, it); | ||
t.end(); | ||
}); | ||
|
||
test('AsyncIterable#as from empty array/iterable', async t => { | ||
const xs: number[] = []; | ||
const res = as(xs); | ||
|
||
const it = res[Symbol.asyncIterator](); | ||
await noNext(t, it); | ||
t.end(); | ||
}); | ||
|
||
test('AsyncIterable#as from array-like', async t => { | ||
const xs = { length: 3 }; | ||
const res = as(xs); | ||
|
||
const it = res[Symbol.asyncIterator](); | ||
await hasNext(t, it, undefined); | ||
await hasNext(t, it, undefined); | ||
await hasNext(t, it, undefined); | ||
await noNext(t, it); | ||
t.end(); | ||
}); | ||
|
||
test('AsyncIterable#as from array-like with selector', async t => { | ||
const xs = { length: 3 }; | ||
const res = map(as(xs), (x, i) => i); | ||
|
||
const it = res[Symbol.asyncIterator](); | ||
await hasNext(t, it, 0); | ||
await hasNext(t, it, 1); | ||
await hasNext(t, it, 2); | ||
await noNext(t, it); | ||
t.end(); | ||
}); | ||
|
||
test('AsyncIterable#as from promise', async t => { | ||
const xs = Promise.resolve(42); | ||
const res = as(xs); | ||
|
||
const it = res[Symbol.asyncIterator](); | ||
await hasNext(t, it, 42); | ||
await noNext(t, it); | ||
t.end(); | ||
}); | ||
|
||
test('AsyncIterable#as from promise with selector', async t => { | ||
const xs = Promise.resolve(42); | ||
const res = map(as(xs), (x, i) => x + i); | ||
|
||
const it = res[Symbol.asyncIterator](); | ||
await hasNext(t, it, 42); | ||
await noNext(t, it); | ||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import * as Ix from '../Ix'; | ||
import * as test from 'tape-async'; | ||
const { as } = Ix.Iterable; | ||
const { map } = Ix.iterable; | ||
import { hasNext, noNext } from '../iterablehelpers'; | ||
|
||
test('Iterable#as from array/iterable', t => { | ||
const xs = [1, 2, 3]; | ||
const res = as(xs); | ||
|
||
const it = res[Symbol.iterator](); | ||
hasNext(t, it, 1); | ||
hasNext(t, it, 2); | ||
hasNext(t, it, 3); | ||
noNext(t, it); | ||
t.end(); | ||
}); | ||
|
||
test('Iterable#as from array/iterable with selector', t => { | ||
const xs = [1, 2, 3]; | ||
const res = map(as(xs), (x, i) => x + i); | ||
|
||
const it = res[Symbol.iterator](); | ||
hasNext(t, it, 1); | ||
hasNext(t, it, 3); | ||
hasNext(t, it, 5); | ||
noNext(t, it); | ||
t.end(); | ||
}); | ||
|
||
test('Iterable#as from empty array/iterable', t => { | ||
const xs: number[] = []; | ||
const res = as(xs); | ||
|
||
const it = res[Symbol.iterator](); | ||
noNext(t, it); | ||
t.end(); | ||
}); | ||
|
||
test('Iterable#as from array-like', t => { | ||
const xs = { length: 3 }; | ||
const res = as(xs); | ||
|
||
const it = res[Symbol.iterator](); | ||
hasNext(t, it, undefined); | ||
hasNext(t, it, undefined); | ||
hasNext(t, it, undefined); | ||
noNext(t, it); | ||
t.end(); | ||
}); | ||
|
||
test('Iterable#as from array-like with selector', t => { | ||
const xs = { length: 3 }; | ||
const res = map(as(xs), (x, i) => i); | ||
|
||
const it = res[Symbol.iterator](); | ||
hasNext(t, it, 0); | ||
hasNext(t, it, 1); | ||
hasNext(t, it, 2); | ||
noNext(t, it); | ||
t.end(); | ||
}); | ||
|
||
test('Iterable#as from non-iterable', t => { | ||
const xs = {}; | ||
const res = as(xs); | ||
|
||
const it = res[Symbol.iterator](); | ||
hasNext(t, it, xs); | ||
noNext(t, it); | ||
t.end(); | ||
}); | ||
|
||
test('Iterable#as from non-iterable with selector', t => { | ||
const xs = {}; | ||
const res = map(as(xs), (x, i) => [x, i]); | ||
|
||
const it = res[Symbol.iterator](); | ||
hasNext(t, it, [xs, 0]); | ||
noNext(t, it); | ||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.