| 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 'dart:io'; |
| 6 |
| 5 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
| 6 | 8 |
| 7 import 'package:analyzer/src/generated/java_core.dart' show CharSequence; | 9 import 'package:analyzer/src/generated/java_core.dart' show CharSequence; |
| 8 import 'package:analyzer/src/generated/scanner.dart'; | 10 import 'package:analyzer/src/generated/scanner.dart'; |
| 9 import 'package:analyzer/src/services/formatter_impl.dart'; | 11 import 'package:analyzer/src/services/formatter_impl.dart'; |
| 10 import 'package:analyzer/src/services/writer.dart'; | 12 import 'package:analyzer/src/services/writer.dart'; |
| 11 | 13 |
| 12 main() { | 14 main() { |
| 13 | 15 |
| 16 /// Data driven statement tests |
| 17 group('stmt_tests.data', () { |
| 18 runTests(new File('data/stmt_tests.data'), (input, expectedOutput) { |
| 19 expect(formatStatement(input) + '\n', equals(expectedOutput)); |
| 20 }); |
| 21 }); |
| 22 |
| 23 /// Data driven compilation unit tests |
| 24 group('cu_tests.data', () { |
| 25 runTests(new File('data/cu_tests.data'), (input, expectedOutput) { |
| 26 expectCUFormatsTo(input, expectedOutput); |
| 27 }); |
| 28 }); |
| 29 |
| 14 /// Formatter tests | 30 /// Formatter tests |
| 15 group('formatter', () { | 31 group('formatter', () { |
| 16 | 32 |
| 17 test('failed parse', () { | 33 test('failed parse', () { |
| 18 var formatter = new CodeFormatter(); | 34 var formatter = new CodeFormatter(); |
| 19 expect(() => formatter.format(CodeKind.COMPILATION_UNIT, '~'), | 35 expect(() => formatter.format(CodeKind.COMPILATION_UNIT, '~'), |
| 20 throwsA(new isInstanceOf<FormatterException>())); | 36 throwsA(new isInstanceOf<FormatterException>())); |
| 21 }); | 37 }); |
| 22 | 38 |
| 23 test('CU (1)', () { | 39 test('CU (1)', () { |
| (...skipping 1258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(), | 1298 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(), |
| 1283 throwsA(new isInstanceOf<FormatterException>())); | 1299 throwsA(new isInstanceOf<FormatterException>())); |
| 1284 | 1300 |
| 1285 expectCUFormatsTo(src, expected, {transforms: true}) => | 1301 expectCUFormatsTo(src, expected, {transforms: true}) => |
| 1286 expect(formatCU(src, options: new FormatterOptions( | 1302 expect(formatCU(src, options: new FormatterOptions( |
| 1287 codeTransforms: transforms)).source, equals(expected)); | 1303 codeTransforms: transforms)).source, equals(expected)); |
| 1288 | 1304 |
| 1289 expectStmtFormatsTo(src, expected, {transforms: true}) => | 1305 expectStmtFormatsTo(src, expected, {transforms: true}) => |
| 1290 expect(formatStatement(src, options: | 1306 expect(formatStatement(src, options: |
| 1291 new FormatterOptions(codeTransforms: transforms)), equals(expected)); | 1307 new FormatterOptions(codeTransforms: transforms)), equals(expected)); |
| 1308 |
| 1309 runTests(testFile, expectClause(input, output)) { |
| 1310 |
| 1311 var testIndex = 1; |
| 1312 var lines = testFile.readAsLinesSync(); |
| 1313 |
| 1314 for (var i = 1; i < lines.length; ++i) { |
| 1315 var input = '', expectedOutput = ''; |
| 1316 while(lines[i] != '<<<') { |
| 1317 input += lines[i++] + '\n'; |
| 1318 } |
| 1319 while(++i < lines.length && lines[i] != '>>>') { |
| 1320 expectedOutput += lines[i] + '\n'; |
| 1321 } |
| 1322 test('test - (${testIndex++})', () { |
| 1323 expectClause(input, expectedOutput); |
| 1324 }); |
| 1325 } |
| 1326 } |
| OLD | NEW |