Skip to content

Commit 995986d

Browse files
committed
Bump edition, add tests, and add CI
1 parent fa4f639 commit 995986d

File tree

3 files changed

+77
-5
lines changed

3 files changed

+77
-5
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Continuous integration
2+
on: [push, pull_request]
3+
4+
jobs:
5+
tests:
6+
name: Tests
7+
strategy:
8+
matrix:
9+
os: [ubuntu-latest, windows-latest]
10+
runs-on: ${{ matrix.os }}
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: dtolnay/[email protected]
14+
- uses: Swatinem/rust-cache@v2
15+
- run: cargo test --no-run
16+
- run: cargo test --no-fail-fast
17+
18+
checks:
19+
name: Check clippy, formatting, and documentation
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: dtolnay/[email protected]
24+
with:
25+
components: clippy, rustfmt
26+
- uses: Swatinem/rust-cache@v2
27+
- run: cargo clippy --all-targets --all-features
28+
- run: cargo fmt --check --all
29+
- run: cargo doc --no-deps

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ categories = ["compilers", "science"]
55
keywords = ["markup", "typesetting", "typst"]
66
version = "0.13.1"
77
authors = ["The Typst Project Developers"]
8-
edition = "2021"
8+
edition = "2024"
99
homepage = "https://typst.app"
1010
repository = "https://github.com/typst/typst-dev-assets"
1111
license = "Apache-2.0"

src/lib.rs

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn get(path: &str) -> Option<&'static [u8]> {
2929
pub fn get_by_name(filename: &str) -> Option<&'static [u8]> {
3030
FILES
3131
.iter()
32-
.find(|&&(p, _)| p.split('/').last() == Some(filename))
32+
.find(|&&(p, _)| p.split('/').next_back() == Some(filename))
3333
.map(|&(_, d)| d)
3434
}
3535

@@ -46,8 +46,8 @@ pub fn fonts() -> impl Iterator<Item = &'static [u8]> {
4646
files! {
4747
"bib/bad.bib",
4848
"bib/scifi-authors.yaml",
49-
"bib/works_too.bib",
5049
"bib/works.bib",
50+
"bib/works_too.bib",
5151
"data/bad.csv",
5252
"data/bad.json",
5353
"data/bad.toml",
@@ -111,13 +111,13 @@ files! {
111111
"images/molecular.jpg",
112112
"images/monkey.svg",
113113
"images/pattern.svg",
114-
"images/rhino.png",
115114
"images/relative.svg",
115+
"images/rhino.png",
116116
"images/tetrahedron.svg",
117117
"images/tiger.jpg",
118118
"images/typing.jpg",
119-
"plugins/hello.wasm",
120119
"plugins/hello-mut.wasm",
120+
"plugins/hello.wasm",
121121
"plugins/plugin-oob.wasm",
122122
"screenshots/1-writing-app.png",
123123
"screenshots/1-writing-upload.png",
@@ -133,6 +133,8 @@ files! {
133133

134134
#[cfg(test)]
135135
mod tests {
136+
use std::path::{Path, PathBuf};
137+
136138
use super::*;
137139

138140
#[test]
@@ -146,4 +148,45 @@ mod tests {
146148
assert!(get("data\\zoo.csv").is_some());
147149
assert!(get("data\\zoos.csv").is_none());
148150
}
151+
152+
#[test]
153+
fn test_list_sorted() {
154+
for window in FILES.windows(2) {
155+
let (a, _) = window[0];
156+
let (b, _) = window[1];
157+
if a > b {
158+
panic!("{a:?} and {b:?} are out of order");
159+
}
160+
}
161+
}
162+
163+
#[test]
164+
fn test_all_files_included() {
165+
let root = Path::new("files");
166+
walk(root, &mut |path| {
167+
let stringified = path
168+
.strip_prefix(root)
169+
.unwrap()
170+
.to_string_lossy()
171+
.replace(std::path::MAIN_SEPARATOR_STR, "/");
172+
let data = std::fs::read(&path).unwrap();
173+
if get(&stringified) != Some(data.as_slice()) {
174+
panic!("{} is not listed in {}", path.display(), file!());
175+
}
176+
})
177+
}
178+
179+
fn walk(dir: &Path, f: &mut impl FnMut(PathBuf)) {
180+
for entry in std::fs::read_dir(dir).unwrap() {
181+
let path = entry.unwrap().path();
182+
if path.is_dir() {
183+
walk(&path, f);
184+
} else if let Some(stem) = path.file_stem()
185+
&& let Some(stem_str) = stem.to_str()
186+
&& !stem_str.starts_with(".")
187+
{
188+
f(path);
189+
}
190+
}
191+
}
149192
}

0 commit comments

Comments
 (0)