File tree 8 files changed +68
-2
lines changed
jvm/src/test/scala/scala/xml
8 files changed +68
-2
lines changed Original file line number Diff line number Diff line change
1
+ package scala .xml
2
+
3
+ import org .junit .Test
4
+ import org .junit .Assert .assertEquals
5
+ import org .junit .Assert .assertNotEquals
6
+
7
+ class AttributeTestJVM {
8
+
9
+ @ Test
10
+ def attributeOrder : Unit = {
11
+ val x = <x y =" 1" z =" 2" />
12
+ assertEquals(""" <x y="1" z="2"/>""" , x.toString)
13
+ }
14
+
15
+ @ Test
16
+ def attributesFromString : Unit = {
17
+ val str = """ <x y="1" z="2"/>"""
18
+ val doc = XML .loadString(str)
19
+ assertEquals(str, doc.toString)
20
+ }
21
+
22
+ @ Test
23
+ def attributesAndNamespaceFromString : Unit = {
24
+ val str = """ <x xmlns:w="w" y="1" z="2"/>"""
25
+ val doc = XML .loadString(str)
26
+ assertNotEquals(str, doc.toString)
27
+ val str2 = """ <x y="1" z="2" xmlns:w="w"/>"""
28
+ val doc2 = XML .loadString(str2)
29
+ assertEquals(str2, doc2.toString)
30
+ }
31
+
32
+ @ Test (expected= classOf [SAXParseException ])
33
+ def attributesFromStringWithDuplicate : Unit = {
34
+ val str = """ <elem one="test" one="test1" two="test2" three="test3"></elem>"""
35
+ XML .loadString(str)
36
+ }
37
+ }
Original file line number Diff line number Diff line change @@ -71,4 +71,14 @@ class ConstructingParserTest {
71
71
72
72
ConstructingParser .fromSource(source, true ).content(TopScope )
73
73
}
74
+
75
+ @ Test
76
+ def SI6341issue65 : Unit = {
77
+ val str = """ <elem one="test" two="test2" three="test3"/>"""
78
+ val cpa = ConstructingParser .fromSource(io.Source .fromString(str), preserveWS = true )
79
+ val cpadoc = cpa.document()
80
+ val ppr = new PrettyPrinter (80 ,5 )
81
+ val out = ppr.format(cpadoc.docElem)
82
+ assertEquals(str, out)
83
+ }
74
84
}
Original file line number Diff line number Diff line change @@ -155,6 +155,11 @@ abstract class MetaData
155
155
if (f(this )) copy(next filter f)
156
156
else next filter f
157
157
158
+ def reverse : MetaData =
159
+ foldLeft(Null : MetaData ) { (x, xs) =>
160
+ xs.copy(x)
161
+ }
162
+
158
163
/** returns key of this MetaData item */
159
164
def key : String
160
165
Original file line number Diff line number Diff line change @@ -158,7 +158,7 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node
158
158
if (scopeStack.isEmpty) TopScope
159
159
else scopeStack.head
160
160
161
- for (i <- 0 until attributes.getLength() ) {
161
+ for (i <- ( 0 until attributes.getLength).reverse ) {
162
162
val qname = attributes getQName i
163
163
val value = attributes getValue i
164
164
val (pre, key) = splitName(qname)
Original file line number Diff line number Diff line change @@ -339,7 +339,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
339
339
if (! aMap.wellformed(scope))
340
340
reportSyntaxError(" double attribute" )
341
341
342
- (aMap, scope)
342
+ (aMap.reverse , scope)
343
343
}
344
344
345
345
/**
Original file line number Diff line number Diff line change @@ -49,6 +49,11 @@ class AttributeTest {
49
49
}
50
50
51
51
@ Test
52
+ def attributeOrder : Unit = {
53
+ val x = <x y =" 1" z =" 2" />
54
+ assertEquals(""" <x y="1" z="2"/>""" , x.toString)
55
+ }
56
+
52
57
def attributeToString : Unit = {
53
58
val expected : String = """ <b x="&"/>"""
54
59
assertEquals(expected, (<b x =" & " />).toString)
Original file line number Diff line number Diff line change @@ -54,4 +54,11 @@ class MetaDataTest {
54
54
assertEquals(new Atom (3 ), domatch(z2))
55
55
}
56
56
57
+ @ Test
58
+ def reverseTest : Unit = {
59
+ assertEquals(" " , Null .reverse.toString)
60
+ assertEquals(""" b="c"""" , <a b =" c" />.attributes.reverse.toString)
61
+ assertEquals(""" d="e" b="c"""" , <a b =" c" d =" e" />.attributes.reverse.toString)
62
+ }
63
+
57
64
}
Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ class UtilityTest {
38
38
39
39
@ Test
40
40
def sort : Unit = {
41
+ assertEquals(" " , xml.Utility .sort(<a />.attributes).toString)
42
+ assertEquals(""" b="c"""" , xml.Utility .sort(<a b =" c" />.attributes).toString)
41
43
val q = xml.Utility .sort(<a g =' 3' j =' 2' oo =' 2' a =' 2' />)
42
44
assertEquals(" a=\" 2\" g=\" 3\" j=\" 2\" oo=\" 2\" " , xml.Utility .sort(q.attributes).toString)
43
45
val pp = new xml.PrettyPrinter (80 ,5 )
You can’t perform that action at this time.
0 commit comments