summaryrefslogtreecommitdiffstats
path: root/third_party/rust/fastrand/tests/char.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/fastrand/tests/char.rs
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/fastrand/tests/char.rs')
-rw-r--r--third_party/rust/fastrand/tests/char.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/third_party/rust/fastrand/tests/char.rs b/third_party/rust/fastrand/tests/char.rs
new file mode 100644
index 0000000000..0f48c57708
--- /dev/null
+++ b/third_party/rust/fastrand/tests/char.rs
@@ -0,0 +1,44 @@
+use std::convert::TryFrom;
+use std::ops::RangeBounds;
+
+fn test_char_coverage<R>(n: usize, range: R)
+where
+ R: Iterator<Item = char> + RangeBounds<char> + Clone,
+{
+ use std::collections::HashSet;
+
+ let all: HashSet<char> = range.clone().collect();
+ let mut covered = HashSet::new();
+ for _ in 0..n {
+ let c = fastrand::char(range.clone());
+ assert!(all.contains(&c));
+ covered.insert(c);
+ }
+ assert_eq!(covered, all);
+}
+
+#[test]
+fn test_char() {
+ // ASCII control chars.
+ let nul = 0u8 as char;
+ let soh = 1u8 as char;
+ let stx = 2u8 as char;
+ // Some undefined Hangul Jamo codepoints just before
+ // the surrogate area.
+ let last_jamo = char::try_from(0xd7ffu32).unwrap();
+ let penultimate_jamo = char::try_from(last_jamo as u32 - 1).unwrap();
+ // Private-use codepoints just after the surrogate area.
+ let first_private = char::try_from(0xe000u32).unwrap();
+ let second_private = char::try_from(first_private as u32 + 1).unwrap();
+ // Private-use codepoints at the end of Unicode space.
+ let last_private = std::char::MAX;
+ let penultimate_private = char::try_from(last_private as u32 - 1).unwrap();
+
+ test_char_coverage(100, nul..stx);
+ test_char_coverage(100, nul..=soh);
+
+ test_char_coverage(400, penultimate_jamo..second_private);
+ test_char_coverage(400, penultimate_jamo..=second_private);
+
+ test_char_coverage(100, penultimate_private..=last_private);
+}