fix ci
This commit is contained in:
parent
5a238f6521
commit
93c43d3448
23
Cargo.lock
generated
23
Cargo.lock
generated
@ -47,6 +47,12 @@ dependencies = [
|
||||
"powerfmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "diff"
|
||||
version = "0.1.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.28"
|
||||
@ -132,6 +138,16 @@ version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||
|
||||
[[package]]
|
||||
name = "pretty_assertions"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66"
|
||||
dependencies = [
|
||||
"diff",
|
||||
"yansi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.69"
|
||||
@ -168,6 +184,7 @@ dependencies = [
|
||||
name = "risp"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"pretty_assertions",
|
||||
"roxmltree",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@ -451,3 +468,9 @@ name = "xmlparser"
|
||||
version = "0.13.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4"
|
||||
|
||||
[[package]]
|
||||
name = "yansi"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
|
||||
|
@ -11,3 +11,6 @@ time = { version = "0.3", features = [ "formatting" ] }
|
||||
serde = { version = "1.0", features = [ "derive" ] }
|
||||
serde_json = "1.0"
|
||||
roxmltree = "0.18"
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = "1.4"
|
||||
|
55
src/law.rs
55
src/law.rs
@ -1,24 +1,29 @@
|
||||
use crate::overview;
|
||||
|
||||
pub(crate) struct Law {
|
||||
name: String, //ABGB, UrhG
|
||||
section: Vec<Section>, // § 1, § 2, ...
|
||||
}
|
||||
// pub(crate) struct Law {
|
||||
// name: String, //ABGB, UrhG
|
||||
// section: Vec<Section>, // § 1, § 2, ...
|
||||
// }
|
||||
|
||||
impl Law {
|
||||
pub(crate) fn new(name: &str) -> Self {
|
||||
Self {
|
||||
name: name.into(),
|
||||
section: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
// impl Law {
|
||||
// pub(crate) fn new(name: &str) -> Self {
|
||||
// Self {
|
||||
// name: name.into(),
|
||||
// section: Vec::new(),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/// Is used to generate a law struct. It's organized mainly by classifier.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub(crate) struct LawBuilder {
|
||||
/// Name of the law
|
||||
name: String, //ABGB, UrhG
|
||||
|
||||
/// Structure of the law text
|
||||
classifiers: Vec<Classifier>,
|
||||
cur_classifier_index: Option<usize>,
|
||||
|
||||
/// Stores the header of the next paragraph
|
||||
next_para_header: Option<String>,
|
||||
}
|
||||
|
||||
@ -33,15 +38,19 @@ impl LawBuilder {
|
||||
let mut abschnitt = Classifier::new("Abschnitt");
|
||||
abschnitt.set_parent(hauptstueck);
|
||||
classifiers.push(abschnitt);
|
||||
} else if name == "no-headers" {
|
||||
let mut class = Classifier::new("");
|
||||
class.add_instance(ClassifierInstance::new(""));
|
||||
classifiers.push(class);
|
||||
}
|
||||
Self {
|
||||
name: name.into(),
|
||||
classifiers,
|
||||
cur_classifier_index: None,
|
||||
next_para_header: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new law builder. Adds classifier for known law texts.
|
||||
pub(crate) fn new(name: &str) {
|
||||
//TODO: return Law (not LawBuilder)
|
||||
let mut classifiers = Vec::new();
|
||||
@ -60,13 +69,13 @@ impl LawBuilder {
|
||||
let mut builder = Self {
|
||||
name: name.into(),
|
||||
classifiers,
|
||||
cur_classifier_index: None,
|
||||
next_para_header: None,
|
||||
};
|
||||
|
||||
overview::parse(law_id.unwrap(), &mut builder);
|
||||
}
|
||||
|
||||
/// Sets a new header.
|
||||
pub(crate) fn new_header(&mut self, name: &str) {
|
||||
let classifier_index = self
|
||||
.classifiers
|
||||
@ -75,26 +84,28 @@ impl LawBuilder {
|
||||
match classifier_index {
|
||||
Some(index) => {
|
||||
self.classifiers[index].add_instance(ClassifierInstance::new(name));
|
||||
self.cur_classifier_index = Some(index);
|
||||
}
|
||||
None => panic!("No classifier for {name}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets a new description for the last classifier.
|
||||
pub(crate) fn new_desc(&mut self, desc: &str) {
|
||||
if let Some(index) = self.cur_classifier_index {
|
||||
self.classifiers[index].set_desc(desc);
|
||||
if let Some(class) = self.classifiers.last_mut() {
|
||||
class.set_desc(desc);
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds a new paragraph.
|
||||
pub(crate) fn new_par(&mut self, par: Content) {
|
||||
if let Some(index) = self.cur_classifier_index {
|
||||
self.classifiers[index].add_par(par);
|
||||
if let Some(class) = self.classifiers.last_mut() {
|
||||
class.add_par(par);
|
||||
} else {
|
||||
panic!("Expected at least one classifier");
|
||||
}
|
||||
}
|
||||
|
||||
/// Next paragraph has a header, store its name.
|
||||
pub(crate) fn new_next_para_header(&mut self, header: &str) {
|
||||
self.next_para_header = Some(header.into());
|
||||
}
|
||||
@ -198,6 +209,7 @@ pub(crate) enum Content {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
@ -234,8 +246,7 @@ mod tests {
|
||||
}],
|
||||
},
|
||||
],
|
||||
cur_classifier_index: Some(1),
|
||||
next_para_header: Some("2. Abschnitt".into()),
|
||||
next_para_header: None,
|
||||
};
|
||||
assert_eq!(builder, expected);
|
||||
}
|
||||
|
@ -331,8 +331,6 @@ impl Layoutdaten {
|
||||
mod tests {
|
||||
use std::{fs::File, io::Read};
|
||||
|
||||
use crate::law::Law;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
@ -341,7 +339,7 @@ mod tests {
|
||||
let mut xml = String::new();
|
||||
file.read_to_string(&mut xml).unwrap();
|
||||
|
||||
let mut builder = LawBuilder::test("a");
|
||||
let mut builder = LawBuilder::test("no-headers");
|
||||
let risdok = Risdok::from_str(&xml, &mut builder);
|
||||
if risdok.is_err() {
|
||||
println!("{:#?}", risdok.as_ref().err());
|
||||
@ -364,7 +362,7 @@ 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 mut builder = LawBuilder::test("no-headers");
|
||||
|
||||
let risdok = Risdok::from_str(&xml, &mut builder);
|
||||
if risdok.is_err() {
|
||||
|
Loading…
Reference in New Issue
Block a user