From 634330feca5e0bd3a7dd33a1a8f46b37dc180987 Mon Sep 17 00:00:00 2001 From: minhtrannhat Date: Tue, 29 Aug 2023 14:48:45 -0400 Subject: [PATCH] Feat(testing and infra): skeleton for catr library --- Cargo.lock | 486 ++++++++++++++++++++++ Cargo.toml | 8 + src/lib.rs | 58 +++ src/main.rs | 2 +- tests/cli.rs | 200 +++++++++ tests/expected/all.b.out | 13 + tests/expected/all.n.out | 13 + tests/expected/all.out | 13 + tests/expected/empty.txt.b.out | 0 tests/expected/empty.txt.n.out | 0 tests/expected/empty.txt.out | 0 tests/expected/fox.txt.b.out | 1 + tests/expected/fox.txt.n.out | 1 + tests/expected/fox.txt.out | 1 + tests/expected/spiders.txt.b.out | 3 + tests/expected/spiders.txt.n.out | 3 + tests/expected/spiders.txt.out | 3 + tests/expected/the-bustle.txt.b.out | 9 + tests/expected/the-bustle.txt.b.stdin.out | 9 + tests/expected/the-bustle.txt.n.out | 9 + tests/expected/the-bustle.txt.n.stdin.out | 9 + tests/expected/the-bustle.txt.out | 9 + tests/expected/the-bustle.txt.stdin.out | 9 + 23 files changed, 858 insertions(+), 1 deletion(-) create mode 100644 src/lib.rs create mode 100644 tests/cli.rs create mode 100644 tests/expected/all.b.out create mode 100644 tests/expected/all.n.out create mode 100644 tests/expected/all.out create mode 100644 tests/expected/empty.txt.b.out create mode 100644 tests/expected/empty.txt.n.out create mode 100644 tests/expected/empty.txt.out create mode 100644 tests/expected/fox.txt.b.out create mode 100644 tests/expected/fox.txt.n.out create mode 100644 tests/expected/fox.txt.out create mode 100644 tests/expected/spiders.txt.b.out create mode 100644 tests/expected/spiders.txt.n.out create mode 100644 tests/expected/spiders.txt.out create mode 100644 tests/expected/the-bustle.txt.b.out create mode 100644 tests/expected/the-bustle.txt.b.stdin.out create mode 100644 tests/expected/the-bustle.txt.n.out create mode 100644 tests/expected/the-bustle.txt.n.stdin.out create mode 100644 tests/expected/the-bustle.txt.out create mode 100644 tests/expected/the-bustle.txt.stdin.out diff --git a/Cargo.lock b/Cargo.lock index 3f56043..cf83047 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,492 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" +dependencies = [ + "memchr", +] + +[[package]] +name = "anstream" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is-terminal", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" + +[[package]] +name = "anstyle-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "assert_cmd" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88903cb14723e4d4003335bb7f8a14f27691649105346a0f0957466c096adfe6" +dependencies = [ + "anstyle", + "bstr", + "doc-comment", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" + +[[package]] +name = "bstr" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6798148dccfbff0fae41c7574d2fa8f1ef3492fba0face179de5d8d447d67b05" +dependencies = [ + "memchr", + "regex-automata", + "serde", +] + [[package]] name = "catr" version = "0.1.0" +dependencies = [ + "assert_cmd", + "clap", + "predicates", + "rand", +] + +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "4.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd304a20bff958a57f04c4e96a2e7594cc4490a0e809cbd48bb6437edaa452d" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01c6a3f08f1fe5662a35cfe393aec09c4df95f60ee93b7556505260f75eee9e1" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "once_cell", + "strsim", +] + +[[package]] +name = "clap_lex" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] +name = "either" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" + +[[package]] +name = "errno" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "float-cmp" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" +dependencies = [ + "num-traits", +] + +[[package]] +name = "getrandom" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hermit-abi" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" + +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi", + "rustix", + "windows-sys", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "libc" +version = "0.2.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + +[[package]] +name = "linux-raw-sys" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "normalize-line-endings" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" + +[[package]] +name = "num-traits" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "predicates" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09963355b9f467184c04017ced4a2ba2d75cbcb4e7462690d388233253d4b1a9" +dependencies = [ + "anstyle", + "difflib", + "float-cmp", + "itertools", + "normalize-line-endings", + "predicates-core", + "regex", +] + +[[package]] +name = "predicates-core" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" + +[[package]] +name = "predicates-tree" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf" +dependencies = [ + "predicates-core", + "termtree", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "regex" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39354c10dd07468c2e73926b23bb9c2caca74c5501e38a35da70406f1d923310" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" + +[[package]] +name = "rustix" +version = "0.38.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a962918ea88d644592894bc6dc55acc6c0956488adcebbfb6e273506b7fd6e5" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "serde" +version = "1.0.176" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76dc28c9523c5d70816e393136b86d48909cfb27cecaa902d338c19ed47164dc" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "termtree" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" diff --git a/Cargo.toml b/Cargo.toml index e5e84a0..e00af02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,16 @@ [package] name = "catr" +authors = ["Minh Tran "] version = "0.1.0" edition = "2021" +description = "Rust rewrite of cat" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = { version = "4", features = ["cargo", "help"] } + +[dev-dependencies] +assert_cmd = "2.0.12" +predicates = "3.0.3" +rand = "0.8.5" diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..6f2162d --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,58 @@ +use clap::builder::{Arg, Command}; +use clap::{crate_authors, crate_description, crate_name, crate_version, ArgAction, ArgMatches}; +use std::error::Error; + +type MyResult = Result>; + +#[derive(Debug)] +pub struct Config { + files: Vec<&str>, + number_lines: bool, + number_nonblank_lines: bool, +} + +pub fn get_args() -> MyResult { + let matches: ArgMatches = Command::new(crate_name!()) + .version(crate_version!()) + .author(crate_authors!("\n")) + .about(crate_description!()) + .help_template( + "\ +{before-help}{name} {version} + {author-with-newline}{about-with-newline} +{usage-heading} {usage} +{all-args} {after-help} +", + ) + .arg( + Arg::new("file") + .value_name("FILE") + .help("Input file(s)") + .num_args(1..), + ) + .arg( + Arg::new("number_lines") + .short('n') + .help("Number the lines (excluding the non-blank lines).") + .num_args(0) + .action(ArgAction::SetTrue), + ) + .arg( + Arg::new("number_nonblank_lines") + .short('b') + .help("Number the lines (including the non-blank lines).") + .num_args(0) + .action(ArgAction::SetTrue), + ) + .get_matches(); + + Ok(Config { + files: matches + .get_many::("file") + .expect("Must be a valid file path") + .map(|s| s.as_str()) + .collect(), + number_lines: matches.get_flag("number_lines"), + number_nonblank_lines: matches.get_flag("number_nonblank_lines"), + }) +} diff --git a/src/main.rs b/src/main.rs index e7a11a9..5bf256e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,3 @@ fn main() { - println!("Hello, world!"); + println!("Hello world"); } diff --git a/tests/cli.rs b/tests/cli.rs new file mode 100644 index 0000000..4a27c3b --- /dev/null +++ b/tests/cli.rs @@ -0,0 +1,200 @@ +use assert_cmd::Command; +use predicates::prelude::*; +use rand::{distributions::Alphanumeric, Rng}; +use std::error::Error; +use std::fs; + +type TestResult = Result<(), Box>; + +const PRG: &str = "catr"; +const EMPTY: &str = "tests/inputs/empty.txt"; +const FOX: &str = "tests/inputs/fox.txt"; +const SPIDERS: &str = "tests/inputs/spiders.txt"; +const BUSTLE: &str = "tests/inputs/the-bustle.txt"; + +// -------------------------------------------------- +#[test] +fn usage() -> TestResult { + for flag in &["-h", "--help"] { + Command::cargo_bin(PRG)? + .arg(flag) + .assert() + .stdout(predicate::str::contains("USAGE")); + } + Ok(()) +} + +// -------------------------------------------------- +fn gen_bad_file() -> String { + loop { + let filename: String = rand::thread_rng() + .sample_iter(&Alphanumeric) + .take(7) + .map(char::from) + .collect(); + + if fs::metadata(&filename).is_err() { + return filename; + } + } +} + +// -------------------------------------------------- +#[test] +fn skips_bad_file() -> TestResult { + let bad = gen_bad_file(); + let expected = format!("{}: .* [(]os error 2[)]", bad); + Command::cargo_bin(PRG)? + .arg(&bad) + .assert() + .success() + .stderr(predicate::str::is_match(expected)?); + Ok(()) +} + +// -------------------------------------------------- +fn run(args: &[&str], expected_file: &str) -> TestResult { + let expected = fs::read_to_string(expected_file)?; + Command::cargo_bin(PRG)? + .args(args) + .assert() + .success() + .stdout(expected); + Ok(()) +} + +// -------------------------------------------------- +fn run_stdin( + input_file: &str, + args: &[&str], + expected_file: &str, +) -> TestResult { + let input = fs::read_to_string(input_file)?; + let expected = fs::read_to_string(expected_file)?; + Command::cargo_bin(PRG)? + .args(args) + .write_stdin(input) + .assert() + .success() + .stdout(expected); + Ok(()) +} + +// -------------------------------------------------- +#[test] +fn bustle_stdin() -> TestResult { + run_stdin(BUSTLE, &["-"], "tests/expected/the-bustle.txt.stdin.out") +} + +// -------------------------------------------------- +#[test] +fn bustle_stdin_n() -> TestResult { + run_stdin( + BUSTLE, + &["-n", "-"], + "tests/expected/the-bustle.txt.n.stdin.out", + ) +} + +// -------------------------------------------------- +#[test] +fn bustle_stdin_b() -> TestResult { + run_stdin( + BUSTLE, + &["-b", "-"], + "tests/expected/the-bustle.txt.b.stdin.out", + ) +} + +// -------------------------------------------------- +#[test] +fn empty() -> TestResult { + run(&[EMPTY], "tests/expected/empty.txt.out") +} + +// -------------------------------------------------- +#[test] +fn empty_n() -> TestResult { + run(&["-n", EMPTY], "tests/expected/empty.txt.n.out") +} + +// -------------------------------------------------- +#[test] +fn empty_b() -> TestResult { + run(&["-b", EMPTY], "tests/expected/empty.txt.b.out") +} + +// -------------------------------------------------- +#[test] +fn fox() -> TestResult { + run(&[FOX], "tests/expected/fox.txt.out") +} + +// -------------------------------------------------- +#[test] +fn fox_n() -> TestResult { + run(&["-n", FOX], "tests/expected/fox.txt.n.out") +} + +// -------------------------------------------------- +#[test] +fn fox_b() -> TestResult { + run(&["-b", FOX], "tests/expected/fox.txt.b.out") +} + +// -------------------------------------------------- +#[test] +fn spiders() -> TestResult { + run(&[SPIDERS], "tests/expected/spiders.txt.out") +} + +// -------------------------------------------------- +#[test] +fn spiders_n() -> TestResult { + run(&["--number", SPIDERS], "tests/expected/spiders.txt.n.out") +} + +// -------------------------------------------------- +#[test] +fn spiders_b() -> TestResult { + run( + &["--number-nonblank", SPIDERS], + "tests/expected/spiders.txt.b.out", + ) +} + +// -------------------------------------------------- +#[test] +fn bustle() -> TestResult { + run(&[BUSTLE], "tests/expected/the-bustle.txt.out") +} + +// -------------------------------------------------- +#[test] +fn bustle_n() -> TestResult { + run(&["-n", BUSTLE], "tests/expected/the-bustle.txt.n.out") +} + +// -------------------------------------------------- +#[test] +fn bustle_b() -> TestResult { + run(&["-b", BUSTLE], "tests/expected/the-bustle.txt.b.out") +} + +// -------------------------------------------------- +#[test] +fn all() -> TestResult { + run(&[FOX, SPIDERS, BUSTLE], "tests/expected/all.out") +} + +// -------------------------------------------------- +#[test] +fn all_n() -> TestResult { + run(&[FOX, SPIDERS, BUSTLE, "-n"], "tests/expected/all.n.out") +} + +// -------------------------------------------------- +#[test] +fn all_b() -> TestResult { + run(&[FOX, SPIDERS, BUSTLE, "-b"], "tests/expected/all.b.out") +} diff --git a/tests/expected/all.b.out b/tests/expected/all.b.out new file mode 100644 index 0000000..152b15f --- /dev/null +++ b/tests/expected/all.b.out @@ -0,0 +1,13 @@ + 1 The quick brown fox jumps over the lazy dog. + 1 Don't worry, spiders, + 2 I keep house + 3 casually. + 1 The bustle in a house + 2 The morning after death + 3 Is solemnest of industries + 4 Enacted upon earth,— + + 5 The sweeping up the heart, + 6 And putting love away + 7 We shall not want to use again + 8 Until eternity. diff --git a/tests/expected/all.n.out b/tests/expected/all.n.out new file mode 100644 index 0000000..9176de6 --- /dev/null +++ b/tests/expected/all.n.out @@ -0,0 +1,13 @@ + 1 The quick brown fox jumps over the lazy dog. + 1 Don't worry, spiders, + 2 I keep house + 3 casually. + 1 The bustle in a house + 2 The morning after death + 3 Is solemnest of industries + 4 Enacted upon earth,— + 5 + 6 The sweeping up the heart, + 7 And putting love away + 8 We shall not want to use again + 9 Until eternity. diff --git a/tests/expected/all.out b/tests/expected/all.out new file mode 100644 index 0000000..1e3501a --- /dev/null +++ b/tests/expected/all.out @@ -0,0 +1,13 @@ +The quick brown fox jumps over the lazy dog. +Don't worry, spiders, +I keep house +casually. +The bustle in a house +The morning after death +Is solemnest of industries +Enacted upon earth,— + +The sweeping up the heart, +And putting love away +We shall not want to use again +Until eternity. diff --git a/tests/expected/empty.txt.b.out b/tests/expected/empty.txt.b.out new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/empty.txt.n.out b/tests/expected/empty.txt.n.out new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/empty.txt.out b/tests/expected/empty.txt.out new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/fox.txt.b.out b/tests/expected/fox.txt.b.out new file mode 100644 index 0000000..2daa68b --- /dev/null +++ b/tests/expected/fox.txt.b.out @@ -0,0 +1 @@ + 1 The quick brown fox jumps over the lazy dog. diff --git a/tests/expected/fox.txt.n.out b/tests/expected/fox.txt.n.out new file mode 100644 index 0000000..2daa68b --- /dev/null +++ b/tests/expected/fox.txt.n.out @@ -0,0 +1 @@ + 1 The quick brown fox jumps over the lazy dog. diff --git a/tests/expected/fox.txt.out b/tests/expected/fox.txt.out new file mode 100644 index 0000000..2fe6575 --- /dev/null +++ b/tests/expected/fox.txt.out @@ -0,0 +1 @@ +The quick brown fox jumps over the lazy dog. diff --git a/tests/expected/spiders.txt.b.out b/tests/expected/spiders.txt.b.out new file mode 100644 index 0000000..ab5ba3f --- /dev/null +++ b/tests/expected/spiders.txt.b.out @@ -0,0 +1,3 @@ + 1 Don't worry, spiders, + 2 I keep house + 3 casually. diff --git a/tests/expected/spiders.txt.n.out b/tests/expected/spiders.txt.n.out new file mode 100644 index 0000000..ab5ba3f --- /dev/null +++ b/tests/expected/spiders.txt.n.out @@ -0,0 +1,3 @@ + 1 Don't worry, spiders, + 2 I keep house + 3 casually. diff --git a/tests/expected/spiders.txt.out b/tests/expected/spiders.txt.out new file mode 100644 index 0000000..c29ddb0 --- /dev/null +++ b/tests/expected/spiders.txt.out @@ -0,0 +1,3 @@ +Don't worry, spiders, +I keep house +casually. diff --git a/tests/expected/the-bustle.txt.b.out b/tests/expected/the-bustle.txt.b.out new file mode 100644 index 0000000..0318cef --- /dev/null +++ b/tests/expected/the-bustle.txt.b.out @@ -0,0 +1,9 @@ + 1 The bustle in a house + 2 The morning after death + 3 Is solemnest of industries + 4 Enacted upon earth,— + + 5 The sweeping up the heart, + 6 And putting love away + 7 We shall not want to use again + 8 Until eternity. diff --git a/tests/expected/the-bustle.txt.b.stdin.out b/tests/expected/the-bustle.txt.b.stdin.out new file mode 100644 index 0000000..0318cef --- /dev/null +++ b/tests/expected/the-bustle.txt.b.stdin.out @@ -0,0 +1,9 @@ + 1 The bustle in a house + 2 The morning after death + 3 Is solemnest of industries + 4 Enacted upon earth,— + + 5 The sweeping up the heart, + 6 And putting love away + 7 We shall not want to use again + 8 Until eternity. diff --git a/tests/expected/the-bustle.txt.n.out b/tests/expected/the-bustle.txt.n.out new file mode 100644 index 0000000..41adb14 --- /dev/null +++ b/tests/expected/the-bustle.txt.n.out @@ -0,0 +1,9 @@ + 1 The bustle in a house + 2 The morning after death + 3 Is solemnest of industries + 4 Enacted upon earth,— + 5 + 6 The sweeping up the heart, + 7 And putting love away + 8 We shall not want to use again + 9 Until eternity. diff --git a/tests/expected/the-bustle.txt.n.stdin.out b/tests/expected/the-bustle.txt.n.stdin.out new file mode 100644 index 0000000..41adb14 --- /dev/null +++ b/tests/expected/the-bustle.txt.n.stdin.out @@ -0,0 +1,9 @@ + 1 The bustle in a house + 2 The morning after death + 3 Is solemnest of industries + 4 Enacted upon earth,— + 5 + 6 The sweeping up the heart, + 7 And putting love away + 8 We shall not want to use again + 9 Until eternity. diff --git a/tests/expected/the-bustle.txt.out b/tests/expected/the-bustle.txt.out new file mode 100644 index 0000000..a1fccbb --- /dev/null +++ b/tests/expected/the-bustle.txt.out @@ -0,0 +1,9 @@ +The bustle in a house +The morning after death +Is solemnest of industries +Enacted upon earth,— + +The sweeping up the heart, +And putting love away +We shall not want to use again +Until eternity. diff --git a/tests/expected/the-bustle.txt.stdin.out b/tests/expected/the-bustle.txt.stdin.out new file mode 100644 index 0000000..a1fccbb --- /dev/null +++ b/tests/expected/the-bustle.txt.stdin.out @@ -0,0 +1,9 @@ +The bustle in a house +The morning after death +Is solemnest of industries +Enacted upon earth,— + +The sweeping up the heart, +And putting love away +We shall not want to use again +Until eternity.