From 80509e558f38cd00f06d44d9a647234fa32b949f Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Mon, 27 May 2024 20:47:30 -0700 Subject: fix tests to handle readtables Change-Id: If0b44bfb070bab02e7922d6d419071390882d971 Force-Push: sigh --- src/main.rs | 26 +++++++++++++++----------- src/tests.rs | 3 ++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5ee8d68..8ecb03e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,7 +72,7 @@ fn print_value(v: &Value) { #[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] -enum Mode { +pub enum Mode { Integer, Decimal, Str, @@ -113,15 +113,7 @@ fn main() { registers: baseline_registers(), stack: Vec::new(), mode: Mode::CommandChar, - readtables: BTreeMap::from([ - (Mode::Integer, make_integer_readtable()), - (Mode::Decimal, make_decimal_readtable()), - (Mode::Str, make_string_readtable()), - (Mode::CommandChar, make_command_character_readtable()), - (Mode::CommandNamed, make_command_string_readtable()), - (Mode::RegisterChar, make_register_character_readtable()), - (Mode::RegisterStr, make_register_string_readtable()), - ]), + readtables: make_default_readtables(), wip_str: String::from(""), // TODO: I don't think we need a return stack // But this the closest thing we have right now @@ -165,7 +157,7 @@ fn usize_to_decimal(input: usize) -> Decimal { type ReadAction = Rc Result<(), Exit>>; -struct ReadTable { +pub struct ReadTable { action_map: BTreeMap, default_action: ReadAction, } @@ -223,6 +215,18 @@ struct RPState { // Err(err_msg("(shuf) not implemented yet!".into())) // } +pub fn make_default_readtables() -> BTreeMap { + BTreeMap::from([ + (Mode::Integer, make_integer_readtable()), + (Mode::Decimal, make_decimal_readtable()), + (Mode::Str, make_string_readtable()), + (Mode::CommandChar, make_command_character_readtable()), + (Mode::CommandNamed, make_command_string_readtable()), + (Mode::RegisterChar, make_register_character_readtable()), + (Mode::RegisterStr, make_register_string_readtable()), + ]) +} + fn make_command_string_readtable() -> ReadTable { let mut result = ReadTable::new(move |c, state| { state.wip_str.push(c); diff --git a/src/tests.rs b/src/tests.rs index 013696b..166567f 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -6,10 +6,11 @@ mod tests { fn new_state() -> RPState { return RPState { - registers: baseline_regsiters(), + registers: baseline_registers(), stack: Vec::new(), eat_count: 0, mode: Mode::CommandChar, + readtables: make_default_readtables(), is_num_negative: false, wip_str: String::from(""), reg_command: String::from(""), -- cgit 1.4.1