| 1 | use serde::Deserialize; |
| 2 | use teams_core::{card_markdown_to_html, 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 | } |
| 63 | |
| 64 | #[test] |
| 65 | fn card_markdown_adds_italic_and_mentions_to_the_message_dialect() { |
| 66 | assert_eq!( |
| 67 | card_markdown_to_html("_soft_ and *slanted* and **bold**"), |
| 68 | "<i>soft</i> and <i>slanted</i> and <b>bold</b>" |
| 69 | ); |
| 70 | assert_eq!( |
| 71 | card_markdown_to_html("hi <at>Ada & Co</at> <x>"), |
| 72 | "hi <at>Ada & Co</at> <x>" |
| 73 | ); |
| 74 | assert_eq!( |
| 75 | markdown_to_html("_soft_ <at>Ada</at>"), |
| 76 | "_soft_ <at>Ada</at>" |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | #[test] |
| 81 | fn card_markdown_keeps_snake_case_and_urls() { |
| 82 | assert_eq!( |
| 83 | card_markdown_to_html("my_var_name https://a.example/_x_/ [l](https://a.example/_y_)"), |
| 84 | "my_var_name https://a.example/_x_/ <a href=\"https://a.example/_y_\">l</a>" |
| 85 | ); |
| 86 | } |