#[cfg(feature = "serde")]
use inc_id::IdGenerator;

#[test]
#[cfg(feature = "serde")]
fn serialize() {
    let mut id_gen = IdGenerator::<u8>::new();

    // generate all available values
    for _ in 0..10 {
        id_gen.get_id().unwrap();
    }

    id_gen.return_id(2).unwrap();
    id_gen.return_id(4).unwrap();
    id_gen.return_id(6).unwrap();

    let res = serde_json::to_string(&id_gen);

    assert!(res.is_ok());
    assert_eq!(res.unwrap(), "{\"cur_id\":9,\"available_ids\":[2,4,6]}")
}

#[test]
#[cfg(feature = "serde")]
fn deserialize() {
    let val = "{\"cur_id\":9,\"available_ids\":[2,4,6]}";
    
    let res = serde_json::from_str::<IdGenerator<u8>>(val);
    assert!(res.is_ok());

    assert_eq!(res.unwrap().get_id().unwrap(), 6);
}
