Beispiel #1
0
        /**
         * Gets a new {@link RelativeUnixPath} from a Unix-style path in relative form. The {@code path}
         * must be relative (does not begin with a leading slash {@code /}).
         *
         * @param relativePath the relative path
         * @return a new {@link RelativeUnixPath}
         */
        public static RelativeUnixPath Get(string relativePath)
        {
            relativePath = relativePath ?? throw new ArgumentNullException(nameof(relativePath));
            Preconditions.CheckArgument(
                !relativePath.StartsWith("/", StringComparison.Ordinal), "Path starts with forward slash (/): " + relativePath);

            return(new RelativeUnixPath(UnixPathParser.Parse(relativePath)));
        }
Beispiel #2
0
        /**
         * Gets a new {@link AbsoluteUnixPath} from a Unix-style path string. The path must begin with a
         * forward slash ({@code /}).
         *
         * @param unixPath the Unix-style path string in absolute form
         * @return a new {@link AbsoluteUnixPath}
         */
        public static AbsoluteUnixPath Get(string unixPath)
        {
            Preconditions.CheckNotNull(unixPath);
            Preconditions.CheckArgument(
                unixPath.StartsWith("/", StringComparison.InvariantCulture),
                "Path does not start with forward slash (/): " + unixPath);

            return(new AbsoluteUnixPath(UnixPathParser.Parse(unixPath), null));
        }
Beispiel #3
0
 public void TestParse()
 {
     CollectionAssert.AreEqual(ImmutableArray.Create("some", "path"), UnixPathParser.Parse("/some/path"));
     CollectionAssert.AreEqual(ImmutableArray.Create("some", "path"), UnixPathParser.Parse("some/path/"));
     CollectionAssert.AreEqual(ImmutableArray.Create("some", "path"), UnixPathParser.Parse("some///path///"));
     // Windows-style paths are resolved in Unix semantics.
     CollectionAssert.AreEqual(
         ImmutableArray.Create("\\windows\\path"), UnixPathParser.Parse("\\windows\\path"));
     CollectionAssert.AreEqual(ImmutableArray.Create("T:\\dir"), UnixPathParser.Parse("T:\\dir"));
     CollectionAssert.AreEqual(
         ImmutableArray.Create("T:\\dir", "real", "path"), UnixPathParser.Parse("T:\\dir/real/path"));
 }