codama_nodes/contextual_value_nodes/
identity_value_node.rs

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
use codama_nodes_derive::node;

#[node]
#[derive(Default)]
pub struct IdentityValueNode {}

impl From<IdentityValueNode> for crate::Node {
    fn from(val: IdentityValueNode) -> Self {
        crate::Node::ContextualValue(val.into())
    }
}

impl IdentityValueNode {
    pub fn new() -> Self {
        Self::default()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn new() {
        let node = IdentityValueNode::new();
        assert_eq!(node, IdentityValueNode {});
    }

    #[test]
    fn to_json() {
        let node = IdentityValueNode::new();
        let json = serde_json::to_string(&node).unwrap();
        assert_eq!(json, r#"{"kind":"identityValueNode"}"#);
    }

    #[test]
    fn from_json() {
        let json = r#"{"kind":"identityValueNode"}"#;
        let node: IdentityValueNode = serde_json::from_str(json).unwrap();
        assert_eq!(node, IdentityValueNode::new());
    }
}