Skip to content

Commit

Permalink
Preserve attribute order in inline XML
Browse files Browse the repository at this point in the history
  • Loading branch information
khernyo committed Jan 14, 2012
1 parent 066b1a1 commit 126469f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
Expand Up @@ -117,7 +117,7 @@ trait MarkupParsers {
* | `{` scalablock `}`
*/
def xAttributes = {
val aMap = mutable.HashMap[String, Tree]()
val aMap = mutable.LinkedHashMap[String, Tree]()

while (isNameStart(ch)) {
val start = curOffset
Expand Down
4 changes: 2 additions & 2 deletions test/files/jvm/serialization.check
Expand Up @@ -206,7 +206,7 @@ x equals y: true, y equals x: true

x = <html>
<body>
<table cellspacing="0" cellpadding="2">
<table cellpadding="2" cellspacing="0">
<tr>
<th>Last Name</th>
<th>First Name</th>
Expand All @@ -226,7 +226,7 @@ x = <html>
</html>
y = <html>
<body>
<table cellspacing="0" cellpadding="2">
<table cellpadding="2" cellspacing="0">
<tr>
<th>Last Name</th>
<th>First Name</th>
Expand Down
12 changes: 12 additions & 0 deletions test/files/run/xml-attribute.check
@@ -0,0 +1,12 @@
<t></t>
<t></t>
<t></t>
<t></t>
<t></t>
<t b="1" d="2"></t>
<t b="1" d="2"></t>
<t b="1" d="2"></t>
<t a="1" d="2"></t>
<t b="1" d="2"></t>
<t a="1" b="2" c="3"></t>
<t g="1" e="2" p:a="3" f:e="4" mgruhu:ji="5"></t>
24 changes: 14 additions & 10 deletions test/files/run/xml-attribute.scala
Expand Up @@ -12,22 +12,26 @@ object Test {
assert(noAttr == preAttrNull)
assert(noAttr == preAttrNone)

val noAttrStr = "<t></t>"
assert(noAttr.toString() == noAttrStr)
assert(attrNull.toString() == noAttrStr)
assert(attrNone.toString() == noAttrStr)
assert(preAttrNull.toString() == noAttrStr)
assert(preAttrNone.toString() == noAttrStr)
println(noAttr)
println(attrNull)
println(attrNone)
println(preAttrNull)
println(preAttrNone)

val xml1 = <t b="1" d="2"/>
val xml2 = <t a={ null: String } p:a={ null: String } b="1" c={ null: String } d="2"/>
val xml3 = <t b="1" c={ null: String } d="2" a={ null: String } p:a={ null: String }/>
assert(xml1 == xml2)
assert(xml1 == xml3)

val xml1Str = "<t d=\"2\" b=\"1\"></t>"
assert(xml1.toString() == xml1Str)
assert(xml2.toString() == xml1Str)
assert(xml3.toString() == xml1Str)
println(xml1)
println(xml2)
println(xml3)

// Check if attribute order is retained
println(<t a="1" d="2"/>)
println(<t b="1" d="2"/>)
println(<t a="1" b="2" c="3"/>)
println(<t g="1" e="2" p:a="3" f:e="4" mgruhu:ji="5"/>)
}
}
2 changes: 1 addition & 1 deletion test/scaladoc/scala/html/HtmlFactoryTest.scala
Expand Up @@ -192,7 +192,7 @@ object Test extends Properties("HtmlFactory") {
val html = node.toString
html.contains("<span title=\"gt4s: $plus$colon\" class=\"name\">+:</span>") &&
html.contains("<span title=\"gt4s: $minus$colon\" class=\"name\">-:</span>") &&
html.contains("""<span class="params">(<span name="n">n: <span name="scala.Int" class="extype">Int</span></span>)</span><span class="result">: <span name="scala.Int" class="extype">Int</span></span>""")
html.contains("""<span class="params">(<span name="n">n: <span class="extype" name="scala.Int">Int</span></span>)</span><span class="result">: <span class="extype" name="scala.Int">Int</span></span>""")
}
case _ => false
}
Expand Down

0 comments on commit 126469f

Please sign in to comment.