示例#1
0
        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)
                       ));
        }
示例#2
0
        public void RelativeTo_WithCaseSensitivePathAndDifferentCasing_ThrowsException()
        {
            var root = new PurePosixPath(@"/home");
            var abs  = new PurePosixPath(@"/HOME/nemec");

            abs.RelativeTo(root);
        }
示例#3
0
        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());
        }
示例#4
0
        /// <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);
        }
示例#5
0
        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);
        }
示例#6
0
        public void CreatePath_WithCurrentDir_CreatesRelativePathWithDirname()
        {
            // Arrange

            // Act
            var path = new PurePosixPath();

            // Assert
            Assert.AreEqual(".", path.Basename);
        }
示例#7
0
        public void CreatePath_WithCurrentDir_CreatesRelativePathWithDirname()
        {
            // Arrange

            // Act
            var path = new PurePosixPath();

            // Assert
            Assert.AreEqual(".", path.Basename);
        }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
        public void CreatePath_WithFilename_StoresPathInFilename()
        {
            // Arrange

            // Act
            var path = new PurePosixPath("file.txt");

            // Assert
            Assert.AreEqual("file.txt", path.Filename);
        }
示例#12
0
        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);
        }
示例#13
0
        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));
        }
示例#14
0
        public void IsAbsolute_WithRelativePath_ReturnsFalse()
        {
            // Arrange
            var parent = new PurePosixPath("home/tmp");

            // Act
            var actual = parent.IsAbsolute();

            // Assert
            Assert.False(actual);
        }
示例#15
0
        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());
        }
示例#16
0
        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());
        }
示例#17
0
        public void IsAbsolute_WithAbsolutePath_ReturnsTrue()
        {
            // Arrange
            var parent = new PurePosixPath("/home/tmp");

            // Act
            var actual = parent.IsAbsolute();

            // Assert
            Assert.IsTrue(actual);
        }
示例#18
0
        public void IsAbsolute_WithRelativePath_ReturnsTrue()
        {
            // Arrange
            var parent = new PurePosixPath("music/songs");

            // Act
            var actual = parent.IsAbsolute();

            // Assert
            Assert.IsFalse(actual);
        }
示例#19
0
        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);
        }
示例#20
0
        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());
        }
示例#21
0
        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);
        }
示例#22
0
        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());
        }
示例#23
0
        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());
        }
示例#24
0
        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);
        }
示例#25
0
        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());
        }
示例#26
0
        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);
        }
示例#27
0
        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);
        }
示例#28
0
 /// <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);
 }
示例#29
0
        /// <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));
        }
示例#30
0
        public void CreatePath_WithFilename_StoresPathInFilename()
        {
            // Arrange

            // Act
            var path = new PurePosixPath("file.txt");

            // Assert
            Assert.AreEqual("file.txt", path.Filename);
        }
示例#31
0
        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);
        }
示例#32
0
        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);
        }
示例#33
0
        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());
        }
示例#34
0
        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);
        }
示例#35
0
        public void IsAbsolute_WithAbsolutePath_ReturnsTrue()
        {
            // Arrange
            var parent = new PurePosixPath("/home/tmp");

            // Act
            var actual = parent.IsAbsolute();

            // Assert
            Assert.IsTrue(actual);
        }
示例#36
0
        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);
        }
示例#37
0
        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());
        }
示例#38
0
        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);
        }
示例#39
0
        public void IsAbsolute_WithRelativePath_ReturnsTrue()
        {
            // Arrange
            var parent = new PurePosixPath("music/songs");

            // Act
            var actual = parent.IsAbsolute();

            // Assert
            Assert.IsFalse(actual);
        }
示例#40
0
        public void RelativeTo_WithCaseSensitivePathAndDifferentCasing_ThrowsException()
        {
            var root = new PurePosixPath(@"/home");
            var abs = new PurePosixPath(@"/HOME/nemec");

            abs.RelativeTo(root);
        }
示例#41
0
        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());
        }