summaryrefslogtreecommitdiff
path: root/rust-bindings/src/tests/collection_ref.rs
blob: 515bd3858193b0628ad164000cacc2b3efb1208f (plain)
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
#![cfg(feature = "v2018_6")]

use crate::CollectionRef;
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};

fn hash(v: &impl Hash) -> u64 {
    let mut s = DefaultHasher::new();
    v.hash(&mut s);
    s.finish()
}

#[test]
fn same_value_should_be_equal() {
    let r = CollectionRef::new(Some("io.gitlab.fkrull"), "ref");
    assert_eq!(r, r);
}

#[test]
fn equal_values_should_be_equal() {
    let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref");
    let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref");
    assert_eq!(a, b);
}

#[test]
fn equal_values_without_collection_id_should_be_equal() {
    let a = CollectionRef::new(None, "ref-name");
    let b = CollectionRef::new(None, "ref-name");
    assert_eq!(a, b);
}

#[test]
fn different_values_should_not_be_equal() {
    let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref1");
    let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref2");
    assert_ne!(a, b);
}

#[test]
fn hash_for_equal_values_should_be_equal() {
    let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref");
    let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref");
    assert_eq!(hash(&a), hash(&b));
}

#[test]
fn hash_for_values_with_different_collection_id_should_be_different() {
    let a = CollectionRef::new(Some("io.gitlab.fkrull1"), "ref");
    let b = CollectionRef::new(Some("io.gitlab.fkrull2"), "ref");
    assert_ne!(hash(&a), hash(&b));
}

#[test]
fn hash_for_values_with_different_ref_id_should_be_different() {
    let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref-1");
    let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref-2");
    assert_ne!(hash(&a), hash(&b));
}

#[test]
fn hash_should_be_different_if_collection_id_is_absent() {
    let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref");
    let b = CollectionRef::new(None, "ref");
    assert_ne!(hash(&a), hash(&b));
}

#[test]
fn clone_should_be_equal_to_original_value() {
    let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref");
    let b = a.clone();
    assert_eq!(a, b);
}