forked from dotnet/Nerdbank.GitVersioning
/
FilterPathTests.cs
106 lines (99 loc) · 5.04 KB
/
FilterPathTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using Nerdbank.GitVersioning;
using Xunit;
public class FilterPathTests
{
[Theory]
[InlineData("./", "foo", "foo")]
[InlineData("../relative-dir", "foo", "relative-dir")]
[InlineData("../../some/dir/here", "foo/multi/wow", "foo/some/dir/here")]
[InlineData("relativepath.txt", "foo", "foo/relativepath.txt")]
[InlineData("./relativepath.txt", "foo", "foo/relativepath.txt")]
[InlineData("./dir\\hi/relativepath.txt", "foo", "foo/dir/hi/relativepath.txt")]
[InlineData(".\\relativepath.txt", "foo", "foo/relativepath.txt")]
[InlineData(":^relativepath.txt", "foo", "foo/relativepath.txt")]
[InlineData(":!relativepath.txt", "foo", "foo/relativepath.txt")]
[InlineData(":!/absolutepath.txt", "foo", "absolutepath.txt")]
[InlineData(":!\\absolutepath.txt", "foo", "absolutepath.txt")]
[InlineData("../bar/relativepath.txt", "foo", "bar/relativepath.txt")]
[InlineData("/", "foo", "")]
[InlineData("/absolute/file.txt", "foo", "absolute/file.txt")]
[InlineData(":/", "foo", "")]
[InlineData(":/absolutepath.txt", "foo", "absolutepath.txt")]
[InlineData(":/bar/absolutepath.txt", "foo", "bar/absolutepath.txt")]
[InlineData(":\\bar\\absolutepath.txt", "foo", "bar/absolutepath.txt")]
public void CanBeParsedToRepoRelativePath(string pathSpec, string relativeTo, string expected)
{
Assert.Equal(expected, new FilterPath(pathSpec, relativeTo).RepoRelativePath);
}
[Theory]
[InlineData(":!.", "foo", "foo")]
[InlineData(":!.", "foo", "foo/")]
[InlineData(":!.", "foo", "foo/relativepath.txt")]
[InlineData(":!relativepath.txt", "foo", "foo/relativepath.txt")]
[InlineData(":^relativepath.txt", "foo", "foo/relativepath.txt")]
[InlineData(":^./relativepath.txt", "foo", "foo/relativepath.txt")]
[InlineData(":^../bar", "foo", "bar")]
[InlineData(":^../bar", "foo", "bar/")]
[InlineData(":^../bar", "foo", "bar/somefile.txt")]
[InlineData(":^/absolute.txt", "foo", "absolute.txt")]
public void PathsCanBeExcluded(string pathSpec, string relativeTo, string repoRelativePath)
{
Assert.True(new FilterPath(pathSpec, relativeTo, true).Excludes(repoRelativePath));
Assert.True(new FilterPath(pathSpec, relativeTo, false).Excludes(repoRelativePath));
}
[Theory]
[InlineData(":!.", "foo", "foo.txt")]
[InlineData(":^relativepath.txt", "foo", "foo2/relativepath.txt")]
[InlineData(":^/absolute.txt", "foo", "absolute.txt.bak")]
[InlineData(":^/absolute.txt", "foo", "absolute")]
// Not exclude paths
[InlineData(":/absolute.txt", "foo", "absolute.txt")]
[InlineData("/absolute.txt", "foo", "absolute.txt")]
[InlineData("../root.txt", "foo", "root.txt")]
[InlineData("relativepath.txt", "foo", "foo/relativepath.txt")]
public void NonMatchingPathsAreNotExcluded(string pathSpec, string relativeTo, string repoRelativePath)
{
Assert.False(new FilterPath(pathSpec, relativeTo, true).Excludes(repoRelativePath));
Assert.False(new FilterPath(pathSpec, relativeTo, false).Excludes(repoRelativePath));
}
[Theory]
[InlineData(":!.", "foo", "Foo")]
[InlineData(":!.", "foo", "Foo/")]
[InlineData(":!.", "foo", "Foo/relativepath.txt")]
[InlineData(":!RelativePath.txt", "foo", "foo/relativepath.txt")]
[InlineData(":^relativepath.txt", "foo", "Foo/RelativePath.txt")]
[InlineData(":^./relativepath.txt", "Foo", "foo/RelativePath.txt")]
[InlineData(":^../bar", "foo", "Bar")]
[InlineData(":^../bar", "foo", "Bar/")]
[InlineData(":^../bar", "foo", "Bar/SomeFile.txt")]
[InlineData(":^/absOLUte.txt", "foo", "Absolute.TXT")]
public void PathsCanBeExcludedCaseInsensitive(string pathSpec, string relativeTo, string repoRelativePath)
{
Assert.True(new FilterPath(pathSpec, relativeTo, true).Excludes(repoRelativePath));
}
[Theory]
[InlineData(":!.", "foo", "Foo")]
[InlineData(":!.", "foo", "Foo/")]
[InlineData(":!.", "foo", "Foo/relativepath.txt")]
[InlineData(":!RelativePath.txt", "foo", "foo/relativepath.txt")]
[InlineData(":^relativepath.txt", "foo", "Foo/RelativePath.txt")]
[InlineData(":^./relativepath.txt", "Foo", "foo/RelativePath.txt")]
[InlineData(":^../bar", "foo", "Bar")]
[InlineData(":^../bar", "foo", "Bar/")]
[InlineData(":^../bar", "foo", "Bar/SomeFile.txt")]
[InlineData(":^/absOLUte.txt", "foo", "Absolute.TXT")]
public void NonMatchingPathsAreNotExcludedCaseSensitive(string pathSpec, string relativeTo, string repoRelativePath)
{
Assert.False(new FilterPath(pathSpec, relativeTo, false).Excludes(repoRelativePath));
}
[Fact]
public void InvalidPathspecsThrow()
{
Assert.Throws<ArgumentNullException>(() => new FilterPath(null, ""));
Assert.Throws<ArgumentException>(() => new FilterPath("", ""));
Assert.Throws<FormatException>(() => new FilterPath(":?", ""));
Assert.Throws<FormatException>(() => new FilterPath("../foo.txt", ""));
Assert.Throws<FormatException>(() => new FilterPath(".././a/../../foo.txt", "foo"));
}
}