Chromium Code Reviews| 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 library formatter_test; | 5 library formatter_test; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:path/path.dart'; | 9 import 'package:path/path.dart'; |
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| (...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 993 'if (true) {\n' | 993 'if (true) {\n' |
| 994 ' print("true!");\n' | 994 ' print("true!");\n' |
| 995 '} else {\n' | 995 '} else {\n' |
| 996 ' print("false!");\n' | 996 ' print("false!");\n' |
| 997 '}'); | 997 '}'); |
| 998 expectStmtFormatsTo('if (true) print("true!"); else print("false!");', | 998 expectStmtFormatsTo('if (true) print("true!"); else print("false!");', |
| 999 'if (true) print("true!"); else print("false!");', | 999 'if (true) print("true!"); else print("false!");', |
| 1000 transforms: false); | 1000 transforms: false); |
| 1001 }); | 1001 }); |
| 1002 | 1002 |
| 1003 test('String - multiline - short - same line', () { | |
| 1004 expectCUFormatsTo( | |
| 1005 'main() {\n' | |
| 1006 ' print("""01234567890123456789012345678901234567890123456789""");\n' | |
| 1007 '}\n', | |
| 1008 'main() {\n' | |
| 1009 ' print("""01234567890123456789012345678901234567890123456789""");\n' | |
| 1010 '}\n' | |
| 1011 ); | |
| 1012 }); | |
| 1013 | |
| 1014 test('String - multiline - short - next line', () { | |
| 1015 expectCUFormatsTo( | |
| 1016 'main() {\n' | |
| 1017 ' print("""\n' | |
| 1018 '01234567890123456789012345678901234567890123456789\n' | |
| 1019 '""");\n' | |
| 1020 '}\n', | |
| 1021 'main() {\n' | |
| 1022 ' print("""\n' | |
|
Brian Wilkerson
2014/06/06 17:23:54
indentation?
scheglov
2014/06/06 17:25:37
Done.
| |
| 1023 '01234567890123456789012345678901234567890123456789\n' | |
| 1024 '""");\n' | |
| 1025 '}\n' | |
| 1026 ); | |
| 1027 }); | |
| 1028 | |
| 1029 test('String - multiline - long', () { | |
| 1030 expectCUFormatsTo( | |
| 1031 'main() {\n' | |
| 1032 ' print("""\n' | |
| 1033 '01234567890123456789012345678901234567890123456789\n' | |
| 1034 '01234567890123456789012345678901234567890123456789\n' | |
| 1035 '01234567890123456789012345678901234567890123456789\n' | |
| 1036 '""");\n' | |
| 1037 '}\n', | |
| 1038 'main() {\n' | |
| 1039 ' print("""\n' | |
| 1040 '01234567890123456789012345678901234567890123456789\n' | |
| 1041 '01234567890123456789012345678901234567890123456789\n' | |
| 1042 '01234567890123456789012345678901234567890123456789\n' | |
| 1043 '""");\n' | |
| 1044 '}\n' | |
| 1045 ); | |
| 1046 }); | |
| 1047 | |
| 1003 // smoketest to ensure we're enforcing the 'no gratuitous linebreaks' | 1048 // smoketest to ensure we're enforcing the 'no gratuitous linebreaks' |
| 1004 // opinion | 1049 // opinion |
| 1005 test('CU (eat newlines)', () { | 1050 test('CU (eat newlines)', () { |
| 1006 expectCUFormatsTo( | 1051 expectCUFormatsTo( |
| 1007 'abstract\n' | 1052 'abstract\n' |
| 1008 'class\n' | 1053 'class\n' |
| 1009 'A{}', | 1054 'A{}', |
| 1010 'abstract class A {}\n' | 1055 'abstract class A {}\n' |
| 1011 ); | 1056 ); |
| 1012 }); | 1057 }); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1259 writer.write('foo'); | 1304 writer.write('foo'); |
| 1260 writer.indent(); | 1305 writer.indent(); |
| 1261 writer.newline(); | 1306 writer.newline(); |
| 1262 writer.write('bar'); | 1307 writer.write('bar'); |
| 1263 writer.unindent(); | 1308 writer.unindent(); |
| 1264 writer.newline(); | 1309 writer.newline(); |
| 1265 writer.write('baz'); | 1310 writer.write('baz'); |
| 1266 expect(writer.toString(), equals('foo\n bar\nbaz')); | 1311 expect(writer.toString(), equals('foo\n bar\nbaz')); |
| 1267 }); | 1312 }); |
| 1268 | 1313 |
| 1314 test('write - multiline', () { | |
| 1315 var writer = new SourceWriter(); | |
| 1316 writer.indent(); | |
| 1317 writer.newline(); | |
| 1318 writer.write('aaa\nbbb\nccc'); | |
| 1319 expect(writer.toString(), equals('\n aaa\nbbb\nccc')); | |
| 1320 expect(writer.currentLine.toString(), equals('ccc')); | |
| 1321 }); | |
| 1322 | |
| 1269 }); | 1323 }); |
| 1270 | 1324 |
| 1271 | 1325 |
| 1272 | 1326 |
| 1273 /// Line breaker tests | 1327 /// Line breaker tests |
| 1274 group('linebreaker', () { | 1328 group('linebreaker', () { |
| 1275 | 1329 |
| 1276 List<Chunk> breakLine(Line line, int maxLength) => | 1330 List<Chunk> breakLine(Line line, int maxLength) => |
| 1277 new SimpleLineBreaker(maxLength).breakLine(line); | 1331 new SimpleLineBreaker(maxLength).breakLine(line); |
| 1278 | 1332 |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1508 input += lines[i++] + '\n'; | 1562 input += lines[i++] + '\n'; |
| 1509 } | 1563 } |
| 1510 while(++i < lines.length && !lines[i].startsWith('>>>')) { | 1564 while(++i < lines.length && !lines[i].startsWith('>>>')) { |
| 1511 expectedOutput += lines[i] + '\n'; | 1565 expectedOutput += lines[i] + '\n'; |
| 1512 } | 1566 } |
| 1513 test('test - (${testIndex++})', () { | 1567 test('test - (${testIndex++})', () { |
| 1514 expectClause(input, expectedOutput); | 1568 expectClause(input, expectedOutput); |
| 1515 }); | 1569 }); |
| 1516 } | 1570 } |
| 1517 } | 1571 } |
| OLD | NEW |