#[cfg(test)] mod tests { use config_forge::convert::{parse_content, detect_format, convert, ConfigFormat}; use serde_json::json; #[test] fn test_parse_json() { let content = r#"{"name": "test", "value": 42}"#; let result = parse_content(content, ConfigFormat::Json); assert!(result.is_ok()); let value = result.unwrap(); assert_eq!(value["name"], "test"); assert_eq!(value["value"], 42); } #[test] fn test_parse_yaml() { let content = r#"name: test value: 42"#; let result = parse_content(content, ConfigFormat::Yaml); assert!(result.is_ok()); let value = result.unwrap(); assert_eq!(value["name"], "test"); assert_eq!(value["value"], 42); } #[test] fn test_parse_toml() { let content = r#"name = "test" value = 42"#; let result = parse_content(content, ConfigFormat::Toml); assert!(result.is_ok()); let value = result.unwrap(); assert_eq!(value["name"], "test"); } #[test] fn test_parse_env() { let content = r#"NAME=test VALUE=42"#; let result = parse_content(content, ConfigFormat::Env); assert!(result.is_ok()); let value = result.unwrap(); assert_eq!(value["NAME"], "test"); assert_eq!(value["VALUE"], "42"); } #[test] fn test_parse_ini() { let content = r#"[section] name = test value = 42"#; let result = parse_content(content, ConfigFormat::Ini); assert!(result.is_ok()); let value = result.unwrap(); assert!(value.get("section").is_some()); } #[test] fn test_detect_format() { assert_eq!(detect_format("test.json"), ConfigFormat::Json); assert_eq!(detect_format("test.yaml"), ConfigFormat::Yaml); assert_eq!(detect_format("test.yml"), ConfigFormat::Yaml); assert_eq!(detect_format("test.toml"), ConfigFormat::Toml); assert_eq!(detect_format("test.env"), ConfigFormat::Env); assert_eq!(detect_format("test.ini"), ConfigFormat::Ini); } #[test] fn test_convert_json_to_yaml() { let value = json!({"name": "test", "value": 42}); let result = convert(value, ConfigFormat::Yaml); assert!(result.is_ok()); let yaml = result.unwrap(); assert!(yaml.contains("name: test")); assert!(yaml.contains("value: 42")); } #[test] fn test_convert_json_to_toml() { let value = json!({"name": "test", "value": 42}); let result = convert(value, ConfigFormat::Toml); assert!(result.is_ok()); let toml = result.unwrap(); assert!(toml.contains("name = \"test\"")); } #[test] fn test_convert_json_to_env() { let value = json!({"NAME": "test", "VALUE": "42"}); let result = convert(value, ConfigFormat::Env); assert!(result.is_ok()); let env = result.unwrap(); assert!(env.contains("NAME=test")); } #[test] fn test_roundtrip_json_yaml() { let original = json!({"name": "test", "nested": {"key": "value"}}); let yaml = convert(original.clone(), ConfigFormat::Yaml).unwrap(); let back_to_json = parse_content(&yaml, ConfigFormat::Yaml).unwrap(); assert_eq!(original, back_to_json); } }