Add test for locations of regexp terms.

This commit is contained in:
Max Schaefer
2023-09-22 10:09:03 +01:00
parent 9638a6cb8f
commit d4ff9c8ed1
3 changed files with 119 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
| locations.py | 14 | 5 |
| locations.py | 19 | 5 |
| locations.py | 24 | 5 |
| locations.py | 29 | 5 |
| locations.py | 34 | 5 |
| locations.py | 39 | 5 |
| locations.py | 44 | 5 |
| locations.py | 49 | 5 |
| locations.py | 54 | 5 |
| locations.py | 54 | 26 |
| locations.py | 59 | 5 |
| locations.py | 59 | 26 |
| locations.py | 65 | 5 |
| locations.py | 65 | 26 |
| locations.py | 72 | 6 |
| locations.py | 72 | 27 |
| locations.py | 80 | 6 |
| locations.py | 85 | 7 |
| locations.py | 90 | 5 |
| locations.py | 90 | 26 |

View File

@@ -0,0 +1,7 @@
import semmle.python.regexp.RegexTreeView::RegexTreeView
from RegExpTerm t, string file, int line, int column
where
t.toString() = "[this]" and
t.hasLocationInfo(file, line, column, _, _)
select file, line, column

View File

@@ -0,0 +1,92 @@
import re
# This file contains tests for the regexp parser's location tracking.
# To keep the expected results manageable, we only test the locations of the
# regexp term `[this]`, appearing in various kinds of regexps.
#
# To make the location information easier to understand, we generally put each
# regexp on its own line, even though this is not the way one would normally
# write regexps in Python.
# plain string
re.compile(
'[this] is a test'
)
# raw string
re.compile(
r'[this] is a test'
)
# byte string
re.compile(
b'[this] is a test'
)
# byte raw string
re.compile(
br'[this] is a test'
)
# multiline string
re.compile(
'''[this] is a test'''
)
# multiline raw string
re.compile(
r'''[this] is a test'''
)
# multiline byte string
re.compile(
b'''[this] is a test'''
)
# multiline byte raw string
re.compile(
br'''[this] is a test'''
)
# plain string with multiple parts
re.compile(
'[this] is a test' ' and [this] is another test'
)
# plain string with multiple parts across lines
re.compile(
'[this] is a test'
' and [this] is another test'
)
# plain string with multiple parts across lines and comments
re.compile(
'[this] is a test'
# comment
' and [this] is another test'
)
# actual multiline string
re.compile(
r'''
[this] is a test
and [this] is another test
'''
)
# plain string with escape sequences
re.compile(
'\t[this] is a test'
)
# raw string with escape sequences
re.compile(
r'\A[this] is a test'
)
# plain string with escaped newline
re.compile(
'[this] is a test\
and [this] is another test'
)