7631e57f69
- Add test_from_header_valid to verify valid repository header parsing - Add test_from_header_empty_path to handle empty path scenarios - Add test_from_header_relative_storage_path to validate absolute paths - Add test_from_header_relative_path_without_storage for missing storage - Add test_from_header_nonexistent_repo to check repo existence - Add test_from_header_path_traversal to prevent directory traversal - Add test_from_header_not_a_directory for file instead of directory - Add test_from_header_dir_without_head to verify bare repository format - Add test_object_format to validate object format detection - Add test_oid_to_pb to verify OID conversion functionality - Add test_oid_to_pb_invalid_hex to handle invalid hex input gracefully test(error): add comprehensive error handling tests - Add test_error_display_variants to verify error message formatting - Add test_error_is_debug to
79 lines
1.9 KiB
Rust
79 lines
1.9 KiB
Rust
use gitks::error::GitError;
|
|
use gitks::oid::{ObjectId, ZERO_OID, hex_to_bytes};
|
|
|
|
#[test]
|
|
fn test_hex_to_bytes_valid() {
|
|
let bytes = hex_to_bytes("abcdef0123456789").unwrap();
|
|
assert_eq!(bytes, vec![0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89]);
|
|
}
|
|
|
|
#[test]
|
|
fn test_hex_to_bytes_sha1() {
|
|
// 40-char SHA-1 hex
|
|
let hex = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
|
|
let bytes = hex_to_bytes(hex).unwrap();
|
|
assert_eq!(bytes.len(), 20);
|
|
}
|
|
|
|
#[test]
|
|
fn test_hex_to_bytes_odd_length() {
|
|
let result = hex_to_bytes("abc");
|
|
assert!(result.is_err());
|
|
match result.unwrap_err() {
|
|
GitError::InvalidOid(_) => {}
|
|
other => panic!("expected InvalidOid, got: {:?}", other),
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test_hex_to_bytes_invalid_hex() {
|
|
let result = hex_to_bytes("zzzz");
|
|
assert!(result.is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn test_hex_to_bytes_with_whitespace() {
|
|
let bytes = hex_to_bytes(" abcd ").unwrap();
|
|
assert_eq!(bytes, vec![0xab, 0xcd]);
|
|
}
|
|
|
|
#[test]
|
|
fn test_object_id_new_lowercase() {
|
|
let id = ObjectId::new("ABCDEF1234");
|
|
assert_eq!(id.as_str(), "abcdef1234");
|
|
}
|
|
|
|
#[test]
|
|
fn test_object_id_display() {
|
|
let id = ObjectId::new("abcdef");
|
|
assert_eq!(format!("{}", id), "abcdef");
|
|
}
|
|
|
|
#[test]
|
|
fn test_object_id_as_ref() {
|
|
let id = ObjectId::new("123456");
|
|
let s: &str = id.as_ref();
|
|
assert_eq!(s, "123456");
|
|
}
|
|
|
|
#[test]
|
|
fn test_object_id_try_into_gix() {
|
|
let hex = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
|
|
let id = ObjectId::new(hex);
|
|
let gix_id: gix::hash::ObjectId = (&id).try_into().unwrap();
|
|
assert_eq!(gix_id.to_string(), hex);
|
|
}
|
|
|
|
#[test]
|
|
fn test_object_id_try_into_invalid() {
|
|
let id = ObjectId::new("not_a_valid_hex_oid_at_all_way_too_long_for_any_hash");
|
|
let result: Result<gix::hash::ObjectId, _> = (&id).try_into();
|
|
assert!(result.is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn test_zero_oid() {
|
|
assert_eq!(ZERO_OID.len(), 40);
|
|
assert!(ZERO_OID.chars().all(|c| c == '0'));
|
|
}
|