| •1 |
use crate::{oid::ObjectId, tests::LOCK}; |
| 2 |
|
| 3 |
#[test] |
| 4 |
fn string_oid() { |
| 5 |
let _guard = LOCK.run_concurrently(); |
| 6 |
let s = "123456789012123456789012"; |
| 7 |
let oid_res = ObjectId::parse_str(s); |
| 8 |
assert!(oid_res.is_ok()); |
| 9 |
let actual_s = hex::encode(oid_res.unwrap().bytes()); |
| 10 |
assert_eq!(s.to_owned(), actual_s); |
| 11 |
} |
| 12 |
|
| 13 |
#[test] |
| 14 |
fn byte_string_oid() { |
| 15 |
let _guard = LOCK.run_concurrently(); |
| 16 |
let s = "541b1a00e8a23afa832b218e"; |
| 17 |
let oid_res = ObjectId::parse_str(s); |
| 18 |
assert!(oid_res.is_ok()); |
| 19 |
let oid = oid_res.unwrap(); |
| 20 |
let bytes: [u8; 12] = [ |
| 21 |
0x54u8, 0x1Bu8, 0x1Au8, 0x00u8, 0xE8u8, 0xA2u8, 0x3Au8, 0xFAu8, 0x83u8, 0x2Bu8, 0x21u8, |
| 22 |
0x8Eu8, |
| 23 |
]; |
| 24 |
|
| 25 |
assert_eq!(bytes, oid.bytes()); |
| 26 |
assert_eq!(s, oid.to_string()); |
| 27 |
} |
| 28 |
|
| 29 |
#[test] |
| 30 |
#[allow(clippy::eq_op)] |
| 31 |
fn oid_equals() { |
| 32 |
let _guard = LOCK.run_concurrently(); |
| 33 |
let oid = ObjectId::new(); |
| 34 |
assert_eq!(oid, oid); |
| 35 |
} |
| 36 |
|
| 37 |
#[test] |
| 38 |
fn oid_not_equals() { |
| 39 |
let _guard = LOCK.run_concurrently(); |
| 40 |
assert!(ObjectId::new() != ObjectId::new()); |
| 41 |
} |
| 42 |
|
| 43 |
// check that the last byte in objectIDs is increasing |
| 44 |
#[test] |
| 45 |
fn counter_increasing() { |
| 46 |
let _guard = LOCK.run_concurrently(); |
| 47 |
let oid1_bytes = ObjectId::new().bytes(); |
| 48 |
let oid2_bytes = ObjectId::new().bytes(); |
| 49 |
assert!(oid1_bytes[11] < oid2_bytes[11]); |
| 50 |
} |
| 51 |
|
| 52 |
#[test] |
| 53 |
fn fromstr_oid() { |
| 54 |
let _guard = LOCK.run_concurrently(); |
| 55 |
let s = "123456789012123456789012"; |
| 56 |
let oid_res = s.parse::<ObjectId>(); |
| 57 |
assert!(oid_res.is_ok(), "oid parse failed"); |
| 58 |
let actual_s = hex::encode(oid_res.unwrap().bytes()); |
| 59 |
assert_eq!(s, &actual_s, "parsed and expected oids differ"); |
| 60 |
} |