crier

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs

commit 78331aed69f7cd81b2ac231e844585318e1b7ae1
parent 0d6e9f867e7da20181e3daeb867578e2e0e001d5
Author: lash <dev@holbrook.no>
Date:   Mon,  8 Jul 2024 22:26:39 +0100

Add xml parsing check on sequencing test

Diffstat:
MCargo.lock | 3+--
MCargo.toml | 9+++++----
Msrc/tests.rs | 146+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
3 files changed, 97 insertions(+), 61 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -38,7 +38,7 @@ dependencies = [ [[package]] name = "atom_syndication" version = "0.12.3" -source = "git+git://holbrook.no/contrib/atom_syndication?branch=lash/entry-to-xml#a18b2d44e6ea8cf397d85b2d7f360db029fe80ee" +source = "git+git://holbrook.no/contrib/atom_syndication?rev=fab6f733f6481ecfcbd6a76074f1038c79c854ae#fab6f733f6481ecfcbd6a76074f1038c79c854ae" dependencies = [ "chrono", "derive_builder", @@ -500,7 +500,6 @@ checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33" dependencies = [ "encoding_rs", "memchr", - "serde", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml @@ -23,17 +23,18 @@ itertools = "^0.13" serde = "^1.0" atom_syndication = "^0.12" -[dependencies.quick-xml] -version = "^0.31" -features = ["serialize"] +#[dependencies.quick-xml] +#version = "^0.31" +#features = ["serialize"] [patch.crates-io] #atom_syndication = { path = "/home/lash/src/contrib/atom_syndication" } -atom_syndication = { git = "git://holbrook.no/contrib/atom_syndication", branch="lash/entry-to-xml" } +atom_syndication = { git = "git://holbrook.no/contrib/atom_syndication", rev="fab6f733f6481ecfcbd6a76074f1038c79c854ae" } #branch="lash/entry-to-xml" } [dev-dependencies] tempfile = "3.3.0" mediatype = "^0.19" +quick-xml = "^0.31" [features] fs = [] diff --git a/src/tests.rs b/src/tests.rs @@ -1,5 +1,6 @@ use std::clone::Clone; use std::fs::File; +use std::str; use feed_rs::model::Entry; use feed_rs::model::Text; @@ -8,6 +9,8 @@ use chrono::DateTime; use tempfile::NamedTempFile; use tempfile::TempDir; use atom_syndication::Entry as OutEntry; +use quick_xml::Reader as XMLReader; +use quick_xml::events::Event as XMLEvent; use crate::Sequencer; use crate::io::FeedGet; @@ -17,54 +20,85 @@ use crate::io::fs::FsCache; use crate::io::fs::FsFeed; -//#[test] -//fn test_entry_guard() { -// let mut r: bool; -// let mut seq = Sequencer::new(); -// let mut src = Entry::default(); -// let mut s: String; -// -// src.id = String::from("foo"); -// s = String::from("inky"); -// src.title = Some(Text{ -// content_type: MediaTypeBuf::from_string(String::from("text/plain")).unwrap(), -// src: Some(s.clone()), -// content: s, -// -// }); -// -// //src.published = Some(DateTime::<Utc>::default()); -// src.published = Some(DateTime::parse_from_rfc3339("2024-06-25T20:46:00+02:00").unwrap().into()); -// r = seq.add(src); -// assert!(r); -// -// let mut src_two = Entry::default(); -// src_two.id = String::from("foo"); -// s = String::from("pinky"); -// src_two.title = Some(Text{ -// content_type: MediaTypeBuf::from_string(String::from("text/plain")).unwrap(), -// src: Some(s.clone()), -// content: s, -// -// }); -// src_two.published = Some(DateTime::parse_from_rfc3339("2024-06-25T20:46:00+02:00").unwrap().into()); -// r = seq.add(src_two); -// assert!(!r); -// -// let mut src_three = Entry::default(); -// src_three.id = String::from("foo"); -// s = String::from("blinky"); -// src_three.title = Some(Text{ -// content_type: MediaTypeBuf::from_string(String::from("text/plain")).unwrap(), -// src: Some(s.clone()), -// content: s, -// -// }); -// -// src_three.published = Some(DateTime::parse_from_rfc3339("2024-06-25T20:46:00+03:00").unwrap().into()); -// r = seq.add(src_three); -// assert!(r); -//} +fn check_xml_title(xml: Vec<u8>, title: &str) { + let mut rxml = XMLReader::from_str(str::from_utf8(&xml).unwrap()); + let mut xmlbuf = Vec::new(); + let mut state = 0; + loop { + match rxml.read_event_into(&mut xmlbuf) { + Err(e) => panic!("cant read back xml"), + Ok(XMLEvent::Eof) => break, + Ok(XMLEvent::Start(v)) => { + match v.name().as_ref() { + b"title" => { + state = 1; + }, + _ => { + state = 0 + }, + } + }, + Ok(XMLEvent::End(v)) => { + state = 0; + }, + Ok(XMLEvent::Text(v)) => { + if state > 0 { + assert_eq!(v.unescape().unwrap(), title); + } + }, + _ => (), + } + } +} + +#[test] +fn test_entry_guard() { + let mut r: bool; + let mut seq = Sequencer::new(); + let mut src = Entry::default(); + let mut s: String; + + src.id = String::from("foo"); + s = String::from("inky"); + src.title = Some(Text{ + content_type: MediaTypeBuf::from_string(String::from("text/plain")).unwrap(), + src: Some(s.clone()), + content: s, + + }); + + //src.published = Some(DateTime::<Utc>::default()); + src.published = Some(DateTime::parse_from_rfc3339("2024-06-25T20:46:00+02:00").unwrap().into()); + r = seq.add(src); + assert!(r); + + let mut src_two = Entry::default(); + src_two.id = String::from("foo"); + s = String::from("pinky"); + src_two.title = Some(Text{ + content_type: MediaTypeBuf::from_string(String::from("text/plain")).unwrap(), + src: Some(s.clone()), + content: s, + + }); + src_two.published = Some(DateTime::parse_from_rfc3339("2024-06-25T20:46:00+02:00").unwrap().into()); + r = seq.add(src_two); + assert!(!r); + + let mut src_three = Entry::default(); + src_three.id = String::from("foo"); + s = String::from("blinky"); + src_three.title = Some(Text{ + content_type: MediaTypeBuf::from_string(String::from("text/plain")).unwrap(), + src: Some(s.clone()), + content: s, + + }); + + src_three.published = Some(DateTime::parse_from_rfc3339("2024-06-25T20:46:00+03:00").unwrap().into()); + r = seq.add(src_three); + assert!(r); +} #[test] #[cfg(feature = "fs")] @@ -209,11 +243,13 @@ fn test_sequence_order() { // TODO find value where sort digest is reverse of lexical id r = seq.next().unwrap(); -// assert_eq!(r, Vec::from("b")); -// r = seq.next().unwrap(); -// assert_eq!(r, Vec::from("d")); -// r = seq.next().unwrap(); -// assert_eq!(r, Vec::from("y")); -// r = seq.next().unwrap(); -// assert_eq!(r, Vec::from("a")); + check_xml_title(r, "pinky"); + r = seq.next().unwrap(); + check_xml_title(r, "blinky"); + r = seq.next().unwrap(); + check_xml_title(r, "inky"); + r = seq.next().unwrap(); + check_xml_title(r, "clyde"); } + +