From 23ae71afdf8b314e43b41fb4825131846d4f91ae Mon Sep 17 00:00:00 2001 From: Zijing Zhang <50045289+pluveto@users.noreply.github.com> Date: Thu, 13 Feb 2025 18:54:12 +0800 Subject: [PATCH] feat(parser): add tests for float, string, and list parsing --- rulog_core/src/parser.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/rulog_core/src/parser.rs b/rulog_core/src/parser.rs index 5040251..2a88a48 100644 --- a/rulog_core/src/parser.rs +++ b/rulog_core/src/parser.rs @@ -492,6 +492,42 @@ mod tests { }) ); } + #[test] + fn test_parse_float() { + assert_eq!( + parse("temperature(23.5).").unwrap(), + Program(vec![Clause::Fact(Predicate { + name: "temperature".to_string(), + terms: vec![Term::Float(Float(23.5))] + })]) + ); + } + + #[test] + fn test_parse_string() { + assert_eq!( + parse("name(\"John Doe\").").unwrap(), + Program(vec![Clause::Fact(Predicate { + name: "name".to_string(), + terms: vec![Term::String("John Doe".to_string())] + })]) + ); + } + + #[test] + fn test_parse_list() { + assert_eq!( + parse("colors([red, green, blue]).").unwrap(), + Program(vec![Clause::Fact(Predicate { + name: "colors".to_string(), + terms: vec![Term::List(vec![ + Term::Atom("red".to_string()), + Term::Atom("green".to_string()), + Term::Atom("blue".to_string()) + ])] + })]) + ); + } //===------------------------------------------------------------------===// // Comprehensive tests