Skip to content

Commit 8c63b1c

Browse files
committed
refactor: remove unused merge_json
1 parent f371506 commit 8c63b1c

File tree

1 file changed

+3
-45
lines changed

1 file changed

+3
-45
lines changed

src/context.rs

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::{HashMap, VecDeque};
22

33
use serde::Serialize;
4-
use serde_json::value::{to_value, Map, Value as Json};
4+
use serde_json::value::{to_value, Value as Json};
55

66
use crate::block::{BlockContext, BlockParamHolder};
77
use crate::error::{RenderError, RenderErrorReason};
@@ -141,19 +141,6 @@ fn get_in_block_params<'a>(
141141
None
142142
}
143143

144-
pub(crate) fn merge_json(base: &Json, addition: &HashMap<&str, &Json>) -> Json {
145-
let mut base_map = match base {
146-
Json::Object(ref m) => m.clone(),
147-
_ => Map::new(),
148-
};
149-
150-
for (k, v) in addition {
151-
base_map.insert((*k).to_string(), (*v).clone());
152-
}
153-
154-
Json::Object(base_map)
155-
}
156-
157144
impl Context {
158145
/// Create a context with null data
159146
pub fn null() -> Context {
@@ -228,12 +215,12 @@ impl From<Json> for Context {
228215
#[cfg(test)]
229216
mod test {
230217
use crate::block::{BlockContext, BlockParams};
231-
use crate::context::{self, Context};
218+
use crate::context::Context;
232219
use crate::error::RenderError;
233220
use crate::json::path::Path;
234221
use crate::json::value::{self, ScopedJson};
235222
use serde_json::value::Map;
236-
use std::collections::{HashMap, VecDeque};
223+
use std::collections::VecDeque;
237224

238225
fn navigate_from_root<'rc>(
239226
ctx: &'rc Context,
@@ -330,35 +317,6 @@ mod test {
330317
);
331318
}
332319

333-
#[test]
334-
fn test_merge_json() {
335-
let map = json!({ "age": 4 });
336-
let s = "hello".to_owned();
337-
let mut hash = HashMap::new();
338-
let v = value::to_json("h1");
339-
hash.insert("tag", &v);
340-
341-
let ctx_a1 = Context::wraps(context::merge_json(&map, &hash)).unwrap();
342-
assert_eq!(
343-
navigate_from_root(&ctx_a1, "age").unwrap().render(),
344-
"4".to_owned()
345-
);
346-
assert_eq!(
347-
navigate_from_root(&ctx_a1, "tag").unwrap().render(),
348-
"h1".to_owned()
349-
);
350-
351-
let ctx_a2 = Context::wraps(context::merge_json(&value::to_json(s), &hash)).unwrap();
352-
assert_eq!(
353-
navigate_from_root(&ctx_a2, "this").unwrap().render(),
354-
"[object]".to_owned()
355-
);
356-
assert_eq!(
357-
navigate_from_root(&ctx_a2, "tag").unwrap().render(),
358-
"h1".to_owned()
359-
);
360-
}
361-
362320
#[test]
363321
fn test_key_name_with_this() {
364322
let m = json!({

0 commit comments

Comments
 (0)