From 380d0adb427c552f33c8c9e8936708d9d489a622 Mon Sep 17 00:00:00 2001
From: Kirill Leonov <leonov835@yandex.ru>
Date: Sat, 10 Feb 2024 16:16:37 +0300
Subject: [PATCH] init

---
 src/interpreter/arrays.rs | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/src/interpreter/arrays.rs b/src/interpreter/arrays.rs
index f56f119..6c18015 100644
--- a/src/interpreter/arrays.rs
+++ b/src/interpreter/arrays.rs
@@ -28,3 +28,42 @@ pub fn push<'a>(
 
     Ok(OpCodeResultType::Empty)
 }
+
+#[cfg(test)]
+mod test {
+    use super::*;
+    use pretty_assertions::assert_eq;
+    use std::collections::HashMap;
+
+    #[test]
+    fn test_push_to_array() {
+        let mut target: HashMap<&String, ValueType> = HashMap::new();
+        let key = String::from("key");
+        let value = String::from("123");
+        let arr = Vec::<ValueType>::new();
+
+        target.insert(&key, Arr(arr));
+
+        let result = push(&key, &value, &mut target);
+
+        match result {
+            Ok(r) => match r {
+                OpCodeResultType::Empty => {}
+                _ => panic!("not expected result! 1"),
+            },
+            Err(_e) => panic!("not expected result! 2"),
+        }
+
+        let arr = match target.get(&key) {
+            Some(ValueType::Arr(arr)) => arr,
+            _ => panic!("Expected an array"),
+        };
+
+        assert_eq!(arr.len(), 1);
+
+        match arr[0] {
+            Int(i) => assert_eq!(i, 123.0),
+            _ => panic!("Expected an integer"),
+        }
+    }
+}