From 766cf017cd3744598e6267c060ce7565548a5168 Mon Sep 17 00:00:00 2001 From: hcpl Date: Sun, 4 Jun 2017 09:32:42 +0300 Subject: Add tests regarding padding --- src/lib.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index f3111e9..c0184bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -603,7 +603,7 @@ mod tests { use row::Row; use cell::Cell; use format; - use format::consts::{FORMAT_NO_LINESEP, FORMAT_NO_COLSEP, FORMAT_CLEAN}; + use format::consts::{FORMAT_DEFAULT, FORMAT_NO_LINESEP, FORMAT_NO_COLSEP, FORMAT_CLEAN}; #[test] fn table() { @@ -718,6 +718,35 @@ mod tests { assert_eq!(out, table.to_string().replace("\r\n", "\n")); } + #[test] + fn padding() { + let mut table = Table::new(); + let mut format = *FORMAT_DEFAULT; + format.padding(2, 2); + table.set_format(format); + table.add_row(Row::new(vec![Cell::new("a"), Cell::new("bc"), Cell::new("def")])); + table.add_row(Row::new(vec![Cell::new("def"), Cell::new("bc"), Cell::new("a")])); + table.set_titles(Row::new(vec![Cell::new("t1"), Cell::new("t2"), Cell::new("t3")])); + assert_eq!(table[1][1].get_content(), "bc"); + + table[1][1] = Cell::new("newval"); + assert_eq!(table[1][1].get_content(), "newval"); + + let out = "\ ++-------+----------+-------+ +| t1 | t2 | t3 | ++=======+==========+=======+ +| a | bc | def | ++-------+----------+-------+ +| def | newval | a | ++-------+----------+-------+ +"; + println!("{}", out); + println!("____"); + println!("{}", table.to_string().replace("\r\n", "\n")); + assert_eq!(out, table.to_string().replace("\r\n", "\n")); + } + #[test] fn slices() { let mut table = Table::new(); -- cgit v1.2.3