codama_nodes/display_nodes/
instruction_account_display_node.rs1use crate::{DisplaySkip, InstructionAccountDisplayNode};
2
3impl InstructionAccountDisplayNode {
4 pub fn new<T>(label: T) -> Self
5 where
6 T: Into<String>,
7 {
8 Self {
9 label: Some(label.into()),
10 ..Default::default()
11 }
12 }
13
14 pub fn skipped(skip: DisplaySkip) -> Self {
15 Self {
16 skip: Some(skip),
17 ..Default::default()
18 }
19 }
20}
21
22#[cfg(test)]
23mod tests {
24 use super::*;
25
26 #[test]
27 fn new() {
28 let node = InstructionAccountDisplayNode::new("To");
29 assert_eq!(node.label.as_deref(), Some("To"));
30 assert_eq!(node.skip, None);
31 }
32
33 #[test]
34 fn skipped() {
35 let node = InstructionAccountDisplayNode::skipped(DisplaySkip::Always);
36 assert_eq!(node.label, None);
37 assert_eq!(node.skip, Some(DisplaySkip::Always));
38 }
39
40 #[test]
41 fn to_json() {
42 let node = InstructionAccountDisplayNode {
43 label: Some("To".to_string()),
44 skip: Some(DisplaySkip::WhenInjected),
45 };
46 let json = serde_json::to_string(&node).unwrap();
47 assert_eq!(
48 json,
49 r#"{"kind":"instructionAccountDisplayNode","label":"To","skip":"whenInjected"}"#
50 );
51 }
52
53 #[test]
54 fn from_json() {
55 let json = r#"{"kind":"instructionAccountDisplayNode","label":"To"}"#;
56 let node: InstructionAccountDisplayNode = serde_json::from_str(json).unwrap();
57 assert_eq!(node, InstructionAccountDisplayNode::new("To"));
58 }
59}