Skip to content

Conversation

@egil
Copy link
Member

@egil egil commented Sep 27, 2020

Pull request description

Fixes #198. This is an attempt to implement a automatic context detection if the string to be parsed by BunitHtmlParser starts with a HTML tag.

PR meta checklist

  • Pull request is targeting at DEV branch.
  • Pull request is linked to all related issues, if any.
  • I have read the CONTRIBUTING.md document.

Content checklist

  • My code follows the code style of this project and AspNetCore coding guidelines.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • I have updated the appropriate sub section in the CHANGELOG.md.
  • I have added, updated or removed tests to according to my changes.
    • All tests passed.

egil and others added 5 commits September 15, 2020 22:15
* componentparametercollection

* Support for passing multiple template and render fragments

* Automated dotnet-format update

* cascading values

* Finished component parameter collection, closed #142, updated tests to component parameter factory

* Fixed null warnings

* Automated dotnet-format update

* Fixes for CodeQL warnings

* Added ChildContent and RenderFragment tests

* Added support for passing template fragments

* Removed ComponentParameterBuilder, added support for unmatched and cascading values

* Switched to C# 9 compile

* Automated dotnet-format update

* unnamed cascading value with add

* Removed .net move hack from workflows

* Fix for null errors

* Automated dotnet-format update

* Added extra factory method and moved ComponentParameter out into Bunit namespace

* Updated docs with new parameter passing logic

* Automated dotnet-format update

* Updated changelog

Co-authored-by: Github Actions <[email protected]>
@egil egil linked an issue Sep 27, 2020 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Sep 27, 2020

Codecov Report

❗ No coverage uploaded for pull request base (dev@fafa45c). Click here to learn what that means.
The diff coverage is 81.45%.

Impacted file tree graph

@@          Coverage Diff           @@
##             dev     #220   +/-   ##
======================================
  Coverage       ?   79.17%           
======================================
  Files          ?      103           
  Lines          ?     3011           
  Branches       ?      394           
======================================
  Hits           ?     2384           
  Misses         ?      498           
  Partials       ?      129           
Impacted Files Coverage Δ
src/bunit.core/ComponentParameterCollection.cs 80.35% <ø> (ø)
.../bunit.core/ComponentParameterCollectionBuilder.cs 81.25% <ø> (ø)
src/bunit.core/ComponentParameterFactory.cs 100.00% <ø> (ø)
...re/Extensions/RenderedComponentRenderExtensions.cs 74.35% <ø> (ø)
....web/Asserting/ShouldBeAdditionAssertExtensions.cs 0.00% <0.00%> (ø)
...t.web/Asserting/ShouldBeRemovalAssertExtensions.cs 0.00% <0.00%> (ø)
...eb/Asserting/ShouldBeTextChangeAssertExtensions.cs 0.00% <0.00%> (ø)
...it.web/Extensions/Internal/AngleSharpExtensions.cs 33.33% <0.00%> (ø)
src/bunit.web/TestContext.cs 100.00% <ø> (ø)
...nit.web/Asserting/MarkupMatchesAssertExtensions.cs 12.50% <25.00%> (ø)
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fafa45c...a17f120. Read the comment docs.

Copy link

@FlorianRappl FlorianRappl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good.

As suggested, I would only create the document + elements locally and separate the parser instance from the document instance. Also I would go for the async variant. However, as it is it should also just work fine.

@egil
Copy link
Member Author

egil commented Sep 28, 2020

Huge thanks for the review.

In all the cases where this is used in bUnit isnt async, so from that point of view it does not make sense to make the parse method async.

I am not sure I follow your suggestion, can you share a link to some docs are a snippet that shows what you are thinking of?

Last question. I would like to support parsing html, head, and body start tags, but haven't figured out how to do so with the contexts. Any suggestions?

@FlorianRappl
Copy link

I am not sure I follow your suggestion, can you share a link to some docs are a snippet that shows what you are thinking of?

I am not sure which suggestion you mean. Locality means avoid having members, but just local references, e.g.,

public INodeList Parse(string markup)
{
  var document = ...
  var body = ...
  return ParseInto(document, body, ..., markup); // just an example call, you could also make a local function and capture the variables above
}

Last question. I would like to support parsing html, head, and body start tags, but haven't figured out how to do so with the contexts.

For the given three tags I would not use a fragment, but rather full parsing. These are not fragments but (parts of) full documents.

@egil
Copy link
Member Author

egil commented Sep 28, 2020

Ahh yes, that's what I meant. Is it purely esthetics that you prefer locality or is there also some internal AngleSharp reason not to reuse the "contexts"?

Update: saw your other comment on the code, so I guess the answer is yes to the last part.

@FlorianRappl
Copy link

Update: saw your other comment on the code, so I guess the answer is yes to the last part.

If yes means "has functional consequences" then yes. You should always prefer locals over members. If that parser is reused you will be in deep trouble as there are already members on them.

@egil
Copy link
Member Author

egil commented Sep 28, 2020

Update: saw your other comment on the code, so I guess the answer is yes to the last part.

If yes means "has functional consequences" then yes. You should always prefer locals over members. If that parser is reused you will be in deep trouble as there are already members on them.

How so? The current version in main does the same thing, and that is typically scoped to a test, such that all parsing needs within a single test share the document.

What kind of problems should this be causing?

@FlorianRappl
Copy link

The current version in main does the same thing, and that is typically scoped to a test, such that all parsing needs within a single test share the document.

Again, if you reuse the parser you reuse the document you end up with unexpected results. This can cause all kinds of problems - usually you want that locality (it does not only help the GC, but it implies a more advanced development paradigm that avoids side-effects).

I mean this discussion quite derailed right now. So I'd like to close it. If you want to have members - sure go ahead. All I am writing is that keeping local things local does help. It also helps thinking just in the context of one class (I don't want to look at uses of this class to understand if having members is acceptable or not - just avoiding it would be the way to go to prevent unnecessary cognitive load in the first place).

@egil
Copy link
Member Author

egil commented Sep 28, 2020

I mean this discussion quite derailed right now...

That's fair. I am not pro one or the other, but I am trying to understand how AngleSharp works and how to use it correct in this regard.

@egil
Copy link
Member Author

egil commented Sep 29, 2020

@FlorianRappl I did as you suggested and stopped reusing the context elements. Also have support for html, head and body now. Does this look alright?

(code is a bit messy but I can refactor it later when my flu passes).

@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 2, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@egil egil merged commit 2611704 into dev Oct 2, 2020
@egil egil deleted the bug/198-htmlparser-context branch October 2, 2020 09:14
@egil egil mentioned this pull request Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bUnit's HtmlParser should detect markup context to avoid surprising users

3 participants