@@ -292,6 +292,80 @@ mod write_object {
292292 ) ;
293293 Ok ( ( ) )
294294 }
295+
296+ #[ test]
297+ fn blob_write_to_implementation ( ) -> crate :: Result {
298+ let repo = empty_bare_in_memory_repo ( ) ?;
299+ let test_data = b"hello world" ;
300+
301+ // Create a blob directly to test our WriteTo implementation
302+ let blob_id = repo. write_blob ( test_data) ?;
303+ let blob = repo. find_object ( blob_id) ?. into_blob ( ) ;
304+
305+ // Test that we can use the blob with write_object (which requires WriteTo)
306+ let written_id = repo. write_object ( blob) ?;
307+
308+ // The written blob should have the same ID as the original
309+ assert_eq ! ( blob_id, written_id, "WriteTo implementation should produce identical blob" ) ;
310+
311+ // Verify the content is correct
312+ let retrieved_blob = repo. find_object ( written_id) ?. into_blob ( ) ;
313+ assert_eq ! ( retrieved_blob. data, test_data, "Blob data should be preserved" ) ;
314+
315+ Ok ( ( ) )
316+ }
317+
318+ #[ test]
319+ fn blob_write_to_properties ( ) -> crate :: Result {
320+ let repo = empty_bare_in_memory_repo ( ) ?;
321+ let test_data = b"test data for WriteTo properties" ;
322+
323+ // Create a blob to test WriteTo trait methods
324+ let blob_id = repo. write_blob ( test_data) ?;
325+ let blob = repo. find_object ( blob_id) ?. into_blob ( ) ;
326+
327+ // Test WriteTo trait methods directly
328+ use gix_object:: WriteTo ;
329+
330+ // Test kind() method
331+ assert_eq ! ( blob. kind( ) , gix_object:: Kind :: Blob , "kind() should return Blob" ) ;
332+
333+ // Test size() method
334+ assert_eq ! ( blob. size( ) , test_data. len( ) as u64 , "size() should return data length" ) ;
335+
336+ // Test write_to() method
337+ let mut buffer = Vec :: new ( ) ;
338+ blob. write_to ( & mut buffer) ?;
339+ assert_eq ! ( buffer, test_data, "write_to() should write blob data verbatim" ) ;
340+
341+ Ok ( ( ) )
342+ }
343+
344+ #[ test]
345+ fn blob_write_to_empty_blob ( ) -> crate :: Result {
346+ let repo = empty_bare_in_memory_repo ( ) ?;
347+ let empty_data = b"" ;
348+
349+ // Create an empty blob to test edge case
350+ let blob_id = repo. write_blob ( empty_data) ?;
351+ let blob = repo. find_object ( blob_id) ?. into_blob ( ) ;
352+
353+ // Test WriteTo trait methods with empty blob
354+ use gix_object:: WriteTo ;
355+
356+ assert_eq ! ( blob. kind( ) , gix_object:: Kind :: Blob , "kind() should return Blob for empty blob" ) ;
357+ assert_eq ! ( blob. size( ) , 0 , "size() should return 0 for empty blob" ) ;
358+
359+ let mut buffer = Vec :: new ( ) ;
360+ blob. write_to ( & mut buffer) ?;
361+ assert_eq ! ( buffer, empty_data, "write_to() should write empty data for empty blob" ) ;
362+
363+ // Test that we can write the empty blob using write_object
364+ let written_id = repo. write_object ( blob) ?;
365+ assert_eq ! ( blob_id, written_id, "WriteTo implementation should work for empty blobs" ) ;
366+
367+ Ok ( ( ) )
368+ }
295369}
296370
297371mod write_blob {
0 commit comments