public bool testComponent() { TestUtilities.title("Testing FileNameEditor", '='); TestUtilities.putLine(); TestUtilities.title("Testing extension edits"); FileName fileName = "SomeFile.cs.2"; FileName test1Name = addXmlExt(fileName); bool t1 = test1Name.Contains(".xml"); showResult(t1, test1Name, "addXmlExt"); FileName test2Name = removeXmlExt(test1Name); bool t2 = test2Name == fileName; showResult(t2, test2Name, "removeXmlExt"); FileName test3Name = removeXmlExt(test2Name); bool t3 = test3Name == fileName; showResult(t3, test3Name, "removeXmlExt"); TestUtilities.putLine(); TestUtilities.title("Testing path construction"); DirName stagingdir = "Fawcett"; FullDir stagingpath = stagingPath(stagingdir); bool t4 = (stagingpath.Contains("C:/") || stagingpath.Contains("../")) && stagingpath.Contains(stagingdir); showResult(t4, stagingpath, "stagingPath"); DirName category = "SomeCategory"; FullDir storagepath = storagePath(category); bool t5 = (storagepath.Contains("C:/") || storagepath.Contains("../")) && storagepath.Contains(category); showResult(t5, storagepath, "storagePath"); FileName someFileName = "someFileName"; FileSpec filespec = fileSpec(storagepath, someFileName); bool t6 = filespec.Contains("/someFileName"); showResult(t6, filespec, "fileSpec"); FileRef fileref = storageFolderRef(filespec); bool t7 = fileref.IndexOf('/') == fileref.LastIndexOf('/'); showResult(t7, fileref, "storageFolderRef"); DirName cat = extractCategory(fileref); bool t8 = cat == category; showResult(t8, cat, "extractCategory"); FileName file = extractFileName(fileref); bool t9 = file == someFileName; showResult(t8, file, "extractFileName"); return(t1 && t2 && t3 && t4 && t5 && t6 && t7 && t8 && t9); }
/*----< extract category name from a FileRef object >----------*/ /* * FileRefs have the form category/filename. * This function extracts the category. */ public DirName extractCategory(FileRef fileRef) { int pos = fileRef.IndexOf('/'); if (pos == -1) { return(""); } return(fileRef.Substring(0, pos)); }
/*----< extract file name from FileRef object >----------------*/ /* * FileRefs have the form category/filename. * This function extracts the filename. */ public FileName extractFileName(FileRef fileRef) { int pos = fileRef.IndexOf('/'); if (pos == -1) { return(""); } return(fileRef.Substring(pos + 1)); }