@@ -147,13 +147,13 @@ end
147147 @test text_content == " hello"
148148 n= XML. next (n)
149149 text_content = XML. write (n)
150- @test text_content == " <text3 xml:space=\" preserve\" >\n hello \n <text3b> preserve </text3b>\n </text3>"
150+ @test text_content == " <text3 xml:space=\" preserve\" > hello <text3b> preserve </text3b></text3>"
151151 n= XML. prev (n)
152152 text_content = XML. write (n)
153153 @test text_content == " hello"
154154 n= XML. next (n)
155155 text_content = XML. write (n)
156- @test text_content == " <text3 xml:space=\" preserve\" >\n hello \n <text3b> preserve </text3b>\n </text3>"
156+ @test text_content == " <text3 xml:space=\" preserve\" > hello <text3b> preserve </text3b></text3>"
157157 n= XML. next (n)
158158 text_content = XML. write (n)
159159 @test text_content == " hello "
@@ -183,13 +183,13 @@ end
183183 @test text_content == " hello "
184184 n= XML. prev (n)
185185 text_content = XML. write (n)
186- @test text_content == " <text3 xml:space=\" preserve\" >\n hello \n <text3b> preserve </text3b>\n </text3>"
186+ @test text_content == " <text3 xml:space=\" preserve\" > hello <text3b> preserve </text3b></text3>"
187187 n= XML. next (n)
188188 text_content = XML. write (n)
189189 @test text_content == " hello "
190190 n= XML. prev (n)
191191 text_content = XML. write (n)
192- @test text_content == " <text3 xml:space=\" preserve\" >\n hello \n <text3b> preserve </text3b>\n </text3>"
192+ @test text_content == " <text3 xml:space=\" preserve\" > hello <text3b> preserve </text3b></text3>"
193193 n= XML. prev (n)
194194 text_content = XML. write (n)
195195 @test text_content == " hello"
201201 @test text_content == " <text/>"
202202 n= XML. prev (n)
203203 text_content = XML. write (n)
204- @test text_content == " <root>\n <text/>\n <text2>hello</text2>\n <text3 xml:space=\" preserve\" >\n hello \n <text3b> preserve </text3b>\n </text3>\n <text4 xml:space=\" preserve\" />\n <text5/>\n </root>"
204+ @test text_content == " <root>\n <text/>\n <text2>hello</text2>\n <text3 xml:space=\" preserve\" > hello <text3b> preserve </text3b></text3>\n <text4 xml:space=\" preserve\" />\n <text5/>\n </root>"
205205 end
206206
207207 @testset " depth and parent" begin
@@ -428,19 +428,18 @@ end
428428 @test XML. value (d2[1 ][6 ][1 ]) == " after default gap "
429429 @test XML. value (d2[1 ][7 ]) == " \n "
430430 end
431-
432- # @testset "XML whitespace vs Unicode whitespace" begin
433- # nbsp = "\u00A0"
434- # s = """<root>
435- # <a> x\t\n </a>
436- # <b>$(nbsp) y $(nbsp)</b>
437- # <c xml:space="default">$(nbsp) z $(nbsp)</c>
438- # </root>"""
439- # d = XML.parse(XML.Node, s)
440- # @test XML.value(d[1][1][1]) == "x"
441- # @test XML.value(d[1][2][1]) == "$(nbsp) y $(nbsp)"
442- # @test XML.value(d[1][3][1]) == "$(nbsp) z $(nbsp)"
443- # end
431+ @testset " XML whitespace vs Unicode whitespace" begin
432+ nbsp = " \u 00A0"
433+ s = """ <root>
434+ <a> x\t\n </a>
435+ <b>$(nbsp) y $(nbsp) </b>
436+ <c xml:space="default">$(nbsp) z $(nbsp) </c>
437+ </root>"""
438+ d = XML. parse (XML. Node, s)
439+ @test XML. value (d[1 ][1 ][1 ]) == " x"
440+ @test XML. value (d[1 ][2 ][1 ]) == " $(nbsp) y $(nbsp) "
441+ @test XML. value (d[1 ][3 ][1 ]) == " $(nbsp) z $(nbsp) "
442+ end
444443
445444 @testset " CDATA/Comment/PI boundaries" begin
446445 s = """ <root>
@@ -485,17 +484,21 @@ end
485484 @test XML. value (d[1 ][1 ]) == " a"
486485 end
487486
488- # @testset "entities expanding to whitespace" begin
489- # s = """<root>
490- # <a>   a 
 </a>
