From 0ae466bb0b406f375ec1529747e174ccb60aeb79 Mon Sep 17 00:00:00 2001
From: Udo Eisenbarth <u.eisenbarth@gsi.de>
Date: Fri, 2 Jun 2023 11:06:13 +0200
Subject: [PATCH] Add unit test for node_type()

---
 src/nodes/node_dummy.rs |  4 ++--
 src/optic_node.rs       | 14 ++++++++++----
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/nodes/node_dummy.rs b/src/nodes/node_dummy.rs
index 5ee52a0b..e5b03b84 100644
--- a/src/nodes/node_dummy.rs
+++ b/src/nodes/node_dummy.rs
@@ -5,7 +5,7 @@ pub struct NodeDummy;
 
 impl Optical for NodeDummy {
     /// Returns "dummy" as node type.
-    fn node_type(&self) -> String {
-        "dummy".into()
+    fn node_type(&self) -> &str {
+        "dummy"
     }
 }
\ No newline at end of file
diff --git a/src/optic_node.rs b/src/optic_node.rs
index 484eaf4d..4fbaa503 100644
--- a/src/optic_node.rs
+++ b/src/optic_node.rs
@@ -28,12 +28,13 @@ impl OpticNode {
     pub fn name(&self) -> &str {
         self.name.as_ref()
     }
-    /// Returns a string representation of the [`OpticNode`] in `graphviz` format.
+    /// Returns a string representation of the [`OpticNode`] in `graphviz` format. This function is normally called by the top-level `to_dot`function within 
+    /// `OpticScenery`.
     pub fn to_dot(&self) -> String {
         format!("  \"{}\"\n", self.name)
     }
     /// Returns the concrete node type as string representation.
-    pub fn node_type(&self) -> String {
+    pub fn node_type(&self) -> &str {
         self.node.node_type()
     }
 }
@@ -47,8 +48,8 @@ impl Debug for OpticNode {
 /// This trait must be implemented by all concrete optical components.
 pub trait Optical {
     /// Return the type of the optical component (lens, filter, ...). The default implementation returns "undefined".
-    fn node_type(&self) -> String {
-        "undefined".into()
+    fn node_type(&self) -> &str {
+        "undefined"
     }
 }
 
@@ -77,4 +78,9 @@ mod test {
         let node = OpticNode::new("Test".into(), Box::new(NodeDummy));
         assert_eq!(node.to_dot(), "  \"Test\"\n".to_owned())
     }
+    #[test]
+    fn node_type() {
+        let node = OpticNode::new("Test".into(), Box::new(NodeDummy));
+        assert_eq!(node.node_type(), "dummy");
+    }
 }
-- 
GitLab