Skip to content

Commit

Permalink
Tests for scala#107 white space defect when parsing adjacent entities
Browse files Browse the repository at this point in the history
Add unit tests to check for white space between XML entities.  One
test is the original example of two adjacent entities. An additional
test case *has* white space between entities, and is just an
affirmation of the existing behavior, and should be preserved.

This bug pops up when the preserveWS option is either enabled or
disabled for ConstructingParser.  This doubles the number of unit
tests to four.

The fifth unit test, listed first, of adjacent text characters is
rhetoric, and doesn't need to be included in the final merge.  The
previous sentence shouldn't be merged either.

[error] Test XMLTest.preserveNoSpaceBetweenEntitiesOptionEnabled failed:
[error]   expected: <<div>&lt;[]&lt;</div>>
[error]   but was: <<div>&lt;[ ]&lt;</div>>
[error] Test XMLTest.preserveNoSpaceBetweenEntitiesOptionDisabled failed:
[error]   expected: <<div>&lt;[]&lt;</div>>
[error]   but was: <<div>&lt;[ ]&lt;</div>>
  • Loading branch information
ashawley committed Jul 29, 2016
1 parent 55008bd commit a1ee9ac
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/test/scala/scala/xml/XMLTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,75 @@ expected closing tag of foo
}
}

@UnitTest
def preserveSpaceTextOptionDisabledIssue107: Unit = {

// This test is rhetorical, but is the argument for being
// consistent with entities.
val x = "<div>tt</div>"

val preserveWS = false

val d = ConstructingParser.fromSource(scala.io.Source.fromString(x), preserveWS).document

assertEquals(x, d.toString)
}

@UnitTest
def preserveNoSpaceBetweenEntitiesOptionDisabledIssue107: Unit = {

// This is the exammple given in the original post.
val x = "<div>&lt;&lt;</div>"

val preserveWS = false

val d = ConstructingParser.fromSource(scala.io.Source.fromString(x), preserveWS).document

// Should:
assertEquals(x, d.toString)
// But was adding a space:
// assertEquals("<div>&lt; &lt;</div>", d.toString)
}

@UnitTest
def preserveNoSpaceBetweenEntitiesOptionEnabledIssue107: Unit = {
val x = "<div>&lt;&lt;</div>"

// Shouldn't add space when this option is enabled, either.
val preserveWS = true

val d = ConstructingParser.fromSource(scala.io.Source.fromString(x), preserveWS).document

// Should:
assertEquals(x, d.toString)
// But was adding a space:
// assertEquals("<div>&lt; &lt;</div>", d.toString)
}

@UnitTest
def preserveSpaceBetweenEntitiesOptionEnabledIssue107: Unit = {
val x = "<div>&lt; &lt;</div>"

val preserveWS = true

val d = ConstructingParser.fromSource(scala.io.Source.fromString(x), preserveWS).document

// This was already correct in 1.0.5
assertEquals(x, d.toString)
}

@UnitTest
def preserveSpaceBetweenEntitiesOptionDisabledIssue107: Unit = {
val x = "<div>&lt; &lt;</div>"

val preserveWS = false

val d = ConstructingParser.fromSource(scala.io.Source.fromString(x), preserveWS).document

// This was already correct in 1.0.5
assertEquals(x, d.toString)
}

@UnitTest
def issue28: Unit = {
val x = <x:foo xmlns:x="gaga"/>
Expand Down

0 comments on commit a1ee9ac

Please sign in to comment.