Skip to content

Commit

Permalink
Add conformance tests for ignore_empty
Browse files Browse the repository at this point in the history
  • Loading branch information
rodaine committed Nov 3, 2023
1 parent fa528d8 commit 66315f1
Show file tree
Hide file tree
Showing 7 changed files with 1,818 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ proto_library(
"bytes.proto",
"enums.proto",
"filename-with-dash.proto",
"ignore_empty_proto2.proto",
"ignore_empty_proto3.proto",
"kitchen_sink.proto",
"maps.proto",
"messages.proto",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright 2023 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto2";

package buf.validate.conformance.cases;

import "buf/validate/validate.proto";

// all fields in this message should not be impacted by ignore_empty
message IgnoreEmptyProto2Noop {
optional Msg msg = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).cel = {
id: "ignore_empty.proto2.message",
message: "val must be foo",
expression: "this.val == 'foo'",
}
];
oneof o {
int32 a = 2 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).int32.gt = 0
];
}
optional string str = 3 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).string.min_len = 5
];
message Msg {
optional string val = 1;
}
}

message IgnoreEmptyProto2ScalarOptional {
optional int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).int32.gt = 0
];
}

message IgnoreEmptyProto2ScalarOptionalWithDefault {
optional int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).int32.gt = 0,
default = 42
];
}

message IgnoreEmptyProto2ScalarRequired {
required int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).int32.gt = 0
];
}

message IgnoreEmptyProto2Message {
optional Msg val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).cel = {
id: "ignore_empty.proto2.message",
message: "foobar",
expression: "this.val == 'foo'",
}
];
message Msg {
optional string val = 1;
}
}

message IgnoreEmptyProto2Oneof {
oneof o {
int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).int32.gt = 0
];
}
}

message IgnoreEmptyProto2Repeated {
repeated int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).repeated.min_items = 3
];
}

message IgnoreEmptyProto2Map {
map<int32, int32> val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).map.min_pairs = 3
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2023 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package buf.validate.conformance.cases;

import "buf/validate/validate.proto";

message IgnoreEmptyProto3Scalar {
int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).int32.gt = 0
];
}

message IgnoreEmptyProto3OptionalScalar {
optional int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).int32.gt = 0
];
}

message IgnoreEmptyProto3Message {
optional Msg val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).cel = {
id: "ignore_empty.proto3.message",
message: "foobar",
expression: "this.val == 'foo'",
}
];
message Msg {
string val = 1;
}
}

message IgnoreEmptyProto3Oneof {
oneof o {
int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).int32.gt = 0
];
}
}

message IgnoreEmptyProto3Repeated {
repeated int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).repeated.min_items = 3
];
}

message IgnoreEmptyProto3Map {
map<int32, int32> val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).map.min_pairs = 3
];
}
Loading

0 comments on commit 66315f1

Please sign in to comment.