Skip to content

Commit

Permalink
test(stdlib): add test for consecutive separators in unflatten function
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgehermo9 committed Aug 23, 2024
1 parent 57fcea7 commit 234e1dd
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/stdlib/unflatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ where
// and avoid doing recursive calls to `do_unflatten_entries` with a single entry every time
fn do_unflatten_entry(entry: (KeyString, Value), separator: &str, recursive: bool) -> Value {
let (key, value) = entry;
dbg!(&key);
let keys = key.split(separator).map(Into::into).collect::<Vec<_>>();
dbg!(&keys);
let mut result = if recursive {
do_unflatten(value, separator, recursive)
} else {
Expand Down Expand Up @@ -361,17 +363,47 @@ mod test {
consecutive_separators {
args: func_args![value: value!({
"a..b": 1,
"a...c": 2,
})],
want: Ok(value!({
a: {
"": {
b: 1,
"": {
c: 2,
},
},
},
})),
tdef: TypeDef::object(Collection::any()),
}

traling_separator{
args: func_args![value: value!({
"a.": 1,
})],
want: Ok(value!({
a: {
"": 1,
},
})),
tdef: TypeDef::object(Collection::any()),
}

consecutive_trailing_separator{
args: func_args![value: value!({
"a..": 1,
})],
want: Ok(value!({
a: {
"": {
"": 1,
}
},
})),
tdef: TypeDef::object(Collection::any()),
}

filter_out_top_level_value_when_multiple_values {
args: func_args![value: value!({
"a.b": 1,
Expand Down

0 comments on commit 234e1dd

Please sign in to comment.