json_diff/
constants.rs

1use colored::*;
2use std::fmt;
3
4// PartialEq is added for the sake of Test case that uses assert_eq
5#[derive(Debug, PartialEq)]
6pub enum Message {
7    BadOption,
8    SOURCE1,
9    SOURCE2,
10    JSON1,
11    JSON2,
12    UnknownError,
13    NoMismatch,
14    RootMismatch,
15    LeftExtra,
16    RightExtra,
17    Mismatch,
18}
19
20impl fmt::Display for Message {
21    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
22        let message = match self {
23            Message::BadOption => "Invalid option.",
24            Message::SOURCE1 => "Could not read source1.",
25            Message::SOURCE2 => "Could not read source2.",
26            Message::JSON1 => "Could not parse source1.",
27            Message::JSON2 => "Could not parse source2.",
28            Message::UnknownError => "",
29            Message::NoMismatch => "No mismatch was found.",
30            Message::RootMismatch => "Mismatch at root.",
31            Message::LeftExtra => "Extra on left",
32            Message::RightExtra => "Extra on right",
33            Message::Mismatch => "Mismatched",
34        };
35
36        write!(f, "{}", message.bold())
37    }
38}