use mitoo::JsonWrapper;

#[test]
fn test_json_util() {
    let json_wrapper = JsonWrapper::new("docs/config.json").unwrap();

    let x = json_wrapper.get("name");
    // name = [String("Alice")]
    println!("name = {:?}", x);

    let x = json_wrapper.get("age");
    // age = [Number(30)]
    println!("age = {:?}", x);

    let x = json_wrapper.get("is_student");
    // is_student = [Bool(false)]
    println!("is_student = {:?}", x);

    let x = json_wrapper.get("hobbies");
    // hobbies = [Array [String("reading"), String("swimming"), String("cooking")]]
    println!("hobbies = {:?}", x);

    let x = json_wrapper.get("address");
    // address = [Object {"children": Array [Object {"age": Number(5), "name": String("r")}, Object {"age": Number(6), "name": String("s")}], "city": String("New York"), "releases": Array [String("v1"), String("v2")], "state": String("NY"), "street": String("123 Main St"), "x": Object {"y": String("hello, json!")}, "zip": String("10001")}]
    println!("address = {:?}", x);

    let x = json_wrapper.get("address.street");
    // address.street = [String("123 Main St")]
    println!("address.street = {:?}", x);

    let x = json_wrapper.get("address.releases");
    // address.releases = [Array [String("v1"), String("v2")]]
    println!("address.releases = {:?}", x);

    let x = json_wrapper.get("address.x.y");
    // address.x.y = [String("hello, json!")]
    println!("address.x.y = {:?}", x);

    // 注意： 这里面的children是一个数组，不管是数组还是对象，都是通过点来操作
    let x = json_wrapper.get("address.children.name");
    // address.children.name = [String("r"), String("s")]
    println!("address.children.name = {:?}", x);
    println!("=============================================================");

    // 作为配置使用，正常是知晓需要
    let x = json_wrapper.get_one("address.x.y").as_str().unwrap();
    // address.x.y = hello, json!
    println!("address.x.y = {}", x);
}