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 #[cfg(feature = "bench")]
19 #[bench]
cargo_is_xid_start(b: &mut Bencher)20 fn cargo_is_xid_start(b: &mut Bencher) {
21 let string = iter::repeat('a').take(4096).collect::<String>();
22
23 b.bytes = string.len() as u64;
24 b.iter(|| {
25 string.chars().all(super::UnicodeXID::is_xid_start)
26 });
27 }
28
29 #[cfg(feature = "bench")]
30 #[bench]
stdlib_is_xid_start(b: &mut Bencher)31 fn stdlib_is_xid_start(b: &mut Bencher) {
32 let string = iter::repeat('a').take(4096).collect::<String>();
33
34 b.bytes = string.len() as u64;
35 b.iter(|| {
36 string.chars().all(char::is_xid_start)
37 });
38 }
39
40 #[cfg(feature = "bench")]
41 #[bench]
cargo_xid_continue(b: &mut Bencher)42 fn cargo_xid_continue(b: &mut Bencher) {
43 let string = iter::repeat('a').take(4096).collect::<String>();
44
45 b.bytes = string.len() as u64;
46 b.iter(|| {
47 string.chars().all(super::UnicodeXID::is_xid_continue)
48 });
49 }
50
51 #[cfg(feature = "bench")]
52 #[bench]
stdlib_xid_continue(b: &mut Bencher)53 fn stdlib_xid_continue(b: &mut Bencher) {
54 let string = iter::repeat('a').take(4096).collect::<String>();
55
56 b.bytes = string.len() as u64;
57 b.iter(|| {
58 string.chars().all(char::is_xid_continue)
59 });
60 }
61
62 #[test]
test_is_xid_start()63 fn test_is_xid_start() {
64 let chars = [
65 'A', 'Z', 'a', 'z',
66 '\u{1000d}', '\u{10026}',
67 ];
68
69 for ch in &chars {
70 assert!(super::UnicodeXID::is_xid_start(*ch), "{}", ch);
71 }
72 }
73
74 #[test]
test_is_not_xid_start()75 fn test_is_not_xid_start() {
76 let chars = [
77 '\x00', '\x01',
78 '0', '9',
79 ' ', '[', '<', '{', '(',
80 '\u{02c2}', '\u{ffff}',
81 ];
82
83 for ch in &chars {
84 assert!(!super::UnicodeXID::is_xid_start(*ch), "{}", ch);
85 }
86 }
87
88 #[test]
test_is_xid_continue()89 fn test_is_xid_continue() {
90 let chars = [
91 '0', '9', 'A', 'Z', 'a', 'z', '_',
92 '\u{1000d}', '\u{10026}',
93 ];
94
95 for ch in &chars {
96 assert!(super::UnicodeXID::is_xid_continue(*ch), "{}", ch);
97 }
98 }
99
100 #[test]
test_is_not_xid_continue()101 fn test_is_not_xid_continue() {
102 let chars = [
103 '\x00', '\x01',
104 ' ', '[', '<', '{', '(',
105 '\u{02c2}', '\u{ffff}',
106 ];
107
108 for &ch in &chars {
109 assert!(!super::UnicodeXID::is_xid_continue(ch), "{}", ch);
110 }
111 }
112