chiark / gitweb /
zcoord: document (and test a bit more) range_upto()
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 10 Jul 2021 15:07:16 +0000 (16:07 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 10 Jul 2021 15:08:20 +0000 (16:08 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
base/zcoord.rs

index a04abb9cb614857ae31ede5ea48cf1051f85072e..2f3e8690c5463c1becb3a16259f4e2f2caeffdd4 100644 (file)
@@ -427,6 +427,9 @@ impl Mutable {
   }
 
   #[throws(RangeBackwards)]
+  /// Iterator producing a half-open range `[self, other>`
+  ///
+  /// Produces precisely `count` items.
   pub fn range_upto(&self, other: &Mutable, count: RangeCount)
                     -> RangeIterator {
     let (current, aso) = Mutable::range_core(self, other, count)?;
@@ -919,6 +922,15 @@ mod test {
     it.nxt("3333333334_0000000020");
     it.nxt("3333333334_0000000030");
     assert_eq!(it.i.next(), None);
+
+    let x = bf("1000000000").clone_mut();
+    let y = bf("2000000000").clone_mut();
+    let i = x.range_upto(&y, 3).unwrap();
+    let mut it = It { i, last: x.repack().unwrap() };
+    it.nxt("1800000000");
+    it.nxt("1g00000000");
+    it.nxt("1o00000000");
+    assert_eq!(it.i.next(), None);
   }
 
   #[test]