about summary refs log tree commit diff
path: root/src/libcoretest/num
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-08-17 13:23:36 -0700
committerAlex Crichton <alex@alexcrichton.com>2015-08-17 14:03:32 -0700
commit8cb4d8671afecdcfd2432e08c8f43673ce51f67d (patch)
treec42f8eb09400c6b9d5004d22155299eb0be03410 /src/libcoretest/num
parent47ea0cfb6bd250c970e3a61d62bfa1b1c7bb27d4 (diff)
downloadrust-8cb4d8671afecdcfd2432e08c8f43673ce51f67d.tar.gz
rust-8cb4d8671afecdcfd2432e08c8f43673ce51f67d.zip
std: Clean up primitive integer modules
All of the modules in the standard library were just straight reexports of those
in libcore, so remove all the "macro modules" from the standard library and just
reexport what's in core directly.
Diffstat (limited to 'src/libcoretest/num')
-rw-r--r--src/libcoretest/num/uint_macros.rs32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/libcoretest/num/uint_macros.rs b/src/libcoretest/num/uint_macros.rs
index 1712345f9d9..6238c6d43e3 100644
--- a/src/libcoretest/num/uint_macros.rs
+++ b/src/libcoretest/num/uint_macros.rs
@@ -14,6 +14,7 @@ mod tests {
     use core::$T_i::*;
     use num;
     use core::ops::{BitOr, BitAnd, BitXor, Shl, Shr, Not};
+    use std::str;
 
     #[test]
     fn test_overflows() {
@@ -121,6 +122,35 @@ mod tests {
         assert!((10 as $T).checked_div(2) == Some(5));
         assert!((5 as $T).checked_div(0) == None);
     }
-}
+
+    fn from_str<T: FromStr>(t: &str) -> Option<T> {
+        FromStr::from_str(t).ok()
+    }
+
+    #[test]
+    pub fn test_from_str() {
+        assert_eq!(from_str::<$T>("0"), Some(0 as $T));
+        assert_eq!(from_str::<$T>("3"), Some(3 as $T));
+        assert_eq!(from_str::<$T>("10"), Some(10 as $T));
+        assert_eq!(from_str::<u32>("123456789"), Some(123456789 as u32));
+        assert_eq!(from_str::<$T>("00100"), Some(100 as $T));
+
+        assert_eq!(from_str::<$T>(""), None);
+        assert_eq!(from_str::<$T>(" "), None);
+        assert_eq!(from_str::<$T>("x"), None);
+    }
+
+    #[test]
+    pub fn test_parse_bytes() {
+        assert_eq!($T::from_str_radix("123", 10), Ok(123 as $T));
+        assert_eq!($T::from_str_radix("1001", 2), Ok(9 as $T));
+        assert_eq!($T::from_str_radix("123", 8), Ok(83 as $T));
+        assert_eq!(u16::from_str_radix("123", 16), Ok(291 as u16));
+        assert_eq!(u16::from_str_radix("ffff", 16), Ok(65535 as u16));
+        assert_eq!($T::from_str_radix("z", 36), Ok(35 as $T));
+
+        assert_eq!($T::from_str_radix("Z", 10).ok(), None::<$T>);
+        assert_eq!($T::from_str_radix("_", 2).ok(), None::<$T>);
+    }
 
 )}