OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, 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 library test.integration.analysis.update.content; |
| 6 |
| 7 import 'package:analysis_testing/reflective_tests.dart'; |
| 8 import 'package:unittest/unittest.dart'; |
| 9 |
| 10 import '../integration_tests.dart'; |
| 11 |
| 12 @ReflectiveTestCase() |
| 13 class Test extends AbstractAnalysisServerIntegrationTest { |
| 14 test_updateContent() { |
| 15 String pathname = sourcePath('test.dart'); |
| 16 String goodText = r''' |
| 17 main() { |
| 18 print("Hello, world!"); |
| 19 }'''; |
| 20 String badText = goodText.replaceAll(';', ''); |
| 21 writeFile(pathname, badText); |
| 22 standardAnalysisSetup(); |
| 23 return analysisFinished.then((_) { |
| 24 // The contents on disk (badText) are missing a semicolon. |
| 25 expect(currentAnalysisErrors[pathname], isNot(isEmpty)); |
| 26 }).then((_) => sendAnalysisUpdateContent({ |
| 27 pathname: { |
| 28 'type': 'add', |
| 29 'content': goodText |
| 30 } |
| 31 })).then((result) => analysisFinished).then((_) { |
| 32 // There should be no errors now because the contents on disk have been |
| 33 // overriden with goodText. |
| 34 expect(currentAnalysisErrors[pathname], isEmpty); |
| 35 return sendAnalysisUpdateContent({ |
| 36 pathname: { |
| 37 'type': 'change', |
| 38 'offset': goodText.indexOf(';'), |
| 39 'length': 1, |
| 40 'replacement': '' |
| 41 } |
| 42 }); |
| 43 }).then((result) => analysisFinished).then((_) { |
| 44 // There should be errors now because we've removed the semicolon. |
| 45 expect(currentAnalysisErrors[pathname], isNot(isEmpty)); |
| 46 return sendAnalysisUpdateContent({ |
| 47 pathname: { |
| 48 'type': 'change', |
| 49 'offset': goodText.indexOf(';'), |
| 50 'length': 0, |
| 51 'replacement': ';' |
| 52 } |
| 53 }); |
| 54 }).then((result) => analysisFinished).then((_) { |
| 55 // There should be no errors now because we've added the semicolon back. |
| 56 expect(currentAnalysisErrors[pathname], isEmpty); |
| 57 return sendAnalysisUpdateContent({ |
| 58 pathname: { |
| 59 'type': 'remove' |
| 60 } |
| 61 }); |
| 62 }).then((result) => analysisFinished).then((_) { |
| 63 // Now there should be errors again, because the contents on disk are no |
| 64 // longer overridden. |
| 65 expect(currentAnalysisErrors[pathname], isNot(isEmpty)); |
| 66 }); |
| 67 } |
| 68 } |
| 69 |
| 70 main() { |
| 71 runReflectiveTests(Test); |
| 72 } |
OLD | NEW |