+ assert_eq!(
+ read_rows(&b"bar"[..]).flatten().collect::<Vec<_>>(),
+ vec![Row {
+ label: "bar".to_owned(),
+ entries: HashMap::new(),
+ }]
+ );
+ assert_eq!(
+ read_rows(&b"foo\nbar\n"[..]).flatten().collect::<Vec<_>>(),
+ vec![
+ Row {
+ label: "foo".to_owned(),
+ entries: HashMap::new(),
+ },
+ Row {
+ label: "bar".to_owned(),
+ entries: HashMap::new(),
+ }
+ ]
+ );
+ assert_eq!(
+ read_rows(&b"foo\n bar\n"[..]).flatten().collect::<Vec<_>>(),
+ vec![Row {
+ label: "foo".to_owned(),
+ entries: HashMap::from([("bar".to_owned(), vec![None])]),
+ }]
+ );
+ assert_eq!(
+ read_rows(&b"foo\n bar\n baz\n"[..])
+ .flatten()
+ .collect::<Vec<_>>(),
+ vec![Row {
+ label: "foo".to_owned(),
+ entries: HashMap::from([
+ ("bar".to_owned(), vec![None]),
+ ("baz".to_owned(), vec![None])
+ ]),
+ }]
+ );
+ assert_eq!(
+ read_rows(&b"foo\n\nbar\n"[..])
+ .flatten()
+ .collect::<Vec<_>>(),
+ vec![
+ Row {
+ label: "foo".to_owned(),
+ entries: HashMap::new(),
+ },
+ Row {
+ label: "bar".to_owned(),
+ entries: HashMap::new(),
+ }
+ ]
+ );
+ assert_eq!(
+ read_rows(&b"foo\n \nbar\n"[..])
+ .flatten()
+ .collect::<Vec<_>>(),
+ vec![
+ Row {
+ label: "foo".to_owned(),
+ entries: HashMap::new(),
+ },
+ Row {
+ label: "bar".to_owned(),
+ entries: HashMap::new(),
+ }
+ ]
+ );
+ assert_eq!(
+ read_rows(&b"foo \n bar \n"[..])
+ .flatten()
+ .collect::<Vec<_>>(),
+ vec![Row {
+ label: "foo".to_owned(),
+ entries: HashMap::from([("bar".to_owned(), vec![None])]),
+ }]
+ );
+
+ let bad = read_rows(&b" foo"[..]).next().unwrap();
+ assert!(bad.is_err());
+ assert!(format!("{bad:?}").contains("1: Entry with no header"));
+
+ let bad2 = read_rows(&b"foo\n\n bar"[..]).nth(1).unwrap();
+ assert!(bad2.is_err());
+ assert!(format!("{bad2:?}").contains("3: Entry with no header"));
+ }
+
+ #[test]
+ fn test_column_counts() {
+ assert_eq!(
+ column_counts(
+ &read_rows(&b"foo\n bar\n baz\n"[..])
+ .collect::<Result<Vec<_>, _>>()
+ .unwrap()
+ ),
+ vec![(1, String::from("bar")), (1, String::from("baz"))]
+ );
+ assert_eq!(
+ column_counts(
+ &read_rows(&b"foo\n bar\n baz\nquux\n baz"[..])
+ .collect::<Result<Vec<_>, _>>()
+ .unwrap()
+ ),
+ vec![(2, String::from("baz")), (1, String::from("bar"))]
+ );
+ assert_eq!(
+ column_counts(
+ &read_rows(&b"foo\n bar\n bar\n baz\n bar\nquux\n baz"[..])
+ .collect::<Result<Vec<_>, _>>()
+ .unwrap()
+ ),
+ vec![(2, String::from("baz")), (1, String::from("bar"))]
+ );
+ assert_eq!(
+ column_counts(
+ &read_rows(&b"foo\n bar: 1\n bar: 2\n baz\n bar\nquux\n baz"[..])
+ .collect::<Result<Vec<_>, _>>()
+ .unwrap()
+ ),
+ vec![(2, String::from("baz")), (1, String::from("bar"))]
+ );
+ }
+
+ #[test]
+ fn test_render_cell() {
+ assert_eq!(
+ render_cell(
+ "foo",
+ &Row {
+ label: "nope".to_owned(),
+ entries: HashMap::new(),
+ }
+ ),
+ HTML::from("<td class=\"\" onmouseover=\"h2('nope','foo')\" onmouseout=\"ch2('nope','foo')\"></td>")
+ );
+ assert_eq!(
+ render_cell(
+ "foo",
+ &Row {
+ label: "nope".to_owned(),
+ entries: HashMap::from([("bar".to_owned(), vec![None])]),
+ }
+ ),
+ HTML::from("<td class=\"\" onmouseover=\"h2('nope','foo')\" onmouseout=\"ch2('nope','foo')\"></td>")
+ );
+ assert_eq!(
+ render_cell(
+ "foo",
+ &Row {
+ label: "nope".to_owned(),
+ entries: HashMap::from([("foo".to_owned(), vec![None])]),
+ }
+ ),
+ HTML::from("<td class=\"yes\" onmouseover=\"h2('nope','foo')\" onmouseout=\"ch2('nope','foo')\"></td>")
+ );
+ assert_eq!(
+ render_cell(
+ "foo",
+ &Row {
+ label: "nope".to_owned(),
+ entries: HashMap::from([("foo".to_owned(), vec![None, None])]),
+ }
+ ),
+ HTML::from("<td class=\"yes\" onmouseover=\"h2('nope','foo')\" onmouseout=\"ch2('nope','foo')\">2</td>")
+ );
+ assert_eq!(
+ render_cell(
+ "foo",
+ &Row {
+ label: "nope".to_owned(),
+ entries: HashMap::from([("foo".to_owned(), vec![Some("5".to_owned()), Some("10".to_owned())])]),
+ }
+ ),
+ HTML::from("<td class=\"yes\" onmouseover=\"h2('nope','foo')\" onmouseout=\"ch2('nope','foo')\">5 10</td>")
+ );
+ assert_eq!(
+ render_cell(
+ "foo",
+ &Row {
+ label: "nope".to_owned(),
+ entries: HashMap::from([("foo".to_owned(), vec![Some("5".to_owned()), None])]),
+ }
+ ),
+ HTML::from("<td class=\"yes\" onmouseover=\"h2('nope','foo')\" onmouseout=\"ch2('nope','foo')\">5 ✓</td>")
+ );
+ assert_eq!(
+ render_cell(
+ "heart",
+ &Row {
+ label: "nope".to_owned(),
+ entries: HashMap::from([("heart".to_owned(), vec![Some("<3".to_owned())])]),
+ }
+ ),
+ HTML::from("<td class=\"yes\" onmouseover=\"h2('nope','heart')\" onmouseout=\"ch2('nope','heart')\"><3</td>")
+ );
+ assert_eq!(
+ render_cell(
+ "foo",
+ &Row {
+ label: "bob's".to_owned(),
+ entries: HashMap::from([("foo".to_owned(), vec![None])]),
+ }
+ ),
+ HTML::from("<td class=\"yes\" onmouseover=\"h2('bob's','foo')\" onmouseout=\"ch2('bob's','foo')\"></td>")
+ );