Skip to content

Commit

Permalink
(prost-build): Add tests for codeblock cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Silverstone <[email protected]>
  • Loading branch information
kinnison committed May 25, 2022
1 parent b0f6ebf commit 4b661f9
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions prost-build/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,48 @@ mod tests {
assert_eq!(t.expected, actual, "failed {}", t.name);
}
}

#[test]
fn test_codeblocks() {
struct TestCase {
name: &'static str,
input: &'static str,
#[allow(unused)]
cleanedup_expected: Vec<&'static str>,
}

let tests = vec![
TestCase {
name: "unlabelled_block",
input: " thingy\n",
cleanedup_expected: vec!["", "```text", "thingy", "```"],
},
TestCase {
name: "rust_block",
input: "```rust\nfoo.bar()\n```\n",
cleanedup_expected: vec!["", "```compile_fail", "foo.bar()", "```"],
},
TestCase {
name: "js_block",
input: "```javascript\nfoo.bar()\n```\n",
cleanedup_expected: vec!["", "```text,javascript", "foo.bar()", "```"],
},
];

for t in tests {
let loc = Location {
path: vec![],
span: vec![],
leading_comments: Some(t.input.into()),
trailing_comments: None,
leading_detached_comments: vec![],
};
let comments = Comments::from_location(&loc);
#[cfg(feature = "cleanup-markdown")]
let expected = t.cleanedup_expected;
#[cfg(not(feature = "cleanup-markdown"))]
let expected: Vec<&str> = t.input.lines().collect();
assert_eq!(expected, comments.leading, "failed {}", t.name);
}
}
}

0 comments on commit 4b661f9

Please sign in to comment.