Skip to main content

rocketmq_model/common/filter/
operand.rs

1// Copyright 2023 The RocketMQ Rust Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14use 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}