File: content.rs

package info (click to toggle)
rust-atom-syndication 0.12.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 472 kB
  • sloc: xml: 199; makefile: 4
file content (96 lines) | stat: -rw-r--r-- 3,235 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
extern crate atom_syndication as atom;

use std::fs::File;
use std::io::BufReader;

use crate::atom::Feed;

macro_rules! feed {
    ($f:expr) => {{
        let file = File::open($f).unwrap();
        let reader = BufReader::new(file);
        Feed::read_from(reader).unwrap()
    }};
}

#[test]
fn content_src() {
    let feed = feed!("tests/data/content_src.xml");
    let content = feed.entries().first().unwrap().content().unwrap();
    assert_eq!(content.value(), None);
    assert_eq!(content.src(), Some("http://example.com/image.png"));
    assert_eq!(content.content_type(), Some("image/png"));
}

#[test]
fn content_text_cdata_escaped() {
    let feed = feed!("tests/data/content_text_cdata_escaped.xml");
    let content = feed.entries().first().unwrap().content().unwrap();
    assert_eq!(content.value(), Some("<p>Entry content</p>"));
    assert_eq!(content.content_type(), Some("text"));
}

#[test]
fn content_text_cdata() {
    let feed = feed!("tests/data/content_text_cdata.xml");
    let content = feed.entries().first().unwrap().content().unwrap();
    assert_eq!(content.value(), Some("<p>Entry content</p>"));
    assert_eq!(content.content_type(), Some("text"));
}

#[test]
fn content_text_html() {
    let feed = feed!("tests/data/content_text_html.xml");
    let content = feed.entries().first().unwrap().content().unwrap();
    assert_eq!(content.value(), Some("<p>Entry content</p>"));
    assert_eq!(content.content_type(), Some("html"));
}

#[test]
fn content_text_html_common_attributes() {
    let feed = feed!("tests/data/content_text_html_common.xml");
    let content = feed.entries().first().unwrap().content().unwrap();
    assert_eq!(content.base(), Some("http://example.com/blog/"));
    assert_eq!(
        content.value(),
        Some("<p>Entry content</p><a href=\"2021-05-51/article.html\">Read more</a>")
    );
    assert_eq!(content.content_type(), Some("html"));
}

#[test]
fn content_text_other() {
    let feed = feed!("tests/data/content_text_other.xml");
    let content = feed.entries().first().unwrap().content().unwrap();
    assert_eq!(content.value(), Some("RW50cnkgY29udGVudA=="));
    assert_eq!(content.content_type(), Some("application/octet-stream"));
}

#[test]
fn content_text_plain_escaped() {
    let feed = feed!("tests/data/content_text_plain_escaped.xml");
    let content = feed.entries().first().unwrap().content().unwrap();
    assert_eq!(content.value(), Some("<p>Entry content</p>"));
    assert_eq!(content.content_type(), Some("text"));
}

#[test]
fn content_text_plain() {
    let feed = feed!("tests/data/content_text_plain.xml");
    let content = feed.entries().first().unwrap().content().unwrap();
    assert_eq!(content.value(), Some("Entry content"));
    assert_eq!(content.content_type(), Some("text"));
}

#[test]
fn content_text_xhtml() {
    let feed = feed!("tests/data/content_text_xhtml.xml");
    let content = feed.entries().first().unwrap().content().unwrap();
    assert_eq!(
        content.value(),
        Some(
            r#"<div xmlns="http://www.w3.org/1999/xhtml"><p>Entry content <a href="https://example.com/">with a link</a> inside.</p></div>"#
        )
    );
    assert_eq!(content.content_type(), Some("xhtml"));
}