Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add test_100 for 100.dathere.com & tests for lesson/exercise 0 #1848

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/test_100.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// The tests in this file and the test_100 folder are for
// lessons and exercises in the online book "100 exercises with qsv".

// You may read lessons and try out the exercises at:
// https://100.dathere.com

// Warning: These tests may contain solutions to the exercises.

mod exercise_0;
62 changes: 62 additions & 0 deletions tests/test_100/exercise_0.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Lesson 0: Exploring qsv help messages and syntax
// https://100.dathere.com/lessons/0/notes.html

use std::process;

use crate::workdir::Workdir;

fn setup(name: &str, command_str: &str, args: Vec<&str>) -> (Workdir, process::Command) {
let wrk = Workdir::new(name);
wrk.create(
"fruits.csv",
vec![
svec!["fruit", "price"],
svec!["apple", "2.50"],
svec!["banana", "3.00"],
svec!["carrot", "1.50"],
],
);

let mut cmd = wrk.command(command_str);
cmd.args(args);

(wrk, cmd)
}

// https://100.dathere.com/lessons/0/notes.html#displaying-headers-of-a-csv
#[test]
fn fruits_headers() {
let name = "fruits_headers";
let command_str = "headers";
let args = vec!["fruits.csv"];
let (wrk, mut cmd) = setup(name, command_str, args);

let got: String = wrk.stdout(&mut cmd);
let expected = r#"1 fruit
2 price"#;
assert_eq!(got, expected);
}

// https://100.dathere.com/lessons/0/notes.html#exercise-0-total-rows
#[test]
fn fruits_count_total() {
let name = "fruits_count";
let command_str = "count";
let args = vec!["fruits.csv", "--no-headers"];
let (wrk, mut cmd) = setup(name, command_str, args);

let got: String = wrk.stdout(&mut cmd);
let expected = "4";
assert_eq!(got, expected);
}
#[test]
fn fruits_count() {
let name = "fruits_count";
let command_str = "count";
let args = vec!["fruits.csv"];
let (wrk, mut cmd) = setup(name, command_str, args);

let got: String = wrk.stdout(&mut cmd);
let expected = "3";
assert_eq!(got, expected);
}
1 change: 1 addition & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ macro_rules! rassert_eq {

mod workdir;

mod test_100;
#[cfg(feature = "apply")]
mod test_apply;
#[cfg(feature = "datapusher_plus")]
Expand Down
Loading