Move format_utils.hpp to root directory

Move format_utils.hpp to the root directory of this repository so that
it serves as common code.  Change the namespace to reflect the directory
change.  Move automated tests to the test directory for common code.

Change-Id: Id1af4b8f6da3e3b4f86231599a19d70ca6164f12
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
diff --git a/test/format_utils_tests.cpp b/test/format_utils_tests.cpp
new file mode 100644
index 0000000..3f61c99
--- /dev/null
+++ b/test/format_utils_tests.cpp
@@ -0,0 +1,62 @@
+/**
+ * Copyright © 2024 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "format_utils.hpp"
+
+#include <array>
+#include <span>
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+using namespace phosphor::power::format_utils;
+
+TEST(FormatUtilsTests, toString)
+{
+    // Test with spans from integer vector
+    {
+        std::vector<int> vec{1, 3, 5, 7, 9, 11};
+        std::span<int> spn{vec};
+        EXPECT_EQ(toString(spn), "[1, 3, 5, 7, 9, 11]");
+        EXPECT_EQ(toString(spn.subspan(0, 4)), "[1, 3, 5, 7]");
+        EXPECT_EQ(toString(spn.subspan(3, 3)), "[7, 9, 11]");
+        EXPECT_EQ(toString(spn.subspan(5, 1)), "[11]");
+        EXPECT_EQ(toString(spn.subspan(0, 0)), "[]");
+    }
+
+    // Test with spans from double vector
+    {
+        std::vector<double> vec{2.1, -3.9, 21.03};
+        std::span<double> spn{vec};
+        EXPECT_EQ(toString(spn), "[2.1, -3.9, 21.03]");
+    }
+
+    // Test with span from empty vector
+    {
+        std::vector<int> vec{};
+        std::span<int> spn{vec};
+        EXPECT_EQ(toString(spn), "[]");
+    }
+
+    // Test with spans from string array
+    {
+        std::array<std::string, 3> ary{"cow", "horse", "zebra"};
+        std::span<std::string> spn{ary};
+        EXPECT_EQ(toString(spn), "[cow, horse, zebra]");
+        EXPECT_EQ(toString(spn.subspan(1, 2)), "[horse, zebra]");
+    }
+}
diff --git a/test/meson.build b/test/meson.build
index 2e13604..6fa8fee 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -3,6 +3,7 @@
     executable(
         'common-code-tests',
         'file_descriptor_tests.cpp',
+        'format_utils_tests.cpp',
         'nvtest.cpp',
         'temporary_file_tests.cpp',
         'temporary_subdirectory_tests.cpp',