From 67355603a8122f80f297c215db063414c75b5080 Mon Sep 17 00:00:00 2001 From: Juri Leino Date: Tue, 28 Mar 2023 17:09:04 +0200 Subject: [PATCH] [test] refactor serialize.xql The value for each serialization option is now paremeterized. --- .../src/test/xquery/xquery3/serialize.xql | 122 +++++++++--------- 1 file changed, 60 insertions(+), 62 deletions(-) diff --git a/exist-core/src/test/xquery/xquery3/serialize.xql b/exist-core/src/test/xquery/xquery3/serialize.xql index dae99b2939e..bea438d425f 100644 --- a/exist-core/src/test/xquery/xquery3/serialize.xql +++ b/exist-core/src/test/xquery/xquery3/serialize.xql @@ -174,6 +174,13 @@ declare variable $ser:xi-doc := document { }; +declare variable $ser:in-memory-book := + + John Doe + Robert Smith + +; + declare %test:setUp function ser:setup() { @@ -665,126 +672,117 @@ function ser:adaptive-xs-strings-map-params() { }; declare + %test:args("true") %test:assertXPath("contains($result, '-//OASIS//DTD DITA BookMap//EN') and contains($result, 'bookmap.dtd')") -function ser:exist-output-doctype-true() { + %test:args("false") + %test:assertXPath("not(contains($result, '-//OASIS//DTD DITA BookMap//EN')) and not(contains($result, 'bookmap.dtd'))") +function ser:exist-output-doctype-QName($value as xs:boolean) { serialize(doc($ser:collection || "/test-with-doctype.xml"), - map { "exist:output-doctype": true() }) + map { xs:QName("exist:output-doctype") : $value }) }; declare + %test:args("true") %test:assertXPath("contains($result, '-//OASIS//DTD DITA BookMap//EN') and contains($result, 'bookmap.dtd')") -function ser:exist-output-doctype-true-QName() { - serialize(doc($ser:collection || "/test-with-doctype.xml"), - map { xs:QName("exist:output-doctype"): true() }) -}; - -declare + %test:args("false") %test:assertXPath("not(contains($result, '-//OASIS//DTD DITA BookMap//EN')) and not(contains($result, 'bookmap.dtd'))") -function ser:exist-output-doctype-false() { +function ser:exist-output-doctype-string($value as xs:boolean) { serialize(doc($ser:collection || "/test-with-doctype.xml"), - map { "exist:output-doctype": false() }) -}; - -declare - %test:assertXPath("contains($result, 'include')") -function ser:exist-expand-xinclude-false() { - serialize($ser:xi-doc, - map { "exist:expand-xincludes": false() }) + map { "exist:output-doctype" : $value }) }; declare + %test:args("true") %test:assertXPath("contains($result, 'comment')") -function ser:exist-expand-xinclude-true() { + %test:args("false") + %test:assertXPath("contains($result, 'include')") +function ser:exist-expand-xinclude-QName($value as xs:boolean) { serialize($ser:xi-doc, - map { "exist:expand-xincludes": true() }) + map { xs:QName("exist:expand-xincludes"): $value }) }; declare + %test:args("true") %test:assertXPath("contains($result, 'comment')") -function ser:exist-expand-xinclude-true-QName() { + %test:args("false") + %test:assertXPath("contains($result, 'include')") +function ser:exist-expand-xinclude-string($value as xs:boolean) { serialize($ser:xi-doc, - map { xs:QName("exist:expand-xincludes"): true() }) + map { "exist:expand-xincludes": $value }) }; declare + %test:args("all") %test:assertEquals('123') -function ser:exist-add-exist-id-all() { + %test:args("element") + %test:assertEquals('123') + %test:args("none") + %test:assertXPath("not(contains($result, 'exist:id'))") +function ser:exist-add-exist-id-QName($value as xs:string) { serialize(doc($ser:collection || "/test.xml"), - map { "exist:add-exist-id": "all" }) + map { xs:QName("exist:add-exist-id"): $value }) }; declare + %test:args("all") %test:assertEquals('123') -function ser:exist-add-exist-id-all-QName() { - serialize(doc($ser:collection || "/test.xml"), - map { xs:QName("exist:add-exist-id"): "all" }) -}; - -declare + %test:args("element") %test:assertEquals('123') -function ser:exist-add-exist-id-element() { - serialize(doc($ser:collection || "/test.xml"), - map { "exist:add-exist-id": "element" }) -}; - -declare - %test:assertXPath("not(contains($result, 'exist:id'))") -function ser:exist-add-exist-id-none() { + %test:args("none") + %test:assertXPath("not(contains($result, 'exist:id'))") +function ser:exist-add-exist-id-string($value as xs:string) { serialize(doc($ser:collection || "/test.xml"), - map { "exist:add-exist-id": "none" }) + map { "exist:add-exist-id": $value }) }; declare + %test:args("functionName") %test:assertEquals('functionName({"author":["John Doe","Robert Smith"]})') -function ser:exist-jsonp() { - serialize( - - John Doe - Robert Smith - , + %test:args("anotherName") + %test:assertEquals('anotherName({"author":["John Doe","Robert Smith"]})') +function ser:exist-jsonp-QName($value as xs:string) { + serialize($ser:in-memory-book, map { "method": "json", "media-type": "application/json", - "exist:jsonp": "functionName" + xs:QName("exist:jsonp"): $value } ) }; declare + %test:args("functionName") %test:assertEquals('functionName({"author":["John Doe","Robert Smith"]})') -function ser:exist-jsonp-QName() { - serialize( - - John Doe - Robert Smith - , + %test:args("anotherName") + %test:assertEquals('anotherName({"author":["John Doe","Robert Smith"]})') +function ser:exist-jsonp-string($value as xs:string) { + serialize($ser:in-memory-book, map { "method": "json", "media-type": "application/json", - xs:QName("exist:jsonp"): "functionName" + "exist:jsonp": $value } ) }; declare + %test:args("true") %test:assertEquals('processed') -function ser:exist-process-xsl-pi-true() { + %test:args("false") + %test:assertXPath("contains($result, 'stylesheet')") +function ser:exist-process-xsl-pi-QName($value as xs:boolean) { serialize(doc($ser:collection || "/test-xsl.xml"), - map { "exist:process-xsl-pi": true() }) + map { xs:QName("exist:process-xsl-pi"): $value }) }; declare + %test:args("true") %test:assertEquals('processed') -function ser:exist-process-xsl-pi-true-QName() { - serialize(doc($ser:collection || "/test-xsl.xml"), - map { xs:QName("exist:process-xsl-pi"): true() }) -}; - -declare + %test:args("false") %test:assertXPath("contains($result, 'stylesheet')") -function ser:exist-process-xsl-pi-false() { +function ser:exist-process-xsl-pi-string($value as xs:boolean) { serialize(doc($ser:collection || "/test-xsl.xml"), - map { "exist:process-xsl-pi": false() }) + map { "exist:process-xsl-pi": $value }) }; declare