diff options
Diffstat (limited to 'lib/core/libimagstore')
-rw-r--r-- | lib/core/libimagstore/src/file_abstraction/mod.rs | 12 | ||||
-rw-r--r-- | lib/core/libimagstore/src/file_abstraction/stdio/mapper/json.rs | 67 | ||||
-rw-r--r-- | lib/core/libimagstore/src/store.rs | 40 |
3 files changed, 60 insertions, 59 deletions
diff --git a/lib/core/libimagstore/src/file_abstraction/mod.rs b/lib/core/libimagstore/src/file_abstraction/mod.rs index 1b0cc490..f38b6590 100644 --- a/lib/core/libimagstore/src/file_abstraction/mod.rs +++ b/lib/core/libimagstore/src/file_abstraction/mod.rs @@ -112,11 +112,11 @@ mod test { let mut lf = InMemoryFileAbstractionInstance::new(fs.backend().clone(), path.clone()); let loca = StoreId::new_baseless(path).unwrap(); - let file = Entry::from_str(loca.clone(), r#"--- + let file = Entry::from_str(loca.clone(), &format!(r#"--- [imag] -version = "0.7.0" +version = "{}" --- -Hello World"#).unwrap(); +Hello World"#, env!("CARGO_PKG_VERSION"))).unwrap(); lf.write_file_content(&file).unwrap(); let bah = lf.get_file_content(loca).unwrap(); @@ -132,12 +132,12 @@ Hello World"#).unwrap(); let mut lf = InMemoryFileAbstractionInstance::new(fs.backend().clone(), path.clone()); let loca = StoreId::new_baseless(path).unwrap(); - let file = Entry::from_str(loca.clone(), r#"--- + let file = Entry::from_str(loca.clone(), &format!(r#"--- [imag] -version = "0.7.0" +version = "{}" --- Hello World -baz"#).unwrap(); +baz"#, env!("CARGO_PKG_VERSION"))).unwrap(); lf.write_file_content(&file).unwrap(); let bah = lf.get_file_content(loca).unwrap(); diff --git a/lib/core/libimagstore/src/file_abstraction/stdio/mapper/json.rs b/lib/core/libimagstore/src/file_abstraction/stdio/mapper/json.rs index 5cefec17..8b6052f0 100644 --- a/lib/core/libimagstore/src/file_abstraction/stdio/mapper/json.rs +++ b/lib/core/libimagstore/src/file_abstraction/stdio/mapper/json.rs @@ -164,7 +164,8 @@ mod test { #[test] fn test_empty_json_to_fs() { - let json = r#"{"version":"0.7.0","store":{}}"#; + let json = format!(r#"{{"version":"{version}","store":{{}}}}"#, + version = env!("CARGO_PKG_VERSION")); let mut json = Cursor::new(String::from(json).into_bytes()); let mapper = JsonMapper::new(); let mut hm = HashMap::new(); @@ -176,20 +177,20 @@ mod test { #[test] fn test_json_to_fs() { - let json = r#" - { "version": "0.7.0", - "store": { - "example": { - "header": { - "imag": { - "version": "0.7.0" - } - }, + let json = format!(r#" + {{ "version": "{version}", + "store": {{ + "example": {{ + "header": {{ + "imag": {{ + "version": "{version}" + }} + }}, "content": "test" - } - } - } - "#; + }} + }} + }} + "#, version = env!("CARGO_PKG_VERSION")); let mut json = Cursor::new(String::from(json).into_bytes()); let mapper = JsonMapper::new(); let mut hm = HashMap::new(); @@ -207,14 +208,14 @@ mod test { let mut hm = { let mut hm = HashMap::new(); - let content = r#"--- + let content = format!(r#"--- [imag] -version = "0.7.0" +version = "{}" --- -hi there!"#; +hi there!"#, env!("CARGO_PKG_VERSION")); let id = PathBuf::from("example"); - let entry = Entry::from_str(id.clone(), content).unwrap(); + let entry = Entry::from_str(id.clone(), &content).unwrap(); hm.insert(id, entry); hm }; @@ -222,23 +223,23 @@ hi there!"#; let io_res = mapper.fs_to_write(&mut hm, &mut out); assert!(io_res.is_ok()); - let example = r#" - { - "version": "0.7.0", - "store": { - "example": { - "header": { - "imag": { - "version": "0.7.0" - } - }, + let example = format!(r#" + {{ + "version": "{version}", + "store": {{ + "example": {{ + "header": {{ + "imag": {{ + "version": "{version}" + }} + }}, "content": "hi there!" - } - } - } - "#; + }} + }} + }} + "#, version = env!("CARGO_PKG_VERSION")); - let example_json : ::serde_json::Value = ::serde_json::from_str(example).unwrap(); + let example_json : ::serde_json::Value = ::serde_json::from_str(&example).unwrap(); let output_json = String::from_utf8(out.into_inner()).unwrap(); let output_json : ::serde_json::Value = ::serde_json::from_str(&output_json).unwrap(); diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index 500cf58d..8e502b09 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -1284,11 +1284,11 @@ mod store_tests { use file_abstraction::stdio::mapper::json::JsonMapper; // Lets have an empty store as input - let mut input = Cursor::new(r#" - { "version": "0.7.0", - "store": { } - } - "#); + let mut input = Cursor::new(format!(r#" + {{ "version": "{}", + "store": {{}} + }} + "#, env!("CARGO_PKG_VERSION"))); let mapper = JsonMapper::new(); let backend = StdIoFileAbstraction::new(&mut input, output.clone(), mapper).unwrap(); @@ -1322,7 +1322,7 @@ mod store_tests { Value::Object(ref map) => { assert!(map.get("version").is_some(), format!("No 'version' in JSON")); match map.get("version").unwrap() { - &Value::String(ref s) => assert_eq!("0.7.0", s), + &Value::String(ref s) => assert_eq!(env!("CARGO_PKG_VERSION"), s), _ => panic!("Wrong type in JSON at 'version'"), } @@ -1622,20 +1622,20 @@ mod store_tests { use file_abstraction::stdio::mapper::json::JsonMapper; // Lets have an empty store as input - let mut input = Cursor::new(r#" - { "version": "0.7.0", - "store": { - "example": { - "header": { - "imag": { - "version": "0.7.0" - } - }, + let mut input = Cursor::new(format!(r#" + {{ "version": "{version}", + "store": {{ + "example": {{ + "header": {{ + "imag": {{ + "version": "{version}" + }} + }}, "content": "foobar" - } - } - } - "#); + }} + }} + }} + "#, version = env!("CARGO_PKG_VERSION"))); let output = Rc::new(RefCell::new(::std::io::sink())); let mapper = JsonMapper::new(); @@ -1672,7 +1672,7 @@ mod store_tests { Value::Object(ref map) => { assert!(map.get("version").is_some(), format!("No 'version' in JSON")); match map.get("version").unwrap() { - &Value::String(ref s) => assert_eq!("0.7.0", s), + &Value::String(ref s) => assert_eq!(env!("CARGO_PKG_VERSION"), s), _ => panic!("Wrong type in JSON at 'version'"), } |