diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..dcccff1 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,3 @@ +[env] +# insta writes multi-line snapshot metadata as unquoted literal blocks +INSTA_YAML_BLOCK_STYLE = "1" diff --git a/.gitignore b/.gitignore index ff3c111..482a610 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ pkg/aur/.SRCINFO # dummy dir to test org behaviour toss/ + +# don't commit pending snapshots +*.snap.new diff --git a/README.org b/README.org index c825d14..206e7db 100644 --- a/README.org +++ b/README.org @@ -45,3 +45,32 @@ cargo install org-rust *** Development Refer to the [[./docs][documentation]] for developer-specific information & syntax-progress. + + +** Testing + +The parser and exporter rely on snapshot tests built on [[https://insta.rs/][insta]]. +A snapshot test processes a small input and compares the output against a stored snapshot (~.snap~) in ~crates//snapshots/~. +Parser tests compare against the output ~Parser::render_tree()~ to ensure stability. +Exporter snapshot tests are handled [[https://insta.rs/docs/quickstart/#inline-snapshots][inline]]. + +*** Snapshot workflow + +After making a change, run the tests as usual with ~cargo test --workspace~. +If a snapshot doesn't match (or doesn't exist yet), the test fails and ~insta~ generates a pending snapshot as a ~.snap.new~ file. + +Read the diff to verify correctness. Optionally, [[https://insta.rs/docs/cli/][cargo-insta]] offers a convenience tool for this: + +#+begin_src bash +cargo insta review +#+end_src + +If every change is intended, ~INSTA_UPDATE=always cargo test --workspace~ accepts them all at once, overwriting the stored snapshots directly. + +*** Adding a test + +The snapshot is named after the module path and test name. + +1. Run ~cargo test~. The new test fails and writes a ~.snap.new~. +2. Check, then accept it with ~cargo insta review~ / ~cargo insta accept~ or just do it manually. +3. Re-run ~cargo test~, then commit the new ~.snap~ file. diff --git a/crates/org-exporter/Cargo.toml b/crates/org-exporter/Cargo.toml index d05abc8..2a595b1 100644 --- a/crates/org-exporter/Cargo.toml +++ b/crates/org-exporter/Cargo.toml @@ -19,4 +19,5 @@ phf = {version = "0.11.1", features = ["macros"]} thiserror = "1.0.63" [dev-dependencies] +insta = "1.48.0" pretty_assertions = "1.3.0" diff --git a/crates/org-exporter/src/html.rs b/crates/org-exporter/src/html.rs index 82abefa..071d929 100644 --- a/crates/org-exporter/src/html.rs +++ b/crates/org-exporter/src/html.rs @@ -984,11 +984,7 @@ mod tests { ", ); - assert_eq!( - a, - r"

hiii cool three text

-" - ); + insta::assert_snapshot!(a, @"

hiii cool three text

"); } #[test] @@ -1000,11 +996,7 @@ mod tests { ", ); - assert_eq!( - a, - r"

hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii

-", - ); + insta::assert_snapshot!(a, @"

hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii

"); } #[test] @@ -1014,24 +1006,18 @@ mod tests { ", ); - assert_eq!( - a, - r"

abc -
-

-", - ); + insta::assert_snapshot!(a, @" +

abc +
+

+ "); let n = html_export( r" abc\\ q ", ); - assert_eq!( - n, - r"

abc\\ q

-", - ); + insta::assert_snapshot!(n, @r"

abc\\ q

"); } #[test] @@ -1060,11 +1046,7 @@ mod tests { ", ); - assert_eq!( - nb, - r"

----

-", - ); + insta::assert_snapshot!(nb, @"

----

"); } #[test] @@ -1079,7 +1061,15 @@ abc &+ 10\\ \end{align} ", ); - println!("{a}"); + insta::assert_snapshot!(a, @r#" + + abc+10 + "#); } #[test] @@ -1089,11 +1079,7 @@ abc &+ 10\\ ", ); - assert_eq!( - a, - r"

a é😳

-" - ); + insta::assert_snapshot!(a, @"

a é😳

"); } #[test] @@ -1104,14 +1090,12 @@ abc &+ 10\\ ", ); - assert_eq!( - a, - r#"
    -
  1. wordsss??

    -
  2. -
-"#, - ); + insta::assert_snapshot!(a, @r#" +
    +
  1. wordsss??

    +
  2. +
+ "#); } #[test] fn anon_footnote() { @@ -1121,32 +1105,31 @@ hi [fn:next:coolio] yeah [fn:next] ", ); // just codifying what the output is here, not supposed to be set in stone - assert_eq!( - a, - r##"

hi - 1 - yeah - 1 -

- -
- -

Footnotes

-
- - -
- - 1 - -coolio
-
-
"## - ); + insta::assert_snapshot!(a, @r##" +

hi + 1 + yeah + 1 +

+ +
+ +

Footnotes

+
+ + +
+ + 1 + + coolio
+
+
+ "##); } #[test] @@ -1162,31 +1145,30 @@ hello [fn:1] ); // just codifying what the output is here, not supposed to be set in stone - assert_eq!( - a, - r##"

hello - 1 -

-

Footnotes

- -
- -
- - -
- - 1 - -

world

-
-
-
"## - ); + insta::assert_snapshot!(a, @r##" +

hello + 1 +

+

Footnotes

+ +
+ +
+ + +
+ + 1 + +

world

+
+
+
+ "##); } #[test] @@ -1211,62 +1193,61 @@ novel [fn:next:coolio] // REVIEW; investigate different nodeids with export_buf and export // had to change 1.7 to 1.8 to pass the test - assert_eq!( - a, - r##"

hi - 1 - cool test - 2 - - 1 - coolest - 3 - again - 3 -

-

novel - 4 -

-

Footnotes

- -
- -
- - -
- - 1 - -

abcdef

-
- -
- - 2 - -

words babby

-
- -
- - 3 - -

hi

-
- -
- - 4 - -coolio
-
-
"## - ); + insta::assert_snapshot!(a, @r##" +

hi + 1 + cool test + 2 + + 1 + coolest + 3 + again + 3 +

+

novel + 4 +

+

Footnotes

+ +
+ +
+ + +
+ + 1 + +

abcdef

+
+ +
+ + 2 + +

words babby

+
+ +
+ + 3 + +

hi

+
+ +
+ + 4 + + coolio
+
+
+ "##); } #[test] @@ -1281,51 +1262,46 @@ bad [fn:] ", ); - assert_eq!( - a, - r##"

And anonymous ones - 1 -

-

what - 2 -

-

bad [fn:]

- -
- -

Footnotes

-
- - -
- - 1 - -mysterious
- -
- - 2 - -
-
-
"## - ); + insta::assert_snapshot!(a, @r##" +

And anonymous ones + 1 +

+

what + 2 +

+

bad [fn:]

+ +
+ +

Footnotes

+
+ + +
+ + 1 + + mysterious
+ +
+ + 2 + +
+
+
+ "##); } #[test] fn file_link() { let a = html_export(r"[[file:html.org][hi]]"); - assert_eq!( - a, - r#"

hi

-"# - ); + insta::assert_snapshot!(a, @r#"

hi

"#); } #[test] @@ -1335,13 +1311,11 @@ mysterious [[file:bmc.jpg]] ", ); - assert_eq!( - a, - r#"
-bmc.jpg -
-"# - ); + insta::assert_snapshot!(a, @r#" +
+ bmc.jpg +
+ "#); } #[test] @@ -1352,57 +1326,45 @@ mysterious ", ); - assert_eq!( - a, - r#"
-Org-mode-unicorn.svg -
-"# - ); + insta::assert_snapshot!(a, @r#" +
+ Org-mode-unicorn.svg +
+ "#); } #[test] fn unspecified_link() { let a = html_export(r"[[./hello]]"); - assert_eq!( - a, - r##"

./hello

-"## - ); + insta::assert_snapshot!(a, @r#"

./hello

"#); } #[test] fn checkbox() { let a = html_export("- [X]\n"); - assert_eq!( - a, - r#" -"# - ); + insta::assert_snapshot!(a, @r#" + + "#); let b = html_export("- [ ]\n"); - assert_eq!( - b, - r#" -"# - ); + insta::assert_snapshot!(b, @r#" + + "#); let c = html_export("- [-]\n"); - assert_eq!( - c, - r#" -"# - ); + insta::assert_snapshot!(c, @r#" + + "#); } #[test] @@ -1420,10 +1382,13 @@ content here "#; - assert_eq!( - html_export(a), - "

yeah

\n

hello

\n

hi

\n

content

\n

here

\n" - ); + insta::assert_snapshot!(html_export(a), @r#" +

yeah

+

hello

+

hi

+

content

+

here

+ "#); } #[test] @@ -1433,17 +1398,14 @@ here [[suki.jpg]] "#; - assert_eq!( - html_export(a), - r#"
-
-

yes

-
-suki.jpg -
-"# - ) - } + insta::assert_snapshot!(html_export(a), @r#" +
+
+

yes

+
+ suki.jpg +
+ "#);} #[test] fn tabale_caption() { @@ -1452,21 +1414,18 @@ here |a|b|c "#; - assert_eq!( - html_export(a), - r#" - - - - - - -
-

i am a table

-
abc
-"# - ) - } + insta::assert_snapshot!(html_export(a), @" + + + + + + + +
+

i am a table

+
abc
+ ");} #[test] fn block_src() { @@ -1476,13 +1435,12 @@ here (string-append "hello" name)) #+end_src"#; - assert_eq!( - html_export(org_src), - r#"

-(define hello (name)
-    (string-append "hello" name))
-
-"#); + insta::assert_snapshot!(html_export(org_src), @r#" +

+        (define hello (name)
+            (string-append "hello" name))
+        
+ "#); } #[test] @@ -1493,12 +1451,11 @@ here (string-append "hello" name)) #+end_src"#; - assert_eq!( - html_export(org_src), - r#"

-(define hello (name)
-    (string-append "hello" name))
-
-"#); + insta::assert_snapshot!(html_export(org_src), @r#" +

+        (define hello (name)
+            (string-append "hello" name))
+        
+ "#); } } diff --git a/crates/org-exporter/src/include.rs b/crates/org-exporter/src/include.rs index 5dfa67b..2cf364a 100644 --- a/crates/org-exporter/src/include.rs +++ b/crates/org-exporter/src/include.rs @@ -79,32 +79,33 @@ impl<'a> InclParams<'a> { let is_not_kwarg = |x: &&str| !x.starts_with(':'); - let block: Option = if let Some(potential_block) = params.next_if(is_not_kwarg) { - Some(match potential_block { - "example" => IncludeBlock::Example, - "export" => { - let backend = if let Some(potential_arg) = params.next_if(is_not_kwarg) { - Some(potential_arg) - } else { - // issue warning? - None - }; - IncludeBlock::Export { backend } - } - "src" => { - let lang = if let Some(potential_lang) = params.next_if(is_not_kwarg) { - Some(potential_lang) - } else { - // issue warning? - None - }; - IncludeBlock::Src { lang } - } - _ => Err(IncludeError::UnsupportedBlock(potential_block.into()))?, - }) - } else { - None - }; + let block: Option = + if let Some(potential_block) = params.next_if(is_not_kwarg) { + Some(match potential_block { + "example" => IncludeBlock::Example, + "export" => { + let backend = if let Some(potential_arg) = params.next_if(is_not_kwarg) { + Some(potential_arg) + } else { + // issue warning? + None + }; + IncludeBlock::Export { backend } + } + "src" => { + let lang = if let Some(potential_lang) = params.next_if(is_not_kwarg) { + Some(potential_lang) + } else { + // issue warning? + None + }; + IncludeBlock::Src { lang } + } + _ => Err(IncludeError::UnsupportedBlock(potential_block.into()))?, + }) + } else { + None + }; // defaults for kwargs let mut only_contents = false; diff --git a/crates/org-exporter/src/org.rs b/crates/org-exporter/src/org.rs index f487e3a..c9e737b 100644 --- a/crates/org-exporter/src/org.rs +++ b/crates/org-exporter/src/org.rs @@ -701,13 +701,10 @@ three ", ); - assert_eq!( - out_str, - r"** one two -three *four* - -" - ); + insta::assert_snapshot!(out_str, @" + ** one two + three *four* + "); } #[test] @@ -724,24 +721,22 @@ three *four* ", ); - assert_eq!( - a, - r" -- one two three -four five six + insta::assert_snapshot!(a, @" -- two -- three -- four -+five -" - ); + - one two three + four five six + + - two + - three + - four + +five + "); } #[test] fn test_link_export() { - let out = org_export("[[https://swag.org][meowww]]"); - println!("{out}"); + let out = org_export("[[https://swag.org][self]]"); + insta::assert_snapshot!(out, @"[[https://swag.org][self]]"); } #[test] @@ -880,7 +875,50 @@ more content here this is a pargraph ", ); - println!("{out}"); + insta::assert_snapshot!(out, @" + * DONE [#0] *one* two /three/ /four* :one:two:three:four: + more content here this is a pargraph + ** [#1] descendant headline :five: + *** [#2] inherit the tags + ** [#3] different level + subcontent this more content here this is a pargraph + ** [#1] descendant headline :five: + *** [#2] inherit the tags + ** [#3] different level + subcontent this + + is a different paragraph id) = more subcontent + + * [#4] separate andy + more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph + + is a different paragraph id) = more subcontent + + * [#4] separate andy + more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph + ** [#1] descendant headline :five: + *** [#2] inherit the tags + ** [#3] different level + subcontent this + + is a different paragraph id) = more subcontent + + * [#4] separate andy + more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph + ** [#1] descendant headline :five: + *** [#2] inherit the tags + ** [#3] different level + subcontent this + + is a different paragraph id) = more subcontent + + * [#4] separate andy + more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph + ** a + more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph + * a + more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph more content here this is a pargraph + "); } #[test] @@ -893,15 +931,12 @@ more content here this is a pargraph ", ); - assert_eq!( - out, - r"* [#1] abc :c: -** [#1] descendant headline :a:b: -*** [#2] inherit the tags -** [#3] different level -" - ); - println!("{out}"); + insta::assert_snapshot!(out, @" + * [#1] abc :c: + ** [#1] descendant headline :a:b: + *** [#2] inherit the tags + ** [#3] different level + "); } #[test] @@ -918,19 +953,16 @@ more content here this is a pargraph ", ); - println!("{a}"); - assert_eq!( - a, - r" -- one - - two - - three - - four - - five -- six - - seven -" - ); + insta::assert_snapshot!(a, @" + + - one + - two + - three + - four + - five + - six + - seven + "); } #[test] @@ -948,20 +980,17 @@ more content here this is a pargraph ", ); - println!("{a}"); - assert_eq!( - a, - r" -- one - - two -- three - - four -- five - - six - - seven -- eight -" - ); + insta::assert_snapshot!(a, @" + + - one + - two + - three + - four + - five + - six + - seven + - eight + "); } #[test] @@ -981,8 +1010,6 @@ more content here this is a pargraph ", ); - println!("{a}"); - // TODO: whitespace handling is super janky atm. // can't even test output properly caudse whitespace is inserted into // blanklines, and emacs removes trailing whitespace @@ -1012,15 +1039,13 @@ more content here this is a pargraph ", ); - assert_eq!( - a, - r" -| one | two | | -| three | four | | -| five | six | seven | -| eight | | | -" - ); + insta::assert_snapshot!(a, @" + + | one | two | | + | three | four | | + | five | six | seven | + | eight | | | + "); } #[test] @@ -1038,21 +1063,17 @@ more content here this is a pargraph ", ); - println!("{a}"); - assert_eq!( - a, - r" -| one | two | | | -|-------+--------------+--------+--------+ -| three | four | | | -| five | six | seven | | -| eight | | | | -|-------+--------------+--------+--------+ -| swagg | long the | | | -| okay | _underline_ | ~fake | _fake | -" - ); - // println!("{a}"); + insta::assert_snapshot!(a, @" + + | one | two | | | + |-------+--------------+--------+--------+ + | three | four | | | + | five | six | seven | | + | eight | | | | + |-------+--------------+--------+--------+ + | swagg | long the | | | + | okay | _underline_ | ~fake | _fake | + "); } #[test] @@ -1072,50 +1093,43 @@ more content here this is a pargraph ", ); - assert_eq!( - a, - r" -- zero - | one | two | | | - |-------+--------------+--------+--------+ - | three | four | | | - | five | six | seven | | - | eight | | | | - |-------+--------------+--------+--------+ - | swagg | long the | | | - | okay | _underline_ | ~fake | _fake | -- ten -" - ); + insta::assert_snapshot!(a, @" + + - zero + | one | two | | | + |-------+--------------+--------+--------+ + | three | four | | | + | five | six | seven | | + | eight | | | | + |-------+--------------+--------+--------+ + | swagg | long the | | | + | okay | _underline_ | ~fake | _fake | + - ten + "); } #[test] fn proper_list_indent() { let a = org_export( - r" -- one + r"- one - four - one - two ", ); - assert_eq!( - a, - r" -- one -- four - - one - - two -" - ); + insta::assert_snapshot!(a, @" + - one + - four + - one + - two + "); } #[test] fn heading_list_not() { let a = org_export( - r" -- one + r"- one - four * one ", @@ -1124,104 +1138,65 @@ more content here this is a pargraph // make sure * one is not interpreted as another element of the list, // instead as a separate heading (if it was another element, we'd have three -'s // ) - assert_eq!( - a, - r" -- one -- four -* one -" - ); + insta::assert_snapshot!(a, @" + - one + - four + * one + "); } #[test] fn proper_link() { let a = org_export(r"[[abc][one]]"); - assert_eq!( - a, - r"[[abc][one]] -" - ); + insta::assert_snapshot!(a, @"[[abc][one]]"); } #[test] fn link_odd() { let a = org_export("[aayyyy][one]]"); - assert_eq!( - a, - r"[aayyyy][one]] -" - ); + insta::assert_snapshot!(a, @"[aayyyy][one]]"); } #[test] fn superscript() { let a = org_export(r"sample_text^{\gamma}"); - assert_eq!( - a, - r"sample_{text}^{γ} -" - ); + insta::assert_snapshot!(a, @"sample_{text}^{γ}"); let b = org_export( r"sample_text^bunchoftextnowhite!,lkljas after", ); - assert_eq!( - b, - r"sample_{text}^{bunchoftextnowhite}!,lkljas after -" - ); + insta::assert_snapshot!(b, @"sample_{text}^{bunchoftextnowhite}!,lkljas after"); let c = org_export(r"nowhere ^texto"); - assert_eq!( - c, - r"nowhere ^texto -" - ); + insta::assert_snapshot!(c, @"nowhere ^texto"); } #[test] fn subscript() { let a = org_export(r"sample_text_{\gamma}"); - assert_eq!( - a, - r"sample_{text}_{γ} -" - ); + insta::assert_snapshot!(a, @"sample_{text}_{γ}"); let b = org_export( r"sample_{text}_bunchoftextnowhite!,lkljas after", ); - assert_eq!( - b, - r"sample_{text}_{bunchoftextnowhite}!,lkljas after -" - ); + insta::assert_snapshot!(b, @"sample_{text}_{bunchoftextnowhite}!,lkljas after"); let c = org_export(r"nowhere _texto"); - assert_eq!( - c, - r"nowhere _texto -" - ); + insta::assert_snapshot!(c, @"nowhere _texto"); } #[test] fn plain_link() { let a = org_export("https://cool.com abc rest"); - assert_eq!( - a, - "[[https://cool.com]] abc rest -" - ); + insta::assert_snapshot!(a, @"[[https://cool.com]] abc rest"); } #[test] @@ -1232,15 +1207,14 @@ more content here this is a pargraph ", ); - assert_eq!( - a, - r"- test =if ~literal $interpreters \[handle newline \(properly {{{in(a lists -- text that isn't disappearing! -" - ); + insta::assert_snapshot!(a, @r" + - test =if ~literal $interpreters \[handle newline \(properly {{{in(a lists + - text that isn't disappearing! + "); } #[test] + #[ignore = "known bug: org exporter emits the src block body once per line (5x here)"] fn lblock_plus_list() { let a = org_export( r" @@ -1250,24 +1224,24 @@ more content here this is a pargraph hiiiiiiiiiiiiiiiiiii -meowwwwwwwwww +wow? #+end_src - ", ); - println!("{a}"); + assert_eq!( + a.matches("hiiiiiiiiiiiiiiiiiii").count(), + 1, + "src block body should be emitted once: {a:?}" + ); } #[test] fn markup_enclosed_in_bracks() { let a = org_export(r"[_enclosed text here_]"); - assert_eq!( - a, - "[_enclosed text here_] -" - ); + insta::assert_snapshot!(a, @"[_enclosed text here_]"); } #[test] @@ -1288,23 +1262,20 @@ four :end: ", ); - assert_eq!( - a, - r" -:NAME: + insta::assert_snapshot!(a, @" -*words* + :NAME: -| | | | abcds | + *words* + | | | | abcds | -* abc one two three -four -:end: + * abc one two three -" - ); + four + :end: + "); } } diff --git a/crates/org-exporter/src/utils.rs b/crates/org-exporter/src/utils.rs index 87b9c3e..53d7674 100644 --- a/crates/org-exporter/src/utils.rs +++ b/crates/org-exporter/src/utils.rs @@ -152,7 +152,6 @@ mod tests { #[test] fn test_toc() -> Result<(), Box> { - //TODO: properly test let a = Html::export( r#" @@ -178,7 +177,22 @@ ul { ConfigOptions::default(), ) .unwrap(); - println!("{a}"); + insta::assert_snapshot!(a, @r#" + + + +

