From c08e6d8f68be510b3bd951fb74a5432095295eed Mon Sep 17 00:00:00 2001 From: Mike Deverell Date: Thu, 12 Sep 2019 15:47:19 -0400 Subject: [PATCH] [ramda] split tests to separate modules - functions beginning with 'd' - 'e' (#38274) * move 'countBy' tests to separate file * move 'curry' tests to separate file * move 'dec' tests to separate file * move 'defaultTo' tests to separate file * move 'difference' tests to separate file * move 'differenceWith' tests to separate file * move 'dissoc' tests to separate file * move 'dissocPath' tests to separate file * move 'drop' tests to separate file * move 'dropLast' tests to separate file * move 'divide' tests to separate file * move 'dropLastWhile' tests to separate file * move 'dropRepeats' tests to separate file * move 'dropRepeatsWith' tests to separate file * move 'either' tests to separate file * move 'empty' tests to separate file * move 'endsWith' tests to separate file * move 'dropWhile' tests to separate file * move 'eqBy' tests to separate file * move 'eqProps' tests to separate file * move 'equals' tests to separate file * move 'evolve' tests to separate file --- types/ramda/ramda-tests.ts | 282 ---------------------- types/ramda/test/countBy-tests.ts | 8 + types/ramda/test/curry-tests.ts | 84 +++++++ types/ramda/test/dec-tests.ts | 5 + types/ramda/test/defaultTo-tests.ts | 14 ++ types/ramda/test/difference-tests.ts | 6 + types/ramda/test/differenceWith-tests.ts | 21 ++ types/ramda/test/dissoc-tests.ts | 7 + types/ramda/test/dissocPath-tests.ts | 16 ++ types/ramda/test/divide-tests.ts | 8 + types/ramda/test/drop-tests.ts | 8 + types/ramda/test/dropLast-tests.ts | 8 + types/ramda/test/dropLastWhile-tests.ts | 6 + types/ramda/test/dropRepeats-tests.ts | 5 + types/ramda/test/dropRepeatsWith-tests.ts | 6 + types/ramda/test/dropWhile-tests.ts | 10 + types/ramda/test/either-tests.ts | 16 ++ types/ramda/test/empty-tests.ts | 8 + types/ramda/test/endsWith-tests.ts | 10 + types/ramda/test/eqBy-tests.ts | 5 + types/ramda/test/eqProps-tests.ts | 13 + types/ramda/test/equals-tests.ts | 18 ++ types/ramda/test/evolve-tests.ts | 61 +++++ types/ramda/tsconfig.json | 24 +- 24 files changed, 366 insertions(+), 283 deletions(-) create mode 100644 types/ramda/test/countBy-tests.ts create mode 100644 types/ramda/test/curry-tests.ts create mode 100644 types/ramda/test/dec-tests.ts create mode 100644 types/ramda/test/defaultTo-tests.ts create mode 100644 types/ramda/test/difference-tests.ts create mode 100644 types/ramda/test/differenceWith-tests.ts create mode 100644 types/ramda/test/dissoc-tests.ts create mode 100644 types/ramda/test/dissocPath-tests.ts create mode 100644 types/ramda/test/divide-tests.ts create mode 100644 types/ramda/test/drop-tests.ts create mode 100644 types/ramda/test/dropLast-tests.ts create mode 100644 types/ramda/test/dropLastWhile-tests.ts create mode 100644 types/ramda/test/dropRepeats-tests.ts create mode 100644 types/ramda/test/dropRepeatsWith-tests.ts create mode 100644 types/ramda/test/dropWhile-tests.ts create mode 100644 types/ramda/test/either-tests.ts create mode 100644 types/ramda/test/empty-tests.ts create mode 100644 types/ramda/test/endsWith-tests.ts create mode 100644 types/ramda/test/eqBy-tests.ts create mode 100644 types/ramda/test/eqProps-tests.ts create mode 100644 types/ramda/test/equals-tests.ts create mode 100644 types/ramda/test/evolve-tests.ts diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index 0b3cf54b46..3c51ea5ee8 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -64,31 +64,6 @@ class F2 { return [a, b, c]; } - function addFourNumbers(a: number, b: number, c: number, d: number): number { - return a + b + c + d; - } - - function addTenFixedNumbers(a: 0, b: 1, c: 2, d: 3, e: 4, f: 5, g: 6, h: 7, i: 8, k: 9, l: 10): number { - return a + b + c + d; - } - - const x1: (a: number, b: number, c: number, d: number) => number = R.curry(addFourNumbers); - // because of the current way of currying, the following call results in a type error - const x2: (...args: any) => any = R.curry(addFourNumbers)(1, 2, 4); - const x3: (c: number, d: number) => number = R.curry(addFourNumbers)(1)(2); - const x4: (d: number) => number = R.curry(addFourNumbers)(1)(2)(3); - const y1: number = R.curry(addFourNumbers)(1)(2)(3)(4); - const y2: number = R.curry(addFourNumbers)(1, 2)(3, 4); - const y3: number = R.curry(addFourNumbers)(1, 2, 3)(4); - const y4: number = R.curry(addTenFixedNumbers)(R.__, 1, 2)(0)(3)( - R.__, - R.__, - )(R.__, 5)(4)(6, 7)(R.__)(8, R.__, R.__)(9, 10); - const y5: number = R.curry(addTenFixedNumbers)(R.__, 1, R.__)(R.__, 2)( - 0, - 3, - )(R.__, 5)(4, R.__)(R.__)(6, R.__, 8, 9, 10)(7); - R.nAry(0); R.nAry(0, takesNoArg); R.nAry(0, takesOneArg); @@ -98,40 +73,6 @@ class F2 { const u1: (a: any) => any = R.unary(takesOneArg); const u2: (a: any) => any = R.unary(takesTwoArgs); const u3: (a: any) => any = R.unary(takesThreeArgs); - - function addTwoNumbers(a: number, b: number) { - return a + b; - } - - const addTwoNumbersCurried = R.curry(addTwoNumbers); - - const inc = addTwoNumbersCurried(1); - const z1: number = inc(2); - const z2: number = addTwoNumbersCurried(2, 3); -}; - -() => { - interface Car { speed?: number; - } - interface FastCar { speed: number; - } - - function typeGuard(a: number, b: number, c: number, d: number, e: number, car: Car): car is FastCar { - return car.speed !== undefined; - } - - const typeGuardCurried = R.curry(typeGuard); - - function drive(fastCar: FastCar) { - } - - const cars: Car[] = [{speed: 65}, {}]; - for (const car of cars) { - if (typeGuardCurried(1)(2)(3)(4)(5)(car)) { - drive(car); // $ExpectError - // Generic Curry solved a previously non reported issue - } - } }; /** R.__ */ @@ -478,13 +419,6 @@ R.times(i, 5); const c: number[] = R.of(1); }); -() => { - const a1 = R.empty([1, 2, 3, 4, 5]); // => [] - const a2 = R.empty([1, 2, 3]); // => [] - const a3 = R.empty("unicorns"); // => '' - const a4 = R.empty({x: 1, y: 2}); // => {} -}; - (() => { R.length([1, 2, 3]); // => 3 }); @@ -537,43 +471,6 @@ R.times(i, 5); /********************* * List category */ -() => { - R.drop(3, [1, 2, 3, 4, 5, 6, 7]); // => [4,5,6,7] - R.drop(3)([1, 2, 3, 4, 5, 6, 7]); // => [4,5,6,7] - R.drop(3, "ramda"); // => 'ram' - R.drop(3)("ramda"); // => 'ram' -}; - -(() => { - R.dropLast(1, ["foo", "bar", "baz"]); // => ['foo', 'bar'] - R.dropLast(2)(["foo", "bar", "baz"]); // => ['foo'] - R.dropLast(3, "ramda"); // => 'ra' - R.dropLast(3)("ramda"); // => 'ra' -}); - -(() => { - const lteThree = (x: number) => x <= 3; - R.dropLastWhile(lteThree, [1, 2, 3, 4, 3, 2, 1]); // => [1, 2, 3, 4] -}); - -(() => { - R.dropRepeats([1, 1, 1, 2, 3, 4, 4, 2, 2]); // => [1, 2, 3, 4, 2] -}); - -(() => { - const l = [1, -1, 1, 3, 4, -4, -4, -5, 5, 3, 3]; - const x: number[] = R.dropRepeatsWith(R.eqBy(Math.abs), l); // => [1, 3, 4, -5, 3] -}); - -() => { - function lteTwo(x: number) { - return x <= 2; - } - - R.dropWhile(lteTwo, [1, 2, 3, 4]); // => [3, 4] - R.dropWhile(lteTwo)([1, 2, 3, 4]); // => [3, 4] -}; - () => { function isEven(n: number) { return n % 2 === 0; @@ -1293,11 +1190,6 @@ type Pair = KeyValuePair; R.uniqWith(strEq)(["1", 1, 1]); // => ['1'] }; -() => { - R.equals(R.unnest([1, [2], [[3]]]), [1, 2, [3]]); // => true - R.equals(R.unnest([[1, 2], [3, 4], [5, 6]]), [1, 2, 3, 4, 5, 6]); // => true -}; - () => { R.xprod([1, 2], ["a", "b"]); // => [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] R.xprod([1, 2])(["a", "b"]); // => [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] @@ -1337,86 +1229,6 @@ type Pair = KeyValuePair; * Object category */ -() => { - const a1 = R.dissoc<{ a: number, c: number }>("b", {a: 1, b: 2, c: 3}); // => {a: 1, c: 3} - const a2 = R.dissoc("b", {a: 1, b: 2, c: 3}); // => {a: 1, c: 3} - const a4 = R.dissoc("b")<{ a: number, c: number }>({a: 1, b: 2, c: 3}); // => {a: 1, c: 3} -}; - -() => { - const a1 = R.dissocPath(["a", "b", "c"], {a: {b: {c: 42}}}); // => {a: {b: {}}} - // optionally specify return type - const a2 = R.dissocPath<{ a: { b: number } }>(["a", "b", "c"], {a: {b: {c: 42}}}); // => {a: {b: {}}} - const a3 = R.dissocPath(["a", "b", "c"])({a: {b: {c: 42}}}); // => {a: {b: {}}} - - const testPath = ["x", 0, "y"]; - const testObj = {x: [{y: 2, z: 3}, {y: 4, z: 5}]}; - - R.dissocPath(testPath, testObj); // => {x: [{z: 3}, {y: 4, z: 5}]} - R.dissocPath(testPath)(testObj); // => {x: [{z: 3}, {y: 4, z: 5}]} -}; - -() => { - const o1 = {a: 1, b: 2, c: 3, d: 4}; - const o2 = {a: 10, b: 20, c: 3, d: 40}; - const a1 = R.eqProps("a", o1, o2); // => false - const a2 = R.eqProps("c", o1, o2); // => true - const a3: (obj1: T, obj2: U) => boolean = R.eqProps("c"); - const a4: (obj2: U) => boolean = R.eqProps("c", o1); -}; - -() => { - // No type transformation - - const a1 = R.evolve({ elapsed: R.add(1), remaining: R.add(-1) }, { name: "Tomato", elapsed: 100, remaining: 1400 }); - - const a1Test: { elapsed: number, remaining: number, name: string } = a1; - - const a2 = R.evolve({ elapsed: R.add(1), remaining: R.add(-1) })({ name: "Tomato", elapsed: 100, remaining: 1400 }); - - const a2Test: { elapsed: number, remaining: number, name: string } = a2; - - // Object doesn't have all evolver keys - - const a3 = R.evolve({ age: R.add(1), name: R.trim }, { name: "Potato", elapsed: 100 }); - - const a3Test: { name: string, elapsed: number } = a3; - - // Flat transformation - - const ex0 = R.evolve({ a: parseInt }, { a: '10', b: 1 }); - - const ex0Test: { a: number, b: number } = ex0; - - // Nested transformation: - - const ex1 = R.evolve( - { a: { b: R.toString, d: { e: R.toString } } }, - { a: { b: 1, c: null, d: { e: 2 } } }, - ); - - const ex1Test: { a: { b: string, c: null, d: { e: string } } } = ex1; - - // Mapping a nested object with a single function - - const ex2 = R.evolve( - { a: (obj: { foo: string }) => ({ bar: 1, baz: 2 }) }, - { a: { foo: 'a', skipped: 3 }, b: null }, - ); - - const ex2Test: { a: { bar: number, baz: number }, b: null } = ex2; - - // Nested curried: - - const ex3 = R.evolve( - { a: { b: R.toString, d: { e: R.toString } } }, - )( - { a: { b: 1, c: null, d: { e: 2 } } } - ); - - const ex3Test: { a: { b: string, c: null, d: { e: string } } } = ex3; -}; - () => { const hasName = R.has("name"); const a1: boolean = hasName({name: "alice"}); // => true @@ -1887,50 +1699,6 @@ class Rectangle { /***************************************************************** * Relation category */ -() => { - const numbers = [1.0, 1.1, 1.2, 2.0, 3.0, 2.2]; - const letters = R.split("", "abcABCaaaBBc"); - R.countBy(Math.floor)(numbers); // => {'1': 3, '2': 2, '3': 1} - R.countBy(R.toLower)(letters); // => {'a': 5, 'b': 4, 'c': 3} -}; - -() => { - R.difference([1, 2, 3, 4], [7, 6, 5, 4, 3]); // => [1,2] - R.difference([7, 6, 5, 4, 3], [1, 2, 3, 4]); // => [7,6,5] -}; - -() => { - function cmp1(x: any, y: any) { - return x.a === y.a; - } - - function cmp2(x: any, y: any) { - return x.a === y.b; - } - - const l1 = [{a: 1}, {a: 2}, {a: 3}]; - const l2 = [{a: 3}, {a: 4}]; - const l3 = [{b: 3}, {b: 4}]; - R.differenceWith(cmp1, l1, l2); // => [{a: 1}, {a: 2}] - - const differenceWithCurried1 = R.differenceWith(cmp1); - differenceWithCurried1(l1, l2); // =>[{a: 1}, {a: 2}] - - R.differenceWith(cmp2, l1, l3); // => [{a: 1}, {a: 2}] -}; - -() => { - R.equals(1, 1); // => true - R.equals("2", "1"); // => false - R.equals([1, 2, 3], [1, 2, 3]); // => true - - const a: any = {}; - a.v = a; - const b: any = {}; - b.v = b; - R.equals(a, b); // => true -}; - () => { const a1 = R.identity(1); // => 1 const obj = {}; @@ -2026,17 +1794,8 @@ class Rectangle { }; () => { - R.dec(42); // => 41 -}; - -() => { - R.divide(71, 100); // => 0.71 - const half = R.flip(R.divide)(2); half(42); // => 21 - - const reciprocal = R.divide(1); - reciprocal(4); // => 0.25 }; () => { @@ -2291,38 +2050,6 @@ class Rectangle { * Logic category */ -(() => { - R.eqBy(Math.abs, 5, -5); // => true -}); - -() => { - const defaultTo42 = R.defaultTo(42); - defaultTo42(null); // => 42 - defaultTo42(undefined); // => 42 - defaultTo42("Ramda"); // => 'Ramda' - - const valueOrUndefined = 2 as number | undefined; - defaultTo42(valueOrUndefined) - 2; // => 0 - - const valueOrNull = 2 as number | null; - defaultTo42(valueOrNull) - 2; // => 0 -}; - -() => { - function gt10(x: number) { - return x > 10; - } - - function even(x: number) { - return x % 2 === 0; - } - - const f = R.either(gt10, even); - const g = R.either(gt10)(even); - f(101); // => true - f(8); // => true -}; - () => { // Flatten all arrays in the list but leave other values alone. const flattenArrays = R.map(R.ifElse(Array.isArray, R.flatten, R.identity)); @@ -2351,15 +2078,6 @@ class Rectangle { R.isEmpty({a: 1}); // => false }; -() => { - R.endsWith("c", "abc"); // => true - R.endsWith("c")("abc"); // => true - R.endsWith(3, [1, 2, 3]); // => true - R.endsWith(3)([1, 2, 3]); // => true - R.endsWith([3], [1, 2, 3]); // => true - R.endsWith([3])([1, 2, 3]); // => true -}; - () => { R.not(true); // => false R.not(false); // => true diff --git a/types/ramda/test/countBy-tests.ts b/types/ramda/test/countBy-tests.ts new file mode 100644 index 0000000000..8ee5ab9dcf --- /dev/null +++ b/types/ramda/test/countBy-tests.ts @@ -0,0 +1,8 @@ +import * as R from 'ramda'; + +() => { + const numbers = [1.0, 1.1, 1.2, 2.0, 3.0, 2.2]; + const letters = R.split('', 'abcABCaaaBBc'); + R.countBy(Math.floor)(numbers); // => {'1': 3, '2': 2, '3': 1} + R.countBy(R.toLower)(letters); // => {'a': 5, 'b': 4, 'c': 3} +}; diff --git a/types/ramda/test/curry-tests.ts b/types/ramda/test/curry-tests.ts new file mode 100644 index 0000000000..62001f5339 --- /dev/null +++ b/types/ramda/test/curry-tests.ts @@ -0,0 +1,84 @@ +import * as R from 'ramda'; + +() => { + function addFourNumbers(a: number, b: number, c: number, d: number): number { + return a + b + c + d; + } + + function addTenFixedNumbers( + a: 0, + b: 1, + c: 2, + d: 3, + e: 4, + f: 5, + g: 6, + h: 7, + i: 8, + k: 9, + l: 10, + ): number { + return a + b + c + d; + } + + const x1: (a: number, b: number, c: number, d: number) => number = R.curry( + addFourNumbers, + ); + // because of the current way of currying, the following call results in a type error + const x2: (...args: any) => any = R.curry(addFourNumbers)(1, 2, 4); + const x3: (c: number, d: number) => number = R.curry(addFourNumbers)(1)(2); + const x4: (d: number) => number = R.curry(addFourNumbers)(1)(2)(3); + const y1: number = R.curry(addFourNumbers)(1)(2)(3)(4); + const y2: number = R.curry(addFourNumbers)(1, 2)(3, 4); + const y3: number = R.curry(addFourNumbers)(1, 2, 3)(4); + const y4: number = R.curry(addTenFixedNumbers)(R.__, 1, 2)(0)(3)(R.__, R.__)( + R.__, + 5, + )(4)(6, 7)(R.__)(8, R.__, R.__)(9, 10); + const y5: number = R.curry(addTenFixedNumbers)(R.__, 1, R.__)(R.__, 2)(0, 3)( + R.__, + 5, + )(4, R.__)(R.__)(6, R.__, 8, 9, 10)(7); + + function addTwoNumbers(a: number, b: number) { + return a + b; + } + + const addTwoNumbersCurried = R.curry(addTwoNumbers); + + const inc = addTwoNumbersCurried(1); + const z1: number = inc(2); + const z2: number = addTwoNumbersCurried(2, 3); +}; + +() => { + interface Car { + speed?: number; + } + interface FastCar { + speed: number; + } + + function typeGuard( + a: number, + b: number, + c: number, + d: number, + e: number, + car: Car, + ): car is FastCar { + return car.speed !== undefined; + } + + const typeGuardCurried = R.curry(typeGuard); + + function drive(fastCar: FastCar) {} + + const cars: Car[] = [{ speed: 65 }, {}]; + for (const car of cars) { + if (typeGuardCurried(1)(2)(3)(4)(5)(car)) { + drive(car); // $ExpectError + // Generic Curry solved a previously non reported issue + } + } +}; diff --git a/types/ramda/test/dec-tests.ts b/types/ramda/test/dec-tests.ts new file mode 100644 index 0000000000..ee26c5cf8c --- /dev/null +++ b/types/ramda/test/dec-tests.ts @@ -0,0 +1,5 @@ +import * as R from 'ramda'; + +() => { + R.dec(42); // => 41 +}; diff --git a/types/ramda/test/defaultTo-tests.ts b/types/ramda/test/defaultTo-tests.ts new file mode 100644 index 0000000000..da558d5af8 --- /dev/null +++ b/types/ramda/test/defaultTo-tests.ts @@ -0,0 +1,14 @@ +import * as R from 'ramda'; + +() => { + const defaultTo42 = R.defaultTo(42); + defaultTo42(null); // => 42 + defaultTo42(undefined); // => 42 + defaultTo42('Ramda'); // => 'Ramda' + + const valueOrUndefined = 2 as number | undefined; + defaultTo42(valueOrUndefined) - 2; // => 0 + + const valueOrNull = 2 as number | null; + defaultTo42(valueOrNull) - 2; // => 0 +}; diff --git a/types/ramda/test/difference-tests.ts b/types/ramda/test/difference-tests.ts new file mode 100644 index 0000000000..01fca15136 --- /dev/null +++ b/types/ramda/test/difference-tests.ts @@ -0,0 +1,6 @@ +import * as R from 'ramda'; + +() => { + R.difference([1, 2, 3, 4], [7, 6, 5, 4, 3]); // => [1,2] + R.difference([7, 6, 5, 4, 3], [1, 2, 3, 4]); // => [7,6,5] +}; diff --git a/types/ramda/test/differenceWith-tests.ts b/types/ramda/test/differenceWith-tests.ts new file mode 100644 index 0000000000..4888be6705 --- /dev/null +++ b/types/ramda/test/differenceWith-tests.ts @@ -0,0 +1,21 @@ +import * as R from 'ramda'; + +() => { + function cmp1(x: any, y: any) { + return x.a === y.a; + } + + function cmp2(x: any, y: any) { + return x.a === y.b; + } + + const l1 = [{ a: 1 }, { a: 2 }, { a: 3 }]; + const l2 = [{ a: 3 }, { a: 4 }]; + const l3 = [{ b: 3 }, { b: 4 }]; + R.differenceWith(cmp1, l1, l2); // => [{a: 1}, {a: 2}] + + const differenceWithCurried1 = R.differenceWith(cmp1); + differenceWithCurried1(l1, l2); // =>[{a: 1}, {a: 2}] + + R.differenceWith(cmp2, l1, l3); // => [{a: 1}, {a: 2}] +}; diff --git a/types/ramda/test/dissoc-tests.ts b/types/ramda/test/dissoc-tests.ts new file mode 100644 index 0000000000..68b07c9426 --- /dev/null +++ b/types/ramda/test/dissoc-tests.ts @@ -0,0 +1,7 @@ +import * as R from 'ramda'; + +() => { + const a1 = R.dissoc<{ a: number; c: number }>('b', { a: 1, b: 2, c: 3 }); // => {a: 1, c: 3} + const a2 = R.dissoc('b', { a: 1, b: 2, c: 3 }); // => {a: 1, c: 3} + const a4 = R.dissoc('b')<{ a: number; c: number }>({ a: 1, b: 2, c: 3 }); // => {a: 1, c: 3} +}; diff --git a/types/ramda/test/dissocPath-tests.ts b/types/ramda/test/dissocPath-tests.ts new file mode 100644 index 0000000000..a5a1f23585 --- /dev/null +++ b/types/ramda/test/dissocPath-tests.ts @@ -0,0 +1,16 @@ +import * as R from 'ramda'; + +() => { + const a1 = R.dissocPath(['a', 'b', 'c'], { a: { b: { c: 42 } } }); // => {a: {b: {}}} + // optionally specify return type + const a2 = R.dissocPath<{ a: { b: number } }>(['a', 'b', 'c'], { + a: { b: { c: 42 } }, + }); // => {a: {b: {}}} + const a3 = R.dissocPath(['a', 'b', 'c'])({ a: { b: { c: 42 } } }); // => {a: {b: {}}} + + const testPath = ['x', 0, 'y']; + const testObj = { x: [{ y: 2, z: 3 }, { y: 4, z: 5 }] }; + + R.dissocPath(testPath, testObj); // => {x: [{z: 3}, {y: 4, z: 5}]} + R.dissocPath(testPath)(testObj); // => {x: [{z: 3}, {y: 4, z: 5}]} +}; diff --git a/types/ramda/test/divide-tests.ts b/types/ramda/test/divide-tests.ts new file mode 100644 index 0000000000..e765e153d9 --- /dev/null +++ b/types/ramda/test/divide-tests.ts @@ -0,0 +1,8 @@ +import * as R from 'ramda'; + +() => { + R.divide(71, 100); // => 0.71 + + const reciprocal = R.divide(1); + reciprocal(4); // => 0.25 +}; diff --git a/types/ramda/test/drop-tests.ts b/types/ramda/test/drop-tests.ts new file mode 100644 index 0000000000..f0dee121e9 --- /dev/null +++ b/types/ramda/test/drop-tests.ts @@ -0,0 +1,8 @@ +import * as R from 'ramda'; + +() => { + R.drop(3, [1, 2, 3, 4, 5, 6, 7]); // => [4,5,6,7] + R.drop(3)([1, 2, 3, 4, 5, 6, 7]); // => [4,5,6,7] + R.drop(3, 'ramda'); // => 'ram' + R.drop(3)('ramda'); // => 'ram' +}; diff --git a/types/ramda/test/dropLast-tests.ts b/types/ramda/test/dropLast-tests.ts new file mode 100644 index 0000000000..31ad6e43ee --- /dev/null +++ b/types/ramda/test/dropLast-tests.ts @@ -0,0 +1,8 @@ +import * as R from 'ramda'; + +() => { + R.dropLast(1, ['foo', 'bar', 'baz']); // => ['foo', 'bar'] + R.dropLast(2)(['foo', 'bar', 'baz']); // => ['foo'] + R.dropLast(3, 'ramda'); // => 'ra' + R.dropLast(3)('ramda'); // => 'ra' +}; diff --git a/types/ramda/test/dropLastWhile-tests.ts b/types/ramda/test/dropLastWhile-tests.ts new file mode 100644 index 0000000000..01f079961a --- /dev/null +++ b/types/ramda/test/dropLastWhile-tests.ts @@ -0,0 +1,6 @@ +import * as R from 'ramda'; + +() => { + const lteThree = (x: number) => x <= 3; + R.dropLastWhile(lteThree, [1, 2, 3, 4, 3, 2, 1]); // => [1, 2, 3, 4] +}; diff --git a/types/ramda/test/dropRepeats-tests.ts b/types/ramda/test/dropRepeats-tests.ts new file mode 100644 index 0000000000..e50f24faab --- /dev/null +++ b/types/ramda/test/dropRepeats-tests.ts @@ -0,0 +1,5 @@ +import * as R from 'ramda'; + +() => { + R.dropRepeats([1, 1, 1, 2, 3, 4, 4, 2, 2]); // => [1, 2, 3, 4, 2] +}; diff --git a/types/ramda/test/dropRepeatsWith-tests.ts b/types/ramda/test/dropRepeatsWith-tests.ts new file mode 100644 index 0000000000..04e121c95a --- /dev/null +++ b/types/ramda/test/dropRepeatsWith-tests.ts @@ -0,0 +1,6 @@ +import * as R from 'ramda'; + +() => { + const l = [1, -1, 1, 3, 4, -4, -4, -5, 5, 3, 3]; + const x: number[] = R.dropRepeatsWith(R.eqBy(Math.abs), l); // => [1, 3, 4, -5, 3] +}; diff --git a/types/ramda/test/dropWhile-tests.ts b/types/ramda/test/dropWhile-tests.ts new file mode 100644 index 0000000000..4d7187fbbf --- /dev/null +++ b/types/ramda/test/dropWhile-tests.ts @@ -0,0 +1,10 @@ +import * as R from 'ramda'; + +() => { + function lteTwo(x: number) { + return x <= 2; + } + + R.dropWhile(lteTwo, [1, 2, 3, 4]); // => [3, 4] + R.dropWhile(lteTwo)([1, 2, 3, 4]); // => [3, 4] +}; diff --git a/types/ramda/test/either-tests.ts b/types/ramda/test/either-tests.ts new file mode 100644 index 0000000000..b32f713050 --- /dev/null +++ b/types/ramda/test/either-tests.ts @@ -0,0 +1,16 @@ +import * as R from 'ramda'; + +() => { + function gt10(x: number) { + return x > 10; + } + + function even(x: number) { + return x % 2 === 0; + } + + const f = R.either(gt10, even); + const g = R.either(gt10)(even); + f(101); // => true + f(8); // => true +}; diff --git a/types/ramda/test/empty-tests.ts b/types/ramda/test/empty-tests.ts new file mode 100644 index 0000000000..a571fc755c --- /dev/null +++ b/types/ramda/test/empty-tests.ts @@ -0,0 +1,8 @@ +import * as R from 'ramda'; + +() => { + const a1 = R.empty([1, 2, 3, 4, 5]); // => [] + const a2 = R.empty([1, 2, 3]); // => [] + const a3 = R.empty('unicorns'); // => '' + const a4 = R.empty({ x: 1, y: 2 }); // => {} +}; diff --git a/types/ramda/test/endsWith-tests.ts b/types/ramda/test/endsWith-tests.ts new file mode 100644 index 0000000000..e579bfff84 --- /dev/null +++ b/types/ramda/test/endsWith-tests.ts @@ -0,0 +1,10 @@ +import * as R from 'ramda'; + +() => { + R.endsWith('c', 'abc'); // => true + R.endsWith('c')('abc'); // => true + R.endsWith(3, [1, 2, 3]); // => true + R.endsWith(3)([1, 2, 3]); // => true + R.endsWith([3], [1, 2, 3]); // => true + R.endsWith([3])([1, 2, 3]); // => true +}; diff --git a/types/ramda/test/eqBy-tests.ts b/types/ramda/test/eqBy-tests.ts new file mode 100644 index 0000000000..4cc7acf965 --- /dev/null +++ b/types/ramda/test/eqBy-tests.ts @@ -0,0 +1,5 @@ +import * as R from 'ramda'; + +() => { + R.eqBy(Math.abs, 5, -5); // => true +}; diff --git a/types/ramda/test/eqProps-tests.ts b/types/ramda/test/eqProps-tests.ts new file mode 100644 index 0000000000..34467abc75 --- /dev/null +++ b/types/ramda/test/eqProps-tests.ts @@ -0,0 +1,13 @@ +import * as R from 'ramda'; + +() => { + const o1 = { a: 1, b: 2, c: 3, d: 4 }; + const o2 = { a: 10, b: 20, c: 3, d: 40 }; + const a1 = R.eqProps('a', o1, o2); // => false + const a2 = R.eqProps('c', o1, o2); // => true + const a3: ( + obj1: T, + obj2: U, + ) => boolean = R.eqProps('c'); + const a4: (obj2: U) => boolean = R.eqProps('c', o1); +}; diff --git a/types/ramda/test/equals-tests.ts b/types/ramda/test/equals-tests.ts new file mode 100644 index 0000000000..c49855e1aa --- /dev/null +++ b/types/ramda/test/equals-tests.ts @@ -0,0 +1,18 @@ +import * as R from 'ramda'; + +() => { + R.equals(1, 1); // => true + R.equals('2', '1'); // => false + R.equals([1, 2, 3], [1, 2, 3]); // => true + + const a: any = {}; + a.v = a; + const b: any = {}; + b.v = b; + R.equals(a, b); // => true +}; + +() => { + R.equals(R.unnest([1, [2], [[3]]]), [1, 2, [3]]); // => true + R.equals(R.unnest([[1, 2], [3, 4], [5, 6]]), [1, 2, 3, 4, 5, 6]); // => true +}; diff --git a/types/ramda/test/evolve-tests.ts b/types/ramda/test/evolve-tests.ts new file mode 100644 index 0000000000..3adf0a1f99 --- /dev/null +++ b/types/ramda/test/evolve-tests.ts @@ -0,0 +1,61 @@ +import * as R from 'ramda'; + +() => { + // No type transformation + + const a1 = R.evolve( + { elapsed: R.add(1), remaining: R.add(-1) }, + { name: 'Tomato', elapsed: 100, remaining: 1400 }, + ); + + const a1Test: { elapsed: number; remaining: number; name: string } = a1; + + const a2 = R.evolve({ elapsed: R.add(1), remaining: R.add(-1) })({ + name: 'Tomato', + elapsed: 100, + remaining: 1400, + }); + + const a2Test: { elapsed: number; remaining: number; name: string } = a2; + + // Object doesn't have all evolver keys + + const a3 = R.evolve( + { age: R.add(1), name: R.trim }, + { name: 'Potato', elapsed: 100 }, + ); + + const a3Test: { name: string; elapsed: number } = a3; + + // Flat transformation + + const ex0 = R.evolve({ a: parseInt }, { a: '10', b: 1 }); + + const ex0Test: { a: number; b: number } = ex0; + + // Nested transformation: + + const ex1 = R.evolve( + { a: { b: R.toString, d: { e: R.toString } } }, + { a: { b: 1, c: null, d: { e: 2 } } }, + ); + + const ex1Test: { a: { b: string; c: null; d: { e: string } } } = ex1; + + // Mapping a nested object with a single function + + const ex2 = R.evolve( + { a: (obj: { foo: string }) => ({ bar: 1, baz: 2 }) }, + { a: { foo: 'a', skipped: 3 }, b: null }, + ); + + const ex2Test: { a: { bar: number; baz: number }; b: null } = ex2; + + // Nested curried: + + const ex3 = R.evolve({ a: { b: R.toString, d: { e: R.toString } } })({ + a: { b: 1, c: null, d: { e: 2 } }, + }); + + const ex3Test: { a: { b: string; c: null; d: { e: string } } } = ex3; +}; diff --git a/types/ramda/tsconfig.json b/types/ramda/tsconfig.json index f439147a25..870bd9b0f4 100644 --- a/types/ramda/tsconfig.json +++ b/types/ramda/tsconfig.json @@ -53,6 +53,28 @@ "test/construct-tests.ts", "test/constructN-tests.ts", "test/contains-tests.ts", - "test/converge-tests.ts" + "test/converge-tests.ts", + "test/countBy-tests.ts", + "test/curry-tests.ts", + "test/dec-tests.ts", + "test/defaultTo-tests.ts", + "test/difference-tests.ts", + "test/differenceWith-tests.ts", + "test/dissoc-tests.ts", + "test/dissocPath-tests.ts", + "test/divide-tests.ts", + "test/drop-tests.ts", + "test/dropLast-tests.ts", + "test/dropLastWhile-tests.ts", + "test/dropRepeats-tests.ts", + "test/dropRepeatsWith-tests.ts", + "test/dropWhile-tests.ts", + "test/either-tests.ts", + "test/empty-tests.ts", + "test/endsWith-tests.ts", + "test/eqBy-tests.ts", + "test/eqProps-tests.ts", + "test/equals-tests.ts", + "test/evolve-tests.ts" ] } \ No newline at end of file