Skip to content

Commit 8e8c4b4

Browse files
authored
feat(parser): add tests for float, string, and list parsing (#6)
1 parent 477ad88 commit 8e8c4b4

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

rulog_core/src/parser.rs

+36
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,42 @@ mod tests {
492492
})
493493
);
494494
}
495+
#[test]
496+
fn test_parse_float() {
497+
assert_eq!(
498+
parse("temperature(23.5).").unwrap(),
499+
Program(vec![Clause::Fact(Predicate {
500+
name: "temperature".to_string(),
501+
terms: vec![Term::Float(Float(23.5))]
502+
})])
503+
);
504+
}
505+
506+
#[test]
507+
fn test_parse_string() {
508+
assert_eq!(
509+
parse("name(\"John Doe\").").unwrap(),
510+
Program(vec![Clause::Fact(Predicate {
511+
name: "name".to_string(),
512+
terms: vec![Term::String("John Doe".to_string())]
513+
})])
514+
);
515+
}
516+
517+
#[test]
518+
fn test_parse_list() {
519+
assert_eq!(
520+
parse("colors([red, green, blue]).").unwrap(),
521+
Program(vec![Clause::Fact(Predicate {
522+
name: "colors".to_string(),
523+
terms: vec![Term::List(vec![
524+
Term::Atom("red".to_string()),
525+
Term::Atom("green".to_string()),
526+
Term::Atom("blue".to_string())
527+
])]
528+
})])
529+
);
530+
}
495531

496532
//===------------------------------------------------------------------===//
497533
// Comprehensive tests

0 commit comments

Comments
 (0)