-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_regex.py
More file actions
78 lines (75 loc) · 2.54 KB
/
Copy pathtest_regex.py
File metadata and controls
78 lines (75 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""Test regular expressions."""
from __future__ import annotations
import pytest
from latex_dependency_scanner.scanner import REGEX_TEX
@pytest.mark.unit
@pytest.mark.parametrize(
"text, expected",
[
(
"\\usepackage{geometry}",
{"type": "usepackage", "file": "geometry", "relative_to": None},
),
("\\usepackage{}", {"type": "usepackage", "file": "", "relative_to": None}),
("\\usepackages{geometry}", None),
("\\usepackage", None),
(
"\\RequirePackage{geometry}",
{"type": "RequirePackage", "file": "geometry", "relative_to": None},
),
(
"\\RequirePackage{}",
{"type": "RequirePackage", "file": "", "relative_to": None},
),
("\\RequirePackages{geometry}", None),
("\\RequirePackage", None),
(
"\\input{document}",
{"type": "input", "file": "document", "relative_to": None},
),
(
"\\import{./}{document}",
{"type": "import", "file": "document", "relative_to": "./"},
),
(
"\\subimport{sub/}{document}",
{"type": "subimport", "file": "document", "relative_to": "sub/"},
),
(
"\\includegraphics{image}",
{"type": "includegraphics", "file": "image", "relative_to": None},
),
(
"\\includegraphics{image.pdf}",
{"type": "includegraphics", "file": "image.pdf", "relative_to": None},
),
(
"\\includegraphics{image.eps}",
{"type": "includegraphics", "file": "image.eps", "relative_to": None},
),
(
"\\bibliography{bibfile}",
{"type": "bibliography", "file": "bibfile", "relative_to": None},
),
("\\bibliographystyle{plain}", None),
(
"\\addbibresource{bibfile}",
{"type": "addbibresource", "file": "bibfile", "relative_to": None},
),
(
"\\glsxtrresourcefile{glsfile}",
{"type": "glsxtrresourcefile", "file": "glsfile", "relative_to": None},
),
(
"\\GlsXtrLoadResources[src={glsfile}, selection={all}]",
{"type": "GlsXtrLoadResources", "file": "glsfile", "relative_to": None},
),
],
)
def test_regex_tex(text, expected):
"""Test that regexes capture relevant information."""
match = REGEX_TEX.match(text)
if expected is None:
assert match is expected
else:
assert match.groupdict() == expected