Skip to content

Commit

Permalink
[test] refactor serialize.xql
Browse files Browse the repository at this point in the history
The value for each serialization option is now paremeterized.
  • Loading branch information
line-o committed Apr 25, 2023
1 parent 72f4c94 commit 6735560
Showing 1 changed file with 60 additions and 62 deletions.
122 changes: 60 additions & 62 deletions exist-core/src/test/xquery/xquery3/serialize.xql
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ declare variable $ser:xi-doc := document {
</article>
};

declare variable $ser:in-memory-book :=
<book>
<author>John Doe</author>
<author>Robert Smith</author>
</book>
;

declare
%test:setUp
function ser:setup() {
Expand Down Expand Up @@ -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('<?pi?><elem xmlns:exist="http://exist.sourceforge.net/NS/exist" exist:id="2" exist:source="test.xml" a="abc"><!--comment--><b exist:id="2.3">123</b></elem>')
function ser:exist-add-exist-id-all() {
%test:args("element")
%test:assertEquals('<?pi?><elem xmlns:exist="http://exist.sourceforge.net/NS/exist" exist:id="2" exist:source="test.xml" a="abc"><!--comment--><b>123</b></elem>')
%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('<?pi?><elem xmlns:exist="http://exist.sourceforge.net/NS/exist" exist:id="2" exist:source="test.xml" a="abc"><!--comment--><b exist:id="2.3">123</b></elem>')
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('<?pi?><elem xmlns:exist="http://exist.sourceforge.net/NS/exist" exist:id="2" exist:source="test.xml" a="abc"><!--comment--><b>123</b></elem>')
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(
<book>
<author>John Doe</author>
<author>Robert Smith</author>
</book>,
%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(
<book>
<author>John Doe</author>
<author>Robert Smith</author>
</book>,
%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
Expand Down

0 comments on commit 6735560

Please sign in to comment.