krz/orgo
Lightning fast org-mode static site generator.
clone: git clone https://gitbay.org/krz/orgo.git
1//! End-to-end PARSE → RENDER snapshots for the v0.1 core org subset (spec §5).
2//!
3//! Two layers, per the spec's testing philosophy: an element-tree JSON snapshot
4//! (parser correctness) and a rendered-HTML snapshot (renderer correctness), for
5//! each fixture.
6
7use camino::Utf8PathBuf;
8
9use orgo::model::Document;
10use orgo::parser::parse;
11use orgo::render::{render, Html, SyntectHighlighter};
12use orgo::resolve::ResolvedDoc;
13
14fn parse_fixture(name: &str) -> Document {
15 let path = Utf8PathBuf::from(env!("CARGO_MANIFEST_DIR"))
16 .join("fixtures")
17 .join(name);
18 let source = std::fs::read_to_string(&path).expect("read fixture");
19 // Use a stable relative path so snapshots don't embed an absolute machine path.
20 parse(Utf8PathBuf::from("fixtures").join(name).as_path(), &source).expect("parse fixture")
21}
22
23fn render_fixture(name: &str) -> String {
24 let document = parse_fixture(name);
25 let resolved = ResolvedDoc { document };
26 let Html(html) = render(&resolved, &SyntectHighlighter::new());
27 html
28}
29
30#[test]
31fn minimal_element_tree() {
32 insta::assert_json_snapshot!(parse_fixture("minimal.org").root);
33}
34
35#[test]
36fn minimal_html() {
37 insta::assert_snapshot!(render_fixture("minimal.org"));
38}
39
40#[test]
41fn core_element_tree() {
42 insta::assert_json_snapshot!(parse_fixture("core.org").root);
43}
44
45#[test]
46fn core_html() {
47 insta::assert_snapshot!(render_fixture("core.org"));
48}