Coverage / src/cli/json.rs 100.0%
23 of 23 lines run, 37 of 48 functions · run #414 on main · run missed
| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | | pub use oxy_core::repo::{json_array as arr, json_str as s}; |
| 5 | |
|
| 6 | 109× | pub fn obj<I: IntoIterator<Item = (&'static str, String)>>(pairs: I) -> String { |
| 7 | 109× | let inner: Vec<String> = pairs |
| 8 | 109× | .into_iter() |
| 9 | 686× | .map(|(k, v)| format!("{}:{v}", s(k))) |
| 10 | 109× | .collect(); |
| 11 | 109× | format!("{{{}}}", inner.join(",")) |
| 12 | 109× | } |
| 13 | 102× | pub fn b(v: bool) -> String { |
| 14 | 102× | v.to_string() |
| 15 | 102× | } |
| 16 | 78× | pub fn n<T: std::fmt::Display>(v: T) -> String { |
| 17 | 78× | v.to_string() |
| 18 | 78× | } |
| 19 | 62× | pub fn opt<T>(v: Option<T>, f: impl Fn(T) -> String) -> String { |
| 20 | 62× | match v { |
| 21 | 13× | Some(x) => f(x), |
| 22 | 49× | None => "null".into(), |
| 23 | | } |
| 24 | 62× | } |
| 25 | 37× | pub fn hashes(v: &[oxy_core::hash::ChangeHash]) -> String { |
| 26 | 39× | arr(v.iter().map(|h| s(&h.to_hex()))) |
| 27 | 37× | } |