diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2015-11-18 19:06:33 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2015-11-18 19:06:33 -0800 |
commit | a983dc8259c52cc0a586212c1c24fd4ead2bccbb (patch) | |
tree | 5bc21e7d1cdbba0186bac4df960688c520ff82f8 /test/miscellaneous | |
parent | f2a28f095bd36a0126ca63160f4aa941a24dfc50 (diff) | |
download | qtlocation-mapboxgl-a983dc8259c52cc0a586212c1c24fd4ead2bccbb.tar.gz |
Ported replaceTokens() tests from GL JS
Diffstat (limited to 'test/miscellaneous')
-rw-r--r-- | test/miscellaneous/token.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/miscellaneous/token.cpp b/test/miscellaneous/token.cpp new file mode 100644 index 0000000000..638bf77b8d --- /dev/null +++ b/test/miscellaneous/token.cpp @@ -0,0 +1,50 @@ +#include <iostream> +#include "../fixtures/util.hpp" + +#include <mbgl/util/token.hpp> + +using namespace mbgl; + +TEST(Token, replaceTokens) { + EXPECT_EQ("literal", mbgl::util::replaceTokens("literal", [](const std::string &token) -> std::string { + if (token == "name") return "14th St NW"; + return ""; + })); + EXPECT_EQ("14th St NW", mbgl::util::replaceTokens("{name}", [](const std::string &token) -> std::string { + if (token == "name") return "14th St NW"; + return ""; + })); + EXPECT_EQ("", mbgl::util::replaceTokens("{name}", [](const std::string &token) -> std::string { + if (token == "text") return "14th St NW"; + return ""; + })); + EXPECT_EQ("1400", mbgl::util::replaceTokens("{num}", [](const std::string &token) -> std::string { + if (token == "num") return "1400"; + return ""; + })); + EXPECT_EQ("500 m", mbgl::util::replaceTokens("{num} m", [](const std::string &token) -> std::string { + if (token == "num") return "500"; + return ""; + })); + EXPECT_EQ("3 Fine Fields", mbgl::util::replaceTokens("{a} {b} {c}", [](const std::string &token) -> std::string { + if (token == "a") return "3"; + if (token == "b") return "Fine"; + if (token == "c") return "Fields"; + return ""; + })); + EXPECT_EQ(" but still", mbgl::util::replaceTokens("{notset} but still", [](__unused const std::string &token) -> std::string { + return ""; + })); + EXPECT_EQ("dashed", mbgl::util::replaceTokens("{dashed-property}", [](const std::string &token) -> std::string { + if (token == "dashed-property") return "dashed"; + return ""; + })); + EXPECT_EQ("150 m", mbgl::util::replaceTokens("{HØYDE} m", [](const std::string &token) -> std::string { + if (token == "HØYDE") return "150"; + return ""; + })); + EXPECT_EQ("reserved {for:future} use", mbgl::util::replaceTokens("reserved {for:future} use", [](const std::string &token) -> std::string { + if (token == "for:future") return "unknown"; + return ""; + })); +} |