]> git.scottworley.com Git - tablify/blame - src/lib.rs
Read multiple row headers
[tablify] / src / lib.rs
CommitLineData
75bb888a 1#[cfg(test)]
9dfa98b7
SW
2use std::io::BufRead;
3#[cfg(test)]
75bb888a
SW
4use std::iter::Iterator;
5
6#[derive(Debug, PartialEq, Eq)]
7struct RowInput {
8 label: String,
9 entries: Vec<String>,
10}
11
12#[cfg(test)]
9dfa98b7 13fn read_rows(input: impl std::io::Read) -> impl Iterator<Item = RowInput> {
2aa9ef94
SW
14 std::io::BufReader::new(input).lines().map(|line| RowInput {
15 label: line.unwrap(),
75bb888a 16 entries: vec![],
2aa9ef94 17 })
75bb888a
SW
18}
19
ece97615
SW
20pub fn tablify(_input: &impl std::io::Read) -> String {
21 String::from("Hello, world!")
22}
75bb888a
SW
23
24#[cfg(test)]
25mod tests {
26 use super::*;
27
28 #[test]
29 fn test_read_rows() {
30 assert_eq!(
9dfa98b7 31 read_rows(&b"foo"[..]).collect::<Vec<_>>(),
75bb888a
SW
32 vec![RowInput {
33 label: String::from("foo"),
34 entries: vec![]
35 }]
36 );
9dfa98b7
SW
37 assert_eq!(
38 read_rows(&b"bar"[..]).collect::<Vec<_>>(),
39 vec![RowInput {
40 label: String::from("bar"),
41 entries: vec![]
42 }]
43 );
2aa9ef94
SW
44 assert_eq!(
45 read_rows(&b"foo\nbar\n"[..]).collect::<Vec<_>>(),
46 vec![
47 RowInput {
48 label: String::from("foo"),
49 entries: vec![]
50 },
51 RowInput {
52 label: String::from("bar"),
53 entries: vec![]
54 }
55 ]
56 );
75bb888a
SW
57 }
58}