rust-changelog: added a test for `NULL_REVISION` special case
authorGeorges Racinet <georges.racinet@octobus.net>
Wed, 29 Mar 2023 21:03:39 +0200
changeset 50371 b5dd6d6d6fa6
parent 50370 b47a9316050a
child 50372 841b13e6e84c
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()`.
rust/hg-core/src/revlog/changelog.rs
--- 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(())
+    }
 }