File: unit.rs

package info (click to toggle)
rust-html2md 0.2.15-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 484 kB
  • sloc: makefile: 2
file content (117 lines) | stat: -rw-r--r-- 3,945 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
extern crate html2md;

use html2md::parse_html;
use pretty_assertions::assert_eq;

#[test]
fn test_dumb() {
    let md = parse_html("<p>CARTHAPHILUS</p>");
    assert_eq!(md, "CARTHAPHILUS")
}

#[test]
fn test_anchor() {
    let md = parse_html(r#"<p><a href="http://ya.ru">APOSIMZ</a></p>"#);
    assert_eq!(md, "[APOSIMZ](http://ya.ru)")
}

#[test]
fn test_anchor2() {
    let md = parse_html(r#"<p><a href="http://ya.ru">APOSIMZ</a><a href="http://yandex.ru">SIDONIA</a></p>"#);
    assert_eq!(md, "[APOSIMZ](http://ya.ru)[SIDONIA](http://yandex.ru)")
}

#[test]
fn test_anchor3() {
    let md = parse_html(r#"<p><a href="http://ya.ru">APOSIMZ</a><p/><a href="http://yandex.ru">SIDONIA</a></p>"#);
    assert_eq!(md, "[APOSIMZ](http://ya.ru)\n\n[SIDONIA](http://yandex.ru)")
}    

#[test]
fn test_anchor_with_name_attribute_is_preserved() {
    let md = parse_html(r#"<p><a name="part1"></a></p>"#);
    assert_eq!(md, r#"<a name="part1"></a>"#)
}

#[test]
fn test_image() {
    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>"#);
    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)")
}

#[test]
fn test_escaping() {
    let md = parse_html(r#"<p>*god*'s in his **heaven** - all is right with the __world__</p>"#);
    assert_eq!(md, "\\*god\\*\'s in his \\*\\*heaven\\*\\* - all is right with the \\_\\_world\\_\\_")
}

#[test]
fn test_escaping_mid_hyphens() {
    let md = parse_html(r#"<h1>This is a header with-hyphen!</h1>"#);
    assert_eq!(md, "This is a header with-hyphen!\n==========")
}

#[test]
fn test_escaping_start_hyphens() {
    let md = parse_html(r#"<h1>- This is a header with starting hyphen!</h1>"#);
    assert_eq!(md, "\\- This is a header with starting hyphen!\n==========")
}

#[test]
fn test_escaping_start_sharp() {
    let md = parse_html("<html># nothing to worry about</html>");
    assert_eq!(md, "\\# nothing to worry about")
}

/// Note: Also strips multiple spaces
#[test]
fn test_escaping_start_hyphens_space() {
    let md = parse_html(r#"<h1>   - This is a header with starting hyphen!</h1>"#);
    assert_eq!(md, " \\- This is a header with starting hyphen!\n==========")
}

#[test]
fn test_escaping_html_tags() {
    let md = parse_html(r#"xxxxxxx xx xxxxxxxxxxx: &lt;iframe src="xxxxxx_xx_xxxxxxxxxxx/embed/" allowfullscreen="" height="725" width="450"&gt;&lt;/iframe&gt;"#);
    assert_eq!(md, r#"xxxxxxx xx xxxxxxxxxxx: \<iframe src="xxxxxx\_xx\_xxxxxxxxxxx/embed/" allowfullscreen="" height="725" width="450"\>\</iframe\>"#)
}

#[test]
fn test_headers() {
    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>"#);
    assert_eq!(md, "\
MARC-FS
==========

[Mail.ru](http://Mail.ru) Cloud filesystem written for FUSE

Synopsis
----------")
}

#[test]
fn test_escaping_start_equal() {
    let md = parse_html(r#"<p>This is NOT a header!<br/>===========</p>"#);
    assert_eq!(md, "This is NOT a header!  \n\\===========")
}

/// Note: Also strips multiple spaces
#[test]
fn test_escaping_start_equal_space() {
    let md = parse_html(r#"<p>This is NOT a header!<br/>  ===========</p>"#);
    assert_eq!(md, "This is NOT a header!  \n \\===========")
}

#[test]
fn test_escaping_start_hyphen() {
    let md = parse_html(r#"<p>This is NOT a header!<br/>-------</p>"#);
    assert_eq!(md, "This is NOT a header!  \n\\-------")
}

/// Note: Also strips multiple spaces
#[test]
fn test_escaping_start_hyphen_space() {
    let md = parse_html(r#"<p>This is NOT a header!<br/>     -------</p>"#);
    assert_eq!(md, "This is NOT a header!  \n \\-------")
}