Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/smoke/authors/author-name.test.ts
12925 views
1
/*
2
* authors-name.test.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*
6
*/
7
8
import { ensureFileRegexMatches } from "../../verify.ts";
9
import { testRender } from "../render/render.ts";
10
11
// TODO: Add verification of the name parsing and breaking.
12
const authorNames = [
13
"Mine",
14
"Charles Teague",
15
"Charles von Teague",
16
"Alice Jane Malloc",
17
"Memes, Cat Jane",
18
"Memes, Cat J",
19
"Memes, C J",
20
"Ludwig von Beethoven",
21
"\n name: Prince",
22
"\n name:\n literal: Pedro Martinez",
23
"\n name:\n family: Teague\n given: Charles",
24
];
25
const templateContents = `
26
<html>
27
<head></head>
28
<body>
29
$for(by-author)$
30
<p>LITERAL</p>
31
<p class="literal">$by-author.name.literal$</p>
32
33
<p>GIVEN</p>
34
<p class="given">$by-author.name.given$</p>
35
36
<p>FAMILY</p>
37
<p class="family">$by-author.name.family$</p>
38
39
<p>DROPPING PART</p>
40
<p class="dropping-particle">$by-author.name.dropping-particle$<p>
41
42
<p>NON-DROPPING PART</p>
43
<p class="non-dropping-particle">$by-author.name.non-dropping-particle$<p>
44
$endfor$
45
</body>
46
</html>
47
`;
48
49
const documentContents = `---
50
title: Hello World
51
author: !!author!!
52
template: !!template!!
53
---
54
55
## This is a test
56
57
This is the body
58
`;
59
60
for (const name of authorNames) {
61
const template = Deno.makeTempFileSync();
62
Deno.writeTextFileSync(template, templateContents);
63
64
const document = Deno.makeTempFileSync({ suffix: ".qmd" });
65
const documentReady = documentContents.replace("!!author!!", name).replace(
66
"!!template!!",
67
template,
68
);
69
Deno.writeTextFileSync(document, documentReady);
70
testRender(document, "html", false, [
71
ensureFileRegexMatches(document, []),
72
], {
73
prereq: () => {
74
console.log(`Testing author '${name}'`);
75
return Promise.resolve(true);
76
},
77
setup: () => {
78
return Promise.resolve();
79
},
80
teardown: () => {
81
return Deno.remove(document);
82
},
83
});
84
}
85
86