multiversx_sc_meta/cmd/code_report/
compare.rs

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
pub(crate) fn size_status_after_comparing(size: usize, compared_size: usize) -> String {
    match size.cmp(&compared_size) {
        std::cmp::Ordering::Greater => {
            format!(
                "{} :arrow_right: {} :red_circle: (+{})",
                compared_size,
                size,
                size - compared_size
            )
        },
        std::cmp::Ordering::Less => {
            format!(
                "{} :arrow_right: {} :green_circle: (-{})",
                compared_size,
                size,
                compared_size - size
            )
        },
        std::cmp::Ordering::Equal => {
            format!("{}", size)
        },
    }
}

pub(crate) fn allocator_status_after_comparing(
    has_allocator: bool,
    compared_has_allocator: bool,
) -> String {
    if compared_has_allocator == has_allocator {
        return format!("{}", has_allocator);
    }

    let allocator_status = format!("{} :arrow-right: {}", compared_has_allocator, has_allocator);

    if !has_allocator {
        format!("{allocator_status} :green-circle:")
    } else {
        format!("{allocator_status} :red-circle:")
    }
}

pub(crate) fn panic_status_after_comparing(
    has_panic: &String,
    compared_has_panic: &String,
) -> String {
    if has_panic == compared_has_panic {
        return has_panic.to_string();
    }

    let panic_status = format!("{} :arrow-right: {}", compared_has_panic, has_panic);

    if has_panic == "none" {
        return format!("{panic_status} :green-circle:");
    }

    panic_status
}