BlueGit

ict rusty-teams

Files

rusty-teams / crates / core / tests / markdown.rs

markdown.rs

Initial commit
metis Daniel Däschle · pushed by metis · 7 weeks ago
06e0ae51 History
markdown.rs 1.4 KiB Download Raw
1use serde::Deserialize;
2use teams_core::markdown_to_html;
3
4#[derive(Deserialize)]
5struct Golden {
6 input: String,
7 expected: String,
8}
9
10#[test]
11fn matches_the_teams_chat_html() {
12 let goldens: Vec<Golden> =
13 serde_json::from_str(include_str!("fixtures/markdown_golden.json")).unwrap();
14 assert!(goldens.len() > 15);
15 for golden in goldens {
16 assert_eq!(
17 markdown_to_html(&golden.input),
18 golden.expected,
19 "input: {:?}",
20 golden.input
21 );
22 }
23}
24
25#[test]
26fn list_lines_become_a_list() {
27 assert_eq!(
28 markdown_to_html("- one\n- **two**"),
29 "<ul><li>one</li><li><b>two</b></li></ul>"
30 );
31}
32
33#[test]
34fn list_between_text_has_no_stray_breaks() {
35 assert_eq!(
36 markdown_to_html("intro\n- a\n- b\noutro"),
37 "intro<ul><li>a</li><li>b</li></ul>outro"
38 );
39}
40
41#[test]
42fn separate_lists_stay_separate() {
43 assert_eq!(
44 markdown_to_html("- a\ntext\n- b"),
45 "<ul><li>a</li></ul>text<ul><li>b</li></ul>"
46 );
47}
48
49#[test]
50fn list_marker_needs_a_space_and_line_start() {
51 assert_eq!(markdown_to_html("-a\nx - y"), "-a<br>x - y");
52}
53
54#[test]
55fn list_items_escape_html() {
56 assert_eq!(markdown_to_html("- <b>"), "<ul><li>&lt;b&gt;</li></ul>");
57}
58
59#[test]
60fn list_lines_inside_a_fence_stay_code() {
61 assert_eq!(markdown_to_html("```\n- a\n```"), "<pre>- a</pre>");
62}