move tests into new file

This commit is contained in:
Gabriel 2025-07-22 10:16:46 -04:00
parent 8c16e36582
commit 16bfecb1f8
3 changed files with 126 additions and 56 deletions

View file

@ -245,59 +245,4 @@ mod tests {
}
*/
#[cfg(test)]
mod tests {
mod example_data;
use crate::{itemize_content, process_content, tests::example_data::FEEDS,Content,Item};
fn get_feed(u: &str) -> rss::Channel {
rss::Channel::read_from(u.as_bytes()).unwrap()
}
#[test]
fn content_test(){
let example_text = Item::Text("Example.com".to_owned());
let example_link = Item::Link("https://example.com".to_owned(),[example_text].to_vec());
let result = process_content([example_link].to_vec());
println!("Items to content parse result:\n{:#?}",result);
}
#[test]
fn content_display() {
let feed = get_feed(example_data::GABE_ROCKS);
let content: Vec<_> = process_content(
itemize_content(feed.items.first().unwrap().content().unwrap())
);
println!("Content: {:#?}",content)
}
#[test]
fn itemize_feeds(){
let _ = FEEDS.map(|u|{
let feed = get_feed(u);
let results: Vec<_> = feed.items.into_iter().map(|item| {
itemize_content(&item.content.unwrap());
}).collect();
//let results: Vec<_> = itemize_content(u);
println!("Evaluated feed\nScanned {} items without errors",results.len())
});
}
#[test]
fn markdownify_feeds(){
let _ = FEEDS.map(|u|{
let feed = get_feed(u);
let results: Vec<_> = feed.items.into_iter().map(|item|{
process_content(
itemize_content(&item.content.unwrap())
);
}).collect();
println!("Processed {} items without errors",results.len())
});
}
}
mod tests;

67
src/tests.rs Normal file
View file

@ -0,0 +1,67 @@
mod example_data;
use super::*;
use example_data::*;
fn get_feed(u: &str) -> rss::Channel {
rss::Channel::read_from(u.as_bytes()).unwrap()
}
#[test]
fn fragments() {
for f in FRAGMENTS {
println!("Processing Fragment:{}",f);
let items = itemize_content(f);
let content = process_content(items);
println!("Content:\n{:#?}",content);
}
}
#[test]
fn content_test() {
let example_text = Item::Text("Example.com".to_owned());
let example_link = Item::Link("https://example.com".to_owned(), [example_text].to_vec());
let result = process_content([example_link].to_vec());
println!("Items to content parse result:\n{:#?}", result);
}
#[test]
fn content_display() {
let feed = get_feed(example_data::GABE_ROCKS);
let content: Vec<_> = process_content(itemize_content(
feed.items.first().unwrap().content().unwrap(),
));
println!("Content: {:#?}", content)
}
#[test]
fn itemize_feeds() {
let _ = FEEDS.map(|u| {
let feed = get_feed(u);
let results: Vec<_> = feed
.items
.into_iter()
.map(|item| {
itemize_content(&item.content.unwrap());
})
.collect();
//let results: Vec<_> = itemize_content(u);
println!(
"Evaluated feed\nScanned {} items without errors",
results.len()
)
});
}
#[test]
fn markdownify_feeds() {
let _ = FEEDS.map(|u| {
let feed = get_feed(u);
let results: Vec<_> = feed
.items
.into_iter()
.map(|item| {
process_content(itemize_content(&item.content.unwrap()));
})
.collect();
println!("Processed {} items without errors", results.len())
});
}

View file

@ -3,7 +3,65 @@ pub const FEEDS: [&str; 2] = [
GABE_ROCKS
];
pub const FRAGMENTS: [&str; 2] = [
SIMPLE_ARTICLE,
TABLE
];
pub const TABLE: &str = r#"
<table">
<tr>
<th colspan="4">
<h2 style="text-align: center;">Weight Tracker</h2>
</th>
</tr>
<tr>
<td><strong>Starting Weight</strong></td>
<td><strong>Current Weight</strong></td>
<td><strong>Weight Lost</strong></td>
<td><strong>Goal Weight</strong></td>
</tr>
<tr>
<td>576</td>
<td>373</td>
<td>203</td>
<td>15% BF</td>
</tr>
<tr>
<td colspan="4">
<h3 style="font-size:x-large;">2025 Goal: 200lbs in 2025 challenge</h3>
<div
style="border:3px solid var(--color-accent);align-items: flex-start;justify-content: flex-start;margin:5px;border-radius:15px;overflow: hidden;">
<div style="width:53%;padding:10px;background-color:var(--color-accent);color:black;font-weight: bolder;font-size:larger;">53%
</div>
</div>
<p style="margin:5px;text-align: left;width:fit-content;font-size:large;">This year's goal is to lose <strong>200lbs</strong> in 2025!<br>Current progress: <strong>106lbs</strong> out of 200!
<br>I'm catching up 🏃</p>
</td>
</tr>
<tr>
<td colspan="4" style="text-align: center;">Last updated: 2025-07-19</td>
</tr>
</table>
"#;
pub const SIMPLE_ARTICLE: &str = r#"
<p> Just some text here and a <a href="">link</a><br>
with a simple list for funzies:
<ul>
<li>First</li>
<li>Second</li>
<ul>
<li>Indented item</li>
</ul>
</ul>
<image src="https://example.com/photo.png">
<div>
<p>Some other stuff here</p>
</div>
"#;
pub const LSN: &str = r#"
<?xml-stylesheet href="/feed-style.xsl" type="text/xsl"?>