rocketmq_model/common/filter/
operand.rs1use crate::common::filter::op::Op;
15use crate::common::filter::op::OpBase;
16
17#[derive(Debug, Clone)]
18pub struct Operand {
19 op: OpBase,
20}
21
22impl Operand {
23 pub fn new(symbol: &str) -> Self {
24 Self {
25 op: OpBase::new(symbol),
26 }
27 }
28}
29
30impl Op for Operand {
31 fn symbol(&self) -> &str {
32 self.op.symbol()
33 }
34}
35
36#[cfg(test)]
37mod tests {
38 use crate::common::filter::op::Op;
39 use crate::common::filter::operand::Operand;
40
41 #[test]
42 fn create_operand() {
43 let operand = Operand::new("+");
44 assert_eq!(operand.symbol(), "+");
45 }
46
47 #[test]
48 fn create_operand_with_different_symbols() {
49 let symbols = vec!["+", "-", "*", "/", "==", "!=", ">", "<"];
50 for sym in symbols {
51 let operand = Operand::new(sym);
52 assert_eq!(operand.symbol(), sym);
53 }
54 }
55
56 #[test]
57 fn create_operand_with_empty_string() {
58 let operand = Operand::new("");
59 assert_eq!(operand.symbol(), "");
60 }
61
62 #[test]
63 fn operand_clone_works() {
64 let operand = Operand::new("+");
65 let cloned = operand.clone();
66 assert_eq!(cloned.symbol(), "+");
67 }
68}