491- # <b xml:space="preserve">  b 
</b>
492- # <c> c </c>
493- # </root>"""
494- # d = XML.parse(XML.Node, s)
495- # @test XML.value(d[1][1][1]) == "a"
496- # @test XML.value(d[1][2][1]) == " b \n"
497- # @test XML.value(d[1][3][1]) == "\u00A0c\u00A0"
498- # end
487+ @testset " entities expanding to whitespace" begin
488+ chr1= " \u 0020"
489+ chr2= " \u 000A"
490+ chr3= " \u 00A0"
491+
492+ s = """ <root>
493+ <a> $(chr1) a $(chr2) </a>
494+ <b xml:space="preserve">$(chr1) b $(chr2) </b>
495+ <c>$(chr3) c$(chr3) </c>
496+ </root>"""
497+ d = XML. parse (XML. Node, s)
498+ @test XML. value (d[1 ][1 ][1 ]) == " a"
499+ @test XML. value (d[1 ][2 ][1 ]) == " b \n "
500+ @test XML. value (d[1 ][3 ][1 ]) == " $(chr3) c$(chr3) "
501+ end
499502
500503 @testset " invalid values and placement" begin
501504 s_bad = """ <root><x xml:space="weird"> t </x></root>"""
@@ -534,23 +537,22 @@ end
534537 @test reverse (back)[2 : end ] == toks[1 : end - 1 ]
535538 end
536539
537- # @testset "write/read roundtrip extremes" begin
538- # XML.write doesn't respect xml:space="preserve" in the current implementation so roundtrip isn't possible.
539- # xml = """<root>
540- # <p xml:space="preserve"> </p>
541- # <q> </q>
542- # <r xml:space="default"> r </r>
543- # <s xml:space="preserve"> pre <t/> post </s>
544- # </root>"""
545- # n = XML.parse(XML.Node, xml)
546- # io = IOBuffer(); XML.write(io, n)
547- # n2 = XML.parse(XML.Node, String(take!(io)))
548- # @test n == n2
549- # @test XML.write(n2[1][1]) == "<p xml:space=\"preserve\"> </p>"
550- # @test XML.write(n2[1][2]) == "<q/>"
551- # @test XML.value(n2[1][3][1]) == "r"
552- # @test XML.write(n2[1][4]) == "<s xml:space=\"preserve\"> pre <t/> post </s>"
553- # end
540+ @testset " write/read roundtrip extremes" begin
541+ xml = """ <root>
542+ <p xml:space="preserve"> </p>
543+ <q> </q>
544+ <r xml:space="default"> r </r>
545+ <s xml:space="preserve"> pre <t/> post </s>
546+ </root>"""
547+ n = XML. parse (XML. Node, xml)
548+ io = IOBuffer (); XML. write (io, n)
549+ n2 = XML. parse (XML. Node, String (take! (io)))
550+ @test n == n2
551+ @test XML. write (n2[1 ][1 ]) == " <p xml:space=\" preserve\" > </p>"
552+ @test XML. write (n2[1 ][2 ]) == " <q/>"
553+ @test XML. value (n2[1 ][3 ][1 ]) == " r"
554+ @test XML. write (n2[1 ][4 ]) == " <s xml:space=\" preserve\" > pre <t/> post </s>"
555+ end
554556
555557 @testset " self-closing/empty/whitespace-only children" begin
556558 s = """ <root>
641643 xyz = XML. Element (" point" ; kw... )
642644 @test collect (keys (attributes (xyz))) == string .(collect (' a' :' z' ))
643645end
646+
0 commit comments