|
5 | 5 | using System.Collections.Generic; |
6 | 6 | using System.IO; |
7 | 7 | using System.Linq; |
| 8 | +using Microsoft.DotNet.XUnitExtensions; |
8 | 9 | using Microsoft.Extensions.FileSystemGlobbing.Abstractions; |
9 | 10 | using Microsoft.Extensions.FileSystemGlobbing.Tests.TestUtility; |
10 | 11 | using Xunit; |
@@ -851,5 +852,54 @@ public void VerifyInMemoryDirectoryInfo_IsNotEmpty() |
851 | 852 |
|
852 | 853 | Assert.Equal(1, fileSystemInfos.Count()); |
853 | 854 | } |
| 855 | + |
| 856 | + [Theory] |
| 857 | + [InlineData("./sdk/9.0.100-preview.4.24207.1/.version")] |
| 858 | + [InlineData("././sdk/9.0.100-preview.4.24207.1/.version")] |
| 859 | + public void VerifyFiles_RedundantSegment_HasMatches(string file) |
| 860 | + { |
| 861 | + foreach (string pattern in new[] { "**/*", "./", file }) |
| 862 | + { |
| 863 | + var matcher = new Matcher(); |
| 864 | + matcher.AddInclude(pattern); |
| 865 | + Assert.True(matcher.Match(file).HasMatches); |
| 866 | + Assert.True(matcher.Match([file]).HasMatches); |
| 867 | + Assert.True(matcher.Match("X:/foo", file).HasMatches); |
| 868 | + Assert.True(matcher.Match("X:/foo", [file]).HasMatches); |
| 869 | + } |
| 870 | + } |
| 871 | + |
| 872 | + [ConditionalFact] |
| 873 | + public void VerifyFiles_ParentRedundantSegment_HasMatches() |
| 874 | + { |
| 875 | + string file = "sdk/9.0.100-preview.4.24207.1/.version"; |
| 876 | + foreach (string pattern in new[] { "**/*", "./", file }) |
| 877 | + { |
| 878 | + var matcher = new Matcher(); |
| 879 | + matcher.AddInclude(pattern); |
| 880 | + Assert.True(matcher.Match("X:/foo", $"../foo/{file}").HasMatches); |
| 881 | + Assert.True(matcher.Match("X:/foo", [$"../foo/{file}"]).HasMatches); |
| 882 | + } |
| 883 | + } |
| 884 | + |
| 885 | + [ConditionalFact] |
| 886 | + public void VerifyFiles_ParentRedundantSegment_CurrentDirectory_HasMatches() |
| 887 | + { |
| 888 | + string cwd = Environment.CurrentDirectory; |
| 889 | + string cwdFolderName = new DirectoryInfo(cwd).Name; |
| 890 | + if (cwd == cwdFolderName) // cwd is root, we can't do ../C:/ |
| 891 | + { |
| 892 | + throw new SkipTestException($"CurrentDirectory {cwd} is the root directory."); |
| 893 | + } |
| 894 | + |
| 895 | + string file = "sdk/9.0.100-preview.4.24207.1/.version"; |
| 896 | + foreach (string pattern in new[] { "**/*", "./", file }) |
| 897 | + { |
| 898 | + var matcher = new Matcher(); |
| 899 | + matcher.AddInclude(pattern); |
| 900 | + Assert.True(matcher.Match($"../{cwdFolderName}/{file}").HasMatches); |
| 901 | + Assert.True(matcher.Match([$"../{cwdFolderName}/{file}"]).HasMatches); |
| 902 | + } |
| 903 | + } |
854 | 904 | } |
855 | 905 | } |
0 commit comments