using AngleSharp.Html.Parser; namespace XFESystem.Browser.Tests; public sealed class CssCommentStreamingTests { [Theory] [InlineData("/* { }; fake{color:red} */#A{width:137px;color:blue/* ; } */;height:29px}")] [InlineData("@media(min-width:600px){/* } ; */#A{wi/* join */dth:137px;color:blue;height:29px}}")] [InlineData("#A/* } */{width:137px;/* ; } */color:blue;height:29px}/*unterminated { ;")] [InlineData("#A{font-family:'text /*not a comment*/ ; {}';width:137px;color:blue;height:29px}")] public void OriginalCommentsAndQuotedDelimitersKeepExactCascadeAndGeometry(string css) { var page=new HtmlParser().ParseDocument("
Visible
");var target=page.GetElementById("A")!; var result=new BrowserLayoutEngine().Layout(page,new(800,600),[new(css)]); Assert.Equal(137,result.GetBoundingClientRect(target).Width);Assert.Equal(29,result.GetBoundingClientRect(target).Height); Assert.Equal("rgb(0, 0, 255)",result.GetComputedStyle(target)!.GetPropertyValue("color")); } [Fact] public void LargeLicenseCommentDoesNotRequireAWholeStylesheetStringOrCharacterArray() { var page=new HtmlParser().ParseDocument("
Visible
");var target=page.GetElementById("A")!; var engine=new BrowserLayoutEngine();var viewport=new BrowserViewport(800,600); engine.Layout(page,viewport,[new("#A{width:137px;height:29px}")]); var sheets=new[]{new BrowserStyleSheet("/*"+new string('x',232950)+"*/#A{width:137px;height:29px}")}; long before=GC.GetAllocatedBytesForCurrentThread();var result=engine.Layout(page,viewport,sheets); long allocated=GC.GetAllocatedBytesForCurrentThread()-before; Assert.Equal(137,result.GetBoundingClientRect(target).Width); Assert.True(allocated<131072,$"Small-rule parse allocated {allocated} bytes for a comment-only large prefix."); } }