hammond-data::parser: Refactor Episode tests.

This commit is contained in:
Jordan Petridis 2017-12-26 13:40:52 +02:00
parent fde4bedce6
commit 933fec55a5
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6

View File

@ -222,43 +222,51 @@ mod tests {
Shaun King explains his call for a boycott of the NFL and talks about his \ Shaun King explains his call for a boycott of the NFL and talks about his \
campaign to bring violent neo-Nazis to justice. Rapper Open Mike Eagle \ campaign to bring violent neo-Nazis to justice. Rapper Open Mike Eagle \
performs."; performs.";
let i = new_episode(&firstitem, 0).unwrap();
assert_eq!(i.title(), "The Super Bowl of Racism"); let ep = new_episode(&firstitem, 0).unwrap();
assert_eq!( let expected = NewEpisodeBuilder::default()
i.uri(), .title("The Super Bowl of Racism")
Some("http://traffic.megaphone.fm/PPY6458293736.mp3") .uri(Some(String::from(
); "http://traffic.megaphone.fm/PPY6458293736.mp3",
assert_eq!(i.description(), Some(descr)); )))
assert_eq!(i.length(), Some(66738886)); .description(Some(String::from(descr)))
assert_eq!(i.guid(), Some("7df4070a-9832-11e7-adac-cb37b05d5e24")); .guid(Some(String::from("7df4070a-9832-11e7-adac-cb37b05d5e24")))
assert_eq!(i.published_date(), Some("Wed, 13 Sep 2017 10:00:00 +0000")); .published_date(Some(String::from("Wed, 13 Sep 2017 10:00:00 +0000")))
assert_eq!(i.epoch(), 1505296800); .length(Some(66738886))
.epoch(1505296800)
.duration(Some(4171))
.build()
.unwrap();
assert_eq!(ep, expected);
let second = channel.items().iter().nth(1).unwrap(); let second = channel.items().iter().nth(1).unwrap();
let i2 = new_episode(&second, 0).unwrap(); let ep = new_episode(&second, 0).unwrap();
let descr2 = "This week on Intercepted: Jeremy gives an update on the aftermath of \ let descr = "This week on Intercepted: Jeremy gives an update on the aftermath of \
Blackwaters 2007 massacre of Iraqi civilians. Intercept reporter Lee Fang \ Blackwaters 2007 massacre of Iraqi civilians. Intercept reporter Lee Fang \
lays out how a network of libertarian think tanks called the Atlas Network \ lays out how a network of libertarian think tanks called the Atlas Network \
is insidiously shaping political infrastructure in Latin America. We speak \ is insidiously shaping political infrastructure in Latin America. We speak \
with attorney and former Hugo Chavez adviser Eva Golinger about the \ with attorney and former Hugo Chavez adviser Eva Golinger about the \
Venezuela\'s political turmoil.And we hear Claudia Lizardo of the \ Venezuela\'s political turmoil.And we hear Claudia Lizardo of the \
Caracas-based band, La Pequeña Revancha, talk about her music and hopes for \ Caracas-based band, La Pequeña Revancha, talk about her music and hopes for \
Venezuela."; Venezuela.";
assert_eq!(
i2.title(), let expected = NewEpisodeBuilder::default()
"Atlas Golfed — U.S.-Backed Think Tanks Target Latin America" .title("Atlas Golfed — U.S.-Backed Think Tanks Target Latin America")
); .uri(Some(String::from(
assert_eq!( "http://traffic.megaphone.fm/FL5331443769.mp3",
i2.uri(), )))
Some("http://traffic.megaphone.fm/FL5331443769.mp3") .description(Some(String::from(descr)))
); .guid(Some(String::from("7c207a24-e33f-11e6-9438-eb45dcf36a1d")))
assert_eq!(i2.description(), Some(descr2)); .published_date(Some(String::from("Wed, 9 Aug 2017 10:00:00 +0000")))
assert_eq!(i2.length(), Some(67527575)); .length(Some(67527575))
assert_eq!(i2.guid(), Some("7c207a24-e33f-11e6-9438-eb45dcf36a1d")); .epoch(1502272800)
assert_eq!(i2.published_date(), Some("Wed, 9 Aug 2017 10:00:00 +0000")); .duration(Some(4220))
assert_eq!(i2.epoch(), 1502272800); .build()
.unwrap();
assert_eq!(ep, expected);
} }
#[test] #[test]
@ -269,53 +277,52 @@ mod tests {
let firstitem = channel.items().first().unwrap(); let firstitem = channel.items().first().unwrap();
let descr = "<p>A reporter finds that homes meant to replace New Yorks troubled \ let descr = "<p>A reporter finds that homes meant to replace New Yorks troubled \
psychiatric hospitals might be just as bad.</p>"; psychiatric hospitals might be just as bad.</p>";
let i = new_episode(&firstitem, 0).unwrap(); let ep = new_episode(&firstitem, 0).unwrap();
assert_eq!( let expected = NewEpisodeBuilder::default()
i.title(), .title("The Breakthrough: Hopelessness and Exploitation Inside Homes for Mentally Ill")
"The Breakthrough: Hopelessness and Exploitation Inside Homes for Mentally Ill" .uri(Some(String::from("http://tracking.feedpress.it/link/10581/6726758/20170908-cliff-levy.mp3")))
); .description(Some(String::from(descr)))
assert_eq!( .guid(Some(String::from("https://www.propublica.org/podcast/\
i.uri(), the-breakthrough-hopelessness-exploitation-homes-for-mentally-ill#134472")))
Some("http://tracking.feedpress.it/link/10581/6726758/20170908-cliff-levy.mp3") .published_date(Some(String::from("Fri, 8 Sep 2017 12:00:00 +0000")))
); .length(Some(33396551))
assert_eq!(i.description(), Some(descr)); .epoch(1504872000)
assert_eq!(i.length(), Some(33396551)); .duration(Some(1670))
assert_eq!( .build()
i.guid(), .unwrap();
Some(
"https://www.propublica.org/podcast/\ assert_eq!(ep, expected);
the-breakthrough-hopelessness-exploitation-homes-for-mentally-ill#134472"
)
);
assert_eq!(i.published_date(), Some("Fri, 8 Sep 2017 12:00:00 +0000"));
assert_eq!(i.epoch(), 1504872000);
let second = channel.items().iter().nth(1).unwrap(); let second = channel.items().iter().nth(1).unwrap();
let i2 = new_episode(&second, 0).unwrap(); let ep = new_episode(&second, 0).unwrap();
let descr2 = "<p>Jonathan Allen and Amie Parnes didnt know their book would be called \ let descr =
Shattered, or that their extraordinary access would let them chronicle \ "<p>Jonathan Allen and Amie Parnes didnt know their book would be called \
the mounting signs of a doomed campaign.</p>"; Shattered, or that their extraordinary access would let them chronicle the \
mounting signs of a doomed campaign.</p>";
assert_eq!( let expected =
i2.title(), NewEpisodeBuilder::default()
"The Breakthrough: Behind the Scenes of Hillary Clintons Failed Bid for President" .title(
); "The Breakthrough: Behind the Scenes of Hillary Clintons Failed Bid for \
assert_eq!( President",
i2.uri(), )
Some("http://tracking.feedpress.it/link/10581/6726759/16_JohnAllen-CRAFT.mp3") .uri(Some(String::from(
); "http://tracking.feedpress.it/link/10581/6726759/16_JohnAllen-CRAFT.mp3",
assert_eq!(i2.description(), Some(descr2)); )))
assert_eq!(i2.length(), Some(17964071)); .description(Some(String::from(descr)))
assert_eq!( .guid(Some(String::from(
i2.guid(), "https://www.propublica.\
Some( org/podcast/the-breakthrough-hillary-clinton-failed-presidential-bid#133721",
"https://www.propublica.\ )))
org/podcast/the-breakthrough-hillary-clinton-failed-presidential-bid#133721" .published_date(Some(String::from("Fri, 25 Aug 2017 12:00:00 +0000")))
) .length(Some(17964071))
); .epoch(1503662400)
assert_eq!(i2.published_date(), Some("Fri, 25 Aug 2017 12:00:00 +0000")); .duration(Some(1125))
assert_eq!(i2.epoch(), 1503662400); .build()
.unwrap();
assert_eq!(ep, expected);
} }
#[test] #[test]
@ -328,38 +335,49 @@ mod tests {
decides to blow off a little steam by attacking his IoT devices, Wes has the \ decides to blow off a little steam by attacking his IoT devices, Wes has the \
scope on Equifax blaming open source &amp; the Beard just saved the show. \ scope on Equifax blaming open source &amp; the Beard just saved the show. \
Its a really packed episode!"; Its a really packed episode!";
let i = new_episode(&firstitem, 0).unwrap(); let ep = new_episode(&firstitem, 0).unwrap();
assert_eq!(i.title(), "Hacking Devices with Kali Linux | LUP 214"); let expected = NewEpisodeBuilder::default()
assert_eq!( .title("Hacking Devices with Kali Linux | LUP 214")
i.uri(), .uri(Some(String::from(
Some("http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0214.mp3") "http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0214.mp3",
); )))
assert_eq!(i.description(), Some(descr)); .description(Some(String::from(descr)))
assert_eq!(i.length(), Some(46479789)); .guid(Some(String::from("78A682B4-73E8-47B8-88C0-1BE62DD4EF9D")))
assert_eq!(i.guid(), Some("78A682B4-73E8-47B8-88C0-1BE62DD4EF9D")); .published_date(Some(String::from("Tue, 12 Sep 2017 22:24:42 -0700")))
assert_eq!(i.published_date(), Some("Tue, 12 Sep 2017 22:24:42 -0700")); .length(Some(46479789))
assert_eq!(i.epoch(), 1505280282); .epoch(1505280282)
.duration(Some(5733))
.build()
.unwrap();
assert_eq!(ep, expected);
let second = channel.items().iter().nth(1).unwrap(); let second = channel.items().iter().nth(1).unwrap();
let i2 = new_episode(&second, 0).unwrap(); let ep = new_episode(&second, 0).unwrap();
let descr2 = "<p>The Gnome project is about to solve one of our audience's biggest \ let descr = "<p>The Gnome project is about to solve one of our audience's biggest \
Waylands concerns. But as the project takes on a new level of relevance, \ Waylands concerns. But as the project takes on a new level of relevance, \
decisions for the next version of Gnome have us worried about the \ decisions for the next version of Gnome have us worried about the \
future.</p>\n<p>Plus we chat with Wimpy about the Ubuntu Rally in NYC, \ future.</p>\n<p>Plus we chat with Wimpy about the Ubuntu Rally in NYC, \
Microsofts sneaky move to turn Windows 10 into the ULTIMATE LINUX \ Microsofts sneaky move to turn Windows 10 into the ULTIMATE LINUX \
RUNTIME, community news &amp; more!</p>"; RUNTIME, community news &amp; more!</p>";
assert_eq!(i2.title(), "Gnome Does it Again | LUP 213");
assert_eq!( let expected = NewEpisodeBuilder::default()
i2.uri(), .title("Gnome Does it Again | LUP 213")
Some("http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0213.mp3") .uri(Some(String::from(
); "http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0213.mp3",
assert_eq!(i2.description(), Some(descr2)); )))
assert_eq!(i2.length(), Some(36544272)); .description(Some(String::from(descr)))
assert_eq!(i2.guid(), Some("1CE57548-B36C-4F14-832A-5D5E0A24E35B")); .guid(Some(String::from("1CE57548-B36C-4F14-832A-5D5E0A24E35B")))
assert_eq!(i2.published_date(), Some("Tue, 5 Sep 2017 20:57:27 -0700")); .published_date(Some(String::from("Tue, 5 Sep 2017 20:57:27 -0700")))
assert_eq!(i2.epoch(), 1504670247); .length(Some(36544272))
.epoch(1504670247)
.duration(Some(4491))
.build()
.unwrap();
assert_eq!(ep, expected);
} }
#[test] #[test]
@ -370,47 +388,51 @@ mod tests {
let firstitem = channel.items().iter().nth(9).unwrap(); let firstitem = channel.items().iter().nth(9).unwrap();
let descr = "This week we look at <a href=\"https://github.com/rust-lang/rfcs/pull/2094\" \ let descr = "This week we look at <a href=\"https://github.com/rust-lang/rfcs/pull/2094\" \
rel=\"noopener noreferrer\">RFC 2094</a> \"Non-lexical lifetimes\""; rel=\"noopener noreferrer\">RFC 2094</a> \"Non-lexical lifetimes\"";
let i = new_episode(&firstitem, 0).unwrap(); let ep = new_episode(&firstitem, 0).unwrap();
assert_eq!(i.title(), "Episode #9 - A Once in a Lifetime RFC"); let expected = NewEpisodeBuilder::default()
assert_eq!( .title("Episode #9 - A Once in a Lifetime RFC")
i.uri(), .uri(Some(String::from(
Some(
"http://request-for-explanation.github.\ "http://request-for-explanation.github.\
io/podcast/ep9-a-once-in-a-lifetime-rfc/episode.mp3" io/podcast/ep9-a-once-in-a-lifetime-rfc/episode.mp3",
) )))
); .description(Some(String::from(descr)))
assert_eq!(i.description(), Some(descr)); .guid(Some(String::from(
assert_eq!(i.length(), Some(15077388)); "https://request-for-explanation.github.io/podcast/ep9-a-once-in-a-lifetime-rfc/",
assert_eq!( )))
i.guid(), .published_date(Some(String::from("Mon, 28 Aug 2017 15:00:00 -0700")))
Some("https://request-for-explanation.github.io/podcast/ep9-a-once-in-a-lifetime-rfc/") .length(Some(15077388))
); .epoch(1503957600)
assert_eq!(i.published_date(), Some("Mon, 28 Aug 2017 15:00:00 -0700")); .duration(Some(2533))
assert_eq!(i.epoch(), 1503957600); .build()
.unwrap();
assert_eq!(ep, expected);
let second = channel.items().iter().nth(8).unwrap(); let second = channel.items().iter().nth(8).unwrap();
let i2 = new_episode(&second, 0).unwrap(); let ep = new_episode(&second, 0).unwrap();
let descr2 = "This week we look at <a \ let descr = "This week we look at <a href=\"https://github.com/rust-lang/rfcs/pull/2071\" \
href=\"https://github.com/rust-lang/rfcs/pull/2071\" rel=\"noopener \ rel=\"noopener noreferrer\">RFC 2071</a> \"Add impl Trait type alias and \
noreferrer\">RFC 2071</a> \"Add impl Trait type alias and variable \ variable declarations\"";
declarations\"";
assert_eq!(i2.title(), "Episode #8 - An Existential Crisis"); let expected = NewEpisodeBuilder::default()
assert_eq!( .title("Episode #8 - An Existential Crisis")
i2.uri(), .uri(Some(String::from(
Some(
"http://request-for-explanation.github.\ "http://request-for-explanation.github.\
io/podcast/ep8-an-existential-crisis/episode.mp3" io/podcast/ep8-an-existential-crisis/episode.mp3",
) )))
); .description(Some(String::from(descr)))
assert_eq!(i2.description(), Some(descr2)); .guid(Some(String::from(
assert_eq!(i2.length(), Some(13713219)); "https://request-for-explanation.github.io/podcast/ep8-an-existential-crisis/",
assert_eq!( )))
i2.guid(), .published_date(Some(String::from("Tue, 15 Aug 2017 17:00:00 -0700")))
Some("https://request-for-explanation.github.io/podcast/ep8-an-existential-crisis/") .length(Some(13713219))
); .epoch(1502841600)
assert_eq!(i2.published_date(), Some("Tue, 15 Aug 2017 17:00:00 -0700")); .duration(Some(2313))
assert_eq!(i2.epoch(), 1502841600); .build()
.unwrap();
assert_eq!(ep, expected);
} }
} }