Skip to content

Commit

Permalink
Move prefer_double_quotes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins committed Jul 13, 2023
1 parent aed089e commit 55e8bab
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 34 deletions.
2 changes: 2 additions & 0 deletions test/rules/all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import 'prefer_const_literals_to_create_immutables_test.dart'
import 'prefer_constructors_over_static_methods_test.dart'
as prefer_constructors_over_static_methods;
import 'prefer_contains_test.dart' as prefer_contains;
import 'prefer_double_quotes_test.dart' as prefer_double_quotes;
import 'prefer_expression_function_bodies_test.dart'
as prefer_expression_function_bodies;
import 'prefer_final_fields_test.dart' as prefer_final_fields;
Expand Down Expand Up @@ -252,6 +253,7 @@ void main() {
prefer_const_literals_to_create_immutables.main();
prefer_constructors_over_static_methods.main();
prefer_contains.main();
prefer_double_quotes.main();
prefer_expression_function_bodies.main();
prefer_final_fields.main();
prefer_final_in_for_each.main();
Expand Down
116 changes: 116 additions & 0 deletions test/rules/prefer_double_quotes_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// 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(PreferDoubleQuotesTest);
});
}

@reflectiveTest
class PreferDoubleQuotesTest extends LintRuleTest {
@override
String get lintRule => 'prefer_double_quotes';

test_doubleQuotes() async {
await assertNoDiagnostics(r'''
var s = "uses double";
''');
}

test_doubleQuotes_raw() async {
await assertNoDiagnostics(r'''
var s = r"uses double";
''');
}

test_doubleQuotes_triple_raw() async {
await assertNoDiagnostics(r'''
var s = r"""uses double""";
''');
}

test_doubleQuotes_withInterpolation() async {
await assertNoDiagnostics(r'''
var x = "x";
var s = "uses double $x";
''');
}

test_doubleQuotes_withInterpolationWithSingleQuote() async {
await assertNoDiagnostics(r'''
var x = "x";
var s = "foo ${x == 'x'} bar";
''');
}

test_singleQuote() async {
await assertDiagnostics(r'''
var s = 'no quote';
''', [
lint(8, 10),
]);
}

test_singleQuote_hasDoubleQuote_withInterpolation() async {
await assertNoDiagnostics(r'''
var x = "x";
var s = 'has double quote " $x';
''');
}

test_singleQuote_hasDoubleQuotes() async {
await assertNoDiagnostics(r'''
var s = 'has double quote "';
''');
}

test_singleQuote_raw() async {
await assertDiagnostics(r'''
var s = r'no double quote';
''', [
lint(8, 18),
]);
}

test_singleQuote_raw_hasDoubleQuotes() async {
await assertNoDiagnostics(r'''
var s = r'has double quote "';
''');
}

test_singleQuote_triple_raw() async {
await assertDiagnostics(r"""
var s = r'''no double quote''';
""", [
lint(8, 22),
]);
}

test_singleQuote_triple_raw_hasDouble() async {
await assertNoDiagnostics(r"""
var s = r'''has double quote "''';
""");
}

test_singleQuote_withInterpolation() async {
await assertDiagnostics(r'''
var x = "x";
var s = 'no double quote $x';
''', [
lint(21, 20),
]);
}

test_singleQuote_withInterpolationWithDoubleQuotes() async {
await assertNoDiagnostics(r'''
var x = "x";
var s = 'foo ${x == "x"} bar';
''');
}
}
34 changes: 0 additions & 34 deletions test_data/rules/prefer_double_quotes.dart

This file was deleted.

0 comments on commit 55e8bab

Please sign in to comment.