Skip to content

Commit

Permalink
tests: add joinp --maintain-order tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jqnatividad committed Dec 7, 2024
1 parent cd31fdb commit dc62e5f
Showing 1 changed file with 138 additions and 0 deletions.
138 changes: 138 additions & 0 deletions tests/test_joinp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,3 +1284,141 @@ fn joinp_ignore_case() {
];
assert_eq!(got, expected);
}

#[test]
fn joinp_ignore_case_maintain_order_right() {
let wrk = Workdir::new("joinp_mo_r");

// Create test data with mixed case cities
wrk.create(
"cities_mixed.csv",
vec![
svec!["city", "state"],
svec!["BOSTON", "MA"],
svec!["new york", "NY"],
svec!["San Francisco", "CA"],
svec!["BUFFALO", "NY"],
],
);

wrk.create(
"places_mixed.csv",
vec![
svec!["city", "place"],
svec!["Boston", "Logan Airport"],
svec!["boston", "Boston Garden"],
svec!["BUFFALO", "Ralph Wilson Stadium"],
svec!["orlando", "Disney World"],
svec!["new York", "Madison Square Garden"],
svec!["san francisco", "Fisherman's Wharf"],
],
);

let mut cmd = wrk.command("joinp");
cmd.args(&["city", "cities_mixed.csv", "city", "places_mixed.csv"])
.arg("--ignore-case")
.args(["--maintain-order", "right"]);

let got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
let expected = vec![
svec!["city", "state", "city_right", "place"],
svec!["BOSTON", "MA", "Boston", "Logan Airport"],
svec!["BOSTON", "MA", "boston", "Boston Garden"],
svec!["BUFFALO", "NY", "BUFFALO", "Ralph Wilson Stadium"],
svec!["new york", "NY", "new York", "Madison Square Garden"],
svec!["San Francisco", "CA", "san francisco", "Fisherman's Wharf"],
];
assert_eq!(got, expected);
}

#[test]
fn joinp_ignore_case_maintain_order_left() {
let wrk = Workdir::new("joinp_mo_l");

// Create test data with mixed case cities
wrk.create(
"cities_mixed.csv",
vec![
svec!["city", "state"],
svec!["BOSTON", "MA"],
svec!["new york", "NY"],
svec!["San Francisco", "CA"],
svec!["BUFFALO", "NY"],
],
);

wrk.create(
"places_mixed.csv",
vec![
svec!["city", "place"],
svec!["Boston", "Logan Airport"],
svec!["boston", "Boston Garden"],
svec!["BUFFALO", "Ralph Wilson Stadium"],
svec!["orlando", "Disney World"],
svec!["new York", "Madison Square Garden"],
svec!["san francisco", "Fisherman's Wharf"],
],
);

let mut cmd = wrk.command("joinp");
cmd.args(&["city", "cities_mixed.csv", "city", "places_mixed.csv"])
.arg("--ignore-case")
.args(["--maintain-order", "left"]);

let got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
let expected = vec![
svec!["city", "state", "city_right", "place"],
svec!["BOSTON", "MA", "Boston", "Logan Airport"],
svec!["BOSTON", "MA", "boston", "Boston Garden"],
svec!["new york", "NY", "new York", "Madison Square Garden"],
svec!["San Francisco", "CA", "san francisco", "Fisherman's Wharf"],
svec!["BUFFALO", "NY", "BUFFALO", "Ralph Wilson Stadium"],
];
assert_eq!(got, expected);
}

#[test]
fn joinp_ignore_case_maintain_order_right_left() {
let wrk = Workdir::new("joinp_mo_rl");

// Create test data with mixed case cities
wrk.create(
"cities_mixed.csv",
vec![
svec!["city", "state"],
svec!["BOSTON", "MA"],
svec!["new york", "NY"],
svec!["San Francisco", "CA"],
svec!["BUFFALO", "NY"],
],
);

wrk.create(
"places_mixed.csv",
vec![
svec!["city", "place"],
svec!["Boston", "Logan Airport"],
svec!["boston", "Boston Garden"],
svec!["BUFFALO", "Ralph Wilson Stadium"],
svec!["orlando", "Disney World"],
svec!["new York", "Madison Square Garden"],
svec!["san francisco", "Fisherman's Wharf"],
],
);

let mut cmd = wrk.command("joinp");
cmd.args(&["city", "cities_mixed.csv", "city", "places_mixed.csv"])
.arg("--ignore-case")
.args(["--maintain-order", "left_right"]);

let got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
let expected = vec![
svec!["city", "state", "city_right", "place"],
svec!["BOSTON", "MA", "Boston", "Logan Airport"],
svec!["BOSTON", "MA", "boston", "Boston Garden"],
svec!["new york", "NY", "new York", "Madison Square Garden"],
svec!["San Francisco", "CA", "san francisco", "Fisherman's Wharf"],
svec!["BUFFALO", "NY", "BUFFALO", "Ralph Wilson Stadium"],
];
assert_eq!(got, expected);
}

0 comments on commit dc62e5f

Please sign in to comment.