Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--lib/text-size/src/range.rs32
-rw-r--r--lib/text-size/tests/main.rs14
2 files changed, 23 insertions, 23 deletions
diff --git a/lib/text-size/src/range.rs b/lib/text-size/src/range.rs
index fc0bbc8b47..df5296af14 100644
--- a/lib/text-size/src/range.rs
+++ b/lib/text-size/src/range.rs
@@ -88,8 +88,23 @@ impl TextRange {
/// Manipulation methods.
impl TextRange {
+ /// Check if this range contains an offset.
+ ///
+ /// The end index is considered excluded.
+ pub fn contains(self, offset: TextSize) -> bool {
+ self.start() <= offset && offset < self.end()
+ }
+
+ /// Check if this range contains an offset.
+ ///
+ /// The end index is considered included.
+ pub fn contains_inclusive(self, offset: TextSize) -> bool {
+ let point = offset.into();
+ self.start() <= point && point <= self.end()
+ }
+
/// Check if this range completely contains another range.
- pub fn contains(self, other: TextRange) -> bool {
+ pub fn contains_range(self, other: TextRange) -> bool {
self.start() <= other.start() && other.end() <= self.end()
}
@@ -110,21 +125,6 @@ impl TextRange {
let end = cmp::max(lhs.end(), rhs.end());
TextRange(start, end)
}
-
- /// Check if this range contains an offset.
- ///
- /// The end index is considered excluded.
- pub fn contains_exclusive(self, offset: TextSize) -> bool {
- self.start() <= offset && offset < self.end()
- }
-
- /// Check if this range contains an offset.
- ///
- /// The end index is considered included.
- pub fn contains_inclusive(self, offset: TextSize) -> bool {
- let point = offset.into();
- self.start() <= point && point <= self.end()
- }
}
impl Index<TextRange> for str {
diff --git a/lib/text-size/tests/main.rs b/lib/text-size/tests/main.rs
index 66b6106671..073c2ebaa3 100644
--- a/lib/text-size/tests/main.rs
+++ b/lib/text-size/tests/main.rs
@@ -32,8 +32,8 @@ fn checked_math() {
#[test]
#[rustfmt::skip]
fn contains() {
- assert!( range(2..4).contains(range(2..3)));
- assert!( ! range(2..4).contains(range(1..3)));
+ assert!( range(2..4).contains_range(range(2..3)));
+ assert!( ! range(2..4).contains_range(range(1..3)));
}
#[test]
@@ -59,11 +59,11 @@ fn covering() {
#[test]
#[rustfmt::skip]
fn contains_point() {
- assert!( ! range(1..3).contains_exclusive(size(0)));
- assert!( range(1..3).contains_exclusive(size(1)));
- assert!( range(1..3).contains_exclusive(size(2)));
- assert!( ! range(1..3).contains_exclusive(size(3)));
- assert!( ! range(1..3).contains_exclusive(size(4)));
+ assert!( ! range(1..3).contains(size(0)));
+ assert!( range(1..3).contains(size(1)));
+ assert!( range(1..3).contains(size(2)));
+ assert!( ! range(1..3).contains(size(3)));
+ assert!( ! range(1..3).contains(size(4)));
assert!( ! range(1..3).contains_inclusive(size(0)));
assert!( range(1..3).contains_inclusive(size(1)));