> = if skip_first {
+ Box::new(iter.skip(1))
+ } else {
+ Box::new(iter)
+ };
+ for par in boxed_iter {
+ ret.push(par);
+ //if !crate::par::parse(&par).unwrap() {
+ // return Ok(false);
+ //}
+ }
+
+ if !wrapper.ogd_search_result.has_next_page() {
+ return Ok((false, ret));
+ }
+ return Ok((true, ret));
}
diff --git a/src/overview/parser.rs b/src/overview/parser.rs
index d8deb3a..6fb911c 100644
--- a/src/overview/parser.rs
+++ b/src/overview/parser.rs
@@ -192,12 +192,27 @@ pub(crate) struct ContentUrlItem {
#[cfg(test)]
mod tests {
- use std::{fs::File, io::Read};
+ use std::{
+ fs::{self, File},
+ io::{self, BufRead, Read},
+ path::Path,
+ };
use log::debug;
+ use crate::{law::LawBuilder, overview::parse_from_str};
+
use super::*;
+ fn read_lines(filename: P) -> io::Result>
+ where
+ P: AsRef,
+ {
+ let file = File::open(filename)?;
+ let buf_reader = io::BufReader::new(file);
+ buf_reader.lines().collect()
+ }
+
#[derive(Deserialize)]
#[serde(rename_all = "PascalCase")]
pub(crate) struct Wrapper {
@@ -248,4 +263,37 @@ mod tests {
assert!(wrapper.is_ok());
}
+
+ #[test]
+ fn test_overview_full_urhg() {
+ let mut files = Vec::new();
+ let path = Path::new("./data/urhg/overview");
+ let mut entries: Vec<_> = fs::read_dir(path)
+ .unwrap()
+ .filter_map(|entry| entry.ok())
+ .collect();
+
+ entries.sort_by_key(|entry| entry.file_name());
+
+ let last_index = fs::read_dir(path).unwrap().count() - 1;
+ let mut skip = true;
+ for (idx, entry) in entries.into_iter().enumerate() {
+ let mut file = File::open(path.join(entry.file_name())).unwrap();
+ let mut json = String::new();
+ file.read_to_string(&mut json).unwrap();
+
+ let expected_continue = !(idx == last_index);
+ let (cont, cur_files) = parse_from_str(&json, skip).unwrap();
+ assert_eq!(cont, expected_continue);
+
+ for file in cur_files {
+ files.push(file);
+ }
+
+ skip = false;
+ }
+
+ let expected = read_lines(path.join("../overview.result")).unwrap();
+ assert_eq!(files, expected);
+ }
}
diff --git a/src/par/mod.rs b/src/par/mod.rs
index 0b089a7..d9da0b6 100644
--- a/src/par/mod.rs
+++ b/src/par/mod.rs
@@ -11,9 +11,12 @@ fn fetch_page(url: &str) -> Result {
pub(crate) fn parse(url: &str, builder: &mut LawBuilder) -> Result {
info!("Parsing {url}");
let xml = fetch_page(url)?;
+ parse_from_str(&xml, builder)
+}
+
+pub(crate) fn parse_from_str(xml: &str, builder: &mut LawBuilder) -> Result {
let xml = xml.replace("", "-"); // used e.g. in §11 Abs. 3 UrhG
- //
- //
+
let xml = xml.replace(
// in § 17 (2)
r#"(2) Einer Rundfunksendung steht es gleich, wenn ein Werk von einer im In- oder im Ausland gelegenen Stelle aus der Öffentlichkeit im Inland, ähnlich wie durch Rundfunk, aber mit Hilfe von Leitungen wahrnehmbar gemacht wird."#,