mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 21:10:23 +00:00
[ramda] split tests to separate modules: 'identical' - 'isNaN' (#38546)
* move 'identical' tests to separate file * move 'identity' tests to separate file * move 'ifElse' tests to separate file * move 'includes' tests to separate file * move 'indexBy' tests to separate file * move 'indexOf' tests to separate file * move 'init' tests to separate file * move 'innerJoin' tests to separate file * move 'insert' tests to separate file * move 'insertAll' tests to separate file * move 'intersection' tests to separate file * move 'intersperse' tests to separate file * move 'into' tests to separate file * move 'invert' tests to separate file * move 'invertObj' tests to separate file * move 'invoker' tests to separate file * move 'is' tests to separate file * move 'isArrayLike' tests to separate file * move 'isEmpty' tests to separate file * move 'isNaN' tests to separate file
This commit is contained in:
committed by
Michael Crane
parent
e46cfc9a73
commit
77614d5fac
@@ -24,13 +24,6 @@ class F2 {
|
||||
}
|
||||
}
|
||||
|
||||
(() => {
|
||||
let x: boolean;
|
||||
x = R.isArrayLike("a");
|
||||
x = R.isArrayLike([1, 2, 3]);
|
||||
x = R.isArrayLike([]);
|
||||
});
|
||||
|
||||
(() => {
|
||||
R.propIs(Number, "x", {x: 1, y: 2}); // => true
|
||||
R.propIs(Number, "x")({x: 1, y: 2}); // => true
|
||||
@@ -252,11 +245,6 @@ class F2 {
|
||||
const followersForUser2: (userName: string) => Promise<string[]> = R.pipeWith(R.then)([db.getUserById, db.getFollowers]);
|
||||
};
|
||||
|
||||
() => {
|
||||
R.invoker(1, "slice")(6, "abcdefghijklm");
|
||||
R.invoker(2, "slice")(6)(8, "abcdefghijklm");
|
||||
};
|
||||
|
||||
(() => {
|
||||
const range = R.juxt([Math.min, Math.max]);
|
||||
range(3, 4, 9, -3); // => [-3, 9]
|
||||
@@ -551,61 +539,12 @@ interface Obj {
|
||||
title: string;
|
||||
}
|
||||
const list: Book[] = [{id: "xyz", title: "A"}, {id: "abc", title: "B"}];
|
||||
const a1 = R.indexBy(R.prop("id"), list);
|
||||
// Typescript 3.3 incorrectly gives `a2: {}`, 3.4 gives an error instead.
|
||||
// const a2 = R.indexBy(R.prop("id"))(list);
|
||||
const a3 = R.indexBy<{ id: string }>(R.prop("id"))(list);
|
||||
const a4 = R.indexBy(R.prop<"id", string>("id"))(list);
|
||||
const a5 = R.indexBy<{ id: string }>(R.prop<"id", string>("id"))(list);
|
||||
|
||||
const titlesIndexedByTitles: { [k: string]: string } = R.pipe(
|
||||
R.map((x: Book) => x.title),
|
||||
R.indexBy(x => x),
|
||||
)(list);
|
||||
});
|
||||
|
||||
() => {
|
||||
R.includes('ba', 'banana'); // => true
|
||||
R.includes('ba')('kiwi'); // => false
|
||||
R.includes('ma', ['ma', 'ng', 'o']); // => true
|
||||
R.includes('ma')(['li', 'me']); // => false
|
||||
R.includes(8, [1, 8, 9, 17]); // => true
|
||||
R.includes(1)([2, 3, 5, 8]); // => false
|
||||
};
|
||||
|
||||
() => {
|
||||
R.indexOf(3, [1, 2, 3, 4]); // => 2
|
||||
R.indexOf(10)([1, 2, 3, 4]); // => -1
|
||||
};
|
||||
|
||||
() => {
|
||||
R.init(["fi", "fo", "fum"]); // => ['fi', 'fo']
|
||||
R.init("abc"); // => 'ab'
|
||||
R.init(""); // => ''
|
||||
};
|
||||
|
||||
() => {
|
||||
R.insert(2, 5, [1, 2, 3, 4]); // => [1,2,5,3,4]
|
||||
R.insert(2)(5, [1, 2, 3, 4]); // => [1,2,5,3,4]
|
||||
R.insert(2, 5)([1, 2, 3, 4]); // => [1,2,5,3,4]
|
||||
};
|
||||
|
||||
() => {
|
||||
R.insertAll(2, [10, 11, 12], [1, 2, 3, 4]);
|
||||
R.insertAll(2)([10, 11, 12], [1, 2, 3, 4]);
|
||||
R.insertAll(2, [10, 11, 12])([1, 2, 3, 4]);
|
||||
};
|
||||
|
||||
() => {
|
||||
const numbers = [1, 2, 3, 4];
|
||||
const transducer = R.compose(R.map(R.add(1)), R.take(2));
|
||||
|
||||
R.into([], transducer, numbers); // => [2, 3]
|
||||
|
||||
const intoArray = R.into([]);
|
||||
intoArray(transducer, numbers); // => [2, 3]
|
||||
};
|
||||
|
||||
() => {
|
||||
const spacer = R.join(" ");
|
||||
spacer(["a", 2, 3.4]); // => 'a 2 3.4'
|
||||
@@ -1086,30 +1025,6 @@ type Pair = KeyValuePair<string, number>;
|
||||
* Object category
|
||||
*/
|
||||
|
||||
() => {
|
||||
const raceResultsByFirstName = {
|
||||
first : "alice",
|
||||
second: "jake",
|
||||
third : "alice",
|
||||
};
|
||||
R.invert(raceResultsByFirstName);
|
||||
// => { 'alice': ['first', 'third'], 'jake':['second'] }
|
||||
};
|
||||
|
||||
() => {
|
||||
const raceResults0 = {
|
||||
first : "alice",
|
||||
second: "jake"
|
||||
};
|
||||
R.invertObj(raceResults0);
|
||||
// => { 'alice': 'first', 'jake':'second' }
|
||||
|
||||
// Alternatively:
|
||||
const raceResults1 = ["alice", "jake"];
|
||||
R.invertObj(raceResults1);
|
||||
// => { 'alice': '0', 'jake':'1' }
|
||||
};
|
||||
|
||||
() => {
|
||||
const objKeys = R.keys({a: 1, b: 2, c: 3}); // => ['a', 'b', 'c']
|
||||
const numberKeys = R.keys(1);
|
||||
@@ -1504,24 +1419,6 @@ type Pair = KeyValuePair<string, number>;
|
||||
/*****************************************************************
|
||||
* Relation category
|
||||
*/
|
||||
() => {
|
||||
const a1 = R.identity(1); // => 1
|
||||
const obj = {};
|
||||
const a2 = R.identity([1, 2, 3]);
|
||||
const a3 = R.identity(["a", "b", "c"]);
|
||||
const a4 = R.identity(obj) === obj; // => true
|
||||
};
|
||||
|
||||
() => {
|
||||
const o = {};
|
||||
R.identical(o, o); // => true
|
||||
R.identical(1, 1); // => true
|
||||
R.identical("2", "1"); // => false
|
||||
R.identical([], []); // => false
|
||||
R.identical(0, -0); // => false
|
||||
R.identical(NaN, NaN); // => true
|
||||
};
|
||||
|
||||
() => {
|
||||
const testPath = ["x", 0, "y"];
|
||||
const testObj = {x: [{y: 2, z: 3}, {y: 4, z: 5}]};
|
||||
@@ -1598,12 +1495,6 @@ type Pair = KeyValuePair<string, number>;
|
||||
R.startsWith([1])([1, 2, 3]); // => true
|
||||
};
|
||||
|
||||
() => {
|
||||
R.isNaN(NaN); // => true
|
||||
R.isNaN(undefined); // => false
|
||||
R.isNaN({}); // => false
|
||||
};
|
||||
|
||||
() => {
|
||||
R.lt(2, 6); // => true
|
||||
R.lt(2, 0); // => false
|
||||
@@ -1744,24 +1635,6 @@ type Pair = KeyValuePair<string, number>;
|
||||
R.symmetricDifferenceWith(eqL)(l1, l2); // => ['dddd', 'c']
|
||||
};
|
||||
|
||||
() => {
|
||||
const list1 = [
|
||||
{id: 1, name: 'One'},
|
||||
{id: 2, name: 'Two'},
|
||||
{id: 3, name: 'Three'},
|
||||
{id: 4, name: 'Four'},
|
||||
{id: 5, name: 'Five'}
|
||||
];
|
||||
|
||||
const list2 = [5, 4, 6];
|
||||
const matchId = (record: { id: number, name: string }, id: number): boolean => record.id === id;
|
||||
|
||||
R.innerJoin(matchId, list1, list2); // [{"id": 4, "name": "Four"}, {"id": 5, "name": "Five"}]
|
||||
|
||||
const innerJoinCurried = R.innerJoin(matchId);
|
||||
innerJoinCurried(list1, list2); // [{"id": 4, "name": "Four"}, {"id": 5, "name": "Five"}]
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
* String category
|
||||
*/
|
||||
@@ -1782,28 +1655,6 @@ type Pair = KeyValuePair<string, number>;
|
||||
R.replace(/([cfk])oo/g)((match, p1, offset) => `${p1}-${offset}`) ("coo foo koo"); // => 'c0oo f4oo k8oo'
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
* Is category
|
||||
*/
|
||||
() => {
|
||||
R.is(Object, {}); // => true
|
||||
R.is(Object)({}); // => true
|
||||
R.is(Number, 1); // => true
|
||||
R.is(Number)(1); // => true
|
||||
R.is(Object, 1); // => false
|
||||
R.is(Object)(1); // => false
|
||||
R.is(String, "s"); // => true
|
||||
R.is(String)("s"); // => true
|
||||
R.is(String, new String("")); // => true
|
||||
R.is(String)(new String("")); // => true
|
||||
R.is(Object, new String("")); // => true
|
||||
R.is(Object)(new String("")); // => true
|
||||
R.is(Object, "s"); // => false
|
||||
R.is(Object)("s"); // => false
|
||||
R.is(Number, {}); // => false
|
||||
R.is(Number)({}); // => false
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
* Logic category
|
||||
*/
|
||||
@@ -1816,26 +1667,6 @@ type Pair = KeyValuePair<string, number>;
|
||||
flattenArrays([[[10], 123], [8, [10]], "hello"]); // => [[10, 123], [8, 10], "hello"]
|
||||
};
|
||||
|
||||
() => {
|
||||
const incCount = R.ifElse(
|
||||
R.has('count'),
|
||||
R.over(R.lensProp('count'), R.inc),
|
||||
R.assoc('count', 1)
|
||||
);
|
||||
incCount({}); // => { count: 1 }
|
||||
incCount({ count: 1 }); // => { count: 2 }
|
||||
R.ifElse(R.identical, R.add as (a: number, b: number) => number, R.always(""))(2, 2); // https://goo.gl/CVUSs9
|
||||
};
|
||||
|
||||
() => {
|
||||
R.isEmpty([1, 2, 3]); // => false
|
||||
R.isEmpty([]); // => true
|
||||
R.isEmpty(""); // => true
|
||||
R.isEmpty(null); // => false
|
||||
R.isEmpty({}); // =>true
|
||||
R.isEmpty({a: 1}); // => false
|
||||
};
|
||||
|
||||
() => {
|
||||
R.not(true); // => false
|
||||
R.not(false); // => true
|
||||
@@ -1865,15 +1696,4 @@ class Why {
|
||||
const x4: Why | boolean = R.or(why, false); // false
|
||||
};
|
||||
|
||||
() => {
|
||||
R.intersperse(",", ["foo", "bar"]); // => ['foo', ',', 'bar']
|
||||
R.intersperse(0, [1, 2]); // => [1, 0, 2]
|
||||
R.intersperse(0, [1]); // => [1]
|
||||
};
|
||||
|
||||
() => {
|
||||
R.intersection([1, 2, 3], [2, 3, 3, 4]); // => [2, 3]
|
||||
R.intersection([1, 2, 3])([2, 3, 3, 4]); // => [2, 3]
|
||||
};
|
||||
|
||||
// Curry tests
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
const o = {};
|
||||
R.identical(o, o); // => true
|
||||
R.identical(1, 1); // => true
|
||||
R.identical('2', '1'); // => false
|
||||
R.identical([], []); // => false
|
||||
R.identical(0, -0); // => false
|
||||
R.identical(NaN, NaN); // => true
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
const a1 = R.identity(1); // => 1
|
||||
const obj = {};
|
||||
const a2 = R.identity([1, 2, 3]);
|
||||
const a3 = R.identity(['a', 'b', 'c']);
|
||||
const a4 = R.identity(obj) === obj; // => true
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
const incCount = R.ifElse(
|
||||
R.has('count'),
|
||||
R.over(R.lensProp('count'), R.inc),
|
||||
R.assoc('count', 1),
|
||||
);
|
||||
incCount({}); // => { count: 1 }
|
||||
incCount({ count: 1 }); // => { count: 2 }
|
||||
R.ifElse(
|
||||
R.identical,
|
||||
R.add as (a: number, b: number) => number,
|
||||
R.always(''),
|
||||
)(2, 2); // https://goo.gl/CVUSs9
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.includes('ba', 'banana'); // => true
|
||||
R.includes('ba')('kiwi'); // => false
|
||||
R.includes('ma', ['ma', 'ng', 'o']); // => true
|
||||
R.includes('ma')(['li', 'me']); // => false
|
||||
R.includes(8, [1, 8, 9, 17]); // => true
|
||||
R.includes(1)([2, 3, 5, 8]); // => false
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
interface Book {
|
||||
id: string;
|
||||
title: string;
|
||||
}
|
||||
const list: Book[] = [{ id: 'xyz', title: 'A' }, { id: 'abc', title: 'B' }];
|
||||
const a1 = R.indexBy(R.prop('id'), list);
|
||||
// Typescript 3.3 incorrectly gives `a2: {}`, 3.4 gives an error instead.
|
||||
// const a2 = R.indexBy(R.prop("id"))(list);
|
||||
const a3 = R.indexBy<{ id: string }>(R.prop('id'))(list);
|
||||
const a4 = R.indexBy(R.prop<'id', string>('id'))(list);
|
||||
const a5 = R.indexBy<{ id: string }>(R.prop<'id', string>('id'))(list);
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.indexOf(3, [1, 2, 3, 4]); // => 2
|
||||
R.indexOf(10)([1, 2, 3, 4]); // => -1
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.init(['fi', 'fo', 'fum']); // => ['fi', 'fo']
|
||||
R.init('abc'); // => 'ab'
|
||||
R.init(''); // => ''
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
const list1 = [
|
||||
{ id: 1, name: 'One' },
|
||||
{ id: 2, name: 'Two' },
|
||||
{ id: 3, name: 'Three' },
|
||||
{ id: 4, name: 'Four' },
|
||||
{ id: 5, name: 'Five' },
|
||||
];
|
||||
|
||||
const list2 = [5, 4, 6];
|
||||
const matchId = (record: { id: number; name: string }, id: number): boolean =>
|
||||
record.id === id;
|
||||
|
||||
R.innerJoin(matchId, list1, list2); // [{"id": 4, "name": "Four"}, {"id": 5, "name": "Five"}]
|
||||
|
||||
const innerJoinCurried = R.innerJoin(matchId);
|
||||
innerJoinCurried(list1, list2); // [{"id": 4, "name": "Four"}, {"id": 5, "name": "Five"}]
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.insert(2, 5, [1, 2, 3, 4]); // => [1,2,5,3,4]
|
||||
R.insert(2)(5, [1, 2, 3, 4]); // => [1,2,5,3,4]
|
||||
R.insert(2, 5)([1, 2, 3, 4]); // => [1,2,5,3,4]
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.insertAll(2, [10, 11, 12], [1, 2, 3, 4]);
|
||||
R.insertAll(2)([10, 11, 12], [1, 2, 3, 4]);
|
||||
R.insertAll(2, [10, 11, 12])([1, 2, 3, 4]);
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.intersection([1, 2, 3], [2, 3, 3, 4]); // => [2, 3]
|
||||
R.intersection([1, 2, 3])([2, 3, 3, 4]); // => [2, 3]
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.intersperse(',', ['foo', 'bar']); // => ['foo', ',', 'bar']
|
||||
R.intersperse(0, [1, 2]); // => [1, 0, 2]
|
||||
R.intersperse(0, [1]); // => [1]
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
const numbers = [1, 2, 3, 4];
|
||||
const transducer = R.compose(
|
||||
R.map(R.add(1)),
|
||||
R.take(2),
|
||||
);
|
||||
|
||||
R.into([], transducer, numbers); // => [2, 3]
|
||||
|
||||
const intoArray = R.into([]);
|
||||
intoArray(transducer, numbers); // => [2, 3]
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
const raceResultsByFirstName = {
|
||||
first: 'alice',
|
||||
second: 'jake',
|
||||
third: 'alice',
|
||||
};
|
||||
R.invert(raceResultsByFirstName);
|
||||
// => { 'alice': ['first', 'third'], 'jake':['second'] }
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
const raceResults0 = {
|
||||
first: 'alice',
|
||||
second: 'jake',
|
||||
};
|
||||
R.invertObj(raceResults0);
|
||||
// => { 'alice': 'first', 'jake':'second' }
|
||||
|
||||
// Alternatively:
|
||||
const raceResults1 = ['alice', 'jake'];
|
||||
R.invertObj(raceResults1);
|
||||
// => { 'alice': '0', 'jake':'1' }
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.invoker(1, 'slice')(6, 'abcdefghijklm');
|
||||
R.invoker(2, 'slice')(6)(8, 'abcdefghijklm');
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.is(Object, {}); // => true
|
||||
R.is(Object)({}); // => true
|
||||
R.is(Number, 1); // => true
|
||||
R.is(Number)(1); // => true
|
||||
R.is(Object, 1); // => false
|
||||
R.is(Object)(1); // => false
|
||||
R.is(String, 's'); // => true
|
||||
R.is(String)('s'); // => true
|
||||
R.is(String, new String('')); // => true
|
||||
R.is(String)(new String('')); // => true
|
||||
R.is(Object, new String('')); // => true
|
||||
R.is(Object)(new String('')); // => true
|
||||
R.is(Object, 's'); // => false
|
||||
R.is(Object)('s'); // => false
|
||||
R.is(Number, {}); // => false
|
||||
R.is(Number)({}); // => false
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
let x: boolean;
|
||||
x = R.isArrayLike('a');
|
||||
x = R.isArrayLike([1, 2, 3]);
|
||||
x = R.isArrayLike([]);
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.isEmpty([1, 2, 3]); // => false
|
||||
R.isEmpty([]); // => true
|
||||
R.isEmpty(''); // => true
|
||||
R.isEmpty(null); // => false
|
||||
R.isEmpty({}); // =>true
|
||||
R.isEmpty({ a: 1 }); // => false
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.isNaN(NaN); // => true
|
||||
R.isNaN(undefined); // => false
|
||||
R.isNaN({}); // => false
|
||||
};
|
||||
@@ -92,6 +92,26 @@
|
||||
"test/has-tests.ts",
|
||||
"test/hasIn-tests.ts",
|
||||
"test/hasPath-tests.ts",
|
||||
"test/head-tests.ts"
|
||||
"test/head-tests.ts",
|
||||
"test/identical-tests.ts",
|
||||
"test/identity-tests.ts",
|
||||
"test/ifElse-tests.ts",
|
||||
"test/includes-tests.ts",
|
||||
"test/indexBy-tests.ts",
|
||||
"test/indexOf-tests.ts",
|
||||
"test/init-tests.ts",
|
||||
"test/innerJoin-tests.ts",
|
||||
"test/insert-tests.ts",
|
||||
"test/insertAll-tests.ts",
|
||||
"test/intersection-tests.ts",
|
||||
"test/intersperse-tests.ts",
|
||||
"test/into-tests.ts",
|
||||
"test/invert-tests.ts",
|
||||
"test/invertObj-tests.ts",
|
||||
"test/invoker-tests.ts",
|
||||
"test/is-tests.ts",
|
||||
"test/isArrayLike-tests.ts",
|
||||
"test/isEmpty-tests.ts",
|
||||
"test/isNaN-tests.ts"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user