use std::str; use crate::token::*; test!(document_01, "",); test!(document_02, " ",); test!(document_03, " \n\t\r ",); // BOM test!( document_05, str::from_utf8(b"\xEF\xBB\xBF").unwrap(), Token::ElementStart("", "a", 3..5), Token::ElementEnd(ElementEnd::Empty, 5..7) ); test!( document_06, str::from_utf8(b"\xEF\xBB\xBF").unwrap(), Token::Declaration("1.0", None, None, 3..24) ); test!( document_07, "\n\n\ ", Token::Declaration("1.0", Some("utf-8"), None, 0..38), Token::Comment(" comment ", 39..55), Token::EmptyDtd( "svg", Some(ExternalId::Public( "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" )), 56..154 ) ); test!( document_08, "\n\ ", Token::PI("xml-stylesheet", None, 0..18), Token::EmptyDtd( "svg", Some(ExternalId::Public( "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" )), 19..117 ) ); test!( document_09, "\n\n\ ", Token::Declaration("1.0", Some("utf-8"), None, 0..38), Token::PI("xml-stylesheet", None, 39..57), Token::EmptyDtd( "svg", Some(ExternalId::Public( "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" )), 58..156 ) ); test!( document_err_01, "", Token::Error("unknown token at 1:1".to_string()) ); test!( document_err_02, " &www---------ำค+----------w-----www_", Token::Error("unknown token at 1:2".to_string()) ); test!( document_err_03, "q", Token::Error("unknown token at 1:1".to_string()) ); test!( document_err_04, "", Token::Error("unknown token at 1:1".to_string()) ); test!( document_err_05, "", Token::EmptyDtd("greeting1", None, 0..20), Token::Error("unknown token at 1:21".to_string()) ); test!( document_err_06, " ", Token::Error("unknown token at 1:1".to_string()) ); #[test] fn parse_fragment_1() { let s = "

"; let mut p = html::Tokenizer::from_fragment(s, 0..s.len()); match p.next().unwrap().unwrap() { html::Token::ElementStart { local, .. } => assert_eq!(local.as_str(), "p"), _ => panic!(), } match p.next().unwrap().unwrap() { html::Token::ElementEnd { .. } => {} _ => panic!(), } match p.next().unwrap().unwrap() { html::Token::ElementStart { local, .. } => assert_eq!(local.as_str(), "p"), _ => panic!(), } }