mirror of
https://gitlab.com/Anson-Projects/zine.git
synced 2025-07-26 16:21:22 +00:00
Use Custom Struct
This commit is contained in:
@@ -1,39 +1,15 @@
|
||||
use feed_rs::parser;
|
||||
use reqwest::blocking::get;
|
||||
use std::collections::HashSet;
|
||||
use std::fs;
|
||||
|
||||
// Function to read URLs from a file
|
||||
fn read_feed() -> Vec<String> {
|
||||
let binding = fs::read_to_string("feeds.txt").unwrap();
|
||||
fn read_feed(path: &str) -> Vec<String> {
|
||||
let binding = fs::read_to_string(path).unwrap();
|
||||
binding.lines().map(|s| s.to_owned()).collect()
|
||||
}
|
||||
|
||||
// Function to fetch and parse a feed, returning true if successful
|
||||
fn fetch_and_parse_feed(url: &str) -> bool {
|
||||
let content = match get(url) {
|
||||
Ok(response) => response.text().unwrap_or_default(),
|
||||
Err(_) => return false,
|
||||
};
|
||||
|
||||
parser::parse(content.as_bytes()).is_ok()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_that_urls_point_to_valid_feeds() {
|
||||
let urls = read_feed();
|
||||
|
||||
for url in urls {
|
||||
assert!(
|
||||
fetch_and_parse_feed(&url),
|
||||
"Feed at URL failed validation: {}",
|
||||
url
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_if_feeds_are_in_alphabetical_order() {
|
||||
let mut urls = read_feed();
|
||||
let mut urls = read_feed("feeds.txt");
|
||||
|
||||
if !urls.windows(2).all(|w| w[0] < w[1]) {
|
||||
println!("Sorted feeds.txt:");
|
||||
@@ -46,3 +22,10 @@ fn test_if_feeds_are_in_alphabetical_order() {
|
||||
panic!("feeds.txt was not sorted!")
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_if_feeds_lists_have_overlapping_feed() {
|
||||
let set1: HashSet<_> = read_feed("feeds.txt").into_iter().collect();
|
||||
let set2: HashSet<_> = read_feed("featured_feeds.txt").into_iter().collect();
|
||||
assert!(set1.is_disjoint(&set2));
|
||||
}
|
||||
|
Reference in New Issue
Block a user