Skip to content

Commit 586fcae

Browse files
author
Illia Aihistov
committed
refactor: migrate no_magic_number test cases to unit tests and remove legacy integration tests
1 parent cc0e0cf commit 586fcae

4 files changed

Lines changed: 92 additions & 190 deletions

File tree

lint_test/no_magic_number_allowed_in_widget_params_test/analysis_options.yaml

Lines changed: 0 additions & 8 deletions
This file was deleted.

lint_test/no_magic_number_allowed_in_widget_params_test/no_magic_number_allowed_in_widget_params_test.dart

Lines changed: 0 additions & 33 deletions
This file was deleted.

lint_test/no_magic_number_test.dart

Lines changed: 0 additions & 149 deletions
This file was deleted.

test/src/lints/no_magic_number/no_magic_number_rule_test.dart

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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'''
5261
void 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

Comments
 (0)