use crate::base::{
block::{Block, BlockDesc, BlockProps, BlockState},
input::{InputProps, input_reader::InputReader},
};
use libhaystack::val::Value;
use uuid::Uuid;
use libhaystack::val::kind::HaystackKind;
use crate::{blocks::InputImpl, blocks::OutputImpl};
#[block]
#[derive(BlockProps, Debug)]
#[category = "bitwise"]
pub struct BitwiseNot {
#[input(name = "in", kind = "Number")]
pub input: InputImpl,
#[output(kind = "Number")]
pub out: OutputImpl,
}
impl Block for BitwiseNot {
async fn execute(&mut self) {
self.read_inputs_until_ready().await;
if let Some(Value::Number(n)) = self.input.get_value() {
self.out.value = Value::make_int(!(n.value as i64));
}
}
}
#[cfg(test)]
mod test {
use crate::{
base::block::Block, base::block::test_utils::write_block_inputs,
blocks::bitwise::BitwiseNot,
};
#[tokio::test]
async fn test_not_op() {
let mut block = BitwiseNot::new();
write_block_inputs([(&mut block.input, 2)]).await;
block.execute().await;
assert_eq!(block.out.value, (-3).into());
}
}