From ba3ced4420febcb5285e72552e2ca0149dd6989c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 14 Apr 2019 19:43:09 +0100 Subject: [PATCH] Merge remote-tracking branch 'origin/development' # Conflicts: # include/etl/basic_format_spec.h # include/etl/private/to_string_helper.h # include/etl/to_string.h # include/etl/to_u16string.h # include/etl/to_u32string.h # include/etl/to_wstring.h # include/etl/version.h # support/Release notes.txt --- test/test_to_u16string.cpp | 67 +++++++++++++++++++ test/test_to_u32string.cpp | 67 +++++++++++++++++++ test/test_to_wstring.cpp | 129 +++++++++++++++++++++++++++++++++++++ 3 files changed, 263 insertions(+) diff --git a/test/test_to_u16string.cpp b/test/test_to_u16string.cpp index f1aea7da..f36f0859 100644 --- a/test/test_to_u16string.cpp +++ b/test/test_to_u16string.cpp @@ -326,6 +326,73 @@ namespace str.assign(STR("Result ")); CHECK_EQUAL(etl::u16string<20>(STR("Result true ")), to_string(true, str, Format().precision(6).width(10).left().boolalpha(true), true)); } + + //************************************************************************* + TEST(test_floating_point_no_append) + { + etl::u16string<20> str; + + CHECK_EQUAL(etl::u16string<20>(STR(" 12.345678")), etl::to_u16string(12.345678, str, Format().precision(6).width(10).right())); + CHECK_EQUAL(etl::u16string<20>(STR("12.345678 ")), etl::to_u16string(12.345678, str, Format().precision(6).width(10).left())); + } + + //************************************************************************* + TEST(test_floating_point_append) + { + etl::u16string<20> str; + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u16string<20>(STR("Result 12.345678")), etl::to_u16string(12.345678, str, Format().precision(6).width(10).right(), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u16string<20>(STR("Result 12.345678 ")), etl::to_u16string(12.345678, str, Format().precision(6).width(10).left(), true)); + } + + //************************************************************************* + TEST(test_bool_no_append) + { + etl::u16string<20> str; + + CHECK_EQUAL(etl::u16string<20>(STR(" 0")), to_u16string(false, str, Format().precision(6).width(10).right().boolalpha(false))); + CHECK_EQUAL(etl::u16string<20>(STR(" 1")), to_u16string(true, str, Format().precision(6).width(10).right().boolalpha(false))); + CHECK_EQUAL(etl::u16string<20>(STR("0 ")), to_u16string(false, str, Format().precision(6).width(10).left().boolalpha(false))); + CHECK_EQUAL(etl::u16string<20>(STR("1 ")), to_u16string(true, str, Format().precision(6).width(10).left().boolalpha(false))); + + CHECK_EQUAL(etl::u16string<20>(STR(" false")), to_u16string(false, str, Format().precision(6).width(10).right().boolalpha(true))); + CHECK_EQUAL(etl::u16string<20>(STR(" true")), to_u16string(true, str, Format().precision(6).width(10).right().boolalpha(true))); + CHECK_EQUAL(etl::u16string<20>(STR("false ")), to_u16string(false, str, Format().precision(6).width(10).left().boolalpha(true))); + CHECK_EQUAL(etl::u16string<20>(STR("true ")), to_u16string(true, str, Format().precision(6).width(10).left().boolalpha(true))); + } + + //************************************************************************* + TEST(test_bool_append) + { + etl::u16string<20> str; + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u16string<20>(STR("Result 0")), to_u16string(false, str, Format().precision(6).width(10).right().boolalpha(false), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u16string<20>(STR("Result 1")), to_u16string(true, str, Format().precision(6).width(10).right().boolalpha(false), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u16string<20>(STR("Result 0 ")), to_u16string(false, str, Format().precision(6).width(10).left().boolalpha(false), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u16string<20>(STR("Result 1 ")), to_u16string(true, str, Format().precision(6).width(10).left().boolalpha(false), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u16string<20>(STR("Result false")), to_u16string(false, str, Format().precision(6).width(10).right().boolalpha(true), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u16string<20>(STR("Result true")), to_u16string(true, str, Format().precision(6).width(10).right().boolalpha(true), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u16string<20>(STR("Result false ")), to_u16string(false, str, Format().precision(6).width(10).left().boolalpha(true), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u16string<20>(STR("Result true ")), to_u16string(true, str, Format().precision(6).width(10).left().boolalpha(true), true)); + } }; } diff --git a/test/test_to_u32string.cpp b/test/test_to_u32string.cpp index 4e39fa41..e2ce928b 100644 --- a/test/test_to_u32string.cpp +++ b/test/test_to_u32string.cpp @@ -329,6 +329,73 @@ namespace str.assign(STR("Result ")); CHECK_EQUAL(etl::u32string<20>(STR("Result true ")), to_string(true, str, Format().precision(6).width(10).left().boolalpha(true), true)); } + + //************************************************************************* + TEST(test_floating_point_no_append) + { + etl::u32string<20> str; + + CHECK_EQUAL(etl::u32string<20>(STR(" 12.345678")), etl::to_u32string(12.345678, str, Format().precision(6).width(10).right())); + CHECK_EQUAL(etl::u32string<20>(STR("12.345678 ")), etl::to_u32string(12.345678, str, Format().precision(6).width(10).left())); + } + + //************************************************************************* + TEST(test_floating_point_append) + { + etl::u32string<20> str; + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u32string<20>(STR("Result 12.345678")), etl::to_u32string(12.345678, str, Format().precision(6).width(10).right(), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u32string<20>(STR("Result 12.345678 ")), etl::to_u32string(12.345678, str, Format().precision(6).width(10).left(), true)); + } + + //************************************************************************* + TEST(test_bool_no_append) + { + etl::u32string<20> str; + + CHECK_EQUAL(etl::u32string<20>(STR(" 0")), to_u32string(false, str, Format().precision(6).width(10).right().boolalpha(false))); + CHECK_EQUAL(etl::u32string<20>(STR(" 1")), to_u32string(true, str, Format().precision(6).width(10).right().boolalpha(false))); + CHECK_EQUAL(etl::u32string<20>(STR("0 ")), to_u32string(false, str, Format().precision(6).width(10).left().boolalpha(false))); + CHECK_EQUAL(etl::u32string<20>(STR("1 ")), to_u32string(true, str, Format().precision(6).width(10).left().boolalpha(false))); + + CHECK_EQUAL(etl::u32string<20>(STR(" false")), to_u32string(false, str, Format().precision(6).width(10).right().boolalpha(true))); + CHECK_EQUAL(etl::u32string<20>(STR(" true")), to_u32string(true, str, Format().precision(6).width(10).right().boolalpha(true))); + CHECK_EQUAL(etl::u32string<20>(STR("false ")), to_u32string(false, str, Format().precision(6).width(10).left().boolalpha(true))); + CHECK_EQUAL(etl::u32string<20>(STR("true ")), to_u32string(true, str, Format().precision(6).width(10).left().boolalpha(true))); + } + + //************************************************************************* + TEST(test_bool_append) + { + etl::u32string<20> str; + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u32string<20>(STR("Result 0")), to_u32string(false, str, Format().precision(6).width(10).right().boolalpha(false), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u32string<20>(STR("Result 1")), to_u32string(true, str, Format().precision(6).width(10).right().boolalpha(false), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u32string<20>(STR("Result 0 ")), to_u32string(false, str, Format().precision(6).width(10).left().boolalpha(false), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u32string<20>(STR("Result 1 ")), to_u32string(true, str, Format().precision(6).width(10).left().boolalpha(false), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u32string<20>(STR("Result false")), to_u32string(false, str, Format().precision(6).width(10).right().boolalpha(true), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u32string<20>(STR("Result true")), to_u32string(true, str, Format().precision(6).width(10).right().boolalpha(true), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u32string<20>(STR("Result false ")), to_u32string(false, str, Format().precision(6).width(10).left().boolalpha(true), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u32string<20>(STR("Result true ")), to_u32string(true, str, Format().precision(6).width(10).left().boolalpha(true), true)); + } }; } diff --git a/test/test_to_wstring.cpp b/test/test_to_wstring.cpp index bc575ce1..48b8cb40 100644 --- a/test/test_to_wstring.cpp +++ b/test/test_to_wstring.cpp @@ -392,6 +392,135 @@ namespace to_string(&cvi, str, Format().hex().width(10).left().fill(STR('0')), true); CHECK_EQUAL(compare, str); } + + //************************************************************************* + TEST(test_floating_point_no_append) + { + etl::wstring<20> str; + + CHECK_EQUAL(etl::wstring<20>(STR(" 12.345678")), etl::to_wstring(12.345678, str, Format().precision(6).width(10).right())); + CHECK_EQUAL(etl::wstring<20>(STR("12.345678 ")), etl::to_wstring(12.345678, str, Format().precision(6).width(10).left())); + } + + //************************************************************************* + TEST(test_floating_point_append) + { + etl::wstring<20> str; + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::wstring<20>(STR("Result 12.345678")), etl::to_wstring(12.345678, str, Format().precision(6).width(10).right(), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::wstring<20>(STR("Result 12.345678 ")), etl::to_wstring(12.345678, str, Format().precision(6).width(10).left(), true)); + } + + //************************************************************************* + TEST(test_bool_no_append) + { + etl::wstring<20> str; + + CHECK_EQUAL(etl::wstring<20>(STR(" 0")), to_wstring(false, str, Format().precision(6).width(10).right().boolalpha(false))); + CHECK_EQUAL(etl::wstring<20>(STR(" 1")), to_wstring(true, str, Format().precision(6).width(10).right().boolalpha(false))); + CHECK_EQUAL(etl::wstring<20>(STR("0 ")), to_wstring(false, str, Format().precision(6).width(10).left().boolalpha(false))); + CHECK_EQUAL(etl::wstring<20>(STR("1 ")), to_wstring(true, str, Format().precision(6).width(10).left().boolalpha(false))); + + CHECK_EQUAL(etl::wstring<20>(STR(" false")), to_wstring(false, str, Format().precision(6).width(10).right().boolalpha(true))); + CHECK_EQUAL(etl::wstring<20>(STR(" true")), to_wstring(true, str, Format().precision(6).width(10).right().boolalpha(true))); + CHECK_EQUAL(etl::wstring<20>(STR("false ")), to_wstring(false, str, Format().precision(6).width(10).left().boolalpha(true))); + CHECK_EQUAL(etl::wstring<20>(STR("true ")), to_wstring(true, str, Format().precision(6).width(10).left().boolalpha(true))); + } + + //************************************************************************* + TEST(test_bool_append) + { + etl::wstring<20> str; + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::wstring<20>(STR("Result 0")), to_wstring(false, str, Format().precision(6).width(10).right().boolalpha(false), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::wstring<20>(STR("Result 1")), to_wstring(true, str, Format().precision(6).width(10).right().boolalpha(false), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::wstring<20>(STR("Result 0 ")), to_wstring(false, str, Format().precision(6).width(10).left().boolalpha(false), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::wstring<20>(STR("Result 1 ")), to_wstring(true, str, Format().precision(6).width(10).left().boolalpha(false), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::wstring<20>(STR("Result false")), to_wstring(false, str, Format().precision(6).width(10).right().boolalpha(true), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::wstring<20>(STR("Result true")), to_wstring(true, str, Format().precision(6).width(10).right().boolalpha(true), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::wstring<20>(STR("Result false ")), to_wstring(false, str, Format().precision(6).width(10).left().boolalpha(true), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::wstring<20>(STR("Result true ")), to_wstring(true, str, Format().precision(6).width(10).left().boolalpha(true), true)); + } + + //************************************************************************* + TEST(test_pointer_no_append) + { + etl::wstring<20> str; + + static const volatile int cvi = 0; + + std::wostringstream oss; + oss.width(10); + oss.fill(STR('0')); + oss << std::hex << std::uppercase << std::right << uintptr_t(&cvi); + std::wstring temp(oss.str()); + etl::wstring<20> compare(temp.begin(), temp.end()); + + to_wstring(&cvi, str, Format().hex().width(10).right().fill(STR('0'))); + CHECK_EQUAL(compare, str); + + oss.clear(); + oss.str(STR("")); + oss.width(10); + oss.fill(STR('0')); + oss << std::hex << std::uppercase << std::left << uintptr_t(&cvi); + temp = oss.str(); + compare.assign(temp.begin(), temp.end()); + + to_wstring(&cvi, str, Format().hex().width(10).left().fill(STR('0'))); + CHECK_EQUAL(compare, str); + } + + //************************************************************************* + TEST(test_pointer_append) + { + etl::wstring<20> str; + + static const volatile int cvi = 0; + + std::wostringstream oss; + oss.width(10); + oss.fill(STR('0')); + oss << std::hex << std::uppercase << std::right << uintptr_t(&cvi); + std::wstring temp(STR("Result ")); + temp.append(oss.str()); + etl::wstring<20> compare(temp.begin(), temp.end()); + + str.assign(STR("Result ")); + to_wstring(&cvi, str, Format().hex().width(10).right().fill(STR('0')), true); + CHECK_EQUAL(compare, str); + + oss.clear(); + oss.str(STR("")); + oss.width(10); + oss.fill(STR('0')); + oss << std::hex << std::uppercase << std::left << uintptr_t(&cvi); + temp = STR("Result "); + temp.append(oss.str()); + compare.assign(temp.begin(), temp.end()); + + str.assign(STR("Result ")); + to_wstring(&cvi, str, Format().hex().width(10).left().fill(STR('0')), true); + CHECK_EQUAL(compare, str); + } }; }