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