]> git.proxmox.com Git - rustc.git/blob - vendor/unicode-xid-0.1.0/src/tests.rs
New upstream version 1.39.0+dfsg1
[rustc.git] / vendor / unicode-xid-0.1.0 / src / tests.rs
1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
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.
10
11 #[cfg(feature = "bench")]
12 use std::iter;
13 #[cfg(feature = "bench")]
14 use test::Bencher;
15 #[cfg(feature = "bench")]
16 use std::prelude::v1::*;
17
18 use super::UnicodeXID;
19
20 #[cfg(feature = "bench")]
21 #[bench]
22 fn cargo_is_xid_start(b: &mut Bencher) {
23 let string = iter::repeat('a').take(4096).collect::<String>();
24
25 b.bytes = string.len() as u64;
26 b.iter(|| {
27 string.chars().all(UnicodeXID::is_xid_start)
28 });
29 }
30
31 #[cfg(feature = "bench")]
32 #[bench]
33 fn stdlib_is_xid_start(b: &mut Bencher) {
34 let string = iter::repeat('a').take(4096).collect::<String>();
35
36 b.bytes = string.len() as u64;
37 b.iter(|| {
38 string.chars().all(char::is_xid_start)
39 });
40 }
41
42 #[cfg(feature = "bench")]
43 #[bench]
44 fn cargo_xid_continue(b: &mut Bencher) {
45 let string = iter::repeat('a').take(4096).collect::<String>();
46
47 b.bytes = string.len() as u64;
48 b.iter(|| {
49 string.chars().all(UnicodeXID::is_xid_continue)
50 });
51 }
52
53 #[cfg(feature = "bench")]
54 #[bench]
55 fn stdlib_xid_continue(b: &mut Bencher) {
56 let string = iter::repeat('a').take(4096).collect::<String>();
57
58 b.bytes = string.len() as u64;
59 b.iter(|| {
60 string.chars().all(char::is_xid_continue)
61 });
62 }
63
64 #[test]
65 fn test_is_xid_start() {
66 let chars = [
67 'A', 'Z', 'a', 'z',
68 '\u{1000d}', '\u{10026}',
69 ];
70
71 for ch in &chars {
72 assert!(UnicodeXID::is_xid_start(*ch), "{}", ch);
73 }
74 }
75
76 #[test]
77 fn test_is_not_xid_start() {
78 let chars = [
79 '\x00', '\x01',
80 '0', '9',
81 ' ', '[', '<', '{', '(',
82 '\u{02c2}', '\u{ffff}',
83 ];
84
85 for ch in &chars {
86 assert!(!UnicodeXID::is_xid_start(*ch), "{}", ch);
87 }
88 }
89
90 #[test]
91 fn test_is_xid_continue() {
92 let chars = [
93 '0', '9', 'A', 'Z', 'a', 'z', '_',
94 '\u{1000d}', '\u{10026}',
95 ];
96
97 for ch in &chars {
98 assert!(UnicodeXID::is_xid_continue(*ch), "{}", ch);
99 }
100 }
101
102 #[test]
103 fn test_is_not_xid_continue() {
104 let chars = [
105 '\x00', '\x01',
106 ' ', '[', '<', '{', '(',
107 '\u{02c2}', '\u{ffff}',
108 ];
109
110 for &ch in &chars {
111 assert!(!UnicodeXID::is_xid_continue(ch), "{}", ch);
112 }
113 }