| 1 |
#![cfg(feature = "attributes")] |
| 2 |
|
| 3 |
use crate::tests::assert_ast_match; |
| 4 |
|
| 5 |
#[test] |
| 6 |
fn heading_with_attrs() { |
| 7 |
assert_ast_match!( |
| 8 |
[extension.header_attributes], |
| 9 |
"# Hi! {#greeting}\n", |
| 10 |
(document (1:1-1:17) [ |
| 11 |
(heading (1:1-1:17) {#greeting} [ |
| 12 |
(text (1:3-1:5) "Hi!") |
| 13 |
]) |
| 14 |
]) |
| 15 |
); |
| 16 |
|
| 17 |
assert_ast_match!( |
| 18 |
[extension.header_attributes], |
| 19 |
"## Yeww {.ok yeww=\"\\\"true\\\"\"} ##\n", |
| 20 |
(document (1:1-1:32) [ |
| 21 |
(heading (1:1-1:32) {.ok yeww="\"true\""} [ |
| 22 |
(text (1:4-1:7) "Yeww") |
| 23 |
]) |
| 24 |
]) |
| 25 |
); |
| 26 |
|
| 27 |
assert_ast_match!( |
| 28 |
[extension.header_attributes], |
| 29 |
"## Yeww ## {x=y x=y #a #b}\n", |
| 30 |
(document (1:1-1:26) [ |
| 31 |
(heading (1:1-1:26) {#b x="y" x="y"} [ |
| 32 |
(text (1:4-1:10) "Yeww ##") |
| 33 |
]) |
| 34 |
]) |
| 35 |
); |
| 36 |
|
| 37 |
assert_ast_match!( |
| 38 |
[extension.header_attributes], |
| 39 |
"Yeww {x=y x=y #a #b}\n" |
| 40 |
"====================\n", |
| 41 |
(document (1:1-2:20) [ |
| 42 |
(heading (1:1-2:20) {#b x="y" x="y"} [ |
| 43 |
(text (1:1-1:4) "Yeww") |
| 44 |
]) |
| 45 |
]) |
| 46 |
); |
| 47 |
} |
| 48 |
|
| 49 |
#[test] |
| 50 |
fn fenced_code_with_attrs() { |
| 51 |
assert_ast_match!( |
| 52 |
[extension.fenced_code_attributes], |
| 53 |
"```rust {#example}\n" |
| 54 |
"const fn dogs() -> ! { yay }\n" |
| 55 |
"```\n", |
| 56 |
(document (1:1-3:3) [ |
| 57 |
(code_block (1:1-3:3) info:"rust" {#example} "const fn dogs() -> ! { yay }\n") |
| 58 |
]) |
| 59 |
); |
| 60 |
|
| 61 |
// Pandoc does some weird language/first-class interpretative dance, |
| 62 |
// but I'm not yet convinced I want to do that. Let the formatter decide. |
| 63 |
assert_ast_match!( |
| 64 |
[extension.fenced_code_attributes], |
| 65 |
"```{.zig #truism}\n" |
| 66 |
"fn cats() noreturn { yay_too }\n" |
| 67 |
"```\n", |
| 68 |
(document (1:1-3:3) [ |
| 69 |
(code_block (1:1-3:3) info:"" {#truism .zig} "fn cats() noreturn { yay_too }\n") |
| 70 |
]) |
| 71 |
); |
| 72 |
} |
| 73 |
|
| 74 |
#[test] |
| 75 |
fn inline_code_with_attrs() { |
| 76 |
assert_ast_match!( |
| 77 |
[extension.inline_code_attributes], |
| 78 |
"Uhh `totally`{yea=so} hm.", |
| 79 |
(document (1:1-1:25) [ |
| 80 |
(paragraph (1:1-1:25) [ |
| 81 |
(text (1:1-1:4) "Uhh ") |
| 82 |
// There's probably someone out there depending on sourcepos not being this way. |
| 83 |
// But then again, if they enable attributes, it's on them! |
| 84 |
(code (1:5-1:21) {yea="so"} "totally") |
| 85 |
(text (1:22-1:25) " hm.") |
| 86 |
]) |
| 87 |
]) |
| 88 |
); |
| 89 |
|
| 90 |
// "Bart, can we stop for newlines?" |
| 91 |
// "I don't see why not." |
| 92 |
assert_ast_match!( |
| 93 |
[extension.inline_code_attributes], |
| 94 |
"`T1 Faker`{role=mid\n" |
| 95 |
" kda=\"0/0/0\"\n" |
| 96 |
" cs=120}\n", |
| 97 |
(document (1:1-3:9) [ |
| 98 |
(paragraph (1:1-3:9) [ |
| 99 |
(code (1:1-3:9) {role="mid" kda="0/0/0" cs="120"} "T1 Faker") |
| 100 |
]) |
| 101 |
]) |
| 102 |
); |
| 103 |
} |
| 104 |
|
| 105 |
#[test] |
| 106 |
fn links_and_images_with_attrs() { |
| 107 |
assert_ast_match!( |
| 108 |
[extension.link_attributes], |
| 109 |
"Incredible [Jhin](game){lies=true}.\n", |
| 110 |
(document (1:1-1:35) [ |
| 111 |
(paragraph (1:1-1:35) [ |
| 112 |
(text (1:1-1:11) "Incredible ") |
| 113 |
(link (1:12-1:34) {lies="true"} "game" [ |
| 114 |
(text (1:13-1:16) "Jhin") |
| 115 |
]) |
| 116 |
(text (1:35-1:35) ".") |
| 117 |
]) |
| 118 |
]) |
| 119 |
); |
| 120 |
|
| 121 |
assert_ast_match!( |
| 122 |
[extension.link_attributes], |
| 123 |
"Incredible {lies=true}.\n", |
| 124 |
(document (1:1-1:36) [ |
| 125 |
(paragraph (1:1-1:36) [ |
| 126 |
(text (1:1-1:11) "Incredible ") |
| 127 |
(image (1:12-1:35) {lies="true"} "game" [ |
| 128 |
(text (1:14-1:17) "Jhin") |
| 129 |
]) |
| 130 |
(text (1:36-1:36) ".") |
| 131 |
]) |
| 132 |
]) |
| 133 |
); |
| 134 |
} |