1 // Copyright 2014-2017 The html5ever Project Developers. See the
2 // COPYRIGHT file at the top-level directory of this distribution.
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.
10 extern crate string_cache
;
12 pub extern crate tendril
;
14 /// Create a [`SmallCharSet`], with each space-separated number stored in the set.
19 /// # #[macro_use] extern crate markup5ever;
21 /// let set = small_char_set!(12 54 42);
22 /// assert_eq!(set.bits,
23 /// 0b00000000_01000000_00000100_00000000_00000000_00000000_00010000_00000000);
27 /// [`SmallCharSet`]: struct.SmallCharSet.html
29 macro_rules
! small_char_set ( ($
($e
:expr
)+) => (
30 $
crate ::SmallCharSet
{
31 bits
: $
( (1 << ($e
as usize)) )|+
35 include
!(concat
!(env
!("OUT_DIR"), "/generated.rs"));
39 #[macro_use] pub mod interface;
48 pub use interface
::{ExpandedName, QualName, Attribute}
;
49 pub use util
::smallcharset
::SmallCharSet
;
54 #[allow(non_snake_case)]
56 #[allow(unused_imports)] use std::ascii::AsciiExt;
57 use tendril
::SliceExt
;
59 use super::util
::buffer_queue
::{BufferQueue, FromSet, NotFromSet}
;
63 let mut bq
= BufferQueue
::new();
64 assert_eq
!(bq
.peek(), None
);
65 assert_eq
!(bq
.next(), None
);
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
);
81 let mut bq
= BufferQueue
::new();
82 bq
.push_back("abc".to_tendril());
83 assert_eq
!(bq
.next(), Some('a'
));
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
);
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
);
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
);