Skip to content

Commit

Permalink
Add unit tests for replace_ellipsis
Browse files Browse the repository at this point in the history
  • Loading branch information
mmorella-dev committed May 25, 2024
1 parent 51295a7 commit 79b19ef
Showing 1 changed file with 117 additions and 1 deletion.
118 changes: 117 additions & 1 deletion src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ mod tests {
use log::info;
use testresult::TestResult;

use super::NS_GLOBAL_DOMAIN;
use super::{replace_ellipsis, NS_GLOBAL_DOMAIN};
// use serial_test::serial;

#[test]
Expand Down Expand Up @@ -560,4 +560,120 @@ mod tests {

Ok(())
}

#[test]
fn test_replace_ellipsis_dict() -> TestResult {
use plist::{Dictionary, Value};

let old_value = Dictionary::from_iter([
("foo", Value::from(10)), // !!
("bar", 20.into()), // !! takes precedence
])
.into();
let mut new_value = Dictionary::from_iter([
("foo", Value::from(30)), // !!! takes precedence
("fub", 40.into()), // !!!
("...", "".into()),
("bar", 60.into()), // !
("baz", 70.into()), // !
])
.into();

replace_ellipsis(&mut new_value, Some(&old_value));

let expected = Dictionary::from_iter([
("foo", Value::from(30)), // from new
("fub", 40.into()),
("bar", 20.into()), // from old
("baz", 70.into()),
])
.into();

assert_eq!(new_value, expected);

Ok(())
}

#[test]
fn test_replace_ellipsis_dict_nested() -> TestResult {
use plist::{Dictionary, Value};

let old_value = Dictionary::from_iter([(
"level_1",
Dictionary::from_iter([(
"level_2",
Dictionary::from_iter([
("foo", Value::from(10)), //
("bar", 20.into()),
("baz", 30.into()),
]),
)]),
)])
.into();

let mut new_value = Dictionary::from_iter([(
"level_1",
Dictionary::from_iter([(
"level_2",
Dictionary::from_iter([
("baz", Value::from(90)), //
("...", Value::from("")),
]), //
)]),
)])
.into();

replace_ellipsis(&mut new_value, Some(&old_value));

let expected = Dictionary::from_iter([(
"level_1",
Dictionary::from_iter([(
"level_2",
Dictionary::from_iter([
("foo", Value::from(10)), //
("bar", 20.into()),
("baz", 90.into()),
]),
)]),
)])
.into();

assert_eq!(new_value, expected);

Ok(())
}

#[test]
fn test_replace_ellipsis_array() -> TestResult {
let old_value = vec![
10.into(), // !
20.into(), // !
30.into(), // !
40.into(), // !
]
.into();
let mut new_value = vec![
30.into(), // !!!
20.into(), // !!!
"...".into(),
60.into(), // !!
50.into(), // !!
40.into(), // !!
]
.into();

replace_ellipsis(&mut new_value, Some(&old_value));

let expected = vec![
30.into(), // from new array before "..."
20.into(),
10.into(), // from old array
40.into(),
60.into(), // from new array after "..."
50.into(),
]
.into();
assert_eq!(new_value, expected);
Ok(())
}
}

0 comments on commit 79b19ef

Please sign in to comment.