create more function in expect struct
All checks were successful
CI/CD Pipeline / test (push) Successful in 4m44s
All checks were successful
CI/CD Pipeline / test (push) Successful in 4m44s
This commit is contained in:
parent
256763425b
commit
4eac917f2a
@ -88,7 +88,7 @@ impl Abschnitt {
|
||||
break;
|
||||
}
|
||||
|
||||
assert_eq!(c.next(), None);
|
||||
Expect::empty(c.next());
|
||||
|
||||
ret.cont = true;
|
||||
ret
|
||||
|
@ -61,6 +61,25 @@ impl<'a> Expect<'a> {
|
||||
);
|
||||
self
|
||||
}
|
||||
|
||||
fn typ(self, value: &str) -> Self {
|
||||
if let Some(typ) = self.node.attribute("typ") {
|
||||
assert!(
|
||||
typ == value,
|
||||
"Expected 'typ' attribute to have value {value}, got {typ} on node ({self})"
|
||||
);
|
||||
} else {
|
||||
panic!("Expected 'typ' attribute on {self}");
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
fn empty(next: Option<Node<'_, '_>>) {
|
||||
if let Some(n) = next {
|
||||
let expect = Expect::from(&n);
|
||||
assert!(false, "Expected no more elements, got {expect}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Expect<'_> {
|
||||
@ -91,7 +110,7 @@ impl Risdok {
|
||||
}
|
||||
Layoutdaten::parse(c.next().unwrap());
|
||||
|
||||
assert_eq!(c.next(), None);
|
||||
Expect::empty(c.next());
|
||||
|
||||
true
|
||||
}
|
||||
@ -111,7 +130,7 @@ impl Metadaten {
|
||||
pub(crate) fn parse(n: Node) -> Self {
|
||||
Expect::from(&n).tag("metadaten");
|
||||
|
||||
assert_eq!(n.children().next(), None);
|
||||
Expect::empty(n.children().next());
|
||||
|
||||
Self {}
|
||||
}
|
||||
@ -127,7 +146,7 @@ impl Nutzdaten {
|
||||
|
||||
let ret = Abschnitt::parse(c.next().unwrap(), builder);
|
||||
|
||||
assert_eq!(c.next(), None);
|
||||
Expect::empty(c.next());
|
||||
|
||||
ret.cont
|
||||
}
|
||||
@ -165,7 +184,7 @@ impl Listelem {
|
||||
let text = c.next().unwrap().text().unwrap().into();
|
||||
|
||||
trace!("Parsed Listelem with text='{text}'");
|
||||
assert_eq!(c.next(), None);
|
||||
Expect::empty(c.next());
|
||||
|
||||
Self { symbol, text }
|
||||
}
|
||||
@ -271,7 +290,7 @@ impl Td {
|
||||
let mut c = n.children();
|
||||
let absatz = Absatz::parse(c.next().unwrap());
|
||||
|
||||
assert_eq!(c.next(), None);
|
||||
Expect::empty(c.next());
|
||||
|
||||
Self { absatz }
|
||||
}
|
||||
@ -350,7 +369,7 @@ impl AbsatzAbs {
|
||||
content: c.next().unwrap().text().unwrap().trim().into(),
|
||||
};
|
||||
|
||||
assert_eq!(c.next(), None);
|
||||
Expect::empty(c.next());
|
||||
|
||||
ret
|
||||
}
|
||||
@ -381,9 +400,7 @@ impl Ueberschrift {
|
||||
}
|
||||
|
||||
pub(crate) fn parse(n: Node, typ: &str) -> Self {
|
||||
Expect::from(&n).tag("ueberschrift");
|
||||
|
||||
assert_eq!(n.attribute("typ").unwrap(), typ);
|
||||
Expect::from(&n).tag("ueberschrift").typ(typ);
|
||||
|
||||
Self {
|
||||
content: n.text().unwrap().into(),
|
||||
@ -418,7 +435,7 @@ impl Layoutdaten {
|
||||
pub(crate) fn parse(n: Node) -> Self {
|
||||
Expect::from(&n).tag("layoutdaten");
|
||||
|
||||
assert_eq!(n.children().next(), None);
|
||||
Expect::empty(n.children().next());
|
||||
|
||||
Self {}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user