internal IFile Build() { // Inside our manifest model we normalize on Posix path syntax so that any manifest // errors regarding any file path uses the same syntax used by the manifest file. var path = new PurePosixPath(this.Path); // If either output directory or name isn't given, derive it from the source path. var outputDirectory = this.OutputDirectory ?? path.Directory; var outputName = this.OutputName ?? path.Filename; // There shouldn't be any directory component in the output name. var outputNamePath = new PurePosixPath(outputName); if (!string.IsNullOrEmpty(outputNamePath.Directory)) { throw new NotSupportedException($"Output name {outputName} must not specify any directory components."); } return(new File( path.ToString(), this.Computed, new ComputedString(outputDirectory), new ComputedString(outputName) )); }
public void RelativeTo_WithCaseSensitivePathAndDifferentCasing_ThrowsException() { var root = new PurePosixPath(@"/home"); var abs = new PurePosixPath(@"/HOME/nemec"); abs.RelativeTo(root); }
public void ItCanReadSimpleFileFromManifest() { SetManifest(@" name: FooTemplate version: 1.0.0 files: - path: path/to/file.txt "); var t = this.TemplateLoader.LoadFromTemplateDirectory(TestTemplatePath); t.Files.Count.Should().Be(1); var f = t.Files.First(); f.Path.Should().Be("path/to/file.txt"); f.Computed.Should().BeFalse(); f.OutputDirectory.Value.Should().Be("path/to"); f.OutputName.Value.Should().Be("file.txt"); var outputPath = new PurePosixPath(f.OutputDirectory.Value, f.OutputName.Value); f.Path.Should().Be(outputPath.ToString()); }
/// <summary> /// Factory method to create a new <see cref="PurePath"/> instance /// based upon the current operating system. /// </summary> /// <param name="path"></param> /// <param name="options"></param> /// <param name="result"></param> /// <returns></returns> public bool TryCreate(string path, PurePathFactoryOptions options, out IPurePath result) { result = null; switch (PlatformChooser.GetPlatform()) { case Platform.Posix: PurePosixPath purePosixPath; if (PurePosixPath.TryParse(path, out purePosixPath)) { result = purePosixPath; break; } return(false); case Platform.Windows: PureWindowsPath pureWindowsPath; if (PureWindowsPath.TryParse(path, out pureWindowsPath)) { result = pureWindowsPath; break; } return(false); } result = ApplyOptions(result, options); return(true); }
public void Join_WithEmptyPathAsInitial_CreatesPathEqualToSecondPath() { var path = new PurePosixPath(); var expected = new PurePosixPath(@"\Users\nemecd\tmp\testfiles"); var joined = path.Join(@"\Users\nemecd\tmp\testfiles"); Assert.AreEqual(expected, joined); }
public void CreatePath_WithCurrentDir_CreatesRelativePathWithDirname() { // Arrange // Act var path = new PurePosixPath(); // Assert Assert.AreEqual(".", path.Basename); }
public void Addition_WithOtherPureNtPath_JoinsBoth() { var first = new PurePosixPath(@"/home/"); var second = new PurePosixPath(@"dan"); var expected = new PurePosixPath(@"/home/dan"); var actual = first + second; Assert.AreEqual(expected, actual); }
public void Addition_WithString_JoinsBoth() { var first = new PurePosixPath(@"/home/"); const string second = @"dan"; var expected = new PurePosixPath(@"/home/dan"); var actual = first + second; Assert.AreEqual(expected, actual); }
public void CreatePath_WithFilename_StoresPathInFilename() { // Arrange // Act var path = new PurePosixPath("file.txt"); // Assert Assert.AreEqual("file.txt", path.Filename); }
public void CreatePath_WithEmptyPath_AllPartsAreNonNull() { var path = new PurePosixPath(""); Assert.NotNull(path.Drive); Assert.NotNull(path.Root); Assert.NotNull(path.Dirname); Assert.NotNull(path.Basename); Assert.NotNull(path.Extension); Assert.Empty(path.Parts.Where(p => p is null)); }
public void IsAbsolute_WithRelativePath_ReturnsFalse() { // Arrange var parent = new PurePosixPath("home/tmp"); // Act var actual = parent.IsAbsolute(); // Assert Assert.False(actual); }
public void CreatePath_WithEmptyPath_AllPartsAreNonNull() { var path = new PurePosixPath(""); Assert.IsNotNull(path.Drive); Assert.IsNotNull(path.Root); Assert.IsNotNull(path.Dirname); Assert.IsNotNull(path.Basename); Assert.IsNotNull(path.Extension); CollectionAssert.AllItemsAreNotNull(path.Parts.ToList()); }
public void IsAbsolute_WithAbsolutePath_ReturnsTrue() { // Arrange var parent = new PurePosixPath("/home/tmp"); // Act var actual = parent.IsAbsolute(); // Assert Assert.IsTrue(actual); }
public void IsAbsolute_WithRelativePath_ReturnsTrue() { // Arrange var parent = new PurePosixPath("music/songs"); // Act var actual = parent.IsAbsolute(); // Assert Assert.IsFalse(actual); }
public void PathEquality_UsingPosixPaths_ComparesCaseSensitive() { // Arrange var first = new PurePosixPath("foo"); var second = new PurePosixPath("FOO"); // Act var actual = first == second; // Assert Assert.IsFalse(actual); }
public void CreatePath_WithExtraDoubleDots_KeepsDoubleDots() { // Arrange var paths = new[] { "foo/../bar" }; const string expected = "foo/../bar"; // Act var path = new PurePosixPath(paths); // Assert Assert.AreEqual(expected, path.ToPosix()); }
public void PathCompare_ParentLessThanChild_ReturnsTrue() { // Arrange var parent = new PurePosixPath("/home"); var child = new PurePosixPath("/home/dan"); // Act var actual = parent < child; // Assert Assert.IsTrue(actual); }
public void CreatePath_WithMultipleAbsolutePaths_UsesLastPathAsAnchor() { // Arrange var paths = new[] { "/home/dan", "/lib", "lib64" }; const string expected = "/lib/lib64"; // Act var path = new PurePosixPath(paths); // Assert Assert.AreEqual(expected, path.ToPosix()); }
public void CreatePath_WithMultipleStringPaths_CombinesPaths() { // Arrange const string someInitialPath = "/home/dan"; const string someSubPath = "music"; // Act var path = new PurePosixPath(someInitialPath, someSubPath); // Assert Assert.AreEqual("/home/dan/music", path.ToPosix()); }
public void PathEquality_WithSamePath_AreEqual() { // Arrange var first = new PurePosixPath("foo"); var second = new PurePosixPath("foo"); // Act var actual = first == second; // Assert Assert.IsTrue(actual); }
public void CreatePath_WithExtraDots_RemovesExtraDots() { // Arrange var paths = new[] { "foo/./bar" }; const string expected = "foo/bar"; // Act var path = new PurePosixPath(paths); // Assert Assert.AreEqual(expected, path.ToPosix()); }
public void CreatePath_WithLeadingTripleSlash_CompressesLeadingSlashesToOne() { // Arrange var paths = new[] { "///home/dan" }; const string expected = "/"; // Act var path = new PurePosixPath(paths); // Assert Assert.AreEqual(expected, path.Root); }
public void CreatePath_WithLeadingDoubleSlash_KeepsDoubleSlashAsRoot() { // Arrange var paths = new[] { "//home/dan" }; const string expected = "//"; // Act var path = new PurePosixPath(paths); // Assert Assert.AreEqual(expected, path.Root); }
/// <summary> /// Factory method to create a new <see cref="PurePath"/> instance /// based upon the current operating system. /// </summary> /// <param name="path"></param> /// <param name="options"></param> /// <returns></returns> public IPurePath Create(string path, PurePathFactoryOptions options) { IPurePath ret = null; switch (PlatformChooser.GetPlatform()) { case Platform.Posix: ret = new PurePosixPath(path); break; case Platform.Windows: ret = new PureWindowsPath(path); break; } return ApplyOptions(ret, options); }
/// <summary> /// Factory method to create a new <see cref="PurePath"/> instance /// based upon the current operating system. /// </summary> /// <param name="path"></param> /// <param name="options"></param> /// <returns></returns> public IPurePath Create(string path, PurePathFactoryOptions options) { IPurePath ret = null; switch (PlatformChooser.GetPlatform()) { case Platform.Posix: ret = new PurePosixPath(path); break; case Platform.Windows: ret = new PureWindowsPath(path); break; } return(ApplyOptions(ret, options)); }
public void CreatePath_WithMultipleAbsolutePaths_UsesLastPathAsAnchor() { // Arrange var paths = new[]{ "/home/dan", "/lib", "lib64" }; const string expected = "/lib/lib64"; // Act var path = new PurePosixPath(paths); // Assert Assert.AreEqual(expected, path.ToPosix()); }
public void CreatePath_WithExtraSlashes_RemovesExtraSlashes() { // Arrange var paths = new[] { "foo//bar" }; const string expected = "foo/bar"; // Act var path = new PurePosixPath(paths); // Assert Assert.AreEqual(expected, path.ToPosix()); }