changeset 50410:b5dd6d6d6fa6

rust-changelog: added a test for `NULL_REVISION` special case The result is due to `Revlog.get_rev_data()` returning an empty byte string for `NULL_REVISION`, followed by special case for emtpty byte strings in `ChangelogRevisionData::new()`.
author Georges Racinet <georges.racinet@octobus.net>
date Wed, 29 Mar 2023 21:03:39 +0200
parents b47a9316050a
children 841b13e6e84c
files rust/hg-core/src/revlog/changelog.rs
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/changelog.rs	Wed Mar 29 20:24:58 2023 +0200
+++ b/rust/hg-core/src/revlog/changelog.rs	Wed Mar 29 21:03:39 2023 +0200
@@ -215,6 +215,8 @@
 #[cfg(test)]
 mod tests {
     use super::*;
+    use crate::vfs::Vfs;
+    use crate::NULL_REVISION;
     use pretty_assertions::assert_eq;
 
     #[test]
@@ -268,4 +270,20 @@
         );
         assert_eq!(data.description(), b"some\ncommit\nmessage");
     }
+
+    #[test]
+    fn test_data_from_rev_null() -> Result<(), RevlogError> {
+        // an empty revlog will be enough for this case
+        let temp = tempfile::tempdir().unwrap();
+        let vfs = Vfs { base: temp.path() };
+        std::fs::write(temp.path().join("foo.i"), b"").unwrap();
+        let revlog = Revlog::open(&vfs, "foo.i", None, false).unwrap();
+
+        let changelog = Changelog { revlog };
+        assert_eq!(
+            changelog.data_for_rev(NULL_REVISION)?,
+            ChangelogRevisionData::null()
+        );
+        Ok(())
+    }
 }