1 // Copyright 2017 The UNIC Project Developers.
3 // See the COPYRIGHT file at the top-level directory of this distribution.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use std
::{char, u32, vec}
;
13 use unic_char_range
::CharRange
;
15 fn all_chars() -> vec
::IntoIter
<char> {
17 .take_while(|&u
| u
<= char::MAX
as u32)
18 .filter_map(char::from_u32
)
24 fn test_iter_all_chars() {
25 assert
!(CharRange
::all().iter().eq(all_chars()))
29 fn test_iter_all_chars_rev() {
30 assert
!(CharRange
::all().iter().rev().eq(all_chars().rev()))
34 fn test_iter_all_chars_mixed_next_back() {
35 let mut custom
= CharRange
::all().iter();
36 let mut simple
= all_chars();
37 while let Some(custom_char
) = custom
.next() {
38 assert_eq
!(Some(custom_char
), simple
.next());
39 assert_eq
!(custom
.next_back(), simple
.next_back());
41 assert_eq
!(None
, simple
.next());
45 fn test_iter_all_chars_into_iter() {
46 for _ch
in CharRange
::all() {
52 fn test_iter_fused() {
53 let mut iter
= CharRange
::all().iter();
54 let mut fused
= all_chars().fuse();
55 assert
!(iter
.by_ref().eq(fused
.by_ref()));
57 assert_eq
!(iter
.next(), fused
.next());
62 fn test_iter_exact_trusted_len() {
63 fn assert_presents_right_len
<I
: ExactSizeIterator
>(iter
: &I
, len
: usize) {
64 assert_eq
!(iter
.len(), len
);
65 assert_eq
!(iter
.size_hint(), (len
, Some(len
)));
68 let mut iter
= CharRange
::all().iter();
69 let mut predicted_length
= iter
.len();
70 assert_eq
!(predicted_length
, all_chars().len());
72 while let Some(_
) = iter
.next() {
73 predicted_length
-= 1;
74 assert_presents_right_len(&iter
, predicted_length
);
77 assert_presents_right_len(&iter
, 0);