1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6pub enum BinOp {
7 Add,
8 Sub,
9 Mul,
10 Div,
11 Mod,
12 Pow,
13 Lt,
14 Gt,
15 Le,
16 Ge,
17 Eq,
18 Ne,
19 StrictEq,
20 StrictNe,
21 BitAnd,
22 BitOr,
23 BitXor,
24 Shl,
25 Shr,
26 UrShr,
27 In,
28 InstanceOf,
29}
30
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
33pub enum UnaOp {
34 Neg, Not, BitNot, TypeOf, Void, Delete, }
41
42#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
44pub enum LogicalOp {
45 And, Or, Nullish, }
49
50#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
52pub enum UpdateOp {
53 Increment,
54 Decrement,
55}
56
57#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
59pub enum AssignOp {
60 Assign, Add, Sub, Mul, Div, Mod, Shl, Shr, BitAnd, BitOr, BitXor, LogicAnd, LogicOr, Nullish, }
75
76impl AssignOp {
77 pub fn to_zig_str(self) -> &'static str {
79 match self {
80 AssignOp::Assign => "=",
81 AssignOp::Add => "+=",
82 AssignOp::Sub => "-=",
83 AssignOp::Mul => "*=",
84 AssignOp::Div => "/=",
85 AssignOp::Mod => "%=",
86 AssignOp::Shl => "<<=",
87 AssignOp::Shr => ">>=",
88 AssignOp::BitAnd => "&=",
89 AssignOp::BitOr => "|=",
90 AssignOp::BitXor => "^=",
91 AssignOp::LogicAnd => "and=",
92 AssignOp::LogicOr => "or=",
93 AssignOp::Nullish => "orelse=",
94 }
95 }
96}
97
98#[cfg(test)]
99mod tests {
100 use super::*;
101
102 #[test]
103 fn test_assign_op_zig_str() {
104 assert_eq!(AssignOp::Assign.to_zig_str(), "=");
105 assert_eq!(AssignOp::LogicAnd.to_zig_str(), "and=");
106 assert_eq!(AssignOp::Nullish.to_zig_str(), "orelse=");
107 }
108
109 #[test]
110 fn test_bin_op_coverage() {
111 let ops = [
113 BinOp::Add,
114 BinOp::Sub,
115 BinOp::Mul,
116 BinOp::Div,
117 BinOp::Mod,
118 BinOp::Lt,
119 BinOp::Gt,
120 BinOp::Le,
121 BinOp::Ge,
122 BinOp::Eq,
123 BinOp::Ne,
124 BinOp::StrictEq,
125 BinOp::StrictNe,
126 BinOp::BitAnd,
127 BinOp::BitOr,
128 BinOp::BitXor,
129 BinOp::Shl,
130 BinOp::Shr,
131 BinOp::UrShr,
132 BinOp::In,
133 BinOp::InstanceOf,
134 BinOp::Pow,
135 ];
136 assert_eq!(ops.len(), 22);
137 }
138}