1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
- using System . Text . RegularExpressions ;
5
4
using PerformanceTestReportViewer . Definition ;
6
- using PerformanceTestReportViewer . UI ;
7
- using Unity . PerformanceTesting . Data ;
5
+ using PerformanceTestReportViewer . Editor . UI ;
8
6
9
- namespace PerformanceTestReportViewer
7
+ namespace PerformanceTestReportViewer . Editor
10
8
{
11
- public static class Utility
9
+ internal static class Utility
12
10
{
13
- // [prefix][categoryName]Definition
14
- public static readonly Regex sampleGroupNameWithSampleTargetRegex = new ( @"^\[([\w\.]+)\]\[([\w\.]+)\](.+)$" ) ;
15
- public static readonly Regex sampleGroupNameWithoutSampleTargetRegex = new ( @"^\[([\w\.]+)\](.+)$" ) ;
16
- public static bool TryParseFromSampleGroupName ( string sampleGroupName , out string sampleTarget , out string category , out string definition )
17
- {
18
- sampleTarget = string . Empty ;
19
- category = string . Empty ;
20
- definition = string . Empty ;
21
-
22
- if ( sampleGroupName == "Time" )
23
- {
24
- definition = sampleGroupName ;
25
- return true ;
26
- }
27
-
28
- var match = sampleGroupNameWithSampleTargetRegex . Match ( sampleGroupName ) ;
29
- if ( match . Success == false )
30
- {
31
- match = sampleGroupNameWithoutSampleTargetRegex . Match ( sampleGroupName ) ;
32
- if ( match . Success == false )
33
- return false ;
34
-
35
- category = match . Groups [ 1 ] . Value ;
36
- definition = match . Groups [ 2 ] . Value ;
37
- return true ;
38
- }
39
-
40
- if ( match . Groups . Count != 4 )
41
- return false ;
42
-
43
- sampleTarget = match . Groups [ 1 ] . Value ;
44
- category = match . Groups [ 2 ] . Value ;
45
- definition = match . Groups [ 3 ] . Value ;
46
- return true ;
47
- }
48
-
49
- public static string FormatSampleGroupName ( string sampleTarget , string category , string definition )
50
- {
51
- if ( string . IsNullOrEmpty ( sampleTarget ) )
52
- return $ "[{ category } ]{ definition } ";
53
-
54
- return $ "[{ sampleTarget } ][{ category } ]{ definition } ";
55
- }
56
-
57
- private static readonly Regex parameterizedTestNameRegex = new Regex ( @"(.*)\((.+)\)" ) ;
58
- public static bool IsParameterizedTest ( string testName , out string testNameWithoutParameter , out string parameter )
11
+ public static IEnumerable < string > GetTags ( this PerformanceTestResultContext resultContext )
59
12
{
60
- // TODO: Not working when the parameter value contains '(' or ')' ...
61
- parameter = string . Empty ;
62
- testNameWithoutParameter = string . Empty ;
63
- var match = parameterizedTestNameRegex . Match ( testName ) ;
64
-
65
- if ( match . Success == false )
66
- return false ;
67
-
68
- if ( match . Groups . Count != 3 )
69
- return false ;
13
+ if ( resultContext == null || resultContext . Results == null || resultContext . Results . Length == 0 )
14
+ return Enumerable . Empty < string > ( ) ;
70
15
71
- testNameWithoutParameter = match . Groups [ 1 ] . Value ;
72
- parameter = match . Groups [ 2 ] . Value ;
73
- return true ;
16
+ return resultContext . GetSampleGroupDefinitions ( ) . SelectMany ( g => g . Tags ) . Distinct ( ) ;
74
17
}
75
18
76
19
public static IEnumerable < T > TrySort < T , T2 > ( this IEnumerable < T > collection , Func < T , T2 > keySelector , SortMethod sortMethod )
@@ -88,31 +31,6 @@ public static IEnumerable<T> TrySort<T, T2>(this IEnumerable<T> collection, Func
88
31
}
89
32
}
90
33
91
- public static IEnumerable < string > GetSampleTargets ( this PerformanceTestResultContext resultContext )
92
- {
93
- if ( resultContext == null || resultContext . Results == null || resultContext . Results . Length == 0 )
94
- return Enumerable . Empty < string > ( ) ;
95
-
96
- return resultContext . Results
97
- . SelectMany ( t => t . SampleGroups )
98
- . Select ( s =>
99
- {
100
- bool result = TryParseFromSampleGroupName ( s . Name , out string sampleTarget , out _ , out _ ) ;
101
- return ( result , sampleTarget ) ;
102
- } )
103
- . Where ( p => p . result && string . IsNullOrEmpty ( p . sampleTarget ) == false )
104
- . Select ( p => p . sampleTarget )
105
- . Distinct ( ) ;
106
- }
107
-
108
- public static IEnumerable < string > GetTags ( this PerformanceTestResultContext resultContext )
109
- {
110
- if ( resultContext == null || resultContext . Results == null || resultContext . Results . Length == 0 )
111
- return Enumerable . Empty < string > ( ) ;
112
-
113
- return resultContext . GetSampleGroupDefinitions ( ) . SelectMany ( g => g . Tags ) . Distinct ( ) ;
114
- }
115
-
116
34
public static IEnumerable < ISampleDefinition > GetSampleGroupDefinitions ( this PerformanceTestResultContext resultContext )
117
35
{
118
36
return resultContext . Results
@@ -134,46 +52,5 @@ public static string GetSampleUnit(this SampleElement[] elements)
134
52
135
53
return string . Empty ;
136
54
}
137
-
138
- public static bool TryExtractCommonStrings ( string [ ] input , out string common , out string [ ] variations )
139
- {
140
- variations = null ;
141
- common = FindCommonPrefix ( input ) ;
142
- if ( string . IsNullOrEmpty ( common ) )
143
- return false ;
144
-
145
- variations = new string [ input . Length ] ;
146
- for ( int i = 0 ; i < input . Length ; ++ i )
147
- {
148
- string remaining = input [ i ] . Substring ( common . Length ) ;
149
- variations [ i ] = remaining ;
150
- }
151
-
152
- return true ;
153
- }
154
-
155
- private static string FindCommonPrefix ( string [ ] strings )
156
- {
157
- if ( strings == null || strings . Length == 0 )
158
- return "" ;
159
-
160
- string firstString = strings [ 0 ] ;
161
-
162
- for ( int i = 1 ; i < strings . Length ; i ++ )
163
- {
164
- int j = 0 ;
165
- while ( j < firstString . Length && j < strings [ i ] . Length && firstString [ j ] == strings [ i ] [ j ] )
166
- {
167
- j ++ ;
168
- }
169
-
170
- firstString = firstString . Substring ( 0 , j ) ;
171
-
172
- if ( string . IsNullOrEmpty ( firstString ) )
173
- break ;
174
- }
175
-
176
- return firstString ;
177
- }
178
55
}
179
56
}
0 commit comments