From e584bb838442399daad59a68fa034762b6e2c296 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 25 Apr 2020 11:38:10 +0200 Subject: [PATCH] Fix docs --- lib/text-size/src/range.rs | 6 +++--- lib/text-size/tests/constructors.rs | 29 +++++++++-------------------- lib/text-size/tests/main.rs | 2 +- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/lib/text-size/src/range.rs b/lib/text-size/src/range.rs index 3b946ab436..fcf286d62e 100644 --- a/lib/text-size/src/range.rs +++ b/lib/text-size/src/range.rs @@ -98,8 +98,8 @@ impl TextRange { /// let range = TextRange::up_to(point); /// /// assert_eq!(range.len(), point); - /// assert_eq!(range, TextRange::new(TextSize::zero(), point)); - /// assert_eq!(range, TextRange::at(TextSize::zero(), point)); + /// assert_eq!(range, TextRange::new(0.into(), point)); + /// assert_eq!(range, TextRange::at(0.into(), point)); /// ``` #[inline] pub fn up_to(end: TextSize) -> TextRange { @@ -254,7 +254,7 @@ impl TextRange { /// ```rust /// # use text_size::*; /// assert_eq!( - /// TextRange::empty(TextSize::zero()).cover_offset(20.into()), + /// TextRange::empty(0.into()).cover_offset(20.into()), /// TextRange::new(0.into(), 20.into()), /// ) /// ``` diff --git a/lib/text-size/tests/constructors.rs b/lib/text-size/tests/constructors.rs index 9c9d0801ca..9ff4e19c62 100644 --- a/lib/text-size/tests/constructors.rs +++ b/lib/text-size/tests/constructors.rs @@ -1,35 +1,24 @@ -use { - std::{borrow::Cow, sync::Arc}, - text_size::*, -}; +use text_size::TextSize; #[derive(Copy, Clone)] struct BadRope<'a>(&'a [&'a str]); impl BadRope<'_> { fn text_len(self) -> TextSize { - self.0.iter().map(TextSize::of).sum() + self.0.iter().copied().map(TextSize::of).sum() } } #[test] fn main() { - macro_rules! test { - ($($expr:expr),+ $(,)?) => { - $(let _ = TextSize::of($expr);)+ - }; - } + let x: char = 'c'; + let _ = TextSize::of(x); - test! { - "", - &"", - 'a', - &'a', - &String::new(), - &String::new().into_boxed_str(), - &Arc::new(String::new()), - &Cow::Borrowed(""), - } + let x: &str = "hello"; + let _ = TextSize::of(x); + + let x: &String = &"hello".into(); + let _ = TextSize::of(x); let _ = BadRope(&[""]).text_len(); } diff --git a/lib/text-size/tests/main.rs b/lib/text-size/tests/main.rs index f8eb6d6735..5e6b86d659 100644 --- a/lib/text-size/tests/main.rs +++ b/lib/text-size/tests/main.rs @@ -26,7 +26,7 @@ fn checked_math() { assert_eq!(size(1).checked_add(size(1)), Some(size(2))); assert_eq!(size(1).checked_sub(size(1)), Some(size(0))); assert_eq!(size(1).checked_sub(size(2)), None); - assert_eq!(TextSize::MAX.checked_add(size(1)), None); + assert_eq!(size(!0).checked_add(size(1)), None); } #[test]