-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some tweaks. Add test for
with_argument
.
- Loading branch information
1 parent
1302081
commit 36ef219
Showing
4 changed files
with
115 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//! Tests for front-facing APIs and interfaces | ||
use hvmc::{ | ||
ast::{Book, Net, Tree}, | ||
host::Host, | ||
}; | ||
use insta::assert_display_snapshot; | ||
|
||
#[test] | ||
fn test_with_argument() { | ||
use hvmc::run; | ||
fn eval_with_args(fun: &str, args: &[&str]) -> Net { | ||
let area = run::Net::<run::Strict>::init_heap(1 << 10); | ||
|
||
let mut fun: Net = fun.parse().unwrap(); | ||
for arg in args { | ||
let arg: Tree = arg.parse().unwrap(); | ||
fun.with_argument(arg) | ||
} | ||
// TODO: When feature/sc-472/argument-passing, use encode_net instead. | ||
let mut book = Book::default(); | ||
book.nets.insert("main".into(), fun); | ||
let host = Host::new(&book); | ||
|
||
let mut rnet = run::Net::<run::Strict>::new(&area); | ||
rnet.boot(&host.defs["main"]); | ||
rnet.normal(); | ||
let got_result = host.readback(&rnet); | ||
got_result | ||
} | ||
assert_display_snapshot!( | ||
eval_with_args("(a a)", &vec!["(a a)"]), | ||
@"(a a)" | ||
); | ||
assert_display_snapshot!( | ||
eval_with_args("b & (a b) ~ a", &vec!["(a a)"]), | ||
@"a" | ||
); | ||
assert_display_snapshot!( | ||
eval_with_args("(z0 z0)", &vec!["(z1 z1)"]), | ||
@"(a a)" | ||
); | ||
assert_display_snapshot!( | ||
eval_with_args("(* #1)", &vec!["(a a)"]), | ||
@"#1" | ||
); | ||
assert_display_snapshot!( | ||
eval_with_args("(<+ a b> (a b))", &vec!["#1", "#2"]), | ||
@"#3" | ||
); | ||
assert_display_snapshot!( | ||
eval_with_args("(<* a b> (a b))", &vec!["#2", "#3"]), | ||
@"#6" | ||
); | ||
assert_display_snapshot!( | ||
eval_with_args("(<* a b> (a b))", &vec!["#2"]), | ||
@"(<2* a> a)" | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters