This commit is contained in:
parent
c92d72c580
commit
1933b47e46
@ -140,6 +140,12 @@ impl PartialEq for LawBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for LawBuilder {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl LawBuilder {
|
||||
/// Creates a new law builder. Adds classifier for known law texts.
|
||||
pub fn new() -> Self {
|
||||
|
@ -12,6 +12,12 @@ pub struct Parser {
|
||||
replace: Vec<(String, String)>,
|
||||
}
|
||||
|
||||
impl Default for Parser {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Parser {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
@ -33,7 +39,7 @@ impl Parser {
|
||||
info!("Parsing {url}");
|
||||
let xml = fetch(url)?;
|
||||
|
||||
let xml = xml.replace("\u{a0}", " ");
|
||||
let xml = xml.replace('\u{a0}', " ");
|
||||
|
||||
self.parse_from_str(&xml, builder)
|
||||
}
|
||||
@ -84,45 +90,13 @@ fn fetch(url: &str) -> Result<String, Error> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use std::{fs, sync::Arc};
|
||||
use std::{fs};
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
law::{
|
||||
responsible::{contains, starts_with_number},
|
||||
Classifier, LawBuilder,
|
||||
},
|
||||
risparser::paragraph::Parser,
|
||||
};
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
fn test(law_id: &str, builder: &mut LawBuilder, parser: Parser) {
|
||||
let paragraph_path = format!("./data/expected/overview/{law_id}");
|
||||
let expected_path = format!("./data/expected/par/{law_id}");
|
||||
|
||||
let pars =
|
||||
fs::read_to_string(paragraph_path).expect("Could not read file {paragraph_path}.");
|
||||
let pars = pars.trim().split('\n').collect::<Vec<&str>>();
|
||||
|
||||
for par in pars {
|
||||
println!("{par}");
|
||||
let cont = parser.parse(par, builder).unwrap();
|
||||
if !cont {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let actual = &builder.history;
|
||||
|
||||
println!("{actual:?}");
|
||||
|
||||
let expected = fs::read_to_string(&expected_path)
|
||||
.expect(&format!("Could not read file {expected_path}."));
|
||||
let expected = expected.trim().split('\n').collect::<Vec<&str>>();
|
||||
|
||||
assert_eq!(actual, &expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_configs_produce_expected_output() {
|
||||
let configs = fs::read_dir("./data/configs").expect("No folder with config files");
|
||||
@ -150,7 +124,7 @@ mod tests {
|
||||
let actual = &builder.history;
|
||||
|
||||
let expected = fs::read_to_string(&expected_path)
|
||||
.expect(&format!("Could not read file {expected_path}."));
|
||||
.unwrap_or_else(|_| panic!("Could not read file {expected_path}."));
|
||||
let expected = expected.trim().split('\n').collect::<Vec<&str>>();
|
||||
|
||||
assert_eq!(actual, &expected);
|
||||
|
Loading…
Reference in New Issue
Block a user