-
Notifications
You must be signed in to change notification settings - Fork 353
Expand file tree
/
Copy pathtest-build-llm.R
More file actions
79 lines (71 loc) · 2.37 KB
/
Copy pathtest-build-llm.R
File metadata and controls
79 lines (71 loc) · 2.37 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
79
test_that("integration test for convert_md()", {
skip_if_no_pandoc()
path <- withr::local_tempfile(pattern = "pkgdown-llm")
convert_md(test_path("assets", "llm.html"), path)
expect_snapshot(write_lines(read_lines(path), stdout()))
})
test_that("simplifies page header", {
html <- xml2::read_html(
r"(
<main><div class="page-header">
<img src="../logo.png" class="logo" alt=""><h1>Package index</h1>
</div></main>)"
)
simplify_page_header(xml2::xml_find_first(html, ".//main"))
expect_equal(xpath_contents(html, ".//main"), "<h1>Package index</h1>")
})
test_that("replaces lifecycle badges with strong text", {
html <- xml2::read_html(
r"(
<span class="badge lifecycle lifecycle-deprecated">deprecated</span>
<a href="https://lifecycle.r-lib.org/articles/stages.html#experimental" class="external-link"><img src="figures/lifecycle-experimental.svg" alt="[Experimental]"></a>
)"
)
simplify_lifecycle_badges(html)
expect_equal(
xpath_text(html, ".//strong"),
c("[deprecated]", "[experimental]")
)
})
test_that("replaces inline data URI images with text placeholders", {
html <- xml2::read_html(
'<img src="data:image/png;base64,abc123" alt="A plot">'
)
simplify_inline_images(html)
expect_equal(xpath_text(html, ".//span"), "[Image: A plot]")
})
test_that("replaces inline data URI images without alt text", {
html <- xml2::read_html(
'<img src="data:image/png;base64,abc123">'
)
simplify_inline_images(html)
expect_equal(xpath_text(html, ".//span"), "[Image]")
})
test_that("converts internal urls to absolute with .md ending", {
html <- xml2::read_html(
r"(
<a href="llm.html">link</a>
<a href="#fragment">link</a>
<a href="https://example.org">link</a>
)"
)
create_absolute_links(html, "https://pkgdown.r-lib.org")
expect_equal(
xpath_attr(html, ".//a", "href"),
c(
"https://pkgdown.r-lib.org/llm.md",
"#fragment",
"https://example.org"
)
)
})
test_that("adjusts extension even without url", {
html <- xml2::read_html(r"(<a href="llm.html">link</a>)")
create_absolute_links(html)
expect_equal(xpath_attr(html, ".//a", "href"), "llm.md")
})
test_that("strip extra classes from pre", {
html <- xml2::read_html(r"(<pre class="downlit sourceCode r">1+1</pre>)")
simplify_code(html)
expect_equal(xpath_attr(html, ".//pre", "class"), "r")
})