forked from BurntSushi/xsv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_flatten.rs
84 lines (72 loc) · 1.45 KB
/
test_flatten.rs
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use std::process;
use workdir::Workdir;
fn setup(name: &str) -> (Workdir, process::Command) {
let rows = vec![
svec!["h1", "h2"],
svec!["abcdef", "ghijkl"],
svec!["mnopqr", "stuvwx"],
];
let wrk = Workdir::new(name);
wrk.create("in.csv", rows);
let mut cmd = wrk.command("flatten");
cmd.arg("in.csv");
(wrk, cmd)
}
#[test]
fn flatten_basic() {
let (wrk, mut cmd) = setup("flatten_basic");
let got: String = wrk.stdout(&mut cmd);
let expected = "\
h1 abcdef
h2 ghijkl
#
h1 mnopqr
h2 stuvwx\
";
assert_eq!(got, expected.to_string());
}
#[test]
fn flatten_no_headers() {
let (wrk, mut cmd) = setup("flatten_no_headers");
cmd.arg("--no-headers");
let got: String = wrk.stdout(&mut cmd);
let expected = "\
0 h1
1 h2
#
0 abcdef
1 ghijkl
#
0 mnopqr
1 stuvwx\
";
assert_eq!(got, expected.to_string());
}
#[test]
fn flatten_separator() {
let (wrk, mut cmd) = setup("flatten_separator");
cmd.args(&["--separator", "!mysep!"]);
let got: String = wrk.stdout(&mut cmd);
let expected = "\
h1 abcdef
h2 ghijkl
!mysep!
h1 mnopqr
h2 stuvwx\
";
assert_eq!(got, expected.to_string());
}
#[test]
fn flatten_condense() {
let (wrk, mut cmd) = setup("flatten_condense");
cmd.args(&["--condense", "2"]);
let got: String = wrk.stdout(&mut cmd);
let expected = "\
h1 ab...
h2 gh...
#
h1 mn...
h2 st...\
";
assert_eq!(got, expected.to_string());
}