Skip to content

Commit

Permalink
feat(tests): add tests & fix merge;
Browse files Browse the repository at this point in the history
  • Loading branch information
5-pebbles committed Jun 15, 2024
1 parent 21c2ca9 commit e61d2a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions lua/nordic/tests/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ assert_eq(U.is_none('NONE'), true, 'U.is_none("NONE") should return true')
assert_eq(U.is_none('none'), true, 'U.is_none("none") should return true')
assert_eq(U.is_none('nil'), false, 'U.is_none("nil") should return false')

-- merge
assert_eq(U.merge({}, {}), {}, 'M.merge({}, {}) should return an empty table')

assert_eq(U.merge(nil, nil), {}, 'M.merge(nil, nil) should return an empty table')

assert_eq(U.merge(nil, {a = 1}), {a = 1}, 'M.merge(nil, {a = 1}) should return {a = 1}')
assert_eq(U.merge({a = 1}, nil), {a = 1}, 'M.merge({a = 1}, nil) should return {a = 1}')

assert_eq(U.merge({a = 1, b = 3}, {b = 2, c = 4}), {a = 1, b = 2, c = 4}, 'M.merge({a = 1, b = 3}, {b = 2, c = 4}) should return {a = 1, b = 2, c = 4}')

-- hex_to_rgb
assert_eq({ U.hex_to_rgb('#191D24') }, {25, 29, 36}, 'M.hex_to_rgb("#191D24") should return 25, 29, 36')

Expand Down
4 changes: 2 additions & 2 deletions lua/nordic/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ end
function M.merge(table1, table2)
if table1 == table2 == nil then return {} end
if table1 == nil then
return table2
return table2 or {}
elseif table2 == nil then
return table1
return table1 or {}
end
return vim.tbl_deep_extend('force', table1, table2)
end
Expand Down

0 comments on commit e61d2a5

Please sign in to comment.