mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-11 01:36:39 +00:00
c0a353a4de
* Preparation to enforce formatting and style in CI - enabled IDE0055 to enforce formatting on build - disabled SA1137 and SA1025 because they are already covered by IDE0055 - disabled SA1021 because it conflicts with csharp_space_after_cast * Cleanup formatting and style on codebase This commit has no manual changes, it is the result of running "dotnet format whitespace" and "dotnet format style" * new formatting fixes after merge * appveyor: set git autocrlf as suggested by sharwell to hopefully fix Windows CI. * use autocrlf input to hopefully fix Linux tests * fix formatting * use autocrlf input for Linux only * set csharp_space_after_cast to false * Revert SA1021 suppression --------- Co-authored-by: Robert Hague <rh@johnstreetcapital.com>
162 lines
3.8 KiB
C#
162 lines
3.8 KiB
C#
using System;
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
using Renci.SshNet.Common;
|
|
|
|
namespace Renci.SshNet.Tests.Classes.Common
|
|
{
|
|
[TestClass]
|
|
public class PosixPathTest_GetDirectoryName
|
|
{
|
|
[TestMethod]
|
|
public void Path_Null()
|
|
{
|
|
const string path = null;
|
|
|
|
try
|
|
{
|
|
_ = PosixPath.GetDirectoryName(path);
|
|
Assert.Fail();
|
|
}
|
|
catch (ArgumentNullException ex)
|
|
{
|
|
Assert.IsNull(ex.InnerException);
|
|
Assert.AreEqual("path", ex.ParamName);
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Path_Empty()
|
|
{
|
|
var path = string.Empty;
|
|
|
|
var actual = PosixPath.GetDirectoryName(path);
|
|
|
|
Assert.IsNotNull(actual);
|
|
Assert.AreEqual(".", actual);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Path_TrailingForwardSlash()
|
|
{
|
|
var path = "/abc/";
|
|
|
|
var actual = PosixPath.GetDirectoryName(path);
|
|
|
|
Assert.IsNotNull(actual);
|
|
Assert.AreEqual("/abc", actual);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Path_FileWithoutNoDirectory()
|
|
{
|
|
var path = "abc.log";
|
|
|
|
var actual = PosixPath.GetDirectoryName(path);
|
|
|
|
Assert.IsNotNull(actual);
|
|
Assert.AreEqual(".", actual);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Path_FileInRootDirectory()
|
|
{
|
|
var path = "/abc.log";
|
|
|
|
var actual = PosixPath.GetDirectoryName(path);
|
|
|
|
Assert.IsNotNull(actual);
|
|
Assert.AreEqual("/", actual);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Path_RootDirectoryOnly()
|
|
{
|
|
var path = "/";
|
|
|
|
var actual = PosixPath.GetDirectoryName(path);
|
|
|
|
Assert.IsNotNull(actual);
|
|
Assert.AreEqual("/", actual);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Path_FileInNonRootDirectory()
|
|
{
|
|
var path = "/home/sshnet/xyz";
|
|
|
|
var actual = PosixPath.GetDirectoryName(path);
|
|
|
|
Assert.IsNotNull(actual);
|
|
Assert.AreEqual("/home/sshnet", actual);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Path_BackslashIsNotConsideredDirectorySeparator()
|
|
{
|
|
var path = "/home\\abc.log";
|
|
|
|
var actual = PosixPath.GetDirectoryName(path);
|
|
|
|
Assert.IsNotNull(actual);
|
|
Assert.AreEqual("/", actual);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Path_ColonIsNotConsideredPathSeparator()
|
|
{
|
|
var path = "/home:abc.log";
|
|
|
|
var actual = PosixPath.GetDirectoryName(path);
|
|
|
|
Assert.IsNotNull(actual);
|
|
Assert.AreEqual("/", actual);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Path_LeadingWhitespace()
|
|
{
|
|
var path = " / \tabc";
|
|
|
|
var actual = PosixPath.GetDirectoryName(path);
|
|
|
|
Assert.IsNotNull(actual);
|
|
Assert.AreEqual(" ", actual);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Path_TrailingWhitespace()
|
|
{
|
|
var path = "/abc \t ";
|
|
|
|
var actual = PosixPath.GetDirectoryName(path);
|
|
|
|
Assert.IsNotNull(actual);
|
|
Assert.AreEqual("/", actual);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Path_OnlyWhitespace()
|
|
{
|
|
var path = " ";
|
|
|
|
var actual = PosixPath.GetDirectoryName(path);
|
|
|
|
Assert.IsNotNull(actual);
|
|
Assert.AreEqual(".", actual);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Path_FileNameOnlyWhitespace()
|
|
{
|
|
var path = "/home/\t ";
|
|
|
|
var actual = PosixPath.GetDirectoryName(path);
|
|
|
|
Assert.IsNotNull(actual);
|
|
Assert.AreEqual("/home", actual);
|
|
}
|
|
}
|
|
}
|