Skip to content

Fix Decl.toString #270

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
Apr 4, 2019
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 shared/src/main/scala/scala/xml/dtd/Decl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Utility.sbToString
sealed abstract class Decl

sealed abstract class MarkupDecl extends Decl {
override def toString(): String = sbToString(buildString)
def buildString(sb: StringBuilder): StringBuilder
}

Expand Down
42 changes: 42 additions & 0 deletions shared/src/test/scala/scala/xml/dtd/DeclTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package scala.xml
package dtd

import org.junit.Test
import org.junit.Assert.assertEquals

class DeclTest {

@Test
def elemDeclToString: Unit = {
assertEquals(
"<!ELEMENT x (#PCDATA)>",
ElemDecl("x", PCDATA).toString
)
}

@Test
def attListDeclToString: Unit = {

val expected =
"""|<!ATTLIST x
| y CDATA #REQUIRED
| z CDATA #REQUIRED>""".stripMargin

val actual = AttListDecl("x",
List(
AttrDecl("y", "CDATA", REQUIRED),
AttrDecl("z", "CDATA", REQUIRED)
)
).toString

assertEquals(expected, actual)
}

@Test
def parsedEntityDeclToString: Unit = {
assertEquals(
"""<!ENTITY foo SYSTEM "bar">""",
ParsedEntityDecl("foo", ExtDef(SystemID("bar"))).toString
)
}
}