Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.distiller; | 5 package org.chromium.distiller; |
| 6 | 6 |
| 7 import com.google.gwt.core.client.JavaScriptException; | 7 import com.google.gwt.core.client.JavaScriptException; |
| 8 import com.google.gwt.regexp.shared.RegExp; | 8 import com.google.gwt.regexp.shared.RegExp; |
| 9 import com.google.gwt.user.client.Window; | 9 import com.google.gwt.user.client.Window; |
| 10 | 10 |
| 11 import java.util.ArrayList; | |
| 12 import java.util.List; | |
| 11 import java.util.Map; | 13 import java.util.Map; |
| 12 import java.util.Set; | 14 import java.util.Set; |
| 13 import java.util.TreeMap; | 15 import java.util.TreeMap; |
| 14 | 16 |
| 15 public class JsTestSuiteBase { | 17 public class JsTestSuiteBase { |
| 16 private boolean debug = false; | 18 private boolean debug = false; |
| 17 | 19 |
| 18 public interface TestCaseRunner { | 20 public interface TestCaseRunner { |
| 19 public void run(JsTestCase testCase) throws Throwable; | 21 public void run(JsTestCase testCase) throws Throwable; |
| 20 } | 22 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 } | 120 } |
| 119 return results; | 121 return results; |
| 120 } | 122 } |
| 121 | 123 |
| 122 public Set<String> getTestNames() { | 124 public Set<String> getTestNames() { |
| 123 return tests.keySet(); | 125 return tests.keySet(); |
| 124 } | 126 } |
| 125 } | 127 } |
| 126 | 128 |
| 127 private class TestFilter { | 129 private class TestFilter { |
| 128 RegExp regexp; | 130 List<RegExp> pos; |
| 131 List<RegExp> neg; | |
| 132 | |
| 129 TestFilter(String filter) { | 133 TestFilter(String filter) { |
| 130 if (filter != null) regexp = RegExp.compile(filter); | 134 pos = new ArrayList<RegExp>(); |
| 135 neg = new ArrayList<RegExp>(); | |
| 136 | |
| 137 if (filter == null) return; | |
| 138 | |
| 139 int begin = 0; | |
| 140 filter = filter + ":"; | |
| 141 for (int i = 0; i < filter.length(); i++) { | |
|
cjhopman
2015/03/31 17:55:40
how about just split on "-" and then split each si
wychen
2015/03/31 18:26:49
Done.
| |
| 142 if (filter.charAt(i) == ':' || filter.charAt(i) == '-') { | |
| 143 if (begin != i) { | |
| 144 Boolean isNeg = false; | |
|
cjhopman
2015/03/31 17:55:40
Doesn't this need to be initialized outside the lo
wychen
2015/03/31 18:26:49
isNeg is used to tell whether the current segment
| |
| 145 | |
| 146 if (filter.charAt(begin) == '-') { | |
| 147 isNeg = true; | |
| 148 begin++; | |
| 149 } | |
| 150 String q = filter.substring(begin, i); | |
| 151 q = q.replace(".", "\\."); | |
| 152 q = q.replace("*", ".*"); | |
| 153 q = q.replace("?", "."); | |
| 154 RegExp r = RegExp.compile("^" + q + "$"); | |
| 155 if (isNeg) { | |
| 156 neg.add(r); | |
| 157 } else { | |
| 158 pos.add(r); | |
| 159 } | |
| 160 } | |
| 161 if (filter.charAt(i) == ':') { | |
| 162 begin = i + 1; | |
| 163 } else { | |
| 164 begin = i; | |
| 165 } | |
| 166 } | |
| 167 } | |
| 131 } | 168 } |
| 132 | 169 |
| 133 public boolean test(String className, String methodName) { | 170 public boolean test(String className, String methodName) { |
| 134 if (regexp == null) return true; | 171 boolean ans = false; |
| 135 return regexp.test(className + "." + methodName); | 172 if (pos.size() == 0) ans = true; |
| 173 for (int i = 0; i < pos.size(); i++) { | |
| 174 if (pos.get(i).test(className + "." + methodName)) { | |
| 175 ans = true; | |
| 176 } | |
| 177 } | |
| 178 for (int i = 0; i < neg.size(); i++) { | |
| 179 if (neg.get(i).test(className + "." + methodName)) { | |
| 180 ans = false; | |
| 181 } | |
| 182 } | |
| 183 return ans; | |
| 136 } | 184 } |
| 137 } | 185 } |
| 138 | 186 |
| 139 private TreeMap<String, TestCase> testCases; | 187 private TreeMap<String, TestCase> testCases; |
| 140 | 188 |
| 141 public JsTestSuiteBase() { | 189 public JsTestSuiteBase() { |
| 142 testCases = new TreeMap<String, TestCase>(); | 190 testCases = new TreeMap<String, TestCase>(); |
| 143 debug = "1".equals(Window.Location.getParameter("debug")); | 191 debug = "1".equals(Window.Location.getParameter("debug")); |
| 144 } | 192 } |
| 145 | 193 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 } | 247 } |
| 200 | 248 |
| 201 public static String stackFrameString(StackTraceElement ste) { | 249 public static String stackFrameString(StackTraceElement ste) { |
| 202 String mangledName = ste.getMethodName(); | 250 String mangledName = ste.getMethodName(); |
| 203 mangledName = mangledName.split("__")[0]; | 251 mangledName = mangledName.split("__")[0]; |
| 204 String demangledName = | 252 String demangledName = |
| 205 mangledName.replaceAll("_1", "~~").replaceAll("_", ".").replaceA ll("~~", "_"); | 253 mangledName.replaceAll("_1", "~~").replaceAll("_", ".").replaceA ll("~~", "_"); |
| 206 return demangledName + "(" + ste.getFileName() + ":" + ste.getLineNumber () + ")"; | 254 return demangledName + "(" + ste.getFileName() + ":" + ste.getLineNumber () + ")"; |
| 207 } | 255 } |
| 208 } | 256 } |
| OLD | NEW |