1 extern crate html2md;
2 
3 use html2md::parse_html;
4 use pretty_assertions::assert_eq;
5 
6 #[test]
test_dumb()7 fn test_dumb() {
8     let md = parse_html("<p>CARTHAPHILUS</p>");
9     assert_eq!(md, "CARTHAPHILUS")
10 }
11 
12 #[test]
test_anchor()13 fn test_anchor() {
14     let md = parse_html(r#"<p><a href="http://ya.ru">APOSIMZ</a></p>"#);
15     assert_eq!(md, "[APOSIMZ](http://ya.ru)")
16 }
17 
18 #[test]
test_anchor2()19 fn test_anchor2() {
20     let md = parse_html(r#"<p><a href="http://ya.ru">APOSIMZ</a><a href="http://yandex.ru">SIDONIA</a></p>"#);
21     assert_eq!(md, "[APOSIMZ](http://ya.ru)[SIDONIA](http://yandex.ru)")
22 }
23 
24 #[test]
test_anchor3()25 fn test_anchor3() {
26     let md = parse_html(r#"<p><a href="http://ya.ru">APOSIMZ</a><p/><a href="http://yandex.ru">SIDONIA</a></p>"#);
27     assert_eq!(md, "\
28 [APOSIMZ](http://ya.ru)
29 
30 [SIDONIA](http://yandex.ru)")
31 }
32 
33 #[test]
test_image()34 fn test_image() {
35     let md = parse_html(r#"<p><a href="https://gitter.im/MARC-FS/Lobby?utm_source=badge&amp;utm_medium=badge&amp;utm_campaign=pr-badge&amp;utm_content=badge"><img src="https://img.shields.io/gitter/room/MARC-FS/MARC-FS.svg" alt="Gitter"></a><br>"#);
36     assert_eq!(md, "[![Gitter](https://img.shields.io/gitter/room/MARC-FS/MARC-FS.svg)](https://gitter.im/MARC-FS/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)")
37 }
38 
39 #[test]
test_escaping()40 fn test_escaping() {
41     let md = parse_html(r#"<p>*god*'s in his **heaven** - all is right with the __world__</p>"#);
42     assert_eq!(md, "\\*god\\*\'s in his \\*\\*heaven\\*\\* - all is right with the \\_\\_world\\_\\_")
43 }
44 
45 #[test]
test_escaping_mid_hyphens()46 fn test_escaping_mid_hyphens() {
47     let md = parse_html(r#"<h1>This is a header with-hyphen!</h1>"#);
48     assert_eq!(md, "This is a header with-hyphen!\n==========")
49 }
50 
51 #[test]
test_escaping_start_hyphens()52 fn test_escaping_start_hyphens() {
53     let md = parse_html(r#"<h1>- This is a header with starting hyphen!</h1>"#);
54     assert_eq!(md, "\\- This is a header with starting hyphen!\n==========")
55 }
56 
57 #[test]
test_escaping_start_sharp()58 fn test_escaping_start_sharp() {
59     let md = parse_html("<html># nothing to worry about</html>");
60     assert_eq!(md, "\\# nothing to worry about")
61 }
62 
63 /// Note: Also strips multiple spaces
64 #[test]
test_escaping_start_hyphens_space()65 fn test_escaping_start_hyphens_space() {
66     let md = parse_html(r#"<h1>   - This is a header with starting hyphen!</h1>"#);
67     assert_eq!(md, " \\- This is a header with starting hyphen!\n==========")
68 }
69 
70 #[test]
test_escaping_html_tags()71 fn test_escaping_html_tags() {
72     let md = parse_html(r#"xxxxxxx xx xxxxxxxxxxx: &lt;iframe src="xxxxxx_xx_xxxxxxxxxxx/embed/" allowfullscreen="" height="725" width="450"&gt;&lt;/iframe&gt;"#);
73     assert_eq!(md, r#"xxxxxxx xx xxxxxxxxxxx: \<iframe src="xxxxxx\_xx\_xxxxxxxxxxx/embed/" allowfullscreen="" height="725" width="450"\>\</iframe\>"#)
74 }
75 
76 #[test]
test_headers()77 fn test_headers() {
78     let md = parse_html(r#"<h1 id="marc-fs">MARC-FS</h1><p><a href="http://Mail.ru">Mail.ru</a> Cloud filesystem written for FUSE</p><h2 id="synopsis">Synopsis</h2>"#);
79     assert_eq!(md, "\
80 MARC-FS
81 ==========
82 
83 [Mail.ru](http://Mail.ru) Cloud filesystem written for FUSE
84 
85 Synopsis
86 ----------")
87 }
88 
89 #[test]
test_escaping_start_equal()90 fn test_escaping_start_equal() {
91     let md = parse_html(r#"<p>This is NOT a header!<br/>===========</p>"#);
92     assert_eq!(md, "This is NOT a header!  \n\\===========")
93 }
94 
95 /// Note: Also strips multiple spaces
96 #[test]
test_escaping_start_equal_space()97 fn test_escaping_start_equal_space() {
98     let md = parse_html(r#"<p>This is NOT a header!<br/>  ===========</p>"#);
99     assert_eq!(md, "This is NOT a header!  \n \\===========")
100 }
101 
102 #[test]
test_escaping_start_hyphen()103 fn test_escaping_start_hyphen() {
104     let md = parse_html(r#"<p>This is NOT a header!<br/>-------</p>"#);
105     assert_eq!(md, "This is NOT a header!  \n\\-------")
106 }
107 
108 /// Note: Also strips multiple spaces
109 #[test]
test_escaping_start_hyphen_space()110 fn test_escaping_start_hyphen_space() {
111     let md = parse_html(r#"<p>This is NOT a header!<br/>     -------</p>"#);
112     assert_eq!(md, "This is NOT a header!  \n \\-------")
113 }