Skip to content

Commit 5f66888

Browse files
Add some test cases.
1 parent 23daf8c commit 5f66888

File tree

16 files changed

+231
-16
lines changed

16 files changed

+231
-16
lines changed

.github/workflows/check.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ jobs:
1515
build:
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v3
18+
- uses: actions/checkout@v4
19+
- name: Add tools
20+
run: sudo apt-get update -y && sudo apt-get install -y graphviz
1921
- name: Format
2022
run: cargo fmt --check
2123
- name: Build
2224
run: cargo build
25+
- name: Test
26+
run: cargo test
2327
- name: Clippy
2428
run: cargo clippy --all-targets --all-features
2529
- name: Build with 1.74

Cargo.lock

Lines changed: 55 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ serde = {version = "1", features = ["derive"]}
2121
thiserror = "1"
2222
toml = "0.7"
2323

24+
[dev-dependencies]
25+
folder_compare = "0.4.0"
26+
2427
# The profile that 'cargo dist' will build with
2528
[profile.dist]
2629
inherits = "release"

tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data_out

tests/data_in/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
book

tests/data_in/book.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[book]
2+
authors = ["Jonathan Pallant"]
3+
language = "en"
4+
multilingual = false
5+
src = "src"
6+
title = "Sample Book"

tests/data_in/index_template.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>$TITLE</title>
5+
</head>
6+
<body class="article">
7+
<h1>$TITLE</h1>
8+
<div>
9+
$INDEX
10+
</div>
11+
</body>
12+
</html>

tests/data_in/src/SUMMARY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Summary
2+
3+
- [Chapter 1](./chapter_1.md)
4+
- [Chapter 2](./chapter_2.md)

tests/data_in/src/chapter_1.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Page 1
2+
3+
## Page 2
4+
5+
---
6+
7+
Page 3
8+
9+
## Page 4

tests/data_in/src/chapter_2.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Page 1
2+
3+
```dot process
4+
digraph {
5+
node [shape=record];
6+
"X";
7+
}
8+
```
9+
10+
## Page 2

tests/data_in/template.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>$TITLE</title>
5+
</head>
6+
<body>
7+
<section data-markdown>
8+
<textarea data-template>
9+
$CONTENT
10+
</textarea>
11+
</section>
12+
</body>
13+
</html>

tests/data_out/.keep

Whitespace-only changes.

tests/reference.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//! Builds a reference book into a set of slides, and checks they match what we expect.
2+
3+
use std::path::Path;
4+
5+
#[test]
6+
fn build_slides() {
7+
let slide_template_string = include_str!("./data_in/template.html");
8+
let index_template_string = include_str!("./data_in/index_template.html");
9+
println!("We are in: {}", std::env::current_dir().unwrap().display());
10+
mdslides::run(
11+
Some(Path::new("tests/data_in")),
12+
Path::new("tests/data_out"),
13+
slide_template_string,
14+
Some(index_template_string),
15+
).expect("mdslides failed");
16+
17+
18+
let comparison = folder_compare::FolderCompare::new(Path::new("tests/reference_out"), Path::new("tests/data_out"), &vec![]).expect("failed to compare");
19+
if !comparison.changed_files.is_empty() {
20+
for filename in comparison.changed_files {
21+
let contents = std::fs::read_to_string(&filename).unwrap();
22+
eprintln!("Changed File {filename}:\n{contents}", filename=filename.display());
23+
}
24+
panic!("Some files differ");
25+
}
26+
if !comparison.new_files.is_empty() {
27+
for filename in comparison.new_files {
28+
let contents = std::fs::read_to_string(&filename).unwrap();
29+
eprintln!("New File {filename}:\n{contents}", filename=filename.display());
30+
}
31+
panic!("Some new files found");
32+
}
33+
}

tests/reference_out/chapter_1.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Chapter 1</title>
5+
</head>
6+
<body>
7+
<section data-markdown>
8+
<textarea data-template>
9+
# Page 1
10+
11+
---
12+
## Page 2
13+
14+
---
15+
16+
Page 3
17+
18+
---
19+
## Page 4
20+
21+
</textarea>
22+
</section>
23+
</body>
24+
</html>

tests/reference_out/chapter_2.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Chapter 2</title>
5+
</head>
6+
<body>
7+
<section data-markdown>
8+
<textarea data-template>
9+
# Page 1
10+
11+
<figure>
12+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
13+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
14+
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
15+
<!-- Generated by graphviz version 12.2.0 (20241103.1931)
16+
-->
17+
<!-- Pages: 1 -->
18+
<svg width="62pt" height="45pt"
19+
viewBox="0.00 0.00 62.00 45.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
20+
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 41)">
21+
<polygon fill="white" stroke="none" points="-4,4 -4,-41 58,-41 58,4 -4,4"/>
22+
<!-- X -->
23+
<g id="node1" class="node">
24+
<title>X</title>
25+
<polygon fill="none" stroke="black" points="0,-0.5 0,-36.5 54,-36.5 54,-0.5 0,-0.5"/>
26+
<text text-anchor="middle" x="26.88" y="-13.45" font-family="Times,serif" font-size="14.00">X</text>
27+
</g>
28+
</g>
29+
</svg>
30+
</figure>
31+
32+
---
33+
## Page 2
34+
35+
</textarea>
36+
</section>
37+
</body>
38+
</html>

tests/reference_out/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Sample Book</title>
5+
</head>
6+
<body class="article">
7+
<h1>Sample Book</h1>
8+
<div>
9+
<h1>Summary</h1>
10+
<ul>
11+
<li><a href="./chapter_1.html">Chapter 1</a></li>
12+
<li><a href="./chapter_2.html">Chapter 2</a></li>
13+
</ul>
14+
15+
</div>
16+
</body>
17+
</html>

0 commit comments

Comments
 (0)