summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2012-09-19 16:11:08 +0200
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2012-09-19 16:11:08 +0200
commit54dfc65486683aeff4d612ebc218795bd971de4b (patch)
tree6c6e35a4cfc12d5c806a80a9d8bb27e65f77eb62 /test
parent4314608361014c4e376ac160f6097c0af56ee437 (diff)
downloadpylint-54dfc65486683aeff4d612ebc218795bd971de4b.tar.gz
[format checker] check for anomalous backslash escape (new W1401, W1402). Closes #104571
Diffstat (limited to 'test')
-rw-r--r--test/input/func_excess_escapes.py44
-rw-r--r--test/messages/func_excess_escapes.txt8
2 files changed, 52 insertions, 0 deletions
diff --git a/test/input/func_excess_escapes.py b/test/input/func_excess_escapes.py
new file mode 100644
index 0000000..fe3dc11
--- /dev/null
+++ b/test/input/func_excess_escapes.py
@@ -0,0 +1,44 @@
+# pylint:disable=W0105, W0511
+"""Stray backslash escapes may be missing a raw-string prefix."""
+
+__revision__ = '$Id$'
+
+# Bad escape sequences, which probably don't do what you expect.
+A = "\[\]\\"
+assert '\/' == '\\/'
+ESCAPE_BACKSLASH = '\`'
+
+# Valid escape sequences.
+NEWLINE = "\n"
+OLD_ESCAPES = '\a\b\f\n\t\r\v'
+HEX = '\xad\x0a\x0d'
+OCTAL = '\o123\o000'
+UNICODE = u'\u1234'
+HIGH_UNICODE = u'\U0000abcd'
+QUOTES = '\'\"'
+LITERAL_NEWLINE = '\
+'
+ESCAPE_UNICODE = "\\\\n"
+
+# Bad docstring
+"""Even in a docstring
+
+You shouldn't have ambiguous text like: C:\Program Files\alpha
+"""
+
+# Would be valid in Unicode, but probably not what you want otherwise
+BAD_UNICODE = '\u0042'
+BAD_LONG_UNICODE = '\U00000042'
+BAD_NAMED_UNICODE = '\N{GREEK SMALL LETTER ALPHA}'
+
+GOOD_UNICODE = u'\u0042'
+GOOD_LONG_UNICODE = u'\U00000042'
+GOOD_NAMED_UNICODE = u'\N{GREEK SMALL LETTER ALPHA}'
+
+
+# Valid raw strings
+RAW_BACKSLASHES = r'raw'
+RAW_UNICODE = ur"\u0062\n"
+
+# In a comment you can have whatever you want: \ \\ \n \m
+# even things that look like bad strings: "C:\Program Files"
diff --git a/test/messages/func_excess_escapes.txt b/test/messages/func_excess_escapes.txt
new file mode 100644
index 0000000..aad9ebc
--- /dev/null
+++ b/test/messages/func_excess_escapes.txt
@@ -0,0 +1,8 @@
+W: 7: Anomalous backslash in string: '\['. String constant might be missing an r prefix.
+W: 7: Anomalous backslash in string: '\]'. String constant might be missing an r prefix.
+W: 8: Anomalous backslash in string: '\/'. String constant might be missing an r prefix.
+W: 9: Anomalous backslash in string: '\`'. String constant might be missing an r prefix.
+W: 24: Anomalous backslash in string: '\P'. String constant might be missing an r prefix.
+W: 30: Anomalous Unicode escape in byte string: '\u'. String constant might be missing an r or u prefix.
+W: 31: Anomalous Unicode escape in byte string: '\U'. String constant might be missing an r or u prefix.
+W: 32: Anomalous Unicode escape in byte string: '\N'. String constant might be missing an r or u prefix.