From 72e9388a61fa1f346043da594d33d2881f7aa329 Mon Sep 17 00:00:00 2001 From: Alexander Shalamov Date: Wed, 20 Nov 2019 13:54:42 +0200 Subject: [core] Add unit tests for Formatted class --- next/test/CMakeLists.txt | 1 + src/mbgl/style/expression/formatted.cpp | 5 ++-- test/test-files.json | 1 + test/text/formatted.test.cpp | 51 +++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 test/text/formatted.test.cpp diff --git a/next/test/CMakeLists.txt b/next/test/CMakeLists.txt index 12a6d8108c..363e52c95d 100644 --- a/next/test/CMakeLists.txt +++ b/next/test/CMakeLists.txt @@ -65,6 +65,7 @@ add_library( ${MBGL_ROOT}/test/style/style_parser.test.cpp ${MBGL_ROOT}/test/text/bidi.test.cpp ${MBGL_ROOT}/test/text/cross_tile_symbol_index.test.cpp + ${MBGL_ROOT}/test/text/formatted.test.cpp ${MBGL_ROOT}/test/text/glyph_manager.test.cpp ${MBGL_ROOT}/test/text/glyph_pbf.test.cpp ${MBGL_ROOT}/test/text/language_tag.test.cpp diff --git a/src/mbgl/style/expression/formatted.cpp b/src/mbgl/style/expression/formatted.cpp index 4069dd8a7c..9041bb3121 100644 --- a/src/mbgl/style/expression/formatted.cpp +++ b/src/mbgl/style/expression/formatted.cpp @@ -17,9 +17,8 @@ bool Formatted::operator==(const Formatted& other) const { for (std::size_t i = 0; i < sections.size(); i++) { const auto& thisSection = sections.at(i); const auto& otherSection = other.sections.at(i); - if (thisSection.text != otherSection.text || - thisSection.fontScale != otherSection.fontScale || - thisSection.fontStack != otherSection.fontStack || + if (thisSection.text != otherSection.text || thisSection.image != otherSection.image || + thisSection.fontScale != otherSection.fontScale || thisSection.fontStack != otherSection.fontStack || thisSection.textColor != otherSection.textColor) { return false; } diff --git a/test/test-files.json b/test/test-files.json index 1d220f579d..d388788212 100644 --- a/test/test-files.json +++ b/test/test-files.json @@ -67,6 +67,7 @@ "test/style/style_parser.test.cpp", "test/text/bidi.test.cpp", "test/text/cross_tile_symbol_index.test.cpp", + "test/text/formatted.test.cpp", "test/text/glyph_manager.test.cpp", "test/text/glyph_pbf.test.cpp", "test/text/language_tag.test.cpp", diff --git a/test/text/formatted.test.cpp b/test/text/formatted.test.cpp new file mode 100644 index 0000000000..70e743f5c8 --- /dev/null +++ b/test/text/formatted.test.cpp @@ -0,0 +1,51 @@ + +#include +#include +#include + +using namespace mbgl; +using namespace mbgl::style::expression; + +TEST(Formatted, Equality) { + Formatted text{"Formatted"}; + auto emptyImage = FormattedSection{style::expression::Image("Formatted")}; + Formatted image{std::vector{emptyImage}}; + EXPECT_FALSE(text == image); + EXPECT_EQ(text, text); + EXPECT_EQ(image, image); +} + +TEST(Formatted, Empty) { + Formatted emptyFormatted{""}; + EXPECT_TRUE(emptyFormatted.empty()); + + auto emptyText = FormattedSection{"", nullopt, nullopt, nullopt}; + auto emptyImage = FormattedSection{style::expression::Image()}; + Formatted multipleEmptySections{std::vector{emptyText, emptyText, emptyText}}; + EXPECT_TRUE(multipleEmptySections.empty()); + + Formatted multipleEmptySectionsWithImage{std::vector{emptyText, emptyImage, emptyText}}; + EXPECT_TRUE(multipleEmptySectionsWithImage.empty()); + + auto text = FormattedSection{"Formatted", nullopt, nullopt, nullopt}; + auto image = FormattedSection{style::expression::Image("Image")}; + + Formatted multipleSections{std::vector{emptyText, text, emptyText}}; + EXPECT_FALSE(multipleSections.empty()); + + Formatted multipleSectionsWithImage{std::vector{emptyText, image, text}}; + EXPECT_FALSE(multipleSectionsWithImage.empty()); +} + +TEST(Formatted, ToString) { + Formatted emptyFormatted{""}; + EXPECT_EQ(emptyFormatted.toString(), ""); + + auto text = FormattedSection{"Formatted", nullopt, nullopt, nullopt}; + Formatted multipleSections{std::vector{text, text}}; + EXPECT_EQ(multipleSections.toString(), "FormattedFormatted"); + + auto image = FormattedSection{style::expression::Image("Image")}; + Formatted multipleEmptySectionsWithImage{std::vector{text, image}}; + EXPECT_EQ(multipleEmptySectionsWithImage.toString(), "Formatted"); +} -- cgit v1.2.1