Chromium Code Reviews| 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.domain.analysis; | 5 library test.domain.analysis; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/computer/computer_highlights.dart'; | 9 import 'package:analysis_server/src/computer/computer_highlights.dart'; |
| 10 import 'package:analysis_server/src/analysis_server.dart'; | 10 import 'package:analysis_server/src/analysis_server.dart'; |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 expect(response, isResponseSuccess('0')); | 344 expect(response, isResponseSuccess('0')); |
| 345 } | 345 } |
| 346 | 346 |
| 347 /** | 347 /** |
| 348 * Stops the associated server. | 348 * Stops the associated server. |
| 349 */ | 349 */ |
| 350 void stopServer() { | 350 void stopServer() { |
| 351 server.done(); | 351 server.done(); |
| 352 } | 352 } |
| 353 | 353 |
| 354 /** | |
| 355 * Send an updateContent request for testFile. | |
|
scheglov
2014/06/13 16:55:54
Would be good to wrap constants with ``.
Send an
Paul Berry
2014/06/13 20:23:00
Done.
| |
| 356 */ | |
| 357 void sendContentChange(Map contentChange) { | |
| 358 Request request = new Request('0', METHOD_UPDATE_CONTENT); | |
| 359 request.setParameter('files', { | |
| 360 testFile: contentChange | |
| 361 }); | |
| 362 handleSuccessfulRequest(request); | |
| 363 } | |
| 364 | |
| 354 static String _getCodeString(code) { | 365 static String _getCodeString(code) { |
| 355 if (code is List<String>) { | 366 if (code is List<String>) { |
| 356 code = code.join('\n'); | 367 code = code.join('\n'); |
| 357 } | 368 } |
| 358 return code as String; | 369 return code as String; |
| 359 } | 370 } |
| 360 } | 371 } |
| 361 | 372 |
| 362 | 373 |
| 363 testNotificationErrors() { | 374 testNotificationErrors() { |
| (...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1553 | 1564 |
| 1554 testUpdateContent() { | 1565 testUpdateContent() { |
| 1555 test('full content', () { | 1566 test('full content', () { |
| 1556 AnalysisTestHelper helper = new AnalysisTestHelper(); | 1567 AnalysisTestHelper helper = new AnalysisTestHelper(); |
| 1557 helper.createSingleFileProject('// empty'); | 1568 helper.createSingleFileProject('// empty'); |
| 1558 return helper.waitForOperationsFinished().then((_) { | 1569 return helper.waitForOperationsFinished().then((_) { |
| 1559 // no errors initially | 1570 // no errors initially |
| 1560 List<AnalysisError> errors = helper.getTestErrors(); | 1571 List<AnalysisError> errors = helper.getTestErrors(); |
| 1561 expect(errors, isEmpty); | 1572 expect(errors, isEmpty); |
| 1562 // update code | 1573 // update code |
| 1563 { | 1574 helper.sendContentChange({ |
| 1564 Request request = new Request('0', METHOD_UPDATE_CONTENT); | 1575 CONTENT: 'library lib' |
| 1565 request.setParameter('files', | 1576 }); |
| 1566 { | |
| 1567 helper.testFile : { | |
| 1568 CONTENT : 'library lib' | |
| 1569 } | |
| 1570 }); | |
| 1571 helper.handleSuccessfulRequest(request); | |
| 1572 } | |
| 1573 // wait, there is an error | 1577 // wait, there is an error |
| 1574 return helper.waitForOperationsFinished().then((_) { | 1578 return helper.waitForOperationsFinished().then((_) { |
| 1575 List<AnalysisError> errors = helper.getTestErrors(); | 1579 List<AnalysisError> errors = helper.getTestErrors(); |
| 1576 expect(errors, hasLength(1)); | 1580 expect(errors, hasLength(1)); |
| 1577 }); | 1581 }); |
| 1578 }); | 1582 }); |
| 1579 }); | 1583 }); |
| 1580 | 1584 |
| 1581 test('incremental', () { | 1585 test('incremental', () { |
| 1582 AnalysisTestHelper helper = new AnalysisTestHelper(); | 1586 AnalysisTestHelper helper = new AnalysisTestHelper(); |
| 1583 helper.createSingleFileProject('library A;'); | 1587 helper.createSingleFileProject('library A;'); |
| 1584 return helper.waitForOperationsFinished().then((_) { | 1588 return helper.waitForOperationsFinished().then((_) { |
| 1585 // no errors initially | 1589 // no errors initially |
| 1586 List<AnalysisError> errors = helper.getTestErrors(); | 1590 List<AnalysisError> errors = helper.getTestErrors(); |
| 1587 expect(errors, isEmpty); | 1591 expect(errors, isEmpty); |
| 1588 // update code | 1592 // update code |
| 1589 { | 1593 helper.sendContentChange({ |
| 1590 Request request = new Request('0', METHOD_UPDATE_CONTENT); | 1594 CONTENT: 'library lib', |
| 1591 request.setParameter('files', | 1595 OFFSET: 'library '.length, |
| 1592 { | 1596 OLD_LENGTH: 'A;'.length, |
| 1593 helper.testFile : { | 1597 NEW_LENGTH: 'lib'.length, |
| 1594 CONTENT : 'library lib', | 1598 }); |
| 1595 OFFSET : 'library '.length, | |
| 1596 OLD_LENGTH : 'A;'.length, | |
| 1597 NEW_LENGTH : 'lib'.length, | |
| 1598 } | |
| 1599 }); | |
| 1600 helper.handleSuccessfulRequest(request); | |
| 1601 } | |
| 1602 // wait, there is an error | 1599 // wait, there is an error |
| 1603 return helper.waitForOperationsFinished().then((_) { | 1600 return helper.waitForOperationsFinished().then((_) { |
| 1604 List<AnalysisError> errors = helper.getTestErrors(); | 1601 List<AnalysisError> errors = helper.getTestErrors(); |
| 1605 expect(errors, hasLength(1)); | 1602 expect(errors, hasLength(1)); |
| 1606 }); | 1603 }); |
| 1607 }); | 1604 }); |
| 1608 }); | 1605 }); |
| 1606 | |
| 1607 test('change on disk', () { | |
| 1608 AnalysisTestHelper helper = new AnalysisTestHelper(); | |
| 1609 helper.createSingleFileProject('library A;'); | |
| 1610 return helper.waitForOperationsFinished().then((_) { | |
| 1611 // update code | |
| 1612 helper.sendContentChange({ | |
| 1613 CONTENT: 'library B;' | |
| 1614 }); | |
| 1615 // There should be no errors | |
| 1616 return helper.waitForOperationsFinished().then((_) { | |
| 1617 expect(helper.getTestErrors(), hasLength(0)); | |
| 1618 // Change file on disk, adding a syntax error. | |
| 1619 helper.resourceProvider.modifyFile(helper.testFile, 'library lib'); | |
| 1620 // There should still be no errors (file should not have been reread). | |
| 1621 return helper.waitForOperationsFinished().then((_) { | |
| 1622 expect(helper.getTestErrors(), hasLength(0)); | |
| 1623 // Send a content change with a null content param--file should be | |
| 1624 // reread from disk. | |
| 1625 helper.sendContentChange({ | |
| 1626 CONTENT: null | |
| 1627 }); | |
| 1628 // There should be errors now. | |
| 1629 return helper.waitForOperationsFinished().then((_) { | |
| 1630 expect(helper.getTestErrors(), hasLength(1)); | |
| 1631 }); | |
| 1632 }); | |
| 1633 }); | |
| 1634 }); | |
| 1635 }); | |
| 1609 } | 1636 } |
| 1610 | 1637 |
| 1611 | |
| 1612 void test_setSubscriptions() { | 1638 void test_setSubscriptions() { |
| 1613 test('before analysis', () { | 1639 test('before analysis', () { |
| 1614 AnalysisTestHelper helper = new AnalysisTestHelper(); | 1640 AnalysisTestHelper helper = new AnalysisTestHelper(); |
| 1615 // subscribe | 1641 // subscribe |
| 1616 helper.addAnalysisSubscriptionHighlights(helper.testFile); | 1642 helper.addAnalysisSubscriptionHighlights(helper.testFile); |
| 1617 // create project | 1643 // create project |
| 1618 helper.createSingleFileProject('int V = 42;'); | 1644 helper.createSingleFileProject('int V = 42;'); |
| 1619 // wait, there are highlight regions | 1645 // wait, there are highlight regions |
| 1620 helper.waitForOperationsFinished().then((_) { | 1646 helper.waitForOperationsFinished().then((_) { |
| 1621 var highlights = helper.getHighlights(helper.testFile); | 1647 var highlights = helper.getHighlights(helper.testFile); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1634 // subscribe | 1660 // subscribe |
| 1635 helper.addAnalysisSubscriptionHighlights(helper.testFile); | 1661 helper.addAnalysisSubscriptionHighlights(helper.testFile); |
| 1636 // wait, has regions | 1662 // wait, has regions |
| 1637 return helper.waitForOperationsFinished().then((_) { | 1663 return helper.waitForOperationsFinished().then((_) { |
| 1638 var highlights = helper.getHighlights(helper.testFile); | 1664 var highlights = helper.getHighlights(helper.testFile); |
| 1639 expect(highlights, isNot(isEmpty)); | 1665 expect(highlights, isNot(isEmpty)); |
| 1640 }); | 1666 }); |
| 1641 }); | 1667 }); |
| 1642 }); | 1668 }); |
| 1643 } | 1669 } |
| OLD | NEW |