Skip to content

Commit

Permalink
Add concrete types; reorganize.
Browse files Browse the repository at this point in the history
  • Loading branch information
conartist6 authored Aug 19, 2018
1 parent 1ae82f4 commit 312a596
Show file tree
Hide file tree
Showing 53 changed files with 1,991 additions and 1,035 deletions.
4 changes: 3 additions & 1 deletion .babelrc
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"
]
}
}
}
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ root = true
end_of_line = lf
insert_final_newline = true

[{*.{js,mjs,d.ts,json}, .babelrc}]
[*.{js,mjs,d.ts,json,babelrc}]
charset = utf-8
indent_style = space
indent_size = 2
46 changes: 46 additions & 0 deletions jest_setup.js
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,
};
},
});
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "sequins",
"version": "0.0.1",
"description": "An object oriented wrapper for iterators, a la Immutable.Seq",
"main": "lib/index",
"scripts": {
"build": "broccoli build lib --overwrite"
"build": "broccoli build lib --overwrite",
"test": "jest"
},
"repository": {
"type": "git",
Expand All @@ -29,19 +29,25 @@
"homepage": "https://github.com/conartist6/sequins#readme",
"devDependencies": {
"@babel/core": "^7.0.0-beta.54",
"@babel/plugin-transform-classes": "^7.0.0-beta.54",
"@babel/plugin-transform-modules-commonjs": "^7.0.0-beta.54",
"@babel/preset-env": "^7.0.0-beta.54",
"babel-core": "^7.0.0-beta.41",
"babel-jest": "^23.4.0",
"babel-plugin-transform-builtin-extend": "^1.1.2",
"broccoli": "^2.0.0-beta.2",
"jest": "^23.4.1"
},
"dependencies": {
"iter-tools": "^4.1.1",
"memoizee": "^0.4.12"
"invariant": "^2.2.4",
"iter-tools": "^6.0.0",
"memoizee": "^0.4.12",
"stable": "^0.1.8"
},
"jest": {
"moduleFileExtensions": [
"js"
]
],
"setupTestFrameworkScriptFile": "<rootDir>/jest_setup.js"
}
}
64 changes: 64 additions & 0 deletions src/__test__/collection-indexed.test.js
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');
74 changes: 74 additions & 0 deletions src/__test__/collection-keyed.test.js
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');
63 changes: 63 additions & 0 deletions src/__test__/collection-set.test.js
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');
Loading

0 comments on commit 312a596

Please sign in to comment.