Skip to main content

codama_nodes/value_nodes/
string_value_node.rs

1use crate::StringValueNode;
2
3impl StringValueNode {
4    pub fn new<T>(string: T) -> Self
5    where
6        T: Into<String>,
7    {
8        Self {
9            string: string.into(),
10        }
11    }
12}
13
14#[cfg(test)]
15mod tests {
16    use super::*;
17
18    #[test]
19    fn new() {
20        assert_eq!(
21            StringValueNode::new("Hello World".to_string()).string,
22            "Hello World".to_string()
23        );
24        assert_eq!(
25            StringValueNode::new("Hello World").string,
26            "Hello World".to_string()
27        );
28        assert_eq!(StringValueNode::new('a').string, "a".to_string());
29    }
30
31    #[test]
32    fn to_json() {
33        let node = StringValueNode::new("Hello World!");
34        let json = serde_json::to_string(&node).unwrap();
35        assert_eq!(
36            json,
37            r#"{"kind":"stringValueNode","string":"Hello World!"}"#
38        );
39    }
40
41    #[test]
42    fn from_json() {
43        let json = r#"{"kind":"stringValueNode","string":"Hello World!"}"#;
44        let node: StringValueNode = serde_json::from_str(json).unwrap();
45        assert_eq!(node, StringValueNode::new("Hello World!"));
46    }
47}