Skip to content

Commit

Permalink
Add some test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpallant committed Nov 21, 2024
1 parent 23daf8c commit b18add3
Show file tree
Hide file tree
Showing 16 changed files with 242 additions and 16 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Add tools
run: sudo apt-get update -y && sudo apt-get install -y graphviz
- name: Format
run: cargo fmt --check
- name: Build
run: cargo build
- name: Test
run: cargo test
- name: Clippy
run: cargo clippy --all-targets --all-features
- name: Build with 1.74
Expand Down
70 changes: 55 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ serde = {version = "1", features = ["derive"]}
thiserror = "1"
toml = "0.7"

[dev-dependencies]
folder_compare = "0.4.0"

# The profile that 'cargo dist' will build with
[profile.dist]
inherits = "release"
Expand Down
1 change: 1 addition & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data_out
1 change: 1 addition & 0 deletions tests/data_in/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
book
6 changes: 6 additions & 0 deletions tests/data_in/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[book]
authors = ["Jonathan Pallant"]
language = "en"
multilingual = false
src = "src"
title = "Sample Book"
12 changes: 12 additions & 0 deletions tests/data_in/index_template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>$TITLE</title>
</head>
<body class="article">
<h1>$TITLE</h1>
<div>
$INDEX
</div>
</body>
</html>
4 changes: 4 additions & 0 deletions tests/data_in/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Summary

- [Chapter 1](./chapter_1.md)
- [Chapter 2](./chapter_2.md)
9 changes: 9 additions & 0 deletions tests/data_in/src/chapter_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Page 1

## Page 2

---

Page 3

## Page 4
10 changes: 10 additions & 0 deletions tests/data_in/src/chapter_2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Page 1

```dot process
digraph {
node [shape=record];
"X";
}
```

## Page 2
13 changes: 13 additions & 0 deletions tests/data_in/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>$TITLE</title>
</head>
<body>
<section data-markdown>
<textarea data-template>
$CONTENT
</textarea>
</section>
</body>
</html>
Empty file added tests/data_out/.keep
Empty file.
44 changes: 44 additions & 0 deletions tests/reference.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//! Builds a reference book into a set of slides, and checks they match what we expect.
use std::path::Path;

#[test]
fn build_slides() {
let slide_template_string = include_str!("./data_in/template.html");
let index_template_string = include_str!("./data_in/index_template.html");
println!("We are in: {}", std::env::current_dir().unwrap().display());
mdslides::run(
Some(Path::new("tests/data_in")),
Path::new("tests/data_out"),
slide_template_string,
Some(index_template_string),
)
.expect("mdslides failed");

let comparison = folder_compare::FolderCompare::new(
Path::new("tests/reference_out"),
Path::new("tests/data_out"),
&vec![],
)
.expect("failed to compare");
if !comparison.changed_files.is_empty() {
for filename in comparison.changed_files {
let contents = std::fs::read_to_string(&filename).unwrap();
eprintln!(
"Changed File {filename}:\n{contents}",
filename = filename.display()
);
}
panic!("Some files differ");
}
if !comparison.new_files.is_empty() {
for filename in comparison.new_files {
let contents = std::fs::read_to_string(&filename).unwrap();
eprintln!(
"New File {filename}:\n{contents}",
filename = filename.display()
);
}
panic!("Some new files found");
}
}
24 changes: 24 additions & 0 deletions tests/reference_out/chapter_1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Chapter 1</title>
</head>
<body>
<section data-markdown>
<textarea data-template>
# Page 1

---
## Page 2

---

Page 3

---
## Page 4

</textarea>
</section>
</body>
</html>
38 changes: 38 additions & 0 deletions tests/reference_out/chapter_2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Chapter 2</title>
</head>
<body>
<section data-markdown>
<textarea data-template>
# Page 1

<figure>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 12.2.0 (20241103.1931)
-->
<!-- Pages: 1 -->
<svg width="62pt" height="45pt"
viewBox="0.00 0.00 62.00 45.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 41)">
<polygon fill="white" stroke="none" points="-4,4 -4,-41 58,-41 58,4 -4,4"/>
<!-- X -->
<g id="node1" class="node">
<title>X</title>
<polygon fill="none" stroke="black" points="0,-0.5 0,-36.5 54,-36.5 54,-0.5 0,-0.5"/>
<text text-anchor="middle" x="26.88" y="-13.45" font-family="Times,serif" font-size="14.00">X</text>
</g>
</g>
</svg>
</figure>

---
## Page 2

</textarea>
</section>
</body>
</html>
17 changes: 17 additions & 0 deletions tests/reference_out/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Sample Book</title>
</head>
<body class="article">
<h1>Sample Book</h1>
<div>
<h1>Summary</h1>
<ul>
<li><a href="./chapter_1.html">Chapter 1</a></li>
<li><a href="./chapter_2.html">Chapter 2</a></li>
</ul>

</div>
</body>
</html>

0 comments on commit b18add3

Please sign in to comment.