robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
2.0 KiB65 linesraw
1local t = require('test.unit.testutil')
2local describe = t.describe
3local itp = t.gen_itp(t.it)
4
5local ffi = t.ffi
6local eq = t.eq
7local neq = t.neq
8
9local keycodes = t.cimport('./src/nvim/keycodes.h')
10local NULL = t.NULL
11
12describe('keycodes.c', function()
13  describe('find_special_key()', function()
14    local srcp = ffi.new('const unsigned char *[1]')
15    local modp = ffi.new('int[1]')
16
17    itp('no keycode', function()
18      srcp[0] = 'abc'
19      eq(0, keycodes.find_special_key(srcp, 3, modp, 0, NULL))
20    end)
21
22    itp('keycode with multiple modifiers', function()
23      srcp[0] = '<C-M-S-A>'
24      neq(0, keycodes.find_special_key(srcp, 9, modp, 0, NULL))
25      neq(0, modp[0])
26    end)
27
28    itp('case-insensitive', function()
29      -- Compare other capitalizations to this.
30      srcp[0] = '<C-A>'
31      local all_caps_key = keycodes.find_special_key(srcp, 5, modp, 0, NULL)
32      local all_caps_mod = modp[0]
33
34      srcp[0] = '<C-a>'
35      eq(all_caps_key, keycodes.find_special_key(srcp, 5, modp, 0, NULL))
36      eq(all_caps_mod, modp[0])
37
38      srcp[0] = '<c-A>'
39      eq(all_caps_key, keycodes.find_special_key(srcp, 5, modp, 0, NULL))
40      eq(all_caps_mod, modp[0])
41
42      srcp[0] = '<c-a>'
43      eq(all_caps_key, keycodes.find_special_key(srcp, 5, modp, 0, NULL))
44      eq(all_caps_mod, modp[0])
45    end)
46
47    itp('double-quote in keycode #7411', function()
48      -- Unescaped with in_string=false
49      srcp[0] = '<C-">'
50      eq(string.byte('"'), keycodes.find_special_key(srcp, 5, modp, 0, NULL))
51
52      -- Unescaped with in_string=true
53      eq(0, keycodes.find_special_key(srcp, 5, modp, keycodes.FSK_IN_STRING, NULL))
54
55      -- Escaped with in_string=false
56      srcp[0] = '<C-\\">'
57      -- Should fail because the key is invalid
58      -- (more than 1 non-modifier character).
59      eq(0, keycodes.find_special_key(srcp, 6, modp, 0, NULL))
60
61      -- Escaped with in_string=true
62      eq(string.byte('"'), keycodes.find_special_key(srcp, 6, modp, keycodes.FSK_IN_STRING, NULL))
63    end)
64  end)
65end)