| 1 | use serde::Deserialize; |
| 2 | use teams_core::markdown_to_html; |
| 3 | |
| 4 | #[derive(Deserialize)] |
| 5 | struct Golden { |
| 6 | input: String, |
| 7 | expected: String, |
| 8 | } |
| 9 | |
| 10 | #[test] |
| 11 | fn 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] |
| 26 | fn 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] |
| 34 | fn 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] |
| 42 | fn 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] |
| 50 | fn 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] |
| 55 | fn list_items_escape_html() { |
| 56 | assert_eq!(markdown_to_html("- <b>"), "<ul><li><b></li></ul>"); |
| 57 | } |
| 58 | |
| 59 | #[test] |
| 60 | fn list_lines_inside_a_fence_stay_code() { |
| 61 | assert_eq!(markdown_to_html("```\n- a\n```"), "<pre>- a</pre>"); |
| 62 | } |