1
0
mirror of https://github.com/lise-henry/crowbook synced 2024-09-25 16:10:43 +02:00

Add tests for toc.render_epub

This commit is contained in:
Elisabeth Henry 2016-12-19 00:56:41 +01:00
parent 23f1562035
commit 45e91c1ebc

View File

@ -32,3 +32,100 @@ fn toc_simple() {
</ul>";
test_eq(&actual, expected);
}
#[test]
fn toc_epub_simple() {
let mut toc = Toc::new();
toc.add(1, String::from("#1"), "1".to_owned());
toc.add(1, String::from("#2"), "2".to_owned());
let actual = toc.render_epub(1);
let expected = "
<navPoint id = \"navPoint-1\">
<navLabel>
<text>1</text>
</navLabel>
<content src = \"#1\" />
</navPoint>
<navPoint id = \"navPoint-2\">
<navLabel>
<text>2</text>
</navLabel>
<content src = \"#2\" />
</navPoint>
";
test_eq(&actual, expected);
}
#[test]
fn toc_epub_simple_sublevels() {
let mut toc = Toc::new();
toc.add(1, String::from("#1"), "1".to_owned());
toc.add(2, String::from("#1.1"), "1.1".to_owned());
toc.add(1, String::from("#2"), "2".to_owned());
toc.add(2, String::from("#2.1"), "2.1".to_owned());
let actual = toc.render_epub(1);
let expected = "
<navPoint id = \"navPoint-1\">
<navLabel>
<text>1</text>
</navLabel>
<content src = \"#1\" />
<navPoint id = \"navPoint-2\">
<navLabel>
<text>1.1</text>
</navLabel>
<content src = \"#1.1\" />
</navPoint>
</navPoint>
<navPoint id = \"navPoint-3\">
<navLabel>
<text>2</text>
</navLabel>
<content src = \"#2\" />
<navPoint id = \"navPoint-4\">
<navLabel>
<text>2.1</text>
</navLabel>
<content src = \"#2.1\" />
</navPoint>
</navPoint>
";
test_eq(&actual, expected);
}
#[test]
fn toc_epub_broken_sublevels() {
let mut toc = Toc::new();
toc.add(2, String::from("#1.1"), "1.1".to_owned());
toc.add(1, String::from("#2"), "2".to_owned());
toc.add(2, String::from("#2.1"), "2.1".to_owned());
let actual = toc.render_epub(1);
let expected = "
<navPoint id = \"navPoint-1\">
<navLabel>
<text>1.1</text>
</navLabel>
<content src = \"#1.1\" />
</navPoint>
<navPoint id = \"navPoint-2\">
<navLabel>
<text>2</text>
</navLabel>
<content src = \"#2\" />
<navPoint id = \"navPoint-3\">
<navLabel>
<text>2.1</text>
</navLabel>
<content src = \"#2.1\" />
</navPoint>
</navPoint>
";
test_eq(&actual, expected);
}