Make tests xplat
This commit is contained in:
parent
9cd10eca58
commit
210ab065c2
4 changed files with 242 additions and 133 deletions
|
|
@ -15,16 +15,18 @@ namespace FileNamingTemplateTests
|
|||
static ReplacementCharacters Replacements = ReplacementCharacters.Default;
|
||||
|
||||
[TestMethod]
|
||||
public void equiv_GetValidFilename()
|
||||
[DataRow(@"C:\foo\bar", @"C:\foo\bar\my꞉ book 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 [ID123456].txt", PlatformID.Win32NT)]
|
||||
[DataRow(@"/foo/bar", @"/foo/bar/my: book 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 [ID123456].txt", PlatformID.Unix)]
|
||||
public void equiv_GetValidFilename(string dirFullPath, string expected, PlatformID platformID)
|
||||
{
|
||||
if (Environment.OSVersion.Platform != platformID)
|
||||
return;
|
||||
|
||||
var sb = new System.Text.StringBuilder();
|
||||
sb.Append('0', 300);
|
||||
var longText = sb.ToString();
|
||||
|
||||
var expectedNew = @"C:\foo\bar\my꞉ book 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 [ID123456].txt";
|
||||
var f2 = NEW_GetValidFilename_FileNamingTemplate(@"C:\foo\bar", "my: book " + longText, "txt", "ID123456");
|
||||
|
||||
f2.Should().Be(expectedNew);
|
||||
NEW_GetValidFilename_FileNamingTemplate(dirFullPath, "my: book " + longText, "txt", "ID123456").Should().Be(expected);
|
||||
}
|
||||
|
||||
private static string NEW_GetValidFilename_FileNamingTemplate(string dirFullPath, string filename, string extension, string metadataSuffix)
|
||||
|
|
@ -40,12 +42,12 @@ namespace FileNamingTemplateTests
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void equiv_GetMultipartFileName()
|
||||
[DataRow(@"C:\foo\bar\my file.txt", @"C:\foo\bar\my file - 002 - title.txt", PlatformID.Win32NT)]
|
||||
[DataRow(@"/foo/bar/my file.txt", @"/foo/bar/my file - 002 - title.txt", PlatformID.Unix)]
|
||||
public void equiv_GetMultipartFileName(string inStr, string outStr, PlatformID platformID)
|
||||
{
|
||||
var expected = @"C:\foo\bar\my file - 002 - title.txt";
|
||||
var f2 = NEW_GetMultipartFileName_FileNamingTemplate(@"C:\foo\bar\my file.txt", 2, 100, "title");
|
||||
|
||||
f2.Should().Be(expected);
|
||||
if (Environment.OSVersion.Platform == platformID)
|
||||
NEW_GetMultipartFileName_FileNamingTemplate(inStr, 2, 100, "title").Should().Be(outStr);
|
||||
}
|
||||
|
||||
private static string NEW_GetMultipartFileName_FileNamingTemplate(string originalPath, int partsPosition, int partsTotal, string suffix)
|
||||
|
|
@ -64,11 +66,16 @@ namespace FileNamingTemplateTests
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void remove_slashes()
|
||||
[DataRow(@"\foo\<title>.txt", @"\foo\sl∕as∕he∕s.txt", PlatformID.Win32NT)]
|
||||
[DataRow(@"/foo/<title>.txt", @"/foo/s\l∕a\s∕h\e∕s.txt", PlatformID.Unix)]
|
||||
public void remove_slashes(string inStr, string outStr, PlatformID platformID)
|
||||
{
|
||||
var fileNamingTemplate = new FileNamingTemplate(@"\foo\<title>.txt");
|
||||
fileNamingTemplate.AddParameterReplacement("title", @"s\l/a\s/h\e/s");
|
||||
fileNamingTemplate.GetFilePath(Replacements).PathWithoutPrefix.Should().Be(@"\foo\sl∕as∕he∕s.txt");
|
||||
if (Environment.OSVersion.Platform == platformID)
|
||||
{
|
||||
var fileNamingTemplate = new FileNamingTemplate(inStr);
|
||||
fileNamingTemplate.AddParameterReplacement("title", @"s\l/a\s/h\e/s");
|
||||
fileNamingTemplate.GetFilePath(Replacements).PathWithoutPrefix.Should().Be(outStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,51 +21,78 @@ namespace FileUtilityTests
|
|||
|
||||
[TestMethod]
|
||||
// non-empty replacement
|
||||
[DataRow("abc*abc.txt", "abc✱abc.txt")]
|
||||
// standardize slashes
|
||||
[DataRow(@"a/b\c/d", @"a\b\c\d")]
|
||||
[DataRow("abc*abc.txt", "abc✱abc.txt", PlatformID.Win32NT)]
|
||||
[DataRow("abc*abc.txt", "abc*abc.txt", PlatformID.Unix)]
|
||||
// standardize slashes. There is no unix equivalent because there is no alt directory separator
|
||||
[DataRow(@"a/b\c/d", @"a\b\c\d", PlatformID.Win32NT)]
|
||||
// remove illegal chars
|
||||
[DataRow("a*?:z.txt", "a✱?꞉z.txt")]
|
||||
[DataRow("a*?:z.txt", "a✱?꞉z.txt", PlatformID.Win32NT)]
|
||||
[DataRow("a*?:z.txt", "a*?:z.txt", PlatformID.Unix)]
|
||||
// retain drive letter path colon
|
||||
[DataRow(@"C:\az.txt", @"C:\az.txt")]
|
||||
[DataRow(@"C:\az.txt", @"C:\az.txt", PlatformID.Win32NT)]
|
||||
[DataRow(@"/:/az.txt", @"/:/az.txt", PlatformID.Unix)]
|
||||
// replace all other colons
|
||||
[DataRow(@"a\b:c\d.txt", @"a\b꞉c\d.txt")]
|
||||
[DataRow(@"a\b:c\d.txt", @"a\b꞉c\d.txt", PlatformID.Win32NT)]
|
||||
[DataRow(@"a/b:c/d.txt", @"a/b:c/d.txt", PlatformID.Unix)]
|
||||
// remove empty directories
|
||||
[DataRow(@"C:\a\\\b\c\\\d.txt", @"C:\a\b\c\d.txt")]
|
||||
[DataRow(@"C:\""foo\<id>", @"C:\“foo\<id>")]
|
||||
public void DefaultTests(string inStr, string outStr) => Assert.AreEqual(outStr, FileUtility.GetSafePath(inStr, Default).PathWithoutPrefix);
|
||||
[DataRow(@"C:\a\\\b\c\\\d.txt", @"C:\a\b\c\d.txt", PlatformID.Win32NT)]
|
||||
[DataRow(@"/a///b/c///d.txt", @"/a/b/c/d.txt", PlatformID.Unix)]
|
||||
[DataRow(@"C:\""foo\<id>", @"C:\“foo\<id>", PlatformID.Win32NT)]
|
||||
[DataRow(@"/""foo/<id>", @"/“foo/<id>", PlatformID.Unix)]
|
||||
public void DefaultTests(string inStr, string outStr, PlatformID platformID)
|
||||
=> Test(inStr, outStr, Default, platformID);
|
||||
|
||||
[TestMethod]
|
||||
// non-empty replacement
|
||||
[DataRow("abc*abc.txt", "abc_abc.txt")]
|
||||
// standardize slashes
|
||||
[DataRow(@"a/b\c/d", @"a\b\c\d")]
|
||||
[DataRow("abc*abc.txt", "abc_abc.txt", PlatformID.Win32NT)]
|
||||
[DataRow("abc*abc.txt", "abc*abc.txt", PlatformID.Unix)]
|
||||
// standardize slashes. There is no unix equivalent because there is no alt directory separator
|
||||
[DataRow(@"a/b\c/d", @"a\b\c\d", PlatformID.Win32NT)]
|
||||
// remove illegal chars
|
||||
[DataRow("a*?:z.txt", "a__-z.txt")]
|
||||
[DataRow("a*?:z.txt", "a__-z.txt", PlatformID.Win32NT)]
|
||||
[DataRow("a*?:z.txt", "a*?:z.txt", PlatformID.Unix)]
|
||||
// retain drive letter path colon
|
||||
[DataRow(@"C:\az.txt", @"C:\az.txt")]
|
||||
[DataRow(@"C:\az.txt", @"C:\az.txt", PlatformID.Win32NT)]
|
||||
[DataRow(@"/:az.txt", @"/:az.txt", PlatformID.Unix)]
|
||||
// replace all other colons
|
||||
[DataRow(@"a\b:c\d.txt", @"a\b-c\d.txt")]
|
||||
[DataRow(@"a\b:c\d.txt", @"a\b-c\d.txt", PlatformID.Win32NT)]
|
||||
[DataRow(@"a/b:c/d.txt", @"a/b:c/d.txt", PlatformID.Unix)]
|
||||
// remove empty directories
|
||||
[DataRow(@"C:\a\\\b\c\\\d.txt", @"C:\a\b\c\d.txt")]
|
||||
[DataRow(@"C:\""foo\<id>", @"C:\'foo\{id}")]
|
||||
public void LoFiDefaultTests(string inStr, string outStr) => Assert.AreEqual(outStr, FileUtility.GetSafePath(inStr, LoFiDefault).PathWithoutPrefix);
|
||||
[DataRow(@"C:\a\\\b\c\\\d.txt", @"C:\a\b\c\d.txt", PlatformID.Win32NT)]
|
||||
[DataRow(@"/a///b/c///d.txt", @"/a/b/c/d.txt", PlatformID.Unix)]
|
||||
[DataRow(@"C:\""foo\<id>", @"C:\'foo\{id}", PlatformID.Win32NT)]
|
||||
[DataRow(@"/""foo/<id>", @"/""foo/<id>", PlatformID.Unix)]
|
||||
public void LoFiDefaultTests(string inStr, string outStr, PlatformID platformID)
|
||||
=> Test(inStr, outStr, LoFiDefault, platformID);
|
||||
|
||||
[TestMethod]
|
||||
// empty replacement
|
||||
[DataRow("abc*abc.txt", "abc_abc.txt")]
|
||||
// standardize slashes
|
||||
[DataRow(@"a/b\c/d", @"a\b\c\d")]
|
||||
[DataRow("abc*abc.txt", "abc_abc.txt", PlatformID.Win32NT)]
|
||||
[DataRow("abc*abc.txt", "abc*abc.txt", PlatformID.Unix)]
|
||||
// standardize slashes. There is no unix equivalent because there is no alt directory separator
|
||||
[DataRow(@"a/b\c/d", @"a\b\c\d", PlatformID.Win32NT)]
|
||||
// remove illegal chars
|
||||
[DataRow("a*?:z.txt", "a___z.txt")]
|
||||
[DataRow("a*?:z.txt", "a___z.txt", PlatformID.Win32NT)]
|
||||
[DataRow("a*?:z.txt", "a*?:z.txt", PlatformID.Unix)]
|
||||
// retain drive letter path colon
|
||||
[DataRow(@"C:\az.txt", @"C:\az.txt")]
|
||||
[DataRow(@"C:\az.txt", @"C:\az.txt", PlatformID.Win32NT)]
|
||||
[DataRow(@"/:az.txt", @"/:az.txt", PlatformID.Unix)]
|
||||
// replace all other colons
|
||||
[DataRow(@"a\b:c\d.txt", @"a\b_c\d.txt")]
|
||||
[DataRow(@"a\b:c\d.txt", @"a\b_c\d.txt", PlatformID.Win32NT)]
|
||||
[DataRow(@"a/b:c/d.txt", @"a/b:c/d.txt", PlatformID.Unix)]
|
||||
// remove empty directories
|
||||
[DataRow(@"C:\a\\\b\c\\\d.txt", @"C:\a\b\c\d.txt")]
|
||||
[DataRow(@"C:\""foo\<id>", @"C:\_foo\_id_")]
|
||||
public void BarebonesDefaultTests(string inStr, string outStr) => Assert.AreEqual(outStr, FileUtility.GetSafePath(inStr, Barebones).PathWithoutPrefix);
|
||||
[DataRow(@"C:\a\\\b\c\\\d.txt", @"C:\a\b\c\d.txt", PlatformID.Win32NT)]
|
||||
[DataRow(@"/a///b/c///d.txt", @"/a/b/c/d.txt", PlatformID.Unix)]
|
||||
[DataRow(@"C:\""foo\<id>", @"C:\_foo\_id_", PlatformID.Win32NT)]
|
||||
[DataRow(@"/""foo/<id>", @"/""foo/<id>", PlatformID.Unix)]
|
||||
public void BarebonesDefaultTests(string inStr, string outStr, PlatformID platformID)
|
||||
=> Test(inStr, outStr, Barebones, platformID);
|
||||
|
||||
private void Test(string inStr, string outStr, ReplacementCharacters replacements, PlatformID platformID)
|
||||
{
|
||||
if (Environment.OSVersion.Platform == platformID)
|
||||
FileUtility.GetSafePath(inStr, replacements).PathWithoutPrefix.Should().Be(outStr);
|
||||
}
|
||||
}
|
||||
|
||||
[TestClass]
|
||||
|
|
@ -77,23 +104,33 @@ namespace FileUtilityTests
|
|||
|
||||
// needs separate method. middle null param not running correctly in TestExplorer when used in DataRow()
|
||||
[TestMethod]
|
||||
[DataRow("http://test.com/a/b/c", "http꞉∕∕test.com∕a∕b∕c")]
|
||||
public void url_null_replacement(string inStr, string outStr) => DefaultReplacementTest(inStr, outStr);
|
||||
[DataRow("http://test.com/a/b/c", "http꞉∕∕test.com∕a∕b∕c", PlatformID.Win32NT)]
|
||||
[DataRow("http://test.com/a/b/c", "http:∕∕test.com∕a∕b∕c", PlatformID.Unix)]
|
||||
public void url_null_replacement(string inStr, string outStr, PlatformID platformID) => DefaultReplacementTest(inStr, outStr, platformID);
|
||||
|
||||
[TestMethod]
|
||||
// empty replacement
|
||||
[DataRow("http://test.com/a/b/c", "http꞉∕∕test.com∕a∕b∕c")]
|
||||
public void DefaultReplacementTest(string inStr, string outStr) => Default.ReplaceFilenameChars(inStr).Should().Be(outStr);
|
||||
[DataRow("http://test.com/a/b/c", "http꞉∕∕test.com∕a∕b∕c", PlatformID.Win32NT)]
|
||||
[DataRow("http://test.com/a/b/c", "http:∕∕test.com∕a∕b∕c", PlatformID.Unix)]
|
||||
public void DefaultReplacementTest(string inStr, string outStr, PlatformID platformID) => Test(inStr, outStr, Default, platformID);
|
||||
|
||||
[TestMethod]
|
||||
// empty replacement
|
||||
[DataRow("http://test.com/a/b/c", "http-__test.com_a_b_c")]
|
||||
public void LoFiDefaultReplacementTest(string inStr, string outStr) => LoFiDefault.ReplaceFilenameChars(inStr).Should().Be(outStr);
|
||||
[DataRow("http://test.com/a/b/c", "http-__test.com_a_b_c", PlatformID.Win32NT)]
|
||||
[DataRow("http://test.com/a/b/c", "http:__test.com_a_b_c", PlatformID.Unix)]
|
||||
public void LoFiDefaultReplacementTest(string inStr, string outStr, PlatformID platformID) => Test(inStr, outStr, LoFiDefault, platformID);
|
||||
|
||||
[TestMethod]
|
||||
// empty replacement
|
||||
[DataRow("http://test.com/a/b/c", "http___test.com_a_b_c")]
|
||||
public void BarebonesDefaultReplacementTest(string inStr, string outStr) => Barebones.ReplaceFilenameChars(inStr).Should().Be(outStr);
|
||||
[DataRow("http://test.com/a/b/c", "http___test.com_a_b_c", PlatformID.Win32NT)]
|
||||
[DataRow("http://test.com/a/b/c", "http:__test.com_a_b_c", PlatformID.Unix)]
|
||||
public void BarebonesDefaultReplacementTest(string inStr, string outStr, PlatformID platformID) => Test(inStr, outStr, Barebones, platformID);
|
||||
|
||||
private void Test(string inStr, string outStr, ReplacementCharacters replacements, PlatformID platformID)
|
||||
{
|
||||
if (Environment.OSVersion.Platform == platformID)
|
||||
replacements.ReplaceFilenameChars(inStr).Should().Be(outStr);
|
||||
}
|
||||
}
|
||||
|
||||
[TestClass]
|
||||
|
|
@ -154,32 +191,41 @@ namespace FileUtilityTests
|
|||
}
|
||||
|
||||
[TestClass]
|
||||
public class GetValidFilename
|
||||
public class GetValidFilename
|
||||
{
|
||||
static ReplacementCharacters Replacements = ReplacementCharacters.Default;
|
||||
|
||||
[TestMethod]
|
||||
// dot-files
|
||||
[DataRow(@"C:\a bc\x y z\.f i l e.txt")]
|
||||
[DataRow(@"C:\a bc\x y z\.f i l e.txt", PlatformID.Win32NT)]
|
||||
[DataRow(@"/a bc/x y z/.f i l e.txt", PlatformID.Unix)]
|
||||
// dot-folders
|
||||
[DataRow(@"C:\a bc\.x y z\f i l e.txt")]
|
||||
public void Valid(string input) => Tests(input, input);
|
||||
[DataRow(@"C:\a bc\.x y z\f i l e.txt", PlatformID.Win32NT)]
|
||||
[DataRow(@"/a bc/.x y z/f i l e.txt", PlatformID.Unix)]
|
||||
public void Valid(string input, PlatformID platformID) => Tests(input, input, platformID);
|
||||
|
||||
[TestMethod]
|
||||
// folder spaces
|
||||
[DataRow(@"C:\ a bc \x y z ", @"C:\a bc\x y z")]
|
||||
[DataRow(@"C:\ a bc \x y z ", @"C:\a bc\x y z", PlatformID.Win32NT)]
|
||||
[DataRow(@"/ a bc /x y z ", @"/a bc/x y z", PlatformID.Unix)]
|
||||
// file spaces
|
||||
[DataRow(@"C:\a bc\x y z\ f i l e.txt ", @"C:\a bc\x y z\f i l e.txt")]
|
||||
[DataRow(@"C:\a bc\x y z\ f i l e.txt ", @"C:\a bc\x y z\f i l e.txt", PlatformID.Win32NT)]
|
||||
[DataRow(@"/a bc/x y z/ f i l e.txt ", @"/a bc/x y z/f i l e.txt", PlatformID.Unix)]
|
||||
// eliminate beginning space and end dots and spaces
|
||||
[DataRow(@"C:\a bc\ . . . x y z . . . \f i l e.txt", @"C:\a bc\. . . x y z\f i l e.txt")]
|
||||
[DataRow(@"C:\a bc\ . . . x y z . . . \f i l e.txt", @"C:\a bc\. . . x y z\f i l e.txt", PlatformID.Win32NT)]
|
||||
[DataRow(@"/a bc/ . . . x y z . . . /f i l e.txt", @"/a bc/. . . x y z/f i l e.txt", PlatformID.Unix)]
|
||||
// file end dots
|
||||
[DataRow(@"C:\a bc\x y z\f i l e.txt . . .", @"C:\a bc\x y z\f i l e.txt")]
|
||||
public void Tests(string input, string expected)
|
||||
=> FileUtility.GetValidFilename(input, Replacements).PathWithoutPrefix.Should().Be(expected);
|
||||
[DataRow(@"C:\a bc\x y z\f i l e.txt . . .", @"C:\a bc\x y z\f i l e.txt", PlatformID.Win32NT)]
|
||||
[DataRow(@"/a bc/x y z/f i l e.txt . . .", @"/a bc/x y z/f i l e.txt", PlatformID.Unix)]
|
||||
public void Tests(string input, string expected, PlatformID platformID)
|
||||
{
|
||||
if (Environment.OSVersion.Platform == platformID)
|
||||
FileUtility.GetValidFilename(input, Replacements).PathWithoutPrefix.Should().Be(expected);
|
||||
}
|
||||
}
|
||||
|
||||
[TestClass]
|
||||
public class RemoveLastCharacter
|
||||
public class RemoveLastCharacter
|
||||
{
|
||||
[TestMethod]
|
||||
public void is_null() => Tests(null, null);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue