pddl_core/pretty_print/
name.rs1use crate::pretty_print::{sealed, PrettyRenderer};
4use crate::types::{FunctionSymbol, Name, Variable};
5use crate::visitor::Visitor;
6use pretty::RcDoc;
7
8impl sealed::Sealed for Name {}
9impl sealed::Sealed for Variable {}
10impl sealed::Sealed for FunctionSymbol {}
11
12impl Visitor<Name, RcDoc<'static>> for PrettyRenderer {
13 fn visit(&self, value: &Name) -> RcDoc<'static> {
14 RcDoc::text(value.to_string())
15 }
16}
17
18impl Visitor<Variable, RcDoc<'static>> for PrettyRenderer {
19 fn visit(&self, value: &Variable) -> RcDoc<'static> {
20 RcDoc::text(value.to_string())
21 }
22}
23
24impl Visitor<FunctionSymbol, RcDoc<'static>> for PrettyRenderer {
25 fn visit(&self, value: &FunctionSymbol) -> RcDoc<'static> {
26 RcDoc::text(value.to_string())
27 }
28}
29
30#[cfg(test)]
31mod tests {
32 use super::*;
33 use crate::pretty_print::prettify;
34 use crate::visitor::Accept;
35 use assert2::check;
36
37 #[test]
38 fn name_works() {
39 let x = Name::new("name");
40 check!(prettify!(x, 10) == "name");
41 }
42
43 #[test]
44 fn variable_works() {
45 let x = Variable::from("var");
46 check!(prettify!(x, 10) == "?var");
47 }
48
49 #[test]
50 fn function_symbol_works() {
51 let x = FunctionSymbol::from("fun-sym");
52 check!(prettify!(x, 10) == "fun-sym");
53 }
54}