@@ -17,30 +17,110 @@ extern crate tendril;
1717#[ macro_export]
1818macro_rules! qualname {
1919 ( "" , $local: tt) => {
20- :: markup5ever :: QualName {
20+ $ crate :: QualName {
2121 ns: ns!( ) ,
2222 prefix: None ,
2323 local: local_name!( $local) ,
2424 }
2525 } ;
2626 ( $ns: tt, $local: tt) => {
27- :: markup5ever :: QualName {
27+ $ crate :: QualName {
2828 ns: ns!( $ns) ,
2929 prefix: None ,
3030 local: local_name!( $local) ,
3131 }
3232 }
3333}
3434
35+ #[ macro_export]
36+ macro_rules! small_char_set ( ( $( $e: expr) +) => (
37+ $ crate :: SmallCharSet {
38+ bits: $( ( 1 << ( $e as usize ) ) ) |+
39+ }
40+ ) ) ;
41+
3542include ! ( concat!( env!( "OUT_DIR" ) , "/generated.rs" ) ) ;
3643
3744
3845pub mod data;
3946pub mod interface;
4047pub mod util {
41- pub mod buffer_queue;
4248 pub mod smallcharset;
49+ pub mod buffer_queue;
50+
4351}
4452
4553pub use interface:: { QualName , Attribute } ;
4654pub use util:: smallcharset:: SmallCharSet ;
55+
56+
57+
58+ #[ cfg( test) ]
59+ #[ allow( non_snake_case) ]
60+ mod test {
61+ use std:: ascii:: AsciiExt ;
62+ use tendril:: SliceExt ;
63+
64+ use super :: { QualName } ;
65+ use super :: util:: buffer_queue:: { BufferQueue , FromSet , NotFromSet } ;
66+
67+
68+
69+ #[ test]
70+ fn smoke_test ( ) {
71+ let mut bq = BufferQueue :: new ( ) ;
72+ assert_eq ! ( bq. peek( ) , None ) ;
73+ assert_eq ! ( bq. next( ) , None ) ;
74+
75+ bq. push_back ( "abc" . to_tendril ( ) ) ;
76+ assert_eq ! ( bq. peek( ) , Some ( 'a' ) ) ;
77+ assert_eq ! ( bq. next( ) , Some ( 'a' ) ) ;
78+ assert_eq ! ( bq. peek( ) , Some ( 'b' ) ) ;
79+ assert_eq ! ( bq. peek( ) , Some ( 'b' ) ) ;
80+ assert_eq ! ( bq. next( ) , Some ( 'b' ) ) ;
81+ assert_eq ! ( bq. peek( ) , Some ( 'c' ) ) ;
82+ assert_eq ! ( bq. next( ) , Some ( 'c' ) ) ;
83+ assert_eq ! ( bq. peek( ) , None ) ;
84+ assert_eq ! ( bq. next( ) , None ) ;
85+ }
86+
87+ #[ test]
88+ fn can_unconsume ( ) {
89+ let mut bq = BufferQueue :: new ( ) ;
90+ bq. push_back ( "abc" . to_tendril ( ) ) ;
91+ assert_eq ! ( bq. next( ) , Some ( 'a' ) ) ;
92+
93+ bq. push_front ( "xy" . to_tendril ( ) ) ;
94+ assert_eq ! ( bq. next( ) , Some ( 'x' ) ) ;
95+ assert_eq ! ( bq. next( ) , Some ( 'y' ) ) ;
96+ assert_eq ! ( bq. next( ) , Some ( 'b' ) ) ;
97+ assert_eq ! ( bq. next( ) , Some ( 'c' ) ) ;
98+ assert_eq ! ( bq. next( ) , None ) ;
99+ }
100+
101+ #[ test]
102+ fn can_pop_except_set ( ) {
103+ let mut bq = BufferQueue :: new ( ) ;
104+ bq. push_back ( "abc&def" . to_tendril ( ) ) ;
105+ let mut pop = || bq. pop_except_from ( small_char_set ! ( '&' ) ) ;
106+ assert_eq ! ( pop( ) , Some ( NotFromSet ( "abc" . to_tendril( ) ) ) ) ;
107+ assert_eq ! ( pop( ) , Some ( FromSet ( '&' ) ) ) ;
108+ assert_eq ! ( pop( ) , Some ( NotFromSet ( "def" . to_tendril( ) ) ) ) ;
109+ assert_eq ! ( pop( ) , None ) ;
110+ }
111+
112+ #[ test]
113+ fn can_eat ( ) {
114+ // This is not very comprehensive. We rely on the tokenizer
115+ // integration tests for more thorough testing with many
116+ // different input buffer splits.
117+ let mut bq = BufferQueue :: new ( ) ;
118+ bq. push_back ( "a" . to_tendril ( ) ) ;
119+ bq. push_back ( "bc" . to_tendril ( ) ) ;
120+ assert_eq ! ( bq. eat( "abcd" , u8 :: eq_ignore_ascii_case) , None ) ;
121+ assert_eq ! ( bq. eat( "ax" , u8 :: eq_ignore_ascii_case) , Some ( false ) ) ;
122+ assert_eq ! ( bq. eat( "ab" , u8 :: eq_ignore_ascii_case) , Some ( true ) ) ;
123+ assert_eq ! ( bq. next( ) , Some ( 'c' ) ) ;
124+ assert_eq ! ( bq. next( ) , None ) ;
125+ }
126+ }
0 commit comments