Mercurial > code
changeset 323:c5dd79aaa216
Json: be sure we can cast iterator arrays to JsonValue
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 03 Mar 2015 18:57:50 +0100 |
parents | 0e80e4589533 |
children | 99e83685d4da 14d9c7a4f358 |
files | C++/Json.h C++/Tests/Json/main.cpp |
diffstat | 2 files changed, 14 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/C++/Json.h Fri Feb 27 18:15:33 2015 +0100 +++ b/C++/Json.h Tue Mar 03 18:57:50 2015 +0100 @@ -689,7 +689,7 @@ { return m_index == other.m_index; } - + inline bool operator!=(const iterator &other) const noexcept { return m_index != other.m_index; @@ -817,7 +817,7 @@ { return m_index == other.m_index; } - + inline bool operator!=(const const_iterator &other) const noexcept { return m_index != other.m_index; @@ -1368,7 +1368,7 @@ inline JsonObject(std::initializer_list<value_type> list) : JsonObject() { - for (auto &v : list) + for (auto &v : list) set(v.first, std::move(v.second)); }
--- a/C++/Tests/Json/main.cpp Fri Feb 27 18:15:33 2015 +0100 +++ b/C++/Tests/Json/main.cpp Tue Mar 03 18:57:50 2015 +0100 @@ -858,6 +858,17 @@ } } +TEST_F(ArrayIteratorsTest, castToRef) +{ + JsonArray array{1, 2, 3}; + int i = 1; + + for (const JsonValue &v : array) + { + ASSERT_EQ(i++, v.toInteger()); + } +} + int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv);