forked from BurntSushi/xsv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_fmt.rs
71 lines (58 loc) · 1.43 KB
/
test_fmt.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
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("fmt");
cmd.arg("in.csv");
(wrk, cmd)
}
#[test]
fn fmt_delimiter() {
let (wrk, mut cmd) = setup("fmt_delimiter");
cmd.args(&["--out-delimiter", "\t"]);
let got: String = wrk.stdout(&mut cmd);
let expected = "\
h1\th2
abcdef\tghijkl
mnopqr\tstuvwx";
assert_eq!(got, expected.to_string());
}
#[test]
fn fmt_weird_delimiter() {
let (wrk, mut cmd) = setup("fmt_weird_delimiter");
cmd.args(&["--out-delimiter", "h"]);
let got: String = wrk.stdout(&mut cmd);
let expected = "\
\"h1\"h\"h2\"
abcdefh\"ghijkl\"
mnopqrhstuvwx";
assert_eq!(got, expected.to_string());
}
#[test]
fn fmt_crlf() {
let (wrk, mut cmd) = setup("fmt_crlf");
cmd.arg("--crlf");
let got: String = wrk.stdout(&mut cmd);
let expected = "\
h1,h2\r
abcdef,ghijkl\r
mnopqr,stuvwx";
assert_eq!(got, expected.to_string());
}
#[test]
fn fmt_quote_always() {
let (wrk, mut cmd) = setup("fmt_quote_always");
cmd.arg("--quote-always");
let got: String = wrk.stdout(&mut cmd);
let expected = "\
\"h1\",\"h2\"
\"abcdef\",\"ghijkl\"
\"mnopqr\",\"stuvwx\"";
assert_eq!(got, expected.to_string());
}