1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
use swhid::content::*;
use swhid::{ObjectType, Swhid};
#[test]
fn content_from_bytes() {
let data = b"test content";
let content = Content::from_bytes(data);
assert_eq!(content.len(), 12); // "test content" is 12 bytes
assert!(!content.is_empty());
}
#[test]
fn content_from_vec() {
let data = vec![1, 2, 3, 4, 5];
let content = Content::from_bytes(data);
assert_eq!(content.len(), 5);
}
#[test]
fn content_from_slice() {
let data = &[1, 2, 3, 4, 5];
let content = Content::from_bytes(data);
assert_eq!(content.len(), 5);
}
#[test]
fn content_empty() {
let content = Content::from_bytes(&[]);
assert_eq!(content.len(), 0);
assert!(content.is_empty());
}
#[test]
fn content_swhid_consistency() {
let data = b"consistent test";
let content1 = Content::from_bytes(data);
let content2 = Content::from_bytes(data);
assert_eq!(content1.swhid(), content2.swhid());
}
#[test]
fn content_swhid_different_data() {
let content1 = Content::from_bytes(b"data1");
let content2 = Content::from_bytes(b"data2");
assert_ne!(content1.swhid(), content2.swhid());
}
#[test]
fn content_swhid_empty() {
let content = Content::from_bytes(&[]);
let swhid = content.swhid();
assert_eq!(swhid.object_type(), ObjectType::Content);
assert_eq!(
swhid.to_string(),
"swh:1:cnt:e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
);
}
#[test]
fn content_swhid_hello_world() {
let content = Content::from_bytes(b"Hello, World!");
let swhid = content.swhid();
assert_eq!(swhid.object_type(), ObjectType::Content);
assert_eq!(
swhid.to_string(),
"swh:1:cnt:b45ef6fec89518d314f546fd6c3025367b721684"
);
}
#[test]
fn content_unicode() {
let unicode_data = "Hello, δΈη! π";
let content = Content::from_bytes(unicode_data.as_bytes());
let swhid = content.swhid();
assert_eq!(swhid.object_type(), ObjectType::Content);
assert_eq!(swhid.digest_bytes().len(), 20);
}
#[test]
fn content_large_data() {
let large_data = vec![0u8; 10000];
let content = Content::from_bytes(large_data);
let swhid = content.swhid();
assert_eq!(swhid.object_type(), ObjectType::Content);
assert_eq!(swhid.digest_bytes().len(), 20);
}
#[test]
fn content_binary_data() {
let binary_data = vec![0x00, 0x01, 0xFF, 0xFE, 0x80, 0x7F];
let content = Content::from_bytes(binary_data);
let swhid = content.swhid();
assert_eq!(swhid.object_type(), ObjectType::Content);
assert_eq!(swhid.digest_bytes().len(), 20);
}
#[test]
fn content_newline_variations() {
let unix_content = Content::from_bytes(b"line1\nline2\n");
let windows_content = Content::from_bytes(b"line1\r\nline2\r\n");
let mac_content = Content::from_bytes(b"line1\rline2\r");
assert_ne!(unix_content.swhid(), windows_content.swhid());
assert_ne!(unix_content.swhid(), mac_content.swhid());
assert_ne!(windows_content.swhid(), mac_content.swhid());
}
#[test]
fn content_cow_borrowed() {
let data = b"borrowed data";
let content = Content::from_bytes(data);
assert_eq!(content.len(), 13);
}
#[test]
fn content_cow_owned() {
let data = vec![1, 2, 3, 4, 5];
let content = Content::from_bytes(data);
assert_eq!(content.len(), 5);
}
#[test]
fn content_swhid_roundtrip() {
let data = b"roundtrip test";
let content = Content::from_bytes(data);
let swhid = content.swhid();
let swhid_str = swhid.to_string();
let parsed: Swhid = swhid_str.parse().unwrap();
assert_eq!(swhid, parsed);
}
#[test]
fn content_swhid_format() {
let content = Content::from_bytes(b"test");
let swhid = content.swhid();
let swhid_str = swhid.to_string();
assert!(swhid_str.starts_with("swh:1:cnt:"));
assert_eq!(swhid_str.len(), "swh:1:cnt:".len() + 40);
}
#[test]
fn content_swhid_digest_hex() {
let content = Content::from_bytes(b"test");
let swhid = content.swhid();
let hex = swhid.digest_hex();
assert_eq!(hex.len(), 40);
assert!(hex.chars().all(|c| c.is_ascii_hexdigit()));
}
#[test]
fn content_swhid_digest_bytes() {
let content = Content::from_bytes(b"test");
let swhid = content.swhid();
let bytes = swhid.digest_bytes();
assert_eq!(bytes.len(), 20);
}
#[test]
fn content_swhid_object_type() {
let content = Content::from_bytes(b"test");
let swhid = content.swhid();
assert_eq!(swhid.object_type(), ObjectType::Content);
}
#[test]
fn content_swhid_version() {
let _content = Content::from_bytes(b"test");
assert_eq!(Swhid::VERSION, "1");
}
#[test]
fn content_swhid_equality() {
let data = b"equality test";
let content1 = Content::from_bytes(data);
let content2 = Content::from_bytes(data);
assert_eq!(content1.swhid(), content2.swhid());
}
#[test]
fn content_swhid_hash_consistency() {
let data = b"hash consistency test";
let content = Content::from_bytes(data);
let swhid1 = content.swhid();
let swhid2 = content.swhid();
assert_eq!(swhid1, swhid2);
}
|