linter: Move tests for two lint rules

* lines_longer_than_80_chars
* unnecessary_brace_in_string_interps

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I75b5a5feeb863cb7463467d96ad751d6334e7cfd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371940
Auto-Submit: Sam Rawlins <srawlins@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
This commit is contained in:
Sam Rawlins 2024-06-24 17:58:11 +00:00 committed by Commit Queue
parent 80b0bda3de
commit 39497e46fc
4 changed files with 128 additions and 45 deletions

View file

@ -86,6 +86,29 @@ class LinesLongerThan80CharsTest extends LintRuleTest {
);
}
test_exactly80Characters() async {
await assertNoDiagnostics(r'''
var p =
' ';
''');
}
test_lineEndsWithCrlf() async {
await assertNoDiagnostics('''
var p =
' ';\r\n
''');
}
test_longerThan80Characters() async {
await assertDiagnostics(r'''
var p =
' ';
''', [
lint(88, 1),
]);
}
test_multilineBlockComment_noSpaceAfter80() async {
await assertNoDiagnostics(
'/*\n'
@ -123,4 +146,32 @@ class LinesLongerThan80CharsTest extends LintRuleTest {
],
);
}
test_multilineString() async {
await assertNoDiagnostics(r'''
var p = """
This line is a long, very long, very very long, very very very long, very very very very long
""";
''');
}
test_shorterThan80Characters() async {
await assertNoDiagnostics(r'''
var short = 'This is a short line';
''');
}
test_stringContainsBackslash() async {
await assertNoDiagnostics(r'''
var p =
r'C:\home\dart.dev\guides\language\effective-dart\style\avoid-lines-longer-than-80-characters';
''');
}
test_stringContainsForwardSlash() async {
await assertNoDiagnostics(r'''
var p =
'/home/dart.dev/guides/language/effective-dart/style#avoid-lines-longer-than-80-characters'; // OK
''');
}
}

View file

@ -17,6 +17,83 @@ class UnnecessaryBraceInStringInterpsTest extends LintRuleTest {
@override
String get lintRule => 'unnecessary_brace_in_string_interps';
test_braces_bangAfter() async {
await assertDiagnostics(r'''
void f() {
print('hello ${int}!');
}
''', [
lint(26, 6),
]);
}
test_braces_nonSimpleIdentifier() async {
await assertNoDiagnostics(r'''
void f(int p) {
print('hello ${p.hashCode}');
}
''');
}
test_braces_precededByDollar() async {
await assertNoDiagnostics(r'''
void f() {
var $int = 7;
print('Value is: ${$int}');
}
''');
}
test_braces_simpleIdentifier() async {
await assertDiagnostics(r'''
void f() {
print('hello ${int}');
}
''', [
lint(26, 6),
]);
}
test_braces_simpleIdentifier_numberAfter() async {
await assertNoDiagnostics(r'''
void f() {
print('hello ${int}1');
}
''');
}
test_braces_surroundedByUnderscores() async {
await assertNoDiagnostics(r'''
void f() {
print('hello _${int}_');
}
''');
}
test_noBraces() async {
await assertNoDiagnostics(r'''
void f() {
print('hello $int');
}
''');
}
test_noBraces_bangAfter() async {
await assertNoDiagnostics(r'''
void f() {
print('hello $int!');
}
''');
}
test_noInterpolation() async {
await assertNoDiagnostics(r'''
void f() {
print('hello');
}
''');
}
test_simpleIdentifier() async {
await assertDiagnostics(r'''
void hi(String name) {

View file

@ -1,29 +0,0 @@
// Copyright (c) 2018, 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.
var short = 'This is a short line'; // OK
var line80 =
' '; // OK
var line81 =
' '; // LINT
var long =
'This line is a long, very long, very very long, very very very long, very very very very long'; // LINT
var uriIsOk =
'https://dart.dev/guides/language/effective-dart/style#avoid-lines-longer-than-80-characters'; // OK
var posixPathIsOk =
'/home/dart.dev/guides/language/effective-dart/style#avoid-lines-longer-than-80-characters'; // OK
var windowsPathIsOk =
r'C:\home\dart.dev\guides\language\effective-dart\style\avoid-lines-longer-than-80-characters'; // OK
var multilinesOK = '''
This line is a long, very long, very very long, very very very long, very very very very long
''';
var interpolated = 'this $uriIsOk that';
var line80EndingWithCRLF =
' '; // OK

View file

@ -1,16 +0,0 @@
// Copyright (c) 2015, 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.
main(args) {
print('hello');
print('hello $args');
print('hello $args!');
print('hello ${args}1');
print('hello ${args}'); //LINT [16:7]
print('hello ${args}!'); //LINT
print('hello ${args.length}');
print('hello _${args}_');
var $someString = 'Some Value';
print('Value is: ${$someString}'); //OK
}