Skip to main content

pddl_core/pretty_print/
timeless.rs

1//! Pretty-printing of the `:timeless` section.
2
3use crate::pretty_print::{sealed, PrettyRenderer};
4use crate::types::Timeless;
5use crate::visitor::{Accept, Visitor};
6use pretty::RcDoc;
7
8impl sealed::Sealed for Timeless {}
9
10impl Visitor<Timeless, RcDoc<'static>> for PrettyRenderer {
11    fn visit(&self, value: &Timeless) -> RcDoc<'static> {
12        if value.values().is_empty() {
13            return RcDoc::nil();
14        }
15        RcDoc::text("(:timeless")
16            .append(RcDoc::softline())
17            .append(RcDoc::intersperse(
18                value.values().iter().map(|lit| lit.accept(self)),
19                RcDoc::softline(),
20            ))
21            .nest(4)
22            .group()
23            .append(")")
24    }
25}
26
27#[cfg(test)]
28mod tests {
29    use super::*;
30    use crate::pretty_print::prettify;
31    use crate::visitor::Accept;
32    use assert2::check;
33
34    #[test]
35    fn timeless_empty_works() {
36        let t = Timeless::default();
37        check!(prettify!(t, 20) == "");
38    }
39
40    #[test]
41    fn timeless_non_empty_works() {
42        use crate::{AtomicFormula, Literal, Name};
43        let af =
44            AtomicFormula::new_predicate(crate::Predicate::new_string("p"), vec![Name::new("x")]);
45        let t = Timeless::new(vec![Literal::new(af)]);
46        check!(prettify!(t, 20) == "(:timeless (p x))");
47    }
48}