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

Side by Side Diff: pkg/analyzer/test/generated/hint_code_test.dart

Issue 1863803002: Validation of `@required` params (#26182). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 analyzer.test.generated.hint_code_test; 5 library analyzer.test.generated.hint_code_test;
6 6
7 import 'package:analyzer/src/generated/engine.dart'; 7 import 'package:analyzer/src/generated/engine.dart';
8 import 'package:analyzer/src/generated/error.dart'; 8 import 'package:analyzer/src/generated/error.dart';
9 import 'package:analyzer/src/generated/source_io.dart'; 9 import 'package:analyzer/src/generated/source_io.dart';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 void reset() { 100 void reset() {
101 analysisContext2 = AnalysisContextFactory.contextWithCoreAndPackages({ 101 analysisContext2 = AnalysisContextFactory.contextWithCoreAndPackages({
102 'package:meta/meta.dart': r''' 102 'package:meta/meta.dart': r'''
103 library meta; 103 library meta;
104 104
105 const _Factory factory = const _Factory(); 105 const _Factory factory = const _Factory();
106 const _Literal literal = const _Literal(); 106 const _Literal literal = const _Literal();
107 const _MustCallSuper mustCallSuper = const _MustCallSuper(); 107 const _MustCallSuper mustCallSuper = const _MustCallSuper();
108 const _Override override = const _Override(); 108 const _Override override = const _Override();
109 const _Protected protected = const _Protected(); 109 const _Protected protected = const _Protected();
110 const _Required required = const _Required(); 110 const Required required = const Required();
111 class Required {
112 final String reason;
113 const Required([this.reason]);
114 }
111 115
112 class _Factory { 116 class _Factory {
113 const _Factory(); 117 const _Factory();
114 } 118 }
115 class _Literal { 119 class _Literal {
116 const _Literal(); 120 const _Literal();
117 } 121 }
118 class _MustCallSuper { 122 class _MustCallSuper {
119 const _MustCallSuper(); 123 const _MustCallSuper();
120 } 124 }
(...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 } 1520 }
1517 class B extends A { 1521 class B extends A {
1518 @override 1522 @override
1519 set m(int x) {} 1523 set m(int x) {}
1520 }'''); 1524 }''');
1521 computeLibrarySourceErrors(source); 1525 computeLibrarySourceErrors(source);
1522 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_SETTER]); 1526 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_SETTER]);
1523 verify([source]); 1527 verify([source]);
1524 } 1528 }
1525 1529
1530 void test_required_constructor_param() {
1531 Source source = addSource(r'''
1532 import 'package:meta/meta.dart';
1533
1534 class C {
1535 C({@Required('must specify an `a`') int a}) {}
1536 }
1537
1538 main() {
1539 new C();
1540 }
1541 ''');
1542 computeLibrarySourceErrors(source);
1543 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]);
1544 verify([source]);
1545 }
1546
1547 void test_required_constructor_param_no_reason() {
1548 Source source = addSource(r'''
1549 import 'package:meta/meta.dart';
1550
1551 class C {
1552 C({@required int a}) {}
1553 }
1554
1555 main() {
1556 new C();
1557 }
1558 ''');
1559 computeLibrarySourceErrors(source);
1560 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]);
1561 verify([source]);
1562 }
1563
1564 void test_required_constructor_param_null_reason() {
1565 Source source = addSource(r'''
1566 import 'package:meta/meta.dart';
1567
1568 class C {
1569 C({@Required(null) int a}) {}
1570 }
1571
1572 main() {
1573 new C();
1574 }
1575 ''');
1576 computeLibrarySourceErrors(source);
1577 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]);
1578 verify([source]);
1579 }
1580
1581 void test_required_constructor_param_OK() {
1582 Source source = addSource(r'''
1583 import 'package:meta/meta.dart';
1584
1585 class C {
1586 C({@required int a}) {}
1587 }
1588
1589 main() {
1590 new C(a: 2);
1591 }
1592 ''');
1593 computeLibrarySourceErrors(source);
1594 assertNoErrors(source);
1595 verify([source]);
1596 }
1597
1598 void test_required_function_param() {
1599 Source source = addSource(r'''
1600 import 'package:meta/meta.dart';
1601
1602 void f({@Required('must specify an `a`') int a}) {}
1603
1604 main() {
1605 f();
1606 }
1607 ''');
1608 computeLibrarySourceErrors(source);
1609 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]);
1610 verify([source]);
1611 }
1612
1613 void test_required_method_param() {
1614 Source source = addSource(r'''
1615 import 'package:meta/meta.dart';
1616 class A {
1617 void m({@Required('must specify an `a`') int a}) {}
1618 }
1619 f() {
1620 new A().m();
1621 }
1622 ''');
1623 computeLibrarySourceErrors(source);
1624 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]);
1625 verify([source]);
1626 }
1627
1526 void test_typeCheck_type_is_Null() { 1628 void test_typeCheck_type_is_Null() {
1527 Source source = addSource(r''' 1629 Source source = addSource(r'''
1528 m(i) { 1630 m(i) {
1529 bool b = i is Null; 1631 bool b = i is Null;
1530 }'''); 1632 }''');
1531 computeLibrarySourceErrors(source); 1633 computeLibrarySourceErrors(source);
1532 assertErrors(source, [HintCode.TYPE_CHECK_IS_NULL]); 1634 assertErrors(source, [HintCode.TYPE_CHECK_IS_NULL]);
1533 verify([source]); 1635 verify([source]);
1534 } 1636 }
1535 1637
(...skipping 1461 matching lines...) Expand 10 before | Expand all | Expand 10 after
2997 n() { 3099 n() {
2998 var a = m(), b = m(); 3100 var a = m(), b = m();
2999 } 3101 }
3000 }'''); 3102 }''');
3001 computeLibrarySourceErrors(source); 3103 computeLibrarySourceErrors(source);
3002 assertErrors( 3104 assertErrors(
3003 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); 3105 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]);
3004 verify([source]); 3106 verify([source]);
3005 } 3107 }
3006 } 3108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698