-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtail-recursion.xml
More file actions
118 lines (102 loc) · 4.22 KB
/
Copy pathtail-recursion.xml
File metadata and controls
118 lines (102 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?xml version="1.0" encoding="UTF-8"?>
<!--
Elemental
Copyright (C) 2024, Evolved Binary Ltd
admin@evolvedbinary.com
https://www.evolvedbinary.com | https://www.elemental.xyz
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; version 2.1.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
NOTE: Parts of this file contain code from 'The eXist-db Authors'.
The original license header is included below.
=====================================================================
eXist-db Open Source Native XML Database
Copyright (C) 2001 The eXist-db Authors
info@exist-db.org
http://www.exist-db.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-->
<TestSet>
<testName>tail-recursion tests</testName>
<description>
<p>tail-recursion tests</p>
<author>LordGeoffrey</author>
</description>
<setup>
<create-collection parent="/db" name="test-correct-error"/>
</setup>
<!--
<test output="text">
<task>tail-recursion test</task>
<code>
declare function local:plus($x) {
if ($x > 0)
then $x + local:plus($x - 1)
else 0
};
local:plus(1000)
</code>
<expected>500500</expected>
</test>
-->
<test output="text">
<task>tail-recursion test</task>
<code>
declare function local:plus($x, $total) {
if ($x > 0)
then local:plus($x - 1, $total+$x)
else $total
};
local:plus(1000, 0)
</code>
<expected>500500</expected>
</test>
<test output="text">
<!-- See: https://github.com/eXist-db/exist/issues/5139 -->
<task>correct-error</task>
<code><![CDATA[
xquery version "3.1";
declare function local:parent-collection($collection-path as xs:string) as xs:string? {
let $parent-collection-path := replace($collection-path, "(/.+)/.*", "$1")
return
if ($parent-collection-path eq $collection-path or not(starts-with($parent-collection-path, "/db")))
then
()
else
$parent-collection-path
};
declare %private function local:ascend($collection-path as xs:string, $group-name as xs:string, $collection-permission as xs:string) as empty-sequence() {
if (not(starts-with($collection-path, "/db")))
then
()
else
let $_ := sm:add-group-ace(xs:anyURI($collection-path), $group-name, true(), $collection-permission)
return
local:ascend(local:parent-collection($collection-path), $group-name, $collection-permission)
};
try {
local:ascend("/db/test-correct-error", "guest", "r-x")
} catch * {
substring-before($err:description, ", source:")
}
]]></code>
<expected>exerr:ERROR XPTY0004: The actual cardinality for parameter 1 does not match the cardinality declared in the function's signature: local:ascend($collection-path as xs:string, $group-name as xs:string, $collection-permission as xs:string) empty-sequence(). Expected cardinality: exactly one, got 0. [at line 21, column 26</expected>
</test>
</TestSet>