]> git.scottworley.com Git - tablify/blame_incremental - src/lib.rs
Read multiple row headers
[tablify] / src / lib.rs
... / ...
CommitLineData
1#[cfg(test)]
2use std::io::BufRead;
3#[cfg(test)]
4use std::iter::Iterator;
5
6#[derive(Debug, PartialEq, Eq)]
7struct RowInput {
8 label: String,
9 entries: Vec<String>,
10}
11
12#[cfg(test)]
13fn 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
20pub fn tablify(_input: &impl std::io::Read) -> String {
21 String::from("Hello, world!")
22}
23
24#[cfg(test)]
25mod 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}