use bwrap::Result; use bwrap::WrapStyle; use bwrap::Wrapper; mod ascii { use super::*; #[test] fn _1() -> Result<()> { let before = "hhhhh"; let mut after = [0u8; 256]; let len = Wrapper::new(before, 3, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("-"), None))?; assert_eq!(&after[..len], "hhh-\nhh".as_bytes()); assert_eq!(unicode_width::UnicodeWidthStr::width("⤶"), 1); let len = Wrapper::new(before, 3, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!(&after[..len], "hhh⤶\nhh".as_bytes()); Ok(()) } #[test] fn _2() -> Result<()> { let before = "hhhhh hhhhh"; let mut after = [0u8; 256]; let len = Wrapper::new(before, 3, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!(&after[..len], "hhh⤶\nhh ⤶\nhhh⤶\nhh".as_bytes()); Ok(()) } #[test] fn _3() -> Result<()> { let before = "hello hello hello"; let mut after = [0u8; 256]; let len = Wrapper::new(before, 4, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!(&after[..len], "hell⤶\no he⤶\nllo ⤶\nhell⤶\no".as_bytes()); Ok(()) } // - } mod nonascii { use super::*; #[test] fn _1() -> Result<()> { let before = "HHHHH"; let mut after = [0u8; 256]; let len = Wrapper::new(before, 7, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!(&after[..len], "HHH⤶\nHH".as_bytes()); Ok(()) } #[test] fn _2() -> Result<()> { let before = "HHHHH HHHHH"; let mut after = [0u8; 256]; let len = Wrapper::new(before, 7, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!(&after[..len], "HHH⤶\nHH H⤶\nHHH⤶\nH".as_bytes()); Ok(()) } #[test] fn _3() -> Result<()> { let before = "HHHHH HHHHH HHHHH"; let mut after = [0u8; 256]; let len = Wrapper::new(before, 7, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!( &after[..len], "HHH⤶\nHH H⤶\nHHH⤶\nH HH⤶\nHHH".as_bytes() ); Ok(()) } #[test] fn _4() -> Result<()> { let before = "HHHHH HHHHH HHHHH HHHHH"; let mut after = [0u8; 315]; let len = Wrapper::new(before, 7, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!( &after[..len], "HHH⤶\nHH H⤶\nHHH⤶\nH HH⤶\nHHH ⤶\nHHH⤶\nHH".as_bytes() ); Ok(()) } #[test] fn _5() -> Result<()> { let before = "HHHHH HHHhH HHHHH HHHHH"; let mut after = [0u8; 305]; let len = Wrapper::new(before, 7, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!( &after[..len], "HHH⤶\nHH H⤶\nHHhH⤶\n HHH⤶\nHH H⤶\nHHH⤶\nH".as_bytes() ); Ok(()) } #[test] fn _6() -> Result<()> { let before = " HHHHH HHHHH HHHHH "; let mut after = [0u8; 285]; let len = Wrapper::new(before, 7, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!( &after[..len], " HH⤶\nHHH ⤶\n HH⤶\nHHH ⤶\n HH⤶\nHHH ⤶\n ".as_bytes() ); Ok(()) } } mod nonascii_existnl { use super::*; #[test] fn _1() -> Result<()> { let before = "HHH\nHH"; let mut after = [0u8; 256]; let len = Wrapper::new(before, 7, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!(&after[..len], "HHH\nHH".as_bytes()); Ok(()) } #[test] fn _11() -> Result<()> { let before = "HHH\nHH \n"; let mut after = [0u8; 256]; let len = Wrapper::new(before, 7, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!(&after[..len], "HHH\nHH \n".as_bytes()); Ok(()) } #[test] fn _111() -> Result<()> { let before = "HHH\nHH \n"; let mut after = [0u8; 256]; let len = Wrapper::new(before, 7, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!(&after[..len], "HHH\nHH ⤶\n \n".as_bytes()); Ok(()) } #[test] fn _1111() -> Result<()> { let before = "HHH\nHH \n"; let mut after = [0u8; 256]; let len = Wrapper::new(before, 7, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!(&after[..len], "HHH\nHH ⤶\n ⤶\n \n".as_bytes()); Ok(()) } #[test] fn _11111() -> Result<()> { let before = " HHH\nHH \n"; let mut after = [0u8; 256]; let len = Wrapper::new(before, 7, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!( &after[..len], " H⤶\nHH\nHH ⤶\n ⤶\n \n".as_bytes() ); Ok(()) } #[test] fn _111111() -> Result<()> { let before = " HHH\nHH \n"; let mut after = [0u8; 256]; let len = Wrapper::new(before, 7, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!( &after[..len], " ⤶\n H⤶\nHH\nHH ⤶\n ⤶\n \n".as_bytes() ); Ok(()) } #[test] fn _2() -> Result<()> { let before = "HHH\nHH HHHHH"; let mut after = [0u8; 256]; let len = Wrapper::new(before, 7, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!(&after[..len], "HHH\nHH H⤶\nHHH⤶\nH".as_bytes()); Ok(()) } #[test] fn _3() -> Result<()> { let before = "HHH\nHH H\nHHHH HH\nHHH"; let mut after = [0u8; 256]; let len = Wrapper::new(before, 7, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!( &after[..len], "HHH\nHH H\nHHH⤶\nH HH\nHHH".as_bytes() ); Ok(()) } #[test] fn _4() -> Result<()> { let before = "HHH\n\n\nHH H\n\n\nHHHH HH\n\n\nHHH"; let mut after = [0u8; 280]; let len = Wrapper::new(before, 7, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!( &after[..len], "HHH\n\n\nHH H\n\n\nHHH⤶\nH HH\n\n\nHHH".as_bytes() ); Ok(()) } #[test] fn _5() -> Result<()> { // similar to _4, but longer let before = "\n\n\nHHH\n\n\nHH H\n\n\nHHHH HH\n\n\nHHH\n\n\n"; let mut after = [0u8; 310]; let len = Wrapper::new(before, 7, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!( &after[..len], "\n\n\nHHH\n\n\nHH H\n\n\nHHH⤶\nH HH\n\n\nHHH\n\n\n".as_bytes() ); Ok(()) } #[test] fn _6() -> Result<()> { // similar to _5, but with one ascii let before = "\n\n\nHHH\n\n\nHH H\n\n\nHHHh HH\n\n\nHHH\n\n\n"; let mut after = [0u8; 300]; let len = Wrapper::new(before, 7, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!( &after[..len], "\n\n\nHHH\n\n\nHH H\n\n\nHHHh⤶\n HH\n\n\nHHH\n\n\n".as_bytes() ); Ok(()) } #[test] fn _7() -> Result<()> { let before = "\nH\nH\nH\nH\nH\nH\nH\nH\nH\nH\n"; let mut after = [0u8; 256]; let len = Wrapper::new(before, 1, &mut after)? .wrap_use_style(WrapStyle::MayBrk(Some("⤶"), None))?; assert_eq!( &after[..len], "\n⤶\nH\n⤶\nH\n⤶\nH\n⤶\nH\n⤶\nH\n⤶\nH\n⤶\nH\n⤶\nH\n⤶\nH\n⤶\nH\n".as_bytes() ); Ok(()) } //- }