Update at_path(toml::path) to handle missing component (#168)
* test(paths): check at_path handles missing path component * fix(paths): update at_path to handle missing component
This commit is contained in:
parent
cc3c6606f8
commit
be0fbd5203
@ -259,6 +259,7 @@ UTF-8 decoding is performed using a state machine based on Bjoern Hoehrmann's '[
|
||||
- **[@bobfang1992](https://github.com/bobfang1992)** - Reported a bug and created a [wrapper in python](https://github.com/bobfang1992/pytomlpp)
|
||||
- **[@GiulioRomualdi](https://github.com/GiulioRomualdi)** - Added cmake+meson support
|
||||
- **[@jonestristand](https://github.com/jonestristand)** - Designed and implemented the `toml::path`s feature
|
||||
- **[@kcsaul](https://github.com/kcsaul)** - Fixed a bug
|
||||
- **[@levicki](https://github.com/levicki)** - Helped design some new features
|
||||
- **[@moorereason](https://github.com/moorereason)** - Reported a whole bunch of bugs
|
||||
- **[@mosra](https://github.com/mosra)** - Created the awesome [m.css] used to generate the API docs
|
||||
|
@ -504,6 +504,9 @@ TOML_NAMESPACE_START
|
||||
// Error: invalid component
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!current)
|
||||
return {}; // not found
|
||||
}
|
||||
|
||||
return node_view{ current };
|
||||
|
@ -510,6 +510,8 @@ TEST_CASE("path - accessing")
|
||||
|
||||
CHECK(tbl["d"][""]);
|
||||
CHECK(tbl["d"][""] == at_path(tbl, toml::path("d.")));
|
||||
|
||||
CHECK(!at_path(tbl, toml::path("has.missing.component")));
|
||||
}
|
||||
|
||||
SECTION("array")
|
||||
@ -535,6 +537,8 @@ TEST_CASE("path - accessing")
|
||||
CHECK(tbl["b"][2]["c"]);
|
||||
CHECK(tbl["b"][2]["c"] == arr.at_path(toml::path("[2].c")));
|
||||
CHECK(tbl["b"][2]["c"] == arr.at_path(toml::path("[2] \t.c"))); // whitespace is allowed after array indexers
|
||||
|
||||
CHECK(!arr.at_path(toml::path("[3].missing.component")));
|
||||
}
|
||||
|
||||
SECTION("indexing operator")
|
||||
@ -580,5 +584,7 @@ TEST_CASE("path - accessing")
|
||||
|
||||
CHECK(tbl["d"][""]);
|
||||
CHECK(tbl["d"][""] == tbl[toml::path("d.")]);
|
||||
|
||||
CHECK(!tbl[toml::path("has.missing.component")]);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user