Skip to content

Commit

Permalink
Increase code coverage on parsers further
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsided committed May 19, 2024
1 parent 6c68a47 commit 77eb56d
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 14 deletions.
10 changes: 9 additions & 1 deletion src/parsers/con_gd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,15 @@ mod tests {
let input = "(within 10 (at-most-once (= x y)))";
assert!(ConGD::parse(input).is_value(ConGD::new_within(
Number::from(10),
Con2GD::new_nested(ConGD::new_at_most_once(Con2GD::new_goal(gd)))
Con2GD::new_nested(ConGD::new_at_most_once(Con2GD::new_goal(gd.clone())))
)));

let input = "(within 10 (at-most-once (= x y)))";
assert!(
Con2GD::parse(input).is_value(Con2GD::Nested(Box::new(ConGD::new_within(
Number::from(10),
Con2GD::new_nested(ConGD::new_at_most_once(Con2GD::new_goal(gd)))
))))
);
}
}
3 changes: 2 additions & 1 deletion src/parsers/da_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl crate::parsers::Parser for DurativeActionDefinition {
#[cfg(test)]
mod tests {
use super::*;
use crate::Parser;

#[test]
fn it_works() {
Expand Down Expand Up @@ -134,6 +135,6 @@ mod tests {
(at end (increase (distance-travelled) 5))
)
)"#;
let (_, _gd) = parse_da_def(Span::new(input)).unwrap();
let (_, _gd) = DurativeActionDefinition::parse(Span::new(input)).unwrap();
}
}
13 changes: 13 additions & 0 deletions src/parsers/function_typed_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,18 @@ mod tests {
)])
)
)])));

assert!(function_typed_list(parse_atomic_function_skeleton)(
"(move ?from ?to - location)".into()
)
.is_value(FunctionTypedList::from_iter([FunctionTyped::new_number(
AtomicFunctionSkeleton::new(
FunctionSymbol::from_str("move"),
TypedList::from_iter([
Typed::new(Variable::from("from"), Type::Exactly("location".into())),
Typed::new(Variable::from("to"), Type::Exactly("location".into()))
])
)
)])));
}
}
7 changes: 7 additions & 0 deletions src/parsers/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl crate::parsers::Parser for Number {
mod tests {
use crate::parsers::number::parse_decimal;
use crate::parsers::{Match, Span};
use crate::{Number, Parser};

#[test]
fn parse_decimal_works() {
Expand All @@ -56,4 +57,10 @@ mod tests {
assert!(parse_decimal(Span::new(".")).is_err());
assert!(parse_decimal(Span::new("012")).is_err());
}

#[test]
fn test_parse() {
let (_, value) = Number::parse("1.20").unwrap();
assert_eq!(value, Number::from(1.2));
}
}
12 changes: 5 additions & 7 deletions src/parsers/objects_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,16 @@ impl crate::parsers::Parser for Objects {
#[cfg(test)]
mod test {
use crate::parsers::UnwrapValue;
use crate::{Name, ToTyped, Type};
use crate::{Name, Parser, ToTyped, Type};

use super::*;

#[test]
fn test_parse() {
let input = "(:objects train1 train2)";
assert!(
parse_problem_objects_declaration(input).is_value(Objects::new([
Name::new("train1").to_typed(Type::OBJECT),
Name::new("train2").to_typed(Type::OBJECT),
]))
);
assert!(Objects::parse(input).is_value(Objects::new([
Name::new("train1").to_typed(Type::OBJECT),
Name::new("train2").to_typed(Type::OBJECT),
])));
}
}
21 changes: 19 additions & 2 deletions src/parsers/requirements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ impl crate::parsers::Parser for Requirement {
#[cfg(test)]
mod tests {
use crate::parsers::preamble::*;
use crate::Requirement;
use crate::{Requirement, Requirements};

#[test]
fn test_parse() {
fn test_parse_requirement() {
assert!(Requirement::parse(":strips").is_value(Requirement::Strips));
assert!(Requirement::parse(":typing").is_value(Requirement::Typing));
assert!(Requirement::parse(":negative-preconditions")
Expand Down Expand Up @@ -141,4 +141,21 @@ mod tests {
assert!(Requirement::parse(":unknown").is_err());
assert!(Requirement::parse("invalid").is_err());
}

#[test]
fn test_parse_requirements() {
assert!(Requirements::parse("(:requirements :adl)")
.is_value(Requirements::new([Requirement::Adl])));
assert!(
Requirements::parse("(:requirements :strips :typing)").is_value(Requirements::new([
Requirement::Strips,
Requirement::Typing
]))
);
assert!(
Requirements::parse("(:requirements\n:strips :typing )").is_value(
Requirements::new([Requirement::Strips, Requirement::Typing])
)
);
}
}
6 changes: 3 additions & 3 deletions src/parsers/time_specifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ impl crate::parsers::Parser for TimeSpecifier {
#[cfg(test)]
mod tests {
use crate::parsers::{parse_time_specifier, UnwrapValue};
use crate::TimeSpecifier;
use crate::{Parser, TimeSpecifier};

#[test]
fn test_parse() {
assert!(parse_time_specifier("start").is_value(TimeSpecifier::Start));
assert!(parse_time_specifier("end").is_value(TimeSpecifier::End));
assert!(TimeSpecifier::parse("start").is_value(TimeSpecifier::Start));
assert!(TimeSpecifier::parse("end").is_value(TimeSpecifier::End));
}
}
5 changes: 5 additions & 0 deletions src/parsers/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,9 @@ mod tests {
])
);
}

#[test]
fn test_invalid() {
assert!(parse_type(Span::new("()")).is_err());
}
}

0 comments on commit 77eb56d

Please sign in to comment.