Skip to content

Commit d4ff9c8

Browse files
author
Max Schaefer
committed
Add test for locations of regexp terms.
1 parent 9638a6c commit d4ff9c8

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
| locations.py | 14 | 5 |
2+
| locations.py | 19 | 5 |
3+
| locations.py | 24 | 5 |
4+
| locations.py | 29 | 5 |
5+
| locations.py | 34 | 5 |
6+
| locations.py | 39 | 5 |
7+
| locations.py | 44 | 5 |
8+
| locations.py | 49 | 5 |
9+
| locations.py | 54 | 5 |
10+
| locations.py | 54 | 26 |
11+
| locations.py | 59 | 5 |
12+
| locations.py | 59 | 26 |
13+
| locations.py | 65 | 5 |
14+
| locations.py | 65 | 26 |
15+
| locations.py | 72 | 6 |
16+
| locations.py | 72 | 27 |
17+
| locations.py | 80 | 6 |
18+
| locations.py | 85 | 7 |
19+
| locations.py | 90 | 5 |
20+
| locations.py | 90 | 26 |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import semmle.python.regexp.RegexTreeView::RegexTreeView
2+
3+
from RegExpTerm t, string file, int line, int column
4+
where
5+
t.toString() = "[this]" and
6+
t.hasLocationInfo(file, line, column, _, _)
7+
select file, line, column
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import re
2+
3+
# This file contains tests for the regexp parser's location tracking.
4+
5+
# To keep the expected results manageable, we only test the locations of the
6+
# regexp term `[this]`, appearing in various kinds of regexps.
7+
#
8+
# To make the location information easier to understand, we generally put each
9+
# regexp on its own line, even though this is not the way one would normally
10+
# write regexps in Python.
11+
12+
# plain string
13+
re.compile(
14+
'[this] is a test'
15+
)
16+
17+
# raw string
18+
re.compile(
19+
r'[this] is a test'
20+
)
21+
22+
# byte string
23+
re.compile(
24+
b'[this] is a test'
25+
)
26+
27+
# byte raw string
28+
re.compile(
29+
br'[this] is a test'
30+
)
31+
32+
# multiline string
33+
re.compile(
34+
'''[this] is a test'''
35+
)
36+
37+
# multiline raw string
38+
re.compile(
39+
r'''[this] is a test'''
40+
)
41+
42+
# multiline byte string
43+
re.compile(
44+
b'''[this] is a test'''
45+
)
46+
47+
# multiline byte raw string
48+
re.compile(
49+
br'''[this] is a test'''
50+
)
51+
52+
# plain string with multiple parts
53+
re.compile(
54+
'[this] is a test' ' and [this] is another test'
55+
)
56+
57+
# plain string with multiple parts across lines
58+
re.compile(
59+
'[this] is a test'
60+
' and [this] is another test'
61+
)
62+
63+
# plain string with multiple parts across lines and comments
64+
re.compile(
65+
'[this] is a test'
66+
# comment
67+
' and [this] is another test'
68+
)
69+
70+
# actual multiline string
71+
re.compile(
72+
r'''
73+
[this] is a test
74+
and [this] is another test
75+
'''
76+
)
77+
78+
# plain string with escape sequences
79+
re.compile(
80+
'\t[this] is a test'
81+
)
82+
83+
# raw string with escape sequences
84+
re.compile(
85+
r'\A[this] is a test'
86+
)
87+
88+
# plain string with escaped newline
89+
re.compile(
90+
'[this] is a test\
91+
and [this] is another test'
92+
)

0 commit comments

Comments
 (0)