Skip to content

Fix PIs appearing before text nodes. #34

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

Merged
merged 1 commit into from
Dec 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/scala/scala/xml/parsing/FactoryAdapter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node
* Processing instruction.
*/
override def processingInstruction(target: String, data: String) {
captureText()
hStack pushAll createProcInstr(target, data)
}
}
53 changes: 53 additions & 0 deletions src/test/scala/scala/xml/parsing/PiParsingTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package scala.xml.parsing

import org.junit.Test
import org.junit.Ignore
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import scala.xml.JUnitAssertsForXML.assertEquals

class PiParsingTest {


import scala.io.Source.fromString
import scala.xml.parsing.ConstructingParser.fromSource
import scala.xml.TopScope
private def parse(s:String) = fromSource(fromString(s), preserveWS = true).element(TopScope)
private def parseNoWS(s:String) = fromSource(fromString(s), preserveWS = false).element(TopScope)

@Test
def piNoWSparse: Unit = {
val expected = "<foo>a<?pi?>b</foo>"
assertEquals(expected, parseNoWS("<foo>a<?pi?>b</foo>"))
}

@Test
def piNoWSLiteral: Unit = {
val expected = "<foo>a<?pi?>b</foo>"
assertEquals(expected, <foo>a<?pi?>b</foo>)
}

@Test
def piNoWSloadString: Unit = {
val expected = "<foo>a<?pi?>b</foo>"
assertEquals(expected, xml.XML.loadString("<foo>a<?pi?>b</foo>"))
}

@Test
def piParse: Unit = {
val expected = "<foo> a <?pi?> b </foo>"
assertEquals(expected, parse("<foo> a <?pi?> b </foo>"))
}

@Test
def piLoadString: Unit = {
val expected = "<foo> a <?pi?> b </foo>"
assertEquals(expected, xml.XML.loadString("<foo> a <?pi?> b </foo>"))
}
@Test
def piLiteral: Unit = {
val expected = "<foo> a <?pi?> b </foo>"
assertEquals(expected, <foo> a <?pi?> b </foo>)
}

}