diff options
-rw-r--r-- | c++/core/string_literal.h | 6 | ||||
-rw-r--r-- | tests/core.cpp | 11 | ||||
-rw-r--r-- | tests/tree.cpp | 2 |
3 files changed, 16 insertions, 3 deletions
diff --git a/c++/core/string_literal.h b/c++/core/string_literal.h index 30f62fd..ccc8f49 100644 --- a/c++/core/string_literal.h +++ b/c++/core/string_literal.h @@ -38,12 +38,12 @@ public: constexpr string_literal<CharT, N+NR-1> operator+(const string_literal<CharT, NR>& rhs) const noexcept { CharT sum[N+NR-1]; - // The weird +1 happen due to needing to skip the '\0' terminator + // The weird i+1 happens due to needing to skip the '\0' terminator for(size_t i = 0; (i+1) < N; ++i){ sum[i] = data[i]; } - for(size_t i = N; (i+1) < (N+NR); ++i){ - sum[i+1] = rhs.data[i+1]; + for(size_t i = 0; i < NR; ++i){ + sum[i+N-1] = rhs.data[i]; } return string_literal<CharT, N+NR-1>{sum}; diff --git a/tests/core.cpp b/tests/core.cpp index 5b6c116..281cca6 100644 --- a/tests/core.cpp +++ b/tests/core.cpp @@ -1,6 +1,7 @@ #include <forstio/test/suite.h> #include <forstio/core/id.h> #include <forstio/core/id_map.h> +#include <forstio/core/string_literal.h> namespace { SAW_TEST("ID functionality") { @@ -28,6 +29,16 @@ SAW_TEST("ID functionality") { SAW_EXPECT(a.get_value() == 1, "Lost original value"); } +SAW_TEST("String Literal Append"){ + using namespace saw; + + constexpr string_literal a = "foo"; + constexpr string_literal b = "bar"; + constexpr string_literal c = a+b; + + SAW_EXPECT(c == "foobar", "CT String sum is not \"foobar\""); +} + SAW_TEST("ID Map Insert"){ using namespace saw; diff --git a/tests/tree.cpp b/tests/tree.cpp index ab4cfa2..a33f0b1 100644 --- a/tests/tree.cpp +++ b/tests/tree.cpp @@ -2,6 +2,7 @@ #include <forstio/core/tree.h> namespace { +/* SAW_TEST("Tree insert"){ using namespace saw; @@ -39,4 +40,5 @@ SAW_TEST("Tree add child"){ SAW_EXPECT(eov2.is_value(), "Didn't manage to add to inner tree"); } } +*/ } |