| OLD | NEW |
| 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/scanner.dart'; | 7 import 'package:analyzer_experimental/src/generated/scanner.dart'; |
| 8 import 'package:analyzer_experimental/src/services/formatter_impl.dart'; | 8 import 'package:analyzer_experimental/src/services/formatter_impl.dart'; |
| 9 import 'package:analyzer_experimental/src/services/writer.dart'; | 9 import 'package:analyzer_experimental/src/services/writer.dart'; |
| 10 | 10 |
| (...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 '}', | 760 '}', |
| 761 'for (final foo in bar.foos) {\n' | 761 'for (final foo in bar.foos) {\n' |
| 762 ' print(foo);\n' | 762 ' print(foo);\n' |
| 763 '}' | 763 '}' |
| 764 ); | 764 ); |
| 765 }); | 765 }); |
| 766 | 766 |
| 767 test('initialIndent', () { | 767 test('initialIndent', () { |
| 768 var formatter = new CodeFormatter( | 768 var formatter = new CodeFormatter( |
| 769 new FormatterOptions(initialIndentationLevel: 2)); | 769 new FormatterOptions(initialIndentationLevel: 2)); |
| 770 var formattedSource = formatter.format(CodeKind.STATEMENT, 'var x;'); | 770 var formattedSource = |
| 771 formatter.format(CodeKind.STATEMENT, 'var x;').source; |
| 771 expect(formattedSource, startsWith(' ')); | 772 expect(formattedSource, startsWith(' ')); |
| 772 }); | 773 }); |
| 773 | 774 |
| 774 }); | 775 }); |
| 775 | 776 |
| 776 | 777 |
| 777 /// Token streams | 778 /// Token streams |
| 778 group('token streams', () { | 779 group('token streams', () { |
| 779 | 780 |
| 780 test('string tokens', () { | 781 test('string tokens', () { |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 new StringToken(TokenType.CLOSE_PAREN, '}', offset); | 949 new StringToken(TokenType.CLOSE_PAREN, '}', offset); |
| 949 | 950 |
| 950 Token chain(List<Token> tokens) { | 951 Token chain(List<Token> tokens) { |
| 951 for (var i = 0; i < tokens.length - 1; ++i) { | 952 for (var i = 0; i < tokens.length - 1; ++i) { |
| 952 tokens[i].setNext(tokens[i + 1]); | 953 tokens[i].setNext(tokens[i + 1]); |
| 953 } | 954 } |
| 954 return tokens[0]; | 955 return tokens[0]; |
| 955 } | 956 } |
| 956 | 957 |
| 957 String formatCU(src, {options: const FormatterOptions()}) => | 958 String formatCU(src, {options: const FormatterOptions()}) => |
| 958 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src); | 959 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src).source; |
| 959 | 960 |
| 960 String formatStatement(src, {options: const FormatterOptions()}) => | 961 String formatStatement(src, {options: const FormatterOptions()}) => |
| 961 new CodeFormatter(options).format(CodeKind.STATEMENT, src); | 962 new CodeFormatter(options).format(CodeKind.STATEMENT, src).source; |
| 962 | 963 |
| 963 Token tokenize(String str) => new StringScanner(null, str, null).tokenize(); | 964 Token tokenize(String str) => new StringScanner(null, str, null).tokenize(); |
| 964 | 965 |
| 965 | 966 |
| 966 expectTokenizedEqual(String s1, String s2) => | 967 expectTokenizedEqual(String s1, String s2) => |
| 967 expectStreamsEqual(tokenize(s1), tokenize(s2)); | 968 expectStreamsEqual(tokenize(s1), tokenize(s2)); |
| 968 | 969 |
| 969 expectTokenizedNotEqual(String s1, String s2) => | 970 expectTokenizedNotEqual(String s1, String s2) => |
| 970 expect(()=> expectStreamsEqual(tokenize(s1), tokenize(s2)), | 971 expect(()=> expectStreamsEqual(tokenize(s1), tokenize(s2)), |
| 971 throwsA(new isInstanceOf<FormatterException>())); | 972 throwsA(new isInstanceOf<FormatterException>())); |
| 972 | 973 |
| 973 expectStreamsEqual(Token t1, Token t2) => | 974 expectStreamsEqual(Token t1, Token t2) => |
| 974 new TokenStreamComparator(null, t1, t2).verifyEquals(); | 975 new TokenStreamComparator(null, t1, t2).verifyEquals(); |
| 975 | 976 |
| 976 expectStreamsNotEqual(Token t1, Token t2) => | 977 expectStreamsNotEqual(Token t1, Token t2) => |
| 977 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(), | 978 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(), |
| 978 throwsA(new isInstanceOf<FormatterException>())); | 979 throwsA(new isInstanceOf<FormatterException>())); |
| 979 | 980 |
| 980 expectCUFormatsTo(src, expected) => expect(formatCU(src), equals(expected)); | 981 expectCUFormatsTo(src, expected) => expect(formatCU(src), equals(expected)); |
| 981 | 982 |
| 982 expectStmtFormatsTo(src, expected) => expect(formatStatement(src), | 983 expectStmtFormatsTo(src, expected) => expect(formatStatement(src), |
| 983 equals(expected)); | 984 equals(expected)); |
| OLD | NEW |