56 lines
1.4 KiB
Rust
56 lines
1.4 KiB
Rust
#[cfg(test)]
|
|
mod tests {
|
|
use config_forge::convert::infer_schema;
|
|
use serde_json::json;
|
|
|
|
#[test]
|
|
fn test_infer_schema_string() {
|
|
let value = json!("test");
|
|
let schema = infer_schema(&value);
|
|
assert_eq!(schema["type"], "string");
|
|
}
|
|
|
|
#[test]
|
|
fn test_infer_schema_number() {
|
|
let value = json!(42);
|
|
let schema = infer_schema(&value);
|
|
assert_eq!(schema["type"], "integer");
|
|
}
|
|
|
|
#[test]
|
|
fn test_infer_schema_boolean() {
|
|
let value = json!(true);
|
|
let schema = infer_schema(&value);
|
|
assert_eq!(schema["type"], "boolean");
|
|
}
|
|
|
|
#[test]
|
|
fn test_infer_schema_object() {
|
|
let value = json!({"name": "test", "value": 42});
|
|
let schema = infer_schema(&value);
|
|
assert_eq!(schema["type"], "object");
|
|
assert!(schema["properties"].is_object());
|
|
}
|
|
|
|
#[test]
|
|
fn test_infer_schema_array() {
|
|
let value = json!([1, 2, 3]);
|
|
let schema = infer_schema(&value);
|
|
assert_eq!(schema["type"], "array");
|
|
}
|
|
|
|
#[test]
|
|
fn test_infer_schema_nested() {
|
|
let value = json!({
|
|
"user": {
|
|
"name": "test",
|
|
"age": 30
|
|
}
|
|
});
|
|
let schema = infer_schema(&value);
|
|
assert_eq!(schema["type"], "object");
|
|
let props = schema["properties"].as_object().unwrap();
|
|
assert!(props.contains_key("user"));
|
|
}
|
|
}
|