[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Common / TestNameParser.cs
1 // ***********************************************************************
2 // Copyright (c) 2011 Charlie Poole
3 //
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:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
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 // ***********************************************************************
23 #define PORTABLE
24 #define TIZEN
25 #define NUNIT_FRAMEWORK
26 #define NUNITLITE
27 #define NET_4_5
28 #define PARALLEL
29 using System.Collections.Generic;
30
31 namespace NUnit.Common
32 {
33     /// <summary>
34     /// TestNameParser is used to parse the arguments to the 
35     /// -run option, separating testnames at the correct point.
36     /// </summary>
37     public class TestNameParser
38     {
39         /// <summary>
40         /// Parse the -run argument and return an array of argument
41         /// </summary>
42         /// <param name="argument">argument</param>
43         /// <returns></returns>
44         public static string[] Parse(string argument)
45         {
46             List<string> list = new List<string>();
47
48             int index = 0;
49             while (index < argument.Length)
50             {
51                 string name = GetTestName(argument, ref index);
52                 if (name != null && name != string.Empty)
53                     list.Add(name);
54             }
55
56             return list.ToArray();
57         }
58
59         private static string GetTestName(string argument, ref int index)
60         {
61             int separator = GetSeparator(argument, index);
62             string result;
63
64             if (separator >= 0)
65             {
66                 result = argument.Substring(index, separator - index).Trim();
67                 index = separator + 1;
68             }
69             else
70             {
71                 result = argument.Substring(index).Trim();
72                 index = argument.Length;
73             }
74
75             return result;
76         }
77
78         private static int GetSeparator(string argument, int index)
79         {
80             int nest = 0;
81
82             while (index < argument.Length)
83             {
84                 switch (argument[index])
85                 {
86                     case ',':
87                         if (nest == 0)
88                             return index;
89                         break;
90
91                     case '"':
92                         while (++index < argument.Length && argument[index] != '"')
93                             ;
94                         break;
95
96                     case '(':
97                     case '<':
98                         nest++;
99                         break;
100
101                     case ')':
102                     case '>':
103                         nest--;
104                         break;
105                 }
106
107                 index++;
108             }
109
110             return -1;
111         }
112     }
113 }