Skip to content

Commit

Permalink
Add double.finite and float.finite (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfus authored Jul 20, 2023
1 parent e7350f1 commit 1a1a608
Show file tree
Hide file tree
Showing 6 changed files with 3,796 additions and 3,551 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ message FloatExGTELTE {
gte: 256
}];
}
message FloatFinite {
float val = 1 [(buf.validate.field).float.finite = true];
}
message FloatIgnore {
float val = 1 [
(buf.validate.field).float = {
Expand Down Expand Up @@ -142,6 +145,9 @@ message DoubleExGTELTE {
gte: 256
}];
}
message DoubleFinite {
double val = 1 [(buf.validate.field).double.finite = true];
}
message DoubleIgnore {
double val = 1 [
(buf.validate.field).double = {
Expand Down
14 changes: 14 additions & 0 deletions proto/protovalidate/buf/validate/validate.proto
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,13 @@ message FloatRules {
id: "float.not_in",
expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''",
}];

//`finite` requires the field value to be finite. If the field value is
// infinite or NaN, an error message is generated.
bool finite = 8 [(priv.field).cel = {
id: "float.finite",
expression: "this == 1.0/0.0 || this == -1.0/0.0 || string(this) == 'NaN' ? 'value must be finite' : ''",
}];
}

// DoubleRules describes the constraints applied to `double` values. These
Expand Down Expand Up @@ -556,6 +563,13 @@ message DoubleRules {
id: "double.not_in",
expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''",
}];

//`finite` requires the field value to be finite. If the field value is
// infinite or NaN, an error message is generated.
bool finite = 8 [(priv.field).cel = {
id: "float.finite",
expression: "this == 1.0/0.0 || this == -1.0/0.0 || string(this) == 'NaN' ? 'value must be finite' : ''",
}];
}

// Int32Rules describes the constraints applied to `int32` values. These
Expand Down
Loading

0 comments on commit 1a1a608

Please sign in to comment.