codama_nodes/contextual_value_nodes/
account_value_node.rs1use crate::CamelCaseString;
2use codama_nodes_derive::node;
3
4#[node]
5pub struct AccountValueNode {
6 pub name: CamelCaseString,
8}
9
10impl From<AccountValueNode> for crate::Node {
11 fn from(val: AccountValueNode) -> Self {
12 crate::Node::ContextualValue(val.into())
13 }
14}
15
16impl AccountValueNode {
17 pub fn new<T>(name: T) -> Self
18 where
19 T: Into<CamelCaseString>,
20 {
21 Self { name: name.into() }
22 }
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28
29 #[test]
30 fn new() {
31 let node = AccountValueNode::new("my_account");
32 assert_eq!(node.name, CamelCaseString::new("myAccount"));
33 }
34
35 #[test]
36 fn to_json() {
37 let node = AccountValueNode::new("myAccount");
38 let json = serde_json::to_string(&node).unwrap();
39 assert_eq!(json, r#"{"kind":"accountValueNode","name":"myAccount"}"#);
40 }
41
42 #[test]
43 fn from_json() {
44 let json = r#"{"kind":"accountValueNode","name":"myAccount"}"#;
45 let node: AccountValueNode = serde_json::from_str(json).unwrap();
46 assert_eq!(node, AccountValueNode::new("myAccount"));
47 }
48}