Skip to content

Commit

Permalink
geocode: add suggest tests using --country filter option
Browse files Browse the repository at this point in the history
  • Loading branch information
jqnatividad committed Sep 2, 2023
1 parent 8facedf commit 248f51f
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions tests/test_geocode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,128 @@ fn geocode_suggest() {
assert_eq!(got, expected);
}

#[test]
fn geocode_suggest_intl() {
let wrk = Workdir::new("geocode_suggest_intl");
wrk.create(
"data.csv",
vec![
svec!["Location"],
svec!["Paris"],
svec!["Manila"],
svec!["London"],
svec!["Berlin"],
svec!["Moscow"],
svec!["This is not a Location and it will not be geocoded"],
svec!["Brazil"],
svec!["95.213424, 190,1234565"], // invalid lat, long
svec!["Havana"],
],
);
let mut cmd = wrk.command("geocode");
cmd.arg("suggest")
.arg("Location")
.args(["-f", "%city-admin1-country"])
.arg("data.csv");

let got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
let expected = vec![
svec!["Location"],
svec!["Paris, Île-de-France Region France"],
svec!["Manila, National Capital Region Philippines"],
svec!["London, England United Kingdom"],
svec!["Berlin, Germany"],
svec!["Moscow, Moscow Russia"],
svec!["This is not a Location and it will not be geocoded"],
svec!["Brasília, Federal District Brazil"],
svec!["95.213424, 190,1234565"],
svec!["Havana, La Habana Province Cuba"],
];
assert_eq!(got, expected);
}

#[test]
fn geocode_suggest_intl_country_filter() {
let wrk = Workdir::new("geocode_suggest_intl_country_filter");
wrk.create(
"data.csv",
vec![
svec!["Location"],
svec!["Paris"],
svec!["Manila"],
svec!["London"],
svec!["Berlin"],
svec!["Moscow"],
svec!["This is not a Location and it will not be geocoded"],
svec!["Brazil"],
svec!["95.213424, 190,1234565"], // invalid lat, long
svec!["Havana"],
],
);
let mut cmd = wrk.command("geocode");
cmd.arg("suggest")
.arg("Location")
.args(["--country", "us"])
.args(["-f", "%city-admin1-country"])
.arg("data.csv");

let got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
let expected = vec![
svec!["Location"],
svec!["Paris, Texas United States"],
svec!["Manteca, California United States"],
svec!["Sterling, Virginia United States"],
svec!["Burlington, North Carolina United States"],
svec!["Moscow, Idaho United States"],
svec!["This is not a Location and it will not be geocoded"],
svec!["Bradley, Illinois United States"],
svec!["95.213424, 190,1234565"],
svec!["Savannah, Georgia United States"],
];
assert_eq!(got, expected);
}

#[test]
fn geocode_suggest_intl_multi_country_filter() {
let wrk = Workdir::new("geocode_suggest_intl_multi_country_filter");
wrk.create(
"data.csv",
vec![
svec!["Location"],
svec!["Paris"],
svec!["Manila"],
svec!["London"],
svec!["Berlin"],
svec!["Moscow"],
svec!["This is not a Location and it will not be geocoded"],
svec!["Brazil"],
svec!["95.213424, 190,1234565"], // invalid lat, long
svec!["Havana"],
],
);
let mut cmd = wrk.command("geocode");
cmd.arg("suggest")
.arg("Location")
.args(["--country", "us,fr,ru"])
.args(["-f", "%city-admin1-country"])
.arg("data.csv");

let got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
let expected = vec![
svec!["Location"],
svec!["Paris, Île-de-France Region France"],
svec!["Manteca, California United States"],
svec!["Sterling, Virginia United States"],
svec!["Burlington, North Carolina United States"],
svec!["Moscow, Moscow Russia"],
svec!["This is not a Location and it will not be geocoded"],
svec!["Bradley, Illinois United States"],
svec!["95.213424, 190,1234565"],
svec!["Savannah, Georgia United States"],
];
assert_eq!(got, expected);
}

#[test]
fn geocode_suggest_invalid() {
let wrk = Workdir::new("geocode_suggest_invalid");
Expand Down

0 comments on commit 248f51f

Please sign in to comment.