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 74 75 76 77
use specs::*; use util::*; pub trait Named { fn name(&self) -> String; fn camel_name(&self) -> String; fn snake_name(&self) -> String; } macro_rules! named { ($t:ty) => { impl Named for $t { fn name(&self) -> String { self.name.clone() } fn camel_name(&self) -> String { camel_case(&self.name) } fn snake_name(&self) -> String { snake_case(&self.name) } } } } named!(AMQProtocolDefinition); named!(AMQPConstant); named!(AMQPClass); named!(AMQPMethod); named!(AMQPValueArgument); named!(AMQPFlagArgument); named!(AMQPProperty); #[cfg(test)] mod test { use super::*; use amq_protocol_types::AMQPType; #[test] fn test_named_constant() { let c = AMQPConstant { name: "Test".to_string(), value: 42, amqp_type: AMQPType::ShortUInt, }; assert_eq!(c.name(), "Test".to_string()); assert_eq!(c.camel_name(), "Test".to_string()); assert_eq!(c.snake_name(), "test".to_string()); } #[test] fn test_named_value_argument() { let c = AMQPValueArgument { amqp_type: AMQPType::ShortUInt, name: "TestName".to_string(), default_value: None, domain: None, }; assert_eq!(c.name(), "TestName".to_string()); assert_eq!(c.camel_name(), "TestName".to_string()); assert_eq!(c.snake_name(), "test_name".to_string()); } #[test] fn test_named_flag_argument() { let c = AMQPFlagArgument { name: "Test_name".to_string(), default_value: false, }; assert_eq!(c.name(), "Test_name".to_string()); assert_eq!(c.camel_name(), "TestName".to_string()); assert_eq!(c.snake_name(), "test_name".to_string()); } }