Skip to content

Commit a1ee9ac

Browse files
committed
Tests for scala#107 white space defect when parsing adjacent entities
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>>
1 parent 55008bd commit a1ee9ac

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

Diff for: src/test/scala/scala/xml/XMLTest.scala

+69
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,75 @@ expected closing tag of foo
835835
}
836836
}
837837

838+
@UnitTest
839+
def preserveSpaceTextOptionDisabledIssue107: Unit = {
840+
841+
// This test is rhetorical, but is the argument for being
842+
// consistent with entities.
843+
val x = "<div>tt</div>"
844+
845+
val preserveWS = false
846+
847+
val d = ConstructingParser.fromSource(scala.io.Source.fromString(x), preserveWS).document
848+
849+
assertEquals(x, d.toString)
850+
}
851+
852+
@UnitTest
853+
def preserveNoSpaceBetweenEntitiesOptionDisabledIssue107: Unit = {
854+
855+
// This is the exammple given in the original post.
856+
val x = "<div>&lt;&lt;</div>"
857+
858+
val preserveWS = false
859+
860+
val d = ConstructingParser.fromSource(scala.io.Source.fromString(x), preserveWS).document
861+
862+
// Should:
863+
assertEquals(x, d.toString)
864+
// But was adding a space:
865+
// assertEquals("<div>&lt; &lt;</div>", d.toString)
866+
}
867+
868+
@UnitTest
869+
def preserveNoSpaceBetweenEntitiesOptionEnabledIssue107: Unit = {
870+
val x = "<div>&lt;&lt;</div>"
871+
872+
// Shouldn't add space when this option is enabled, either.
873+
val preserveWS = true
874+
875+
val d = ConstructingParser.fromSource(scala.io.Source.fromString(x), preserveWS).document
876+
877+
// Should:
878+
assertEquals(x, d.toString)
879+
// But was adding a space:
880+
// assertEquals("<div>&lt; &lt;</div>", d.toString)
881+
}
882+
883+
@UnitTest
884+
def preserveSpaceBetweenEntitiesOptionEnabledIssue107: Unit = {
885+
val x = "<div>&lt; &lt;</div>"
886+
887+
val preserveWS = true
888+
889+
val d = ConstructingParser.fromSource(scala.io.Source.fromString(x), preserveWS).document
890+
891+
// This was already correct in 1.0.5
892+
assertEquals(x, d.toString)
893+
}
894+
895+
@UnitTest
896+
def preserveSpaceBetweenEntitiesOptionDisabledIssue107: Unit = {
897+
val x = "<div>&lt; &lt;</div>"
898+
899+
val preserveWS = false
900+
901+
val d = ConstructingParser.fromSource(scala.io.Source.fromString(x), preserveWS).document
902+
903+
// This was already correct in 1.0.5
904+
assertEquals(x, d.toString)
905+
}
906+
838907
@UnitTest
839908
def issue28: Unit = {
840909
val x = <x:foo xmlns:x="gaga"/>

0 commit comments

Comments
 (0)