diff --git a/src/util.rs b/src/util.rs index 92f1810b..9badffc1 100644 --- a/src/util.rs +++ b/src/util.rs @@ -21,7 +21,7 @@ pub(crate) fn create_var(mut id: usize) -> String { /// /// Returns None when the provided string is not an output of /// `create_var`. -pub fn var_to_num(s: &str) -> Option { +pub(crate) fn var_to_num(s: &str) -> Option { let mut n = 0usize; for i in s.chars() { let i = (i as u32).checked_sub('a' as u32)? as usize; @@ -53,6 +53,7 @@ fn test_create_var() { assert_eq!(create_var(1352), "aza"); assert_eq!(create_var(1378), "baa"); } + #[test] fn test_var_to_num() { for i in [0, 1, 2, 3, 10, 26, 27, 30, 50, 70] { @@ -178,9 +179,7 @@ impl Tree { Tree::Op1 { rgt, .. } => { rgt.ensure_no_conflicts(fresh); } - Tree::Era => (), - Tree::Num { .. } => (), - Tree::Ref { .. } => (), + Tree::Era | Tree::Num { .. } | Tree::Ref { .. } => {}, } } } @@ -198,8 +197,7 @@ impl Net { /// The result is equivalent a λ-calculus application. Thus, /// if the net is a λ-calculus term, then this function will /// apply an argument to it. - #[allow(dead_code)] // used in tests - pub(crate) fn with_argument(&mut self, arg: Tree) { + pub fn apply_tree(&mut self, arg: Tree) { let mut fresh = 0usize; self.ensure_no_conflicts(&mut fresh); arg.ensure_no_conflicts(&mut fresh); diff --git a/tests/api.rs b/tests/api.rs index 53c5fefc..e80871ba 100644 --- a/tests/api.rs +++ b/tests/api.rs @@ -7,7 +7,7 @@ use hvmc::{ use insta::assert_display_snapshot; #[test] -fn test_with_argument() { +fn test_apply_tree() { use hvmc::run; fn eval_with_args(fun: &str, args: &[&str]) -> Net { let area = run::Net::::init_heap(1 << 10); @@ -15,7 +15,7 @@ fn test_with_argument() { let mut fun: Net = fun.parse().unwrap(); for arg in args { let arg: Tree = arg.parse().unwrap(); - fun.with_argument(arg) + fun.apply_tree(arg) } // TODO: When feature/sc-472/argument-passing, use encode_net instead. let mut book = Book::default(); diff --git a/tests/lists.rs b/tests/lists.rs index 523ba5a4..6e36b594 100644 --- a/tests/lists.rs +++ b/tests/lists.rs @@ -8,9 +8,9 @@ fn list_got(index: u32) -> Book { let mut book = parse_core(&code); println!("{:#?}", book.keys().collect::>()); let def = book.get_mut("GenGotIndex").unwrap(); - def.with_argument(hvmc::ast::Tree::Ref { nam: format!("S{index}") }); + def.apply_tree(hvmc::ast::Tree::Ref { nam: format!("S{index}") }); let def = book.get_mut("main").unwrap(); - def.with_argument(hvmc::ast::Tree::Ref { nam: format!("GenGotIndex") }); + def.apply_tree(hvmc::ast::Tree::Ref { nam: format!("GenGotIndex") }); book } @@ -18,11 +18,11 @@ fn list_put(index: u32, value: u32) -> Book { let code = load_file("list_put_got.hvmc"); let mut book = parse_core(&code); let def = book.get_mut("GenPutIndexValue").unwrap(); - def.with_argument(hvmc::ast::Tree::Ref { nam: format!("S{index}") }); - def.with_argument(hvmc::ast::Tree::Ref { nam: format!("S{value}") }); + def.apply_tree(hvmc::ast::Tree::Ref { nam: format!("S{index}") }); + def.apply_tree(hvmc::ast::Tree::Ref { nam: format!("S{value}") }); println!("{:?}", def); let def = book.get_mut("main").unwrap(); - def.with_argument(hvmc::ast::Tree::Ref { nam: format!("GenPutIndexValue") }); + def.apply_tree(hvmc::ast::Tree::Ref { nam: format!("GenPutIndexValue") }); book }