-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GetOptTests_Inherited_WindowsConventions.cs
143 lines (112 loc) · 4.68 KB
/
GetOptTests_Inherited_WindowsConventions.cs
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System;
namespace getopt.net.tests {
[TestClass]
public class GetOptTests_Inherited_Windows: GetOpt {
public GetOptTests_Inherited_Windows() {
AllowWindowsConventions = true;
Options = new[] {
new Option("windowsarg", ArgumentType.None, 'w'),
new Option("AnotherWindowsArg", ArgumentType.None, 'A')
};
}
[TestMethod]
public void TestIsLongOption() {
Assert.IsTrue(IsLongOption("/windowsarg"));
Assert.IsTrue(IsLongOption("/AnotherWindowsArg"));
Assert.IsFalse(IsLongOption("/a"));
Assert.IsTrue(IsLongOption("--posix-like"));
}
[TestMethod]
public void TestIsShortOption() {
Assert.IsTrue(IsShortOption("/w"));
Assert.IsTrue(IsShortOption("/W"));
Assert.IsTrue(IsShortOption("/0"));
Assert.IsFalse(IsShortOption(":m"));
Assert.IsFalse(IsShortOption("O"));
Assert.IsTrue(IsShortOption("-c"));
}
[TestMethod]
public void TestStripDashes() {
AppArgs = new[] { "no-dashes-or-slahes" };
Assert.AreEqual("no-dashes-or-slahes", StripDashes(true));
AppArgs = new[] { "-single-dash" };
Assert.AreEqual("single-dash", StripDashes(true));
AppArgs = new[] { "--double-dash" };
Assert.AreEqual("double-dash", StripDashes(true));
AppArgs = new[] { "-shortopt" };
Assert.AreEqual("shortopt", StripDashes(false));
AppArgs = new[] { "/single-slash" };
Assert.AreEqual("single-slash", StripDashes(true));
AppArgs = new[] { "/long-option" };
Assert.AreEqual("long-option", StripDashes(true));
AppArgs = new[] { "/shortopt" };
Assert.AreEqual("shortopt", StripDashes(false));
}
[TestMethod]
public void TestHasArgumentInOption_NoArgs() {
m_currentIndex = 0; // ensure we always start at first index
AppArgs = new[] {
// no arguments here
"/noarg", "-c", "--noarg"
};
Assert.IsFalse(HasArgumentInOption(out var optName, out var optVal));
Assert.IsNotNull(optName);
Assert.AreEqual("noarg", optName);
Assert.IsNull(optVal);
m_currentIndex++; // manually increment counter
Assert.IsFalse(HasArgumentInOption(out optName, out optVal));
Assert.IsNotNull(optName);
Assert.AreEqual("c", optName);
Assert.IsNull(optVal);
m_currentIndex++;
Assert.IsFalse(HasArgumentInOption(out optName, out optVal));
Assert.IsNotNull(optName);
Assert.AreEqual("noarg", optName);
Assert.IsNull(optVal);
}
[TestMethod]
public void TestHasArgumentInOption_WinStyleArgs() {
m_currentIndex = 0;
AppArgs = new[] {
// Windows style
"/has:arg", "/has arg", "/has=arg",
};
Assert.IsTrue(HasArgumentInOption(out var optName, out var optVal));
Assert.IsNotNull(optName);
Assert.AreEqual("/has", optName);
Assert.IsNotNull(optVal);
Assert.AreEqual("arg", optVal);
m_currentIndex++; // manually increment counter
Assert.IsTrue(HasArgumentInOption(out optName, out optVal));
Assert.IsNotNull(optName);
Assert.AreEqual("/has", optName);
Assert.IsNotNull(optVal);
Assert.AreEqual("arg", optVal);
m_currentIndex++;
Assert.IsTrue(HasArgumentInOption(out optName, out optVal));
Assert.IsNotNull(optName);
Assert.AreEqual("/has", optName);
Assert.IsNotNull(optVal);
Assert.AreEqual("arg", optVal);
}
[TestMethod]
public void TestHasArgumentInOption_GnuPosixStyleArgs() {
m_currentIndex = 0;
AppArgs = new[] {
// GNU/POSIX style
"--has arg", "--has=arg"
};
Assert.IsTrue(HasArgumentInOption(out var optName, out var optVal));
Assert.IsNotNull(optName);
Assert.AreEqual("--has", optName);
Assert.IsNotNull(optVal);
Assert.AreEqual("arg", optVal);
m_currentIndex++; // manually increment counter
Assert.IsTrue(HasArgumentInOption(out optName, out optVal));
Assert.IsNotNull(optName);
Assert.AreEqual("--has", optName);
Assert.IsNotNull(optVal);
Assert.AreEqual("arg", optVal);
}
}
}