diff options
author | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-11-20 13:54:42 +0200 |
---|---|---|
committer | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-12-02 17:11:49 +0200 |
commit | 72e9388a61fa1f346043da594d33d2881f7aa329 (patch) | |
tree | 202daaeca239b98e878c4369213febd5f0464030 /test | |
parent | 614000256b709ff9d566740534f68c4cb795e0f2 (diff) | |
download | qtlocation-mapboxgl-72e9388a61fa1f346043da594d33d2881f7aa329.tar.gz |
[core] Add unit tests for Formatted class
Diffstat (limited to 'test')
-rw-r--r-- | test/test-files.json | 1 | ||||
-rw-r--r-- | test/text/formatted.test.cpp | 51 |
2 files changed, 52 insertions, 0 deletions
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 <mbgl/style/expression/formatted.hpp> +#include <mbgl/test/util.hpp> +#include <mbgl/util/optional.hpp> + +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<FormattedSection>{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<FormattedSection>{emptyText, emptyText, emptyText}}; + EXPECT_TRUE(multipleEmptySections.empty()); + + Formatted multipleEmptySectionsWithImage{std::vector<FormattedSection>{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<FormattedSection>{emptyText, text, emptyText}}; + EXPECT_FALSE(multipleSections.empty()); + + Formatted multipleSectionsWithImage{std::vector<FormattedSection>{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<FormattedSection>{text, text}}; + EXPECT_EQ(multipleSections.toString(), "FormattedFormatted"); + + auto image = FormattedSection{style::expression::Image("Image")}; + Formatted multipleEmptySectionsWithImage{std::vector<FormattedSection>{text, image}}; + EXPECT_EQ(multipleEmptySectionsWithImage.toString(), "Formatted"); +} |