public void TestGlobExpressions(string pattern, string positiveMatch, string negativeMatch = null) { var parser = new Parser(pattern); var segments = parser.ParseTree().Segments; var mockFileDatas = new Dictionary <string, MockFileData>(); if (positiveMatch != null) { mockFileDatas[Path.Combine(FileSystemRoot, positiveMatch)] = MockFileData.NullObject; } if (negativeMatch != null) { mockFileDatas[Path.Combine(FileSystemRoot, negativeMatch)] = MockFileData.NullObject; } var cache = new MockTraverseOptions(true, true, false, new MockFileSystem(mockFileDatas)); var root = new DirectoryInfo(FileSystemRoot); var results = PathTraverser.Traverse(root, segments, cache).ToArray(); if (positiveMatch != null) { Assert.Single(results); } if (positiveMatch == null && negativeMatch != null) { Assert.Empty(results); } }
///------------------------------------------------------------------------------------------------- /// <summary> /// Gets the paths in this collection. /// </summary> /// <param name="node"> /// The start node. /// </param> /// <returns> /// An enumerator that allows foreach to be used to process the paths in this collection. /// </returns> ///------------------------------------------------------------------------------------------------- public IEnumerable <GraphPath> GetPaths(NodeInfo node) { Contract.Requires(node, "node"); try { PathTraverser.Initialize(this); UnicityPolicy.Reset(); foreach (var p in PathTraverser.Traverse(node)) { yield return(p); } } finally { UnicityPolicy.Reset(); } }
public void TestGlobExpressionsWithEmitDirectories(string pattern, string files, string matches) { var parser = new Parser(pattern); var segments = parser.ParseTree().Segments; var mockFileDatas = new Dictionary <string, MockFileData>(); foreach (var file in files.Split(' ')) { mockFileDatas[Path.Combine(FileSystemRoot, file)] = MockFileData.NullObject; } var cache = new MockTraverseOptions(false, true, true, new MockFileSystem(mockFileDatas)); var root = new DirectoryInfo(FileSystemRoot); var results = PathTraverser.Traverse(root, segments, cache).Select(file => file.FullName.Substring(FileSystemRoot.Length)).OrderBy(x => x).ToArray(); var fileMatches = matches.Split(' ').Select(x => x.Replace('\\', Path.DirectorySeparatorChar)).OrderBy(x => x).ToArray(); Assert.Equal(fileMatches, results); }