Skip to content

Commit

Permalink
Fixup ignore_empty oneof tests + add tests for repeated items and map…
Browse files Browse the repository at this point in the history
… keys/values (#128)

Oneof tests were redundant (and contradictory to the behavior we're
going for), so removed them in favor of the more exhaustive ones in the
ignore_empty suite. Likewise, added tests to ensure the behavior of
ignore_empty as applied to repeated items and map keys/values is
consistent as well.

Relates to #115
  • Loading branch information
rodaine authored Nov 6, 2023
1 parent ddf3fb4 commit 5e6e4fb
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,23 @@ message IgnoreEmptyProto3Map {
(buf.validate.field).map.min_pairs = 3
];
}

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

message IgnoreEmptyMapPairs {
map<string, int32> val = 1 [
(buf.validate.field).map.keys = {
ignore_empty: true,
string: {min_len: 3},
},
(buf.validate.field).map.values = {
ignore_empty: true,
int32: {gt: 0},
}
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,3 @@ message OneofRequiredWithRequiredField {
string b = 2;
}
}

message OneofIgnoreEmpty {
oneof o {
string x = 1 [
(buf.validate.field).string = {
min_len: 3,
max_len: 5
},
(buf.validate.field).ignore_empty = true
];
bytes y = 2 [
(buf.validate.field).bytes = {
min_len: 3,
max_len: 5
},
(buf.validate.field).ignore_empty = true
];
int32 z = 3 [
(buf.validate.field).int32 = {
gte: 128,
lte: 256,
},
(buf.validate.field).ignore_empty = true
];
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5e6e4fb

Please sign in to comment.