| 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'; | 5 import 'dart:io'; |
| 6 | 6 |
| 7 import 'package:path/path.dart'; |
| 7 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
| 8 | 9 |
| 9 import 'package:analyzer/src/generated/java_core.dart' show CharSequence; | 10 import 'package:analyzer/src/generated/java_core.dart' show CharSequence; |
| 10 import 'package:analyzer/src/generated/scanner.dart'; | 11 import 'package:analyzer/src/generated/scanner.dart'; |
| 11 import 'package:analyzer/src/services/formatter_impl.dart'; | 12 import 'package:analyzer/src/services/formatter_impl.dart'; |
| 12 import 'package:analyzer/src/services/writer.dart'; | 13 import 'package:analyzer/src/services/writer.dart'; |
| 13 | 14 |
| 15 // Test data location ('pkg/analyzer/test/services/data') |
| 16 final TEST_DATA_DIR = join(dirname(fromUri(Platform.script)), 'data'); |
| 17 |
| 14 main() { | 18 main() { |
| 15 | 19 |
| 16 //TODO(pquitslund): disabled pending build investigation | 20 /// Data-driven statement tests |
| 21 group('stmt_tests.data', () { |
| 22 runTests('stmt_tests.data', (input, expectedOutput) { |
| 23 expect(formatStatement(input) + '\n', equals(expectedOutput)); |
| 24 }); |
| 25 }); |
| 17 | 26 |
| 18 // /// Data driven statement tests | 27 /// Data-driven compilation unit tests |
| 19 // group('stmt_tests.data', () { | 28 group('cu_tests.data', () { |
| 20 // runTests(new File('data/stmt_tests.data'), (input, expectedOutput) { | 29 runTests('cu_tests.data', (input, expectedOutput) { |
| 21 // expect(formatStatement(input) + '\n', equals(expectedOutput)); | 30 expectCUFormatsTo(input, expectedOutput); |
| 22 // }); | 31 }); |
| 23 // }); | 32 }); |
| 24 // | 33 |
| 25 // /// Data driven compilation unit tests | 34 /// Data-driven Style Guide acceptance tests |
| 26 // group('cu_tests.data', () { | 35 group('style_guide_tests.data', () { |
| 27 // runTests(new File('data/cu_tests.data'), (input, expectedOutput) { | 36 runTests('style_guide_tests.data', (input, expectedOutput) { |
| 28 // expectCUFormatsTo(input, expectedOutput); | 37 expectCUFormatsTo(input, expectedOutput); |
| 29 // }); | 38 }); |
| 30 // }); | 39 }); |
| 31 | 40 |
| 32 /// Formatter tests | 41 /// Formatter tests |
| 33 group('formatter', () { | 42 group('formatter', () { |
| 34 | 43 |
| 35 test('failed parse', () { | 44 test('failed parse', () { |
| 36 var formatter = new CodeFormatter(); | 45 var formatter = new CodeFormatter(); |
| 37 expect(() => formatter.format(CodeKind.COMPILATION_UNIT, '~'), | 46 expect(() => formatter.format(CodeKind.COMPILATION_UNIT, '~'), |
| 38 throwsA(new isInstanceOf<FormatterException>())); | 47 throwsA(new isInstanceOf<FormatterException>())); |
| 39 }); | 48 }); |
| 40 | 49 |
| (...skipping 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1301 throwsA(new isInstanceOf<FormatterException>())); | 1310 throwsA(new isInstanceOf<FormatterException>())); |
| 1302 | 1311 |
| 1303 expectCUFormatsTo(src, expected, {transforms: true}) => | 1312 expectCUFormatsTo(src, expected, {transforms: true}) => |
| 1304 expect(formatCU(src, options: new FormatterOptions( | 1313 expect(formatCU(src, options: new FormatterOptions( |
| 1305 codeTransforms: transforms)).source, equals(expected)); | 1314 codeTransforms: transforms)).source, equals(expected)); |
| 1306 | 1315 |
| 1307 expectStmtFormatsTo(src, expected, {transforms: true}) => | 1316 expectStmtFormatsTo(src, expected, {transforms: true}) => |
| 1308 expect(formatStatement(src, options: | 1317 expect(formatStatement(src, options: |
| 1309 new FormatterOptions(codeTransforms: transforms)), equals(expected)); | 1318 new FormatterOptions(codeTransforms: transforms)), equals(expected)); |
| 1310 | 1319 |
| 1311 runTests(testFile, expectClause(input, output)) { | 1320 |
| 1321 runTests(testFileName, expectClause(input, output)) { |
| 1312 | 1322 |
| 1313 var testIndex = 1; | 1323 var testIndex = 1; |
| 1324 var testFile = new File(join(TEST_DATA_DIR, testFileName)); |
| 1314 var lines = testFile.readAsLinesSync(); | 1325 var lines = testFile.readAsLinesSync(); |
| 1315 | 1326 |
| 1316 for (var i = 1; i < lines.length; ++i) { | 1327 for (var i = 1; i < lines.length; ++i) { |
| 1317 var input = '', expectedOutput = ''; | 1328 var input = '', expectedOutput = ''; |
| 1318 while(lines[i] != '<<<') { | 1329 while(!lines[i].startsWith('<<<')) { |
| 1319 input += lines[i++] + '\n'; | 1330 input += lines[i++] + '\n'; |
| 1320 } | 1331 } |
| 1321 while(++i < lines.length && lines[i] != '>>>') { | 1332 while(++i < lines.length && !lines[i].startsWith('>>>')) { |
| 1322 expectedOutput += lines[i] + '\n'; | 1333 expectedOutput += lines[i] + '\n'; |
| 1323 } | 1334 } |
| 1324 test('test - (${testIndex++})', () { | 1335 test('test - (${testIndex++})', () { |
| 1325 expectClause(input, expectedOutput); | 1336 expectClause(input, expectedOutput); |
| 1326 }); | 1337 }); |
| 1327 } | 1338 } |
| 1328 } | 1339 } |
| OLD | NEW |