Merge branch 'feature/to_array' into develop
This commit is contained in:
commit
ea5aed0769
3 changed files with 38 additions and 3 deletions
|
@ -295,9 +295,12 @@ TEST_CASE("constructors")
|
|||
{
|
||||
json j{1};
|
||||
|
||||
CHECK_THROWS((j.get<std::pair<int, int>>()));
|
||||
CHECK_THROWS((j.get<std::tuple<int, int>>()));
|
||||
CHECK_THROWS((j.get<std::array<int, 3>>()));
|
||||
CHECK_THROWS_AS((j.get<std::pair<int, int>>()), json::out_of_range);
|
||||
CHECK_THROWS_WITH((j.get<std::pair<int, int>>()), "[json.exception.out_of_range.401] array index 1 is out of range");
|
||||
CHECK_THROWS_AS((j.get<std::tuple<int, int>>()), json::out_of_range);
|
||||
CHECK_THROWS_WITH((j.get<std::tuple<int, int>>()), "[json.exception.out_of_range.401] array index 1 is out of range");
|
||||
CHECK_THROWS_AS((j.get<std::array<int, 3>>()), json::out_of_range);
|
||||
CHECK_THROWS_WITH((j.get<std::array<int, 3>>()), "[json.exception.out_of_range.401] array index 1 is out of range");
|
||||
}
|
||||
|
||||
SECTION("std::forward_list<json>")
|
||||
|
|
|
@ -1009,6 +1009,30 @@ TEST_CASE("value conversion")
|
|||
auto m5 = j5.get<std::forward_list<std::string>>();
|
||||
}
|
||||
|
||||
SECTION("std::array")
|
||||
{
|
||||
auto m1 = j1.get<std::array<int, 4>>();
|
||||
auto m2 = j2.get<std::array<unsigned int, 3>>();
|
||||
auto m3 = j3.get<std::array<double, 4>>();
|
||||
auto m4 = j4.get<std::array<bool, 3>>();
|
||||
auto m5 = j5.get<std::array<std::string, 3>>();
|
||||
|
||||
SECTION("std::array is larger than JSON")
|
||||
{
|
||||
std::array<int, 6> arr6 = {1, 2, 3, 4, 5, 6};
|
||||
CHECK_THROWS_AS(arr6 = j1, json::out_of_range);
|
||||
CHECK_THROWS_WITH(arr6 = j1, "[json.exception.out_of_range.401] array index 4 is out of range");
|
||||
}
|
||||
|
||||
SECTION("std::array is smaller than JSON")
|
||||
{
|
||||
std::array<int, 2> arr2 = {8, 9};
|
||||
arr2 = j1;
|
||||
CHECK(arr2[0] == 1);
|
||||
CHECK(arr2[1] == 2);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("std::valarray")
|
||||
{
|
||||
auto m1 = j1.get<std::valarray<int>>();
|
||||
|
|
|
@ -1305,4 +1305,12 @@ TEST_CASE("regression tests")
|
|||
j = {{"nocopy", n}};
|
||||
CHECK(j["nocopy"]["val"] == 0);
|
||||
}
|
||||
|
||||
SECTION("issue #843 - converting to array not working")
|
||||
{
|
||||
json j;
|
||||
std::array<int, 4> ar = {1, 1, 1, 1};
|
||||
j = ar;
|
||||
ar = j;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue