-
Notifications
You must be signed in to change notification settings - Fork 89
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
Deyan Totev
committed
Jan 4, 2024
1 parent
180d9f2
commit b295779
Showing
10 changed files
with
156 additions
and
170 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
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 |
---|---|---|
@@ -1,43 +1,34 @@ | ||
import { hasIn } from './hasIn' | ||
import { hasIn as hasInRamda } from 'ramda' | ||
|
||
test('happy', () => { | ||
const result = hasIn() | ||
console.log(result) | ||
}) | ||
|
||
/* | ||
var R = require('../source/index.js') | ||
var eq = require('./shared/eq.js') | ||
describe('hasIn', function () { | ||
var fred = {name: 'Fred', age: 23} | ||
var anon = {age: 99} | ||
import { hasIn } from './hasIn.js' | ||
|
||
it('returns a function that checks the appropriate property', function () { | ||
var nm = R.hasIn('name') | ||
eq(typeof nm, 'function') | ||
eq(nm(fred), true) | ||
eq(nm(anon), false) | ||
}) | ||
const fred = { | ||
age : 23, | ||
name : 'Fred', | ||
} | ||
const anon = { age : 99 } | ||
|
||
it('checks properties from the prototype chain', function () { | ||
var Person = function () {} | ||
Person.prototype.age = function () {} | ||
test('returns a function that checks the appropriate property', () => { | ||
const nm = hasIn('name') | ||
expect(typeof nm).toBe('function') | ||
expect(nm(fred)).toBe(true) | ||
expect(nm(anon)).toBe(false) | ||
}) | ||
|
||
var bob = new Person() | ||
eq(R.hasIn('age', bob), true) | ||
}) | ||
test('checks properties from the prototype chain', () => { | ||
function Person(){} | ||
Person.prototype.age = function (){} | ||
|
||
it('works properly when called with two arguments', function () { | ||
eq(R.hasIn('name', fred), true) | ||
eq(R.hasIn('name', anon), false) | ||
}) | ||
const bob = new Person() | ||
expect(hasIn('age', bob)).toBe(true) | ||
}) | ||
|
||
it('returns false when non-existent object', function () { | ||
eq(R.hasIn('name', null), false) | ||
eq(R.hasIn('name', undefined), false) | ||
}) | ||
test('works properly when called with two arguments', () => { | ||
expect(hasIn('name', fred)).toBe(true) | ||
expect(hasIn('name', anon)).toBe(false) | ||
}) | ||
|
||
*/ | ||
test('returns false when non-existent object', () => { | ||
expect(hasIn('name', null)).toBe(false) | ||
expect(hasIn('name', undefined)).toBe(false) | ||
}) |
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,35 +1,30 @@ | ||
import { innerJoin } from './innerJoin' | ||
import { innerJoin as innerJoinRamda } from 'ramda' | ||
|
||
test('happy', () => { | ||
const result = innerJoin() | ||
console.log(result) | ||
}) | ||
import { innerJoin } from './innerJoin.js' | ||
|
||
/* | ||
var R = require('../source/index.js') | ||
var eq = require('./shared/eq.js') | ||
const a = { | ||
id : 1, | ||
name : 'a', | ||
} | ||
const b = { | ||
id : 2, | ||
name : 'b', | ||
} | ||
const c = { | ||
id : 3, | ||
name : 'c', | ||
} | ||
const f = innerJoin((r, id) => r.id === id) | ||
|
||
var a = {id: 1, name: 'a'} | ||
var b = {id: 2, name: 'b'} | ||
var c = {id: 3, name: 'c'} | ||
var f = R.innerJoin(function (r, id) { | ||
return r.id === id | ||
test('only returns elements from the first list', () => { | ||
expect(f([ a, b, c ], [])).toEqual([]) | ||
expect(f([ a, b, c ], [ 1 ])).toEqual([ a ]) | ||
expect(f([ a, b, c ], [ 1, 2 ])).toEqual([ a, b ]) | ||
expect(f([ a, b, c ], [ 1, 2, 3 ])).toEqual([ a, b, c ]) | ||
expect(f([ a, b, c ], [ 1, 2, 3, 4 ])).toEqual([ a, b, c ]) | ||
}) | ||
|
||
describe('innerJoin', function () { | ||
it('only returns elements from the first list', function () { | ||
eq(f([a, b, c], []), []) | ||
eq(f([a, b, c], [1]), [a]) | ||
eq(f([a, b, c], [1, 2]), [a, b]) | ||
eq(f([a, b, c], [1, 2, 3]), [a, b, c]) | ||
eq(f([a, b, c], [1, 2, 3, 4]), [a, b, c]) | ||
}) | ||
it('does not remove duplicates', function () { | ||
eq(f([a, a, a], [1, 2, 3]), [a, a, a]) | ||
eq(f([a, b, c], [1, 1, 1]), [a]) | ||
}) | ||
test('does not remove duplicates', () => { | ||
expect(f([ a, a, a ], [ 1, 2, 3 ])).toEqual([ a, a, a ]) | ||
expect(f([ a, b, c ], [ 1, 1, 1 ])).toEqual([ a ]) | ||
}) | ||
*/ |
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,15 +1,52 @@ | ||
import {lens, assoc} from 'rambda' | ||
import {lens, assoc, lensProp, view, lensIndex, lensPath} from 'rambda' | ||
|
||
interface Input { | ||
foo: string, | ||
} | ||
const testObject: Input = { | ||
foo: 'Jazz', | ||
} | ||
|
||
describe('R.lens', () => { | ||
it('happy', () => { | ||
const fn = lens<Input, string, string>((x: Input) => { | ||
const fn = lens<Input, string>((x: Input) => { | ||
x.foo // $ExpectType string | ||
return x.foo | ||
}, assoc('name')) | ||
fn // $ExpectType Lens | ||
fn // $ExpectType Lens<Input, string> | ||
}) | ||
}) | ||
|
||
describe('R.lensProp', () => { | ||
it('happy', () => { | ||
const result = view<Input, string>(lensProp('foo'), testObject) | ||
result // $ExpectType string | ||
}) | ||
}) | ||
|
||
describe('R.lensIndex', () => { | ||
const testList: Input[] = [{foo: 'bar'}, {foo: 'baz'}] | ||
it('happy', () => { | ||
const result = view<Input[], Input>(lensIndex(0), testList) | ||
result // $ExpectType Input | ||
result.foo // $ExpectType string | ||
}) | ||
}) | ||
|
||
describe('R.lensPath', () => { | ||
const path = lensPath(['bar', 'a']) | ||
it('happy', () => { | ||
const result = view<Input, string>(path, testObject) | ||
result // $ExpectType string | ||
}) | ||
}) | ||
|
||
describe('R.view', () => { | ||
const fooLens = lens<Input, string>((x: Input) => { | ||
return x.foo | ||
}, assoc('foo')) | ||
it('happt', () => { | ||
const result = view<Input, string>(fooLens, testObject) | ||
result // $ExpectType string | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.