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