Skip to content

Commit

Permalink
Add null value (#28)
Browse files Browse the repository at this point in the history
* add null value

* More assertions

* Fix assertions
  • Loading branch information
mourner authored and jfirebaugh committed May 9, 2016
1 parent d705c09 commit d7a28b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/mapbox/geometry/feature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace mapbox { namespace geometry {

struct value;

using value_base = mapbox::util::variant<bool, int64_t, uint64_t, double, std::string,
using value_base = mapbox::util::variant<std::nullptr_t, bool, int64_t, uint64_t, double, std::string,
mapbox::util::recursive_wrapper<std::vector<value>>,
mapbox::util::recursive_wrapper<std::unordered_map<std::string, value>>>;

Expand Down
24 changes: 24 additions & 0 deletions tests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,30 @@ static void testFeature() {
feature<double> pf { point<double>() };
assert(pf.geometry.is<point<double>>());
assert(pf.properties.size() == 0);

auto &p = pf.properties;

p["bool"] = true;
p["string"] = std::string("foo");
p["double"] = 2.5;
p["uint"] = uint64_t(10);
p["int"] = int64_t(-10);
p["null"] = nullptr;

assert(p["bool"].is<bool>());
assert(p["bool"] == true);
assert(p["string"].is<std::string>());
assert(p["string"] == std::string("foo"));
assert(p["double"].is<double>());
assert(p["double"] == 2.5);
assert(p["uint"].is<uint64_t>());
assert(p["uint"] == uint64_t(10));
assert(p["int"].is<int64_t>());
assert(p["int"] == int64_t(-10));
assert(p["null"].is<std::nullptr_t>());
assert(p["null"] == nullptr);

assert(p.size() == 6);
}

static void testFeatureCollection() {
Expand Down

0 comments on commit d7a28b4

Please sign in to comment.