2014-01-19 13:04:08 +04:00
|
|
|
//===- unittest/Format/FormatTestProto.cpp --------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "FormatTestUtils.h"
|
|
|
|
#include "clang/Format/Format.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2014-04-22 07:17:02 +04:00
|
|
|
#define DEBUG_TYPE "format-test"
|
|
|
|
|
2014-01-19 13:04:08 +04:00
|
|
|
namespace clang {
|
|
|
|
namespace format {
|
|
|
|
|
|
|
|
class FormatTestProto : public ::testing::Test {
|
|
|
|
protected:
|
|
|
|
static std::string format(llvm::StringRef Code, unsigned Offset,
|
2018-04-23 11:50:36 +03:00
|
|
|
unsigned Length, const FormatStyle &Style) {
|
2018-05-15 16:30:56 +03:00
|
|
|
LLVM_DEBUG(llvm::errs() << "---\n");
|
|
|
|
LLVM_DEBUG(llvm::errs() << Code << "\n\n");
|
2014-01-19 13:04:08 +04:00
|
|
|
std::vector<tooling::Range> Ranges(1, tooling::Range(Offset, Length));
|
2018-04-23 11:50:36 +03:00
|
|
|
tooling::Replacements Replaces = reformat(Style, Code, Ranges);
|
2016-07-11 16:53:12 +03:00
|
|
|
auto Result = applyAllReplacements(Code, Replaces);
|
|
|
|
EXPECT_TRUE(static_cast<bool>(Result));
|
2018-05-15 16:30:56 +03:00
|
|
|
LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
|
2016-07-11 16:53:12 +03:00
|
|
|
return *Result;
|
2014-01-19 13:04:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static std::string format(llvm::StringRef Code) {
|
2014-02-03 00:50:45 +04:00
|
|
|
FormatStyle Style = getGoogleStyle(FormatStyle::LK_Proto);
|
2014-01-22 12:04:52 +04:00
|
|
|
Style.ColumnLimit = 60; // To make writing tests easier.
|
|
|
|
return format(Code, 0, Code.size(), Style);
|
2014-01-19 13:04:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void verifyFormat(llvm::StringRef Code) {
|
2018-04-05 00:09:00 +03:00
|
|
|
EXPECT_EQ(Code.str(), format(Code)) << "Expected code is not stable";
|
2014-01-19 13:04:08 +04:00
|
|
|
EXPECT_EQ(Code.str(), format(test::messUp(Code)));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(FormatTestProto, FormatsMessages) {
|
|
|
|
verifyFormat("message SomeMessage {\n"
|
|
|
|
" required int32 field1 = 1;\n"
|
|
|
|
"}");
|
2014-06-23 11:36:25 +04:00
|
|
|
verifyFormat("message SomeMessage {\n"
|
|
|
|
" required .absolute.Reference field1 = 1;\n"
|
|
|
|
"}");
|
2014-01-19 13:04:08 +04:00
|
|
|
verifyFormat("message SomeMessage {\n"
|
|
|
|
" required int32 field1 = 1;\n"
|
|
|
|
" optional string field2 = 2 [default = \"2\"]\n"
|
|
|
|
"}");
|
2014-01-22 12:04:52 +04:00
|
|
|
|
|
|
|
verifyFormat("message SomeMessage {\n"
|
2014-05-08 04:05:13 +04:00
|
|
|
" optional really.really.long.qualified.type.aaa.aaaaaaa\n"
|
2014-01-22 12:04:52 +04:00
|
|
|
" fiiiiiiiiiiiiiiiiiiiiiiiiield = 1;\n"
|
|
|
|
" optional\n"
|
2014-05-08 04:05:13 +04:00
|
|
|
" really.really.long.qualified.type.aaa.aaaaaaa.aaaaaaaa\n"
|
2014-01-22 12:04:52 +04:00
|
|
|
" another_fiiiiiiiiiiiiiiiiiiiiield = 2;\n"
|
|
|
|
"}");
|
2017-06-27 13:06:40 +03:00
|
|
|
verifyFormat("message SomeMessage {\n"
|
|
|
|
" map<string, Project> projects = 1;\n"
|
|
|
|
" optional map<string, int32> size_projects = 2;\n"
|
|
|
|
" map<int, really.really.really.long.qualified.type.nameeee>\n"
|
|
|
|
" projects = 3;\n"
|
|
|
|
" map<int, really.really.really.really.long.qualified.type\n"
|
|
|
|
" .nameeee> projects = 4;\n"
|
|
|
|
" map<int,\n"
|
|
|
|
" reallyreallyreallyreallyreallyreallyreallylongname>\n"
|
|
|
|
" projects = 5;\n"
|
|
|
|
" map<int, Project>\n"
|
|
|
|
" longlonglonglonglonglonglonglonglonglongonglon = 6;\n"
|
|
|
|
" map<releleallyreallyreallyreallyreallyreallyreallylongname,\n"
|
|
|
|
" int> projects = 7;\n"
|
|
|
|
" map<releleallyreallyreallyreallyreallyreallyreallylongname,\n"
|
|
|
|
" releleallyreallyreallyreallyreallyreallyreallylongname>\n"
|
|
|
|
" releleallyreallyreallyreallyreallyreallyreallylongnam =\n"
|
|
|
|
" 8;\n"
|
|
|
|
" map<relele.llyreal.yreallyr.allyreally.eallyreal\n"
|
|
|
|
" .sauenirylongname,\n"
|
|
|
|
" really.really.really.really.long.qualified.type\n"
|
|
|
|
" .nameeee> projects = 9;\n"
|
|
|
|
"}");
|
2014-01-19 13:04:08 +04:00
|
|
|
}
|
|
|
|
|
2015-06-25 11:38:46 +03:00
|
|
|
TEST_F(FormatTestProto, KeywordsInOtherLanguages) {
|
|
|
|
verifyFormat("optional string operator = 1;");
|
|
|
|
}
|
|
|
|
|
2014-01-19 13:04:08 +04:00
|
|
|
TEST_F(FormatTestProto, FormatsEnums) {
|
|
|
|
verifyFormat("enum Type {\n"
|
|
|
|
" UNKNOWN = 0;\n"
|
|
|
|
" TYPE_A = 1;\n"
|
|
|
|
" TYPE_B = 2;\n"
|
|
|
|
"};");
|
2016-06-23 12:40:19 +03:00
|
|
|
verifyFormat("enum Type {\n"
|
2018-01-31 13:14:10 +03:00
|
|
|
" UNKNOWN = 0 [(some_options) = { a: aa, b: bb }];\n"
|
2016-06-23 12:40:19 +03:00
|
|
|
"};");
|
2015-07-16 17:25:43 +03:00
|
|
|
verifyFormat("enum Type {\n"
|
|
|
|
" UNKNOWN = 0 [(some_options) = {\n"
|
2016-06-23 12:40:19 +03:00
|
|
|
" a: aa, // wrap\n"
|
2015-07-16 17:25:43 +03:00
|
|
|
" b: bb\n"
|
|
|
|
" }];\n"
|
|
|
|
"};");
|
2014-01-19 13:04:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FormatTestProto, UnderstandsReturns) {
|
|
|
|
verifyFormat("rpc Search(SearchRequest) returns (SearchResponse);");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FormatTestProto, MessageFieldAttributes) {
|
|
|
|
verifyFormat("optional string test = 1 [default = \"test\"];");
|
2014-01-28 22:51:11 +04:00
|
|
|
verifyFormat("optional bool a = 1 [default = true, deprecated = true];");
|
2016-01-04 10:27:33 +03:00
|
|
|
verifyFormat("optional LongMessageType long_proto_field = 1 [\n"
|
|
|
|
" default = REALLY_REALLY_LONG_CONSTANT_VALUE,\n"
|
|
|
|
" deprecated = true\n"
|
|
|
|
"];");
|
2014-01-19 13:04:08 +04:00
|
|
|
verifyFormat("optional LongMessageType long_proto_field = 1\n"
|
|
|
|
" [default = REALLY_REALLY_LONG_CONSTANT_VALUE];");
|
2014-01-29 22:43:40 +04:00
|
|
|
verifyFormat("repeated double value = 1\n"
|
2018-01-31 13:14:10 +03:00
|
|
|
" [(aaaaaaa.aaaaaaaaa) = { aaaaaaaaaaaaaaaaa: AAAAAAAA }];");
|
2014-10-27 16:25:59 +03:00
|
|
|
verifyFormat("repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = {\n"
|
|
|
|
" aaaaaaaaaaaaaaaa: AAAAAAAAAA,\n"
|
|
|
|
" bbbbbbbbbbbbbbbb: BBBBBBBBBB\n"
|
|
|
|
"}];");
|
|
|
|
verifyFormat("repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = {\n"
|
|
|
|
" aaaaaaaaaaaaaaaa: AAAAAAAAAA\n"
|
|
|
|
" bbbbbbbbbbbbbbbb: BBBBBBBBBB\n"
|
|
|
|
"}];");
|
2016-01-04 10:27:33 +03:00
|
|
|
verifyFormat("repeated double value = 1 [\n"
|
|
|
|
" (aaaaaaa.aaaaaaaaa) = {\n"
|
|
|
|
" aaaaaaaaaaaaaaaa: AAAAAAAAAA\n"
|
|
|
|
" bbbbbbbbbbbbbbbb: BBBBBBBBBB\n"
|
|
|
|
" },\n"
|
|
|
|
" (bbbbbbb.bbbbbbbbb) = {\n"
|
|
|
|
" aaaaaaaaaaaaaaaa: AAAAAAAAAA\n"
|
|
|
|
" bbbbbbbbbbbbbbbb: BBBBBBBBBB\n"
|
|
|
|
" }\n"
|
|
|
|
"];");
|
2015-04-04 00:15:46 +03:00
|
|
|
verifyFormat("repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = {\n"
|
|
|
|
" type: \"AAAAAAAAAA\"\n"
|
|
|
|
" is: \"AAAAAAAAAA\"\n"
|
|
|
|
" or: \"BBBBBBBBBB\"\n"
|
|
|
|
"}];");
|
2014-10-27 16:25:59 +03:00
|
|
|
verifyFormat("repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = {\n"
|
|
|
|
" aaaaaaaaaaaaaaaa: AAAAAAAAAA,\n"
|
|
|
|
" bbbbbbb: BBBB,\n"
|
|
|
|
" bbbb: BBB\n"
|
|
|
|
"}];");
|
2016-01-04 10:27:33 +03:00
|
|
|
verifyFormat("optional AAA aaa = 1 [\n"
|
|
|
|
" foo = {\n"
|
|
|
|
" key: 'a' //\n"
|
|
|
|
" },\n"
|
|
|
|
" bar = {\n"
|
|
|
|
" key: 'a' //\n"
|
|
|
|
" }\n"
|
|
|
|
"];");
|
2018-03-12 13:32:18 +03:00
|
|
|
verifyFormat("optional string test = 1 [default = \"test\"\n"
|
|
|
|
" \"test\"];");
|
2017-03-14 03:40:32 +03:00
|
|
|
verifyFormat("optional Aaaaaaaa aaaaaaaa = 12 [\n"
|
|
|
|
" (aaa) = aaaa,\n"
|
|
|
|
" (bbbbbbbbbbbbbbbbbbbbbbbbbb) = {\n"
|
|
|
|
" aaaaaaaaaaaaaaaaa: true,\n"
|
|
|
|
" aaaaaaaaaaaaaaaa: true\n"
|
|
|
|
" }\n"
|
|
|
|
"];");
|
2018-02-19 18:31:25 +03:00
|
|
|
verifyFormat("extensions 20 [(proto2.type) = 'Aaaa.bbbb'];");
|
|
|
|
verifyFormat("extensions 20\n"
|
|
|
|
" [(proto3.type) = 'Aaaa.bbbb', (aaa.Aaa) = 'aaa.bbb'];");
|
|
|
|
verifyFormat("extensions 123 [\n"
|
|
|
|
" (aaa) = aaaa,\n"
|
|
|
|
" (bbbbbbbbbbbbbbbbbbbbbbbbbb) = {\n"
|
|
|
|
" aaaaaaaaaaaaaaaaa: true,\n"
|
|
|
|
" aaaaaaaaaaaaaaaa: true\n"
|
|
|
|
" }\n"
|
|
|
|
"];");
|
2014-01-19 13:04:08 +04:00
|
|
|
}
|
|
|
|
|
2015-04-23 12:54:10 +03:00
|
|
|
TEST_F(FormatTestProto, DoesntWrapFileOptions) {
|
|
|
|
EXPECT_EQ(
|
|
|
|
"option java_package = "
|
|
|
|
"\"some.really.long.package.that.exceeds.the.column.limit\";",
|
|
|
|
format("option java_package = "
|
|
|
|
"\"some.really.long.package.that.exceeds.the.column.limit\";"));
|
|
|
|
}
|
|
|
|
|
2014-01-20 20:47:22 +04:00
|
|
|
TEST_F(FormatTestProto, FormatsOptions) {
|
2014-07-28 18:08:09 +04:00
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" field_a: OK\n"
|
|
|
|
" field_b: \"OK\"\n"
|
|
|
|
" field_c: \"OK\"\n"
|
2018-01-31 13:14:10 +03:00
|
|
|
" msg_field: { field_d: 123 }\n"
|
2014-07-28 18:08:09 +04:00
|
|
|
"};");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" field_a: OK\n"
|
|
|
|
" field_b: \"OK\"\n"
|
|
|
|
" field_c: \"OK\"\n"
|
2018-01-31 13:14:10 +03:00
|
|
|
" msg_field: { field_d: 123 field_e: OK }\n"
|
2014-07-28 18:08:09 +04:00
|
|
|
"};");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" field_a: OK // Comment\n"
|
|
|
|
" field_b: \"OK\"\n"
|
|
|
|
" field_c: \"OK\"\n"
|
2018-01-31 13:14:10 +03:00
|
|
|
" msg_field: { field_d: 123 }\n"
|
2014-07-28 18:08:09 +04:00
|
|
|
"};");
|
2014-08-15 09:00:35 +04:00
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" field_c: \"OK\"\n"
|
2018-01-31 13:14:10 +03:00
|
|
|
" msg_field { field_d: 123 }\n"
|
2014-08-15 09:00:35 +04:00
|
|
|
"};");
|
2017-06-29 16:30:41 +03:00
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" field_a: OK\n"
|
2018-01-31 13:14:10 +03:00
|
|
|
" field_b { field_c: OK }\n"
|
2017-06-29 16:30:41 +03:00
|
|
|
" field_d: OKOKOK\n"
|
|
|
|
" field_e: OK\n"
|
|
|
|
"}");
|
2016-01-04 10:28:12 +03:00
|
|
|
|
|
|
|
// Support syntax with <> instead of {}.
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" field_c: \"OK\",\n"
|
2018-02-06 14:34:34 +03:00
|
|
|
" msg_field: < field_d: 123 >\n"
|
|
|
|
" empty: <>\n"
|
|
|
|
" empty <>\n"
|
2016-01-04 10:28:12 +03:00
|
|
|
"};");
|
2017-06-27 16:43:07 +03:00
|
|
|
|
2017-06-29 16:30:41 +03:00
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" field_a: OK\n"
|
2018-02-06 14:34:34 +03:00
|
|
|
" field_b < field_c: OK >\n"
|
2017-06-29 16:30:41 +03:00
|
|
|
" field_d: OKOKOK\n"
|
|
|
|
" field_e: OK\n"
|
|
|
|
"}");
|
|
|
|
|
2017-06-27 16:43:07 +03:00
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" msg_field: <>\n"
|
|
|
|
" field_c: \"OK\",\n"
|
2018-02-06 14:34:34 +03:00
|
|
|
" msg_field: < field_d: 123 >\n"
|
2017-06-27 16:43:07 +03:00
|
|
|
" field_e: OK\n"
|
2018-02-06 14:34:34 +03:00
|
|
|
" msg_field: < field_d: 12 >\n"
|
2017-06-27 16:43:07 +03:00
|
|
|
"};");
|
|
|
|
|
|
|
|
verifyFormat("option (MyProto.options) = <\n"
|
|
|
|
" field_a: OK\n"
|
|
|
|
" field_b: \"OK\"\n"
|
|
|
|
" field_c: 1\n"
|
|
|
|
" field_d: 12.5\n"
|
|
|
|
" field_e: OK\n"
|
|
|
|
">;");
|
|
|
|
|
|
|
|
verifyFormat("option (MyProto.options) = <\n"
|
|
|
|
" field_a: OK,\n"
|
|
|
|
" field_b: \"OK\",\n"
|
|
|
|
" field_c: 1,\n"
|
|
|
|
" field_d: 12.5,\n"
|
|
|
|
" field_e: OK,\n"
|
|
|
|
">;");
|
|
|
|
|
|
|
|
verifyFormat("option (MyProto.options) = <\n"
|
|
|
|
" field_a: \"OK\"\n"
|
2018-01-31 13:14:10 +03:00
|
|
|
" msg_field: { field_b: OK }\n"
|
2017-06-27 16:43:07 +03:00
|
|
|
" field_g: OK\n"
|
|
|
|
" field_g: OK\n"
|
|
|
|
" field_g: OK\n"
|
|
|
|
">;");
|
|
|
|
|
|
|
|
verifyFormat("option (MyProto.options) = <\n"
|
|
|
|
" field_a: \"OK\"\n"
|
2017-07-06 16:58:29 +03:00
|
|
|
" msg_field <\n"
|
2017-06-27 16:43:07 +03:00
|
|
|
" field_b: OK\n"
|
|
|
|
" field_c: OK\n"
|
|
|
|
" field_d: OK\n"
|
|
|
|
" field_e: OK\n"
|
|
|
|
" field_f: OK\n"
|
|
|
|
" >\n"
|
|
|
|
" field_g: OK\n"
|
|
|
|
">;");
|
|
|
|
|
|
|
|
verifyFormat("option (MyProto.options) = <\n"
|
|
|
|
" field_a: \"OK\"\n"
|
2017-07-06 16:58:29 +03:00
|
|
|
" msg_field <\n"
|
2017-06-27 16:43:07 +03:00
|
|
|
" field_b: OK,\n"
|
|
|
|
" field_c: OK,\n"
|
|
|
|
" field_d: OK,\n"
|
|
|
|
" field_e: OK,\n"
|
|
|
|
" field_f: OK\n"
|
|
|
|
" >\n"
|
|
|
|
" field_g: OK\n"
|
|
|
|
">;");
|
|
|
|
|
|
|
|
verifyFormat("option (MyProto.options) = <\n"
|
|
|
|
" field_a: \"OK\"\n"
|
|
|
|
" msg_field: <\n"
|
|
|
|
" field_b: OK\n"
|
|
|
|
" field_c: OK\n"
|
|
|
|
" field_d: OK\n"
|
|
|
|
" field_e: OK\n"
|
|
|
|
" field_f: OK\n"
|
|
|
|
" >\n"
|
|
|
|
" field_g: OK\n"
|
|
|
|
">;");
|
|
|
|
|
|
|
|
verifyFormat("option (MyProto.options) = <\n"
|
|
|
|
" field_a: \"OK\"\n"
|
|
|
|
" msg_field: {\n"
|
|
|
|
" field_b: OK\n"
|
|
|
|
" field_c: OK\n"
|
|
|
|
" field_d: OK\n"
|
|
|
|
" field_e: OK\n"
|
|
|
|
" field_f: OK\n"
|
|
|
|
" }\n"
|
|
|
|
" field_g: OK\n"
|
|
|
|
">;");
|
|
|
|
|
|
|
|
verifyFormat("option (MyProto.options) = <\n"
|
|
|
|
" field_a: \"OK\"\n"
|
2017-07-06 16:58:29 +03:00
|
|
|
" msg_field {\n"
|
2017-06-27 16:43:07 +03:00
|
|
|
" field_b: OK\n"
|
|
|
|
" field_c: OK\n"
|
|
|
|
" field_d: OK\n"
|
|
|
|
" field_e: OK\n"
|
|
|
|
" field_f: OK\n"
|
|
|
|
" }\n"
|
|
|
|
" field_g: OK\n"
|
|
|
|
">;");
|
|
|
|
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" field_a: \"OK\"\n"
|
2017-07-06 16:58:29 +03:00
|
|
|
" msg_field <\n"
|
2017-06-27 16:43:07 +03:00
|
|
|
" field_b: OK\n"
|
|
|
|
" field_c: OK\n"
|
|
|
|
" field_d: OK\n"
|
|
|
|
" field_e: OK\n"
|
|
|
|
" field_f: OK\n"
|
|
|
|
" >\n"
|
|
|
|
" field_g: OK\n"
|
|
|
|
"};");
|
|
|
|
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" field_a: \"OK\"\n"
|
|
|
|
" msg_field: <\n"
|
|
|
|
" field_b: OK\n"
|
|
|
|
" field_c: OK\n"
|
|
|
|
" field_d: OK\n"
|
|
|
|
" field_e: OK\n"
|
|
|
|
" field_f: OK\n"
|
|
|
|
" >\n"
|
|
|
|
" field_g: OK\n"
|
|
|
|
"};");
|
|
|
|
|
|
|
|
verifyFormat("option (MyProto.options) = <\n"
|
|
|
|
" field_a: \"OK\"\n"
|
2017-07-06 16:58:29 +03:00
|
|
|
" msg_field {\n"
|
2017-06-27 16:43:07 +03:00
|
|
|
" field_b: OK\n"
|
|
|
|
" field_c: OK\n"
|
|
|
|
" field_d: OK\n"
|
2017-07-06 16:58:29 +03:00
|
|
|
" msg_field <\n"
|
2017-06-27 16:43:07 +03:00
|
|
|
" field_A: 1\n"
|
|
|
|
" field_B: 2\n"
|
|
|
|
" field_C: 3\n"
|
|
|
|
" field_D: 4\n"
|
|
|
|
" field_E: 5\n"
|
|
|
|
" >\n"
|
2018-02-06 14:34:34 +03:00
|
|
|
" msg_field < field_A: 1 field_B: 2 field_C: 3 f_D: 4 >\n"
|
2017-06-27 16:43:07 +03:00
|
|
|
" field_e: OK\n"
|
|
|
|
" field_f: OK\n"
|
|
|
|
" }\n"
|
|
|
|
" field_g: OK\n"
|
2017-08-03 16:43:45 +03:00
|
|
|
">;");
|
|
|
|
|
|
|
|
verifyFormat("option (MyProto.options) = <\n"
|
2018-02-06 14:34:34 +03:00
|
|
|
" data1 < key1: value1 >\n"
|
2018-01-31 13:14:10 +03:00
|
|
|
" data2 { key2: value2 }\n"
|
2017-06-27 16:43:07 +03:00
|
|
|
">;");
|
2017-08-03 17:17:29 +03:00
|
|
|
|
|
|
|
verifyFormat("option (MyProto.options) = <\n"
|
|
|
|
" app_id: 'com.javax.swing.salsa.latino'\n"
|
|
|
|
" head_id: 1\n"
|
2018-02-06 14:34:34 +03:00
|
|
|
" data < key: value >\n"
|
2017-08-03 17:17:29 +03:00
|
|
|
">;");
|
|
|
|
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" app_id: 'com.javax.swing.salsa.latino'\n"
|
|
|
|
" head_id: 1\n"
|
|
|
|
" headheadheadheadheadhead_id: 1\n"
|
2018-01-31 13:14:10 +03:00
|
|
|
" product_data { product { 1 } }\n"
|
2017-08-03 17:17:29 +03:00
|
|
|
"};");
|
2014-01-20 20:47:22 +04:00
|
|
|
}
|
|
|
|
|
2014-04-10 11:27:12 +04:00
|
|
|
TEST_F(FormatTestProto, FormatsService) {
|
|
|
|
verifyFormat("service SearchService {\n"
|
|
|
|
" rpc Search(SearchRequest) returns (SearchResponse) {\n"
|
|
|
|
" option foo = true;\n"
|
|
|
|
" }\n"
|
|
|
|
"};");
|
|
|
|
}
|
|
|
|
|
2015-11-20 17:32:54 +03:00
|
|
|
TEST_F(FormatTestProto, ExtendingMessage) {
|
|
|
|
verifyFormat("extend .foo.Bar {\n"
|
|
|
|
"}");
|
|
|
|
}
|
|
|
|
|
2016-06-20 21:20:38 +03:00
|
|
|
TEST_F(FormatTestProto, FormatsImports) {
|
|
|
|
verifyFormat("import \"a.proto\";\n"
|
|
|
|
"import \"b.proto\";\n"
|
|
|
|
"// comment\n"
|
|
|
|
"message A {\n"
|
|
|
|
"}");
|
|
|
|
|
2016-06-20 23:39:53 +03:00
|
|
|
verifyFormat("import public \"a.proto\";\n"
|
|
|
|
"import \"b.proto\";\n"
|
|
|
|
"// comment\n"
|
|
|
|
"message A {\n"
|
|
|
|
"}");
|
|
|
|
|
2016-06-20 21:20:38 +03:00
|
|
|
// Missing semicolons should not confuse clang-format.
|
|
|
|
verifyFormat("import \"a.proto\"\n"
|
|
|
|
"import \"b.proto\"\n"
|
|
|
|
"// comment\n"
|
|
|
|
"message A {\n"
|
|
|
|
"}");
|
|
|
|
}
|
|
|
|
|
2018-02-08 13:47:12 +03:00
|
|
|
TEST_F(FormatTestProto, KeepsLongStringLiteralsOnSameLine) {
|
|
|
|
verifyFormat(
|
|
|
|
"option (MyProto.options) = {\n"
|
|
|
|
" foo: {\n"
|
|
|
|
" text: \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasaaaaaaaa\"\n"
|
|
|
|
" }\n"
|
|
|
|
"}");
|
|
|
|
}
|
|
|
|
|
2018-02-13 13:20:39 +03:00
|
|
|
TEST_F(FormatTestProto, FormatsOptionsExtensions) {
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" msg_field: { field_d: 123 }\n"
|
|
|
|
" [ext.t/u] { key: value }\n"
|
|
|
|
" key: value\n"
|
|
|
|
" [t.u/v] <\n"
|
|
|
|
" [ext] { key: value }\n"
|
|
|
|
" >\n"
|
|
|
|
"};");
|
|
|
|
}
|
|
|
|
|
2018-04-05 12:33:03 +03:00
|
|
|
TEST_F(FormatTestProto, SpacesAroundPercents) {
|
2018-02-14 22:47:58 +03:00
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" key: %lld\n"
|
2018-04-05 12:33:03 +03:00
|
|
|
" key: 0x%04x\n"
|
|
|
|
" key: \"%d %d\"\n"
|
2018-02-14 22:47:58 +03:00
|
|
|
"};");
|
|
|
|
}
|
|
|
|
|
2018-02-15 18:30:22 +03:00
|
|
|
TEST_F(FormatTestProto, FormatsRepeatedListInitializersInOptions) {
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" key: item\n"
|
|
|
|
" keys: [\n"
|
|
|
|
" 'ala',\n"
|
|
|
|
" 'bala',\n"
|
|
|
|
" 'porto',\n"
|
|
|
|
" 'kala',\n"
|
|
|
|
" 'too',\n"
|
|
|
|
" 'long',\n"
|
|
|
|
" 'long',\n"
|
|
|
|
" 'long'\n"
|
|
|
|
" ]\n"
|
|
|
|
" key: [ item ]\n"
|
|
|
|
" msg {\n"
|
|
|
|
" key: item\n"
|
|
|
|
" keys: [\n"
|
|
|
|
" 'ala',\n"
|
|
|
|
" 'bala',\n"
|
|
|
|
" 'porto',\n"
|
|
|
|
" 'kala',\n"
|
|
|
|
" 'too',\n"
|
|
|
|
" 'long',\n"
|
|
|
|
" 'long'\n"
|
|
|
|
" ]\n"
|
|
|
|
" }\n"
|
|
|
|
" key: value\n"
|
|
|
|
"};");
|
|
|
|
}
|
|
|
|
|
2018-02-27 22:07:47 +03:00
|
|
|
TEST_F(FormatTestProto, AcceptsOperatorAsKeyInOptions) {
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" bbbbbbbbb: <\n"
|
|
|
|
" ccccccccccccccccccccccc: <\n"
|
|
|
|
" operator: 1\n"
|
|
|
|
" operator: 2\n"
|
2018-05-09 12:02:11 +03:00
|
|
|
" operator: 3\n"
|
2018-02-27 22:07:47 +03:00
|
|
|
" operator { key: value }\n"
|
|
|
|
" >\n"
|
|
|
|
" >\n"
|
|
|
|
"};");
|
|
|
|
}
|
|
|
|
|
2018-06-11 15:53:25 +03:00
|
|
|
TEST_F(FormatTestProto, BreaksEntriesOfSubmessagesContainingSubmessages) {
|
|
|
|
FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
|
|
|
|
Style.ColumnLimit = 60;
|
|
|
|
// The column limit allows for the keys submessage to be put on 1 line, but we
|
|
|
|
// break it since it contains a submessage an another entry.
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" key: valueeeeeeee\n"
|
|
|
|
" keys: {\n"
|
|
|
|
" item: 'aaaaaaaaaaaaaaaa'\n"
|
|
|
|
" sub <>\n"
|
|
|
|
" }\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" key: valueeeeeeee\n"
|
|
|
|
" keys: {\n"
|
|
|
|
" item: 'aaaaaaaaaaaaaaaa'\n"
|
|
|
|
" sub {}\n"
|
|
|
|
" }\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" key: valueeeeeeee\n"
|
|
|
|
" keys: {\n"
|
|
|
|
" sub {}\n"
|
|
|
|
" sub: <>\n"
|
|
|
|
" sub: []\n"
|
|
|
|
" }\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" key: valueeeeeeee\n"
|
|
|
|
" keys: {\n"
|
|
|
|
" item: 'aaaaaaaaaaa'\n"
|
|
|
|
" sub { msg: 1 }\n"
|
|
|
|
" }\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" key: valueeeeeeee\n"
|
|
|
|
" keys: {\n"
|
|
|
|
" item: 'aaaaaaaaaaa'\n"
|
|
|
|
" sub: { msg: 1 }\n"
|
|
|
|
" }\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" key: valueeeeeeee\n"
|
|
|
|
" keys: {\n"
|
|
|
|
" item: 'aaaaaaaaaaa'\n"
|
|
|
|
" sub < msg: 1 >\n"
|
|
|
|
" }\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" key: valueeeeeeee\n"
|
|
|
|
" keys: {\n"
|
|
|
|
" item: 'aaaaaaaaaaa'\n"
|
|
|
|
" sub: [ msg: 1 ]\n"
|
|
|
|
" }\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" key: valueeeeeeee\n"
|
|
|
|
" keys: <\n"
|
|
|
|
" item: 'aaaaaaaaaaa'\n"
|
|
|
|
" sub: [ 1, 2 ]\n"
|
|
|
|
" >\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" key: valueeeeeeee\n"
|
|
|
|
" keys: {\n"
|
|
|
|
" sub {}\n"
|
|
|
|
" item: 'aaaaaaaaaaaaaaaa'\n"
|
|
|
|
" }\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" key: valueeeeeeee\n"
|
|
|
|
" keys: {\n"
|
|
|
|
" sub: []\n"
|
|
|
|
" item: 'aaaaaaaaaaaaaaaa'\n"
|
|
|
|
" }\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" key: valueeeeeeee\n"
|
|
|
|
" keys: {\n"
|
|
|
|
" sub <>\n"
|
|
|
|
" item: 'aaaaaaaaaaaaaaaa'\n"
|
|
|
|
" }\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" key: valueeeeeeee\n"
|
|
|
|
" keys: {\n"
|
|
|
|
" sub { key: value }\n"
|
|
|
|
" item: 'aaaaaaaaaaaaaaaa'\n"
|
|
|
|
" }\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" key: valueeeeeeee\n"
|
|
|
|
" keys: {\n"
|
|
|
|
" sub: [ 1, 2 ]\n"
|
|
|
|
" item: 'aaaaaaaaaaaaaaaa'\n"
|
|
|
|
" }\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" key: valueeeeeeee\n"
|
|
|
|
" keys: {\n"
|
|
|
|
" sub < sub_2: {} >\n"
|
|
|
|
" item: 'aaaaaaaaaaaaaaaa'\n"
|
|
|
|
" }\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" key: valueeeeeeee\n"
|
|
|
|
" keys: {\n"
|
|
|
|
" item: data\n"
|
|
|
|
" sub: [ 1, 2 ]\n"
|
|
|
|
" item: 'aaaaaaaaaaaaaaaa'\n"
|
|
|
|
" }\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" key: valueeeeeeee\n"
|
|
|
|
" keys: {\n"
|
|
|
|
" item: data\n"
|
|
|
|
" sub < sub_2: {} >\n"
|
|
|
|
" item: 'aaaaaaaaaaaaaaaa'\n"
|
|
|
|
" }\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" sub: {\n"
|
|
|
|
" key: valueeeeeeee\n"
|
|
|
|
" keys: {\n"
|
|
|
|
" sub: [ 1, 2 ]\n"
|
|
|
|
" item: 'aaaaaaaaaaaaaaaa'\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
"}");
|
|
|
|
}
|
|
|
|
|
2018-06-12 20:26:31 +03:00
|
|
|
TEST_F(FormatTestProto, PreventBreaksBetweenKeyAndSubmessages) {
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" submessage: {\n"
|
|
|
|
" key: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\n"
|
|
|
|
" }\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" submessage {\n"
|
|
|
|
" key: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\n"
|
|
|
|
" }\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" submessage: <\n"
|
|
|
|
" key: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\n"
|
|
|
|
" >\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" submessage <\n"
|
|
|
|
" key: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\n"
|
|
|
|
" >\n"
|
|
|
|
"}");
|
|
|
|
verifyFormat("option (MyProto.options) = {\n"
|
|
|
|
" repeatedd: [\n"
|
|
|
|
" 'eyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\n"
|
|
|
|
" ]\n"
|
|
|
|
"}");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-23 02:07:51 +03:00
|
|
|
} // end namespace tooling
|
2014-01-19 13:04:08 +04:00
|
|
|
} // end namespace clang
|