changeset 46642:1b7c0b10d930

rust: Add some unit tests for parse_byte_size in config Differential Revision: https://phab.mercurial-scm.org/D10022
author Simon Sapin <simon.sapin@octobus.net>
date Wed, 17 Feb 2021 20:40:19 +0100
parents a687a7f27951
children ad107ed7a4aa
files rust/hg-core/src/config/values.rs
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/config/values.rs	Wed Feb 17 20:24:04 2021 +0100
+++ b/rust/hg-core/src/config/values.rs	Wed Feb 17 20:40:19 2021 +0100
@@ -41,3 +41,21 @@
     }
     value.parse().ok()
 }
+
+#[test]
+fn test_parse_byte_size() {
+    assert_eq!(parse_byte_size(b""), None);
+    assert_eq!(parse_byte_size(b"b"), None);
+
+    assert_eq!(parse_byte_size(b"12"), Some(12));
+    assert_eq!(parse_byte_size(b"12b"), Some(12));
+    assert_eq!(parse_byte_size(b"12 b"), Some(12));
+    assert_eq!(parse_byte_size(b"12.1 b"), Some(12));
+    assert_eq!(parse_byte_size(b"1.1 K"), Some(1126));
+    assert_eq!(parse_byte_size(b"1.1 kB"), Some(1126));
+
+    assert_eq!(parse_byte_size(b"-12 b"), None);
+    assert_eq!(parse_byte_size(b"-0.1 b"), None);
+    assert_eq!(parse_byte_size(b"0.1 b"), Some(0));
+    assert_eq!(parse_byte_size(b"12.1 b"), Some(12));
+}