@@ -40,6 +40,19 @@ def _assert_valid_pdf(path):
4040 assert header == b"%PDF-" , f"Not a valid PDF: { path } "
4141
4242
43+ def _read_pdf_title (path ):
44+ """Extract the /Title string from a PDF's Info dictionary."""
45+ import re
46+ raw = path .read_bytes ()
47+ m = re .search (rb'/Title\s*\(([^)]*)\)' , raw )
48+ if m :
49+ return m .group (1 ).decode ("latin-1" )
50+ m = re .search (rb'/Title\s*<([0-9A-Fa-f]+)>' , raw )
51+ if m :
52+ return bytes .fromhex (m .group (1 ).decode ("ascii" )).decode ("utf-16-be" )
53+ return None
54+
55+
4356def test_build_minimal (default_style , tmp_path ):
4457 md = FIXTURES / "minimal.md"
4558 out = tmp_path / "minimal.pdf"
@@ -110,3 +123,35 @@ def test_build_no_toc(default_style, tmp_path):
110123 out = tmp_path / "headings-notoc.pdf"
111124 result = build_pdf (md , out , {"no_toc" : True }, copy .deepcopy (default_style ))
112125 _assert_valid_pdf (result )
126+
127+
128+ def test_build_intent_info (wg21_style , tmp_path ):
129+ md = FIXTURES / "intent-info.md"
130+ out = tmp_path / "intent-info.pdf"
131+ result = build_pdf (md , out , {}, copy .deepcopy (wg21_style ))
132+ _assert_valid_pdf (result )
133+ title = _read_pdf_title (result )
134+ assert title is not None , "Could not read PDF title metadata"
135+ assert title .startswith ("Info: " ), f"Expected 'Info: ' prefix, got: { title !r} "
136+ assert "Symmetric Transfer" in title
137+
138+
139+ def test_build_intent_ask (wg21_style , tmp_path ):
140+ md = FIXTURES / "intent-ask.md"
141+ out = tmp_path / "intent-ask.pdf"
142+ result = build_pdf (md , out , {}, copy .deepcopy (wg21_style ))
143+ _assert_valid_pdf (result )
144+ title = _read_pdf_title (result )
145+ assert title is not None , "Could not read PDF title metadata"
146+ assert title .startswith ("Ask: " ), f"Expected 'Ask: ' prefix, got: { title !r} "
147+ assert "Coroutine Execution Model" in title
148+
149+
150+ def test_build_no_intent_no_prefix (wg21_style , tmp_path ):
151+ md = FIXTURES / "front-matter.md"
152+ out = tmp_path / "no-intent.pdf"
153+ result = build_pdf (md , out , {}, copy .deepcopy (wg21_style ))
154+ _assert_valid_pdf (result )
155+ title = _read_pdf_title (result )
156+ assert title is not None , "Could not read PDF title metadata"
157+ assert title == "Test Paper" , f"Expected bare title, got: { title !r} "
0 commit comments