Skip to content

Commit 70fbb99

Browse files
committed
test: add some more tests
Just to show that `ignore_case` and `smart_case` interplay the way I describe here: - #431 Note that we're testing the matcher directly here, so Neovim settings and defaults play no role in these tests. If you look at the definition of `matcher_new` in "lua/wincent/commandt/private/lib.lua", you can see where we set both `ignore_case` and `smart_case` to `true`. When running inside Neovim, things are a little bit different, because if you don't set an explicit value for these settings, we grab `vim.o.ignorecase` and `vim.o.smartcase` (see "lua/wincent/commandt/init.lua" for that).
1 parent 6a0518f commit 70fbb99

File tree

1 file changed

+58
-12
lines changed

1 file changed

+58
-12
lines changed

lua/wincent/commandt/test/matcher.lua

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,69 @@ describe('matcher.c', function()
5858
expect(matcher.match('')).to_equal({ 'foo' })
5959
end)
6060

61-
it('performs case-insensitive matching', function()
62-
local matcher = get_matcher({ 'Foo' })
63-
expect(matcher.match('f')).to_equal({ 'Foo' })
61+
context('`ignore_case = false` and `smart_case = false`', function()
62+
it('performs case-sensitive matching', function()
63+
local matcher = get_matcher({ 'Foo' }, {
64+
ignore_case = false,
65+
smart_case = false,
66+
})
67+
expect(matcher.match('F')).to_equal({ 'Foo' })
68+
expect(matcher.match('o')).to_equal({ 'Foo' })
69+
expect(matcher.match('f')).to_equal({})
70+
expect(matcher.match('O')).to_equal({})
71+
expect(matcher.match('b')).to_equal({})
72+
end)
6473
end)
6574

66-
it('performs case-sensitive matching when configured to do so', function()
67-
local matcher = get_matcher({ 'Foo' }, { ignore_case = false })
68-
expect(matcher.match('b')).to_equal({})
69-
expect(matcher.match('f')).to_equal({})
70-
expect(matcher.match('F')).to_equal({ 'Foo' })
75+
context('`ignore_case = false` and `smart_case = true`', function()
76+
it('performs case-sensitive matching', function()
77+
local matcher = get_matcher({ 'Foo' }, {
78+
ignore_case = false,
79+
smart_case = true,
80+
})
81+
expect(matcher.match('F')).to_equal({ 'Foo' })
82+
expect(matcher.match('o')).to_equal({ 'Foo' })
83+
expect(matcher.match('f')).to_equal({})
84+
expect(matcher.match('O')).to_equal({})
85+
expect(matcher.match('b')).to_equal({})
86+
end)
7187
end)
7288

73-
it('performs smart-case matching when configured to do so', function()
74-
local matcher = get_matcher({ 'Foo' }, { smart_case = true })
75-
expect(matcher.match('b')).to_equal({})
76-
expect(matcher.match('f')).to_equal({ 'Foo' })
89+
context('`ignore_case = true` and `smart_case = false`', function()
90+
it('performs case-insensitive matching', function()
91+
local matcher = get_matcher({ 'Foo' }, {
92+
ignore_case = true,
93+
smart_case = false,
94+
})
95+
expect(matcher.match('F')).to_equal({ 'Foo' })
96+
expect(matcher.match('f')).to_equal({ 'Foo' })
97+
expect(matcher.match('O')).to_equal({ 'Foo' })
98+
expect(matcher.match('o')).to_equal({ 'Foo' })
99+
expect(matcher.match('b')).to_equal({})
100+
end)
101+
end)
102+
103+
context('`ignore_case = true` and `smart_case = true`', function()
104+
it('performs case-insensitive matching unless search pattern contains uppercase characters', function()
105+
local matcher = get_matcher({ 'Foo' }, {
106+
ignore_case = true,
107+
smart_case = true,
108+
})
109+
expect(matcher.match('F')).to_equal({ 'Foo' })
110+
expect(matcher.match('f')).to_equal({ 'Foo' })
111+
expect(matcher.match('O')).to_equal({})
112+
expect(matcher.match('o')).to_equal({ 'Foo' })
113+
expect(matcher.match('b')).to_equal({})
114+
end)
115+
end)
116+
117+
it('defaults `ignore_case` and `smart_case` to `true`', function()
118+
local matcher = get_matcher({ 'Foo' })
77119
expect(matcher.match('F')).to_equal({ 'Foo' })
120+
expect(matcher.match('f')).to_equal({ 'Foo' })
121+
expect(matcher.match('O')).to_equal({})
122+
expect(matcher.match('o')).to_equal({ 'Foo' })
123+
expect(matcher.match('b')).to_equal({})
78124
end)
79125

80126
-- We don't expect to see these in practice, but we still want to test it.

0 commit comments

Comments
 (0)