diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-02-17 15:33:05 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-02-18 22:36:34 +0100 |
commit | 38d0c270063c9d7379b45b80b20b179a713edc6e (patch) | |
tree | 77260670f21cc95564d914649dbdc1c3d7e3bea0 /src/test/test-percent-util.c | |
parent | ed5033fd6c5e73a1ee874608338cbfd28b9083b4 (diff) | |
download | systemd-38d0c270063c9d7379b45b80b20b179a713edc6e.tar.gz |
percent-util: when parsing permyriads, permit percents too with 1 place after the dot
Previously, when parsing myriads, we'd support:
x% → percent, no places after the dot
x.yz% → percent, two places after the dot
x‰ → permille, no places after the dot
x.y‰ → permille, one place after the dot
x‱ → permyriad, no places after the dot
What's missing is:
x.y% → percent, one place after the dot
Let's add it in.
Diffstat (limited to 'src/test/test-percent-util.c')
-rw-r--r-- | src/test/test-percent-util.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/test/test-percent-util.c b/src/test/test-percent-util.c index 9d0ad90de1..75f8a6c83d 100644 --- a/src/test/test-percent-util.c +++ b/src/test/test-percent-util.c @@ -7,6 +7,7 @@ static void test_parse_percent(void) { assert_se(parse_percent("") == -EINVAL); assert_se(parse_percent("foo") == -EINVAL); assert_se(parse_percent("0") == -EINVAL); + assert_se(parse_percent("0.1") == -EINVAL); assert_se(parse_percent("50") == -EINVAL); assert_se(parse_percent("100") == -EINVAL); assert_se(parse_percent("-1") == -EINVAL); @@ -34,6 +35,10 @@ static void test_parse_permille(void) { assert_se(parse_permille("50") == -EINVAL); assert_se(parse_permille("100") == -EINVAL); assert_se(parse_permille("-1") == -EINVAL); + assert_se(parse_permille("0.1") == -EINVAL); + assert_se(parse_permille("5%") == 50); + assert_se(parse_permille("5.5%") == 55); + assert_se(parse_permille("5.12%") == -EINVAL); assert_se(parse_permille("0‰") == 0); assert_se(parse_permille("555‰") == 555); @@ -45,6 +50,7 @@ static void test_parse_permille(void) { assert_se(parse_permille("‰1") == -EINVAL); assert_se(parse_permille("1‰‰") == -EINVAL); assert_se(parse_permille("3.2‰") == -EINVAL); + assert_se(parse_permille("0.1‰") == -EINVAL); assert_se(parse_permille("0%") == 0); assert_se(parse_permille("55%") == 550); @@ -57,6 +63,7 @@ static void test_parse_permille(void) { assert_se(parse_permille("%1") == -EINVAL); assert_se(parse_permille("1%%") == -EINVAL); assert_se(parse_permille("3.21%") == -EINVAL); + assert_se(parse_permille("0.1%") == 1); } static void test_parse_permille_unbounded(void) { @@ -107,6 +114,8 @@ static void test_parse_permyriad(void) { assert_se(parse_permyriad("0%") == 0); assert_se(parse_permyriad("55%") == 5500); + assert_se(parse_permyriad("55.5%") == 5550); + assert_se(parse_permyriad("55.50%") == 5550); assert_se(parse_permyriad("55.53%") == 5553); assert_se(parse_permyriad("100%") == 10000); assert_se(parse_permyriad("-7%") == -ERANGE); |