diff options
author | Ashkan Kiani <ashkan.k.kiani@gmail.com> | 2019-10-19 12:35:55 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-19 12:35:55 -0700 |
commit | f5017b0dc1edf7c95a2696744e7a996594cde6a7 (patch) | |
tree | 712144cd6251e3ccd2d8d2c1e51c1d9311de9269 /test | |
parent | Update trie (diff) |
Refactor (#19)
- Refactor and clean up old code.
- Fix the trie printing (it's perfect now :o)
- Add the ability to search from a starting point. This can help
avoid allocations.
- Avoid an allocation in longest_prefix.
- Refactor and allow configuring of color_name_parser setup
Diffstat (limited to 'test')
-rw-r--r-- | test/expectation.txt | 7 | ||||
-rw-r--r-- | test/print-trie.lua | 62 |
2 files changed, 66 insertions, 3 deletions
diff --git a/test/expectation.txt b/test/expectation.txt index 915d4de..7813fe8 100644 --- a/test/expectation.txt +++ b/test/expectation.txt @@ -8,9 +8,9 @@ require'colorizer'.attach_to_buffer(0, {css=true}) #F0F #FF00FF #FFF00F8F - #F0F 1 - #FF00FF 1 - #FFF00F8F 1 + #F0F #F00 + #FF00FF #F00 + #FFF00F8F #F00 Blue Gray LightBlue Gray100 White White #def @@ -22,6 +22,7 @@ hsl(300,50%,50%) hsla(300,50%,50%,0.5) hsla(300,50%,50%,1.0000000000000001) hsla(360,50%,50%,1.0000000000000001) +blue gray lightblue gray100 white gold blue ]] --[[ FAIL diff --git a/test/print-trie.lua b/test/print-trie.lua new file mode 100644 index 0000000..2ec1322 --- /dev/null +++ b/test/print-trie.lua @@ -0,0 +1,62 @@ +-- TODO this is kinda shitty +local function dirname(str,sep) + sep=sep or'/' + return str:match("(.*"..sep..")") +end + +local script_dir = dirname(arg[0]) +package.path = script_dir.."/../lua/?.lua;"..package.path + +local Trie = require 'trie' +local nvim = require 'nvim' + +local function print_color_trie() + local tohex = bit.tohex + local min, max = math.min, math.max + + local COLOR_NAME_SETTINGS = { + lowercase = false; + strip_digits = true; + } + local COLOR_MAP = {} + local COLOR_TRIE = Trie() + for k, v in pairs(nvim.get_color_map()) do + if not (COLOR_NAME_SETTINGS.strip_digits and k:match("%d+$")) then + COLOR_NAME_MINLEN = COLOR_NAME_MINLEN and min(#k, COLOR_NAME_MINLEN) or #k + COLOR_NAME_MAXLEN = COLOR_NAME_MAXLEN and max(#k, COLOR_NAME_MAXLEN) or #k + COLOR_MAP[k] = tohex(v, 6) + COLOR_TRIE:insert(k) + if COLOR_NAME_SETTINGS.lowercase then + local lowercase = k:lower() + COLOR_MAP[lowercase] = tohex(v, 6) + COLOR_TRIE:insert(lowercase) + end + end + end + print(COLOR_TRIE) +end + +local trie = Trie { + "cat"; + "car"; + "celtic"; + "carb"; + "carb0"; + "CART0"; + "CaRT0"; + "Cart0"; + "931"; + "191"; + "121"; + "cardio"; + "call"; + "calcium"; + "calciur"; + "carry"; + "dog"; + "catdog"; +} + +print(trie) +print("catdo", trie:longest_prefix("catdo")) +print("catastrophic", trie:longest_prefix("catastrophic")) |