forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This function works on all base decimal and binary SI units of the set: m, K/Ki, M/Mi, G/Gi, T/Ti, P/Pi, and E/Ei Note: Unlike `units.parse_bytes`, this function is case sensitive. Fixes open-policy-agent#1802. Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
- Loading branch information
1 parent
e0b9c12
commit b5d5c86
Showing
8 changed files
with
771 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
test/cases/testdata/units/test-parse-units-comparisons.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
cases: | ||
- data: | ||
modules: | ||
- | | ||
package test | ||
p { | ||
units.parse("8k") > units.parse("7k") | ||
} | ||
note: parse/comparison | ||
query: data.test.p = x | ||
want_result: | ||
- x: true | ||
- data: | ||
modules: | ||
- | | ||
package test | ||
p { | ||
units.parse("8g") > units.parse("8m") | ||
} | ||
note: parse/comparison | ||
query: data.test.p = x | ||
want_result: | ||
- x: true | ||
- data: | ||
modules: | ||
- | | ||
package test | ||
p { | ||
units.parse("1234k") < units.parse("1g") | ||
} | ||
note: parse/comparison | ||
query: data.test.p = x | ||
want_result: | ||
- x: true | ||
- data: | ||
modules: | ||
- | | ||
package test | ||
p { | ||
units.parse("1024") == units.parse("1Ki") | ||
} | ||
note: parse/comparison | ||
query: data.test.p = x | ||
want_result: | ||
- x: true | ||
- data: | ||
modules: | ||
- | | ||
package test | ||
p { | ||
units.parse("2Mi") == units.parse("2097152") | ||
} | ||
note: parse/comparison | ||
query: data.test.p = x | ||
want_result: | ||
- x: true | ||
- data: | ||
modules: | ||
- | | ||
package test | ||
p { | ||
units.parse("3Mi") > units.parse("3M") | ||
} | ||
note: parse/comparison | ||
query: data.test.p = x | ||
want_result: | ||
- x: true | ||
- data: | ||
modules: | ||
- | | ||
package test | ||
p { | ||
units.parse("2Mi") == units.parse("2Mi") | ||
} | ||
note: parse/comparison | ||
query: data.test.p = x | ||
want_result: | ||
- x: true | ||
- data: | ||
modules: | ||
- | | ||
package test | ||
p { | ||
units.parse("4Mi") > units.parse("4M") | ||
} | ||
note: parse/comparison | ||
query: data.test.p = x | ||
want_result: | ||
- x: true | ||
- data: | ||
modules: | ||
- | | ||
package test | ||
p { | ||
units.parse("4.1Mi") > units.parse("4Mi") | ||
} | ||
note: parse/comparison | ||
query: data.test.p = x | ||
want_result: | ||
- x: true | ||
- data: | ||
modules: | ||
- | | ||
package test | ||
p { | ||
units.parse("128Gi") == units.parse("137438953472") | ||
} | ||
note: parse/comparison | ||
query: data.test.p = x | ||
want_result: | ||
- x: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
cases: | ||
- data: | ||
modules: | ||
- | | ||
package test | ||
p { | ||
units.parse("") | ||
} | ||
note: parse/failure | ||
query: data.test.p = x | ||
want_error: "units.parse error: no amount provided" | ||
strict_error: true | ||
- data: | ||
modules: | ||
- | | ||
package test | ||
p { | ||
units.parse("G") | ||
} | ||
note: parse/failure | ||
query: data.test.p = x | ||
want_error: "units.parse error: no amount provided" | ||
strict_error: true | ||
- data: | ||
modules: | ||
- | | ||
package test | ||
p { | ||
units.parse("foo") | ||
} | ||
note: parse/failure | ||
query: data.test.p = x | ||
want_error: "units.parse error: no amount provided" | ||
strict_error: true | ||
- data: | ||
modules: | ||
- | | ||
package test | ||
p { | ||
units.parse("0.0.0") | ||
} | ||
note: parse/failure | ||
query: data.test.p = x | ||
want_error: "units.parse error: could not parse amount to a number" | ||
strict_error: true | ||
- data: | ||
modules: | ||
- | | ||
package test | ||
p { | ||
units.parse(".5.2") | ||
} | ||
note: parse/failure | ||
query: data.test.p = x | ||
want_error: "units.parse error: could not parse amount to a number" | ||
strict_error: true | ||
- data: | ||
modules: | ||
- | | ||
package test | ||
p { | ||
units.parse("100 k") | ||
} | ||
note: parse/failure | ||
query: data.test.p = x | ||
want_error: "units.parse error: spaces not allowed in resource strings" | ||
strict_error: true | ||
- data: | ||
modules: | ||
- | | ||
package test | ||
p { | ||
units.parse(" 327Mi ") | ||
} | ||
note: parse/failure | ||
query: data.test.p = x | ||
want_error: "units.parse error: spaces not allowed in resource strings" | ||
strict_error: true |
Oops, something went wrong.