PosixPathTest_GetFileName.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using System;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using Renci.SshNet.Common;
  4. namespace Renci.SshNet.Tests.Classes.Common
  5. {
  6. [TestClass]
  7. public class PosixPathTest_GetFileName
  8. {
  9. [TestMethod]
  10. public void Path_Null()
  11. {
  12. const string path = null;
  13. try
  14. {
  15. PosixPath.GetFileName(path);
  16. Assert.Fail();
  17. }
  18. catch (NullReferenceException)
  19. {
  20. }
  21. }
  22. [TestMethod]
  23. public void Path_Empty()
  24. {
  25. var path = string.Empty;
  26. var actual = PosixPath.GetFileName(path);
  27. Assert.IsNotNull(actual);
  28. Assert.AreSame(path, actual);
  29. }
  30. [TestMethod]
  31. public void Path_TrailingForwardSlash()
  32. {
  33. var path = "/abc/";
  34. var actual = PosixPath.GetFileName(path);
  35. Assert.IsNotNull(actual);
  36. Assert.AreEqual(string.Empty, actual);
  37. }
  38. [TestMethod]
  39. public void Path_FileWithoutNoDirectory()
  40. {
  41. var path = "abc.log";
  42. var actual = PosixPath.GetFileName(path);
  43. Assert.IsNotNull(actual);
  44. Assert.AreSame(path, actual);
  45. }
  46. [TestMethod]
  47. public void Path_FileInRootDirectory()
  48. {
  49. var path = "/abc.log";
  50. var actual = PosixPath.GetFileName(path);
  51. Assert.IsNotNull(actual);
  52. Assert.AreEqual("abc.log", actual);
  53. }
  54. [TestMethod]
  55. public void Path_RootDirectoryOnly()
  56. {
  57. var path = "/";
  58. var actual = PosixPath.GetFileName(path);
  59. Assert.IsNotNull(actual);
  60. Assert.AreEqual(string.Empty, actual);
  61. }
  62. [TestMethod]
  63. public void Path_FileInNonRootDirectory()
  64. {
  65. var path = "/home/sshnet/xyz";
  66. var actual = PosixPath.GetFileName(path);
  67. Assert.IsNotNull(actual);
  68. Assert.AreEqual("xyz", actual);
  69. }
  70. [TestMethod]
  71. public void Path_BackslashIsNotConsideredDirectorySeparator()
  72. {
  73. var path = "/home\\abc.log";
  74. var actual = PosixPath.GetFileName(path);
  75. Assert.IsNotNull(actual);
  76. Assert.AreEqual("home\\abc.log", actual);
  77. }
  78. [TestMethod]
  79. public void Path_ColonIsNotConsideredPathSeparator()
  80. {
  81. var path = "/home:abc.log";
  82. var actual = PosixPath.GetFileName(path);
  83. Assert.IsNotNull(actual);
  84. Assert.AreEqual("home:abc.log", actual);
  85. }
  86. [TestMethod]
  87. public void Path_LeadingWhitespace()
  88. {
  89. var path = " / \tabc";
  90. var actual = PosixPath.GetFileName(path);
  91. Assert.IsNotNull(actual);
  92. Assert.AreEqual(" \tabc", actual);
  93. }
  94. [TestMethod]
  95. public void Path_TrailingWhitespace()
  96. {
  97. var path = "/abc \t ";
  98. var actual = PosixPath.GetFileName(path);
  99. Assert.IsNotNull(actual);
  100. Assert.AreEqual("abc \t ", actual);
  101. }
  102. [TestMethod]
  103. public void Path_OnlyWhitespace()
  104. {
  105. var path = " ";
  106. var actual = PosixPath.GetFileName(path);
  107. Assert.IsNotNull(actual);
  108. Assert.AreEqual(" ", actual);
  109. }
  110. [TestMethod]
  111. public void Path_FileNameOnlyWhitespace()
  112. {
  113. var path = "/home/\t ";
  114. var actual = PosixPath.GetFileName(path);
  115. Assert.IsNotNull(actual);
  116. Assert.AreEqual("\t ", actual);
  117. }
  118. }
  119. }