From 2f86f30b8a83bca9d80fa107a1812543590f430a Mon Sep 17 00:00:00 2001 From: Alex Shelkovnykov Date: Thu, 7 Dec 2023 12:18:40 -0300 Subject: [PATCH] jets: move useful function into jet utils --- rust/ares/src/jets.rs | 6 +++++- rust/ares/src/jets/parse.rs | 28 ++++------------------------ 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/rust/ares/src/jets.rs b/rust/ares/src/jets.rs index 6eb13c9..9f3b4b2 100644 --- a/rust/ares/src/jets.rs +++ b/rust/ares/src/jets.rs @@ -327,7 +327,11 @@ pub mod util { } pub fn assert_jet(context: &mut Context, jet: Jet, sam: Noun, res: Noun) { - let sam = T(&mut context.stack, &[D(0), sam, D(0)]); + assert_jet_door(context, jet, sam, D(0), res) + } + + pub fn assert_jet_door(context: &mut Context, jet: Jet, sam: Noun, pay: Noun, res: Noun) { + let sam = T(&mut context.stack, &[D(0), sam, pay]); let jet_res = assert_no_alloc(|| jet(context, sam).unwrap()); assert_noun_eq(&mut context.stack, jet_res, res); } diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index 7f3b91a..189b627 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -340,9 +340,8 @@ pub fn jet_stag(context: &mut Context, subject: Noun) -> Result { pub mod util { use crate::interpreter::{inc, Context}; - use crate::jets::util::test::*; - use crate::jets::{Jet, Result}; - use crate::noun::{Cell, Noun, D, T}; + use crate::jets::Result; + use crate::noun::{Noun, D, T}; use std::cmp::Ordering; pub fn last(zyc: Noun, naz: Noun) -> Result { @@ -400,19 +399,6 @@ pub mod util { pub fn fail(context: &mut Context, hair: Noun) -> Result { Ok(T(&mut context.stack, &[hair, D(0)])) } - - pub fn assert_jet_in_door( - context: &mut Context, - jet: Jet, - sam: Noun, //&[fn(&mut Context) -> Noun], // regular sample - ctx: Noun, //&[fn(&mut Context) -> Noun], // door sample as context - res: Noun, - ) { - let pay = Cell::new(&mut context.stack, sam, ctx).as_noun(); - let sbj = Cell::new(&mut context.stack, D(0), pay).as_noun(); - let jet_res = jet(context, sbj).unwrap(); - assert_noun_eq(&mut context.stack, jet_res, res); - } } #[cfg(test)] @@ -421,18 +407,12 @@ mod tests { use crate::jets::util::test::*; use crate::noun::{D, T}; use crate::serialization::cue; - use ibig::ubig; #[test] fn test_easy() { let c = &mut init_context(); - /* - 'a' at +6 of easy - [[1 1] "abc"] at +6 of (easy 'a') - */ - // ((easy 'a') [[1 1] "abc"]) // [[1 1] "abc"] let sam_jam = A(&mut c.stack, &ubig!(3205468216717221061)) @@ -445,7 +425,7 @@ mod tests { .unwrap(); let ans = cue(&mut c.stack, ans_jam); let ctx = T(&mut c.stack, &[D(0), D(97), D(0)]); - util::assert_jet_in_door(c, jet_easy, sam, ctx, ans); + assert_jet_door(c, jet_easy, sam, ctx, ans); // ((easy %foo) [[1 1] "abc"]) // [[1 1] "abc"] @@ -459,6 +439,6 @@ mod tests { .unwrap(); let ans = cue(&mut c.stack, ans_jam); let ctx = T(&mut c.stack, &[D(0), D(0x6f6f66), D(0)]); - util::assert_jet_in_door(c, jet_easy, sam, ctx, ans); + assert_jet_door(c, jet_easy, sam, ctx, ans); } }