|
| 1 | +// Copyright 2009-present MongoDB, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include <bsoncxx/test/v1/array/view.hh> |
| 16 | + |
| 17 | +// |
| 18 | + |
| 19 | +#include <bsoncxx/test/v1/exception.hh> |
| 20 | +#include <bsoncxx/test/v1/types/view.hh> // IWYU pragma: keep: Catch::StringMaker<bsoncxx::v1::types::view> |
| 21 | + |
| 22 | +#include <string> |
| 23 | + |
| 24 | +#include <bsoncxx/test/stringify.hh> |
| 25 | + |
| 26 | +#include <catch2/catch_test_macros.hpp> |
| 27 | + |
| 28 | +std::string Catch::StringMaker<bsoncxx::v1::array::view>::convert(bsoncxx::v1::array::view const& value) try { |
| 29 | + if (!value) { |
| 30 | + return "invalid"; |
| 31 | + } |
| 32 | + |
| 33 | + auto const end = value.end(); |
| 34 | + auto iter = value.begin(); |
| 35 | + |
| 36 | + if (iter == end) { |
| 37 | + return "[]"; |
| 38 | + } |
| 39 | + |
| 40 | + std::string res; |
| 41 | + res += '['; |
| 42 | + res += bsoncxx::test::stringify(iter->type_view()); |
| 43 | + for (++iter; iter != end; ++iter) { |
| 44 | + res += ", "; |
| 45 | + res += bsoncxx::test::stringify(iter->type_view()); |
| 46 | + } |
| 47 | + res += ']'; |
| 48 | + return res; |
| 49 | +} catch (bsoncxx::v1::exception const& ex) { |
| 50 | + WARN("exception during stringification: " << ex.what()); |
| 51 | + if (ex.code() == bsoncxx::v1::document::view::errc::invalid_data) { |
| 52 | + return "invalid"; |
| 53 | + } else { |
| 54 | + throw; |
| 55 | + } |
| 56 | +} |
0 commit comments