]> git.scottworley.com Git - tablify/blob - src/lib.rs
1d098b03d1d314ec7d6c4e94a72f2f7e6b5b94ce
[tablify] / src / lib.rs
1 #[cfg(test)]
2 use std::io::BufRead;
3 #[cfg(test)]
4 use std::iter::Iterator;
5
6 #[derive(Debug, PartialEq, Eq)]
7 struct RowInput {
8 label: String,
9 entries: Vec<String>,
10 }
11
12 #[cfg(test)]
13 fn read_rows(input: impl std::io::Read) -> impl Iterator<Item = RowInput> {
14 std::io::BufReader::new(input).lines().map(|line| RowInput {
15 label: line.unwrap(),
16 entries: vec![],
17 })
18 }
19
20 pub fn tablify(_input: &impl std::io::Read) -> String {
21 String::from("Hello, world!")
22 }
23
24 #[cfg(test)]
25 mod tests {
26 use super::*;
27
28 #[test]
29 fn test_read_rows() {
30 assert_eq!(
31 read_rows(&b"foo"[..]).collect::<Vec<_>>(),
32 vec![RowInput {
33 label: String::from("foo"),
34 entries: vec![]
35 }]
36 );
37 assert_eq!(
38 read_rows(&b"bar"[..]).collect::<Vec<_>>(),
39 vec![RowInput {
40 label: String::from("bar"),
41 entries: vec![]
42 }]
43 );
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 );
57 }
58 }