internal string GetCacheFilePath(string filePath) { var dbPath = _databasePath; if (!PathEqualityComparer.IsValidPath(dbPath)) { return(null); } var name = PathUtils.GetFileName(filePath); var candidate = Path.ChangeExtension(Path.Combine(dbPath, name), ".pyi"); if (File.Exists(candidate)) { return(candidate); } var hash = SHA256.Create(); var dir = Path.GetDirectoryName(filePath); var dirHash = Convert.ToBase64String(hash.ComputeHash(new UTF8Encoding(false).GetBytes(dir))) .Replace('/', '_').Replace('+', '-'); return(Path.ChangeExtension(Path.Combine( _databasePath, Path.Combine(dirHash, name) ), ".pyi")); }
public void GetPathCompareKey_Linux() { var cmp = new PathEqualityComparer(isCaseSensitivePath: true, directorySeparator: '/'); foreach (var path in new[] { "/normalized//path/", "/normalized/./path", "/normalized/path/", "/normalized/path//", "/normalized/here//..//path/" }) { Assert.AreEqual("/normalized/path", cmp.GetCompareKeyUncached(path), path); } foreach (var path in new[] { "smb://computer/normalized//path/", "smb://computer/normalized/./path", "smb://computer/normalized/path/", "smb://computer/normalized/path/", "smb://computer/normalized/here//..//path/" }) { Assert.AreEqual("smb://computer/normalized/path", cmp.GetCompareKeyUncached(path), path); } }
/// <summary> /// Expands a sequence of directory paths to include any paths that are /// referenced in .pth files. /// /// The original directories are not included in the result. /// </summary> public static IEnumerable <string> ExpandPathFiles(IEnumerable <string> paths) { foreach (var path in paths) { if (Directory.Exists(path)) { foreach (var file in PathUtils.EnumerateFiles(path, "*.pth", recurse: false)) { using (var reader = new StreamReader(file)) { string line; while ((line = reader.ReadLine()) != null) { line = line.Trim(); if (line.StartsWithOrdinal("import ") || !PathEqualityComparer.IsValidPath(line)) { continue; } line = line.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); if (!Path.IsPathRooted(line)) { line = Path.Combine(path, line); } if (Directory.Exists(line)) { yield return(line); } } } } } } }
public void GetPathCompareKey_OSX() { var cmp = new PathEqualityComparer(isCaseSensitivePath: false, directorySeparator: '/'); foreach (var path in new[] { "/normalized//path/", "/normalized/./path", "/NORMalized//path", "/normalized/path/", "/normalized/path//", "/normalized/here//..//path/" }) { Assert.AreEqual("/NORMALIZED/PATH", cmp.GetCompareKeyUncached(path), path); } foreach (var path in new[] { "smb://computer/normalized//path/", "smb://computer/normalized/./path", "smb://computer/NORMalized//path", "smb://computer/normalized/path/", "smb://computer/normalized/path/", "smb://computer/normalized/here//..//path/" }) { Assert.AreEqual("smb://COMPUTER/NORMALIZED/PATH", cmp.GetCompareKeyUncached(path), path); } }
public void PathEqualityCache_Windows() { var cmp = new PathEqualityComparer(isCaseSensitivePath: false, directorySeparator: '\\', altDirectorySeparator: '/'); var path1 = "C:\\normalized\\path\\"; var path2 = "c:/normalized/here/../path"; Assert.AreEqual(0, cmp._compareKeyCache.Count); cmp.GetHashCode(path1); Assert.AreEqual(1, cmp._compareKeyCache[path1].Accessed); cmp.GetHashCode(path2); Assert.AreEqual(1, cmp._compareKeyCache[path1].Accessed); Assert.AreEqual(2, cmp._compareKeyCache[path2].Accessed); cmp.GetHashCode(path1); Assert.AreEqual(3, cmp._compareKeyCache[path1].Accessed); Assert.AreEqual(2, cmp._compareKeyCache[path2].Accessed); foreach (var path_i in Enumerable.Range(0, 100).Select(i => $"C:\\path\\{i}\\here")) { cmp.GetHashCode(path_i); cmp.GetHashCode(path1); } cmp._compareKeyCache .Should().ContainKey(path1) .And.NotContainKey(path2); }
public void GetPathCompareKey_Windows() { var cmp = new PathEqualityComparer(isCaseSensitivePath: false, directorySeparator: '\\', altDirectorySeparator: '/'); foreach (var path in new[] { "C:/normalized//path/", "C:/normalized/.\\path", "C:\\NORMalized\\\\path", "C:/normalized/path\\", "C:/normalized/path/", "C:/normalized/path/p1/p2/p3/../../..", "C:/normalized/path/p1/../p3/../", "C:/normalized/path/", "C:/normalized/here////..////path/" }) { Assert.AreEqual(@"C:\NORMALIZED\PATH", cmp.GetCompareKeyUncached(path), path); } foreach (var path in new[] { @"\\computer/normalized//path/", @"//computer/normalized/.\\path", @"\\computer\NORMalized\\path", @"\\computer/normalized/path\\", @"\/computer/normalized/path/", @"\\computer/normalized/here////..////path/" }) { Assert.AreEqual(@"\\COMPUTER\NORMALIZED\PATH", cmp.GetCompareKeyUncached(path), path); } Assert.AreEqual(@"C:\PATH", cmp.GetCompareKeyUncached(@"C:\..\..\PATH/")); Assert.AreEqual(@"C:\PATH", cmp.GetCompareKeyUncached("C:/.././.././path/")); Assert.AreEqual(@"\\COMPUTER\SHARE\PATH", cmp.GetCompareKeyUncached("//computer/share/.././.././path/")); }
public void PathEqualityCache() { var cmp = new PathEqualityComparer(); var path1 = "C:\\normalized\\path\\"; var path2 = "c:/normalized/here/../path"; Assert.AreEqual(0, cmp._compareKeyCache.Count); cmp.GetHashCode(path1); Assert.AreEqual(1, cmp._compareKeyCache[path1].Accessed); cmp.GetHashCode(path2); Assert.AreEqual(1, cmp._compareKeyCache[path1].Accessed); Assert.AreEqual(2, cmp._compareKeyCache[path2].Accessed); cmp.GetHashCode(path1); Assert.AreEqual(3, cmp._compareKeyCache[path1].Accessed); Assert.AreEqual(2, cmp._compareKeyCache[path2].Accessed); foreach (var path_i in Enumerable.Range(0, 100).Select(i => $"C:\\path\\{i}\\here")) { cmp.GetHashCode(path_i); cmp.GetHashCode(path1); } AssertUtil.CheckCollection( cmp._compareKeyCache.Keys, new[] { path1 }, new[] { path2 } ); }
public void PathEqualityStartsWith_Linux() { var cmp = new PathEqualityComparer(isCaseSensitivePath: true, directorySeparator: '/'); foreach (var path in new[] { new { p = "/root/a/b", isFull = false }, new { p = "/notroot/../root", isFull = true }, new { p = "/./root/", isFull = true } }) { Assert.IsTrue(cmp.StartsWith(path.p, "/root"), path.p); if (path.isFull) { Assert.IsFalse(cmp.StartsWith(path.p, "/root", allowFullMatch: false)); } else { Assert.IsTrue(cmp.StartsWith(path.p, "/root", allowFullMatch: false)); } } foreach (var path in new[] { new { p = "/ROOT/", isFull = true }, }) { Assert.IsFalse(cmp.StartsWith(path.p, "/root"), path.p); if (path.isFull) { Assert.IsFalse(cmp.StartsWith(path.p, "/Root", allowFullMatch: false)); } else { Assert.IsTrue(cmp.StartsWith(path.p, "/ROOT", allowFullMatch: false)); } } }
public string GetCacheFilePath(string filePath) { var name = PathUtils.GetFileName(filePath); if (!PathEqualityComparer.IsValidPath(name)) { _log?.Log(TraceEventType.Warning, $"Invalid cache name: {name}"); return(null); } try { var candidate = Path.ChangeExtension(Path.Combine(StubCacheFolder, name), ".pyi"); if (_fs.FileExists(candidate)) { return(candidate); } } catch (ArgumentException) { return(null); } var dir = Path.GetDirectoryName(filePath) ?? string.Empty; if (_fs.StringComparison == StringComparison.OrdinalIgnoreCase) { dir = dir.ToLowerInvariant(); } var dirHash = CacheFolders.FileNameFromContent(dir); var stubFile = Path.Combine(StubCacheFolder, Path.Combine(dirHash, name)); return(Path.ChangeExtension(stubFile, ".pyi")); }
public void GetPathCompareKey() { foreach (var path in new[] { "C:/normalized//path/", "C:/normalized/.\\path", "C:\\NORMalized\\\\path", "C:/normalized/path\\", "C:/normalized/path/", "C:/normalized/here////..////path/" }) { Assert.AreEqual("C:\\NORMALIZED\\PATH", PathEqualityComparer.GetCompareKeyUncached(path), path); } foreach (var path in new[] { "\\\\computer/normalized//path/", "//computer/normalized/.\\path", "\\\\computer\\NORMalized\\\\path", "\\\\computer/normalized/path\\", "\\/computer/normalized/path/", "\\\\computer/normalized/here////..////path/" }) { Assert.AreEqual("\\\\COMPUTER\\NORMALIZED\\PATH", PathEqualityComparer.GetCompareKeyUncached(path), path); } Assert.AreEqual("C:\\..\\..\\PATH", PathEqualityComparer.GetCompareKeyUncached("C:/.././.././path/")); Assert.AreEqual("\\\\COMPUTER\\SHARE\\..\\..\\PATH", PathEqualityComparer.GetCompareKeyUncached("//computer/share/.././.././path/")); }
public void PathEqualityCache() { var cmp = new PathEqualityComparer(); var path1 = "C:\\normalized\\path\\"; var path2 = "c:/normalized/here/../path"; Assert.AreEqual(0, cmp._compareKeyCache.Count); cmp.GetHashCode(path1); Assert.AreEqual(1, cmp._compareKeyCache[path1].Accessed); cmp.GetHashCode(path2); Assert.AreEqual(1, cmp._compareKeyCache[path1].Accessed); Assert.AreEqual(2, cmp._compareKeyCache[path2].Accessed); cmp.GetHashCode(path1); Assert.AreEqual(3, cmp._compareKeyCache[path1].Accessed); Assert.AreEqual(2, cmp._compareKeyCache[path2].Accessed); foreach (var path_i in Enumerable.Range(0, 100).Select(i => $"C:\\path\\{i}\\here")) { cmp.GetHashCode(path_i); cmp.GetHashCode(path1); } cmp._compareKeyCache .Should().ContainKey(path1) .And.NotContainKey(path2); }
public void PathIsContainedByDifferingCaseParent_WhenPolicyIsCaseInsensitive() { var comparer = new PathEqualityComparer(FileSystemCasing.CasePreservingInsensitive); var path = RelativePath.CreateFromSegments("A", "B", "c"); var parentPath = RelativePath.CreateFromSegments("a", "b").AsContainer(); Assert.That(parentPath.Contains(path, comparer), Is.True); }
public void PathIsContainedByParent([ValueSource(nameof(ValidFileSystemCasings))] FileSystemCasing casing) { var comparer = new PathEqualityComparer(casing); var path = RelativePath.CreateFromSegments("a", "b", "c"); var parentPath = RelativePath.CreateFromSegments("a", "b").AsContainer(); Assert.That(parentPath.Contains(path, comparer), Is.True); }
public void PathIsEqualToIdenticalCasePath([ValueSource(nameof(ValidFileSystemCasings))] FileSystemCasing casing) { var comparer = new PathEqualityComparer(casing); var pathA = RelativePath.CreateFromSegments("a", "b", "c"); var pathB = RelativePath.CreateFromSegments("a", "b", "c"); Assert.That(pathA, Is.EqualTo(pathB).Using <RelativePath>(comparer)); }
public void PathIsEqualToDifferentCasePath_WhenPolicyIsCaseInsensitive() { var comparer = new PathEqualityComparer(FileSystemCasing.CasePreservingInsensitive); var pathA = RelativePath.CreateFromSegments("a", "b", "c"); var pathB = RelativePath.CreateFromSegments("A", "B", "c"); Assert.That(pathA, Is.EqualTo(pathB).Using <RelativePath>(comparer)); }
public void PathDoesNotContainSibling([ValueSource(nameof(ValidFileSystemCasings))] FileSystemCasing casing) { var comparer = new PathEqualityComparer(casing); var path = RelativePath.CreateFromSegments("a", "b", "c"); var siblingPath = RelativePath.CreateFromSegments("a", "b", "d"); Assert.That(path.Contains(siblingPath, comparer), Is.False); Assert.That(path.AsContainer().Contains(siblingPath, comparer), Is.False); }
internal string GetCacheFilePath(string filePath) { var dbPath = _databasePath; if (!PathEqualityComparer.IsValidPath(dbPath)) { if (!_loggedBadDbPath) { _loggedBadDbPath = true; _log?.Log(TraceLevel.Warning, "InvalidDatabasePath", dbPath); } return(null); } var name = PathUtils.GetFileName(filePath); if (!PathEqualityComparer.IsValidPath(name)) { _log?.Log(TraceLevel.Warning, "InvalidCacheName", name); return(null); } try { var candidate = Path.ChangeExtension(Path.Combine(dbPath, name), ".pyi"); if (File.Exists(candidate)) { return(candidate); } } catch (ArgumentException) { return(null); } var hash = SHA256.Create(); var dir = Path.GetDirectoryName(filePath); if (IsWindows()) { dir = dir.ToLowerInvariant(); } var dirHash = Convert.ToBase64String(hash.ComputeHash(new UTF8Encoding(false).GetBytes(dir))) .Replace('/', '_').Replace('+', '-'); return(Path.ChangeExtension(Path.Combine( _databasePath, Path.Combine(dirHash, name) ), ".pyi")); }
public string GetCacheFilePath(string filePath) { if (string.IsNullOrEmpty(filePath) || !PathEqualityComparer.IsValidPath(ModuleCachePath)) { if (!_loggedBadDbPath) { _loggedBadDbPath = true; _log?.Log(TraceEventType.Warning, $"Invalid module cache path: {ModuleCachePath}"); } return(null); } var name = PathUtils.GetFileName(filePath); if (!PathEqualityComparer.IsValidPath(name)) { _log?.Log(TraceEventType.Warning, $"Invalid cache name: {name}"); return(null); } try { var candidate = Path.ChangeExtension(Path.Combine(ModuleCachePath, name), ".pyi"); if (_fs.FileExists(candidate)) { return(candidate); } } catch (ArgumentException) { return(null); } var hash = SHA256.Create(); var dir = Path.GetDirectoryName(filePath) ?? string.Empty; if (_fs.StringComparison == StringComparison.OrdinalIgnoreCase) { dir = dir.ToLowerInvariant(); } var dirHash = Convert.ToBase64String(hash.ComputeHash(new UTF8Encoding(false).GetBytes(dir))) .Replace('/', '_').Replace('+', '-'); return(Path.ChangeExtension(Path.Combine( ModuleCachePath, Path.Combine(dirHash, name) ), ".pyi")); }
/// <summary> /// Returns a new ModulePath value determined from the provided full /// path to a Python file. This function may access the filesystem to /// determine the package name unless <paramref name="isPackage"/> is /// provided. /// </summary> /// <param name="path"> /// The path referring to a Python file. /// </param> /// <param name="topLevelPath"> /// The directory to stop searching for packages at. The module name /// will never include the last segment of this path. /// </param> /// <param name="isPackage"> /// A predicate that determines whether the specified substring of /// <paramref name="path"/> represents a package. If omitted, the /// default behavior is to check for a file named "__init__.py" in the /// directory passed to the predicate. /// </param> /// <exception cref="ArgumentException"> /// path is not a valid Python module. /// </exception> public static ModulePath FromFullPath( string path, string topLevelPath = null, Func <string, bool> isPackage = null ) { var name = PathUtils.GetFileName(path); var nameMatch = PythonFileRegex.Match(name); if (nameMatch == null || !nameMatch.Success) { nameMatch = PythonBinaryRegex.Match(name); } if (nameMatch == null || !nameMatch.Success) { throw new ArgumentException("Not a valid Python module: " + path); } var fullName = nameMatch.Groups["name"].Value; var remainder = Path.GetDirectoryName(path); if (isPackage == null) { // We know that f will be the result of GetParent() and always // ends with a directory separator, so just concatenate to avoid // potential path length problems. isPackage = f => File.Exists(f + "__init__.py") || File.Exists(f + "__init__.pyw") || File.Exists(f + "__init__.pyi"); } while ( PathEqualityComparer.IsValidPath(remainder) && isPackage(remainder) && (string.IsNullOrEmpty(topLevelPath) || PathEqualityComparer.Instance.StartsWith(remainder, topLevelPath, allowFullMatch: false)) ) { fullName = PathUtils.GetFileName(remainder) + "." + fullName; remainder = Path.GetDirectoryName(remainder); } return(new ModulePath(fullName, path, remainder)); }
public void PathEqualityStartsWith_Windows() { var cmp = new PathEqualityComparer(isCaseSensitivePath: false, directorySeparator: '\\', altDirectorySeparator: '/'); foreach (var path in new[] { new { p = "C:/root/a/b", isFull = false }, new { p = @"C:\ROOT\", isFull = true }, new { p = @"C:\Root", isFull = true }, new { p = @"C:\notroot\..\root", isFull = true }, new { p = @"C:\.\root\", isFull = true } }) { Assert.IsTrue(cmp.StartsWith(path.p, @"C:\Root"), path.p); if (path.isFull) { Assert.IsFalse(cmp.StartsWith(path.p, @"C:\Root", allowFullMatch: false)); } else { Assert.IsTrue(cmp.StartsWith(path.p, @"C:\Root", allowFullMatch: false)); } } }
public void PathEqualityStartsWith() { var cmp = new PathEqualityComparer(); foreach (var path in new[] { new { p = "C:/root/a/b", isFull = false }, new { p = "C:\\ROOT\\", isFull = true }, new { p = "C:\\Root", isFull = true }, new { p = "C:\\notroot\\..\\root", isFull = true }, new { p = "C:\\.\\root\\", isFull = true } }) { Assert.IsTrue(cmp.StartsWith(path.p, "C:\\Root")); if (path.isFull) { Assert.IsFalse(cmp.StartsWith(path.p, "C:\\Root", allowFullMatch: false)); } else { Assert.IsTrue(cmp.StartsWith(path.p, "C:\\Root", allowFullMatch: false)); } } }
public bool Equals(AbstractPath <EdgeType, PointType> other) { PathEqualityComparer <EdgeType, PointType> defComparer = new PathEqualityComparer <EdgeType, PointType>(); return(defComparer.Equals(this, other)); }
//return the providers with latest version under the providerAssemblies folder private IEnumerable<string> ProvidersWithLatestVersionFromProviderAssembliesLocation(IHostApi request) { try { var providerPaths = ScanAllProvidersFromProviderAssembliesLocation(request, null, null, null, null, ProviderOption.LatestVersion).WhereNotNull().ToArray(); var notRootAssemblies = providerPaths.Where(each => !ProviderAssembliesLocation.ContainsIgnoreCase(Path.GetDirectoryName(each))).ToArray(); var rootAssemblies = providerPaths.Where(each => ProviderAssembliesLocation.ContainsIgnoreCase(Path.GetDirectoryName(each))).ToArray(); var equalityComparer = new PathEqualityComparer(PathCompareOption.File); //return the assemblies that are installed not directly under ProviderAssemblies root folder. //For the assemblies under the root directory, we need to check further if the provider that has the later version //installed under providername\version folder //Convention: the providers are installed under providerassemblies\providername\version folder has the later version //than those at the top root folder. var assembliesUnderRootFolder = rootAssemblies.Where(rootPath => !notRootAssemblies.Any(element => equalityComparer.Equals(element, rootPath))); //for these assemblies not under the providerassemblies root folders but they have the same provider names, we return the latest version var assembliesUnderVersionFolder = notRootAssemblies.GroupBy(Path.GetFileName).Select( each => each.OrderByDescending(file => { var versionFolder = Path.GetDirectoryName(file); Version ver; return !System.Version.TryParse(Path.GetFileName(versionFolder), out ver) ? new Version("0.0") : ver; }).FirstOrDefault()).WhereNotNull(); return assembliesUnderVersionFolder.Concat(assembliesUnderRootFolder); } catch (Exception ex) { request.Debug(ex.Message); } return Enumerable.Empty<string>(); }
public void UngroupPath_SimplePathWithBackTransitions_UngroupsThePath() { State state1 = new State(), state2; state1.Transitions.Add(new AlwaysTransition { TargetState = state1 }); var path = new ITransition[] { new SimpleTransition { HeadShift = 1, GlyphId = 1, Action = new SubstitutionAction { ReplacedGlyphCount = 1 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs, TargetState = state1 }, new SetTransition { HeadShift = 2, GlyphIdSet = new HashSet <ushort> { 21, 22, 23 }, Action = new SubstitutionAction { ReplacedGlyphCount = 2 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs, TargetState = state2 = new State(), }, new AlwaysTransition { HeadShift = 3, Action = new SubstitutionAction { ReplacedGlyphCount = 3 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs, TargetState = new State { Transitions = new ITransition[] { new AlwaysTransition { TargetState = state2 } } } } }; var builder = new StateMachineBuilder(); var result = builder.UngroupPath(path).ToList(); var expectedPaths = new IEnumerable <ITransition>[] { new ITransition[] { new SimpleTransition { HeadShift = 1, GlyphId = 1, Action = new SubstitutionAction { ReplacedGlyphCount = 1 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs }, new SimpleTransition { HeadShift = 2, GlyphId = 21, Action = new SubstitutionAction { ReplacedGlyphCount = 2 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs }, new AlwaysTransition { HeadShift = 3, Action = new SubstitutionAction { ReplacedGlyphCount = 3 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs } }, new ITransition[] { new SimpleTransition { HeadShift = 1, GlyphId = 1, Action = new SubstitutionAction { ReplacedGlyphCount = 1 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs }, new SimpleTransition { HeadShift = 2, GlyphId = 22, Action = new SubstitutionAction { ReplacedGlyphCount = 2 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs }, new AlwaysTransition { HeadShift = 3, Action = new SubstitutionAction { ReplacedGlyphCount = 3 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs } }, new ITransition[] { new SimpleTransition { HeadShift = 1, GlyphId = 1, Action = new SubstitutionAction { ReplacedGlyphCount = 1 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs }, new SimpleTransition { HeadShift = 2, GlyphId = 23, Action = new SubstitutionAction { ReplacedGlyphCount = 2 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs }, new AlwaysTransition { HeadShift = 3, Action = new SubstitutionAction { ReplacedGlyphCount = 3 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs } } }; var comparer = new PathEqualityComparer(); Assert.IsTrue(comparer.Equals(expectedPaths[0], result[0])); Assert.IsTrue(comparer.Equals(expectedPaths[1], result[1])); Assert.IsTrue(comparer.Equals(expectedPaths[2], result[2])); Assert.AreEqual(expectedPaths.Length, result.Count); Assert.AreSame(result[0].First().TargetState.Transitions.First().TargetState, result[0].First().TargetState); Assert.AreSame(result[2].ElementAt(2).TargetState.Transitions.First().TargetState, result[2].ElementAt(1).TargetState); }
public void UngroupPath_SimplePath_UngroupsThePath() { var path = new ITransition[] { new SimpleTransition { HeadShift = 1, GlyphId = 1, Action = new SubstitutionAction { ReplacedGlyphCount = 1 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs }, new SetTransition { HeadShift = 2, GlyphIdSet = new HashSet <ushort> { 21, 22, 23 }, Action = new SubstitutionAction { ReplacedGlyphCount = 2 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs }, new AlwaysTransition { HeadShift = 3, Action = new SubstitutionAction { ReplacedGlyphCount = 3 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs } }; var builder = new StateMachineBuilder(); var result = builder.UngroupPath(path).ToList(); var expectedPaths = new IEnumerable <ITransition>[] { new ITransition[] { new SimpleTransition { HeadShift = 1, GlyphId = 1, Action = new SubstitutionAction { ReplacedGlyphCount = 1 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs }, new SimpleTransition { HeadShift = 2, GlyphId = 21, Action = new SubstitutionAction { ReplacedGlyphCount = 2 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs }, new AlwaysTransition { HeadShift = 3, Action = new SubstitutionAction { ReplacedGlyphCount = 3 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs } }, new ITransition[] { new SimpleTransition { HeadShift = 1, GlyphId = 1, Action = new SubstitutionAction { ReplacedGlyphCount = 1 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs }, new SimpleTransition { HeadShift = 2, GlyphId = 22, Action = new SubstitutionAction { ReplacedGlyphCount = 2 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs }, new AlwaysTransition { HeadShift = 3, Action = new SubstitutionAction { ReplacedGlyphCount = 3 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs } }, new ITransition[] { new SimpleTransition { HeadShift = 1, GlyphId = 1, Action = new SubstitutionAction { ReplacedGlyphCount = 1 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs }, new SimpleTransition { HeadShift = 2, GlyphId = 23, Action = new SubstitutionAction { ReplacedGlyphCount = 2 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs }, new AlwaysTransition { HeadShift = 3, Action = new SubstitutionAction { ReplacedGlyphCount = 3 }, LookupFlags = LookupFlags.IgnoreBaseGlyphs } } }; var comparer = new PathEqualityComparer(); Assert.IsTrue(comparer.Equals(expectedPaths[0], result[0])); Assert.IsTrue(comparer.Equals(expectedPaths[1], result[1])); Assert.IsTrue(comparer.Equals(expectedPaths[2], result[2])); Assert.AreEqual(expectedPaths.Length, result.Count); }
public void Equals_Should_Be_Case_Insensitive_And_Dir_Separator_Agnostic(string x, string y, bool result) { var pathEqualityComparer = new PathEqualityComparer(); pathEqualityComparer.Equals(x, y).Should().Be(result); }
public void Setup() { _comparer = new PathEqualityComparer(); }