public Parse ( ITextProvider textProvider ) : void | ||
textProvider | ITextProvider | Text provider |
Résultat | void |
public void HtmlParser_UnknownDocType() { var parser = new HtmlParser(); parser.Parse("<!doctype randomname1><html></html>"); Assert.Equal(DocType.Unrecognized, parser.DocType); Assert.Equal(ParsingMode.Html, parser.ParsingMode); parser.Parse("<html></html>"); Assert.Equal(DocType.Undefined, parser.DocType); Assert.Equal(ParsingMode.Html, parser.ParsingMode); }
public void HtmlParser_DuplicateDocType() { var parser = new HtmlParser(); parser.Parse("<!doctype randomname1>" + DocTypeSignatures.Html5 + "<html></html>"); Assert.Equal(DocType.Unrecognized, parser.DocType); Assert.Equal(ParsingMode.Html, parser.ParsingMode); parser.Parse(DocTypeSignatures.Html5 + "<!doctype randomname1><html></html>"); Assert.Equal(DocType.Html5, parser.DocType); Assert.Equal(ParsingMode.Html, parser.ParsingMode); }
public void OnEntity_WellFormedTest1() { HtmlParser parser = new HtmlParser(); parser.EntityFound += delegate (object sender, HtmlParserRangeEventArgs args) { Assert.Equal(3, args.Range.Start); Assert.Equal(9, args.Range.End); }; parser.Parse("foo "); }
public void HtmlParser_KnownDocTypes() { var parser = new HtmlParser(); parser.Parse(DocTypeSignatures.Html32 + "<html></html>"); Assert.Equal(DocType.Html32, parser.DocType); Assert.Equal(ParsingMode.Html, parser.ParsingMode); parser.Parse(DocTypeSignatures.Html401Frameset + "<html></html>"); Assert.Equal(DocType.Html401Frameset, parser.DocType); Assert.Equal(ParsingMode.Html, parser.ParsingMode); parser.Parse(DocTypeSignatures.Html401Strict + "<html></html>"); Assert.Equal(DocType.Html401Strict, parser.DocType); Assert.Equal(ParsingMode.Html, parser.ParsingMode); parser.Parse(DocTypeSignatures.Html401Transitional + "<html></html>"); Assert.Equal(DocType.Html401Transitional, parser.DocType); Assert.Equal(ParsingMode.Html, parser.ParsingMode); parser.Parse(DocTypeSignatures.Html5 + "<html></html>"); Assert.Equal(DocType.Html5, parser.DocType); Assert.Equal(ParsingMode.Html, parser.ParsingMode); parser.Parse(DocTypeSignatures.Xhtml10Frameset + "<html></html>"); Assert.Equal(DocType.Xhtml10Frameset, parser.DocType); Assert.Equal(ParsingMode.Xhtml, parser.ParsingMode); parser.Parse(DocTypeSignatures.Xhtml10Strict + "<html></html>"); Assert.Equal(DocType.Xhtml10Strict, parser.DocType); Assert.Equal(ParsingMode.Xhtml, parser.ParsingMode); parser.Parse(DocTypeSignatures.Xhtml10Transitional + "<html></html>"); Assert.Equal(DocType.Xhtml10Transitional, parser.DocType); Assert.Equal(ParsingMode.Xhtml, parser.ParsingMode); parser.Parse(DocTypeSignatures.Xhtml11 + "<html></html>"); Assert.Equal(DocType.Xhtml11, parser.DocType); Assert.Equal(ParsingMode.Xhtml, parser.ParsingMode); parser.Parse(DocTypeSignatures.Xhtml20 + "<html></html>"); Assert.Equal(DocType.Xhtml20, parser.DocType); Assert.Equal(ParsingMode.Xhtml, parser.ParsingMode); }
public void OnEntity_BrokenTest() { HtmlParser parser = new HtmlParser(); int count = 0; parser.EntityFound += delegate (object sender, HtmlParserRangeEventArgs args) { count++; }; parser.Parse(">"); Assert.Equal(0, count); }
public void OnEntity_WellFormedTest3() { HtmlParser parser = new HtmlParser(); int count = 0; parser.EntityFound += delegate (object sender, HtmlParserRangeEventArgs args) { count++; }; parser.Parse(new TextStream("foo­bar ઼&abc;<html < dir=\">")); Assert.Equal(2, count); }
public void OnEntity_WellFormedTest2() { HtmlParser parser = new HtmlParser(); int count = 0; parser.EntityFound += delegate (object sender, HtmlParserRangeEventArgs args) { count++; }; parser.Parse("foo bar <<html < dir=\">\"> > ""); Assert.Equal(3, count); }
static public void ParseText(HtmlTestFilesFixture fixture, string name) { string testFile = fixture.GetDestinationPath(name); string baselineFile = testFile + ".log"; string text = fixture.LoadDestinationFile(name); EventLogger logger = null; HtmlParser p = new HtmlParser(); logger = new EventLogger(p); p.Parse(text); var actual = logger.ToString(); if (_regenerateBaselineFiles) { // Update this to your actual enlistment if you need to update baseline baselineFile = Path.Combine(fixture.SourcePath, name) + ".log"; TestFiles.UpdateBaseline(baselineFile, actual); } else { TestFiles.CompareToBaseLine(baselineFile, actual); } }
public void HtmlParser_XmlPi() { var parser = new HtmlParser(); parser.Parse("<?xml charset='utf-8' ?><html></html>"); Assert.Equal(DocType.Undefined, parser.DocType); Assert.Equal(ParsingMode.Xml, parser.ParsingMode); }
public void HtmlParser_MalformedDocType() { var parser = new HtmlParser(); parser.Parse("<!doctype randomname1<html></html>"); Assert.Equal(DocType.Undefined, parser.DocType); Assert.Equal(ParsingMode.Html, parser.ParsingMode); }
public void AttributeParse_RandomCharacters() { var target = new HtmlParser(); target.AttributeFound += delegate (object sender, HtmlParserAttributeEventArgs args) { Assert.True(args.AttributeToken is AttributeToken); AttributeToken at = args.AttributeToken; switch (attributeCalls) { case 0: Assert.True(at.HasName()); Assert.Equal(3, at.NameToken.Start); Assert.Equal(2, at.NameToken.Length); Assert.True(at.HasValue()); Assert.Equal(6, at.ValueToken.Start); Assert.Equal(1, at.ValueToken.Length); break; case 1: Assert.True(at.HasName()); Assert.Equal(8, at.NameToken.Start); Assert.Equal(1, at.NameToken.Length); Assert.True(at.HasValue()); Assert.Equal(10, at.ValueToken.Start); Assert.Equal(1, at.ValueToken.Length); break; case 2: Assert.True(at.HasName()); Assert.Equal(12, at.NameToken.Start); Assert.Equal(2, at.NameToken.Length); Assert.False(at.HasValue()); break; } attributeCalls++; }; attributeCalls = 0; target.Parse("<a id=# $=% ^^"); Assert.Equal(3, attributeCalls); }
public void AttributeParse_InlineStyle_Typo() { var target = new HtmlParser(); target.AttributeFound += delegate (object sender, HtmlParserAttributeEventArgs args) { Assert.True(args.AttributeToken is AttributeToken); AttributeToken at = args.AttributeToken; switch (attributeCalls) { case 0: Assert.True(at.HasName()); Assert.Equal(7, at.NameToken.Start); Assert.Equal(5, at.NameToken.Length); Assert.True(at.HasValue()); Assert.Equal(13, at.ValueToken.Start); Assert.Equal(14, at.ValueToken.Length); break; case 1: Assert.True(at.HasName()); Assert.Equal(27, at.NameToken.Start); Assert.Equal(1, at.NameToken.Length); Assert.False(at.HasValue()); break; } attributeCalls++; }; attributeCalls = 0; target.Parse("<input style=\"display:none\";>"); Assert.Equal(2, attributeCalls); }
/// <summary> /// Main method to build a subtree from a text range. /// </summary> public virtual void Build(ITextRange range) { CommentCollection = new CommentCollection(); HtmlParser parser = new HtmlParser(ParsingMode, ScriptTypeResolution, ScriptOrStyleTagNameService); HtmlTreeBuilder builder = new HtmlTreeBuilder(parser, this); parser.Parse(Text, range); DocType = parser.DocType; ParsingMode = parser.ParsingMode; }