diff options
Diffstat (limited to 'src/output/cell.rs')
-rw-r--r-- | src/output/cell.rs | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/src/output/cell.rs b/src/output/cell.rs index d900f6d..b78f821 100644 --- a/src/output/cell.rs +++ b/src/output/cell.rs @@ -1,6 +1,6 @@ //! The `TextCell` type for the details and lines views. -use std::ops::{Deref, DerefMut}; +use std::ops::{Add, Deref, DerefMut}; use ansi_term::{Style, ANSIString, ANSIStrings}; use unicode_width::UnicodeWidthStr; @@ -202,4 +202,51 @@ impl DerefMut for DisplayWidth { fn deref_mut<'a>(&'a mut self) -> &'a mut Self::Target { &mut self.0 } -}
\ No newline at end of file +} + +impl Add for DisplayWidth { + type Output = DisplayWidth; + + fn add(self, rhs: DisplayWidth) -> Self::Output { + DisplayWidth(self.0 + rhs.0) + } +} + +impl Add<usize> for DisplayWidth { + type Output = DisplayWidth; + + fn add(self, rhs: usize) -> Self::Output { + DisplayWidth(self.0 + rhs) + } +} + + +#[cfg(test)] +mod width_unit_test { + use super::DisplayWidth; + + #[test] + fn empty_string() { + let cell = DisplayWidth::from(""); + assert_eq!(*cell, 0); + } + + #[test] + fn test_string() { + let cell = DisplayWidth::from("Diss Playwidth"); + assert_eq!(*cell, 14); + } + + #[test] + fn addition() { + let cell_one = DisplayWidth::from("/usr/bin/"); + let cell_two = DisplayWidth::from("drinking"); + assert_eq!(*(cell_one + cell_two), 17); + } + + #[test] + fn addition_usize() { + let cell = DisplayWidth::from("/usr/bin/"); + assert_eq!(*(cell + 8), 17); + } +} |