Skip to content

Commit

Permalink
Don't force \bye being followed by anything, add unittest for it
Browse files Browse the repository at this point in the history
  • Loading branch information
norbusan committed Sep 26, 2024
1 parent 06ebbd6 commit c5b5266
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions preflight_parser/preflight_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,10 @@ def detect_language(self) -> None:
language = LanguageType.latex
if re.search(r"\\text(bf|it|sl)|\\section|\\chapter", self._data, re.MULTILINE):
language = LanguageType.latex
if re.search(r"^[^%\n]*\\bye[^a-zA-Z0-9_]", self._data, re.MULTILINE):
if re.search(r"^[^%\n]*\\bye(?![a-zA-Z])", self._data, re.MULTILINE):
language = LanguageType.tex
self.contains_bye = True
if re.search(r"^[^%\n]*\\documentclass[^a-zA-Z0-9_]", self._data, re.MULTILINE):
if re.search(r"^[^%\n]*\\documentclass[^a-zA-Z]", self._data, re.MULTILINE):
self.contains_documentclass = True
if language == LanguageType.tex:
self.issues.append(
Expand Down
2 changes: 2 additions & 0 deletions preflight_parser/tests/fixture/bye-no-newline/main.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Hello World
\bye
16 changes: 16 additions & 0 deletions preflight_parser/tests/test_preflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,19 @@ def test_preflight_pre_postamble(self):
self.assertEqual(pf.status.key.value, "success")
self.assertEqual(len(pf.detected_toplevel_files), 1)
self.assertEqual(pf.detected_toplevel_files[0].filename, "main.tex")
self.assertEqual(
pf.detected_toplevel_files[0].process.compiler.json(exclude_none=True, exclude_defaults=True),
"""{"engine": "tex", "lang": "latex", "output": "pdf", "postp": "none"}""",
)

def test_preflight_bye_no_newline(self):
"""Test recursive inclusion."""
dir_path = os.path.join(self.fixture_dir, "bye-no-newline")
pf: PreflightResponse = generate_preflight_response(dir_path)
self.assertEqual(pf.status.key.value, "success")
self.assertEqual(len(pf.detected_toplevel_files), 1)
self.assertEqual(pf.detected_toplevel_files[0].filename, "main.tex")
self.assertEqual(
pf.detected_toplevel_files[0].process.compiler.json(exclude_none=True, exclude_defaults=True),
"""{"engine": "tex", "lang": "tex", "output": "dvi", "postp": "dvips_ps2pdf"}""",
)

0 comments on commit c5b5266

Please sign in to comment.