1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
#include "test.hpp" // IWYU pragma: keep
#include "util.hpp"
#include <osmium/osm/entity_bits.hpp>
#include <sstream>
#include <string>
namespace {
void test_filter(const std::string& expression, osmium::osm_entity_bits::type entities, const char* filter) {
const auto p = get_filter_expression(expression);
REQUIRE(p.first == entities);
REQUIRE(p.second == filter);
}
void test_strip_whitespace(const char* in, const char* out) {
std::string str{in};
strip_whitespace(str);
REQUIRE(str == out);
}
void test_string_matcher(const char* string, const char* print_out) {
std::stringstream ss;
ss << get_string_matcher(string);
REQUIRE(ss.str() == print_out);
}
bool test_tag_matcher(const char* expression, const char* key, const char* value) {
const auto matcher = get_tag_matcher(expression);
return matcher(key, value);
}
} // anonymous namespace
TEST_CASE("Get suffix from filename") {
REQUIRE(get_filename_suffix("foo.bar") == "bar");
}
TEST_CASE("Get suffixes from filename") {
REQUIRE(get_filename_suffix("foo.bar.baz") == "bar.baz");
}
TEST_CASE("Get suffixes from file path") {
REQUIRE(get_filename_suffix("/usr/local/foo.bar.baz") == "bar.baz");
}
TEST_CASE("Get suffixes from relative path") {
REQUIRE(get_filename_suffix("../somewhere/foo.bar.baz") == "bar.baz");
}
TEST_CASE("Get suffixes from path with dots in the middle") {
REQUIRE(get_filename_suffix("anything/../somewhere/foo.bar.baz") == "bar.baz");
}
TEST_CASE("Get object types") {
REQUIRE(get_types("") == osmium::osm_entity_bits::nothing);
REQUIRE(get_types("n") == osmium::osm_entity_bits::node);
REQUIRE(get_types("w") == osmium::osm_entity_bits::way);
REQUIRE(get_types("r") == osmium::osm_entity_bits::relation);
REQUIRE(get_types("nw") == (osmium::osm_entity_bits::node | osmium::osm_entity_bits::way));
REQUIRE(get_types("rw") == (osmium::osm_entity_bits::way | osmium::osm_entity_bits::relation));
REQUIRE_THROWS_AS(get_types("x"), argument_error);
REQUIRE_THROWS_AS(get_types("nwx"), argument_error);
}
TEST_CASE("Get tags filter expression") {
test_filter("highway", osmium::osm_entity_bits::nwr, "highway");
test_filter("/highway", osmium::osm_entity_bits::nwr, "highway");
test_filter("n/highway", osmium::osm_entity_bits::node, "highway");
test_filter("w/highway", osmium::osm_entity_bits::way, "highway");
test_filter("r/highway", osmium::osm_entity_bits::relation, "highway");
test_filter("nw/highway", osmium::osm_entity_bits::node | osmium::osm_entity_bits::way, "highway");
test_filter("n/highway/foo", osmium::osm_entity_bits::node, "highway/foo");
REQUIRE_THROWS_AS(get_filter_expression("highway/foo"), argument_error);
}
TEST_CASE("strip whitespace") {
test_strip_whitespace("foo", "foo");
test_strip_whitespace(" foo", "foo");
test_strip_whitespace("foo ", "foo");
test_strip_whitespace(" foo ", "foo");
test_strip_whitespace(" foo ", "foo");
test_strip_whitespace("f o o", "f o o");
}
TEST_CASE("get_string_matcher") {
test_string_matcher("foo", "equal[foo]");
test_string_matcher("", "equal[]");
test_string_matcher("foo*", "prefix[foo]");
test_string_matcher(" foo* ", "prefix[foo]");
test_string_matcher("*foo", "substring[foo]");
test_string_matcher("*foo*", "substring[foo]");
test_string_matcher(" *foo* ", "substring[foo]");
test_string_matcher("*", "always_true");
test_string_matcher(" * ", "always_true");
test_string_matcher("f*oo", "equal[f*oo]");
test_string_matcher("foo,bar", "list[[foo][bar]]");
test_string_matcher("foo,bar*,baz", "list[[foo][bar*][baz]]");
test_string_matcher("*foo,bar", "substring[foo,bar]");
test_string_matcher("foo ", "equal[foo]");
test_string_matcher(" foo", "equal[foo]");
test_string_matcher(" foo ", "equal[foo]");
test_string_matcher("foo ", "equal[foo]");
test_string_matcher(" foo", "equal[foo]");
test_string_matcher(" foo ", "equal[foo]");
test_string_matcher("foo, bar, baz", "list[[foo][bar][baz]]");
test_string_matcher(" foo, bar ,baz ", "list[[foo][bar][baz]]");
}
TEST_CASE("get_tag_matcher") {
REQUIRE(test_tag_matcher("foo", "foo", "bar"));
REQUIRE(test_tag_matcher("foo=bar", "foo", "bar"));
REQUIRE(test_tag_matcher("foo!=bar", "foo", "baz"));
REQUIRE_FALSE(test_tag_matcher("foo!=bar", "foo", "bar"));
REQUIRE(test_tag_matcher("highway=primary,secondary", "highway", "primary"));
REQUIRE(test_tag_matcher("highway=primary,secondary", "highway", "secondary"));
REQUIRE_FALSE(test_tag_matcher("highway=primary,secondary", "highway", "residential"));
REQUIRE(test_tag_matcher("landuse,natural", "landuse", "forest"));
REQUIRE(test_tag_matcher("landuse,natural", "natural", "wood"));
REQUIRE_FALSE(test_tag_matcher("landuse,natural", "highway", "motorway"));
REQUIRE(test_tag_matcher("addr:*", "addr:city", "Berlin"));
REQUIRE_FALSE(test_tag_matcher("addr:*", "addr", "Berlin"));
}
TEST_CASE("ends_with") {
REQUIRE_FALSE(ends_with("foo", "bar"));
REQUIRE_FALSE(ends_with("", "bar"));
REQUIRE_FALSE(ends_with("foox", "foo"));
REQUIRE(ends_with("", ""));
REQUIRE(ends_with("abc", "abc"));
REQUIRE(ends_with("abc", "bc"));
REQUIRE(ends_with("abc", "c"));
REQUIRE(ends_with("abc", ""));
REQUIRE(ends_with("file.json", ".json"));
REQUIRE(ends_with("some.file.json", ".json"));
REQUIRE(ends_with("file.osm.bz2", ".bz2"));
REQUIRE(ends_with("file.osm.bz2", ".osm.bz2"));
}
|