1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
4#include <userver/protobuf/json/exceptions.hpp>
8namespace protobuf::json::tests {
10TEST(ExceptionsTest, CtorCorrectlyInitializesObject) {
12 const std::string path =
"field.array[0].item[1]";
13 const std::vector<ParseErrorCode> codes{
14 ParseErrorCode::kUnknownField,
15 ParseErrorCode::kUnknownEnum,
16 ParseErrorCode::kMultipleOneofFields,
17 ParseErrorCode::kInvalidType,
18 ParseErrorCode::kInvalidValue,
19 static_cast<ParseErrorCode>(100)
22 for (
const auto& code : codes) {
23 ParseError error(code, path);
25 EXPECT_EQ(error.GetErrorInfo().GetCode(), code);
26 EXPECT_EQ(error.GetErrorInfo().GetPath(), path);
27 EXPECT_EQ(std::move(error).GetErrorInfo().GetPath(), path);
32 const std::string path =
"field.array[0].item[1].map['key']";
33 const std::vector<PrintErrorCode> codes{PrintErrorCode::kInvalidValue,
static_cast<PrintErrorCode>(100)};
35 for (
const auto& code : codes) {
36 PrintError error(code, path);
38 EXPECT_EQ(error.GetErrorInfo().GetCode(), code);
39 EXPECT_EQ(error.GetErrorInfo().GetPath(), path);
40 EXPECT_EQ(std::move(error).GetErrorInfo().GetPath(), path);
45TEST(ExceptionsTest, WhatContainsImportantDetails) {
47 const std::string path =
"field.array[0].item[1]";
48 const ParseError error(ParseErrorCode::kInvalidType, path);
50 EXPECT_THAT(error.what(), ::testing::HasSubstr(path));
54 const std::string path =
"field.array[0].item[1].map['key']";
55 const PrintError error(PrintErrorCode::kInvalidValue, path);
57 EXPECT_THAT(error.what(), ::testing::HasSubstr(path));