| | 1 | | using NUnit.Framework; |
| | 2 | |
|
| | 3 | | namespace DCL.ABConverter |
| | 4 | | { |
| | 5 | | public class ParseOptionShould |
| | 6 | | { |
| 0 | 7 | | readonly static string[] args = new string[] { "-unityRandomOption", "-testOption", "arg1", "arg2", "-garbage", |
| | 8 | |
|
| | 9 | | [Test] |
| | 10 | | public void FailWhenNoOptionsAreFound() |
| | 11 | | { |
| 0 | 12 | | Assert.IsFalse(DCL.ABConverter.Utils.ParseOptionExplicit(args, null, 0, out string[] test)); |
| 0 | 13 | | Assert.IsFalse(DCL.ABConverter.Utils.ParseOptionExplicit(args, "blah", 0, out string[] test2)); |
| 0 | 14 | | Assert.IsTrue(test == null); |
| 0 | 15 | | Assert.IsTrue(test2 == null); |
| 0 | 16 | | } |
| | 17 | |
|
| | 18 | | [Test] |
| | 19 | | public void FailWhenTooManyArgumentsAreGiven() |
| | 20 | | { |
| 0 | 21 | | Assert.IsFalse(DCL.ABConverter.Utils.ParseOptionExplicit(args, "testOption", 5, out string[] test5)); |
| 0 | 22 | | Assert.IsFalse(DCL.ABConverter.Utils.ParseOptionExplicit(args, null, 5, out string[] test6)); |
| 0 | 23 | | Assert.IsTrue(test5 == null); |
| 0 | 24 | | Assert.IsTrue(test6 == null); |
| 0 | 25 | | } |
| | 26 | |
|
| | 27 | | [Test] |
| | 28 | | [TestCase(null, null, -1)] |
| | 29 | | [TestCase(null, "asdasdasd", -1)] |
| | 30 | | [TestCase(null, "asdasdasd", int.MaxValue)] |
| 0 | 31 | | public void NotCrashWhenInvalidArgsAreGiven(string[] rawArgsList, string optionName, int expectedArgsQty) { Asse |
| | 32 | |
|
| | 33 | | [Test] |
| | 34 | | public void SucceedWhenOptionsAreFound() |
| | 35 | | { |
| 0 | 36 | | Assert.IsTrue(DCL.ABConverter.Utils.ParseOptionExplicit(args, "testOption", 0, out string[] test)); |
| 0 | 37 | | Assert.IsTrue(test == null); |
| 0 | 38 | | } |
| | 39 | |
|
| | 40 | | [Test] |
| | 41 | | public void SucceedExtractingArguments() |
| | 42 | | { |
| 0 | 43 | | if (DCL.ABConverter.Utils.ParseOptionExplicit(args, "testOption", 1, out string[] test)) |
| | 44 | | { |
| 0 | 45 | | Assert.IsTrue(test != null); |
| 0 | 46 | | Assert.IsTrue(test.Length == 1); |
| 0 | 47 | | Assert.IsTrue(test[0] == "arg1"); |
| | 48 | | } |
| | 49 | |
|
| 0 | 50 | | if (DCL.ABConverter.Utils.ParseOptionExplicit(args, "testOption", 2, out string[] test2)) |
| | 51 | | { |
| 0 | 52 | | Assert.IsTrue(test2 != null); |
| 0 | 53 | | Assert.IsTrue(test2.Length == 2); |
| 0 | 54 | | Assert.IsTrue(test2[0] == "arg1"); |
| 0 | 55 | | Assert.IsTrue(test2[1] == "arg2"); |
| | 56 | | } |
| 0 | 57 | | } |
| | 58 | | } |
| | 59 | | } |