From 7b5290983add99754dd569a019eff0cb310500bd Mon Sep 17 00:00:00 2001 From: Andreas Tsouchlos Date: Mon, 22 Nov 2021 08:14:04 +0100 Subject: [PATCH] Moved parse_types into namespace detail; Added test Parse_ast_nodes_only --- inc/parse_types.h | 10 +++++++++- test/src/parse.cpp | 31 +++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/inc/parse_types.h b/inc/parse_types.h index d2a613b..46194a6 100644 --- a/inc/parse_types.h +++ b/inc/parse_types.h @@ -2,6 +2,9 @@ #define LOGGER_PARSE_TYPES_H +namespace detail { + + enum class FormatType { s, c, b, B, d, o, x, X, a, A, e, E, f, F, g, G, p }; @@ -40,13 +43,14 @@ public: constexpr bool operator==(const ast_node_t& rhs) const { return ((rhs.m_is_char == m_is_char) && (rhs.m_c == m_c)) || - ((rhs.m_is_char != m_is_char) && (rhs.m_node == m_node)); + ((rhs.m_is_char != m_is_char) && (rhs.m_node == m_node)); } constexpr void set_char(char c) { m_c = c; m_is_char = true; } + constexpr void set_node(fmt_node_t node) { m_node = node; m_is_char = false; @@ -55,6 +59,7 @@ public: constexpr char get_char() const { return m_c; } + constexpr fmt_node_t get_node() const { return m_node; } @@ -73,4 +78,7 @@ template using string_result_t = std::array; +} // namespace detail + + #endif // LOGGER_PARSE_TYPES_H diff --git a/test/src/parse.cpp b/test/src/parse.cpp index 2102a14..d13df82 100644 --- a/test/src/parse.cpp +++ b/test/src/parse.cpp @@ -1,6 +1,10 @@ #include #include + +using namespace detail; + + TEST(Parse, ast_node) { ast_node_t ast_node1{'a'}; ast_node_t ast_node2{'a'}; @@ -10,9 +14,32 @@ TEST(Parse, ast_node) { EXPECT_EQ(ast_node1 == ast_node3, false); } -TEST(Parse, chars_only) { +TEST(Parse, ast_chars_only) { constexpr std::array control = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}; - EXPECT_EQ(detail::parse_string<"abcdefgh">().value, control); + EXPECT_EQ(parse_string<"abcdefgh">().value, control); +} + +TEST(Parse, ast_nodes_only) { + fmt_node_t fmt_node0 = {true, 6, 3, FormatType::s}; + + fmt_node_t fmt_node1; + fmt_node1.length = 8; + fmt_node1.type = FormatType::s; + + fmt_node_t fmt_node2; + fmt_node2.precision = 4; + + fmt_node_t fmt_node3 = {}; + fmt_node_t fmt_node4 = {}; + fmt_node_t fmt_node5 = {}; + fmt_node_t fmt_node6 = {}; + fmt_node_t fmt_node7 = {}; + + std::array control = { + fmt_node0, fmt_node1, fmt_node2, fmt_node3, + fmt_node4, fmt_node5, fmt_node6, fmt_node7}; + + EXPECT_EQ(parse_string<"{:06.3}{:8s}{:.4}{}{}{}{}{}">().value, control); }