mirror of
https://github.com/github/codeql.git
synced 2026-04-25 16:55:19 +02:00
Add test for locations of regexp terms.
This commit is contained in:
20
python/ql/test/library-tests/regexparser/Locations.expected
Normal file
20
python/ql/test/library-tests/regexparser/Locations.expected
Normal 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 |
|
||||
7
python/ql/test/library-tests/regexparser/Locations.ql
Normal file
7
python/ql/test/library-tests/regexparser/Locations.ql
Normal 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
|
||||
92
python/ql/test/library-tests/regexparser/locations.py
Normal file
92
python/ql/test/library-tests/regexparser/locations.py
Normal 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'
|
||||
)
|
||||
Reference in New Issue
Block a user