2026-10-02 22:05:12 +08:00
|
|
|
using YKanBan.Launching;
|
2026-10-04 16:17:05 +08:00
|
|
|
using YKanBan.Tests.TestUtilities;
|
2026-10-02 22:05:12 +08:00
|
|
|
|
|
|
|
|
namespace YKanBan.Tests.Launching;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2026-10-04 16:17:05 +08:00
|
|
|
/// Tests for the <c>ykanban <path></c> command-line contract: exactly one
|
|
|
|
|
/// existing folder, resolved to an absolute path; everything else is rejected.
|
2026-10-02 22:05:12 +08:00
|
|
|
/// </summary>
|
|
|
|
|
[TestClass]
|
2026-10-04 10:22:02 +08:00
|
|
|
public class LaunchArgumentsTests {
|
2026-10-02 22:05:12 +08:00
|
|
|
[TestMethod]
|
2026-10-04 10:22:02 +08:00
|
|
|
public void NoArgumentsIsRejected() {
|
2026-10-02 22:05:12 +08:00
|
|
|
Assert.IsFalse(LaunchArguments.TryParse([], out string? path));
|
|
|
|
|
Assert.IsNull(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2026-10-04 10:22:02 +08:00
|
|
|
public void BlankArgumentIsRejected() {
|
2026-10-02 22:05:12 +08:00
|
|
|
Assert.IsFalse(LaunchArguments.TryParse([" "], out string? path));
|
|
|
|
|
Assert.IsNull(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2026-10-04 10:22:02 +08:00
|
|
|
public void MoreThanOneArgumentIsRejected() {
|
2026-10-02 22:05:12 +08:00
|
|
|
Assert.IsFalse(LaunchArguments.TryParse(["a", "b"], out string? path));
|
|
|
|
|
Assert.IsNull(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2026-10-04 16:17:05 +08:00
|
|
|
[DataRow("--help")]
|
|
|
|
|
[DataRow("-x")]
|
|
|
|
|
public void OptionLikeArgumentIsRejected(string argument) {
|
|
|
|
|
Assert.IsFalse(LaunchArguments.TryParse([argument], out string? path));
|
|
|
|
|
Assert.IsNull(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void NonExistentFolderIsRejected() {
|
|
|
|
|
using var directory = new TempDirectory();
|
|
|
|
|
string missing = Path.Combine(directory.FullPath, "nope");
|
|
|
|
|
|
|
|
|
|
Assert.IsFalse(LaunchArguments.TryParse([missing], out string? path));
|
|
|
|
|
Assert.IsNull(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void FileInsteadOfFolderIsRejected() {
|
|
|
|
|
using var directory = new TempDirectory();
|
|
|
|
|
string file = Path.Combine(directory.FullPath, "file.txt");
|
|
|
|
|
File.WriteAllText(file, "x");
|
|
|
|
|
|
|
|
|
|
Assert.IsFalse(LaunchArguments.TryParse([file], out string? path));
|
|
|
|
|
Assert.IsNull(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void ExistingFolderIsAcceptedAsAnAbsolutePath() {
|
|
|
|
|
using var directory = new TempDirectory();
|
|
|
|
|
|
|
|
|
|
bool parsed = LaunchArguments.TryParse([directory.FullPath], out string? path);
|
|
|
|
|
|
2026-10-02 22:05:12 +08:00
|
|
|
Assert.IsTrue(parsed);
|
2026-10-04 16:17:05 +08:00
|
|
|
Assert.AreEqual(Path.GetFullPath(directory.FullPath), path);
|
|
|
|
|
Assert.IsTrue(Path.IsPathRooted(path));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void RelativePathIsResolvedToAbsolute() {
|
|
|
|
|
using var directory = new TempDirectory();
|
|
|
|
|
string relative = Path.GetRelativePath(Environment.CurrentDirectory, directory.FullPath);
|
|
|
|
|
|
|
|
|
|
bool parsed = LaunchArguments.TryParse([relative], out string? path);
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(parsed);
|
|
|
|
|
Assert.IsTrue(Path.IsPathRooted(path));
|
|
|
|
|
Assert.AreEqual(Path.GetFullPath(relative), path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MalformedPathIsRejected() {
|
|
|
|
|
Assert.IsFalse(LaunchArguments.TryParse(["bad\0path"], out string? path));
|
|
|
|
|
Assert.IsNull(path);
|
2026-10-02 22:05:12 +08:00
|
|
|
}
|
|
|
|
|
}
|