Exemplo n.º 1
0
        /// <summary>
        /// Adds or changes the file extension of an absolute path, returning a new absolute path.
        /// </summary>
        /// <param name="path">The original absolute path that may or may not have an extension.</param>
        /// <param name="extension">The new extension (this string must include a leading .). If this is PathAtom.Invalid then this method is equivalent to calling RemoveExtension instead.</param>
        public AbsolutePath ChangeExtension(AbsolutePath path, PathAtom extension)
        {
            Contract.Requires(path.IsValid);
            Contract.Ensures(Contract.Result <AbsolutePath>().IsValid);

            return(path.ChangeExtension(m_pathTable, extension));
        }
Exemplo n.º 2
0
        public void ChangeExtension()
        {
            var pt = new PathTable();

            // change a single char extension
            AbsolutePath ap1 = AbsolutePath.Create(pt, @"/a.c");
            AbsolutePath ap2 = ap1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));

            XAssert.AreEqual(@"/a.d", ap2.ToString(pt));

            // change a multi char extension
            ap1 = AbsolutePath.Create(pt, @"/a.cpp");
            ap2 = ap1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(@"/a.d", ap2.ToString(pt));

            // change nothing
            ap1 = AbsolutePath.Create(pt, @"/a");
            ap2 = ap1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(@"/a.d", ap2.ToString(pt));

            // change a single char extension
            ap1 = AbsolutePath.Create(pt, @"/ab.c");
            ap2 = ap1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(@"/ab.d", ap2.ToString(pt));

            // change a multi char extension
            ap1 = AbsolutePath.Create(pt, @"/ab.cpp");
            ap2 = ap1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(@"/ab.d", ap2.ToString(pt));

            // change nothing
            ap1 = AbsolutePath.Create(pt, @"/ab");
            ap2 = ap1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(@"/ab.d", ap2.ToString(pt));

            // change a single char extension
            ap1 = AbsolutePath.Create(pt, @"/xyz/ab.c");
            ap2 = ap1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(@"/xyz/ab.d", ap2.ToString(pt));

            // change a multi char extension
            ap1 = AbsolutePath.Create(pt, @"/xyz/ab.cpp");
            ap2 = ap1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(@"/xyz/ab.d", ap2.ToString(pt));

            // change nothing
            ap1 = AbsolutePath.Create(pt, @"/xyz/ab");
            ap2 = ap1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(@"/xyz/ab.d", ap2.ToString(pt));

            // change a single char extension
            ap1 = AbsolutePath.Create(pt, @"/xyz/ab.xyz.c");
            ap2 = ap1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(@"/xyz/ab.xyz.d", ap2.ToString(pt));

            // change a multi char extension
            ap1 = AbsolutePath.Create(pt, @"/xyz/ab.xyz.cpp");
            ap2 = ap1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(@"/xyz/ab.xyz.d", ap2.ToString(pt));

            ap1 = AbsolutePath.Create(pt, @"/xyz/.cpp");
            ap2 = ap1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(@"/xyz/.d", ap2.ToString(pt));

            ap1 = AbsolutePath.Create(pt, @"/xyz/a.cpp");
            ap2 = ap1.ChangeExtension(pt, PathAtom.Invalid);
            XAssert.AreEqual(@"/xyz/a", ap2.ToString(pt));
        }
Exemplo n.º 3
0
        public void ChangeExtension()
        {
            var pt = new PathTable();

            // change a single char extension
            AbsolutePath id1 = AbsolutePath.Create(pt, A("c", "a.c"));
            AbsolutePath id2 = id1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));

            XAssert.AreEqual(A("c", "a.d"), id2.ToString(pt));

            // change a multi char extension
            id1 = AbsolutePath.Create(pt, A("c", "a.cpp"));
            id2 = id1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(A("c", "a.d"), id2.ToString(pt));

            // change nothing
            id1 = AbsolutePath.Create(pt, A("c", "a"));
            id2 = id1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(A("c", "a.d"), id2.ToString(pt));

            // change a single char extension
            id1 = AbsolutePath.Create(pt, A("c", "ab.c"));
            id2 = id1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(A("c", "ab.d"), id2.ToString(pt));

            // change a multi char extension
            id1 = AbsolutePath.Create(pt, A("c", "ab.cpp"));
            id2 = id1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(A("c", "ab.d"), id2.ToString(pt));

            // change nothing
            id1 = AbsolutePath.Create(pt, A("c", "ab"));
            id2 = id1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(A("c", "ab.d"), id2.ToString(pt));

            // change a single char extension
            id1 = AbsolutePath.Create(pt, A("c", "xyz", "ab.c"));
            id2 = id1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(A("c", "xyz", "ab.d"), id2.ToString(pt));

            // change a multi char extension
            id1 = AbsolutePath.Create(pt, A("c", "xyz", "ab.cpp"));
            id2 = id1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(A("c", "xyz", "ab.d"), id2.ToString(pt));

            // change nothing
            id1 = AbsolutePath.Create(pt, A("c", "xyz", "ab"));
            id2 = id1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(A("c", "xyz", "ab.d"), id2.ToString(pt));

            // change a single char extension
            id1 = AbsolutePath.Create(pt, A("c", "xyz", "ab.xyz.c"));
            id2 = id1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(A("c", "xyz", "ab.xyz.d"), id2.ToString(pt));

            // change a multi char extension
            id1 = AbsolutePath.Create(pt, A("c", "xyz", "ab.xyz.cpp"));
            id2 = id1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(A("c", "xyz", "ab.xyz.d"), id2.ToString(pt));

            id1 = AbsolutePath.Create(pt, A("c", "xyz", ".cpp"));
            id2 = id1.ChangeExtension(pt, PathAtom.Create(pt.StringTable, ".d"));
            XAssert.AreEqual(A("c", "xyz", ".d"), id2.ToString(pt));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Changes the file extension
 /// </summary>
 /// <param name="NewExtension">The new extension</param>
 /// <returns></returns>
 public NodeFilePath ChangeExtension(FileExtension NewExtension)
 => new NodeFilePath(Node, AbsolutePath.ChangeExtension(NewExtension));