]> git.proxmox.com Git - rustc.git/blob - src/vendor/markup5ever/lib.rs
New upstream version 1.27.1+dfsg1
[rustc.git] / src / vendor / markup5ever / lib.rs
1 // Copyright 2014-2017 The html5ever Project Developers. See the
2 // COPYRIGHT file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 extern crate string_cache;
11 extern crate phf;
12 pub extern crate tendril;
13
14 /// Create a [`SmallCharSet`], with each space-separated number stored in the set.
15 ///
16 /// # Examples
17 ///
18 /// ```
19 /// # #[macro_use] extern crate markup5ever;
20 /// # fn main() {
21 /// let set = small_char_set!(12 54 42);
22 /// assert_eq!(set.bits,
23 /// 0b00000000_01000000_00000100_00000000_00000000_00000000_00010000_00000000);
24 /// # }
25 /// ```
26 ///
27 /// [`SmallCharSet`]: struct.SmallCharSet.html
28 #[macro_export]
29 macro_rules! small_char_set ( ($($e:expr)+) => (
30 $ crate ::SmallCharSet {
31 bits: $( (1 << ($e as usize)) )|+
32 }
33 ));
34
35 include!(concat!(env!("OUT_DIR"), "/generated.rs"));
36
37
38 pub mod data;
39 #[macro_use] pub mod interface;
40 pub mod rcdom;
41 pub mod serialize;
42 mod util {
43 pub mod smallcharset;
44 pub mod buffer_queue;
45 }
46
47 pub use util::*;
48 pub use interface::{ExpandedName, QualName, Attribute};
49 pub use util::smallcharset::SmallCharSet;
50
51
52
53 #[cfg(test)]
54 #[allow(non_snake_case)]
55 mod test {
56 #[allow(unused_imports)] use std::ascii::AsciiExt;
57 use tendril::SliceExt;
58
59 use super::util::buffer_queue::{BufferQueue, FromSet, NotFromSet};
60
61 #[test]
62 fn smoke_test() {
63 let mut bq = BufferQueue::new();
64 assert_eq!(bq.peek(), None);
65 assert_eq!(bq.next(), None);
66
67 bq.push_back("abc".to_tendril());
68 assert_eq!(bq.peek(), Some('a'));
69 assert_eq!(bq.next(), Some('a'));
70 assert_eq!(bq.peek(), Some('b'));
71 assert_eq!(bq.peek(), Some('b'));
72 assert_eq!(bq.next(), Some('b'));
73 assert_eq!(bq.peek(), Some('c'));
74 assert_eq!(bq.next(), Some('c'));
75 assert_eq!(bq.peek(), None);
76 assert_eq!(bq.next(), None);
77 }
78
79 #[test]
80 fn can_unconsume() {
81 let mut bq = BufferQueue::new();
82 bq.push_back("abc".to_tendril());
83 assert_eq!(bq.next(), Some('a'));
84
85 bq.push_front("xy".to_tendril());
86 assert_eq!(bq.next(), Some('x'));
87 assert_eq!(bq.next(), Some('y'));
88 assert_eq!(bq.next(), Some('b'));
89 assert_eq!(bq.next(), Some('c'));
90 assert_eq!(bq.next(), None);
91 }
92
93 #[test]
94 fn can_pop_except_set() {
95 let mut bq = BufferQueue::new();
96 bq.push_back("abc&def".to_tendril());
97 let mut pop = || bq.pop_except_from(small_char_set!('&'));
98 assert_eq!(pop(), Some(NotFromSet("abc".to_tendril())));
99 assert_eq!(pop(), Some(FromSet('&')));
100 assert_eq!(pop(), Some(NotFromSet("def".to_tendril())));
101 assert_eq!(pop(), None);
102 }
103
104 #[test]
105 fn can_eat() {
106 // This is not very comprehensive. We rely on the tokenizer
107 // integration tests for more thorough testing with many
108 // different input buffer splits.
109 let mut bq = BufferQueue::new();
110 bq.push_back("a".to_tendril());
111 bq.push_back("bc".to_tendril());
112 assert_eq!(bq.eat("abcd", u8::eq_ignore_ascii_case), None);
113 assert_eq!(bq.eat("ax", u8::eq_ignore_ascii_case), Some(false));
114 assert_eq!(bq.eat("ab", u8::eq_ignore_ascii_case), Some(true));
115 assert_eq!(bq.next(), Some('c'));
116 assert_eq!(bq.next(), None);
117 }
118 }