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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
use crate::serialization::op_code::OpCode;
use crate::serialization::sigma_byte_reader::SigmaByteRead;
use crate::serialization::sigma_byte_writer::SigmaByteWrite;
use crate::serialization::SigmaParsingError;
use crate::serialization::SigmaSerializable;
use crate::serialization::SigmaSerializeResult;
use crate::types::stype::SType;
use super::expr::Expr;
use super::expr::InvalidArgumentError;
use crate::has_opcode::HasStaticOpCode;
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct Append {
    pub input: Box<Expr>,
    pub col_2: Box<Expr>,
}
impl Append {
    pub fn new(input: Expr, col_2: Expr) -> Result<Self, InvalidArgumentError> {
        match (input.post_eval_tpe(), col_2.post_eval_tpe()) {
            (SType::SColl(x), SType::SColl(y)) => {
                if x == y {
                    Ok(Append{input: input.into(), col_2: col_2.into()})
                } else {
                    Err(InvalidArgumentError(format!(
                        "Expected Append input and col_2 collection to have the same types; got input={0:?} col_2={1:?}",
                        x, y)))
                }
            }
            (SType::SColl(_), _) => {
                Err(InvalidArgumentError(format!(
                    "Expected Append col_2 param to be a collection; got col_2={:?}", col_2.tpe())))
            }
            (_, SType::SColl(_)) => {
                Err(InvalidArgumentError(format!(
                    "Expected Append input param to be a collection; got input={:?}", input.tpe())))   
            },
            (_, _) => {
                Err(InvalidArgumentError(format!(
                    "Expected Append input and col_2 param to be a collection; got input={:?} col_2={:?}", input.tpe(), col_2.tpe())))   
            }
        }
    }
    pub fn tpe(&self) -> SType {
        self.input.tpe()
    }
}
impl HasStaticOpCode for Append {
    const OP_CODE: OpCode = OpCode::APPEND;
}
impl SigmaSerializable for Append {
    fn sigma_serialize<W: SigmaByteWrite>(&self, w: &mut W) -> SigmaSerializeResult {
        self.input.sigma_serialize(w)?;
        self.col_2.sigma_serialize(w)?;
        Ok(())
    }
    fn sigma_parse<R: SigmaByteRead>(r: &mut R) -> Result<Self, SigmaParsingError> {
        let input = Expr::sigma_parse(r)?;
        let col_2 = Expr::sigma_parse(r)?;
        Ok(Append::new(input, col_2)?)
    }
}
#[cfg(test)]
#[cfg(feature = "arbitrary")]
#[allow(clippy::panic)]
mod tests {
    use super::*;
    use crate::mir::expr::arbitrary::ArbExprParams;
    use crate::mir::expr::Expr;
    use crate::serialization::sigma_serialize_roundtrip;
    use proptest::prelude::*;
    impl Arbitrary for Append {
        type Strategy = BoxedStrategy<Self>;
        type Parameters = ();
        fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
            (
                any_with::<Expr>(ArbExprParams {
                    tpe: SType::SColl(SType::SBoolean.into()),
                    depth: 1,
                }),
                any_with::<Expr>(ArbExprParams {
                    tpe: SType::SColl(SType::SBoolean.into()),
                    depth: 1,
                }),
            )
                .prop_map(|(input, col_2)| Self {
                    input: input.into(),
                    col_2: col_2.into(),
                })
                .boxed()
        }
    }
    proptest! {
        #![proptest_config(ProptestConfig::with_cases(16))]
        #[test]
        fn ser_roundtrip(v in any::<Append>()) {
            let expr: Expr = v.into();
            prop_assert_eq![sigma_serialize_roundtrip(&expr), expr];
        }
    }
}