fix tests

This commit is contained in:
philipp 2023-11-04 13:58:19 +01:00
parent febe7f63cb
commit 11d55ed379
2 changed files with 27 additions and 5 deletions

View File

@ -22,6 +22,24 @@ pub(crate) struct LawBuilder {
}
impl LawBuilder {
#[cfg(test)]
pub(crate) fn test(name: &str) -> Self {
let mut classifiers = Vec::new();
if name == "UrhG" {
let hauptstueck = Classifier::new("Hauptstück");
classifiers.push(hauptstueck.clone());
let mut abschnitt = Classifier::new("Abschnitt");
abschnitt.set_parent(hauptstueck);
classifiers.push(abschnitt);
}
Self {
name: name.into(),
classifiers,
cur_classifier_index: None,
}
}
pub(crate) fn new(name: &str) {
//TODO: return Law (not LawBuilder)
let mut classifiers = Vec::new();
@ -176,10 +194,10 @@ mod tests {
#[test]
fn test() {
let mut builder = LawBuilder::new("UrhG");
let mut builder = LawBuilder::test("UrhG");
builder.new_header("1. Hauptstück", None);
builder.new_header("2. Abschnitt", None);
builder.new_header("1. Hauptstück");
builder.new_header("2. Abschnitt");
builder.new_par(Content::Text("Mein erster Paragraph".into()));

View File

@ -316,6 +316,8 @@ impl Layoutdaten {
mod tests {
use std::{fs::File, io::Read};
use crate::law::Law;
use super::*;
#[test]
@ -324,7 +326,8 @@ mod tests {
let mut xml = String::new();
file.read_to_string(&mut xml).unwrap();
let risdok = Risdok::from_str(&xml);
let mut builder = LawBuilder::test("a");
let risdok = Risdok::from_str(&xml, &mut builder);
if risdok.is_err() {
println!("{:#?}", risdok.as_ref().err());
}
@ -350,8 +353,9 @@ mod tests {
let mut file = File::open("data/par/wucher7.xml").unwrap();
let mut xml = String::new();
file.read_to_string(&mut xml).unwrap();
let mut builder = LawBuilder::test("a");
let risdok = Risdok::from_str(&xml);
let risdok = Risdok::from_str(&xml, &mut builder);
if risdok.is_err() {
println!("{:#?}", risdok.as_ref().err());
}