summaryrefslogtreecommitdiffstats
path: root/third_party/rust/debugid/tests/test_serde.rs
blob: bda92232f9a341c3e8975270565bd510ac544318 (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
#![cfg(feature = "serde")]

use debugid::{CodeId, DebugId};
use uuid::Uuid;

#[test]
fn test_deserialize_debugid() {
    assert_eq!(
        DebugId::from_parts(
            Uuid::parse_str("dfb8e43a-f242-3d73-a453-aeb6a777ef75").unwrap(),
            0,
        ),
        serde_json::from_str("\"dfb8e43a-f242-3d73-a453-aeb6a777ef75\"").unwrap(),
    );
}

#[test]
fn test_serialize_debugid() {
    let id = DebugId::from_parts(
        Uuid::parse_str("dfb8e43a-f242-3d73-a453-aeb6a777ef75").unwrap(),
        0,
    );

    assert_eq!(
        "\"dfb8e43a-f242-3d73-a453-aeb6a777ef75\"",
        serde_json::to_string(&id).unwrap(),
    );
}

#[test]
fn test_deserialize_codeid() {
    assert_eq!(
        CodeId::new("dfb8e43af2423d73a453aeb6a777ef75".into()),
        serde_json::from_str("\"dfb8e43af2423d73a453aeb6a777ef75\"").unwrap(),
    );
}

#[test]
fn test_serialize_codeid() {
    assert_eq!(
        "\"dfb8e43af2423d73a453aeb6a777ef75\"",
        serde_json::to_string(&CodeId::new("dfb8e43af2423d73a453aeb6a777ef75".into())).unwrap(),
    );
}