lib/ignore: Ignore duplicate lines in .stignore

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4350
LGTM: AudriusButkevicius, calmh
This commit is contained in:
Simon Frei
2017-09-04 12:46:19 +00:00
committed by Jakob Borg
parent 9682bbfbda
commit c41aaad3bb
2 changed files with 58 additions and 21 deletions

View File

@@ -872,6 +872,7 @@ func TestLines(t *testing.T) {
!/a
/*
!/a
`
pats := New(fs.NewFilesystem(fs.FilesystemTypeBasic, "."), WithCache(true))
@@ -886,6 +887,7 @@ func TestLines(t *testing.T) {
"",
"!/a",
"/*",
"!/a",
"",
}
@@ -898,5 +900,33 @@ func TestLines(t *testing.T) {
t.Fatalf("Lines()[%d] == %s, expected %s", i, lines[i], expectedLines[i])
}
}
}
func TestDuplicateLines(t *testing.T) {
stignore := `
!/a
/*
!/a
`
stignoreFiltered := `
!/a
/*
`
pats := New(fs.NewFilesystem(fs.FilesystemTypeBasic, "testdata"), WithCache(true))
err := pats.Parse(bytes.NewBufferString(stignore), ".stignore")
if err != nil {
t.Fatal(err)
}
patsLen := len(pats.patterns)
err = pats.Parse(bytes.NewBufferString(stignoreFiltered), ".stignore")
if err != nil {
t.Fatal(err)
}
if patsLen != len(pats.patterns) {
t.Fatalf("Parsed patterns differ when manually removing duplicate lines")
}
}