##// END OF EJS Templates
check-code: improve quote detection regexp, add tests
Benoit Boissinot -
r10722:c4fb2103 default
parent child Browse files
Show More
@@ -10,9 +10,9 b''
10 10 import sys, re, glob
11 11
12 12 def repquote(m):
13 t = re.sub(r"\w", "x", m.group(2))
13 t = re.sub(r"\w", "x", m.group('text'))
14 14 t = re.sub(r"[^\sx]", "o", t)
15 return m.group(1) + t + m.group(1)
15 return m.group('quote') + t + m.group('quote')
16 16
17 17 def repcomment(m):
18 18 return m.group(1) + "#" * len(m.group(2))
@@ -96,10 +96,9 b' pypats = ['
96 96 ]
97 97
98 98 pyfilters = [
99 (r'''(?<!")(")(([^"\n]|\\")+)"(?!")''', repquote),
100 (r"""(?<!')(')(([^'\n]|\\')+)'(?!')""", repquote),
101 (r"""(''')(([^']|\\'|'{1,2}(?!'))*)'''""", repquote),
102 (r'''(""")(([^"]|\\"|"{1,2}(?!"))*)"""''', repquote),
99 (r"""(?msx)(?P<quote>('''|\"\"\"|(?<!')'(?!')|(?<!")"(?!")))
100 (?P<text>(.*?))
101 (?<!\\)(?P=quote)""", repquote),
103 102 (r"( *)(#([^\n]*\S)?)", repcomment),
104 103 ]
105 104
@@ -123,7 +122,7 b' cpats = ['
123 122
124 123 cfilters = [
125 124 (r'(/\*)(((\*(?!/))|[^*])*)\*/', repccomment),
126 (r'''(?<!")(")(([^"]|\\")+"(?!"))''', repquote),
125 (r'''(?P<quote>(?<!")")(?P<text>([^"]|\\")+)"(?!")''', repquote),
127 126 (r'''(#\s*include\s+<)([^>]+)>''', repinclude),
128 127 (r'(\()([^)]+\))', repcallspaces),
129 128 ]
@@ -12,5 +12,13 b' def toto( arg1, arg2):'
12 12 return ( 5+6, 9)
13 13 EOF
14 14
15 cat > quote.py <<EOF
16 (''' ( 4x5 )
17 but """\''' and finally''',
18 """let's fool checkpatch""", '1+2',
19 '"""', 42+1, """and
20 ( 4-1 ) """, "( 1+1 )\" and ")
21 EOF
22
15 23 check_code=`dirname $0`/../contrib/check-code.py
16 ${check_code} ./wrong.py ./correct.py
24 ${check_code} ./wrong.py ./correct.py ./quote.py
@@ -8,3 +8,6 b''
8 8 > return ( 5+6, 9)
9 9 missing whitespace in expression
10 10 gratuitous whitespace in () or []
11 ./quote.py:4:
12 > '"""', 42+1, """and
13 missing whitespace in expression
General Comments 0
You need to be logged in to leave comments. Login now