Skip to content

Commit

Permalink
test(utils): add tests for new removeHash and template
Browse files Browse the repository at this point in the history
Also adjust their doc strings slightly.
  • Loading branch information
DOD-101 committed Jan 5, 2025
1 parent f6c5752 commit fefc3cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 9 additions & 0 deletions lua/nordic/tests/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,12 @@ assert_eq(
assert_eq({ U.hex_to_rgb('#191D24') }, { 25, 29, 36 }, 'U.hex_to_rgb("#191D24") should return 25, 29, 36')
assert_eq(U.rgb_to_hex(25, 29, 36), '#191D24', 'U.rgb_to_hex(25, 29, 36) should return "#191D24"')
assert_eq(U.blend('#FFFFFF', '#000000', 0.5), '#808080', 'U.blend("#FFFFFF", ""#000000", 0.5) should return "#808080"')

assert_eq(
U.removeHash({ red = '#ff0000', green = '#00ff00', blue = { base = '#0000ff', other = '0000fb' } }),
{ red = 'ff0000', green = '00ff00', blue = { base = '0000ff', other = '0000fb' } }
)

-- Template.

assert_eq(U.template('${name} is ${age}', { name = 'Bob', age = 23 }), 'Bob is 23')
12 changes: 7 additions & 5 deletions lua/nordic/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ end

---Simple string interpolation.
---
---Example template: "${name} is ${value}"
---Example template: "${name} is ${age}"
---
--- This function is taken from tokyonight.
--- For more information see `platforms/init.lua`
---@param str string template string
---@param table table key value pairs to replace in the string
function M.template(str, table)
Expand All @@ -131,10 +133,10 @@ function M.removeHash(colors)
return output_colors
end

-- Write a file and its contents to disk
--
-- This function is taken from tokyonight.
-- For more information see `platforms/init.lua`
---Write a file and its contents to disk
---
--- This function is taken from tokyonight.
--- For more information see `platforms/init.lua`
---@param path string
---@param contents string
function M.write(path, contents)
Expand Down

0 comments on commit fefc3cc

Please sign in to comment.