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

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

Issue 649873007: Remove Math and most uses of PrintStringWriter (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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/resolver_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 'dart:collection'; 10 import 'dart:collection';
11 import "dart:math" as math;
11 12
12 import 'package:analyzer/src/generated/ast.dart' show AstNode, NodeLocator; 13 import 'package:analyzer/src/generated/ast.dart' show AstNode, NodeLocator;
13 import 'package:analyzer/src/generated/element.dart'; 14 import 'package:analyzer/src/generated/element.dart';
14 import 'package:analyzer/src/generated/engine.dart'; 15 import 'package:analyzer/src/generated/engine.dart';
15 import 'package:analyzer/src/generated/error.dart'; 16 import 'package:analyzer/src/generated/error.dart';
16 import 'package:analyzer/src/generated/java_core.dart'; 17 import 'package:analyzer/src/generated/java_core.dart';
17 import 'package:analyzer/src/generated/java_engine.dart'; 18 import 'package:analyzer/src/generated/java_engine.dart';
18 import 'package:analyzer/src/generated/java_junit.dart'; 19 import 'package:analyzer/src/generated/java_junit.dart';
19 import 'package:analyzer/src/generated/scanner.dart'; 20 import 'package:analyzer/src/generated/scanner.dart';
20 import 'package:analyzer/src/generated/source.dart'; 21 import 'package:analyzer/src/generated/source.dart';
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 "Content not as expected: is 'null' expected: ${expected}", 180 "Content not as expected: is 'null' expected: ${expected}",
180 false); 181 false);
181 } else { 182 } else {
182 JUnitTestCase.assertTrueMsg( 183 JUnitTestCase.assertTrueMsg(
183 "Content not as expected: expected 'null' is: ${actual}", 184 "Content not as expected: expected 'null' is: ${actual}",
184 false); 185 false);
185 } 186 }
186 } 187 }
187 int diffPos = _getDiffPos(expected, actual); 188 int diffPos = _getDiffPos(expected, actual);
188 if (diffPos != -1) { 189 if (diffPos != -1) {
189 int diffAhead = Math.max(0, diffPos - _PRINT_RANGE); 190 int diffAhead = math.max(0, diffPos - _PRINT_RANGE);
190 int diffAfter = Math.min(actual.length, diffPos + _PRINT_RANGE); 191 int diffAfter = math.min(actual.length, diffPos + _PRINT_RANGE);
191 String diffStr = 192 String diffStr =
192 "${actual.substring(diffAhead, diffPos)}^${actual.substring(diffPos, d iffAfter)}"; 193 "${actual.substring(diffAhead, diffPos)}^${actual.substring(diffPos, d iffAfter)}";
193 // use detailed message 194 // use detailed message
194 String message = 195 String message =
195 "Content not as expected: is\n${actual}\nDiffers at pos ${diffPos}: ${ diffStr}\nexpected:\n${expected}"; 196 "Content not as expected: is\n${actual}\nDiffers at pos ${diffPos}: ${ diffStr}\nexpected:\n${expected}";
196 JUnitTestCase.assertEqualsMsg(message, expected, actual); 197 JUnitTestCase.assertEqualsMsg(message, expected, actual);
197 } 198 }
198 } 199 }
199 200
200 /** 201 /**
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 } 418 }
418 } 419 }
419 420
420 /** 421 /**
421 * Convert the given array of lines into a single source string. 422 * Convert the given array of lines into a single source string.
422 * 423 *
423 * @param lines the lines to be merged into a single source string 424 * @param lines the lines to be merged into a single source string
424 * @return the source string composed of the given lines 425 * @return the source string composed of the given lines
425 */ 426 */
426 static String createSource(List<String> lines) { 427 static String createSource(List<String> lines) {
427 PrintStringWriter writer = new PrintStringWriter(); 428 StringBuffer buffer = new StringBuffer();
428 for (String line in lines) { 429 for (String line in lines) {
429 writer.println(line); 430 buffer.writeln(line);
430 } 431 }
431 return writer.toString(); 432 return buffer.toString();
432 } 433 }
433 434
434 /** 435 /**
435 * @return the [AstNode] with requested type at offset of the "prefix". 436 * @return the [AstNode] with requested type at offset of the "prefix".
436 */ 437 */
437 static AstNode findNode(AstNode root, String code, String prefix, 438 static AstNode findNode(AstNode root, String code, String prefix,
438 Predicate<AstNode> predicate) { 439 Predicate<AstNode> predicate) {
439 int offset = code.indexOf(prefix); 440 int offset = code.indexOf(prefix);
440 if (offset == -1) { 441 if (offset == -1) {
441 throw new IllegalArgumentException("Not found '${prefix}'."); 442 throw new IllegalArgumentException("Not found '${prefix}'.");
442 } 443 }
443 AstNode node = new NodeLocator.con1(offset).searchWithin(root); 444 AstNode node = new NodeLocator.con1(offset).searchWithin(root);
444 return node.getAncestor(predicate); 445 return node.getAncestor(predicate);
445 } 446 }
446 447
447 /** 448 /**
448 * Calculate the offset where the given strings differ. 449 * Calculate the offset where the given strings differ.
449 * 450 *
450 * @param str1 the first String to compare 451 * @param str1 the first String to compare
451 * @param str2 the second String to compare 452 * @param str2 the second String to compare
452 * @return the offset at which the strings differ (or <code>-1</code> if they do not) 453 * @return the offset at which the strings differ (or <code>-1</code> if they do not)
453 */ 454 */
454 static int _getDiffPos(String str1, String str2) { 455 static int _getDiffPos(String str1, String str2) {
455 int len1 = Math.min(str1.length, str2.length); 456 int len1 = math.min(str1.length, str2.length);
456 int diffPos = -1; 457 int diffPos = -1;
457 for (int i = 0; i < len1; i++) { 458 for (int i = 0; i < len1; i++) {
458 if (str1.codeUnitAt(i) != str2.codeUnitAt(i)) { 459 if (str1.codeUnitAt(i) != str2.codeUnitAt(i)) {
459 diffPos = i; 460 diffPos = i;
460 break; 461 break;
461 } 462 }
462 } 463 }
463 if (diffPos == -1 && str1.length != str2.length) { 464 if (diffPos == -1 && str1.length != str2.length) {
464 diffPos = len1; 465 diffPos = len1;
465 } 466 }
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 819
819 /** 820 /**
820 * Assert that the number of errors that have been gathered matches the number of errors that are 821 * Assert that the number of errors that have been gathered matches the number of errors that are
821 * given and that they have the expected error codes. The order in which the e rrors were gathered 822 * given and that they have the expected error codes. The order in which the e rrors were gathered
822 * is ignored. 823 * is ignored.
823 * 824 *
824 * @param errorCodes the errors that should have been gathered 825 * @param errorCodes the errors that should have been gathered
825 * @throws AssertionFailedError with 826 * @throws AssertionFailedError with
826 */ 827 */
827 void _fail(List<AnalysisError> expectedErrors) { 828 void _fail(List<AnalysisError> expectedErrors) {
828 PrintStringWriter writer = new PrintStringWriter(); 829 StringBuffer buffer = new StringBuffer();
829 writer.print("Expected "); 830 buffer.write("Expected ");
830 writer.print(expectedErrors.length); 831 buffer.write(expectedErrors.length);
831 writer.print(" errors:"); 832 buffer.write(" errors:");
832 for (AnalysisError error in expectedErrors) { 833 for (AnalysisError error in expectedErrors) {
833 Source source = error.source; 834 Source source = error.source;
834 LineInfo lineInfo = _lineInfoMap[source]; 835 LineInfo lineInfo = _lineInfoMap[source];
835 writer.newLine(); 836 buffer.writeln();
836 if (lineInfo == null) { 837 if (lineInfo == null) {
837 int offset = error.offset; 838 int offset = error.offset;
838 writer.printf( 839 StringUtils.printf(
840 buffer,
839 " %s %s (%d..%d)", 841 " %s %s (%d..%d)",
840 [ 842 [
841 source == null ? "" : source.shortName, 843 source == null ? "" : source.shortName,
842 error.errorCode, 844 error.errorCode,
843 offset, 845 offset,
844 offset + error.length]); 846 offset + error.length]);
845 } else { 847 } else {
846 LineInfo_Location location = lineInfo.getLocation(error.offset); 848 LineInfo_Location location = lineInfo.getLocation(error.offset);
847 writer.printf( 849 StringUtils.printf(
850 buffer,
848 " %s %s (%d, %d/%d)", 851 " %s %s (%d, %d/%d)",
849 [ 852 [
850 source == null ? "" : source.shortName, 853 source == null ? "" : source.shortName,
851 error.errorCode, 854 error.errorCode,
852 location.lineNumber, 855 location.lineNumber,
853 location.columnNumber, 856 location.columnNumber,
854 error.length]); 857 error.length]);
855 } 858 }
856 } 859 }
857 writer.newLine(); 860 buffer.writeln();
858 writer.print("found "); 861 buffer.write("found ");
859 writer.print(_errors.length); 862 buffer.write(_errors.length);
860 writer.print(" errors:"); 863 buffer.write(" errors:");
861 for (AnalysisError error in _errors) { 864 for (AnalysisError error in _errors) {
862 Source source = error.source; 865 Source source = error.source;
863 LineInfo lineInfo = _lineInfoMap[source]; 866 LineInfo lineInfo = _lineInfoMap[source];
864 writer.newLine(); 867 buffer.writeln();
865 if (lineInfo == null) { 868 if (lineInfo == null) {
866 int offset = error.offset; 869 int offset = error.offset;
867 writer.printf( 870 StringUtils.printf(
871 buffer,
868 " %s %s (%d..%d): %s", 872 " %s %s (%d..%d): %s",
869 [ 873 [
870 source == null ? "" : source.shortName, 874 source == null ? "" : source.shortName,
871 error.errorCode, 875 error.errorCode,
872 offset, 876 offset,
873 offset + error.length, 877 offset + error.length,
874 error.message]); 878 error.message]);
875 } else { 879 } else {
876 LineInfo_Location location = lineInfo.getLocation(error.offset); 880 LineInfo_Location location = lineInfo.getLocation(error.offset);
877 writer.printf( 881 StringUtils.printf(
882 buffer,
878 " %s %s (%d, %d/%d): %s", 883 " %s %s (%d, %d/%d): %s",
879 [ 884 [
880 source == null ? "" : source.shortName, 885 source == null ? "" : source.shortName,
881 error.errorCode, 886 error.errorCode,
882 location.lineNumber, 887 location.lineNumber,
883 location.columnNumber, 888 location.columnNumber,
884 error.length, 889 error.length,
885 error.message]); 890 error.message]);
886 } 891 }
887 } 892 }
888 JUnitTestCase.fail(writer.toString()); 893 JUnitTestCase.fail(buffer.toString());
889 } 894 }
890 895
891 /** 896 /**
892 * Search through the given list of errors for an error that is equal to the t arget error. If one 897 * Search through the given list of errors for an error that is equal to the t arget error. If one
893 * is found, remove it from the list and return `true`, otherwise return `fals e` 898 * is found, remove it from the list and return `true`, otherwise return `fals e`
894 * without modifying the list. 899 * without modifying the list.
895 * 900 *
896 * @param errors the errors through which we are searching 901 * @param errors the errors through which we are searching
897 * @param targetError the error being searched for 902 * @param targetError the error being searched for
898 * @return `true` if the error is found and removed from the list 903 * @return `true` if the error is found and removed from the list
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 void getContentsToReceiver(Source_ContentReceiver receiver) { 1010 void getContentsToReceiver(Source_ContentReceiver receiver) {
1006 throw new UnsupportedOperationException(); 1011 throw new UnsupportedOperationException();
1007 } 1012 }
1008 Source resolve(String uri) { 1013 Source resolve(String uri) {
1009 throw new UnsupportedOperationException(); 1014 throw new UnsupportedOperationException();
1010 } 1015 }
1011 Uri resolveRelativeUri(Uri uri) { 1016 Uri resolveRelativeUri(Uri uri) {
1012 return new Uri(scheme: 'file', path: _name).resolveUri(uri); 1017 return new Uri(scheme: 'file', path: _name).resolveUri(uri);
1013 } 1018 }
1014 } 1019 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/resolver_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698