Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

replaceTokens() tests #3074

Merged
merged 2 commits into from
Nov 19, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions test/miscellaneous/token.cpp
Original file line number Diff line number Diff line change
@@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linux build is failing on __unused -- omit the parameter name instead.

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 "";
}));
}
1 change: 1 addition & 0 deletions test/test.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
'miscellaneous/text_conversions.cpp',
'miscellaneous/thread.cpp',
'miscellaneous/tile.cpp',
'miscellaneous/token.cpp',
'miscellaneous/transform.cpp',
'miscellaneous/work_queue.cpp',
'miscellaneous/variant.cpp',
Expand Down