Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a macro for asserting if two xmlel's are equal #30

Merged
merged 1 commit into from
Dec 12, 2018

Conversation

mentels
Copy link

@mentels mentels commented Aug 4, 2017

The assertion is meant to be used in tests.

It's still lacking:

  • better documentation (for functions; in README)
  • appropriate tests


-include_lib("exml/include/exml_stream.hrl").

-type xmlstreamelement() :: #xmlel{} | #xmlstreamstart{} | #xmlstreamend{}.
Copy link

Choose a reason for hiding this comment

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

According to Compiler:

Warning: type xmlstreamelement() is unused

@arcusfelis arcusfelis added the WIP Don't review WIP-s! label May 10, 2018
@michalwski
Copy link

@mentels any chance for finishing this sooner or later?

@mentels
Copy link
Author

mentels commented Nov 7, 2018

Will have a look this week.

@mentels mentels changed the title [WIP] Add a macro for asserting if two xmlel's are equal Add a macro for asserting if two xmlel's are equal Nov 15, 2018
@codecov-io
Copy link

codecov-io commented Nov 15, 2018

Codecov Report

Merging #30 into master will increase coverage by 0.62%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #30      +/-   ##
==========================================
+ Coverage   87.31%   87.94%   +0.62%     
==========================================
  Files           4        4              
  Lines         134      141       +7     
==========================================
+ Hits          117      124       +7     
  Misses         17       17
Impacted Files Coverage Δ
src/exml.erl 91.89% <100%> (+1.89%) ⬆️

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 80a4ecf...4c9f845. Read the comment docs.

@mentels mentels removed the WIP Don't review WIP-s! label Nov 15, 2018
@mentels
Copy link
Author

mentels commented Nov 15, 2018

@michalwski it's ready. @erszcz have a look if the credits are OK.

@erszcz
Copy link
Member

erszcz commented Nov 15, 2018

@mentels More than OK. Thanks!

Copy link

@michalwski michalwski left a comment

Choose a reason for hiding this comment

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

Thanks for pushing this forward. The code looks good. Tests are also great with a room for a small improvement (details in comments to the code).

children = lists:sort([ xml_sort(C) || C <- Children ])
};
xml_sort(#xmlstreamstart{ attrs = Attrs } = StreamStart) ->
StreamStart#xmlstreamstart{ attrs = lists:sort(Attrs) };

Choose a reason for hiding this comment

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

Any chance to cover this function clause with tests? It's not covered at this moment.

src/exml.erl Outdated
xml_sort(Elements) when is_list(Elements) ->
lists:sort([ xml_sort(E) || E <- Elements ]);
xml_sort(Unknown) ->
Unknown.

Choose a reason for hiding this comment

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

I'm wondering if we need that at all. According to the function spec everything is covered and we never get to this clause (as long as valid item() is passed).

Copy link
Member

Choose a reason for hiding this comment

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

I remember adding it for the sake of convenience, when I was figuring out how to return stuff from the Rust parser to the Erlang layer and I returned some rubbish just to test the mechanism. It might not be needed outside experimental code and even if it would, it's trivial to add again.

xml_sort(#xmlstreamstart{ attrs = Attrs } = StreamStart) ->
StreamStart#xmlstreamstart{ attrs = lists:sort(Attrs) };
xml_sort(#xmlstreamend{} = StreamEnd) ->
StreamEnd;

Choose a reason for hiding this comment

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

It'd be good to cover this one with tests as well.

src/exml.erl Outdated
#xmlel{ attrs = Attrs, children = Children } = El,
El#xmlel{
attrs = lists:sort(Attrs),
children = lists:sort([ xml_sort(C) || C <- Children ])
Copy link
Member

Choose a reason for hiding this comment

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

XML is order sensitive so sorting children can cause false positives in macro. I know that it might be useful to not care about the order sometimes but I'd prefer this to be less implicit, if we're going to keep it like this.

Copy link
Member

@erszcz erszcz Nov 20, 2018

Choose a reason for hiding this comment

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

Indeed, good catch. Attributes should be sorted, but children should not. The original did not sort here - https://github.com/erszcz/rxml/blob/e8483408663f0bc2af7896e786c1cdea2e86e43d/test/exml_test.hrl#L23

@mentels
Copy link
Author

mentels commented Nov 20, 2018 via email

@mentels
Copy link
Author

mentels commented Nov 23, 2018

The PR is improved. Will squash the commits once accepted. Have a look @michalwski @erszcz @fenek

sort_xmlstreamend_test() ->
SE1 = #xmlstreamend{name = <<"n1">>},
SE2 = SE1,
?assertEqual(SE1, SE2).

Choose a reason for hiding this comment

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

@mentels Did you miss a call to exml:xml_sort on one of the arguments?

@mentels
Copy link
Author

mentels commented Nov 23, 2018 via email

@michalwski
Copy link

Looks good to me now. Thanks!

@fenek
Copy link
Member

fenek commented Nov 26, 2018

@mentels Looks good. If you'd like to squash commits, then I think you may do so now. :)

The assertion is meant to be used in tests.
@mentels
Copy link
Author

mentels commented Dec 12, 2018

@fenek done.

@michalwski michalwski merged commit a307e83 into master Dec 12, 2018
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.

None yet

7 participants