Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 import 'package:analysis_server/plugin/protocol/protocol.dart'; | |
| 6 import 'package:test/test.dart'; | |
| 7 import 'package:test_reflective_loader/test_reflective_loader.dart'; | |
| 8 | |
| 9 import '../integration_tests.dart'; | |
| 10 | |
| 11 main() { | |
| 12 defineReflectiveSuite(() { | |
| 13 defineReflectiveTests(FormatTest); | |
| 14 }); | |
| 15 } | |
| 16 | |
| 17 @reflectiveTest | |
| 18 class FormatTest extends AbstractAnalysisServerIntegrationTest { | |
| 19 String setup({bool withErrors: false}) { | |
|
Brian Wilkerson
2017/02/15 14:58:42
Perhaps a different name so that people will know
devoncarew
2017/02/15 15:22:51
Good point; renamed to 'formatTestSetup'.
| |
| 20 String pathname = sourcePath('test.dart'); | |
| 21 | |
| 22 if (withErrors) { | |
| 23 String text = r''' | |
| 24 class Class1 { | |
| 25 int field | |
| 26 void foo() { | |
| 27 } | |
| 28 } | |
| 29 '''; | |
| 30 writeFile(pathname, text); | |
| 31 } else { | |
| 32 String text = r''' | |
| 33 class Class1 { | |
| 34 int field; | |
| 35 | |
| 36 void foo() { | |
| 37 } | |
| 38 | |
| 39 void bar() { | |
| 40 } | |
| 41 } | |
| 42 '''; | |
| 43 writeFile(pathname, text); | |
| 44 } | |
| 45 standardAnalysisSetup(); | |
| 46 return pathname; | |
| 47 } | |
| 48 | |
| 49 test_format() async { | |
| 50 String pathname = setup(); | |
| 51 | |
| 52 EditFormatResult result = await sendEditFormat(pathname, 0, 0); | |
| 53 expect(result.edits, isNotEmpty); | |
| 54 expect(result.selectionOffset, 0); | |
| 55 expect(result.selectionLength, 0); | |
| 56 } | |
| 57 | |
| 58 test_format_preserve_selection() async { | |
| 59 String pathname = setup(); | |
| 60 | |
| 61 // format with 'bar' selected | |
| 62 int initialPosition = readFile(pathname).indexOf('bar()'); | |
|
Brian Wilkerson
2017/02/15 14:58:42
The test will run faster if you capture the initia
devoncarew
2017/02/15 15:22:51
I slightly prefer this as we only have to get one
Brian Wilkerson
2017/02/15 15:27:54
I was thinking about assigning the value to a fiel
| |
| 63 EditFormatResult result = | |
| 64 await sendEditFormat(pathname, initialPosition, 'bar'.length); | |
| 65 expect(result.edits, isNotEmpty); | |
| 66 expect(result.selectionOffset, initialPosition - 3); | |
| 67 expect(result.selectionLength, 'bar'.length); | |
| 68 } | |
| 69 | |
| 70 test_format_with_errors() async { | |
| 71 String pathname = setup(withErrors: true); | |
| 72 | |
| 73 try { | |
| 74 await sendEditFormat(pathname, 0, 0); | |
| 75 fail('expected FORMAT_WITH_ERRORS'); | |
| 76 } on ServerErrorMessage catch (message) { | |
| 77 expect(message.error['code'], 'FORMAT_WITH_ERRORS'); | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 @override | |
| 82 bool get enableNewAnalysisDriver => true; | |
| 83 } | |
| OLD | NEW |