summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2024-05-27 20:47:30 -0700
committerIrene Knapp <ireneista@irenes.space>2024-05-27 20:47:35 -0700
commit80509e558f38cd00f06d44d9a647234fa32b949f (patch)
tree0c22b2fc84cfc29f2a9f247d88acc0ae2682851a
parent260500cc508813d0b9f42b8c6f16880a4b6dad71 (diff)
fix tests to handle readtables
Change-Id: If0b44bfb070bab02e7922d6d419071390882d971
Force-Push: sigh
-rw-r--r--src/main.rs26
-rw-r--r--src/tests.rs3
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<dyn Fn(char, &mut RPState) -> Result<(), Exit>>;
 
-struct ReadTable {
+pub struct ReadTable {
   action_map: BTreeMap<char, ReadAction>,
   default_action: ReadAction,
 }
@@ -223,6 +215,18 @@ struct RPState {
 //    Err(err_msg("(shuf) not implemented yet!".into()))
 // }
 
+pub fn make_default_readtables() -> BTreeMap<Mode, ReadTable> {
+  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(""),