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:
Kevin Saul 2022-08-25 17:13:22 +12:00 committed by GitHub
parent cc3c6606f8
commit be0fbd5203
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 0 deletions

View File

@ -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

View File

@ -504,6 +504,9 @@ TOML_NAMESPACE_START
// Error: invalid component
return {};
}
if (!current)
return {}; // not found
}
return node_view{ current };

View File

@ -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")]);
}
}

View File

@ -11161,6 +11161,9 @@ TOML_NAMESPACE_START
// Error: invalid component
return {};
}
if (!current)
return {}; // not found
}
return node_view{ current };