|
| 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 | +} |
0 commit comments