1use refix_dictionary::spec::DataType;
2
3use crate::NameClash;
4
5#[derive(Debug, Eq, PartialEq)]
7pub enum Warning {
8 Renamed { clash: Box<NameClash>, name: String },
10 UnclaimedType { field: String, data_type: DataType },
12}
13
14impl std::fmt::Display for Warning {
15 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16 match self {
17 Warning::Renamed { clash, name } => write!(
18 f,
19 "`{}` is taken by {}, so {} is named `{name}`",
20 clash.name, clash.first, clash.second
21 ),
22 Warning::UnclaimedType { field, data_type } => write!(
23 f,
24 "field '{field}' has type {data_type}, which is not interpreted, so it reads as \
25 raw bytes"
26 ),
27 }
28 }
29}
30
31#[cfg(test)]
32mod tests {
33 use super::Warning;
34 use crate::{NameClash, Owner};
35 use refix_dictionary::spec::DataType;
36
37 #[test]
38 fn a_rename_names_both_owners_and_the_new_name() {
39 let warning = Warning::Renamed {
40 clash: Box::new(NameClash {
41 name: "SecurityStatus".to_owned(),
42 first: Owner::Message("SecurityStatus".to_owned()),
43 second: Owner::Enum("SecurityStatus".to_owned()),
44 }),
45 name: "SecurityStatusEnum".to_owned(),
46 };
47 assert_eq!(
48 warning.to_string(),
49 "`SecurityStatus` is taken by message 'SecurityStatus', so the enum of field \
50 'SecurityStatus' is named `SecurityStatusEnum`"
51 );
52 }
53
54 #[test]
55 fn an_unclaimed_type_names_the_field_and_its_type() {
56 let warning = Warning::UnclaimedType {
57 field: "RatioQty".to_owned(),
58 data_type: DataType::Other("QUANTITY".to_owned()),
59 };
60 assert_eq!(
61 warning.to_string(),
62 "field 'RatioQty' has type QUANTITY, which is not interpreted, so it reads as raw bytes"
63 );
64 }
65}