hawk_data/
utils.rs

1use serde_json::Value;
2
3pub fn value_to_string(value: &Value) -> String {
4    match value {
5        Value::String(s) => s.clone(),
6        _ => value.to_string().trim_matches('"').to_string(),
7    }
8}
9
10#[cfg(test)]
11mod tests {
12    use super::*;
13
14    #[test]
15    fn test_value_to_string_with_string() {
16        let value = Value::String("Alice".to_string());
17        assert_eq!(value_to_string(&value), "Alice");
18    }
19
20    #[test]
21    fn test_value_to_string_with_number() {
22        let value = Value::Number(serde_json::Number::from(42));
23        assert_eq!(value_to_string(&value), "42");
24    }
25
26    #[test]
27    fn test_value_to_string_with_boolean() {
28        let value = Value::Bool(true);
29        assert_eq!(value_to_string(&value), "true");
30
31        let value = Value::Bool(false);
32        assert_eq!(value_to_string(&value), "false");
33    }
34
35    #[test]
36    fn test_value_to_string_with_null() {
37        let value = Value::Null;
38        assert_eq!(value_to_string(&value), "null");
39    }
40}