Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: pkg/analyzer/test/generated/test_support.dart

Issue 189803004: Translate private Java members to private Dart members. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweaks Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/test/generated/scanner_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.test_support; 8 library engine.test_support;
9 9
10 import 'package:analyzer/src/generated/java_core.dart'; 10 import 'package:analyzer/src/generated/java_core.dart';
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 * Assert that the number of errors that have been gathered matches the number of errors that are 77 * Assert that the number of errors that have been gathered matches the number of errors that are
78 * given and that they have the expected error codes and locations. The order in which the errors 78 * given and that they have the expected error codes and locations. The order in which the errors
79 * were gathered is ignored. 79 * were gathered is ignored.
80 * 80 *
81 * @param errorCodes the errors that should have been gathered 81 * @param errorCodes the errors that should have been gathered
82 * @throws AssertionFailedError if a different number of errors have been gath ered than were 82 * @throws AssertionFailedError if a different number of errors have been gath ered than were
83 * expected or if they do not have the same codes and locations 83 * expected or if they do not have the same codes and locations
84 */ 84 */
85 void assertErrors(List<AnalysisError> expectedErrors) { 85 void assertErrors(List<AnalysisError> expectedErrors) {
86 if (_errors.length != expectedErrors.length) { 86 if (_errors.length != expectedErrors.length) {
87 fail(expectedErrors); 87 _fail(expectedErrors);
88 } 88 }
89 List<AnalysisError> remainingErrors = new List<AnalysisError>(); 89 List<AnalysisError> remainingErrors = new List<AnalysisError>();
90 for (AnalysisError error in expectedErrors) { 90 for (AnalysisError error in expectedErrors) {
91 remainingErrors.add(error); 91 remainingErrors.add(error);
92 } 92 }
93 for (AnalysisError error in _errors) { 93 for (AnalysisError error in _errors) {
94 if (!foundAndRemoved(remainingErrors, error)) { 94 if (!_foundAndRemoved(remainingErrors, error)) {
95 fail(expectedErrors); 95 _fail(expectedErrors);
96 } 96 }
97 } 97 }
98 } 98 }
99 99
100 /** 100 /**
101 * Assert that the number of errors that have been gathered matches the number of errors that are 101 * Assert that the number of errors that have been gathered matches the number of errors that are
102 * given and that they have the expected error codes. The order in which the e rrors were gathered 102 * given and that they have the expected error codes. The order in which the e rrors were gathered
103 * is ignored. 103 * is ignored.
104 * 104 *
105 * @param expectedErrorCodes the error codes of the errors that should have be en gathered 105 * @param expectedErrorCodes the error codes of the errors that should have be en gathered
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 _lineInfoMap[source] = new LineInfo(lineStarts); 296 _lineInfoMap[source] = new LineInfo(lineStarts);
297 } 297 }
298 298
299 /** 299 /**
300 * Return `true` if the two errors are equivalent. 300 * Return `true` if the two errors are equivalent.
301 * 301 *
302 * @param firstError the first error being compared 302 * @param firstError the first error being compared
303 * @param secondError the second error being compared 303 * @param secondError the second error being compared
304 * @return `true` if the two errors are equivalent 304 * @return `true` if the two errors are equivalent
305 */ 305 */
306 bool equalErrors(AnalysisError firstError, AnalysisError secondError) => ident ical(firstError.errorCode, secondError.errorCode) && firstError.offset == second Error.offset && firstError.length == secondError.length && equalSources(firstErr or.source, secondError.source); 306 bool _equalErrors(AnalysisError firstError, AnalysisError secondError) => iden tical(firstError.errorCode, secondError.errorCode) && firstError.offset == secon dError.offset && firstError.length == secondError.length && _equalSources(firstE rror.source, secondError.source);
307 307
308 /** 308 /**
309 * Return `true` if the two sources are equivalent. 309 * Return `true` if the two sources are equivalent.
310 * 310 *
311 * @param firstSource the first source being compared 311 * @param firstSource the first source being compared
312 * @param secondSource the second source being compared 312 * @param secondSource the second source being compared
313 * @return `true` if the two sources are equivalent 313 * @return `true` if the two sources are equivalent
314 */ 314 */
315 bool equalSources(Source firstSource, Source secondSource) { 315 bool _equalSources(Source firstSource, Source secondSource) {
316 if (firstSource == null) { 316 if (firstSource == null) {
317 return secondSource == null; 317 return secondSource == null;
318 } else if (secondSource == null) { 318 } else if (secondSource == null) {
319 return false; 319 return false;
320 } 320 }
321 return firstSource == secondSource; 321 return firstSource == secondSource;
322 } 322 }
323 323
324 /** 324 /**
325 * Assert that the number of errors that have been gathered matches the number of errors that are 325 * Assert that the number of errors that have been gathered matches the number of errors that are
326 * given and that they have the expected error codes. The order in which the e rrors were gathered 326 * given and that they have the expected error codes. The order in which the e rrors were gathered
327 * is ignored. 327 * is ignored.
328 * 328 *
329 * @param errorCodes the errors that should have been gathered 329 * @param errorCodes the errors that should have been gathered
330 * @throws AssertionFailedError with 330 * @throws AssertionFailedError with
331 */ 331 */
332 void fail(List<AnalysisError> expectedErrors) { 332 void _fail(List<AnalysisError> expectedErrors) {
333 PrintStringWriter writer = new PrintStringWriter(); 333 PrintStringWriter writer = new PrintStringWriter();
334 writer.print("Expected "); 334 writer.print("Expected ");
335 writer.print(expectedErrors.length); 335 writer.print(expectedErrors.length);
336 writer.print(" errors:"); 336 writer.print(" errors:");
337 for (AnalysisError error in expectedErrors) { 337 for (AnalysisError error in expectedErrors) {
338 Source source = error.source; 338 Source source = error.source;
339 LineInfo lineInfo = _lineInfoMap[source]; 339 LineInfo lineInfo = _lineInfoMap[source];
340 writer.newLine(); 340 writer.newLine();
341 if (lineInfo == null) { 341 if (lineInfo == null) {
342 int offset = error.offset; 342 int offset = error.offset;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 387
388 /** 388 /**
389 * Search through the given list of errors for an error that is equal to the t arget error. If one 389 * Search through the given list of errors for an error that is equal to the t arget error. If one
390 * is found, remove it from the list and return `true`, otherwise return `fals e` 390 * is found, remove it from the list and return `true`, otherwise return `fals e`
391 * without modifying the list. 391 * without modifying the list.
392 * 392 *
393 * @param errors the errors through which we are searching 393 * @param errors the errors through which we are searching
394 * @param targetError the error being searched for 394 * @param targetError the error being searched for
395 * @return `true` if the error is found and removed from the list 395 * @return `true` if the error is found and removed from the list
396 */ 396 */
397 bool foundAndRemoved(List<AnalysisError> errors, AnalysisError targetError) { 397 bool _foundAndRemoved(List<AnalysisError> errors, AnalysisError targetError) {
398 for (AnalysisError error in errors) { 398 for (AnalysisError error in errors) {
399 if (equalErrors(error, targetError)) { 399 if (_equalErrors(error, targetError)) {
400 errors.remove(error); 400 errors.remove(error);
401 return true; 401 return true;
402 } 402 }
403 } 403 }
404 return true; 404 return true;
405 } 405 }
406 } 406 }
407 407
408 /** 408 /**
409 * The class `EngineTestCase` defines utility methods for making assertions. 409 * The class `EngineTestCase` defines utility methods for making assertions.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 static void assertContains(List<Object> array, List<Object> expectedElements) { 458 static void assertContains(List<Object> array, List<Object> expectedElements) {
459 int expectedSize = expectedElements.length; 459 int expectedSize = expectedElements.length;
460 if (array == null) { 460 if (array == null) {
461 JUnitTestCase.fail("Expected array of length ${expectedSize}; found null") ; 461 JUnitTestCase.fail("Expected array of length ${expectedSize}; found null") ;
462 } 462 }
463 if (array.length != expectedSize) { 463 if (array.length != expectedSize) {
464 JUnitTestCase.fail("Expected array of length ${expectedSize}; contained ${ array.length} elements"); 464 JUnitTestCase.fail("Expected array of length ${expectedSize}; contained ${ array.length} elements");
465 } 465 }
466 List<bool> found = new List<bool>.filled(expectedSize, false); 466 List<bool> found = new List<bool>.filled(expectedSize, false);
467 for (int i = 0; i < expectedSize; i++) { 467 for (int i = 0; i < expectedSize; i++) {
468 privateAssertContains(array, found, expectedElements[i]); 468 _privateAssertContains(array, found, expectedElements[i]);
469 } 469 }
470 } 470 }
471 471
472 /** 472 /**
473 * Assert that the array of actual values contain exactly the same values as t hose in the array of 473 * Assert that the array of actual values contain exactly the same values as t hose in the array of
474 * expected value, with the exception that the order of the elements is not re quired to be the 474 * expected value, with the exception that the order of the elements is not re quired to be the
475 * same. 475 * same.
476 * 476 *
477 * @param expectedValues the values that are expected to be found 477 * @param expectedValues the values that are expected to be found
478 * @param actualValues the actual values that are being compared against the e xpected values 478 * @param actualValues the actual values that are being compared against the e xpected values
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 if (actual == null || expected == null) { 510 if (actual == null || expected == null) {
511 if (identical(actual, expected)) { 511 if (identical(actual, expected)) {
512 return; 512 return;
513 } 513 }
514 if (actual == null) { 514 if (actual == null) {
515 JUnitTestCase.assertTrueMsg("Content not as expected: is 'null' expected : ${expected}", false); 515 JUnitTestCase.assertTrueMsg("Content not as expected: is 'null' expected : ${expected}", false);
516 } else { 516 } else {
517 JUnitTestCase.assertTrueMsg("Content not as expected: expected 'null' is : ${actual}", false); 517 JUnitTestCase.assertTrueMsg("Content not as expected: expected 'null' is : ${actual}", false);
518 } 518 }
519 } 519 }
520 int diffPos = getDiffPos(expected, actual); 520 int diffPos = _getDiffPos(expected, actual);
521 if (diffPos != -1) { 521 if (diffPos != -1) {
522 int diffAhead = Math.max(0, diffPos - _PRINT_RANGE); 522 int diffAhead = Math.max(0, diffPos - _PRINT_RANGE);
523 int diffAfter = Math.min(actual.length, diffPos + _PRINT_RANGE); 523 int diffAfter = Math.min(actual.length, diffPos + _PRINT_RANGE);
524 String diffStr = "${actual.substring(diffAhead, diffPos)}^${actual.substri ng(diffPos, diffAfter)}"; 524 String diffStr = "${actual.substring(diffAhead, diffPos)}^${actual.substri ng(diffPos, diffAfter)}";
525 // use detailed message 525 // use detailed message
526 String message = "Content not as expected: is\n${actual}\nDiffers at pos $ {diffPos}: ${diffStr}\nexpected:\n${expected}"; 526 String message = "Content not as expected: is\n${actual}\nDiffers at pos $ {diffPos}: ${diffStr}\nexpected:\n${expected}";
527 JUnitTestCase.assertEqualsMsg(message, expected, actual); 527 JUnitTestCase.assertEqualsMsg(message, expected, actual);
528 } 528 }
529 } 529 }
530 530
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 return node.getAncestor(predicate); 724 return node.getAncestor(predicate);
725 } 725 }
726 726
727 /** 727 /**
728 * Calculate the offset where the given strings differ. 728 * Calculate the offset where the given strings differ.
729 * 729 *
730 * @param str1 the first String to compare 730 * @param str1 the first String to compare
731 * @param str2 the second String to compare 731 * @param str2 the second String to compare
732 * @return the offset at which the strings differ (or <code>-1</code> if they do not) 732 * @return the offset at which the strings differ (or <code>-1</code> if they do not)
733 */ 733 */
734 static int getDiffPos(String str1, String str2) { 734 static int _getDiffPos(String str1, String str2) {
735 int len1 = Math.min(str1.length, str2.length); 735 int len1 = Math.min(str1.length, str2.length);
736 int diffPos = -1; 736 int diffPos = -1;
737 for (int i = 0; i < len1; i++) { 737 for (int i = 0; i < len1; i++) {
738 if (str1.codeUnitAt(i) != str2.codeUnitAt(i)) { 738 if (str1.codeUnitAt(i) != str2.codeUnitAt(i)) {
739 diffPos = i; 739 diffPos = i;
740 break; 740 break;
741 } 741 }
742 } 742 }
743 if (diffPos == -1 && str1.length != str2.length) { 743 if (diffPos == -1 && str1.length != str2.length) {
744 diffPos = len1; 744 diffPos = len1;
745 } 745 }
746 return diffPos; 746 return diffPos;
747 } 747 }
748 748
749 static void privateAssertContains(List<Object> array, List<bool> found, Object element) { 749 static void _privateAssertContains(List<Object> array, List<bool> found, Objec t element) {
750 if (element == null) { 750 if (element == null) {
751 for (int i = 0; i < array.length; i++) { 751 for (int i = 0; i < array.length; i++) {
752 if (!found[i]) { 752 if (!found[i]) {
753 if (array[i] == null) { 753 if (array[i] == null) {
754 found[i] = true; 754 found[i] = true;
755 return; 755 return;
756 } 756 }
757 } 757 }
758 } 758 }
759 JUnitTestCase.fail("Does not contain null"); 759 JUnitTestCase.fail("Does not contain null");
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 Source resolveRelative(Uri uri) { 852 Source resolveRelative(Uri uri) {
853 throw new UnsupportedOperationException(); 853 throw new UnsupportedOperationException();
854 } 854 }
855 UriKind get uriKind { 855 UriKind get uriKind {
856 throw new UnsupportedOperationException(); 856 throw new UnsupportedOperationException();
857 } 857 }
858 TimestampedData<String> get contents { 858 TimestampedData<String> get contents {
859 throw new UnsupportedOperationException(); 859 throw new UnsupportedOperationException();
860 } 860 }
861 } 861 }
862
863 /**
864 * Wrapper around [Function] which should be called with "target" and "arguments ".
865 */
866 class MethodTrampoline {
867 int parameterCount;
868 Function trampoline;
869 MethodTrampoline(this.parameterCount, this.trampoline);
870 Object invoke(target, List arguments) {
871 if (arguments.length != parameterCount) {
872 throw new IllegalArgumentException("${arguments.length} != $parameterCount ");
873 }
874 switch (parameterCount) {
875 case 0:
876 return trampoline(target);
877 case 1:
878 return trampoline(target, arguments[0]);
879 case 2:
880 return trampoline(target, arguments[0], arguments[1]);
881 case 3:
882 return trampoline(target, arguments[0], arguments[1], arguments[2]);
883 case 4:
884 return trampoline(target, arguments[0], arguments[1], arguments[2], argu ments[3]);
885 default:
886 throw new IllegalArgumentException("Not implemented for > 4 arguments");
887 }
888 }
889 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/scanner_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698