1 // ***********************************************************************
2 // Copyright (c) 2011 Charlie Poole
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 // ***********************************************************************
25 #define NUNIT_FRAMEWORK
29 using System.Collections.Generic;
31 namespace NUnit.Common
34 /// TestNameParser is used to parse the arguments to the
35 /// -run option, separating testnames at the correct point.
37 public class TestNameParser
40 /// Parse the -run argument and return an array of argument
42 /// <param name="argument">argument</param>
43 /// <returns></returns>
44 public static string[] Parse(string argument)
46 List<string> list = new List<string>();
49 while (index < argument.Length)
51 string name = GetTestName(argument, ref index);
52 if (name != null && name != string.Empty)
56 return list.ToArray();
59 private static string GetTestName(string argument, ref int index)
61 int separator = GetSeparator(argument, index);
66 result = argument.Substring(index, separator - index).Trim();
67 index = separator + 1;
71 result = argument.Substring(index).Trim();
72 index = argument.Length;
78 private static int GetSeparator(string argument, int index)
82 while (index < argument.Length)
84 switch (argument[index])
92 while (++index < argument.Length && argument[index] != '"')