about summary refs log tree commit diff
path: root/src/libcore/tests
diff options
context:
space:
mode:
authorMarcel Hellwig <git@cookiesoft.de>2019-02-25 07:09:16 +0100
committerMarcel Hellwig <git@cookiesoft.de>2019-02-25 07:09:16 +0100
commit36bcbc352d4b48f0f3aea35fd9ca74e856f797c9 (patch)
treebfd1a10e6d28281158933d51f8c7cb2d1b48b504 /src/libcore/tests
parent082c86175fcf72c355e6a889956fbea59e65bcdb (diff)
downloadrust-36bcbc352d4b48f0f3aea35fd9ca74e856f797c9.tar.gz
rust-36bcbc352d4b48f0f3aea35fd9ca74e856f797c9.zip
Add FromStr impl for NonZero types
Diffstat (limited to 'src/libcore/tests')
-rw-r--r--src/libcore/tests/nonzero.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libcore/tests/nonzero.rs b/src/libcore/tests/nonzero.rs
index 4532568ee0c..6e2d4588edc 100644
--- a/src/libcore/tests/nonzero.rs
+++ b/src/libcore/tests/nonzero.rs
@@ -126,3 +126,20 @@ fn test_from_signed_nonzero() {
     let num: i32 = nz.into();
     assert_eq!(num, 1i32);
 }
+
+#[test]
+fn test_from_str() {
+    assert_eq!(FromStr::from_str("123"), Ok(NonZeroU8::new(123).unwrap()));
+    assert_eq!(
+        FromStr::from_str("0"),
+        Err(ParseNonZeroIntError {
+            kind: NonZeroIntErrorKind::Zero
+        })
+    );
+    assert_eq!(
+        FromStr::from_str("-1", 
+        Err(ParseNonZeroIntError {
+            kind: NonZeroIntErrorKind::Underflow
+        })
+    );
+}