# HG changeset patch # User Georges Racinet # Date 2023-03-29 19:03:39 # Node ID b5dd6d6d6fa61b5fa870aadebe016685b30e75f1 # Parent b47a9316050aa583a006cef9d60195e2ed6c41a1 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()`. diff --git a/rust/hg-core/src/revlog/changelog.rs b/rust/hg-core/src/revlog/changelog.rs --- a/rust/hg-core/src/revlog/changelog.rs +++ b/rust/hg-core/src/revlog/changelog.rs @@ -215,6 +215,8 @@ fn debug_bytes(bytes: &[u8]) -> String { #[cfg(test)] mod tests { use super::*; + use crate::vfs::Vfs; + use crate::NULL_REVISION; use pretty_assertions::assert_eq; #[test] @@ -268,4 +270,20 @@ message", ); 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(()) + } }