diff --git a/test/rules/all.dart b/test/rules/all.dart index f8dd44894..ee17a0ab1 100644 --- a/test/rules/all.dart +++ b/test/rules/all.dart @@ -190,6 +190,7 @@ import 'use_setters_to_change_properties_test.dart' as use_setters_to_change_properties; import 'use_super_parameters_test.dart' as use_super_parameters; import 'use_test_throws_matchers_test.dart' as use_test_throws_matchers; +import 'valid_regexps_test.dart' as valid_regexps; import 'void_checks_test.dart' as void_checks; void main() { @@ -330,5 +331,6 @@ void main() { use_setters_to_change_properties.main(); use_super_parameters.main(); use_test_throws_matchers.main(); + valid_regexps.main(); void_checks.main(); } diff --git a/test/rules/valid_regexps_test.dart b/test/rules/valid_regexps_test.dart new file mode 100644 index 000000000..823bc4a0a --- /dev/null +++ b/test/rules/valid_regexps_test.dart @@ -0,0 +1,49 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:test_reflective_loader/test_reflective_loader.dart'; + +import '../rule_test_support.dart'; + +main() { + defineReflectiveSuite(() { + defineReflectiveTests(ValidRegexpsTest); + }); +} + +@reflectiveTest +class ValidRegexpsTest extends LintRuleTest { + @override + String get lintRule => 'valid_regexps'; + + test_emojis() async { + // https://stackoverflow.com/questions/61151471/regexp-for-unicode-13-emojis + await assertNoDiagnostics(r''' +var e = RegExp( + r'(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])', + unicode: true); +'''); + } + + test_interpolation() async { + await assertNoDiagnostics(r''' +var r = ''; +var s = RegExp('( $r'); +'''); + } + + test_invalid() async { + await assertDiagnostics(r''' +var s = RegExp('('); +''', [ + lint(15, 3), + ]); + } + + test_valid() async { + await assertNoDiagnostics(r''' +var s = RegExp('[(]'); +'''); + } +} diff --git a/test_data/rules/valid_regexps.dart b/test_data/rules/valid_regexps.dart deleted file mode 100644 index 554c5a46c..000000000 --- a/test_data/rules/valid_regexps.dart +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// test w/ `dart test -N valid_regexps` - -var bad = RegExp('('); //LINT -var good = RegExp('[(]'); //OK -var interpolated = ''; -var skipped = RegExp('( $interpolated'); //OK -- skipped -/// https://stackoverflow.com/questions/61151471/regexp-for-unicode-13-emojis -var emojis = RegExp( - r'(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])', - unicode: true); //OK