@@ -47,6 +47,15 @@ int fn(int b) {
4747''' );
4848 }
4949
50+ Future <void >
51+ test_reports_magic_numbers_in_ternary_comparison () async {
52+ await assertAutoDiagnostics ('''
53+ bool canDrive(int age, {bool isUSA = false}) {
54+ return isUSA ? age >= ${expectLint ('16' )} : age > ${expectLint ('18' )};
55+ }
56+ ''' );
57+ }
58+
5059 Future <void > test_does_not_report_allowed_numbers () async {
5160 await assertNoDiagnostics (r'''
5261void fn() {
@@ -296,6 +305,89 @@ void fn() {
296305 var point = (10, 20);
297306 var named = (x: 100, y: 200);
298307}
308+ ''' );
309+ }
310+
311+ Future <void >
312+ test_does_not_report_anonymous_function_default_param () async {
313+ await assertNoDiagnostics (r'''
314+ void fn() {
315+ ({int value = 7}) {};
316+ }
317+ ''' );
318+ }
319+
320+ Future <void >
321+ test_reports_magic_number_mixed_with_consts_in_constructor () async {
322+ await assertAutoDiagnostics ('''
323+ class TestOperation {
324+ final double res;
325+ const TestOperation({required this.res});
326+ }
327+ const n = 15;
328+ const m = 20;
329+ void fn() {
330+ TestOperation(res: (n / m) * ${expectLint ('20' )});
331+ }
332+ ''' );
333+ }
334+
335+ Future <void >
336+ test_reports_multiple_magic_numbers_in_constructor_expression () async {
337+ await assertAutoDiagnostics ('''
338+ class TestOperation {
339+ final double res;
340+ const TestOperation({required this.res});
341+ }
342+ const m = 20;
343+ const n = 15;
344+ void fn() {
345+ final v = TestOperation(res: (${expectLint ('10' )} / m + ${expectLint ('4' )} + n));
346+ }
347+ ''' );
348+ }
349+
350+ Future <void >
351+ test_does_not_report_var_with_const_constructor_call () async {
352+ await assertNoDiagnostics (r'''
353+ class TestOperation {
354+ final double res;
355+ const TestOperation({required this.res});
356+ }
357+ const n = 15;
358+ void fn() {
359+ var v = const TestOperation(res: 15 + (10 / n));
360+ }
361+ ''' );
362+ }
363+
364+ Future <void >
365+ test_reports_magic_number_in_constructor_inside_list () async {
366+ await assertAutoDiagnostics ('''
367+ class TestOperation {
368+ final double res;
369+ const TestOperation({required this.res});
370+ }
371+ void fn() {
372+ final l = [
373+ TestOperation(res: ${expectLint ('8' )}),
374+ ];
375+ }
376+ ''' );
377+ }
378+
379+ Future <void >
380+ test_does_not_report_const_constructor_inside_list () async {
381+ await assertNoDiagnostics (r'''
382+ class TestOperation {
383+ final double res;
384+ const TestOperation({required this.res});
385+ }
386+ void fn() {
387+ final l = [
388+ const TestOperation(res: 9),
389+ ];
390+ }
299391''' );
300392 }
301393}
0 commit comments