-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ae82f4
commit 312a596
Showing
53 changed files
with
1,991 additions
and
1,035 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
{ | ||
"env": { | ||
"test": { | ||
"plugins": ["@babel/plugin-transform-modules-commonjs"] | ||
"plugins": [ | ||
"@babel/plugin-transform-modules-commonjs" | ||
] | ||
} | ||
} | ||
} |
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,46 @@ | ||
import { equals } from 'expect/build/jasmine_utils'; | ||
|
||
expect.extend({ | ||
toBeIterable(received, argument) { | ||
let pass = Symbol.iterator in received; | ||
|
||
if (pass && argument && typeof argument.asymmetricMatch === 'function') { | ||
return { pass: argument.asymmetricMatch(received[Symbol.iterator]()), message: () => 'meh' }; | ||
} | ||
|
||
return { | ||
message: () => | ||
this.utils.matcherHint(`${pass ? '.not' : ''}.toBeIterable`) + | ||
'\n\n' + | ||
`expected${ | ||
pass ? ' not' : '' | ||
} to find a [Symbol.iterator] property, but Symbol.iterator was:\n` + | ||
` ${this.utils.printReceived(received)}`, | ||
pass, | ||
}; | ||
}, | ||
|
||
yields(received, ...args) { | ||
let pass = args.reduce((pass, arg) => { | ||
return pass && arg === received.next().value; | ||
}, true); | ||
const done = received.next(); | ||
pass = pass && done.done; | ||
return { | ||
message: () => `Didn't do the thing.`, | ||
pass, | ||
}; | ||
}, | ||
|
||
yieldsEqual(received, ...args) { | ||
let pass = args.reduce((pass, arg) => { | ||
return pass && equals(arg, received.next().value); | ||
}, true); | ||
const done = received.next(); | ||
pass = pass && done.done; | ||
return { | ||
message: () => `Didn't do the thing.`, | ||
pass, | ||
}; | ||
}, | ||
}); |
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,64 @@ | ||
import makeTestMethod from './helpers/make-test-method'; | ||
import IndexedSequence from '../subtypes/sequence/indexed'; | ||
import SequinsList from '../subtypes/concrete/list'; | ||
import testData from './data'; | ||
|
||
function makeTests(IndexedConstructor, description) { | ||
describe(description, function() { | ||
let indexed; | ||
|
||
const { keys, values, entries, calls, array } = testData.Indexed; | ||
|
||
const testMethod = makeTestMethod(IndexedConstructor); | ||
|
||
beforeEach(function() { | ||
indexed = new IndexedConstructor(array); | ||
}); | ||
|
||
testMethod('tap') | ||
.callback(() => null, calls) | ||
.run(tapFn => indexed.tap(tapFn)) | ||
.expectCollectionYields(array); | ||
|
||
testMethod('map') | ||
.callback(val => val + 1, calls) | ||
.run(mapFn => indexed.map(mapFn)) | ||
.expectCollectionYields([2, 3, 4]); | ||
|
||
testMethod('flatMap (IndexedSequences)') | ||
.callback(val => new IndexedSequence([val + 1, val + 1.5])) | ||
.expectCalls(calls) | ||
.run(mapFn => indexed.flatMap(mapFn)) | ||
.expectCollectionYields([2, 2.5, 3, 3.5, 4, 4.5]); | ||
|
||
testMethod('flatMap (Arrays)') | ||
.callback(val => [val + 1, val + 1.5]) | ||
.expectCalls(calls) | ||
.run(mapFn => indexed.flatMap(mapFn)) | ||
.expectCollectionYields([2, 2.5, 3, 3.5, 4, 4.5]); | ||
|
||
testMethod('filter') | ||
.callback(val => val > 1, calls) | ||
.run(filterFn => indexed.filter(filterFn)) | ||
.expectCollectionYields([2, 3]); | ||
|
||
testMethod('filterNot') | ||
.callback(val => val > 1, calls) | ||
.run(filterFn => indexed.filterNot(filterFn)) | ||
.expectCollectionYields([1]); | ||
|
||
testMethod('reduce') | ||
.callback((acc, val) => acc + val) | ||
.expectCalls([[1, 2, 1], [3, 3, 2]]) | ||
.run(reducerFn => indexed.reduce(reducerFn)) | ||
.expectReturns(6); | ||
|
||
testMethod('forEach') | ||
.callback(() => true, calls) | ||
.run(eachFn => indexed.forEach(eachFn)) | ||
.expectReturns(3); | ||
}); | ||
} | ||
|
||
makeTests(IndexedSequence, 'IndexedSequence'); | ||
makeTests(SequinsList, 'List'); |
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,74 @@ | ||
import makeTestMethod from './helpers/make-test-method'; | ||
import { KeyedSeq, Map } from '..'; | ||
import testData from './data'; | ||
|
||
function makeTests(KeyedConstructor, description) { | ||
describe(description, function() { | ||
let keyed; | ||
|
||
const { keys, values, entries, calls, array } = testData.Keyed; | ||
|
||
const testMethod = makeTestMethod(KeyedConstructor); | ||
|
||
beforeEach(function() { | ||
keyed = new KeyedConstructor(entries); | ||
}); | ||
|
||
testMethod('tap') | ||
.callback(() => null, calls) | ||
.run(tapFn => keyed.tap(tapFn)) | ||
.expectCollectionYields(entries); | ||
|
||
testMethod('map') | ||
.callback(val => val + 1, calls) | ||
.run(mapFn => keyed.map(mapFn)) | ||
.expectCollectionYields([[9, 2], [8, 3], [7, 4]]); | ||
|
||
testMethod('mapKeys') | ||
.callback(key => key - 1, entries) | ||
.run(mapFn => keyed.mapKeys(mapFn)) | ||
.expectCollectionYields([[8, 1], [7, 2], [6, 3]]); | ||
|
||
testMethod('mapEntries') | ||
.callback(([key, val]) => [val, key]) | ||
.expectCalls([[[9, 1], 0], [[8, 2], 1], [[7, 3], 2]]) | ||
.run(mapFn => keyed.mapEntries(mapFn)) | ||
.expectCollectionYields([[1, 9], [2, 8], [3, 7]]); | ||
|
||
testMethod('flatMap (KeyedSeqs)') | ||
.callback(val => new KeyedSeq([[val + 1, val + 2]])) | ||
.expectCalls(calls) | ||
.run(mapFn => keyed.flatMap(mapFn)) | ||
.expectCollectionYields([[2, 3], [3, 4], [4, 5]]); | ||
|
||
testMethod('flatMap (Maps)') | ||
.callback(val => new Map([[val + 1, val + 2]])) | ||
.expectCalls(calls) | ||
.run(mapFn => keyed.flatMap(mapFn)) | ||
.expectCollectionYields([[2, 3], [3, 4], [4, 5]]); | ||
|
||
testMethod('filter') | ||
.callback(val => val > 1, calls) | ||
.run(filterFn => keyed.filter(filterFn)) | ||
.expectCollectionYields(entries.slice(1)); | ||
|
||
testMethod('filterNot') | ||
.callback(val => val > 1, calls) | ||
.run(filterFn => keyed.filterNot(filterFn)) | ||
.expectCollectionYields(entries.slice(0, 1)); | ||
|
||
testMethod('reduce') | ||
.callback((acc, val, key) => acc + val) | ||
.expectCalls([[1, 2, 8], [3, 3, 7]]) | ||
.run(reducerFn => keyed.reduce(reducerFn)) | ||
.expectReturns(6); | ||
|
||
testMethod('forEach') | ||
.callback(() => true, calls) | ||
.run(eachFn => keyed.forEach(eachFn)) | ||
.expectReturns(3); | ||
}); | ||
} | ||
|
||
makeTests(KeyedSeq, 'KeyedSeq'); | ||
makeTests(Map, 'Map'); |
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,63 @@ | ||
import makeTestMethod from './helpers/make-test-method'; | ||
import { SetSeq, Set } from '..'; | ||
import testData from './data'; | ||
|
||
function makeTests(SetConstructor, description) { | ||
describe(description, function() { | ||
let set; | ||
|
||
const { keys, values, entries, calls, array } = testData.Set; | ||
|
||
const testMethod = makeTestMethod(SetConstructor); | ||
|
||
beforeEach(function() { | ||
set = new SetConstructor(array); | ||
}); | ||
|
||
testMethod('tap') | ||
.callback(() => null, calls) | ||
.run(tapFn => set.tap(tapFn)) | ||
.expectCollectionYields(array); | ||
|
||
testMethod('map') | ||
.callback(val => val + 1, calls) | ||
.run(mapFn => set.map(mapFn)) | ||
.expectCollectionYields([2, 3, 4]); | ||
|
||
testMethod('flatMap (SetSeqs)') | ||
.callback(val => new SetSeq([val + 1, val + 1.5])) | ||
.expectCalls(calls) | ||
.run(mapFn => set.flatMap(mapFn)) | ||
.expectCollectionYields([2, 2.5, 3, 3.5, 4, 4.5]); | ||
|
||
testMethod('flatMap (Sets)') | ||
.callback(val => new Set([val + 1, val + 1.5])) | ||
.expectCalls(calls) | ||
.run(mapFn => set.flatMap(mapFn)) | ||
.expectCollectionYields([2, 2.5, 3, 3.5, 4, 4.5]); | ||
|
||
testMethod('filter') | ||
.callback(val => val > 1, calls) | ||
.run(filterFn => set.filter(filterFn)) | ||
.expectCollectionYields([2, 3]); | ||
|
||
testMethod('filterNot') | ||
.callback(val => val > 1, calls) | ||
.run(filterFn => set.filterNot(filterFn)) | ||
.expectCollectionYields([1]); | ||
|
||
testMethod('reduce') | ||
.callback((acc, val, key) => acc + val) | ||
.expectCalls([[1, 2, 2], [3, 3, 3]]) | ||
.run(reducerFn => set.reduce(reducerFn)) | ||
.expectReturns(6); | ||
|
||
testMethod('forEach') | ||
.callback(() => true, calls) | ||
.run(eachFn => set.forEach(eachFn)) | ||
.expectReturns(3); | ||
}); | ||
} | ||
|
||
makeTests(SetSeq, 'SetSeq'); | ||
makeTests(Set, 'Set'); |
Oops, something went wrong.