Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add ramda placeholder and make tests consistent #1328

Merged
merged 2 commits into from Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions test/padCharsStart.js
Expand Up @@ -60,7 +60,7 @@ describe('padCharsStart', function() {
});
});

specify('should curry', function() {
specify('should be curried', function() {
assert.strictEqual(RA.padCharsStart('-', 5, 'abc'), '--abc');
assert.strictEqual(RA.padCharsStart('-', 5)('abc'), '--abc');
assert.strictEqual(RA.padCharsStart('-')(5, 'abc'), '--abc');
Expand Down Expand Up @@ -133,7 +133,7 @@ describe('padCharsStart', function() {
});
});

specify('should curry', function() {
specify('should be curried', function() {
assert.strictEqual(padStartInvoker('-', 5, 'abc'), '--abc');
assert.strictEqual(padStartInvoker('-', 5)('abc'), '--abc');
assert.strictEqual(padStartInvoker('-')(5, 'abc'), '--abc');
Expand Down Expand Up @@ -201,7 +201,7 @@ describe('padCharsStart', function() {
});
});

specify('should curry', function() {
specify('should be curried', function() {
assert.strictEqual(padStartPolyfill('-', 5, 'abc'), '--abc');
assert.strictEqual(padStartPolyfill('-', 5)('abc'), '--abc');
assert.strictEqual(padStartPolyfill('-')(5, 'abc'), '--abc');
Expand Down
2 changes: 1 addition & 1 deletion test/padEnd.js
Expand Up @@ -40,7 +40,7 @@ describe('padEnd', function() {
});
});

specify('should curry', function() {
specify('should be curried', function() {
assert.strictEqual(RA.padEnd(5, 'abc'), 'abc ');
assert.strictEqual(RA.padEnd(5)('abc'), 'abc ');
});
Expand Down
2 changes: 1 addition & 1 deletion test/padStart.js
Expand Up @@ -40,7 +40,7 @@ describe('padStart', function() {
});
});

it('should curry', function() {
it('should be curried', function() {
assert.strictEqual(RA.padStart(5, 'abc'), ' abc');
assert.strictEqual(RA.padStart(5)('abc'), ' abc');
});
Expand Down
22 changes: 11 additions & 11 deletions test/pathNotEq.js
Expand Up @@ -10,22 +10,15 @@ describe('pathNotEq', function() {
obj = { a: { b: 1 } };
});

it('should curry', function() {
assert.isTrue(RA.pathNotEq(['a', 'b'], 'foo', obj));
assert.isTrue(RA.pathNotEq(['a', 'b'])('foo', obj));
assert.isTrue(RA.pathNotEq(['a', 'b'], 'foo')(obj));
assert.isTrue(RA.pathNotEq(['a', 'b'])('foo')(obj));
});

it('tests path value is not equal', function() {
it('should return true if given path values are not equal', function() {
assert.isTrue(RA.pathNotEq(['a', 'b'], 'foo', obj));
});

js636f marked this conversation as resolved.
Show resolved Hide resolved
it('tests path value is equal', function() {
it('should return false if given path values are equal', function() {
assert.isFalse(RA.pathNotEq(['a', 'b'], 1, obj));
});

it('has R.equals semantics', function() {
it('should have R.equals semantics', function() {
function Just(x) {
this.value = x;
}
Expand Down Expand Up @@ -77,7 +70,7 @@ describe('pathNotEq', function() {
});
});

it('should test example', function() {
it('should work in accordance with the documentation', function() {
const user1 = { address: { zipCode: 90210 } };
const user2 = { address: { zipCode: 55555 } };
const user3 = { name: 'Bob' };
Expand All @@ -87,4 +80,11 @@ describe('pathNotEq', function() {

assert.sameDeepOrderedMembers(result, [user2, user3]);
});

it('should be curried', function() {
assert.isTrue(RA.pathNotEq(['a', 'b'], 'foo', obj));
assert.isTrue(RA.pathNotEq(['a', 'b'])('foo', obj));
assert.isTrue(RA.pathNotEq(['a', 'b'], 'foo')(obj));
assert.isTrue(RA.pathNotEq(['a', 'b'])('foo')(obj));
});
});
2 changes: 1 addition & 1 deletion test/pathOrLazy.js
Expand Up @@ -70,7 +70,7 @@ describe('pathOrLazy', function() {
});
});

it('should curry', function() {
it('should be curried', function() {
const fn = () => 7;
assert.strictEqual(RA.pathOrLazy(fn, ['a', 'b', 'd', 1], obj), 'y');
assert.strictEqual(RA.pathOrLazy(fn)(['a', 'b', 'd', 1], obj), 'y');
Expand Down
10 changes: 5 additions & 5 deletions test/paths.js
Expand Up @@ -5,30 +5,30 @@ import * as RA from '../src';
describe('paths', function() {
const obj = { a: { b: { c: 1 } }, d: 4, e: 5, f: 6 };

it('returns empty array if no paths requested', function() {
it('should return an empty array if no paths requested', function() {
js636f marked this conversation as resolved.
Show resolved Hide resolved
assert.sameOrderedMembers(RA.paths([], obj), []);
});

it('returns values for requested paths', function() {
it('should return values for requested paths', function() {
assert.sameOrderedMembers(RA.paths([['a', 'b', 'c'], ['e']], obj), [1, 5]);
});

it('preserves order', function() {
it('should preserve order', function() {
assert.sameOrderedMembers(RA.paths([['f'], ['a', 'b', 'c'], ['e']], obj), [
6,
1,
5,
]);
});

it('returns undefined for nonexistent paths', function() {
it('should return undefined for nonexistent paths', function() {
js636f marked this conversation as resolved.
Show resolved Hide resolved
const ps = RA.paths([['d'], ['nonexistent']], obj);
assert.lengthOf(ps, 2);
assert.strictEqual(ps[0], 4);
assert.isUndefined(ps[1]);
});

it('is curried', function() {
it('should be curried', function() {
assert.sameOrderedMembers(RA.paths([['a', 'b', 'c'], ['d']])(obj), [1, 4]);
js636f marked this conversation as resolved.
Show resolved Hide resolved
});
});
12 changes: 6 additions & 6 deletions test/pickIndexes.js
Expand Up @@ -9,12 +9,7 @@ describe('pickIndexes', function() {
list = ['a', 'b', 'c'];
});

it('tests currying', function() {
assert.sameOrderedMembers(RA.pickIndexes([], []), []);
assert.sameOrderedMembers(RA.pickIndexes([])([]), []);
});

it('tests picking values from list by indexes', function() {
it('should support picking values from list by indexes', function() {
assert.sameOrderedMembers(RA.pickIndexes([0, 2], list), ['a', 'c']);
});

Expand Down Expand Up @@ -53,4 +48,9 @@ describe('pickIndexes', function() {
assert.sameOrderedMembers(RA.pickIndexes([], []), []);
});
});

it('should be curried', function() {
assert.sameOrderedMembers(RA.pickIndexes([], []), []);
assert.sameOrderedMembers(RA.pickIndexes([])([]), []);
});
});
20 changes: 10 additions & 10 deletions test/propNotEq.js
Expand Up @@ -10,22 +10,15 @@ describe('propNotEq', function() {
obj = { a: 1, b: 2 };
});

it('tests currying', function() {
assert.isTrue(RA.propNotEq('a', 'foo', obj));
assert.isTrue(RA.propNotEq('a')('foo', obj));
assert.isTrue(RA.propNotEq('a', 'foo')(obj));
assert.isTrue(RA.propNotEq('a')('foo')(obj));
});

it('tests prop value is not equal', function() {
it('should return true if given props values are not equal', function() {
assert.isTrue(RA.propNotEq('a', 'foo', obj));
});

it('tests prop value is equal', function() {
it('should return false if given props values are equal', function() {
js636f marked this conversation as resolved.
Show resolved Hide resolved
assert.isFalse(RA.propNotEq('a', 1, obj));
});

it('has R.equals semantics', function() {
it('should have R.equals semantics', function() {
function Just(x) {
this.value = x;
}
Expand Down Expand Up @@ -70,4 +63,11 @@ describe('propNotEq', function() {
});
});
});

it('should be curried', function() {
assert.isTrue(RA.propNotEq('a', 'foo', obj));
assert.isTrue(RA.propNotEq('a')('foo', obj));
assert.isTrue(RA.propNotEq('a', 'foo')(obj));
assert.isTrue(RA.propNotEq('a')('foo')(obj));
});
});
91 changes: 27 additions & 64 deletions test/reduceIndexed.js
Expand Up @@ -4,74 +4,33 @@ import * as R from 'ramda';
import * as RA from '../src';

describe('reduceIndexed', function() {
context('R.reduce', function() {
const addition = (a, b) => a + b;
const mult = (a, b) => a * b;
const addition = (a, b) => a + b;
const mult = (a, b) => a * b;

it('folds simple functions over arrays with the supplied accumulator', function() {
assert.strictEqual(R.reduce(addition, 0, [1, 2, 3, 4]), 10);
assert.strictEqual(R.reduce(mult, 1, [1, 2, 3, 4]), 24);
});

it('dispatches to objects that implement `reduce`', function() {
const obj = {
x: [1, 2, 3],
reduce: function fun() {
return 'override';
},
};

assert.strictEqual(R.reduce(addition, 0, obj), 'override');
assert.strictEqual(R.reduce(addition, 10, obj), 'override');
});

it('returns the accumulator for an empty array', function() {
assert.strictEqual(R.reduce(addition, 0, []), 0);
assert.strictEqual(R.reduce(mult, 1, []), 1);
assert.sameOrderedMembers(R.reduce(R.concat, [], []), []);
});

it('uses the iterator of an object (and handles short-circuits)', function() {
const symIterator =
typeof Symbol !== 'undefined' ? Symbol.iterator : '@@iterator';

function Reducible(arr) {
this.arr = arr;
}

Reducible.prototype[symIterator] = function() {
const a = this.arr;
return {
_pos: 0,
next: function fn() {
if (this._pos < a.length) {
const v = a[this._pos];
this._pos += 1;
return {
value: v,
done: false,
};
}
return {
done: true,
};
},
};
};
it('should fold simple functions over arrays with the supplied accumulator', function() {
assert.strictEqual(RA.reduceIndexed(addition, 0, [1, 2, 3, 4]), 10);
assert.strictEqual(RA.reduceIndexed(mult, 1, [1, 2, 3, 4]), 24);
});

const xf = R.take(2);
const apendingT = {};
apendingT['@@transducer/result'] = R.identity;
apendingT['@@transducer/step'] = R.flip(R.append);
it('should ispatch to objects that implement `reduce`', function() {
js636f marked this conversation as resolved.
Show resolved Hide resolved
const obj = {
x: [1, 2, 3],
reduce: function fun() {
return 'override';
},
};

const rfn = xf(apendingT);
const list = new Reducible([1, 2, 3, 4, 5, 6]);
assert.strictEqual(RA.reduceIndexed(addition, 0, obj), 'override');
assert.strictEqual(RA.reduceIndexed(addition, 10, obj), 'override');
});

assert.sameOrderedMembers(R.reduce(rfn, [], list), [1, 2]);
});
it('should return the accumulator for an empty array', function() {
assert.strictEqual(RA.reduceIndexed(addition, 0, []), 0);
assert.strictEqual(RA.reduceIndexed(mult, 1, []), 1);
assert.sameOrderedMembers(RA.reduceIndexed(R.concat, [], []), []);
});

context('documentation example', function() {
context('given documentation example', function() {
specify('should join idx and value with a "-"', function() {
const initialList = ['f', 'o', 'o', 'b', 'a', 'r'];
const resultAcc = '-f0-o1-o2-b3-a4-r5';
Expand All @@ -87,10 +46,10 @@ describe('reduceIndexed', function() {
});
});

context('fourth argument', function() {
context('given a callback with the fourth argument', function() {
const initialList = ['f', 'o', 'o', 'b', 'a', 'r'];

specify('should be the same reference that original list', function() {
specify('should supply to it an original list reference', function() {
RA.reduceIndexed(
(acc, val, idx, list) => {
assert.strictEqual(list, initialList);
Expand All @@ -101,4 +60,8 @@ describe('reduceIndexed', function() {
);
});
});

it('should be curried', function() {
assert.strictEqual(RA.reduceIndexed(addition)(0)([1, 2, 3, 4]), 10);
js636f marked this conversation as resolved.
Show resolved Hide resolved
});
});