about summary refs log tree commit diff
path: root/library/core/tests/ascii.rs
diff options
context:
space:
mode:
authorChristiaan Dirkx <christiaan@dirkx.email>2020-11-22 09:08:04 +0100
committerChristiaan Dirkx <christiaan@dirkx.email>2020-11-30 02:47:32 +0100
commitbe554c4101df2a9ac65d40962ee37ece85d517bf (patch)
treede404d29144c6db9c24e81a2f6f8cb8d545abbe9 /library/core/tests/ascii.rs
parent349b3b324dade7ca638091db93ba08bbc443c63d (diff)
downloadrust-be554c4101df2a9ac65d40962ee37ece85d517bf.tar.gz
rust-be554c4101df2a9ac65d40962ee37ece85d517bf.zip
Make ui test that are run-pass and do not test the compiler itself library tests
Diffstat (limited to 'library/core/tests/ascii.rs')
-rw-r--r--library/core/tests/ascii.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/library/core/tests/ascii.rs b/library/core/tests/ascii.rs
index 3244bbc2d67..66c25e449df 100644
--- a/library/core/tests/ascii.rs
+++ b/library/core/tests/ascii.rs
@@ -408,3 +408,56 @@ fn ascii_const() {
     const BYTE_IS_ASCII: bool = 97u8.is_ascii();
     assert!(BYTE_IS_ASCII);
 }
+
+#[test]
+fn ascii_ctype_const() {
+    macro_rules! suite {
+        ( $( $fn:ident => [$a:ident, $A:ident, $nine:ident, $dot:ident, $space:ident]; )* ) => {
+            $(
+                mod $fn {
+                    const CHAR_A_LOWER: bool = 'a'.$fn();
+                    const CHAR_A_UPPER: bool = 'A'.$fn();
+                    const CHAR_NINE: bool = '9'.$fn();
+                    const CHAR_DOT: bool = '.'.$fn();
+                    const CHAR_SPACE: bool = ' '.$fn();
+
+                    const U8_A_LOWER: bool = b'a'.$fn();
+                    const U8_A_UPPER: bool = b'A'.$fn();
+                    const U8_NINE: bool = b'9'.$fn();
+                    const U8_DOT: bool = b'.'.$fn();
+                    const U8_SPACE: bool = b' '.$fn();
+
+                    pub fn run() {
+                        assert_eq!(CHAR_A_LOWER, $a);
+                        assert_eq!(CHAR_A_UPPER, $A);
+                        assert_eq!(CHAR_NINE, $nine);
+                        assert_eq!(CHAR_DOT, $dot);
+                        assert_eq!(CHAR_SPACE, $space);
+
+                        assert_eq!(U8_A_LOWER, $a);
+                        assert_eq!(U8_A_UPPER, $A);
+                        assert_eq!(U8_NINE, $nine);
+                        assert_eq!(U8_DOT, $dot);
+                        assert_eq!(U8_SPACE, $space);
+                    }
+                }
+            )*
+
+            $( $fn::run(); )*
+        }
+    }
+
+    suite! {
+        //                        'a'    'A'    '9'    '.'    ' '
+        is_ascii_alphabetic   => [true,  true,  false, false, false];
+        is_ascii_uppercase    => [false, true,  false, false, false];
+        is_ascii_lowercase    => [true,  false, false, false, false];
+        is_ascii_alphanumeric => [true,  true,  true,  false, false];
+        is_ascii_digit        => [false, false, true,  false, false];
+        is_ascii_hexdigit     => [true,  true,  true,  false, false];
+        is_ascii_punctuation  => [false, false, false, true,  false];
+        is_ascii_graphic      => [true,  true,  true,  true,  false];
+        is_ascii_whitespace   => [false, false, false, false, true];
+        is_ascii_control      => [false, false, false, false, false];
+    }
+}