Protocol Buffers - Google's data interchange format (grpc依赖)
https://developers.google.com/protocol-buffers/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.5 KiB
85 lines
2.5 KiB
1 year ago
|
// Protocol Buffers - Google's data interchange format
|
||
|
// Copyright 2023 Google LLC. All rights reserved.
|
||
|
//
|
||
1 year ago
|
// Use of this source code is governed by a BSD-style
|
||
|
// license that can be found in the LICENSE file or at
|
||
|
// https://developers.google.com/open-source/licenses/bsd
|
||
2 years ago
|
|
||
1 year ago
|
#include "upb/reflection/internal/def_builder.h"
|
||
1 year ago
|
|
||
1 year ago
|
#include <gtest/gtest.h>
|
||
2 years ago
|
#include "absl/strings/string_view.h"
|
||
1 year ago
|
#include "upb/mem/arena.hpp"
|
||
2 years ago
|
|
||
|
// Must be last.
|
||
1 year ago
|
#include "upb/port/def.inc"
|
||
2 years ago
|
|
||
2 years ago
|
struct IdentTestData {
|
||
|
absl::string_view text;
|
||
2 years ago
|
bool ok;
|
||
|
};
|
||
2 years ago
|
|
||
2 years ago
|
class FullIdentTestBase : public testing::TestWithParam<IdentTestData> {};
|
||
2 years ago
|
|
||
2 years ago
|
TEST_P(FullIdentTestBase, CheckFullIdent) {
|
||
|
upb_Status status;
|
||
|
upb_DefBuilder ctx;
|
||
|
upb::Arena arena;
|
||
|
ctx.status = &status;
|
||
|
ctx.arena = arena.ptr();
|
||
|
upb_Status_Clear(&status);
|
||
|
|
||
|
if (UPB_SETJMP(ctx.err)) {
|
||
|
EXPECT_FALSE(GetParam().ok);
|
||
|
} else {
|
||
|
_upb_DefBuilder_CheckIdentFull(
|
||
|
&ctx, upb_StringView_FromDataAndSize(GetParam().text.data(),
|
||
|
GetParam().text.size()));
|
||
|
EXPECT_TRUE(GetParam().ok);
|
||
|
}
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
INSTANTIATE_TEST_SUITE_P(FullIdentTest, FullIdentTestBase,
|
||
|
testing::ValuesIn(std::vector<IdentTestData>{
|
||
|
{"foo.bar", true},
|
||
|
{"foo.", true},
|
||
|
{"foo", true},
|
||
2 years ago
|
|
||
2 years ago
|
{"foo.7bar", false},
|
||
|
{".foo", false},
|
||
|
{"#", false},
|
||
|
{".", false},
|
||
|
{"", false}}));
|
||
|
|
||
|
class PartIdentTestBase : public testing::TestWithParam<IdentTestData> {};
|
||
2 years ago
|
|
||
2 years ago
|
TEST_P(PartIdentTestBase, TestNotFullIdent) {
|
||
2 years ago
|
upb_Status status;
|
||
|
upb_DefBuilder ctx;
|
||
2 years ago
|
upb::Arena arena;
|
||
2 years ago
|
ctx.status = &status;
|
||
2 years ago
|
ctx.arena = arena.ptr();
|
||
2 years ago
|
upb_Status_Clear(&status);
|
||
2 years ago
|
|
||
2 years ago
|
if (UPB_SETJMP(ctx.err)) {
|
||
|
EXPECT_FALSE(GetParam().ok);
|
||
|
} else {
|
||
|
_upb_DefBuilder_MakeFullName(
|
||
|
&ctx, "abc",
|
||
|
upb_StringView_FromDataAndSize(GetParam().text.data(),
|
||
|
GetParam().text.size()));
|
||
|
EXPECT_TRUE(GetParam().ok);
|
||
2 years ago
|
}
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
INSTANTIATE_TEST_SUITE_P(PartIdentTest, PartIdentTestBase,
|
||
|
testing::ValuesIn(std::vector<IdentTestData>{
|
||
|
{"foo", true},
|
||
|
{"foo1", true},
|
||
2 years ago
|
|
||
2 years ago
|
{"foo.bar", false},
|
||
|
{"1foo", false},
|
||
|
{"#", false},
|
||
|
{".", false},
|
||
|
{"", false}}));
|