This commit is contained in:
Aleksey Kladov 2020-04-25 11:38:10 +02:00
parent 93e0c7d77a
commit e584bb8384
3 changed files with 13 additions and 24 deletions

View File

@ -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()),
/// )
/// ```

View File

@ -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();
}

View File

@ -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]