extern crate libcratesio;

use libcratesio::{CratesIO, Crate, Error};

#[test]
fn basic_data() {
    let krate = Crate::by_name("requests").unwrap();
    println!("{:?}", krate);
    assert_eq!(krate.name, "requests");
}

#[test]
fn raw_data() {
    let krate = CratesIO::query("requests").unwrap().as_json().unwrap();
    println!("{:#?}", krate);
    assert!(true);
}

#[test]
fn versions_iter() {
    let krate = Crate::by_name("requests").unwrap();
    for ver in krate.versions.iter() {
        println!("{:?}", ver);
    }
    assert!(true);
}

#[test]
fn error() {
    let err = Crate::by_name("xxx").unwrap_err();
    println!("{:?}", err);
    assert!(true);
}

extern crate libcratesio;

use libcratesio::{CratesIO, Crate, Error, ErrorKind};

#[test]
fn basic_data() {
    let krate = Crate::by_name("requests").unwrap();
    println!("{:?}", krate);
    assert_eq!(krate.name, "requests");
}

#[test]
fn raw_data() {
    let krate = CratesIO::query("requests").unwrap().as_json().unwrap();
    println!("{:#?}", krate);
    assert!(true);
}

#[test]
fn versions_iter() {
    let krate = Crate::by_name("requests").unwrap();
    for ver in krate.versions.iter() {
        println!("{:?}", ver);
    }
    assert!(true);
}

#[test]
fn error() {
    let no_such_crate = Crate::by_name("no_such_crate");
    assert!(no_such_crate.is_err());
    let err = no_such_crate.unwrap_err();
    if let Error(ErrorKind::CratesIOError(response), _) = err {
        assert_eq!(response.detail(), "Not Found");
    } else {
        assert!(false);
    }
}

Add test for error response
Add test for error response
