pddl_core/parsers/structure/
problem_constraints_def.rs1use crate::parsers::error::R;
4use crate::parsers::sexpr::Node;
5use crate::parsers::{parse_pref_con_gd, prefix};
6use crate::types::ProblemConstraintsDef;
7
8pub(crate) fn parse_problem_constraints_def(node: &Node) -> R<ProblemConstraintsDef> {
10 prefix(node, ":constraints", |args| {
11 parse_pref_con_gd(args.next()?).map(ProblemConstraintsDef::new)
12 })
13}
14
15crate::parsers::impl_parser!(ProblemConstraintsDef => parse_problem_constraints_def);
16
17#[cfg(test)]
18mod tests {
19 use crate::parsers::UnwrapValue;
20 use assert2::check;
21
22 use crate::*;
23
24 #[test]
25 fn test_parse() {
26 let input = "(:constraints (preference test (and)))";
27 check!(
28 ProblemConstraintsDef::from_str(input).is_value(ProblemConstraintsDef::new(
29 PreferenceConstraintGoalDescriptions::preference(
30 Some("test".into()),
31 ConstraintGoalDescription::and([])
32 )
33 ))
34 );
35 }
36
37 #[test]
38 fn doc_example_0() {
39 let input = "(:constraints (preference test (and)))";
40 check!(
41 ProblemConstraintsDef::from_str(input).is_value(ProblemConstraintsDef::new(
42 PreferenceConstraintGoalDescriptions::preference(
43 Some("test".into()),
44 ConstraintGoalDescription::and([])
45 )
46 ))
47 );
48 }
49}