#![allow(
dead_code,
reason = "each test crate uses a different subset of the helpers"
)]
use feedparser_rs::{FeedError, ItunesFeedMeta, ParsedFeed, Result, parse};
const NS: &str = r#"xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/" xmlns:content="http://purl.org/rss/1.0/modules/content/""#;
pub fn rss(channel: &str) -> Result<ParsedFeed> {
parse(format!(r#"<rss version="2.0" {NS}><channel>{channel}</channel></rss>"#).as_bytes())
}
pub fn item(body: &str) -> Result<ParsedFeed> {
rss(&format!("<item>{body}</item>"))
}
pub fn atom(body: &str) -> Result<ParsedFeed> {
parse(format!(r#"<feed xmlns="http://www.w3.org/2005/Atom" {NS}>{body}</feed>"#).as_bytes())
}
pub fn entry(body: &str) -> Result<ParsedFeed> {
atom(&format!("<entry>{body}</entry>"))
}
pub fn rdf(channel: &str) -> Result<ParsedFeed> {
parse(
format!(
r#"<rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" {NS}><channel rdf:about="http://example.com/">{channel}</channel></rdf:RDF>"#
)
.as_bytes(),
)
}
pub fn feed_itunes(feed: &ParsedFeed) -> Result<&ItunesFeedMeta> {
feed.feed
.itunes
.as_deref()
.ok_or_else(|| FeedError::Unknown("feed.itunes is missing".into()))
}