This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch exact-buffer
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git

commit 3eff133c185afb985cf36f442eee68de5032819c
Author: Xuanwo <[email protected]>
AuthorDate: Wed Aug 23 14:36:15 2023 +0800

    feat(core): Add unit test for ChunkedCursor
    
    Signed-off-by: Xuanwo <[email protected]>
---
 core/src/raw/oio/cursor.rs | 42 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 6 deletions(-)

diff --git a/core/src/raw/oio/cursor.rs b/core/src/raw/oio/cursor.rs
index 848bc1786..8fda30c60 100644
--- a/core/src/raw/oio/cursor.rs
+++ b/core/src/raw/oio/cursor.rs
@@ -205,11 +205,6 @@ impl ChunkedCursor {
         self.inner.iter().skip(self.idx).map(|v| v.len()).sum()
     }
 
-    /// Reset current cursor to start.
-    pub fn reset(&mut self) {
-        self.idx = 0;
-    }
-
     /// Clear the entire cursor.
     pub fn clear(&mut self) {
         self.idx = 0;
@@ -234,7 +229,7 @@ impl oio::Stream for ChunkedCursor {
     }
 
     fn poll_reset(&mut self, _: &mut Context<'_>) -> Poll<Result<()>> {
-        self.reset();
+        self.idx = 0;
         Poll::Ready(Ok(()))
     }
 }
@@ -402,6 +397,8 @@ impl VectorCursor {
 #[cfg(test)]
 mod tests {
     use super::*;
+    use crate::raw::oio::StreamExt;
+    use pretty_assertions::assert_eq;
 
     #[test]
     fn test_vector_cursor() {
@@ -422,4 +419,37 @@ mod tests {
         vc.take(5);
         assert_eq!(vc.peak_exact(1), Bytes::from("r"));
     }
+
+    #[tokio::test]
+    async fn test_chunked_cursor() -> Result<()> {
+        let mut c = ChunkedCursor::new();
+
+        c.push(Bytes::from("hello"));
+        assert_eq!(c.len(), 5);
+        assert!(!c.is_empty());
+
+        c.push(Bytes::from("world"));
+        assert_eq!(c.len(), 10);
+        assert!(!c.is_empty());
+
+        let bs = c.next().await.unwrap().unwrap();
+        assert_eq!(bs, Bytes::from("hello"));
+        assert_eq!(c.len(), 5);
+        assert!(!c.is_empty());
+
+        let bs = c.next().await.unwrap().unwrap();
+        assert_eq!(bs, Bytes::from("world"));
+        assert_eq!(c.len(), 0);
+        assert!(c.is_empty());
+
+        c.reset().await?;
+        assert_eq!(c.len(), 10);
+        assert!(!c.is_empty());
+
+        c.clear();
+        assert_eq!(c.len(), 0);
+        assert!(c.is_empty());
+
+        Ok(())
+    }
 }

Reply via email to