Skip to content

Commit

Permalink
Updating tests to remove dependency on Metta::run_program_str
Browse files Browse the repository at this point in the history
  • Loading branch information
luketpeterson committed Oct 31, 2023
1 parent 145df58 commit d26b225
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 5 additions & 5 deletions lib/examples/sorted_list.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use hyperon::metta::runner::*;
use hyperon::metta::{runner::*, text::SExprParser};

fn main() -> Result<(), String> {
let metta = Metta::new(None);
metta.run_program_str("
metta.run(SExprParser::new("
(: List (-> $a Type))
(: Nil (List $a))
(: Cons (-> $a (List $a) (List $a)))
Expand All @@ -15,11 +15,11 @@ fn main() -> Result<(), String> {
(= (insert $x (Cons $head $tail)) (if (< $x $head)
(Cons $x (Cons $head $tail))
(Cons $head (insert $x $tail))))
")?;
"))?;

assert_eq!(metta.run_program_str("!(insert 1 Nil)")?[0],
assert_eq!(metta.run(SExprParser::new("!(insert 1 Nil)"))?[0],
vec![metta.parse_one_atom("(Cons 1 Nil)")?]);
assert_eq!(metta.run_program_str("(insert 3 (insert 2 (insert 1 Nil)))")?[0],
assert_eq!(metta.run(SExprParser::new("(insert 3 (insert 2 (insert 1 Nil)))"))?[0],
vec![metta.parse_one_atom("(Cons 1 (Cons 2 (Cons 3 Nil)))")?]);

Ok(())
Expand Down
14 changes: 9 additions & 5 deletions lib/src/metta/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,16 @@ fn get_args(expr: &ExpressionAtom) -> &[Atom] {
/// use hyperon::{Atom, expr, assert_eq_no_order};
/// use hyperon::metta::ATOM_TYPE_UNDEFINED;
/// use hyperon::metta::runner::*;
/// use hyperon::metta::text::SExprParser;
/// use hyperon::metta::types::get_atom_types;
///
/// let metta = Metta::new(None);
/// metta.run_program_str("
/// metta.run(SExprParser::new("
/// (: f (-> A B))
/// (: a A)
/// (: a B)
/// (: b B)
/// ").unwrap();
/// ")).unwrap();
///
/// let space = metta.space();
/// assert_eq_no_order!(get_atom_types(&space, &expr!(x)), vec![ATOM_TYPE_UNDEFINED]);
Expand Down Expand Up @@ -390,10 +391,11 @@ fn get_matched_types(space: &dyn Space, atom: &Atom, typ: &Atom) -> Vec<(Atom, B
/// ```
/// use hyperon::expr;
/// use hyperon::metta::runner::*;
/// use hyperon::metta::text::SExprParser;
/// use hyperon::metta::types::check_type;
///
/// let metta = Metta::new(None);
/// metta.run_program_str("(: a A) (: a B)").unwrap();
/// metta.run(SExprParser::new("(: a A) (: a B)")).unwrap();
///
/// assert!(check_type(&metta.space(), &expr!("a"), &expr!("B")));
/// ```
Expand All @@ -410,10 +412,11 @@ pub fn check_type(space: &dyn Space, atom: &Atom, typ: &Atom) -> bool {
/// ```
/// use hyperon::{expr, bind};
/// use hyperon::metta::runner::*;
/// use hyperon::metta::text::SExprParser;
/// use hyperon::metta::types::get_type_bindings;
///
/// let metta = Metta::new(None);
/// metta.run_program_str("(: a (List A))").unwrap();
/// metta.run(SExprParser::new("(: a (List A))")).unwrap();
/// let types = get_type_bindings(&metta.space(), &expr!("a"), &expr!("List" t));
///
/// assert_eq!(types, vec![(expr!("List" "A"), bind!{ t: expr!("A") })]);
Expand Down Expand Up @@ -451,10 +454,11 @@ fn check_meta_type(atom: &Atom, typ: &Atom) -> bool {
/// ```
/// use hyperon::expr;
/// use hyperon::metta::runner::*;
/// use hyperon::metta::text::SExprParser;
/// use hyperon::metta::types::validate_atom;
///
/// let metta = Metta::new(None);
/// metta.run_program_str("(: foo (-> A B)) (: a A) (: b B)").unwrap();
/// metta.run(SExprParser::new("(: foo (-> A B)) (: a A) (: b B)")).unwrap();
///
/// let space = metta.space();
/// assert!(validate_atom(&space, &expr!("foo" "a")));
Expand Down

0 comments on commit d26b225

Please sign in to comment.