swag

+

abc

+

love

+

3

+ "#); Ok(()) } } diff --git a/crates/org-parser/Cargo.toml b/crates/org-parser/Cargo.toml index 48c02d8..2c80447 100644 --- a/crates/org-parser/Cargo.toml +++ b/crates/org-parser/Cargo.toml @@ -21,3 +21,4 @@ regex = "1.9.4" [dev-dependencies] pretty_assertions = "1.3.0" +insta = "1.48.0" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__block__tests__big_greater_block_content.snap b/crates/org-parser/snapshots/org_rust_parser__element__block__tests__big_greater_block_content.snap new file mode 100644 index 0000000..5c7a57a --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__block__tests__big_greater_block_content.snap @@ -0,0 +1,60 @@ +--- +source: crates/org-parser/src/element/block.rs +description: | + + #+begin_quote + + /formatted text? such thing!/ + *abc* + + * headlines too + anything is possible + + blank lines + + #+keyword: one + + #+begin_src rust + let nest = Some() + + if let Some(nested) = nest { + dbg!(meta); + } + + #+end_src + + ** headline :tag:meow: + #+end_quote +--- +0..250 [1, 2, 26] + 0..1 BlankLine + 1..249 Quote { parameters: {}, contents: [3, 4, 10, 11] } + 15..16 BlankLine + 16..52 Paragraph([6, 7, 9]) + 16..45 Italic([5]) + 17..44 "formatted text? such thing!" + 45..46 SoftBreak + 46..51 Bold([8]) + 47..50 "abc" + 52..53 BlankLine + 53..238 Heading { heading_level: One, keyword: None, priority: None, title: Some(("headlines too\n", [12])), tags: None, properties: None, children: Some([13, 14, 16, 17, 19, 20, 21, 22, 23, 24]) } + 55..68 "headlines too" + 69..90 Paragraph([15]) + 69..89 "anything is possible" + 90..91 BlankLine + 91..103 Paragraph([18]) + 91..102 "blank lines" + 103..104 BlankLine + 104..119 Keyword { key: "keyword", val: "one" } + 119..120 BlankLine + 120..213 Src { language: Some("rust"), parameters: {}, contents: "let nest = Some()\n\nif let Some(nested) = nest {\n dbg!(meta);\n}\n\n" } + 213..214 BlankLine + 214..215 BlankLine + 215..238 Heading { heading_level: Two, keyword: None, priority: None, title: Some(("headline", [25])), tags: Some([Raw("meow"), Raw("tag"), Loc(11)]), properties: None, children: None } + 218..226 "headline" + 249..250 BlankLine +targets: + "headline" -> "headline" + "headlines too\n" -> "headlines-too" +keywords: + "keyword" = "one" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__block__tests__gblock_plus_list.snap b/crates/org-parser/snapshots/org_rust_parser__element__block__tests__gblock_plus_list.snap new file mode 100644 index 0000000..818b00b --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__block__tests__gblock_plus_list.snap @@ -0,0 +1,20 @@ +--- +source: crates/org-parser/src/element/block.rs +description: | + + - a + #+begin_quote + hiiiiiiiiiiiiiiiiiii + #+end_quote + - +--- +0..60 [1, 10] + 0..1 BlankLine + 1..60 PlainList { children: [2, 9], kind: Unordered } + 1..58 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [3, 4] } + 3..5 Paragraph([7]) + 3..4 "a" + 8..57 Quote { parameters: {}, contents: [5] } + 22..43 Paragraph([6]) + 22..42 "hiiiiiiiiiiiiiiiiiii" + 58..60 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [] } diff --git a/crates/org-parser/snapshots/org_rust_parser__element__block__tests__greater_block_indented.snap b/crates/org-parser/snapshots/org_rust_parser__element__block__tests__greater_block_indented.snap new file mode 100644 index 0000000..701e1bc --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__block__tests__greater_block_indented.snap @@ -0,0 +1,14 @@ +--- +source: crates/org-parser/src/element/block.rs +description: | + + #+begin_swag + we are eating so good? + #+end_swag +--- +0..87 [1, 2, 5] + 0..1 BlankLine + 14..86 Special { parameters: {}, contents: [3], name: "swag" } + 40..63 Paragraph([4]) + 40..62 "we are eating so good?" + 86..87 BlankLine diff --git a/crates/org-parser/snapshots/org_rust_parser__element__drawer__tests__basic_drawer.snap b/crates/org-parser/snapshots/org_rust_parser__element__drawer__tests__basic_drawer.snap new file mode 100644 index 0000000..c21be25 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__drawer__tests__basic_drawer.snap @@ -0,0 +1,21 @@ +--- +source: crates/org-parser/src/element/drawer.rs +description: | + + + :NAME: + hello + :end: + + halloo +--- +0..29 [1, 2, 3, 6, 7, 8] + 0..1 BlankLine + 1..2 BlankLine + 2..20 Drawer { children: [4], name: "NAME" } + 9..15 Paragraph([5]) + 9..14 "hello" + 20..21 BlankLine + 21..22 BlankLine + 22..29 Paragraph([9]) + 22..28 "halloo" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__drawer__tests__basic_drawer_caps.snap b/crates/org-parser/snapshots/org_rust_parser__element__drawer__tests__basic_drawer_caps.snap new file mode 100644 index 0000000..ea11021 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__drawer__tests__basic_drawer_caps.snap @@ -0,0 +1,21 @@ +--- +source: crates/org-parser/src/element/drawer.rs +description: | + + + :NAME: + hello + :END: + + halloo +--- +0..29 [1, 2, 3, 6, 7, 8] + 0..1 BlankLine + 1..2 BlankLine + 2..20 Drawer { children: [4], name: "NAME" } + 9..15 Paragraph([5]) + 9..14 "hello" + 20..21 BlankLine + 21..22 BlankLine + 22..29 Paragraph([9]) + 22..28 "halloo" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__heading__tests__headline_everything.snap b/crates/org-parser/snapshots/org_rust_parser__element__heading__tests__headline_everything.snap new file mode 100644 index 0000000..e7a9b34 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__heading__tests__headline_everything.snap @@ -0,0 +1,54 @@ +--- +source: crates/org-parser/src/element/heading.rs +description: | + * DONE [#0] *one* two /three/ /four* :one:two:three:four: + more content here this is a pargraph + ** [#1] descendant headline :five: + *** [#2] inherit the tags + ** [#3] different level + subcontent + this + + is a different paragraph + id) = + more subcontent + + * [#4] separate andy +--- +0..272 [1, 28] + 0..251 Heading { heading_level: One, keyword: Some("DONE"), priority: Some(Num(0)), title: Some(("*one* two /three/ /four*", [3, 6, 5, 8, 7])), tags: Some([Raw("four"), Raw("three"), Raw("two"), Raw("one")]), properties: None, children: Some([9, 10, 14]) } + 12..17 Bold([2]) + 13..16 "one" + 17..22 " two " + 22..29 Italic([4]) + 23..28 "three" + 29..31 " /" + 31..36 "four*" + 64..101 Paragraph([30]) + 64..100 "more content here this is a pargraph" + 101..162 Heading { heading_level: Two, keyword: None, priority: Some(Num(1)), title: Some(("descendant headline", [11])), tags: Some([Raw("five"), Loc(1)]), properties: None, children: Some([12]) } + 109..128 "descendant headline" + 136..162 Heading { heading_level: Three, keyword: None, priority: Some(Num(2)), title: Some(("inherit the tags\n", [13])), tags: Some([Loc(10)]), properties: None, children: None } + 145..161 "inherit the tags" + 162..251 Heading { heading_level: Two, keyword: None, priority: Some(Num(3)), title: Some(("different level\n", [15])), tags: Some([Loc(1)]), properties: None, children: Some([16, 19, 21, 26]) } + 170..185 "different level" + 186..202 Paragraph([18, 17, 20]) + 186..196 "subcontent" + 196..197 SoftBreak + 197..201 "this" + 202..203 BlankLine + 203..250 Paragraph([23, 22, 25, 24, 27]) + 203..227 "is a different paragraph" + 227..228 SoftBreak + 228..233 "id) =" + 233..234 SoftBreak + 234..249 "more subcontent" + 250..251 BlankLine + 251..272 Heading { heading_level: One, keyword: None, priority: Some(Num(4)), title: Some(("separate andy\n", [29])), tags: None, properties: None, children: None } + 258..271 "separate andy" +targets: + "*one* two /three/ /four*" -> "one-two-three-four" + "descendant headline" -> "descendant-headline" + "different level\n" -> "different-level" + "inherit the tags\n" -> "inherit-the-tags" + "separate andy\n" -> "separate-andy" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__heading__tests__headline_prio_keyword_decorated_title.snap b/crates/org-parser/snapshots/org_rust_parser__element__heading__tests__headline_prio_keyword_decorated_title.snap new file mode 100644 index 0000000..50105d1 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__heading__tests__headline_prio_keyword_decorated_title.snap @@ -0,0 +1,16 @@ +--- +source: crates/org-parser/src/element/heading.rs +description: | + * TODO [#A] *one* two /three/ /four* +--- +0..38 [1] + 0..38 Heading { heading_level: One, keyword: Some("TODO"), priority: Some(A), title: Some(("*one* two /three/ /four* \n", [3, 6, 5, 8, 7])), tags: None, properties: None, children: None } + 12..17 Bold([2]) + 13..16 "one" + 17..22 " two " + 22..29 Italic([4]) + 23..28 "three" + 29..31 " /" + 31..37 "four* " +targets: + "*one* two /three/ /four* \n" -> "one-two-three-four-" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__heading__tests__headline_prio_keyword_title.snap b/crates/org-parser/snapshots/org_rust_parser__element__heading__tests__headline_prio_keyword_title.snap new file mode 100644 index 0000000..6a01a31 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__heading__tests__headline_prio_keyword_title.snap @@ -0,0 +1,10 @@ +--- +source: crates/org-parser/src/element/heading.rs +description: | + * TODO [#A] SWAG +--- +0..18 [1] + 0..18 Heading { heading_level: One, keyword: Some("TODO"), priority: Some(A), title: Some(("SWAG \n", [2])), tags: None, properties: None, children: None } + 12..17 "SWAG " +targets: + "SWAG \n" -> "swag-" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__heading__tests__tag_parse.snap b/crates/org-parser/snapshots/org_rust_parser__element__heading__tests__tag_parse.snap new file mode 100644 index 0000000..a3a896d --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__heading__tests__tag_parse.snap @@ -0,0 +1,20 @@ +--- +source: crates/org-parser/src/element/heading.rs +description: |- + + * q ac:qbc: + qqqqq + + aaaa +--- +0..25 [1, 2] + 0..1 BlankLine + 1..25 Heading { heading_level: One, keyword: None, priority: None, title: Some(("q ac:qbc:\n", [3])), tags: None, properties: None, children: Some([4, 5, 7]) } + 3..12 "q ac:qbc:" + 13..19 Paragraph([6]) + 13..18 "qqqqq" + 19..20 BlankLine + 20..25 Paragraph([8]) + 20..24 "aaaa" +targets: + "q ac:qbc:\n" -> "q-acqbc" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__basic_latex_env.snap b/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__basic_latex_env.snap new file mode 100644 index 0000000..22d26f1 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__basic_latex_env.snap @@ -0,0 +1,13 @@ +--- +source: crates/org-parser/src/element/latex_env.rs +description: | + + \begin{align*} + \end{align*} +--- +0..29 [1, 2] + 0..1 BlankLine + 1..29 Paragraph([3, 4, 5]) + 1..15 Command { name: "begin", contents: Some("align*") } + 15..16 SoftBreak + 16..28 Command { name: "end", contents: Some("align*") } diff --git a/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__latex_empty_start.snap b/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__latex_empty_start.snap new file mode 100644 index 0000000..9ee37b1 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__latex_empty_start.snap @@ -0,0 +1,11 @@ +--- +source: crates/org-parser/src/element/latex_env.rs +description: | + + \begin{} + \end{} +--- +0..17 [1, 2, 3] + 0..1 BlankLine + 1..16 LatexEnv { name: "", contents: "" } + 16..17 BlankLine diff --git a/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__latex_env_failed_header-2.snap b/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__latex_env_failed_header-2.snap new file mode 100644 index 0000000..3be177e --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__latex_env_failed_header-2.snap @@ -0,0 +1,13 @@ +--- +source: crates/org-parser/src/element/latex_env.rs +description: | + + \begin{a13214-} + \end{a13214-} +--- +0..31 [1, 2] + 0..1 BlankLine + 1..31 Paragraph([3, 4, 5]) + 1..16 Command { name: "begin", contents: Some("a13214-") } + 16..17 SoftBreak + 17..30 Command { name: "end", contents: Some("a13214-") } diff --git a/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__latex_env_failed_header-3.snap b/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__latex_env_failed_header-3.snap new file mode 100644 index 0000000..31b6729 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__latex_env_failed_header-3.snap @@ -0,0 +1,14 @@ +--- +source: crates/org-parser/src/element/latex_env.rs +description: | + + \begin{one}more stuff + \end{one} +--- +0..33 [1, 2] + 0..1 BlankLine + 1..33 Paragraph([3, 5, 4, 6]) + 1..12 Command { name: "begin", contents: Some("one") } + 12..22 "more stuff" + 22..23 SoftBreak + 23..32 Command { name: "end", contents: Some("one") } diff --git a/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__latex_env_failed_header.snap b/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__latex_env_failed_header.snap new file mode 100644 index 0000000..2de2624 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__latex_env_failed_header.snap @@ -0,0 +1,13 @@ +--- +source: crates/org-parser/src/element/latex_env.rs +description: | + + \begin{star!} + \end{star!} +--- +0..27 [1, 2] + 0..1 BlankLine + 1..27 Paragraph([3, 4, 5]) + 1..14 Command { name: "begin", contents: Some("star!") } + 14..15 SoftBreak + 15..26 Command { name: "end", contents: Some("star!") } diff --git a/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__latex_env_with_content.snap b/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__latex_env_with_content.snap new file mode 100644 index 0000000..86495fe --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__latex_env_with_content.snap @@ -0,0 +1,31 @@ +--- +source: crates/org-parser/src/element/latex_env.rs +description: | + + \begin{align*} + + \text{latex constructs}\\ + \alpha\\ + \beta\\ + + 10x + 4 &= 3\\ + + \end{align*} +--- +0..90 [1, 2, 4, 5] + 0..1 BlankLine + 1..16 Paragraph([3]) + 1..15 Command { name: "begin", contents: Some("align*") } + 16..17 BlankLine + 17..90 Paragraph([6, 7, 8, 9, 10, 11, 12, 14, 13, 15, 16]) + 17..40 Command { name: "text", contents: Some("latex constructs") } + 40..43 LineBreak + 43..49 Entity { name: "alpha", mapped_item: "α" } + 49..52 LineBreak + 52..57 Entity { name: "beta", mapped_item: "β" } + 57..60 LineBreak + 60..61 SoftBreak + 61..73 "10x + 4 &= 3" + 73..76 LineBreak + 76..77 SoftBreak + 77..89 Command { name: "end", contents: Some("align*") } diff --git a/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__latex_failed_end.snap b/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__latex_failed_end.snap new file mode 100644 index 0000000..8978461 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__latex_env__tests__latex_failed_end.snap @@ -0,0 +1,13 @@ +--- +source: crates/org-parser/src/element/latex_env.rs +description: | + + \begin{start} + \end{notstart} +--- +0..30 [1, 2] + 0..1 BlankLine + 1..30 Paragraph([3, 4, 5]) + 1..14 Command { name: "begin", contents: Some("start") } + 14..15 SoftBreak + 15..29 Command { name: "end", contents: Some("notstart") } diff --git a/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__basic_list.snap b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__basic_list.snap new file mode 100644 index 0000000..8c0d2d3 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__basic_list.snap @@ -0,0 +1,12 @@ +--- +source: crates/org-parser/src/element/plain_list.rs +description: | + + - one +--- +0..7 [1, 5] + 0..1 BlankLine + 1..7 PlainList { children: [2], kind: Unordered } + 1..7 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [3] } + 3..7 Paragraph([4]) + 3..6 "one" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__blank_list.snap b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__blank_list.snap new file mode 100644 index 0000000..be00d51 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__blank_list.snap @@ -0,0 +1,36 @@ +--- +source: crates/org-parser/src/element/plain_list.rs +description: | + 1. item 1 + abcdef + + next one two three four five + + more thangs more thangs more thangs + more thangs + + 2. [X] item 2 + - aome tag :: item 2.1 +--- +0..149 [22] + 0..149 PlainList { children: [1, 15], kind: Ordered(Number(1)) } + 0..109 Item { bullet: Ordered(Number(1)), counter_set: None, check_box: None, tag: None, children: [2, 5, 7, 8, 10] } + 3..20 Paragraph([4, 3, 6]) + 3..9 "item 1" + 9..10 SoftBreak + 10..19 " abcdef" + 20..21 BlankLine + 24..53 Paragraph([9]) + 24..52 "next one two three four five" + 53..54 BlankLine + 57..108 Paragraph([12, 11, 14]) + 57..92 "more thangs more thangs more thangs" + 92..93 SoftBreak + 93..107 " more thangs" + 109..149 Item { bullet: Ordered(Number(2)), counter_set: None, check_box: Some(On), tag: None, children: [16, 20] } + 116..123 Paragraph([21]) + 116..122 "item 2" + 126..149 PlainList { children: [17], kind: Descriptive } + 126..149 Item { bullet: Unordered, counter_set: None, check_box: None, tag: Some("aome tag"), children: [18] } + 140..149 Paragraph([19]) + 140..148 "item 2.1" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__combined_list.snap b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__combined_list.snap new file mode 100644 index 0000000..8ede812 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__combined_list.snap @@ -0,0 +1,20 @@ +--- +source: crates/org-parser/src/element/plain_list.rs +description: | + + - zero + - one + + a* +--- +0..18 [1, 9, 10] + 0..1 BlankLine + 1..15 PlainList { children: [2, 4], kind: Unordered } + 1..8 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [3] } + 3..8 Paragraph([8]) + 3..7 "zero" + 8..15 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [5] } + 10..14 Paragraph([7]) + 10..13 "one" + 15..18 Paragraph([11]) + 15..17 "a*" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__indent_list_prop.snap b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__indent_list_prop.snap new file mode 100644 index 0000000..77f1645 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__indent_list_prop.snap @@ -0,0 +1,28 @@ +--- +source: crates/org-parser/src/element/plain_list.rs +description: | + + - one + - two + - qq + + + heyy +--- +0..28 [1, 14, 8, 10, 15] + 0..1 BlankLine + 1..20 PlainList { children: [2, 4], kind: Unordered } + 1..7 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [3] } + 3..7 Paragraph([13]) + 3..6 "one" + 7..20 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [5, 11] } + 9..13 Paragraph([12]) + 9..12 "two" + 15..20 PlainList { children: [6], kind: Unordered } + 15..20 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [7] } + 17..20 Paragraph([9]) + 17..19 "qq" + 20..21 BlankLine + 21..22 BlankLine + 23..28 Paragraph([16]) + 23..27 "heyy" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_contained_elements.snap b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_contained_elements.snap new file mode 100644 index 0000000..2b9b050 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_contained_elements.snap @@ -0,0 +1,30 @@ +--- +source: crates/org-parser/src/element/plain_list.rs +description: | + + - one + abcd + eif + #+begin_example + we are eating so good? + #+end_example + + - two +--- +0..94 [1, 12, 10, 11, 16] + 0..1 BlankLine + 1..86 PlainList { children: [2], kind: Unordered } + 1..86 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [3, 8] } + 3..28 Paragraph([5, 4, 7, 6, 9]) + 3..6 "one" + 6..7 SoftBreak + 7..17 " abcd" + 17..18 SoftBreak + 18..27 " eif" + 30..86 Example { parameters: {}, contents: " we are eating so good?\n" } + 86..87 BlankLine + 87..88 BlankLine + 88..94 PlainList { children: [13], kind: Unordered } + 88..94 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [14] } + 90..94 Paragraph([15]) + 90..93 "two" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_continued_item.snap b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_continued_item.snap new file mode 100644 index 0000000..51c702b --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_continued_item.snap @@ -0,0 +1,19 @@ +--- +source: crates/org-parser/src/element/plain_list.rs +description: | + + - one + abcdef + - two +--- +0..21 [1, 10] + 0..1 BlankLine + 1..21 PlainList { children: [2, 6], kind: Unordered } + 1..15 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [3] } + 3..15 Paragraph([5, 4, 9]) + 3..6 "one" + 6..7 SoftBreak + 7..14 " abcdef" + 15..21 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [7] } + 17..21 Paragraph([8]) + 17..20 "two" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_elements_breaking_flow.snap b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_elements_breaking_flow.snap new file mode 100644 index 0000000..10582f5 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_elements_breaking_flow.snap @@ -0,0 +1,36 @@ +--- +source: crates/org-parser/src/element/plain_list.rs +description: | + + - one + abcdef + - four + this aint a list baby + #+begin_src python + not a list too + #+end_src + + + - five +--- +0..97 [1, 10, 11, 12, 14, 15, 16, 20] + 0..1 BlankLine + 1..22 PlainList { children: [2, 6], kind: Unordered } + 1..15 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [3] } + 3..15 Paragraph([5, 4, 9]) + 3..6 "one" + 6..7 SoftBreak + 7..14 " abcdef" + 15..22 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [7] } + 17..22 Paragraph([8]) + 17..21 "four" + 22..44 Paragraph([13]) + 22..43 "this aint a list baby" + 44..87 Src { language: Some("python"), parameters: {}, contents: "not a list too\n" } + 87..88 BlankLine + 88..89 BlankLine + 89..90 BlankLine + 90..97 PlainList { children: [17], kind: Unordered } + 90..97 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [18] } + 92..97 Paragraph([19]) + 92..96 "five" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_empty.snap b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_empty.snap new file mode 100644 index 0000000..e9b36dd --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_empty.snap @@ -0,0 +1,16 @@ +--- +source: crates/org-parser/src/element/plain_list.rs +description: | + + - + - + - + - +--- +0..9 [1, 6] + 0..1 BlankLine + 1..9 PlainList { children: [2, 3, 4, 5], kind: Unordered } + 1..3 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [] } + 3..5 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [] } + 5..7 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [] } + 7..9 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [] } diff --git a/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_inconsistent_types.snap b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_inconsistent_types.snap new file mode 100644 index 0000000..84b3691 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_inconsistent_types.snap @@ -0,0 +1,37 @@ +--- +source: crates/org-parser/src/element/plain_list.rs +description: | + + - one + abcdef + 1. two + 2. three + 3. four + - five + - six +--- +0..52 [1, 22, 24, 26] + 0..1 BlankLine + 1..15 PlainList { children: [2], kind: Unordered } + 1..15 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [3] } + 3..15 Paragraph([5, 4, 21]) + 3..6 "one" + 6..7 SoftBreak + 7..14 " abcdef" + 15..39 PlainList { children: [23, 8, 10], kind: Ordered(Number(1)) } + 15..22 Item { bullet: Ordered(Number(1)), counter_set: None, check_box: None, tag: None, children: [7] } + 18..22 Paragraph([20]) + 18..21 "two" + 22..31 Item { bullet: Ordered(Number(2)), counter_set: None, check_box: None, tag: None, children: [9] } + 25..31 Paragraph([19]) + 25..30 "three" + 31..39 Item { bullet: Ordered(Number(3)), counter_set: None, check_box: None, tag: None, children: [11] } + 34..39 Paragraph([18]) + 34..38 "four" + 39..52 PlainList { children: [25, 14], kind: Unordered } + 39..46 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [13] } + 41..46 Paragraph([17]) + 41..45 "five" + 46..52 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [15] } + 48..52 Paragraph([16]) + 48..51 "six" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_no_item_with_sub_element.snap b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_no_item_with_sub_element.snap new file mode 100644 index 0000000..a9591a7 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_no_item_with_sub_element.snap @@ -0,0 +1,23 @@ +--- +source: crates/org-parser/src/element/plain_list.rs +description: |+ + - [X] + |a|a|a|a| + + - + +--- +0..28 [15] + 0..28 PlainList { children: [1, 13], kind: Unordered } + 0..25 Item { bullet: Unordered, counter_set: None, check_box: Some(On), tag: None, children: [2] } + 14..24 Table { rows: 1, cols: 4, children: [11], caption: None } + 14..24 Standard([4, 6, 8, 10]) + 15..17 TableCell([3]) + 15..16 "a" + 17..19 TableCell([5]) + 17..18 "a" + 19..21 TableCell([7]) + 19..20 "a" + 21..23 TableCell([9]) + 21..22 "a" + 25..28 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [] } diff --git a/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_numbered_empty.snap b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_numbered_empty.snap new file mode 100644 index 0000000..21e66c0 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_numbered_empty.snap @@ -0,0 +1,16 @@ +--- +source: crates/org-parser/src/element/plain_list.rs +description: | + + 1. + 2. + 3. + 4. +--- +0..13 [1, 6] + 0..1 BlankLine + 1..13 PlainList { children: [2, 3, 4, 5], kind: Ordered(Number(1)) } + 1..4 Item { bullet: Ordered(Number(1)), counter_set: None, check_box: None, tag: None, children: [] } + 4..7 Item { bullet: Ordered(Number(2)), counter_set: None, check_box: None, tag: None, children: [] } + 7..10 Item { bullet: Ordered(Number(3)), counter_set: None, check_box: None, tag: None, children: [] } + 10..13 Item { bullet: Ordered(Number(4)), counter_set: None, check_box: None, tag: None, children: [] } diff --git a/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_space_ending.snap b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_space_ending.snap new file mode 100644 index 0000000..ba50ca0 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_space_ending.snap @@ -0,0 +1,36 @@ +--- +source: crates/org-parser/src/element/plain_list.rs +description: | + + - one + abcdef + - two + - three + - four + + + - five +--- +0..45 [1, 18, 12, 14, 22] + 0..1 BlankLine + 1..36 PlainList { children: [2, 6, 8, 10], kind: Unordered } + 1..15 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [3] } + 3..15 Paragraph([5, 4, 17]) + 3..6 "one" + 6..7 SoftBreak + 7..14 " abcdef" + 15..21 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [7] } + 17..21 Paragraph([16]) + 17..20 "two" + 21..29 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [9] } + 23..29 Paragraph([15]) + 23..28 "three" + 29..36 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [11] } + 31..36 Paragraph([13]) + 31..35 "four" + 36..37 BlankLine + 37..38 BlankLine + 38..45 PlainList { children: [19], kind: Unordered } + 38..45 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [20] } + 40..45 Paragraph([21]) + 40..44 "five" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_two_items.snap b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_two_items.snap new file mode 100644 index 0000000..df497e1 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__list_two_items.snap @@ -0,0 +1,16 @@ +--- +source: crates/org-parser/src/element/plain_list.rs +description: | + + - one + - two +--- +0..13 [1, 8] + 0..1 BlankLine + 1..13 PlainList { children: [2, 4], kind: Unordered } + 1..7 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [3] } + 3..7 Paragraph([7]) + 3..6 "one" + 7..13 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [5] } + 9..13 Paragraph([6]) + 9..12 "two" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__nested_list_2.snap b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__nested_list_2.snap new file mode 100644 index 0000000..86f7bc9 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__nested_list_2.snap @@ -0,0 +1,31 @@ +--- +source: crates/org-parser/src/element/plain_list.rs +description: | + + - one + - two + - three + - four + - five +--- +0..44 [1, 20] + 0..1 BlankLine + 1..44 PlainList { children: [2, 17], kind: Unordered } + 1..37 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [3, 15] } + 3..7 Paragraph([16]) + 3..6 "one" + 9..37 PlainList { children: [4], kind: Unordered } + 9..37 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [5, 9, 14] } + 11..15 Paragraph([10]) + 11..14 "two" + 19..27 PlainList { children: [6], kind: Unordered } + 19..27 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [7] } + 21..27 Paragraph([8]) + 21..26 "three" + 30..37 PlainList { children: [11], kind: Unordered } + 30..37 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [12] } + 32..37 Paragraph([13]) + 32..36 "four" + 37..44 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [18] } + 39..44 Paragraph([19]) + 39..43 "five" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__nested_list_3.snap b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__nested_list_3.snap new file mode 100644 index 0000000..ca14089 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__nested_list_3.snap @@ -0,0 +1,30 @@ +--- +source: crates/org-parser/src/element/plain_list.rs +description: | + + - one + - two + - three + - four + - five +--- +0..43 [1, 19] + 0..1 BlankLine + 1..43 PlainList { children: [2, 16], kind: Unordered } + 1..36 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [3, 14] } + 3..7 Paragraph([15]) + 3..6 "one" + 9..36 PlainList { children: [4, 11], kind: Unordered } + 9..27 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [5, 9] } + 11..15 Paragraph([10]) + 11..14 "two" + 19..27 PlainList { children: [6], kind: Unordered } + 19..27 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [7] } + 21..27 Paragraph([8]) + 21..26 "three" + 29..36 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [12] } + 31..36 Paragraph([13]) + 31..35 "four" + 36..43 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [17] } + 38..43 Paragraph([18]) + 38..42 "five" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__nested_list_4.snap b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__nested_list_4.snap new file mode 100644 index 0000000..9a223fc --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__nested_list_4.snap @@ -0,0 +1,21 @@ +--- +source: crates/org-parser/src/element/plain_list.rs +description: | + + 1. item 1 + 2. [X] item 2 + - some tag :: item 2.1 +--- +0..51 [1, 12] + 0..1 BlankLine + 1..51 PlainList { children: [2, 4], kind: Ordered(Number(1)) } + 1..11 Item { bullet: Ordered(Number(1)), counter_set: None, check_box: None, tag: None, children: [3] } + 4..11 Paragraph([11]) + 4..10 "item 1" + 11..51 Item { bullet: Ordered(Number(2)), counter_set: None, check_box: Some(On), tag: None, children: [5, 9] } + 18..25 Paragraph([10]) + 18..24 "item 2" + 28..51 PlainList { children: [6], kind: Descriptive } + 28..51 Item { bullet: Unordered, counter_set: None, check_box: None, tag: Some("some tag"), children: [7] } + 42..51 Paragraph([8]) + 42..50 "item 2.1" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__nested_lists_basic.snap b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__nested_lists_basic.snap new file mode 100644 index 0000000..93d2cb9 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__plain_list__tests__nested_lists_basic.snap @@ -0,0 +1,21 @@ +--- +source: crates/org-parser/src/element/plain_list.rs +description: | + + - one + - two + - three +--- +0..22 [1, 12] + 0..1 BlankLine + 1..22 PlainList { children: [2, 9], kind: Unordered } + 1..14 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [3, 7] } + 3..7 Paragraph([8]) + 3..6 "one" + 8..14 PlainList { children: [4], kind: Unordered } + 8..14 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [5] } + 10..14 Paragraph([6]) + 10..13 "two" + 14..22 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [10] } + 16..22 Paragraph([11]) + 16..21 "three" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__table__tests__basic_table.snap b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__basic_table.snap new file mode 100644 index 0000000..70bcb6b --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__basic_table.snap @@ -0,0 +1,20 @@ +--- +source: crates/org-parser/src/element/table.rs +description: | + + |one|two| + |three|four| +--- +0..24 [1, 2] + 0..1 BlankLine + 1..24 Table { rows: 2, cols: 2, children: [7, 12], caption: None } + 1..11 Standard([4, 6]) + 2..6 TableCell([3]) + 2..5 "one" + 6..10 TableCell([5]) + 6..9 "two" + 11..24 Standard([9, 11]) + 12..18 TableCell([8]) + 12..17 "three" + 18..23 TableCell([10]) + 18..22 "four" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_aligned_cells.snap b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_aligned_cells.snap new file mode 100644 index 0000000..f682c47 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_aligned_cells.snap @@ -0,0 +1,19 @@ +--- +source: crates/org-parser/src/element/table.rs +description: | + + |one two |three| + |s | | +--- +0..35 [1, 2] + 0..1 BlankLine + 1..35 Table { rows: 2, cols: 2, children: [7, 12], caption: None } + 1..18 Standard([4, 6]) + 2..11 TableCell([3]) + 2..10 "one two" + 11..17 TableCell([5]) + 11..16 "three" + 18..35 Standard([9, 11]) + 19..28 TableCell([8]) + 19..27 "s" + 28..34 TableCell([]) diff --git a/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_empty_cells.snap b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_empty_cells.snap new file mode 100644 index 0000000..440a854 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_empty_cells.snap @@ -0,0 +1,18 @@ +--- +source: crates/org-parser/src/element/table.rs +description: | + + ||a| + |b|| +--- +0..11 [1, 2] + 0..1 BlankLine + 1..11 Table { rows: 2, cols: 2, children: [6, 10], caption: None } + 1..6 Standard([3, 5]) + 2..3 TableCell([]) + 3..5 TableCell([4]) + 3..4 "a" + 6..11 Standard([8, 9]) + 7..9 TableCell([7]) + 7..8 "b" + 9..10 TableCell([]) diff --git a/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_eof_1.snap b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_eof_1.snap new file mode 100644 index 0000000..70bcb6b --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_eof_1.snap @@ -0,0 +1,20 @@ +--- +source: crates/org-parser/src/element/table.rs +description: | + + |one|two| + |three|four| +--- +0..24 [1, 2] + 0..1 BlankLine + 1..24 Table { rows: 2, cols: 2, children: [7, 12], caption: None } + 1..11 Standard([4, 6]) + 2..6 TableCell([3]) + 2..5 "one" + 6..10 TableCell([5]) + 6..9 "two" + 11..24 Standard([9, 11]) + 12..18 TableCell([8]) + 12..17 "three" + 18..23 TableCell([10]) + 18..22 "four" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_eof_2.snap b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_eof_2.snap new file mode 100644 index 0000000..972c8bb --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_eof_2.snap @@ -0,0 +1,20 @@ +--- +source: crates/org-parser/src/element/table.rs +description: |- + + |one|two| + |three|four| +--- +0..23 [1, 2] + 0..1 BlankLine + 1..23 Table { rows: 2, cols: 2, children: [7, 12], caption: None } + 1..11 Standard([4, 6]) + 2..6 TableCell([3]) + 2..5 "one" + 6..10 TableCell([5]) + 6..9 "two" + 11..23 Standard([9, 11]) + 12..18 TableCell([8]) + 12..17 "three" + 18..23 TableCell([10]) + 18..22 "four" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_indented.snap b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_indented.snap new file mode 100644 index 0000000..69acb2a --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_indented.snap @@ -0,0 +1,33 @@ +--- +source: crates/org-parser/src/element/table.rs +description: |+ + + word + |one two |three| + |s | | + |four | five| + word + +--- +0..84 [1, 2, 3, 20, 21] + 0..1 BlankLine + 1..6 Paragraph([19]) + 1..5 "word" + 14..78 Table { rows: 3, cols: 2, children: [8, 13, 18], caption: None } + 14..31 Standard([5, 7]) + 15..24 TableCell([4]) + 15..23 "one two" + 24..30 TableCell([6]) + 24..29 "three" + 31..56 Standard([10, 12]) + 40..49 TableCell([9]) + 40..48 "s" + 49..55 TableCell([]) + 56..78 Standard([15, 17]) + 65..71 TableCell([14]) + 65..70 "four" + 71..77 TableCell([16]) + 71..76 " five" + 78..83 Paragraph([22]) + 78..82 "word" + 83..84 BlankLine diff --git a/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_indented_list.snap b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_indented_list.snap new file mode 100644 index 0000000..a4d4284 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_indented_list.snap @@ -0,0 +1,39 @@ +--- +source: crates/org-parser/src/element/table.rs +description: | + + - one + - two + |one two |three| + |s | | + |four | five| + - three +--- +0..96 [1, 28] + 0..1 BlankLine + 1..96 PlainList { children: [2, 25], kind: Unordered } + 1..88 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [3, 23] } + 3..7 Paragraph([24]) + 3..6 "one" + 10..88 PlainList { children: [4], kind: Unordered } + 10..88 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [5, 6] } + 12..16 Paragraph([22]) + 12..15 "two" + 24..88 Table { rows: 3, cols: 2, children: [11, 16, 21], caption: None } + 24..41 Standard([8, 10]) + 25..34 TableCell([7]) + 25..33 "one two" + 34..40 TableCell([9]) + 34..39 "three" + 41..66 Standard([13, 15]) + 50..59 TableCell([12]) + 50..58 "s" + 59..65 TableCell([]) + 66..88 Standard([18, 20]) + 75..81 TableCell([17]) + 75..80 "four" + 81..87 TableCell([19]) + 81..86 " five" + 88..96 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [26] } + 90..96 Paragraph([27]) + 90..95 "three" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_markup_1.snap b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_markup_1.snap new file mode 100644 index 0000000..809475d --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_markup_1.snap @@ -0,0 +1,22 @@ +--- +source: crates/org-parser/src/element/table.rs +description: | + + |one|tw *o* | + |three|four| +--- +0..65 [1, 2] + 0..1 BlankLine + 1..65 Table { rows: 2, cols: 2, children: [10, 15], caption: None } + 1..52 Standard([4, 9]) + 2..6 TableCell([3]) + 2..5 "one" + 6..51 TableCell([7, 6]) + 6..9 "tw " + 9..12 Bold([5]) + 10..11 "o" + 52..65 Standard([12, 14]) + 53..59 TableCell([11]) + 53..58 "three" + 59..64 TableCell([13]) + 59..63 "four" diff --git a/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_no_nl.snap b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_no_nl.snap new file mode 100644 index 0000000..df558b8 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_no_nl.snap @@ -0,0 +1,22 @@ +--- +source: crates/org-parser/src/element/table.rs +description: |+ + + |one|two + |three|four + +--- +0..23 [1, 2, 13] + 0..1 BlankLine + 1..22 Table { rows: 2, cols: 2, children: [7, 12], caption: None } + 1..10 Standard([4, 6]) + 2..6 TableCell([3]) + 2..5 "one" + 6..9 TableCell([5]) + 6..9 "two" + 10..22 Standard([9, 11]) + 11..17 TableCell([8]) + 11..16 "three" + 17..21 TableCell([10]) + 17..21 "four" + 22..23 BlankLine diff --git a/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_uneven_cols.snap b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_uneven_cols.snap new file mode 100644 index 0000000..43aaf4d --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_uneven_cols.snap @@ -0,0 +1,23 @@ +--- +source: crates/org-parser/src/element/table.rs +description: | + + |one two |three||||| + |s | | +--- +0..39 [1, 2] + 0..1 BlankLine + 1..39 Table { rows: 2, cols: 6, children: [11, 16], caption: None } + 1..22 Standard([4, 6, 7, 8, 9, 10]) + 2..11 TableCell([3]) + 2..10 "one two" + 11..17 TableCell([5]) + 11..16 "three" + 17..18 TableCell([]) + 18..19 TableCell([]) + 19..20 TableCell([]) + 20..21 TableCell([]) + 22..39 Standard([13, 15]) + 23..32 TableCell([12]) + 23..31 "s" + 32..38 TableCell([]) diff --git a/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_with_hrule.snap b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_with_hrule.snap new file mode 100644 index 0000000..149308d --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__element__table__tests__table_with_hrule.snap @@ -0,0 +1,24 @@ +--- +source: crates/org-parser/src/element/table.rs +description: |+ + + |one|two + |--------| + |three|four + +--- +0..34 [1, 2, 14] + 0..1 BlankLine + 1..33 Table { rows: 3, cols: 2, children: [7, 8, 13], caption: None } + 1..10 Standard([4, 6]) + 2..6 TableCell([3]) + 2..5 "one" + 6..9 TableCell([5]) + 6..9 "two" + 10..21 Rule + 21..33 Standard([10, 12]) + 22..28 TableCell([9]) + 22..27 "three" + 28..32 TableCell([11]) + 28..32 "four" + 33..34 BlankLine diff --git a/crates/org-parser/snapshots/org_rust_parser__object__emoji__tests__failed_emoji.snap b/crates/org-parser/snapshots/org_rust_parser__object__emoji__tests__failed_emoji.snap new file mode 100644 index 0000000..3474fba --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__emoji__tests__failed_emoji.snap @@ -0,0 +1,8 @@ +--- +source: crates/org-parser/src/object/emoji.rs +description: | + :flu shed: abc +--- +0..16 [1] + 0..16 Paragraph([2]) + 0..15 ":flu shed: abc" diff --git a/crates/org-parser/snapshots/org_rust_parser__object__latex_frag__tests__latex_frag_all.snap b/crates/org-parser/snapshots/org_rust_parser__object__latex_frag__tests__latex_frag_all.snap new file mode 100644 index 0000000..4ec31af --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__latex_frag__tests__latex_frag_all.snap @@ -0,0 +1,42 @@ +--- +source: crates/org-parser/src/object/latex_frag.rs +description: |+ + + $\alpha$ $$do + llar$$ + \[display + block\] \(consecutive gaming\) + + \command + + \comma + and + + \command{ab + c} + +--- +0..103 [1, 2, 10, 11, 13, 14, 17, 19, 22] + 0..1 BlankLine + 1..64 Paragraph([3, 5, 4, 6, 7, 9, 8]) + 1..9 Inline("\\alpha") + 9..10 " " + 10..21 Display("do\nllar") + 21..22 SoftBreak + 22..40 Display("display\n block") + 40..41 " " + 41..63 Inline("consecutive gaming") + 64..65 BlankLine + 65..74 Paragraph([12]) + 65..73 Command { name: "command", contents: None } + 74..75 BlankLine + 75..86 Paragraph([15, 16, 18]) + 75..81 Command { name: "comma", contents: None } + 81..82 SoftBreak + 82..85 "and" + 86..87 BlankLine + 87..102 Paragraph([21, 20, 23]) + 87..98 "\\command{ab" + 98..99 SoftBreak + 99..101 "c}" + 102..103 BlankLine diff --git a/crates/org-parser/snapshots/org_rust_parser__object__latex_frag__tests__latex_frag_command_4.snap b/crates/org-parser/snapshots/org_rust_parser__object__latex_frag__tests__latex_frag_command_4.snap new file mode 100644 index 0000000..11b59e3 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__latex_frag__tests__latex_frag_command_4.snap @@ -0,0 +1,7 @@ +--- +source: crates/org-parser/src/object/latex_frag.rs +description: "\\) not a command" +--- +0..17 [1] + 0..17 Paragraph([2]) + 0..16 "\\) not a command" diff --git a/crates/org-parser/snapshots/org_rust_parser__object__latex_frag__tests__latex_frag_pretext.snap b/crates/org-parser/snapshots/org_rust_parser__object__latex_frag__tests__latex_frag_pretext.snap new file mode 100644 index 0000000..25afd05 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__latex_frag__tests__latex_frag_pretext.snap @@ -0,0 +1,11 @@ +--- +source: crates/org-parser/src/object/latex_frag.rs +description: |- + one two $three + fourfive +--- +0..24 [1] + 0..24 Paragraph([3, 2, 4]) + 0..14 "one two $three" + 14..15 SoftBreak + 15..23 "fourfive" diff --git a/crates/org-parser/snapshots/org_rust_parser__object__link__tests__basic_regular_link.snap b/crates/org-parser/snapshots/org_rust_parser__object__link__tests__basic_regular_link.snap new file mode 100644 index 0000000..ab9aca4 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__link__tests__basic_regular_link.snap @@ -0,0 +1,7 @@ +--- +source: crates/org-parser/src/object/link.rs +description: "[[hps://.org]]" +--- +0..15 [1] + 0..15 Paragraph([2]) + 0..14 RegularLink { path: Match { start: 2, end: 12, obj: Unspecified("hps://.org") }, description: None, caption: None } diff --git a/crates/org-parser/snapshots/org_rust_parser__object__link__tests__file_link.snap b/crates/org-parser/snapshots/org_rust_parser__object__link__tests__file_link.snap new file mode 100644 index 0000000..6606f96 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__link__tests__file_link.snap @@ -0,0 +1,20 @@ +--- +source: crates/org-parser/src/object/link.rs +description: | + + I'll be skipping over the instrumentals unless there's reason to. + + [[file:bmc.jpg]] + ** songs +--- +0..94 [1, 2, 3, 5, 7] + 0..1 BlankLine + 1..67 Paragraph([4]) + 1..66 "I'll be skipping over the instrumentals unless there's reason to." + 67..68 BlankLine + 68..85 Paragraph([6]) + 68..84 RegularLink { path: Match { start: 70, end: 82, obj: File("bmc.jpg") }, description: None, caption: None } + 85..94 Heading { heading_level: Two, keyword: None, priority: None, title: Some(("songs\n", [8])), tags: None, properties: None, children: None } + 88..93 "songs" +targets: + "songs\n" -> "songs" diff --git a/crates/org-parser/snapshots/org_rust_parser__object__link__tests__regular_link_description.snap b/crates/org-parser/snapshots/org_rust_parser__object__link__tests__regular_link_description.snap new file mode 100644 index 0000000..081eb38 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__link__tests__regular_link_description.snap @@ -0,0 +1,8 @@ +--- +source: crates/org-parser/src/object/link.rs +description: " [[https://meo][cool site]]" +--- +0..28 [1] + 1..28 Paragraph([3]) + 1..27 RegularLink { path: Match { start: 3, end: 14, obj: PlainLink(PlainLink { protocol: "https", path: "//meo" }) }, description: Some([2]), caption: None } + 16..25 "cool site" diff --git a/crates/org-parser/snapshots/org_rust_parser__object__link__tests__regular_link_malformed.snap b/crates/org-parser/snapshots/org_rust_parser__object__link__tests__regular_link_malformed.snap new file mode 100644 index 0000000..e2617ac --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__link__tests__regular_link_malformed.snap @@ -0,0 +1,13 @@ +--- +source: crates/org-parser/src/object/link.rs +description: | + + word + [#A] +--- +0..11 [1, 2] + 0..1 BlankLine + 1..11 Paragraph([4, 3, 5]) + 1..5 "word" + 5..6 SoftBreak + 6..10 "[#A]" diff --git a/crates/org-parser/snapshots/org_rust_parser__object__link__tests__regular_link_unclosed_plain_markup.snap b/crates/org-parser/snapshots/org_rust_parser__object__link__tests__regular_link_unclosed_plain_markup.snap new file mode 100644 index 0000000..d818040 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__link__tests__regular_link_unclosed_plain_markup.snap @@ -0,0 +1,14 @@ +--- +source: crates/org-parser/src/object/link.rs +description: " [[https://meo][cool *site* ~one two~ three *four ~five six ]]" +--- +0..63 [1] + 1..63 Paragraph([9]) + 1..62 RegularLink { path: Match { start: 3, end: 14, obj: PlainLink(PlainLink { protocol: "https", path: "//meo" }) }, description: Some([4, 3, 6, 5, 8, 7]), caption: None } + 16..21 "cool " + 21..27 Bold([2]) + 22..26 "site" + 27..28 " " + 28..37 Code("one two") + 37..45 " three *" + 45..60 "four ~five six " diff --git a/crates/org-parser/snapshots/org_rust_parser__object__link__tests__regular_link_unclosed_recursive_markup.snap b/crates/org-parser/snapshots/org_rust_parser__object__link__tests__regular_link_unclosed_recursive_markup.snap new file mode 100644 index 0000000..01f59c6 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__link__tests__regular_link_unclosed_recursive_markup.snap @@ -0,0 +1,14 @@ +--- +source: crates/org-parser/src/object/link.rs +description: " [[https://meo][cool *site* ~one two~ three *four ]]" +--- +0..53 [1] + 1..53 Paragraph([9]) + 1..52 RegularLink { path: Match { start: 3, end: 14, obj: PlainLink(PlainLink { protocol: "https", path: "//meo" }) }, description: Some([4, 3, 6, 5, 8, 7]), caption: None } + 16..21 "cool " + 21..27 Bold([2]) + 22..26 "site" + 27..28 " " + 28..37 Code("one two") + 37..45 " three *" + 45..50 "four " diff --git a/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__basic_bold.snap b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__basic_bold.snap new file mode 100644 index 0000000..7d4d800 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__basic_bold.snap @@ -0,0 +1,9 @@ +--- +source: crates/org-parser/src/object/markup.rs +description: "*hello_world*" +--- +0..14 [1] + 0..14 Paragraph([4]) + 0..13 Bold([3, 2]) + 1..6 "hello" + 6..12 Subscript(Plain("world")) diff --git a/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__basic_code.snap b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__basic_code.snap new file mode 100644 index 0000000..d0e856c --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__basic_code.snap @@ -0,0 +1,7 @@ +--- +source: crates/org-parser/src/object/markup.rs +description: ~hello_world~ +--- +0..14 [1] + 0..14 Paragraph([2]) + 0..13 Code("hello_world") diff --git a/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__basic_italic.snap b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__basic_italic.snap new file mode 100644 index 0000000..94db943 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__basic_italic.snap @@ -0,0 +1,9 @@ +--- +source: crates/org-parser/src/object/markup.rs +description: /hello_world/ +--- +0..14 [1] + 0..14 Paragraph([4]) + 0..13 Italic([3, 2]) + 1..6 "hello" + 6..12 Subscript(Plain("world")) diff --git a/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__basic_strikethrough.snap b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__basic_strikethrough.snap new file mode 100644 index 0000000..0d99137 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__basic_strikethrough.snap @@ -0,0 +1,9 @@ +--- +source: crates/org-parser/src/object/markup.rs +description: +hello_world+ +--- +0..14 [1] + 0..14 Paragraph([4]) + 0..13 StrikeThrough([3, 2]) + 1..6 "hello" + 6..12 Subscript(Plain("world")) diff --git a/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__basic_underline.snap b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__basic_underline.snap new file mode 100644 index 0000000..bccf605 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__basic_underline.snap @@ -0,0 +1,8 @@ +--- +source: crates/org-parser/src/object/markup.rs +description: _hello_world_ +--- +0..14 [1] + 0..14 Paragraph([3]) + 0..13 Underline([2]) + 1..12 "hello_world" diff --git a/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__basic_verbatim.snap b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__basic_verbatim.snap new file mode 100644 index 0000000..b7a32b2 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__basic_verbatim.snap @@ -0,0 +1,7 @@ +--- +source: crates/org-parser/src/object/markup.rs +description: "=hello_world=" +--- +0..14 [1] + 0..14 Paragraph([2]) + 0..13 Verbatim("hello_world") diff --git a/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__leaky_markup.snap b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__leaky_markup.snap new file mode 100644 index 0000000..edc2043 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__leaky_markup.snap @@ -0,0 +1,11 @@ +--- +source: crates/org-parser/src/object/markup.rs +description: abc /one *two thr/ ee* three four +--- +0..34 [1] + 0..34 Paragraph([5, 4, 6]) + 0..4 "abc " + 4..18 Italic([3, 2]) + 5..10 "one *" + 10..17 "two thr" + 18..33 " ee* three four" diff --git a/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__markup_not_fail_on_eof.snap b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__markup_not_fail_on_eof.snap new file mode 100644 index 0000000..3aa3e0c --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__markup_not_fail_on_eof.snap @@ -0,0 +1,7 @@ +--- +source: crates/org-parser/src/object/markup.rs +description: / +--- +0..2 [1] + 0..2 Paragraph([2]) + 0..1 "/" diff --git a/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__markup_plain_empty.snap b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__markup_plain_empty.snap new file mode 100644 index 0000000..ab8393a --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__markup_plain_empty.snap @@ -0,0 +1,7 @@ +--- +source: crates/org-parser/src/object/markup.rs +description: ~~ +--- +0..3 [1] + 0..3 Paragraph([2]) + 0..2 "~~" diff --git a/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__markup_plain_single_char.snap b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__markup_plain_single_char.snap new file mode 100644 index 0000000..a60e1fe --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__markup_plain_single_char.snap @@ -0,0 +1,7 @@ +--- +source: crates/org-parser/src/object/markup.rs +description: ~a~ +--- +0..4 [1] + 0..4 Paragraph([2]) + 0..3 Code("a") diff --git a/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__markup_recursive_empty.snap b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__markup_recursive_empty.snap new file mode 100644 index 0000000..22791ad --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__markup_recursive_empty.snap @@ -0,0 +1,7 @@ +--- +source: crates/org-parser/src/object/markup.rs +description: "**" +--- +0..3 [1] + 0..3 Paragraph([2]) + 0..2 "**" diff --git a/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__markup_recursive_single_char.snap b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__markup_recursive_single_char.snap new file mode 100644 index 0000000..bcedd32 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__markup_recursive_single_char.snap @@ -0,0 +1,8 @@ +--- +source: crates/org-parser/src/object/markup.rs +description: /a/ +--- +0..4 [1] + 0..4 Paragraph([3]) + 0..3 Italic([2]) + 1..2 "a" diff --git a/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__mixed_plain_recursive_leaky_markup.snap b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__mixed_plain_recursive_leaky_markup.snap new file mode 100644 index 0000000..f191aa7 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__mixed_plain_recursive_leaky_markup.snap @@ -0,0 +1,10 @@ +--- +source: crates/org-parser/src/object/markup.rs +description: abc /one ~two thr/ ee~ three four +--- +0..34 [1] + 0..34 Paragraph([4, 3, 5]) + 0..4 "abc " + 4..18 Italic([2]) + 5..17 "one ~two thr" + 18..33 " ee~ three four" diff --git a/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__nested_markup.snap b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__nested_markup.snap new file mode 100644 index 0000000..a0be177 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__markup__tests__nested_markup.snap @@ -0,0 +1,13 @@ +--- +source: crates/org-parser/src/object/markup.rs +description: abc /one *two* three/ four +--- +0..27 [1] + 0..27 Paragraph([7, 6, 8]) + 0..4 "abc " + 4..21 Italic([4, 3, 5]) + 5..9 "one " + 9..14 Bold([2]) + 10..13 "two" + 14..20 " three" + 21..26 " four" diff --git a/crates/org-parser/snapshots/org_rust_parser__object__org_macro__tests__combined_macros.snap b/crates/org-parser/snapshots/org_rust_parser__object__org_macro__tests__combined_macros.snap new file mode 100644 index 0000000..71d7df1 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__org_macro__tests__combined_macros.snap @@ -0,0 +1,14 @@ +--- +source: crates/org-parser/src/object/org_macro.rs +description: | + #+macro: poem hiii $1 $2 text + + {{{poem(cool, three)}}} +--- +0..55 [1, 2, 3] + 0..30 MacroDef { num_args: 2, input: [Text("hiii "), ArgNum(1), Text(" "), ArgNum(2), Text(" text")], name: "poem" } + 30..31 BlankLine + 31..55 Paragraph([4]) + 31..54 MacroCall { name: "poem", args: ["cool", " three"] } +macros: + "poem" = MacroDef { num_args: 2, input: [Text("hiii "), ArgNum(1), Text(" "), ArgNum(2), Text(" text")], name: "poem" } diff --git a/crates/org-parser/snapshots/org_rust_parser__object__sup_sub__tests__basic_sup.snap b/crates/org-parser/snapshots/org_rust_parser__object__sup_sub__tests__basic_sup.snap new file mode 100644 index 0000000..a01f701 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__object__sup_sub__tests__basic_sup.snap @@ -0,0 +1,9 @@ +--- +source: crates/org-parser/src/object/sup_sub.rs +description: "a^{\\smiley}" +--- +0..12 [1] + 0..12 Paragraph([4, 3]) + 0..1 "a" + 1..11 Superscript(Rec([2])) + 3..10 Entity { name: "smiley", mapped_item: "☺" } diff --git a/crates/org-parser/snapshots/org_rust_parser__tests__basic_markup.snap b/crates/org-parser/snapshots/org_rust_parser__tests__basic_markup.snap new file mode 100644 index 0000000..bc4dbe0 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__tests__basic_markup.snap @@ -0,0 +1,11 @@ +--- +source: crates/org-parser/src/lib.rs +description: | + hello /italic/ more text after +--- +0..31 [1] + 0..31 Paragraph([4, 3, 5]) + 0..6 "hello " + 6..14 Italic([2]) + 7..13 "italic" + 14..30 " more text after" diff --git a/crates/org-parser/snapshots/org_rust_parser__tests__basic_paragraph.snap b/crates/org-parser/snapshots/org_rust_parser__tests__basic_paragraph.snap new file mode 100644 index 0000000..aeed5f0 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__tests__basic_paragraph.snap @@ -0,0 +1,9 @@ +--- +source: crates/org-parser/src/lib.rs +description: | + hello_world +--- +0..12 [1] + 0..12 Paragraph([3, 2]) + 0..5 "hello" + 5..11 Subscript(Plain("world")) diff --git a/crates/org-parser/snapshots/org_rust_parser__tests__basic_paragraph_newline.snap b/crates/org-parser/snapshots/org_rust_parser__tests__basic_paragraph_newline.snap new file mode 100644 index 0000000..957ae71 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__tests__basic_paragraph_newline.snap @@ -0,0 +1,13 @@ +--- +source: crates/org-parser/src/lib.rs +description: | + hello_world + same_paragraph +--- +0..27 [1] + 0..27 Paragraph([3, 2, 4, 6, 5]) + 0..5 "hello" + 5..11 Subscript(Plain("world")) + 11..12 SoftBreak + 12..16 "same" + 16..26 Subscript(Plain("paragraph")) diff --git a/crates/org-parser/snapshots/org_rust_parser__tests__basic_paragraph_no_nl.snap b/crates/org-parser/snapshots/org_rust_parser__tests__basic_paragraph_no_nl.snap new file mode 100644 index 0000000..c65e822 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__tests__basic_paragraph_no_nl.snap @@ -0,0 +1,7 @@ +--- +source: crates/org-parser/src/lib.rs +description: hello_world +--- +0..12 [1] + 0..12 Paragraph([2]) + 0..11 "hello_world" diff --git a/crates/org-parser/snapshots/org_rust_parser__tests__basic_unicode.snap b/crates/org-parser/snapshots/org_rust_parser__tests__basic_unicode.snap new file mode 100644 index 0000000..749aa5e --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__tests__basic_unicode.snap @@ -0,0 +1,8 @@ +--- +source: crates/org-parser/src/lib.rs +description: | + é +--- +0..3 [1] + 0..3 Paragraph([2]) + 0..2 "é" diff --git a/crates/org-parser/snapshots/org_rust_parser__tests__correctness_cache.snap b/crates/org-parser/snapshots/org_rust_parser__tests__correctness_cache.snap new file mode 100644 index 0000000..a531004 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__tests__correctness_cache.snap @@ -0,0 +1,19 @@ +--- +source: crates/org-parser/src/lib.rs +description: | + + - one + - two + + -------------- +--- +0..29 [1, 9, 10] + 0..1 BlankLine + 1..14 PlainList { children: [2, 4], kind: Unordered } + 1..7 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [3] } + 3..7 Paragraph([8]) + 3..6 "one" + 7..14 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [5] } + 9..13 Paragraph([7]) + 9..12 "two" + 14..29 HorizontalRule diff --git a/crates/org-parser/snapshots/org_rust_parser__tests__lots.snap b/crates/org-parser/snapshots/org_rust_parser__tests__lots.snap new file mode 100644 index 0000000..c8ab026 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__tests__lots.snap @@ -0,0 +1,181 @@ +--- +source: crates/org-parser/src/lib.rs +description: |+ + + #+macro: greet Hello $1, nice typing... $1. + * Basic Heading + + {{{greet(user)}}} + + ** Child Heading + + - https://plain_links.com. + - + - src_python{(technically) inline_src} + - [[Child Heading]] + - \aleph \leftarrow entities + + #+begin_export + + #+end_export + + |tables!|[[targets][links to output target]]|styled,, manually :sweat_smile: + |no|default css (yet)| + |||||||||table + + 1. +does+ + 2. *it* + 3. /all/ + 4. ~code~ + 5. =code, again..= + 6. /so _nested_, *t^o_o*./ + + emojis :flushed: :tada: :sunglasses: + + \begin{align} + x &+ 4\\ + abc &+ 10\\ + \end{align} + output MathML, little janky atm (might switch to katex..?) + + Target here: <>\\ + + + # doesn't look the best, imo + ----- + + #+begin_src rust + nothing styled for source blocks yet, too. + #+end_src + +--- +0..850 [1, 2, 3] + 0..1 BlankLine + 1..45 MacroDef { num_args: 1, input: [Text("Hello "), ArgNum(1), Text(", nice typing... "), ArgNum(1), Text(".")], name: "greet" } + 45..850 Heading { heading_level: One, keyword: None, priority: None, title: Some(("Basic Heading\n", [4])), tags: None, properties: None, children: Some([5, 6, 8, 9]) } + 47..60 "Basic Heading" + 61..62 BlankLine + 62..80 Paragraph([7]) + 62..79 MacroCall { name: "greet", args: ["user"] } + 80..81 BlankLine + 81..850 Heading { heading_level: Two, keyword: None, priority: None, title: Some(("Child Heading\n", [10])), tags: Some([Loc(3)]), properties: None, children: Some([11, 35, 36, 37, 38, 39, 65, 97, 98, 105, 106, 107, 108, 109, 111, 115, 116, 117, 118, 119, 120, 121]) } + 84..97 "Child Heading" + 98..99 BlankLine + 99..253 PlainList { children: [12, 24], kind: Unordered } + 99..201 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [13, 22] } + 101..126 Paragraph([14, 23]) + 101..124 PlainLink { protocol: "https", path: "//plain_links.com" } + 124..125 "." + 128..201 PlainList { children: [15], kind: Unordered } + 128..201 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [16, 21] } + 130..158 Paragraph([17]) + 130..157 PlainLink { protocol: "mailto", path: "okiedokie@cool.com" } + 162..201 PlainList { children: [18], kind: Unordered } + 162..201 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [19] } + 164..201 Paragraph([20]) + 164..200 InlineSrc { lang: "python", headers: None, body: "(technically) inline_src" } + 201..253 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [25, 34] } + 203..221 Paragraph([26]) + 203..220 RegularLink { path: Match { start: 205, end: 218, obj: Unspecified("Child Heading") }, description: None, caption: None } + 223..253 PlainList { children: [27], kind: Unordered } + 223..253 Item { bullet: Unordered, counter_set: None, check_box: None, tag: None, children: [28] } + 225..252 Paragraph([29, 31, 30, 33]) + 225..231 Entity { name: "aleph", mapped_item: "ℵ" } + 231..232 " " + 232..242 Entity { name: "leftarrow", mapped_item: "←" } + 242..251 " entities" + 253..367 Export { backend: None, parameters: {}, contents: "\n" } + 367..368 BlankLine + 368..369 BlankLine + 369..484 Table { rows: 3, cols: 9, children: [48, 53, 64], caption: None } + 369..446 Standard([41, 44, 47]) + 370..378 TableCell([40]) + 370..377 "tables!" + 378..414 TableCell([43]) + 378..413 RegularLink { path: Match { start: 380, end: 387, obj: Unspecified("targets") }, description: Some([42]), caption: None } + 389..411 "links to output target" + 414..445 TableCell([46, 45]) + 414..432 "styled,, manually " + 432..445 Emoji { name: "sweat_smile", mapped_item: '😅' } + 446..469 Standard([50, 52]) + 447..450 TableCell([49]) + 447..449 "no" + 450..468 TableCell([51]) + 450..467 "default css (yet)" + 469..484 Standard([54, 55, 56, 57, 58, 59, 60, 61, 63]) + 470..471 TableCell([]) + 471..472 TableCell([]) + 472..473 TableCell([]) + 473..474 TableCell([]) + 474..475 TableCell([]) + 475..476 TableCell([]) + 476..477 TableCell([]) + 477..478 TableCell([]) + 478..483 TableCell([62]) + 478..483 "table" + 484..485 BlankLine + 485..569 PlainList { children: [66, 70, 74, 78, 81, 84], kind: Ordered(Number(1)) } + 485..495 Item { bullet: Ordered(Number(1)), counter_set: None, check_box: None, tag: None, children: [67] } + 488..495 Paragraph([69]) + 488..494 StrikeThrough([68]) + 489..493 "does" + 495..503 Item { bullet: Ordered(Number(2)), counter_set: None, check_box: None, tag: None, children: [71] } + 498..503 Paragraph([73]) + 498..502 Bold([72]) + 499..501 "it" + 503..512 Item { bullet: Ordered(Number(3)), counter_set: None, check_box: None, tag: None, children: [75] } + 506..512 Paragraph([77]) + 506..511 Italic([76]) + 507..510 "all" + 512..522 Item { bullet: Ordered(Number(4)), counter_set: None, check_box: None, tag: None, children: [79] } + 515..522 Paragraph([80]) + 515..521 Code("code") + 522..541 Item { bullet: Ordered(Number(5)), counter_set: None, check_box: None, tag: None, children: [82] } + 525..541 Paragraph([83]) + 525..540 Verbatim("code, again..") + 541..569 Item { bullet: Ordered(Number(6)), counter_set: None, check_box: None, tag: None, children: [85] } + 544..568 Paragraph([95]) + 544..567 Italic([88, 87, 93, 92, 94]) + 545..548 "so " + 548..556 Underline([86]) + 549..555 "nested" + 556..558 ", " + 558..565 Bold([90, 89, 91]) + 559..560 "t" + 560..562 Superscript(Plain("o")) + 562..564 Subscript(Plain("o")) + 565..566 "." + 569..606 Paragraph([100, 99, 102, 101, 104, 103]) + 569..576 "emojis " + 576..585 Emoji { name: "flushed", mapped_item: '😳' } + 585..586 " " + 586..592 Emoji { name: "tada", mapped_item: '🎉' } + 592..593 " " + 593..605 Emoji { name: "sunglasses", mapped_item: '😎' } + 606..607 BlankLine + 607..653 LatexEnv { name: "align", contents: "x &+ 4\\\\\nabc &+ 10\\\\\n" } + 653..654 BlankLine + 654..713 Paragraph([110]) + 654..712 "output MathML, little janky atm (might switch to katex..?)" + 713..714 BlankLine + 714..742 Paragraph([113, 112, 114]) + 714..727 "Target here: " + 727..738 Target("targets") + 738..741 LineBreak + 742..743 BlankLine + 743..772 Comment("doesn't look the best, imo") + 772..778 HorizontalRule + 778..779 BlankLine + 779..848 Src { language: Some("rust"), parameters: {}, contents: "nothing styled for source blocks yet, too.\n" } + 848..849 BlankLine + 849..850 BlankLine +targets: + "Basic Heading\n" -> "basic-heading" + "Child Heading\n" -> "child-heading" + "targets" -> "targets" +macros: + "greet" = MacroDef { num_args: 1, input: [Text("Hello "), ArgNum(1), Text(", nice typing... "), ArgNum(1), Text(".")], name: "greet" } diff --git a/crates/org-parser/snapshots/org_rust_parser__tests__newline_in_italic_markup.snap b/crates/org-parser/snapshots/org_rust_parser__tests__newline_in_italic_markup.snap new file mode 100644 index 0000000..dc8518f --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__tests__newline_in_italic_markup.snap @@ -0,0 +1,14 @@ +--- +source: crates/org-parser/src/lib.rs +description: | + hello /italic + newline/ more text after +--- +0..41 [1] + 0..41 Paragraph([6, 5, 7]) + 0..6 "hello " + 6..24 Italic([3, 2, 4]) + 7..14 "italic " + 14..15 SoftBreak + 15..23 " newline" + 24..40 " more text after" diff --git a/crates/org-parser/snapshots/org_rust_parser__tests__newline_in_verbatim.snap b/crates/org-parser/snapshots/org_rust_parser__tests__newline_in_verbatim.snap new file mode 100644 index 0000000..6e88472 --- /dev/null +++ b/crates/org-parser/snapshots/org_rust_parser__tests__newline_in_verbatim.snap @@ -0,0 +1,11 @@ +--- +source: crates/org-parser/src/lib.rs +description: | + hello =italic + newline= more text after +--- +0..41 [1] + 0..41 Paragraph([3, 2, 4]) + 0..6 "hello " + 6..24 Verbatim("italic \n newline") + 24..40 " more text after" diff --git a/crates/org-parser/src/element/block.rs b/crates/org-parser/src/element/block.rs index b965c4f..152c4fe 100644 --- a/crates/org-parser/src/element/block.rs +++ b/crates/org-parser/src/element/block.rs @@ -303,6 +303,7 @@ impl<'a> From> for &'a str { #[cfg(test)] mod tests { + use crate::test_util::snap; use std::collections::HashMap; use crate::element::Block; @@ -452,7 +453,7 @@ if let Some(nested) = nest { #+end_quote "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -514,7 +515,7 @@ here is some text "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -528,7 +529,7 @@ hiiiiiiiiiiiiiiiiiii "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] diff --git a/crates/org-parser/src/element/drawer.rs b/crates/org-parser/src/element/drawer.rs index 0855c77..eff4c9a 100644 --- a/crates/org-parser/src/element/drawer.rs +++ b/crates/org-parser/src/element/drawer.rs @@ -131,6 +131,7 @@ pub(crate) fn parse_property(mut cursor: Cursor) -> Result #[cfg(test)] mod tests { use crate::parse_org; + use crate::test_util::snap; #[test] fn basic_drawer() { @@ -144,7 +145,7 @@ halloo "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -159,6 +160,6 @@ halloo "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } } diff --git a/crates/org-parser/src/element/heading.rs b/crates/org-parser/src/element/heading.rs index 29e05ca..59689e5 100644 --- a/crates/org-parser/src/element/heading.rs +++ b/crates/org-parser/src/element/heading.rs @@ -387,6 +387,7 @@ impl<'a> Heading<'a> { #[cfg(test)] mod tests { + use crate::test_util::snap; use std::borrow::Cow; use crate::element::{HeadingLevel, PropertyDrawer, Tag}; @@ -598,14 +599,14 @@ mod tests { fn headline_prio_keyword_title() { let inp = "* TODO [#A] SWAG \n"; - dbg!(parse_org(inp)); + snap!(parse_org(inp)); } #[test] fn headline_prio_keyword_decorated_title() { let inp = "* TODO [#A] *one* two /three/ /four* \n"; - dbg!(parse_org(inp)); + snap!(parse_org(inp)); } #[test] @@ -626,7 +627,7 @@ more subcontent "; let pool = parse_org(inp); - pool.print_tree(); + snap!(pool); } #[test] @@ -671,7 +672,7 @@ qqqqq aaaa"; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] diff --git a/crates/org-parser/src/element/keyword.rs b/crates/org-parser/src/element/keyword.rs index 76d3ba4..3e7139b 100644 --- a/crates/org-parser/src/element/keyword.rs +++ b/crates/org-parser/src/element/keyword.rs @@ -448,7 +448,6 @@ mod tests { &"yes_my_list".into() ); assert_eq!(parsed.target_occurences.get("yes_my_list").unwrap(), &1); - // parsed.print_tree(); } #[test] diff --git a/crates/org-parser/src/element/latex_env.rs b/crates/org-parser/src/element/latex_env.rs index 0ac4028..c91eddb 100644 --- a/crates/org-parser/src/element/latex_env.rs +++ b/crates/org-parser/src/element/latex_env.rs @@ -52,6 +52,7 @@ impl<'a> Parseable<'a> for LatexEnv<'a> { #[cfg(test)] mod tests { + use crate::test_util::snap; use crate::{element::LatexEnv, expr_in_pool, parse_org, types::Expr}; #[test] @@ -61,7 +62,7 @@ mod tests { \end{align*} "; - dbg!(parse_org(inp)); + snap!(parse_org(inp)); } #[test] @@ -78,7 +79,7 @@ mod tests { \end{align*} "; - dbg!(parse_org(inp)); + snap!(parse_org(inp)); } #[test] @@ -89,19 +90,19 @@ mod tests { \end{star!} "; - dbg!(parse_org(inp)); + snap!(parse_org(inp)); let inp = r" \begin{a13214-} \end{a13214-} "; - dbg!(parse_org(inp)); + snap!(parse_org(inp)); // failed construction let inp = r" \begin{one}more stuff \end{one} "; - dbg!(parse_org(inp)); + snap!(parse_org(inp)); } #[test] @@ -110,7 +111,7 @@ mod tests { \begin{} \end{} "; - dbg!(parse_org(inp)); + snap!(parse_org(inp)); } #[test] @@ -119,7 +120,7 @@ mod tests { \begin{start} \end{notstart} "; - dbg!(parse_org(inp)); + snap!(parse_org(inp)); } #[test] diff --git a/crates/org-parser/src/element/plain_list.rs b/crates/org-parser/src/element/plain_list.rs index 65edfba..8a64557 100644 --- a/crates/org-parser/src/element/plain_list.rs +++ b/crates/org-parser/src/element/plain_list.rs @@ -97,6 +97,7 @@ fn find_kind(item: &Item) -> ListKind { #[cfg(test)] mod tests { + use crate::test_util::snap; use crate::{Expr, parse_org}; #[test] @@ -106,7 +107,7 @@ mod tests { "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -117,7 +118,7 @@ mod tests { "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -129,7 +130,7 @@ mod tests { "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -146,7 +147,7 @@ mod tests { "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -162,7 +163,7 @@ mod tests { "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -181,7 +182,7 @@ not a list too "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -198,7 +199,7 @@ not a list too "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -210,7 +211,7 @@ not a list too "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -223,7 +224,7 @@ not a list too "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -236,7 +237,7 @@ not a list too "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -250,7 +251,7 @@ not a list too "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -264,7 +265,7 @@ not a list too "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -276,7 +277,7 @@ not a list too "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -294,7 +295,7 @@ not a list too "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -306,7 +307,7 @@ not a list too a* "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -320,7 +321,7 @@ a* heyy "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -333,7 +334,7 @@ a* "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] diff --git a/crates/org-parser/src/element/table.rs b/crates/org-parser/src/element/table.rs index 337985b..9764ed0 100644 --- a/crates/org-parser/src/element/table.rs +++ b/crates/org-parser/src/element/table.rs @@ -138,6 +138,7 @@ impl<'a> Parseable<'a> for TableRow { #[cfg(test)] mod tests { + use crate::test_util::snap; use crate::{Expr, element::Affiliated, expr_in_pool, parse_org}; #[test] @@ -148,7 +149,7 @@ mod tests { "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -159,7 +160,7 @@ mod tests { "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -169,7 +170,7 @@ mod tests { |three|four|"; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -181,7 +182,7 @@ mod tests { "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -194,7 +195,7 @@ mod tests { "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -205,7 +206,7 @@ mod tests { "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -216,7 +217,7 @@ mod tests { "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } /// test that alignment spaces are removed @@ -229,7 +230,7 @@ mod tests { let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -241,7 +242,7 @@ mod tests { let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -256,7 +257,7 @@ word "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -272,7 +273,7 @@ word let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] diff --git a/crates/org-parser/src/lib.rs b/crates/org-parser/src/lib.rs index 97ca79c..f718eae 100644 --- a/crates/org-parser/src/lib.rs +++ b/crates/org-parser/src/lib.rs @@ -9,6 +9,10 @@ pub(crate) mod types; pub(crate) mod utils; mod parse; +mod render; + +#[cfg(test)] +pub(crate) mod test_util; pub use node_pool::{NodeID, NodePool}; pub use types::{Expr, Node, Parser}; @@ -112,12 +116,13 @@ pub fn parse_macro_call<'a>(input: &'a str) -> Parser<'a> { #[cfg(test)] mod tests { use super::*; + use crate::test_util::snap; #[test] fn test_basic_paragraph() { let inp = "hello_world\n"; - dbg!(parse_org(inp)); + snap!(parse_org(inp)); } #[test] @@ -125,14 +130,14 @@ mod tests { fn test_basic_paragraph_no_nl() { let inp = "hello_world"; - dbg!(parse_org(inp)); + snap!(parse_org(inp)); } #[test] fn test_basic_paragraph_newline() { let inp = "hello_world\nsame_paragraph\n"; - dbg!(parse_org(inp)); + snap!(parse_org(inp)); } #[test] @@ -140,7 +145,7 @@ mod tests { let inp = "hello /italic/ more text after\n"; let pool = parse_org(inp); - pool.print_tree(); + snap!(pool); } #[test] @@ -148,7 +153,7 @@ mod tests { let inp = "hello /italic \n newline/ more text after\n"; let pool = parse_org(inp); - pool.print_tree(); + snap!(pool); } #[test] @@ -156,7 +161,7 @@ mod tests { let inp = "hello =italic \n newline= more text after\n"; // dbg!(parse_org(inp)); - println!("{:?}", parse_org(inp)); + snap!(parse_org(inp)); } #[test] @@ -214,8 +219,7 @@ nothing styled for source blocks yet, too. "#; let pool = parse_org(input); - pool.print_tree(); - dbg!(pool); + snap!(pool); } #[test] @@ -228,7 +232,7 @@ nothing styled for source blocks yet, too. "; let pool = parse_org(input); // dbg!(&pool); - pool.print_tree(); + snap!(pool); } #[test] @@ -237,6 +241,6 @@ nothing styled for source blocks yet, too. "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } } diff --git a/crates/org-parser/src/node_pool.rs b/crates/org-parser/src/node_pool.rs index 0c6f6b6..8c05789 100644 --- a/crates/org-parser/src/node_pool.rs +++ b/crates/org-parser/src/node_pool.rs @@ -131,11 +131,6 @@ impl<'a> NodePool<'a> { self.inner_vec.iter_mut() } - /// Outputs a (somewhat) legible representation of the tree to stdout. - pub fn print_tree(&self) { - self.inner_vec[0].print_tree(self); - } - /// Returns the [`NodeID`] of the first element in the pool. pub fn root_id(&self) -> NodeID { NodeID(0) diff --git a/crates/org-parser/src/object/emoji.rs b/crates/org-parser/src/object/emoji.rs index 34fac5b..acfd28c 100644 --- a/crates/org-parser/src/object/emoji.rs +++ b/crates/org-parser/src/object/emoji.rs @@ -1913,6 +1913,7 @@ mod tests { use crate::expr_in_pool; use crate::object::Emoji; use crate::parse_org; + use crate::test_util::snap; use crate::types::Expr; #[test] @@ -1938,7 +1939,7 @@ mod tests { "; let pool = parse_org(input); - dbg!(pool); + snap!(pool); } #[test] diff --git a/crates/org-parser/src/object/latex_frag.rs b/crates/org-parser/src/object/latex_frag.rs index fbd8448..34f57b1 100644 --- a/crates/org-parser/src/object/latex_frag.rs +++ b/crates/org-parser/src/object/latex_frag.rs @@ -289,6 +289,7 @@ fn verify_single_char_latex_frag(cursor: Cursor) -> bool { #[cfg(test)] mod tests { + use crate::test_util::snap; use crate::{expr_in_pool, object::LatexFragment, parse_org, types::Expr}; use pretty_assertions::assert_eq; @@ -402,7 +403,7 @@ mod tests { let input = r"\) not a command"; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -462,7 +463,7 @@ c} "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -470,9 +471,7 @@ c} let input = "one two $three\nfourfive"; let pool = parse_org(input); - - dbg!(&pool); - pool.print_tree(); + snap!(pool); } #[test] diff --git a/crates/org-parser/src/object/link.rs b/crates/org-parser/src/object/link.rs index 06d8662..44c8ae4 100644 --- a/crates/org-parser/src/object/link.rs +++ b/crates/org-parser/src/object/link.rs @@ -418,6 +418,7 @@ pub(crate) fn parse_angle_link<'a>( #[cfg(test)] mod tests { + use crate::test_util::snap; use pretty_assertions::assert_eq; use crate::element::Affiliated; @@ -537,7 +538,7 @@ mod tests { fn basic_regular_link() { let input = "[[hps://.org]]"; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -547,28 +548,28 @@ word [#A] "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] fn regular_link_description() { let input = " [[https://meo][cool site]]"; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] fn regular_link_unclosed_recursive_markup() { let input = " [[https://meo][cool *site* ~one two~ three *four ]]"; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] fn regular_link_unclosed_plain_markup() { let input = " [[https://meo][cool *site* ~one two~ three *four ~five six ]]"; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] @@ -581,7 +582,7 @@ I'll be skipping over the instrumentals unless there's reason to. "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] diff --git a/crates/org-parser/src/object/markup.rs b/crates/org-parser/src/object/markup.rs index c82415a..8f601f0 100644 --- a/crates/org-parser/src/object/markup.rs +++ b/crates/org-parser/src/object/markup.rs @@ -144,43 +144,44 @@ plain_markup!(Verbatim, EQUAL); #[cfg(test)] mod tests { use crate::parse_org; + use crate::test_util::snap; #[test] fn basic_verbatim() { let inp = "=hello_world="; - dbg!(parse_org(inp)); + snap!(parse_org(inp)); } #[test] fn basic_code() { let inp = "~hello_world~"; - dbg!(parse_org(inp)); + snap!(parse_org(inp)); } #[test] fn basic_italic() { let inp = "/hello_world/"; - dbg!(parse_org(inp)); + snap!(parse_org(inp)); } #[test] fn basic_bold() { let inp = "*hello_world*"; - dbg!(parse_org(inp)); + snap!(parse_org(inp)); } #[test] fn basic_underline() { let inp = "_hello_world_"; - dbg!(parse_org(inp)); + snap!(parse_org(inp)); } #[test] fn basic_strikethrough() { let inp = "+hello_world+"; - dbg!(parse_org(inp)); + snap!(parse_org(inp)); } #[test] @@ -188,7 +189,7 @@ mod tests { let inp = "**"; let pool = parse_org(inp); - pool.print_tree(); + snap!(pool); } #[test] @@ -196,7 +197,7 @@ mod tests { let inp = "~~"; let pool = parse_org(inp); - pool.print_tree(); + snap!(pool); } #[test] @@ -204,7 +205,7 @@ mod tests { let inp = "abc /one *two* three/ four"; let pool = parse_org(inp); - pool.print_tree(); + snap!(pool); } #[test] @@ -212,7 +213,7 @@ mod tests { let inp = "abc /one *two thr/ ee* three four"; let pool = parse_org(inp); - pool.print_tree(); + snap!(pool); } #[test] @@ -220,7 +221,7 @@ mod tests { let inp = "abc /one ~two thr/ ee~ three four"; let pool = parse_org(inp); - pool.print_tree(); + snap!(pool); } // #[test] // fn @@ -229,7 +230,7 @@ mod tests { let inp = "/"; let pool = parse_org(inp); - pool.print_tree(); + snap!(pool); } #[test] @@ -238,7 +239,7 @@ mod tests { let inp = "~a~"; let pool = parse_org(inp); - pool.print_tree(); + snap!(pool); } #[test] @@ -247,6 +248,6 @@ mod tests { let inp = "/a/"; let pool = parse_org(inp); - pool.print_tree(); + snap!(pool); } } diff --git a/crates/org-parser/src/object/org_macro.rs b/crates/org-parser/src/object/org_macro.rs index 00c719e..c2be300 100644 --- a/crates/org-parser/src/object/org_macro.rs +++ b/crates/org-parser/src/object/org_macro.rs @@ -150,6 +150,7 @@ impl<'a> Parseable<'a> for MacroCall<'a> { #[cfg(test)] mod tests { + use crate::test_util::snap; use std::borrow::Cow; use pretty_assertions::assert_eq; @@ -241,7 +242,7 @@ mod tests { {{{poem(cool, three)}}} "; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } #[test] diff --git a/crates/org-parser/src/object/sup_sub.rs b/crates/org-parser/src/object/sup_sub.rs index 9209a4d..ba04fe7 100644 --- a/crates/org-parser/src/object/sup_sub.rs +++ b/crates/org-parser/src/object/sup_sub.rs @@ -127,12 +127,13 @@ parse_nscript!(Superscript); #[cfg(test)] mod tests { use crate::parse_org; + use crate::test_util::snap; #[test] fn basic_sup() { let input = r"a^{\smiley}"; let pool = parse_org(input); - pool.print_tree(); + snap!(pool); } } diff --git a/crates/org-parser/src/render.rs b/crates/org-parser/src/render.rs new file mode 100644 index 0000000..b8d670f --- /dev/null +++ b/crates/org-parser/src/render.rs @@ -0,0 +1,91 @@ +//! Text rendering of a parsed document (primarily for testing/debugging). + +use std::collections::HashMap; +use std::fmt::{Debug, Write}; + +use crate::element::Affiliated; +use crate::node_pool::NodeID; +use crate::types::{Expr, Parser}; + +/// Every `NodeID` an expression owns, in source order. +fn child_ids(expr: &Expr) -> Vec { + let mut ids: Vec = Vec::new(); + if let Expr::Heading(h) = expr + && let Some((_, title)) = &h.title + { + ids.extend(title); + } + if let Some(children) = expr.children() { + ids.extend(children); + } + match expr { + Expr::RegularLink(l) => ids.extend(l.caption), + Expr::Affiliated(Affiliated::Name(id)) => ids.extend(id), + Expr::Affiliated(Affiliated::Caption(id)) => ids.push(*id), + Expr::Affiliated(Affiliated::Attr { child_id, .. }) => ids.extend(child_id), + _ => {} + } + ids +} + +fn render_node(parser: &Parser, id: NodeID, depth: usize, out: &mut String) { + let node = &parser.pool[id]; + // https://doc.rust-lang.org/std/fmt/#width for the indent trick + let _ = writeln!( + out, + "{:indent$}{}..{} {:?}", + "", + node.start, + node.end, + node.obj, + indent = depth * 2 + ); + for child in child_ids(&node.obj) { + render_node(parser, child, depth + 1, out); + } +} + +/// Writes `title:` followed by one `key sep value` line per entry, sorted by key so the +/// output doesn't depend on `HashMap` iteration order. Writes nothing for an empty map. +fn render_section(out: &mut String, title: &str, sep: &str, map: &HashMap<&str, V>) { + if map.is_empty() { + return; + } + let mut entries: Vec<_> = map.iter().collect(); + entries.sort_by_key(|(key, _)| **key); + let _ = writeln!(out, "{title}:"); + for (key, val) in entries { + let _ = writeln!(out, " {key:?} {sep} {val:?}"); + } +} + +impl Parser<'_> { + /// Renders the parsed tree as indented text. + /// + /// Each line is one node: its span in the source (`start..end`) followed by its + /// contents, indented by depth. Child lists inside a node's contents show the + /// [`NodeID`]s of its children. Only nodes reachable from the root are shown. + /// + /// The tree is followed by the parser's `targets`, `keywords` and `macros` tables, each + /// under its own heading and sorted by key. A table with no entries is omitted. + /// + /// ```rust + /// use org_rust_parser as org_parser; + /// + /// let parsed = org_parser::parse_org("hello /world/\n"); + /// let tree = parsed.render_tree(); + /// + /// assert!(tree.contains("Italic")); + /// + /// let parsed = org_parser::parse_org("#+title: hi\n"); + /// assert!(parsed.render_tree().contains("keywords:\n \"title\" = \"hi\"")); + /// ``` + pub fn render_tree(&self) -> String { + let mut out = String::new(); + render_node(self, self.pool.root_id(), 0, &mut out); + render_section(&mut out, "targets", "->", &self.targets); + render_section(&mut out, "keywords", "=", &self.keywords); + render_section(&mut out, "macros", "=", &self.macros); + out + } +} diff --git a/crates/org-parser/src/test_util.rs b/crates/org-parser/src/test_util.rs new file mode 100644 index 0000000..97fb293 --- /dev/null +++ b/crates/org-parser/src/test_util.rs @@ -0,0 +1,29 @@ +//! Helpers for snapshot tests. +//! +//! [`snap!`] renders a parsed document with [`Parser::render_tree`] and hands it to +//! [`insta`], which compares it with a stored snapshot. Any change in structure fails the test with a diff. +//! +//! Snapshots are stored in `/snapshots/` refer to the README for more. + +/// Snapshots live in one directory at the crate root, not next to each source file. +pub(crate) const SNAPSHOT_DIR: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/snapshots"); + +/// Asserts that a parsed document matches its stored [`insta`] snapshot. +/// +/// The source text goes in the snapshot's YAML header as `description`, so the body is only +/// the rendered tree. Insta doesn't compare the header, only the body. +macro_rules! snap { + ($parser:expr) => {{ + let parser = &$parser; + ::insta::with_settings!({ + snapshot_path => $crate::test_util::SNAPSHOT_DIR, + // we use INSTA_YAML_BLOCK_STYLE=1 in .cargo/config.toml to ensure + // output isn't serialized (not use quotes & newlines) + description => parser.source.to_string(), + omit_expression => true, + }, { + ::insta::assert_snapshot!(parser.render_tree()); + }); + }}; +} +pub(crate) use snap; diff --git a/crates/org-parser/src/types.rs b/crates/org-parser/src/types.rs index 39f3792..d0c01a7 100644 --- a/crates/org-parser/src/types.rs +++ b/crates/org-parser/src/types.rs @@ -169,10 +169,6 @@ impl<'a> Parser<'a> { target_id } - pub(crate) fn print_tree(&self) { - self.pool.print_tree(); - } - /// Creates a unique id based on the raw contents of the item /// use an Rc since the generated id will also be stored in the node /// and in target_occurences. @@ -422,10 +418,6 @@ impl<'a> Node<'a> { attrs: HashMap::new(), } } - - pub fn print_tree(&self, pool: &NodePool) { - self.obj.print_tree(pool); - } } /// An enum that represents all possible AST nodes @@ -643,193 +635,6 @@ impl<'a> Expr<'a> { _ => None, } } - - fn print_tree(&self, pool: &NodePool) { - match self { - Expr::LatexFragment(inner) => print!("{inner:#?}"), - Expr::Root(inner) => { - print!("Root("); - for id in inner { - // print!("{:#?}: ", id); - pool[*id].obj.print_tree(pool); - println!(); - } - print!(")"); - } - Expr::Heading(inner) => { - println!("Heading {{"); - println!("heading_level: {:#?}", inner.heading_level); - println!("keyword: {:#?}", inner.keyword); - println!("priority: {:#?}", inner.priority); - println!("tags: {:#?}", inner.tags); - println!("properties: {:#?}", inner.properties); - print!("title: "); - if let Some(title) = &inner.title { - for id in &title.1 { - pool[*id].obj.print_tree(pool); - } - } - println!(); - print!("children: ["); - if let Some(children) = &inner.children { - for id in children { - // print!("{:#?}: ", id); - pool[*id].obj.print_tree(pool); - print!(", "); - } - } - print!("]"); - print!("}}"); - } - Expr::Block(inner) => { - println!("Block{{"); - match inner { - Block::Center { contents, .. } - | Block::Quote { contents, .. } - | Block::Special { contents, .. } => { - for id in contents { - pool[*id].obj.print_tree(pool); - print!(","); - } - } - Block::Comment { contents, .. } - | Block::Example { contents, .. } - | Block::Export { contents, .. } - | Block::Src { contents, .. } - | Block::Verse { contents, .. } => { - println!("{contents:#?}"); - } - } - print!("\nEndBlock}}"); - } - Expr::RegularLink(inner) => { - println!("RegularLink{{"); - print!("{:#?}", inner.path); - if let Some(children) = &inner.description { - for id in children { - pool[*id].obj.print_tree(pool); - print!(","); - } - } - println!("}}"); - } - - Expr::Paragraph(inner) => { - print!("Paragraph {{"); - for id in &inner.0 { - // print!("{:#?}: ", id); - pool[*id].obj.print_tree(pool); - print!(", "); - } - print!("}}"); - } - - Expr::Italic(inner) => { - print!("Italic{{"); - for id in &inner.0 { - pool[*id].obj.print_tree(pool); - } - print!("}}"); - } - Expr::Bold(inner) => { - print!("Bold{{"); - for id in &inner.0 { - pool[*id].obj.print_tree(pool); - } - print!("}}"); - } - Expr::StrikeThrough(inner) => { - print!("StrikeThrough{{"); - for id in &inner.0 { - pool[*id].obj.print_tree(pool); - } - print!("}}"); - } - Expr::Underline(inner) => { - print!("Underline{{"); - for id in &inner.0 { - pool[*id].obj.print_tree(pool); - } - print!("}}"); - } - Expr::PlainList(inner) => { - print!("PlainList{{"); - for id in &inner.children { - pool[*id].obj.print_tree(pool); - } - print!("}}"); - } - Expr::BlankLine => print!("BlankLine"), - Expr::SoftBreak => print!("SoftBreak"), - Expr::LineBreak => print!("LineBreak"), - Expr::HorizontalRule => print!("HorizontalRule"), - Expr::Plain(inner) => print!("{inner:#?}"), - Expr::Verbatim(inner) => print!("{inner:#?}"), - Expr::Code(inner) => print!("{inner:#?}"), - Expr::Comment(inner) => print!("{inner:#?}"), - Expr::InlineSrc(inner) => print!("{inner:#?}"), - Expr::Keyword(inner) => print!("{inner:#?}"), - Expr::LatexEnv(inner) => print!("{inner:#?}"), - Expr::Item(inner) => { - print!("Item{{"); - for id in &inner.children { - pool[*id].obj.print_tree(pool); - } - print!("}}"); - } - Expr::PlainLink(inner) => print!("{inner:#?}"), - Expr::Entity(inner) => print!("{inner:#?}"), - Expr::Table(inner) => { - println!("Table{{"); - for id in &inner.children { - pool[*id].obj.print_tree(pool); - } - print!("\n}}"); - dbg!(inner); - } - - Expr::TableRow(inner) => { - if let TableRow::Standard(stans) = inner { - print!("|"); - for id in stans { - pool[*id].obj.print_tree(pool); - } - } else { - print!("h-rule"); - } - - println!(); - } - Expr::TableCell(inner) => { - for id in &inner.0 { - pool[*id].obj.print_tree(pool); - } - print!("|"); - } - Expr::Emoji(inner) => print!("{inner:#?}"), - Expr::Superscript(inner) => print!("{inner:#?}"), - Expr::Subscript(inner) => print!("{inner:#?}"), - Expr::Target(inner) => print!("{inner:#?}"), - Expr::Macro(inner) => print!("{inner:#?}"), - Expr::Drawer(inner) => print!("{inner:#?}"), - Expr::ExportSnippet(inner) => print!("{inner:#?}"), - Expr::Affiliated(inner) => match inner { - Affiliated::Name(_) => print!("{inner:#?}"), - Affiliated::Caption(i1) => { - // pool[i1.unwrap()].obj.print_tree(pool); - pool[*i1].obj.print_tree(pool); - } - Affiliated::Attr { - child_id, - backend, - val, - } => print!("{inner:#?}"), - }, - Expr::MacroDef(inner) => print!("{inner:#?}"), - Expr::FootnoteDef(inner) => print!("{inner:#?}"), - Expr::FootnoteRef(inner) => print!("{inner:#?}"), - } - } } #[allow(clippy::format_in_format_args)] diff --git a/crates/org-wasm/src/lib.rs b/crates/org-wasm/src/lib.rs index 5685a04..d168b9e 100644 --- a/crates/org-wasm/src/lib.rs +++ b/crates/org-wasm/src/lib.rs @@ -3,7 +3,7 @@ use org_exporter::ExportError; use org_exporter::Exporter; use org_exporter::Html; use org_exporter::Org; -use org_parser::{parse_org, Expr, Node, NodeID, NodePool}; +use org_parser::{Expr, Node, NodeID, NodePool, parse_org}; use wasm_bindgen::prelude::*; use js_sys::Int32Array;