|
1 | 1 | use std::collections::{HashMap, VecDeque}; |
2 | 2 |
|
3 | 3 | use serde::Serialize; |
4 | | -use serde_json::value::{to_value, Map, Value as Json}; |
| 4 | +use serde_json::value::{to_value, Value as Json}; |
5 | 5 |
|
6 | 6 | use crate::block::{BlockContext, BlockParamHolder}; |
7 | 7 | use crate::error::{RenderError, RenderErrorReason}; |
@@ -141,19 +141,6 @@ fn get_in_block_params<'a>( |
141 | 141 | None |
142 | 142 | } |
143 | 143 |
|
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 | | - |
157 | 144 | impl Context { |
158 | 145 | /// Create a context with null data |
159 | 146 | pub fn null() -> Context { |
@@ -228,12 +215,12 @@ impl From<Json> for Context { |
228 | 215 | #[cfg(test)] |
229 | 216 | mod test { |
230 | 217 | use crate::block::{BlockContext, BlockParams}; |
231 | | - use crate::context::{self, Context}; |
| 218 | + use crate::context::Context; |
232 | 219 | use crate::error::RenderError; |
233 | 220 | use crate::json::path::Path; |
234 | 221 | use crate::json::value::{self, ScopedJson}; |
235 | 222 | use serde_json::value::Map; |
236 | | - use std::collections::{HashMap, VecDeque}; |
| 223 | + use std::collections::VecDeque; |
237 | 224 |
|
238 | 225 | fn navigate_from_root<'rc>( |
239 | 226 | ctx: &'rc Context, |
@@ -330,35 +317,6 @@ mod test { |
330 | 317 | ); |
331 | 318 | } |
332 | 319 |
|
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 | | - |
362 | 320 | #[test] |
363 | 321 | fn test_key_name_with_this() { |
364 | 322 | let m = json!({ |
|
0 commit comments