Skip to content

Commit ca99e32

Browse files
cpruijsensumneko
authored andcommitted
test: cover whitespace-only gitignore lines matching every file
1 parent 0b8f468 commit ca99e32

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎test/basic/gitignore.lua‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
local glob = require 'glob'
2+
3+
local function ignored(patterns, path)
4+
return glob.gitignore(patterns)(path)
5+
end
6+
7+
-- #3458: a whitespace-only gitignore pattern must not match every path
8+
assert(ignored({ ' ' }, 'a.lua') == false)
9+
assert(ignored({ ' ' }, 'foo/bar.lua') == false)
10+
assert(ignored({ '\t' }, 'a.lua') == false)
11+
assert(ignored({ '' }, 'a.lua') == false)
12+
13+
-- Real patterns in the same list still match; the blank line does not take over
14+
assert(ignored({ ' ', '*.log' }, 'a.lua') == false)
15+
assert(ignored({ ' ', '*.log' }, 'a.log') == true)
16+
17+
-- Intentional match-all and ordinary names are unchanged
18+
assert(ignored({ '*' }, 'a.lua') == true)
19+
assert(ignored({ 'foo' }, 'foo') == true)
20+
assert(ignored({ 'foo' }, 'bar') == false)
21+
22+
-- Quoted trailing space is a real pattern (gitignore spec), not a blank line
23+
assert(ignored({ '\\ ' }, 'a.lua') == false)
24+
assert(ignored({ '\\ ' }, ' ') == true)
25+
26+
-- glob.glob shares the same matcher; empty patterns must not match everything
27+
assert(glob.glob({ ' ' })('a.lua') == false)
28+
assert(glob.glob({ ' ', 'foo' })('foo') == true)
29+
assert(glob.glob({ ' ', 'foo' })('bar') == false)
30+
assert(glob.glob({ '*' })('a.lua') == true)

‎test/basic/init.lua‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
require 'basic.textmerger'
22
require 'basic.filewatch'
3+
require 'basic.gitignore'

0 commit comments

Comments
 (0)