restructure overview mod
All checks were successful
CI/CD Pipeline / test (push) Successful in 38s

This commit is contained in:
2024-02-05 12:02:47 +01:00
parent 9454b89d8e
commit 727916cb3f
9 changed files with 3 additions and 30166 deletions

View File

@ -2,4 +2,3 @@
pub mod overview;
pub mod paragraphs;
mod parser;

View File

@ -1,11 +1,13 @@
//! Deals with getting all paragraphs for a given law text
mod ris_structure;
use log::info;
use serde::Deserialize;
use crate::misc::{current_date, Error};
use super::parser::OgdSearchResult;
use ris_structure::OgdSearchResult;
/// Parses a law text from the Austrian RIS (Rechtsinformationssystem) based on the given `law_id`.
///
@ -60,15 +62,6 @@ struct Overview {
ogd_search_result: OgdSearchResult,
}
//TODO: Remove, as we don't want to test internals?
#[cfg(test)]
pub(crate) fn parse_from_str_test(
content: &str,
skip_first: bool,
) -> Result<(bool, Vec<String>), Error> {
parse_from_str(content, skip_first)
}
fn parse_from_str(content: &str, skip_first: bool) -> Result<(bool, Vec<String>), Error> {
let mut ret = Vec::new();
let wrapper: Overview = serde_json::from_str(content)?;

View File

@ -204,113 +204,3 @@ pub(crate) struct ContentUrlItem {
data_type: String,
url: String,
}
#[cfg(test)]
mod tests {
use std::{
fs::{self, File},
io::{self, BufRead, Read},
path::Path,
};
use log::debug;
use crate::risparser::overview::parse_from_str_test;
use super::*;
fn read_lines<P>(filename: P) -> io::Result<Vec<String>>
where
P: AsRef<Path>,
{
let file = File::open(filename)?;
let buf_reader = io::BufReader::new(file);
buf_reader.lines().collect()
}
//TODO: remove, as we don't want to test interal stuff?
#[derive(Deserialize)]
#[allow(dead_code)]
#[serde(rename_all = "PascalCase")]
pub(crate) struct Wrapper {
ogd_search_result: OgdSearchResult,
}
#[test]
fn deserialize_teg_success() {
let mut file = File::open("data/teg.json").unwrap();
let mut json = String::new();
file.read_to_string(&mut json).unwrap();
let wrapper: serde_json::Result<Wrapper> = serde_json::from_str(&json);
if wrapper.is_err() {
let dbg = wrapper.as_ref().err().unwrap();
debug!("{dbg:#?}");
}
assert!(wrapper.is_ok());
}
#[test]
fn deserialize_abgb_success() {
let mut file = File::open("data/abgb.json").unwrap();
let mut json = String::new();
file.read_to_string(&mut json).unwrap();
let wrapper: serde_json::Result<Wrapper> = serde_json::from_str(&json);
if wrapper.is_err() {
let dbg = wrapper.as_ref().err().unwrap();
debug!("{dbg:#?}");
}
assert!(wrapper.is_ok());
}
#[test]
fn deserialize_urhg_success() {
let mut file = File::open("data/urhg.json").unwrap();
let mut json = String::new();
file.read_to_string(&mut json).unwrap();
let wrapper: serde_json::Result<Wrapper> = serde_json::from_str(&json);
if wrapper.is_err() {
let dbg = wrapper.as_ref().err().unwrap();
debug!("{dbg:#?}");
}
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_test(&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);
}
}