Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more predefined rules conformance tests around repeated fields #258

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package buf.validate.conformance.cases;
import "buf/validate/validate.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";

extend buf.validate.FloatRules {
optional float float_abs_range_proto2 = 1161 [(buf.validate.predefined).cel = {
Expand All @@ -37,18 +38,18 @@ extend buf.validate.DoubleRules {
}

extend buf.validate.Int32Rules {
optional bool int32_even_proto2 = 1161 [(buf.validate.predefined).cel = {
id: "int32.even.proto2"
expression: "this % 2 == 0"
message: "int32 value is not even"
repeated int32 int32_abs_in_proto2 = 1161 [(buf.validate.predefined).cel = {
id: "int32.abs_in.proto2"
expression: "this in rule || this in rule.map(n, -n)"
message: "value must be in absolute value of list"
}];
}

extend buf.validate.Int64Rules {
optional bool int64_even_proto2 = 1161 [(buf.validate.predefined).cel = {
id: "int64.even.proto2"
expression: "this % 2 == 0"
message: "int64 value is not even"
repeated google.protobuf.Int64Value int64_abs_in_proto2 = 1161 [(buf.validate.predefined).cel = {
id: "int64.abs_in.proto2"
expression: "this in rule || this in rule.map(n, -n)"
message: "value must be in absolute value of list"
}];
}

Expand Down Expand Up @@ -179,11 +180,11 @@ message PredefinedDoubleRuleProto2 {
}

message PredefinedInt32RuleProto2 {
optional int32 val = 1 [(buf.validate.field).int32.(int32_even_proto2) = true];
optional int32 val = 1 [(buf.validate.field).int32.(int32_abs_in_proto2) = -2];
}

message PredefinedInt64RuleProto2 {
optional int64 val = 1 [(buf.validate.field).int64.(int64_even_proto2) = true];
optional int64 val = 1 [(buf.validate.field).int64.(int64_abs_in_proto2) = {value: -2}];
}

message PredefinedUInt32RuleProto2 {
Expand Down Expand Up @@ -250,13 +251,85 @@ message PredefinedTimestampRuleProto2 {
optional google.protobuf.Timestamp val = 1 [(buf.validate.field).timestamp.(timestamp_in_range_proto2) = true];
}

message PredefinedWrappedFloatRuleProto2 {
optional google.protobuf.FloatValue val = 1 [(buf.validate.field).float.(float_abs_range_proto2) = 1.0];
}

message PredefinedWrappedDoubleRuleProto2 {
optional google.protobuf.DoubleValue val = 1 [(buf.validate.field).double.(double_abs_range_proto2) = 1.0];
}

message PredefinedWrappedInt32RuleProto2 {
optional google.protobuf.Int32Value val = 1 [(buf.validate.field).int32.(int32_abs_in_proto2) = -2];
}

message PredefinedWrappedInt64RuleProto2 {
optional google.protobuf.Int64Value val = 1 [(buf.validate.field).int64.(int64_abs_in_proto2) = {value: -2}];
}

message PredefinedWrappedUInt32RuleProto2 {
optional google.protobuf.UInt32Value val = 1 [(buf.validate.field).uint32.(uint32_even_proto2) = true];
}

message PredefinedWrappedUInt64RuleProto2 {
optional google.protobuf.UInt64Value val = 1 [(buf.validate.field).uint64.(uint64_even_proto2) = true];
}

message PredefinedWrappedBoolRuleProto2 {
optional google.protobuf.BoolValue val = 1 [(buf.validate.field).bool.(bool_false_proto2) = true];
}

message PredefinedWrappedStringRuleProto2 {
optional google.protobuf.StringValue val = 1 [(buf.validate.field).string.(string_valid_path_proto2) = true];
}

message PredefinedWrappedBytesRuleProto2 {
optional google.protobuf.BytesValue val = 1 [(buf.validate.field).bytes.(bytes_valid_path_proto2) = true];
}

message PredefinedRepeatedWrappedFloatRuleProto2 {
repeated google.protobuf.FloatValue val = 1 [(buf.validate.field).repeated.items.float.(float_abs_range_proto2) = 1.0];
}

message PredefinedRepeatedWrappedDoubleRuleProto2 {
repeated google.protobuf.DoubleValue val = 1 [(buf.validate.field).repeated.items.double.(double_abs_range_proto2) = 1.0];
}

message PredefinedRepeatedWrappedInt32RuleProto2 {
repeated google.protobuf.Int32Value val = 1 [(buf.validate.field).repeated.items.int32.(int32_abs_in_proto2) = -2];
}

message PredefinedRepeatedWrappedInt64RuleProto2 {
repeated google.protobuf.Int64Value val = 1 [(buf.validate.field).repeated.items.int64.(int64_abs_in_proto2) = {value: -2}];
}

message PredefinedRepeatedWrappedUInt32RuleProto2 {
repeated google.protobuf.UInt32Value val = 1 [(buf.validate.field).repeated.items.uint32.(uint32_even_proto2) = true];
}

message PredefinedRepeatedWrappedUInt64RuleProto2 {
repeated google.protobuf.UInt64Value val = 1 [(buf.validate.field).repeated.items.uint64.(uint64_even_proto2) = true];
}

message PredefinedRepeatedWrappedBoolRuleProto2 {
repeated google.protobuf.BoolValue val = 1 [(buf.validate.field).repeated.items.bool.(bool_false_proto2) = true];
}

message PredefinedRepeatedWrappedStringRuleProto2 {
repeated google.protobuf.StringValue val = 1 [(buf.validate.field).repeated.items.string.(string_valid_path_proto2) = true];
}

message PredefinedRepeatedWrappedBytesRuleProto2 {
repeated google.protobuf.BytesValue val = 1 [(buf.validate.field).repeated.items.bytes.(bytes_valid_path_proto2) = true];
}

message PredefinedAndCustomRuleProto2 {
optional int32 a = 1 [
optional sint32 a = 1 [
(field).cel = {
id: "predefined_and_custom_rule_scalar_proto2"
expression: "this > 24 ? '' : 'a must be greater than 24'"
},
(field).int32.(int32_even_proto2) = true
(field).sint32.(sint32_even_proto2) = true
];

optional Nested b = 2 [(field).cel = {
Expand All @@ -266,20 +339,20 @@ message PredefinedAndCustomRuleProto2 {
}];

message Nested {
optional int32 c = 1 [
optional sint32 c = 1 [
(field).cel = {
id: "predefined_and_custom_rule_nested_proto2"
expression: "this > 0 ? '' : 'c must be positive'"
},
(field).int32.(int32_even_proto2) = true
(field).sint32.(sint32_even_proto2) = true
];
}
}

message StandardPredefinedAndCustomRuleProto2 {
optional int32 a = 1 [
(field).int32.lt = 28,
(field).int32.(int32_even_proto2) = true,
optional sint32 a = 1 [
(field).sint32.lt = 28,
(field).sint32.(sint32_even_proto2) = true,
(field).cel = {
id: "standard_predefined_and_custom_rule_scalar_proto2"
expression: "this > 24 ? '' : 'a must be greater than 24'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import "buf/validate/conformance/cases/predefined_rules_proto_editions.proto";
import "buf/validate/validate.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";

message PredefinedFloatRuleProto3 {
float val = 1 [(buf.validate.field).float.(float_abs_range_proto2) = 1.0];
Expand All @@ -31,11 +32,11 @@ message PredefinedDoubleRuleProto3 {
}

message PredefinedInt32RuleProto3 {
int32 val = 1 [(buf.validate.field).int32.(int32_even_proto2) = true];
int32 val = 1 [(buf.validate.field).int32.(int32_abs_in_proto2) = -2];
}

message PredefinedInt64RuleProto3 {
int64 val = 1 [(buf.validate.field).int64.(int64_even_proto2) = true];
int64 val = 1 [(buf.validate.field).int64.(int64_abs_in_edition_2023) = {value: -2}];
}

message PredefinedUInt32RuleProto3 {
Expand Down Expand Up @@ -106,13 +107,85 @@ message PredefinedTimestampRuleProto3 {
google.protobuf.Timestamp val = 1 [(buf.validate.field).timestamp.(timestamp_in_range_proto2) = true];
}

message PredefinedWrappedFloatRuleProto3 {
google.protobuf.FloatValue val = 1 [(buf.validate.field).float.(float_abs_range_proto2) = 1.0];
}

message PredefinedWrappedDoubleRuleProto3 {
google.protobuf.DoubleValue val = 1 [(buf.validate.field).double.(double_abs_range_proto2) = 1.0];
}

message PredefinedWrappedInt32RuleProto3 {
google.protobuf.Int32Value val = 1 [(buf.validate.field).int32.(int32_abs_in_proto2) = -2];
}

message PredefinedWrappedInt64RuleProto3 {
google.protobuf.Int64Value val = 1 [(buf.validate.field).int64.(int64_abs_in_proto2) = {value: -2}];
}

message PredefinedWrappedUInt32RuleProto3 {
google.protobuf.UInt32Value val = 1 [(buf.validate.field).uint32.(uint32_even_proto2) = true];
}

message PredefinedWrappedUInt64RuleProto3 {
google.protobuf.UInt64Value val = 1 [(buf.validate.field).uint64.(uint64_even_proto2) = true];
}

message PredefinedWrappedBoolRuleProto3 {
google.protobuf.BoolValue val = 1 [(buf.validate.field).bool.(bool_false_proto2) = true];
}

message PredefinedWrappedStringRuleProto3 {
google.protobuf.StringValue val = 1 [(buf.validate.field).string.(string_valid_path_proto2) = true];
}

message PredefinedWrappedBytesRuleProto3 {
google.protobuf.BytesValue val = 1 [(buf.validate.field).bytes.(bytes_valid_path_proto2) = true];
}

message PredefinedRepeatedWrappedFloatRuleProto3 {
repeated google.protobuf.FloatValue val = 1 [(buf.validate.field).repeated.items.float.(float_abs_range_proto2) = 1.0];
}

message PredefinedRepeatedWrappedDoubleRuleProto3 {
repeated google.protobuf.DoubleValue val = 1 [(buf.validate.field).repeated.items.double.(double_abs_range_proto2) = 1.0];
}

message PredefinedRepeatedWrappedInt32RuleProto3 {
repeated google.protobuf.Int32Value val = 1 [(buf.validate.field).repeated.items.int32.(int32_abs_in_proto2) = -2];
}

message PredefinedRepeatedWrappedInt64RuleProto3 {
repeated google.protobuf.Int64Value val = 1 [(buf.validate.field).repeated.items.int64.(int64_abs_in_proto2) = {value: -2}];
}

message PredefinedRepeatedWrappedUInt32RuleProto3 {
repeated google.protobuf.UInt32Value val = 1 [(buf.validate.field).repeated.items.uint32.(uint32_even_proto2) = true];
}

message PredefinedRepeatedWrappedUInt64RuleProto3 {
repeated google.protobuf.UInt64Value val = 1 [(buf.validate.field).repeated.items.uint64.(uint64_even_proto2) = true];
}

message PredefinedRepeatedWrappedBoolRuleProto3 {
repeated google.protobuf.BoolValue val = 1 [(buf.validate.field).repeated.items.bool.(bool_false_proto2) = true];
}

message PredefinedRepeatedWrappedStringRuleProto3 {
repeated google.protobuf.StringValue val = 1 [(buf.validate.field).repeated.items.string.(string_valid_path_proto2) = true];
}

message PredefinedRepeatedWrappedBytesRuleProto3 {
repeated google.protobuf.BytesValue val = 1 [(buf.validate.field).repeated.items.bytes.(bytes_valid_path_proto2) = true];
}

message PredefinedAndCustomRuleProto3 {
int32 a = 1 [
sint32 a = 1 [
(field).cel = {
id: "predefined_and_custom_rule_scalar_proto3"
expression: "this > 24 ? '' : 'a must be greater than 24'"
},
(field).int32.(int32_even_edition_2023) = true
(field).sint32.(sint32_even_edition_2023) = true
];

optional Nested b = 2 [(field).cel = {
Expand All @@ -122,20 +195,20 @@ message PredefinedAndCustomRuleProto3 {
}];

message Nested {
int32 c = 1 [
sint32 c = 1 [
(field).cel = {
id: "predefined_and_custom_rule_nested_proto3"
expression: "this > 0 ? '' : 'c must be positive'"
},
(field).int32.(int32_even_edition_2023) = true
(field).sint32.(sint32_even_edition_2023) = true
];
}
}

message StandardPredefinedAndCustomRuleProto3 {
int32 a = 1 [
(field).int32.lt = 28,
(field).int32.(int32_even_proto2) = true,
sint32 a = 1 [
(field).sint32.lt = 28,
(field).sint32.(sint32_even_proto2) = true,
(field).cel = {
id: "standard_predefined_and_custom_rule_scalar_proto3"
expression: "this > 24 ? '' : 'a must be greater than 24'"
Expand Down
Loading