codama_nodes/contextual_value_nodes/
account_field_value_node.rs1use crate::{AccountFieldValueNode, CamelCaseString};
2
3impl AccountFieldValueNode {
4 pub fn new<T>(account: T) -> Self
5 where
6 T: Into<CamelCaseString>,
7 {
8 Self {
9 account: account.into(),
10 path: None,
11 }
12 }
13
14 pub fn with_path<T, U>(account: T, path: U) -> Self
15 where
16 T: Into<CamelCaseString>,
17 U: Into<CamelCaseString>,
18 {
19 Self {
20 account: account.into(),
21 path: Some(path.into()),
22 }
23 }
24}
25
26#[cfg(test)]
27mod tests {
28 use super::*;
29
30 #[test]
31 fn new() {
32 let node = AccountFieldValueNode::new("my_account");
33 assert_eq!(node.account, CamelCaseString::new("myAccount"));
34 assert_eq!(node.path, None);
35 }
36
37 #[test]
38 fn with_path() {
39 let node = AccountFieldValueNode::with_path("my_account", "my_field");
40 assert_eq!(node.account, CamelCaseString::new("myAccount"));
41 assert_eq!(node.path, Some(CamelCaseString::new("myField")));
42 }
43
44 #[test]
45 fn to_json() {
46 let node = AccountFieldValueNode::new("myAccount");
47 let json = serde_json::to_string(&node).unwrap();
48 assert_eq!(
49 json,
50 r#"{"kind":"accountFieldValueNode","account":"myAccount"}"#
51 );
52 }
53
54 #[test]
55 fn from_json() {
56 let json = r#"{"kind":"accountFieldValueNode","account":"myAccount"}"#;
57 let node: AccountFieldValueNode = serde_json::from_str(json).unwrap();
58 assert_eq!(node, AccountFieldValueNode::new("myAccount"));
59 }
60
61 #[test]
62 fn to_json_with_path() {
63 let node = AccountFieldValueNode::with_path("myAccount", "myField");
64 let json = serde_json::to_string(&node).unwrap();
65 assert_eq!(
66 json,
67 r#"{"kind":"accountFieldValueNode","account":"myAccount","path":"myField"}"#
68 );
69 }
70
71 #[test]
72 fn from_json_with_path() {
73 let json = r#"{"kind":"accountFieldValueNode","account":"myAccount","path":"myField"}"#;
74 let node: AccountFieldValueNode = serde_json::from_str(json).unwrap();
75 assert_eq!(
76 node,
77 AccountFieldValueNode::with_path("myAccount", "myField")
78 );
79 }
80}