Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: pkg/analysis_server/test/services/completion/completion_test_util.dart

Issue 904653004: fix code completion in conditional expressions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.services.completion.util; 5 library test.services.completion.util;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element,
10 ElementKind; 10 ElementKind;
(...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 addTestSource(''' 1525 addTestSource('''
1526 import "/testAB.dart" show ^; 1526 import "/testAB.dart" show ^;
1527 import "/testCD.dart"; 1527 import "/testCD.dart";
1528 class X {}'''); 1528 class X {}''');
1529 computeFast(); 1529 computeFast();
1530 return computeFull((bool result) { 1530 return computeFull((bool result) {
1531 assertNoSuggestions(); 1531 assertNoSuggestions();
1532 }); 1532 });
1533 } 1533 }
1534 1534
1535 test_ConditionalExpression_empty() { 1535 test_ConditionalExpression_partial_thenExpression() {
1536 // SimpleIdentifier PrefixIdentifier IfStatement 1536 // SimpleIdentifier ConditionalExpression ReturnStatement
1537 addSource('/testA.dart', '''
1538 int T1;
1539 F1() { }
1540 class A {int x;}''');
1537 addTestSource(''' 1541 addTestSource('''
1538 class A {var b; X _c; foo() {A a; if (^) something}}'''); 1542 import "/testA.dart";
1543 int T2;
1544 F2() { }
1545 class B {int x;}
1546 class C {foo(){var f; {var x;} return a ? T^}}''');
1539 computeFast(); 1547 computeFast();
1540 return computeFull((bool result) { 1548 return computeFull((bool result) {
1541 expect(request.replacementOffset, completionOffset); 1549 // top level results are partially filtered based on first char
1542 expect(request.replacementLength, 0); 1550 assertSuggestLocalTopLevelVar('T2', 'int');
1543 assertSuggestLocalField('b', null); 1551 // TODO (danrubel) getter is being suggested instead of top level var
1544 assertSuggestLocalField('_c', 'X'); 1552 //assertSuggestImportedTopLevelVar('T1', 'int');
1545 assertSuggestImportedClass('Object');
1546 assertSuggestLocalClass('A');
1547 assertNotSuggested('==');
1548 }); 1553 });
1549 } 1554 }
1550 1555
1551 test_ConditionalExpression_invocation() { 1556 test_ConditionalExpression_partial_thenExpression_empty() {
1552 // SimpleIdentifier PrefixIdentifier IfStatement 1557 // SimpleIdentifier ConditionalExpression ReturnStatement
1558 addSource('/testA.dart', '''
1559 int T1;
1560 F1() { }
1561 class A {int x;}''');
1553 addTestSource(''' 1562 addTestSource('''
1554 main() {var a; if (a.^) something}'''); 1563 import "/testA.dart";
1564 int T2;
1565 F2() { }
1566 class B {int x;}
1567 class C {foo(){var f; {var x;} return a ? ^}}''');
1555 computeFast(); 1568 computeFast();
1556 return computeFull((bool result) { 1569 return computeFull((bool result) {
1557 expect(request.replacementOffset, completionOffset); 1570 assertNotSuggested('x');
1558 expect(request.replacementLength, 0); 1571 assertSuggestLocalVariable('f', null);
1559 assertSuggestInvocationMethod('toString', 'Object', 'String'); 1572 assertSuggestLocalMethod('foo', 'C', null);
1560 //TODO (danrubel) type for '_c' should be 'X' not null 1573 assertSuggestLocalClass('C');
1561 assertNotSuggested('Object'); 1574 assertSuggestLocalFunction('F2', null);
1562 assertNotSuggested('A'); 1575 assertSuggestLocalTopLevelVar('T2', 'int');
1563 assertNotSuggested('=='); 1576 assertSuggestImportedClass('A');
1577 assertSuggestImportedFunction('F1', null);
1578 // TODO (danrubel) getter is being suggested instead of top level var
1579 //assertSuggestImportedTopLevelVar('T1', 'int');
1564 }); 1580 });
1565 } 1581 }
1566 1582
1583 test_ConditionalExpression_elseExpression() {
1584 // SimpleIdentifier ConditionalExpression ReturnStatement
1585 addSource('/testA.dart', '''
1586 int T1;
1587 F1() { }
1588 class A {int x;}''');
1589 addTestSource('''
1590 import "/testA.dart";
1591 int T2;
1592 F2() { }
1593 class B {int x;}
1594 class C {foo(){var f; {var x;} return a ? T1 : T^}}''');
1595 computeFast();
1596 return computeFull((bool result) {
1597 // top level results are partially filtered based on first char
1598 assertSuggestLocalTopLevelVar('T2', 'int');
1599 // TODO (danrubel) getter is being suggested instead of top level var
1600 //assertSuggestImportedTopLevelVar('T1', 'int');
1601 });
1602 }
1603
1604 test_ConditionalExpression_elseExpression_empty() {
1605 // SimpleIdentifier ConditionalExpression ReturnStatement
1606 addSource('/testA.dart', '''
1607 int T1;
1608 F1() { }
1609 class A {int x;}''');
1610 addTestSource('''
1611 import "/testA.dart";
1612 int T2;
1613 F2() { }
1614 class B {int x;}
1615 class C {foo(){var f; {var x;} return a ? T1 : ^}}''');
1616 computeFast();
1617 return computeFull((bool result) {
1618 assertNotSuggested('x');
1619 assertSuggestLocalVariable('f', null);
1620 assertSuggestLocalMethod('foo', 'C', null);
1621 assertSuggestLocalClass('C');
1622 assertSuggestLocalFunction('F2', null);
1623 assertSuggestLocalTopLevelVar('T2', 'int');
1624 assertSuggestImportedClass('A');
1625 assertSuggestImportedFunction('F1', null);
1626 // TODO (danrubel) getter is being suggested instead of top level var
1627 //assertSuggestImportedTopLevelVar('T1', 'int');
1628 });
1629 }
1630
1631 test_ConditionalExpression_thenExpression() {
1632 // SimpleIdentifier ConditionalExpression ReturnStatement
1633 addSource('/testA.dart', '''
1634 int T1;
1635 F1() { }
1636 class A {int x;}''');
1637 addTestSource('''
1638 import "/testA.dart";
1639 int T2;
1640 F2() { }
1641 class B {int x;}
1642 class C {foo(){var f; {var x;} return a ? T^ : c}}''');
1643 computeFast();
1644 return computeFull((bool result) {
1645 // top level results are partially filtered based on first char
1646 assertSuggestLocalTopLevelVar('T2', 'int');
1647 // TODO (danrubel) getter is being suggested instead of top level var
1648 //assertSuggestImportedTopLevelVar('T1', 'int');
1649 });
1650 }
1651
1567 test_ConstructorName_importedClass() { 1652 test_ConstructorName_importedClass() {
1568 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName 1653 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName
1569 // InstanceCreationExpression 1654 // InstanceCreationExpression
1570 addSource('/testB.dart', ''' 1655 addSource('/testB.dart', '''
1571 lib B; 1656 lib B;
1572 int T1; 1657 int T1;
1573 F1() { } 1658 F1() { }
1574 class X {X.c(); X._d(); z() {}}'''); 1659 class X {X.c(); X._d(); z() {}}''');
1575 addTestSource(''' 1660 addTestSource('''
1576 import "/testB.dart"; 1661 import "/testB.dart";
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 if (f != null) { 1945 if (f != null) {
1861 expect(f.element.isPrivate, isFalse); 1946 expect(f.element.isPrivate, isFalse);
1862 } 1947 }
1863 assertSuggestLocalFunction('bar', 'void'); 1948 assertSuggestLocalFunction('bar', 'void');
1864 assertSuggestParameter('args', 'List'); 1949 assertSuggestParameter('args', 'List');
1865 assertSuggestParameter('b', 'R'); 1950 assertSuggestParameter('b', 'R');
1866 assertSuggestImportedClass('Object'); 1951 assertSuggestImportedClass('Object');
1867 }); 1952 });
1868 } 1953 }
1869 1954
1955 test_IfStatement() {
1956 // SimpleIdentifier IfStatement
1957 addTestSource('''
1958 class A {var b; X _c; foo() {A a; if (true) ^}}''');
1959 computeFast();
1960 return computeFull((bool result) {
1961 expect(request.replacementOffset, completionOffset);
1962 expect(request.replacementLength, 0);
1963 assertSuggestLocalField('b', null);
1964 assertSuggestLocalField('_c', 'X');
1965 assertSuggestImportedClass('Object');
1966 assertSuggestLocalClass('A');
1967 assertNotSuggested('==');
1968 });
1969 }
1970
1870 test_IfStatement_condition() { 1971 test_IfStatement_condition() {
1871 // SimpleIdentifier IfStatement Block BlockFunctionBody 1972 // SimpleIdentifier IfStatement Block BlockFunctionBody
1872 addTestSource(''' 1973 addTestSource('''
1873 class A {int x; int y() => 0;} 1974 class A {int x; int y() => 0;}
1874 main(){var a; if (^)}'''); 1975 main(){var a; if (^)}''');
1875 computeFast(); 1976 computeFast();
1876 return computeFull((bool result) { 1977 return computeFull((bool result) {
1877 expect(request.replacementOffset, completionOffset); 1978 expect(request.replacementOffset, completionOffset);
1878 expect(request.replacementLength, 0); 1979 expect(request.replacementLength, 0);
1879 assertSuggestLocalVariable('a', null); 1980 assertSuggestLocalVariable('a', null);
1880 assertSuggestLocalFunction('main', null); 1981 assertSuggestLocalFunction('main', null);
1881 assertSuggestLocalClass('A'); 1982 assertSuggestLocalClass('A');
1882 assertSuggestImportedClass('Object'); 1983 assertSuggestImportedClass('Object');
1883 }); 1984 });
1884 } 1985 }
1885 1986
1987 test_IfStatement_empty() {
1988 // SimpleIdentifier IfStatement
1989 addTestSource('''
1990 class A {var b; X _c; foo() {A a; if (^) something}}''');
1991 computeFast();
1992 return computeFull((bool result) {
1993 expect(request.replacementOffset, completionOffset);
1994 expect(request.replacementLength, 0);
1995 assertSuggestLocalField('b', null);
1996 assertSuggestLocalField('_c', 'X');
1997 assertSuggestImportedClass('Object');
1998 assertSuggestLocalClass('A');
1999 assertNotSuggested('==');
2000 });
2001 }
2002
2003 test_IfStatement_invocation() {
2004 // SimpleIdentifier PrefixIdentifier IfStatement
2005 addTestSource('''
2006 main() {var a; if (a.^) something}''');
2007 computeFast();
2008 return computeFull((bool result) {
2009 expect(request.replacementOffset, completionOffset);
2010 expect(request.replacementLength, 0);
2011 assertSuggestInvocationMethod('toString', 'Object', 'String');
2012 //TODO (danrubel) type for '_c' should be 'X' not null
2013 assertNotSuggested('Object');
2014 assertNotSuggested('A');
2015 assertNotSuggested('==');
2016 });
2017 }
2018
1886 test_ImportDirective_dart() { 2019 test_ImportDirective_dart() {
1887 // SimpleStringLiteral ImportDirective 2020 // SimpleStringLiteral ImportDirective
1888 addTestSource(''' 2021 addTestSource('''
1889 import "dart^"; 2022 import "dart^";
1890 main() {}'''); 2023 main() {}''');
1891 computeFast(); 2024 computeFast();
1892 return computeFull((bool result) { 2025 return computeFull((bool result) {
1893 assertNoSuggestions(); 2026 assertNoSuggestions();
1894 }); 2027 });
1895 } 2028 }
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after
2743 assertNotSuggested('bar2'); 2876 assertNotSuggested('bar2');
2744 assertNotSuggested('_B'); 2877 assertNotSuggested('_B');
2745 assertSuggestLocalClass('Y'); 2878 assertSuggestLocalClass('Y');
2746 assertSuggestLocalClass('C'); 2879 assertSuggestLocalClass('C');
2747 assertSuggestLocalVariable('f', null); 2880 assertSuggestLocalVariable('f', null);
2748 assertNotSuggested('x'); 2881 assertNotSuggested('x');
2749 assertNotSuggested('e'); 2882 assertNotSuggested('e');
2750 }); 2883 });
2751 } 2884 }
2752 } 2885 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698