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

Fix #231: Minimize empty elements with lengthy attributes #233

Merged
merged 1 commit into from
Jun 25, 2018
Merged

Fix #231: Minimize empty elements with lengthy attributes #233

merged 1 commit into from
Jun 25, 2018

Conversation

hosamaly
Copy link
Contributor

No description provided.

@hosamaly
Copy link
Contributor Author

The build failure is unrelated to the changes in this PR.

val pp = new xml.PrettyPrinter(4, 2, minimizeEmpty = true)
val x = <a b="c"/>
val formatted = pp.format(x)
assertEquals(x, XML.loadString(formatted))
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this test be comparing strings? With XML.loadString, I think you're just verifying the XML structure is preserved from the original.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm verifying that there are no extra nodes caused by the formatting, such as the Text node reported in #231.

I didn't want to hard-code a string to avoid having to modify the test if the formatting behaviour changes. For example, if the commented-out todo is fixed, the output may have 3 lines instead of 2.

// current behaviour
pp.format(x) == s"""<a\n  b="c"/>"""
// possible future behaviour
pp.format(x) == s"""<a\n  b="c"\n  />"""

Since the bug is about the XML structure changing (and, in my case, failing schema validation), I think that using XML.loadString is a better option.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, ok. That's a fair point. The XML structure was getting changed.

There are other tests of PrettyPrinter that compare strings. If history is any guide, I don't think it's a huge risk for the formatting behavior to change often. Again, strings are the output of PrettyPrint.format, so it seems worth checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what value a string comparison would add. I think that the functionality of formatting is covered by other tests, e.g. issue90 on line 746. This test also checks that some formatting happened by checking the number of lines in the output.

I'll add the string comparison if you deem it necessary, but I don't think it would add much value.

val pp = new xml.PrettyPrinter(4, 2, minimizeEmpty = true)
val x = <abcdefg/>
val formatted = pp.format(x)
assertEquals(x, XML.loadString(formatted))
Copy link
Member

@ashawley ashawley May 30, 2018

Choose a reason for hiding this comment

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

Same here. The test should be of the string output from PrettyPrinter.format.

@ashawley ashawley merged commit e6c490e into scala:master Jun 25, 2018
@ashawley
Copy link
Member

ashawley commented Jun 25, 2018

I may try to circle back and refactor this change and even add more tests, but it does fix the defect. Lord knows, this pretty printer code needs some work (it ain't pretty).

Thanks for doing this, Hosam!

@SethTisue SethTisue added this to the 1.1.1 milestone Jun 25, 2018
@hosamaly hosamaly deleted the issue-231 branch June 25, 2018 20:01
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.

3 participants