1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
extern crate cabot;
extern crate url;
extern crate serde;
extern crate serde_json;
#[macro_use]
extern crate serde_derive;

pub mod structs;
pub mod google;
pub mod ds_toolkit;
// pub mod nominatim;

#[cfg(test)]
mod tests {
    use google;
    use ds_toolkit;
    // use nominatim;
    #[test]
    fn returns_data_for_existing_place() {
        let address = "santa rosa,ca";
        let ds_res = ds_toolkit::geocode(address).unwrap();
        let goog_res = google::geocode(address).unwrap();
        // let nom_res = nominatim::geocode("santa rosa, ca").unwrap();
        // println!("{:?}", nom_res);
        // assert_eq!(nom_res.location.lat, 38.450412);
        // assert_eq!(nom_res.location.lng, -122.783159);
        // println!("{:?}", ds_res.formatted_address);
        assert_eq!(ds_res.location.lat, 38.450412);
        assert_eq!(ds_res.location.lng, -122.783159);
        assert_eq!(ds_res.formatted_address, address.to_string());
        assert_eq!(goog_res.location.lat, 38.440429);
        assert_eq!(goog_res.location.lng, -122.7140548);
    }

    #[test]
    fn returns_err_for_non_existing_place() {
        let ds_res = ds_toolkit::geocode("santa dfdfdfdfdfdf");
        let goog_res = google::geocode("santa dfdfdfdfdfdf");
        // let nom_res = nominatim::geocode("santa dfdfdfdfdfdf");
        // println!("{:?}", nom_res);
        // assert_eq!(nom_res.err(), Some(google::ERR_NO_RESULTS.to_string()));
        assert_eq!(ds_res.err(), Some(google::ERR_NO_RESULTS.to_string()));
        assert_eq!(goog_res.err(), Some(google::ERR_NO_RESULTS.to_string()));
    }
}