Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass of introducing protocols for associative and indexed values
- Loading branch information
1 parent
4c34ed0
commit 58e2347
Showing
106 changed files
with
906 additions
and
360 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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import 'babel-polyfill' | ||
import { delete as _delete } from '../' | ||
import { withHintSameType, withMultipleTypeInputs } from './recompose' | ||
import { immutableTest } from './tests' | ||
import { indexed, keyed } from './types' | ||
import { compose, runTests, setupTest } from './util' | ||
|
||
const enhance = compose( | ||
withMultipleTypeInputs, | ||
withHintSameType | ||
) | ||
|
||
const testDelete = enhance(immutableTest(({ data, path }) => _delete(data, path))) | ||
|
||
describe('delete', function() { | ||
const context = setupTest() | ||
const { Symbol } = context | ||
|
||
const symbolA = Symbol('a') | ||
|
||
const tests = { | ||
'should delete indexed `data` on `path`': { | ||
inputs: { | ||
data: { | ||
value: ['a', 'b', 'c'], | ||
types: indexed() | ||
}, | ||
path: { | ||
value: 1 | ||
} | ||
}, | ||
expected: ['a', 'c'] | ||
}, | ||
'should delete keyed `data` on `path`': { | ||
inputs: { | ||
data: { | ||
value: { 'a':1, 'b':2, 'c':3 }, | ||
types: keyed() | ||
}, | ||
path: { | ||
value: 'c' | ||
} | ||
}, | ||
expected: { 'a':1, 'b':2 } | ||
}, | ||
'should delete deep `data` on `path` with nested object': { | ||
inputs: { | ||
data: { | ||
value: { 'a':1, 'b':2, 'c': { 'd': 3, 'e': 4 } }, | ||
types: keyed() | ||
}, | ||
path: { | ||
value: 'c.d' | ||
} | ||
}, | ||
expected: { 'a':1, 'b':2, 'c': { 'e': 4 } } | ||
}, | ||
'should delete deep `data` on `path` with nested array': { | ||
inputs: { | ||
data: { | ||
value: { 'a':1, 'b':2, 'c': [3, 4, 5] }, | ||
types: keyed() | ||
}, | ||
path: { | ||
value: 'c.1' | ||
} | ||
}, | ||
expected: { 'a':1, 'b':2, 'c': [3, 5] } | ||
}, | ||
'should delete keyed `data` with symbol `path`': { | ||
inputs: { | ||
data: { | ||
value: { [symbolA]:1, 'b':2, 'c':3 } | ||
//types: keyed() //TODO BRN: immutable types do not seem to be working with symbols | ||
}, | ||
path: { | ||
value: symbolA | ||
} | ||
}, | ||
expected: { 'b':2, 'c':3 } | ||
} | ||
} | ||
|
||
runTests(tests, context, testDelete) | ||
}) |
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,69 @@ | ||
import 'babel-polyfill' | ||
import { expect } from 'chai' | ||
import { push } from '../' | ||
import Immutable from 'immutable' | ||
import { withHintSameType, withMultipleTypeInputs } from './recompose' | ||
import { immutableTest } from './tests' | ||
import { indexed, indexedWithoutStack, stack } from './types' | ||
import { compose, runTests, setupTest } from './util' | ||
|
||
describe('push', function() { | ||
const enhance = compose( | ||
withMultipleTypeInputs, | ||
withHintSameType | ||
) | ||
|
||
const testPush = enhance(immutableTest(({ data, values }) => push(data, ...values))) | ||
|
||
it('pushes to mutable array', function() { | ||
const array = [] | ||
const result = push(array, 'test1') | ||
expect(result).not.to.equal(array) //expect new array | ||
expect(array).to.deep.equal([]) //do no modify array | ||
expect(result).to.deep.equal([ | ||
'test1' | ||
]) | ||
}) | ||
describe('push', function() { | ||
|
||
it('returns array if data is empty', function() { | ||
const data = null | ||
const result = push(data, 'test1') | ||
expect(result).to.deep.equal([ | ||
'test1' | ||
]) | ||
}) | ||
const context = setupTest() | ||
const tests = { | ||
'pushes `values` to empty indexed `data`': { | ||
inputs: { | ||
data: { | ||
value: [], | ||
types: indexed() | ||
}, | ||
values: { | ||
value: ['a'] | ||
} | ||
}, | ||
expected: ['a'] | ||
}, | ||
'pushes `value` to null data': { | ||
inputs: { | ||
data: { | ||
value: null | ||
}, | ||
values: { | ||
value: ['b'] | ||
} | ||
}, | ||
expected: ['b'] | ||
}, | ||
'pushes multiple `values` to indexed `data`': { | ||
inputs: { | ||
data: { | ||
value: ['a'], | ||
types: indexedWithoutStack() | ||
}, | ||
values: { | ||
value: [ 'b', 'c' ] | ||
} | ||
}, | ||
expected: [ 'a', 'b', 'c' ] | ||
}, | ||
'pushes multiple `values` to front of `Stack`': { | ||
inputs: { | ||
data: { | ||
value: ['a'], | ||
types: stack() | ||
}, | ||
values: { | ||
value: [ 'b', 'c' ] | ||
} | ||
}, | ||
expected: [ 'b', 'c', 'a' ] | ||
} | ||
} | ||
|
||
it('pushes to immutable List', function() { | ||
const data = Immutable.fromJS([]) | ||
const result = push(data, 'test1') | ||
expect(result).not.to.equal(data) //expect new array | ||
expect(Immutable.List.isList(result)).to.be.true | ||
expect(result.toJS()).to.deep.equal([ | ||
'test1' | ||
]) | ||
}) | ||
runTests(tests, context, testPush) | ||
}) |
Oops, something went wrong.