-
Notifications
You must be signed in to change notification settings - Fork 13
/
IoExtensionsTests.cs
151 lines (124 loc) · 6.87 KB
/
IoExtensionsTests.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System;
using System.IO;
using System.Linq;
using NUnit.Framework;
namespace GprTool.Tests
{
[TestFixture]
class IoExtensionsTests
{
[TestCase("./nupkg", "*.*", 2)]
[TestCase("./nupkg/**/*.*", "**/*.*", 2)]
[TestCase("./nupkg/**/**", "**/**", 2)]
[TestCase("./nupkg/**/*.nupkg", "**/*.nupkg", 1)]
[TestCase(".\\nupkg", "*.*", 2)]
[TestCase(".\\nupkg\\**\\*.*", "**/*.*", 2)]
[TestCase(".\\nupkg\\**\\**", "**/**", 2)]
[TestCase(".\\nupkg\\**\\*.nupkg", "**/*.nupkg", 1)]
[TestCase("nupkg", "*.*", 2)]
[TestCase("nupkg/**/*.nupkg", "**/*.nupkg", 1)]
[TestCase("nupkg/**/*.snupkg", "**/*.snupkg", 1)]
[TestCase("nupkg/**/*.*", "**/*.*", 2)]
[TestCase("nupkg/**/**", "**/**", 2)]
public void GetFilesByGlobPattern_Is_Relative_Directory(string globPattern, string expectedGlobPattern, int expectedFilesCount)
{
using var tmpDirectory = new DisposableDirectory(Path.Combine(Directory.GetCurrentDirectory(), Guid.NewGuid().ToString("N")));
var nupkgDirectory = Path.Combine(tmpDirectory, "nupkg");
Directory.CreateDirectory(nupkgDirectory);
var nupkgAbsoluteFilename = Path.Combine(nupkgDirectory, "test.nupkg");
var snupkgAbsoluteFilename = Path.Combine(nupkgDirectory, "test.snupkg");
File.WriteAllText(nupkgAbsoluteFilename, string.Empty);
File.WriteAllText(snupkgAbsoluteFilename, string.Empty);
var packages = tmpDirectory.WorkingDirectory.GetFilesByGlobPattern(globPattern, out var glob).ToList();
var pattern = glob.ToString().Substring(nupkgDirectory.Length).Replace("\\", "/");
if (pattern[0] == '/')
{
pattern = pattern.Substring(1);
}
Assert.That(pattern, Is.EqualTo(expectedGlobPattern));
Assert.That(packages.Count, Is.EqualTo(expectedFilesCount));
}
[TestCase("./nupkg", "*.*", 2)]
[TestCase(".\\nupkg", "*.*", 2)]
[TestCase("nupkg", "*.*", 2)]
[TestCase("nupkg/**/*.nupkg", "**/*.nupkg", 1)]
[TestCase("nupkg/**/*.snupkg", "**/*.snupkg", 1)]
[TestCase("nupkg/**/*.*", "**/*.*", 2)]
[TestCase("nupkg/**/**", "**/**", 2)]
public void GetFilesByGlobPattern_Is_FullPath_Directory(string globPattern, string expectedGlobPattern, int expectedFilesCount)
{
using var tmpDirectory = new DisposableDirectory(Path.Combine(Directory.GetCurrentDirectory(), Guid.NewGuid().ToString("N")));
var nupkgDirectory = Path.Combine(tmpDirectory, "nupkg");
Directory.CreateDirectory(nupkgDirectory);
var nupkgAbsoluteFilename = Path.Combine(nupkgDirectory, "test.nupkg");
var snupkgAbsoluteFilename = Path.Combine(nupkgDirectory, "test.snupkg");
File.WriteAllText(nupkgAbsoluteFilename, string.Empty);
File.WriteAllText(snupkgAbsoluteFilename, string.Empty);
var packages = tmpDirectory.WorkingDirectory.GetFilesByGlobPattern(Path.Combine(tmpDirectory, globPattern), out var glob).ToList();
var pattern = glob.ToString().Substring(nupkgDirectory.Length).Replace("\\", "/");
if (pattern[0] == '/')
{
pattern = pattern.Substring(1);
}
Assert.That(pattern, Is.EqualTo(expectedGlobPattern));
Assert.That(packages.Count, Is.EqualTo(expectedFilesCount));
}
[Test]
public void GetFilesByGlobPattern_Is_Dot_Directory()
{
using var tmpDirectory = new DisposableDirectory(Path.Combine(Directory.GetCurrentDirectory(), Guid.NewGuid().ToString("N")));
var nupkgAbsoluteFilename = Path.Combine(tmpDirectory, "test.nupkg");
var snupkgAbsoluteFilename = Path.Combine(tmpDirectory, "test.snupkg");
File.WriteAllText(nupkgAbsoluteFilename, string.Empty);
File.WriteAllText(snupkgAbsoluteFilename, string.Empty);
var packages = tmpDirectory.WorkingDirectory.GetFilesByGlobPattern(".", out var glob).ToList();
var globPattern = glob.ToString().Substring(tmpDirectory.WorkingDirectory.Length).Replace("\\", "/");
if (globPattern[0] == '/')
{
globPattern = globPattern.Substring(1);
}
Assert.That(globPattern, Is.EqualTo(globPattern));
Assert.That(packages.Count, Is.EqualTo(2));
Assert.That(packages[0], Is.EqualTo(nupkgAbsoluteFilename));
Assert.That(packages[1], Is.EqualTo(snupkgAbsoluteFilename));
}
[TestCase("test.nupkg")]
[TestCase("./test.nupkg")]
[TestCase(".\\test.nupkg")]
public void GetFilesByGlobPattern_Is_Relative_Filename(string relativeFilename)
{
using var tmpDirectory = new DisposableDirectory(Path.Combine(Directory.GetCurrentDirectory(), Guid.NewGuid().ToString("N")));
var nupkgAbsoluteFilename = Path.Combine(tmpDirectory, "test.nupkg");
var snupkgAbsoluteFilename = Path.Combine(tmpDirectory, "test.snupkg");
File.WriteAllText(nupkgAbsoluteFilename, string.Empty);
File.WriteAllText(snupkgAbsoluteFilename, string.Empty);
var packages = tmpDirectory.WorkingDirectory.GetFilesByGlobPattern(relativeFilename, out var glob).ToList();
var globPattern = glob.ToString().Substring(tmpDirectory.WorkingDirectory.Length).Replace("\\", "/");
if (globPattern[0] == '/')
{
globPattern = globPattern.Substring(1);
}
Assert.That(globPattern, Is.EqualTo("test.nupkg"));
Assert.That(packages.Count, Is.EqualTo(1));
Assert.That(packages[0], Is.EqualTo(nupkgAbsoluteFilename));
}
[Test]
public void GetFilesByGlobPattern_Is_FullPath_Filename()
{
using var tmpDirectory = new DisposableDirectory(Path.Combine(Directory.GetCurrentDirectory(), Guid.NewGuid().ToString("N")));
var nupkgAbsoluteFilename = Path.Combine(tmpDirectory, "test.nupkg");
var snupkgAbsoluteFilename = Path.Combine(tmpDirectory, "test.snupkg");
File.WriteAllText(nupkgAbsoluteFilename, string.Empty);
File.WriteAllText(snupkgAbsoluteFilename, string.Empty);
var packages = tmpDirectory.WorkingDirectory.GetFilesByGlobPattern(nupkgAbsoluteFilename, out var glob).ToList();
var globPattern = glob.ToString().Substring(tmpDirectory.WorkingDirectory.Length).Replace("\\", "/");
if (globPattern[0] == '/')
{
globPattern = globPattern.Substring(1);
}
Assert.That(globPattern, Is.EqualTo("test.nupkg"));
Assert.That(packages.Count, Is.EqualTo(1));
Assert.That(packages[0], Is.EqualTo(nupkgAbsoluteFilename));
}
}
}