Skip to content

Commit a10ee7a

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
[linter] Move use_raw_strings tests
Change-Id: I70f1aadcb2216a5d328632ad2804e592e5f03804 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/323225 Commit-Queue: Phil Quitslund <[email protected]> Auto-Submit: Samuel Rawlins <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent 38e0046 commit a10ee7a

File tree

3 files changed

+126
-25
lines changed

3 files changed

+126
-25
lines changed

pkg/linter/test/rules/all.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ import 'use_key_in_widget_constructors_test.dart'
217217
import 'use_late_for_private_fields_and_variables_test.dart'
218218
as use_late_for_private_fields_and_variables;
219219
import 'use_named_constants_test.dart' as use_named_constants;
220+
import 'use_raw_strings_test.dart' as use_raw_strings;
220221
import 'use_rethrow_when_possible_test.dart' as use_rethrow_when_possible;
221222
import 'use_setters_to_change_properties_test.dart'
222223
as use_setters_to_change_properties;
@@ -383,6 +384,7 @@ void main() {
383384
use_key_in_widget_constructors.main();
384385
use_late_for_private_fields_and_variables.main();
385386
use_named_constants.main();
387+
use_raw_strings.main();
386388
use_rethrow_when_possible.main();
387389
use_setters_to_change_properties.main();
388390
use_string_buffers.main();
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
import 'package:test_reflective_loader/test_reflective_loader.dart';
6+
7+
import '../rule_test_support.dart';
8+
9+
main() {
10+
defineReflectiveSuite(() {
11+
defineReflectiveTests(UseRawStringsTest);
12+
});
13+
}
14+
15+
@reflectiveTest
16+
class UseRawStringsTest extends LintRuleTest {
17+
@override
18+
String get lintRule => 'use_raw_strings';
19+
20+
test_escapedBackslash() async {
21+
await assertDiagnostics(r'''
22+
var f = '\\';
23+
''', [
24+
lint(8, 4),
25+
]);
26+
}
27+
28+
test_escapedDollar() async {
29+
await assertDiagnostics(r'''
30+
var f = '\$';
31+
''', [
32+
lint(8, 4),
33+
]);
34+
}
35+
36+
test_escapedMultiple() async {
37+
await assertDiagnostics(r'''
38+
var f = '\$ and \\';
39+
''', [
40+
lint(8, 11),
41+
]);
42+
}
43+
44+
test_escapedMultiple_withInterpolation() async {
45+
await assertNoDiagnostics(r'''
46+
var x = 1;
47+
var f = '\$ and \\ and $x';
48+
''');
49+
}
50+
51+
test_escapedMultiple_withNewline() async {
52+
await assertNoDiagnostics(r'''
53+
var f = '\$ and \\ and \n';
54+
''');
55+
}
56+
57+
test_raw_escapedBackslash() async {
58+
await assertNoDiagnostics(r'''
59+
var f = r'\\';
60+
''');
61+
}
62+
63+
test_raw_escapedDollar() async {
64+
await assertNoDiagnostics(r'''
65+
var f = r'\$';
66+
''');
67+
}
68+
69+
test_raw_escapedMultiple() async {
70+
await assertNoDiagnostics(r'''
71+
var f = r'\$ and \\';
72+
''');
73+
}
74+
75+
test_raw_escapedMultiple_andInterpolation() async {
76+
await assertNoDiagnostics(r'''
77+
var x = 1;
78+
var f = r'\$ and \\ and $x';
79+
''');
80+
}
81+
82+
test_raw_escapedMultiple_andNewline() async {
83+
await assertNoDiagnostics(r'''
84+
var f = r'\$ and \\ and \n';
85+
''');
86+
}
87+
88+
test_triple_escapedBackslash() async {
89+
await assertDiagnostics(r"""
90+
var f = '''\\''';
91+
""", [
92+
lint(8, 8),
93+
]);
94+
}
95+
96+
test_triple_escapedDollar() async {
97+
await assertDiagnostics(r"""
98+
var f = '''\$''';
99+
""", [
100+
lint(8, 8),
101+
]);
102+
}
103+
104+
test_triple_escapedMultiple() async {
105+
await assertDiagnostics(r"""
106+
var f = '''\$ and \\''';
107+
""", [
108+
lint(8, 15),
109+
]);
110+
}
111+
112+
test_triple_escapedMultiple_andInterpolation() async {
113+
await assertNoDiagnostics(r"""
114+
var x = 1;
115+
var f = '''\$ and \\ and $x''';
116+
""");
117+
}
118+
119+
test_triple_escapedMultiple_andNewline() async {
120+
await assertNoDiagnostics(r"""
121+
var f = '''\$ and \\ and \n''';
122+
""");
123+
}
124+
}

pkg/linter/test_data/rules/use_raw_strings.dart

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

0 commit comments

Comments
 (0)