def test_extract_bibitem_tokens_from_curly_braces(): tex = "\n".join(["\\bibitem[label]{key1}", "token1 {token2} {token3}",]) extractor = BibitemExtractor() bibitems = list(extractor.parse(tex)) assert len(bibitems) == 1 assert bibitems[0].id_ == "key1" assert bibitems[0].text == "token1 token2 token3"
def test_extract_bibitem_include_hyperref_contents(): tex = "\n".join( ["\\bibitem[label]{key1}", r"token1 \href{https://url.com}{token2}"]) extractor = BibitemExtractor() bibitems = list(extractor.parse(tex)) assert len(bibitems) == 1 assert bibitems[0].text == "token1 token2"
def test_extract_bibitem_stop_at_newline(): tex = "\n".join( ["\\bibitem[label]{key1}", "token1", "", "text after bibliography (to ignore)"] ) extractor = BibitemExtractor() bibitems = list(extractor.parse(tex)) assert len(bibitems) == 1 assert bibitems[0].id_ == "key1" assert bibitems[0].text == "token1"
def test_extract_bibitems_from_environment(): tex = "\n".join([ "\\begin{thebibliography}", "\\bibitem[label]{key1}", "token1", "\\end{thebibliography}", ]) extractor = BibitemExtractor() bibitems = list(extractor.parse(tex)) assert len(bibitems) == 1 assert bibitems[0].id_ == "key1" assert bibitems[0].text == "token1"
def test_extract_bibitems(): tex = "\n".join([ "\\bibitem[label]{key1}", "token1", "\\newblock \\emph{token2}", "\\newblock token3", "\\bibitem[label]{key2}", "token4", "\\newblock \\emph{token5}", ]) extractor = BibitemExtractor() bibitems = list(extractor.parse(tex)) assert len(bibitems) == 2 assert bibitems[0].id_ == "key1" assert bibitems[0].text == "token1 token2 token3" assert bibitems[1].id_ == "key2" assert bibitems[1].text == "token4 token5"
def test_extract_bibitem_with_brackets_in_label(): tex = "\n".join([r"\bibitem[label{[]}]{key}", r"token"]) extractor = BibitemExtractor() bibitems = list(extractor.parse(tex)) assert len(bibitems) == 1 assert "token" in bibitems[0].text
def test_extract_bibitem_wrapping_key(): tex = "\n".join([r"\bibitem[label]%", r" {key}", r" token"]) extractor = BibitemExtractor() bibitems = list(extractor.parse(tex)) assert len(bibitems) == 1 assert "token" in bibitems[0].text