use crate::token::*; test!( dtd_01, "", Token::EmptyDtd("greeting", Some(ExternalId::System("hello.dtd")), 0..38) ); test!( dtd_02, "", Token::EmptyDtd( "greeting", Some(ExternalId::Public("hello.dtd", "goodbye.dtd")), 0..52 ) ); test!( dtd_03, "", Token::EmptyDtd("greeting", Some(ExternalId::System("hello.dtd")), 0..38) ); test!( dtd_04, "", Token::EmptyDtd("greeting", None, 0..19) ); test!( dtd_05, "", Token::DtdStart("greeting", None, 0..20), Token::DtdEnd(20..22) ); test!( dtd_06, "", Token::EmptyDtd("greeting", None, 0..19), Token::ElementStart("", "a", 19..21), Token::ElementEnd(ElementEnd::Empty, 21..23) ); test!( dtd_07, "", Token::DtdStart("greeting", None, 0..20), Token::DtdEnd(20..23) ); test!( dtd_08, "", Token::DtdStart("greeting", None, 0..20), Token::DtdEnd(21..24) ); test!( dtd_09, "", Token::EmptyDtd("html", None, 0..15) ); test!( dtd_10, "", Token::EmptyDtd("html", None, 0..15) ); test!( dtd_entity_01, " ]>", Token::DtdStart("svg", None, 0..15), Token::EntityDecl( "ns_extend", EntityDefinition::EntityValue("http://ns.adobe.com/Extensibility/1.0/"), 20..80, ), Token::DtdEnd(81..83) ); test!( dtd_entity_02, " ]>", Token::DtdStart("svg", None, 0..15), Token::EntityDecl( "Pub-Status", EntityDefinition::EntityValue("This is a pre-release of the\nspecification."), 20..86, ), Token::DtdEnd(87..89) ); test!( dtd_entity_03, " ]>", Token::DtdStart("svg", None, 0..15), Token::EntityDecl( "open-hatch", EntityDefinition::ExternalId(ExternalId::System( "http://www.textuality.com/boilerplate/OpenHatch.xml" )), 20..101, ), Token::DtdEnd(102..104) ); test!( dtd_entity_04, " ]>", Token::DtdStart("svg", None, 0..15), Token::EntityDecl( "open-hatch", EntityDefinition::ExternalId(ExternalId::Public( "-//Textuality//TEXT Standard open-hatch boilerplate//EN", "http://www.textuality.com/boilerplate/OpenHatch.xml" )), 20..185, ), Token::DtdEnd(186..188) ); // TODO: NDATA will be ignored test!( dtd_entity_05, " ]>", Token::DtdStart("svg", None, 0..15), Token::EntityDecl( "hatch-pic", EntityDefinition::ExternalId(ExternalId::System("../grafix/OpenHatch.gif")), 20..83, ), Token::DtdEnd(84..86) ); // TODO: unsupported data will be ignored test!( dtd_entity_06, " ]>", Token::DtdStart("svg", None, 0..15), Token::EntityDecl( "ns_extend", EntityDefinition::EntityValue("http://ns.adobe.com/Extensibility/1.0/"), 44..104 ), Token::DtdEnd(203..205) ); // We do not support !ELEMENT DTD token and it will be skipped. // Previously, we were calling `Tokenizer::next` after the skip, // which is recursive and could cause a stack overflow when there are too many sequential // unsupported tokens. // This tests checks that the current code do not crash with stack overflow. #[test] fn dtd_entity_07() { let mut text = "\n"); } text.push_str("]>\n"); let mut p = html::Tokenizer::from(text.as_str()); assert_eq!( to_test_token(p.next().unwrap()), Token::DtdStart("svg", None, 0..15) ); assert_eq!( to_test_token(p.next().unwrap()), Token::DtdEnd(10016..10018) ); } test!( dtd_err_01, "\u{000a}<", Token::Error("invalid DTD at 1:1 cause expected space not 'E' at 1:10".to_string()) ); test!( dtd_err_02, "' not '!' at 1:16".to_string()) );