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

Side by Side Diff: pkg/analyzer_experimental/test/services/formatter_test.dart

Issue 42863002: New analyzer_experimental snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 import 'package:unittest/unittest.dart'; 5 import 'package:unittest/unittest.dart';
6 6
7 import 'package:analyzer_experimental/src/generated/java_core.dart' show CharSeq uence;
7 import 'package:analyzer_experimental/src/generated/scanner.dart'; 8 import 'package:analyzer_experimental/src/generated/scanner.dart';
8 import 'package:analyzer_experimental/src/services/formatter_impl.dart'; 9 import 'package:analyzer_experimental/src/services/formatter_impl.dart';
9 import 'package:analyzer_experimental/src/services/writer.dart'; 10 import 'package:analyzer_experimental/src/services/writer.dart';
10 11
11 main() { 12 main() {
12 13
13 /// Formatter tests 14 /// Formatter tests
14 group('formatter', () { 15 group('formatter', () {
15 16
16 test('failed parse', () { 17 test('failed parse', () {
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 test('stmt (cascades)', () { 714 test('stmt (cascades)', () {
714 expectStmtFormatsTo( 715 expectStmtFormatsTo(
715 '"foo"\n' 716 '"foo"\n'
716 '..toString()\n' 717 '..toString()\n'
717 '..toString();', 718 '..toString();',
718 '"foo"\n' 719 '"foo"\n'
719 ' ..toString()\n' 720 ' ..toString()\n'
720 ' ..toString();' 721 ' ..toString();'
721 ); 722 );
722 }); 723 });
723 724
724 test('stmt (generics)', () { 725 test('stmt (generics)', () {
725 expectStmtFormatsTo( 726 expectStmtFormatsTo(
726 'var numbers = <int>[1, 2, (3 + 4)];', 727 'var numbers = <int>[1, 2, (3 + 4)];',
727 'var numbers = <int>[1, 2, (3 + 4)];' 728 'var numbers = <int>[1, 2, (3 + 4)];'
728 ); 729 );
729 }); 730 });
730 731
731 test('stmt (lists)', () { 732 test('stmt (lists)', () {
732 expectStmtFormatsTo( 733 expectStmtFormatsTo(
733 'var l = [1,2,3,4];', 734 'var l = [1,2,3,4];',
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 return tokens[0]; 1032 return tokens[0];
1032 } 1033 }
1033 1034
1034 FormattedSource formatCU(src, {options: const FormatterOptions(), selection}) => 1035 FormattedSource formatCU(src, {options: const FormatterOptions(), selection}) =>
1035 new CodeFormatter(options).format( 1036 new CodeFormatter(options).format(
1036 CodeKind.COMPILATION_UNIT, src, selection: selection); 1037 CodeKind.COMPILATION_UNIT, src, selection: selection);
1037 1038
1038 String formatStatement(src, {options: const FormatterOptions()}) => 1039 String formatStatement(src, {options: const FormatterOptions()}) =>
1039 new CodeFormatter(options).format(CodeKind.STATEMENT, src).source; 1040 new CodeFormatter(options).format(CodeKind.STATEMENT, src).source;
1040 1041
1041 Token tokenize(String str) => new StringScanner(null, str, null).tokenize(); 1042 Token tokenize(String str) {
1043 var reader = new CharSequenceReader(new CharSequence(str));
1044 return new Scanner(null, reader, null).tokenize();
1045 }
1042 1046
1043 expectSelectedPostFormat(src, token) { 1047 expectSelectedPostFormat(src, token) {
1044 var preOffset = src.indexOf(token); 1048 var preOffset = src.indexOf(token);
1045 var length = token.length; 1049 var length = token.length;
1046 var formatted = formatCU(src, selection: new Selection(preOffset, length)); 1050 var formatted = formatCU(src, selection: new Selection(preOffset, length));
1047 var postOffset = formatted.selection.offset; 1051 var postOffset = formatted.selection.offset;
1048 expect(formatted.source.substring(postOffset, postOffset + length), 1052 expect(formatted.source.substring(postOffset, postOffset + length),
1049 equals(src.substring(preOffset, preOffset + length))); 1053 equals(src.substring(preOffset, preOffset + length)));
1050 } 1054 }
1051 1055
(...skipping 11 matching lines...) Expand all
1063 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(), 1067 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(),
1064 throwsA(new isInstanceOf<FormatterException>())); 1068 throwsA(new isInstanceOf<FormatterException>()));
1065 1069
1066 expectCUFormatsTo(src, expected, {transforms: true}) => 1070 expectCUFormatsTo(src, expected, {transforms: true}) =>
1067 expect(formatCU(src, options: new FormatterOptions( 1071 expect(formatCU(src, options: new FormatterOptions(
1068 codeTransforms: transforms)).source, equals(expected)); 1072 codeTransforms: transforms)).source, equals(expected));
1069 1073
1070 expectStmtFormatsTo(src, expected, {transforms: true}) => 1074 expectStmtFormatsTo(src, expected, {transforms: true}) =>
1071 expect(formatStatement(src, options: 1075 expect(formatStatement(src, options:
1072 new FormatterOptions(codeTransforms: transforms)), equals(expected)); 1076 new FormatterOptions(codeTransforms: transforms)), equals(expected));
OLDNEW
« no previous file with comments | « pkg/analyzer_experimental/test/generated/scanner_test.dart ('k') | pkg/analyzer_experimental/test/services/test_utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698