Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Covering tests for pushing new elements into an array #29

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/interpreter/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}
}
Loading