-
-
Notifications
You must be signed in to change notification settings - Fork 545
Expand file tree
/
Copy pathCommandLineTest.cs
More file actions
118 lines (108 loc) · 7 KB
/
CommandLineTest.cs
File metadata and controls
118 lines (108 loc) · 7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
namespace Notepads.UnitTest
{
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Notepads.Utilities;
[TestClass]
public class CommandLineTest
{
private const string cmdArg = "notepads";
private const string pwshArg = "\"C:\\Users\\Test User\\AppData\\Local\\Microsoft\\WindowsApps\\Notepads.exe\"";
private const string windowsRoot = "C:";
private const string wslRoot = @"\\wsl$\Ubuntu";
private static IEnumerable<string[]> GetTestData(string root, string alias)
{
yield return new string[] { $"{root}\\", $"{alias} \"{root}\\1.txt\"", $"{root}\\1.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"{root}\\1 2.txt\"", $"{root}\\1 2.txt" };
yield return new string[] { $"{root}\\", $"{alias} {root}\\1.txt", $"{root}\\1.txt" };
yield return new string[] { $"{root}\\", $"{alias} {root}\\1 2.txt", $"{root}\\1 2.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \"{root}\\2.txt\"", $"{root}\\2.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \"{root}\\2 3.txt\"", $"{root}\\2 3.txt" };
yield return new string[] { $"{root}\\1", $"{alias} {root}\\2.txt", $"{root}\\2.txt" };
yield return new string[] { $"{root}\\1", $"{alias} {root}\\2 3.txt", $"{root}\\2 3.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"\\1.txt\"", $"{root}\\1.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"\\1 2.txt\"", $"{root}\\1 2.txt" };
yield return new string[] { $"{root}\\", $"{alias} \\1.txt", $"{root}\\1.txt" };
yield return new string[] { $"{root}\\", $"{alias} \\1 2.txt", $"{root}\\1 2.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \"\\2.txt\"", $"{root}\\2.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \"\\2 3.txt\"", $"{root}\\2 3.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \\2.txt", $"{root}\\2.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \\2 3.txt", $"{root}\\2 3.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"1.txt\"", $"{root}\\1.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"1 2.txt\"", $"{root}\\1 2.txt" };
yield return new string[] { $"{root}\\", $"{alias} 1.txt", $"{root}\\1.txt" };
yield return new string[] { $"{root}\\", $"{alias} 1 2.txt", $"{root}\\1 2.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \"2.txt\"", $"{root}\\1\\2.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \"2 3.txt\"", $"{root}\\1\\2 3.txt" };
yield return new string[] { $"{root}\\1", $"{alias} 2.txt", $"{root}\\1\\2.txt" };
yield return new string[] { $"{root}\\1", $"{alias} 2 3.txt", $"{root}\\1\\2 3.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"1\\2.txt\"", $"{root}\\1\\2.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"1 2\\3 4.txt\"", $"{root}\\1 2\\3 4.txt" };
yield return new string[] { $"{root}\\", $"{alias} 1\\2.txt", $"{root}\\1\\2.txt" };
yield return new string[] { $"{root}\\", $"{alias} 1 2\\3 4.txt", $"{root}\\1 2\\3 4.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \"2\\3.txt\"", $"{root}\\1\\2\\3.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \"2 3\\4 5.txt\"", $"{root}\\1\\2 3\\4 5.txt" };
yield return new string[] { $"{root}\\1", $"{alias} 2\\3.txt", $"{root}\\1\\2\\3.txt" };
yield return new string[] { $"{root}\\1", $"{alias} 2 3\\4 5.txt", $"{root}\\1\\2 3\\4 5.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"D:\\1.txt\"", $"D:\\1.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"D:\\1\\2.txt\"", $"D:\\1\\2.txt" };
yield return new string[] { $"{root}\\", $"{alias} D:\\1.txt", $"D:\\1.txt" };
yield return new string[] { $"{root}\\", $"{alias} D:\\1\\2.txt", $"D:\\1\\2.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"D:\\1 2.txt\"", $"D:\\1 2.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"D:\\1 2\\3 4.txt\"", $"D:\\1 2\\3 4.txt" };
yield return new string[] { $"{root}\\", $"{alias} D:\\1 2.txt", $"D:\\1 2.txt" };
yield return new string[] { $"{root}\\", $"{alias} D:\\1 2\\3 4.txt", $"D:\\1 2\\3 4.txt" };
}
private static IEnumerable<string[]> GetCommandPromptTestData()
{
return GetTestData(windowsRoot, cmdArg);
}
private static IEnumerable<string[]> GetPowerShellTestData()
{
return GetTestData(windowsRoot, pwshArg);
}
private static IEnumerable<string[]> GetWslTestData()
{
foreach(var data in GetTestData(wslRoot, pwshArg))
{
yield return data;
}
yield return new string[] { $"{wslRoot}\\", $"{pwshArg} \"/etc/sudo.conf\"", $"{wslRoot}\\etc\\sudo.conf" };
yield return new string[] { $"{wslRoot}\\", $"{pwshArg} \"etc/sudo.conf\"", $"{wslRoot}\\etc\\sudo.conf" };
yield return new string[] { $"{wslRoot}\\", $"{pwshArg} /etc/sudo.conf", $"{wslRoot}\\etc\\sudo.conf" };
yield return new string[] { $"{wslRoot}\\", $"{pwshArg} etc/sudo.conf", $"{wslRoot}\\etc\\sudo.conf" };
yield return new string[] { $"{wslRoot}\\etc", $"{pwshArg} \"/etc/sudo.conf\"", $"{wslRoot}\\etc\\sudo.conf" };
yield return new string[] { $"{wslRoot}\\etc", $"{pwshArg} \"sudo.conf\"", $"{wslRoot}\\etc\\sudo.conf" };
yield return new string[] { $"{wslRoot}\\etc", $"{pwshArg} /etc/sudo.conf", $"{wslRoot}\\etc\\sudo.conf" };
yield return new string[] { $"{wslRoot}\\etc", $"{pwshArg} sudo.conf", $"{wslRoot}\\etc\\sudo.conf" };
}
[DataTestMethod]
[DynamicData(nameof(GetCommandPromptTestData), DynamicDataSourceType.Method)]
public void CommandLineTestForCommandPrompt(string dir, string arg, string result)
{
Assert.AreEqual(
CommandLineUtility.GetAbsolutePathFromCommandLine(dir, arg),
result
);
}
[DataTestMethod]
[DynamicData(nameof(GetPowerShellTestData), DynamicDataSourceType.Method)]
public void CommandLineTestForPowerShell(string dir, string arg, string result)
{
Assert.AreEqual(
CommandLineUtility.GetAbsolutePathFromCommandLine(dir, arg),
result
);
}
[DataTestMethod]
[DynamicData(nameof(GetWslTestData), DynamicDataSourceType.Method)]
public void CommandLineTestForWsl(string dir, string arg, string result)
{
Assert.AreEqual(
CommandLineUtility.GetAbsolutePathFromCommandLine(dir, arg),
result
);
}
}
}