|
| 1 | +use crate::nodes::{AstNode, NodeCode, NodeValue}; |
1 | 2 | use cm; |
2 | 3 | use html; |
3 | 4 | use propfuzz::prelude::*; |
@@ -95,6 +96,18 @@ macro_rules! html_opts { |
95 | 96 | }; |
96 | 97 | } |
97 | 98 |
|
| 99 | +fn asssert_node_eq<'a>(node: &'a AstNode<'a>, location: &[usize], expected: &NodeValue) { |
| 100 | + let node = location |
| 101 | + .iter() |
| 102 | + .fold(node, |node, &n| node.children().nth(n).unwrap()); |
| 103 | + |
| 104 | + let data = node.data.borrow(); |
| 105 | + let actual = format!("{:?}", data.value); |
| 106 | + let expected = format!("{:?}", expected); |
| 107 | + |
| 108 | + compare_strs(&actual, &expected, "ast comparison"); |
| 109 | +} |
| 110 | + |
98 | 111 | #[test] |
99 | 112 | fn basic() { |
100 | 113 | html( |
@@ -310,6 +323,27 @@ fn backticks() { |
310 | 323 | ); |
311 | 324 | } |
312 | 325 |
|
| 326 | +#[test] |
| 327 | +fn backticks_num() { |
| 328 | + let input = "Some `code1`. More ``` code2 ```.\n"; |
| 329 | + |
| 330 | + let arena = Arena::new(); |
| 331 | + let options = ComrakOptions::default(); |
| 332 | + let root = parse_document(&arena, input, &options); |
| 333 | + |
| 334 | + let code1 = NodeValue::Code(NodeCode { |
| 335 | + num_backticks: 1, |
| 336 | + literal: b"code1".to_vec(), |
| 337 | + }); |
| 338 | + asssert_node_eq(root, &[0, 1], &code1); |
| 339 | + |
| 340 | + let code2 = NodeValue::Code(NodeCode { |
| 341 | + num_backticks: 3, |
| 342 | + literal: b"code2".to_vec(), |
| 343 | + }); |
| 344 | + asssert_node_eq(root, &[0, 3], &code2); |
| 345 | +} |
| 346 | + |
313 | 347 | #[test] |
314 | 348 | fn backslashes() { |
315 | 349 | html( |
@@ -1065,9 +1099,9 @@ fn exercise_full_api() { |
1065 | 1099 |
|
1066 | 1100 | let _: String = ::Anchorizer::new().anchorize("header".to_string()); |
1067 | 1101 |
|
1068 | | - let _: &::nodes::AstNode = ::parse_document(&arena, "document", &default_options); |
| 1102 | + let _: &AstNode = ::parse_document(&arena, "document", &default_options); |
1069 | 1103 |
|
1070 | | - let _: &::nodes::AstNode = ::parse_document_with_broken_link_callback( |
| 1104 | + let _: &AstNode = ::parse_document_with_broken_link_callback( |
1071 | 1105 | &arena, |
1072 | 1106 | "document", |
1073 | 1107 | &default_options, |
@@ -1168,7 +1202,8 @@ fn exercise_full_api() { |
1168 | 1202 | ::nodes::NodeValue::SoftBreak => {} |
1169 | 1203 | ::nodes::NodeValue::LineBreak => {} |
1170 | 1204 | ::nodes::NodeValue::Code(code) => { |
1171 | | - let _: &Vec<u8> = code; |
| 1205 | + let _: usize = code.num_backticks; |
| 1206 | + let _: Vec<u8> = code.literal; |
1172 | 1207 | } |
1173 | 1208 | ::nodes::NodeValue::HtmlInline(html) => { |
1174 | 1209 | let _: &Vec<u8> = html; |
|
0 commit comments