codama_nodes/count_nodes/
fixed_count_node.rs1use codama_nodes_derive::node;
2
3#[node]
4pub struct FixedCountNode {
5 pub value: usize,
7}
8
9impl From<FixedCountNode> for crate::Node {
10 fn from(val: FixedCountNode) -> Self {
11 crate::Node::Count(val.into())
12 }
13}
14
15impl FixedCountNode {
16 pub fn new(value: usize) -> Self {
17 Self { value }
18 }
19}
20
21#[cfg(test)]
22mod tests {
23 use super::*;
24
25 #[test]
26 fn new() {
27 let node = FixedCountNode::new(42);
28 assert_eq!(node.value, 42);
29 }
30
31 #[test]
32 fn to_json() {
33 let node = FixedCountNode::new(42);
34 let json = serde_json::to_string(&node).unwrap();
35 assert_eq!(json, r#"{"kind":"fixedCountNode","value":42}"#);
36 }
37
38 #[test]
39 fn from_json() {
40 let json = r#"{"kind":"fixedCountNode","value":42}"#;
41 let node: FixedCountNode = serde_json::from_str(json).unwrap();
42 assert_eq!(node, FixedCountNode::new(42));
43 }
44}