|
| 1 | + |
| 2 | +(: |
| 3 | + : eXist-db Open Source Native XML Database |
| 4 | + : Copyright (C) 2001 The eXist-db Authors |
| 5 | + : |
| 6 | + |
| 7 | + : http://www.exist-db.org |
| 8 | + : |
| 9 | + : This library is free software; you can redistribute it and/or |
| 10 | + : modify it under the terms of the GNU Lesser General Public |
| 11 | + : License as published by the Free Software Foundation; either |
| 12 | + : version 2.1 of the License, or (at your option) any later version. |
| 13 | + : |
| 14 | + : This library is distributed in the hope that it will be useful, |
| 15 | + : but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | + : Lesser General Public License for more details. |
| 18 | + : |
| 19 | + : You should have received a copy of the GNU Lesser General Public |
| 20 | + : License along with this library; if not, write to the Free Software |
| 21 | + : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 | + :) |
| 23 | + (:~ |
| 24 | + : @see https://github.com/eXist-db/exist/issues/4518 |
| 25 | + :) |
| 26 | +xquery version "3.1"; |
| 27 | + |
| 28 | +module namespace ca="http://exist-db.org/xquery/test"; |
| 29 | + |
| 30 | +declare namespace test="http://exist-db.org/xquery/xqsuite"; |
| 31 | + |
| 32 | +(: atomic values not explicitly converted to strings were falsely returning false to _castable_as_ |
| 33 | + in other words, all these tests were returning nc="false" |
| 34 | +:) |
| 35 | +declare |
| 36 | +%test:args("ixml") %test:assertEquals("<result name=""ixml"" nc=""true""/>") |
| 37 | +%test:args("comment") %test:assertEquals("<result name=""comment"" nc=""true""/>") |
| 38 | +%test:args("apple-jack") %test:assertEquals("<result name=""apple-jack"" nc=""true""/>") |
| 39 | +%test:args("123") %test:assertEquals("<result name=""123"" nc=""false""/>") |
| 40 | +%test:args("élève") %test:assertEquals("<result name=""élève"" nc=""true""/>") |
| 41 | +%test:args("pfx:suffix") %test:assertEquals("<result name=""pfx:suffix"" nc=""false""/>") |
| 42 | +function ca:n-castable($d) { |
| 43 | + let $doc := <e name="e"><f n="{$d}"/></e> |
| 44 | + let $el := $doc/descendant::*[exists(@n)] |
| 45 | + let $n := $el/@n |
| 46 | + return <result name="{$n}" nc="{$n castable as xs:NCName}"/> |
| 47 | +}; |
| 48 | + |
| 49 | +(: explicit string conversion was always working - for reference :) |
| 50 | +declare |
| 51 | +%test:args("ixml") %test:assertEquals("<result name=""ixml"" nc=""true""/>") |
| 52 | +%test:args("comment") %test:assertEquals("<result name=""comment"" nc=""true""/>") |
| 53 | +%test:args("apple-jack") %test:assertEquals("<result name=""apple-jack"" nc=""true""/>") |
| 54 | +%test:args("123") %test:assertEquals("<result name=""123"" nc=""false""/>") |
| 55 | +%test:args("élève") %test:assertEquals("<result name=""élève"" nc=""true""/>") |
| 56 | +%test:args("pfx:suffix") %test:assertEquals("<result name=""pfx:suffix"" nc=""false""/>") |
| 57 | +function ca:s-castable($d) { |
| 58 | + let $doc := <e name="e"><f n="{$d}"/></e> |
| 59 | + let $el := $doc/descendant::*[exists(@n)] |
| 60 | + let $n := $el/@n, $s := string($n) |
| 61 | + return <result name="{$n}" nc="{$s castable as xs:NCName}"/> |
| 62 | +}; |
| 63 | + |
| 64 | +(: sanity check that casting accepts the same values as castable as :) |
| 65 | +declare |
| 66 | +%test:args("ixml") %test:assertEquals("<result name=""ixml"" nc=""true""/>") |
| 67 | +%test:args("comment") %test:assertEquals("<result name=""comment"" nc=""true""/>") |
| 68 | +%test:args("apple-jack") %test:assertEquals("<result name=""apple-jack"" nc=""true""/>") |
| 69 | +%test:args("123") %test:assertError("err:") |
| 70 | +%test:args("élève") %test:assertEquals("<result name=""élève"" nc=""true""/>") |
| 71 | +%test:args("pfx:suffix") %test:assertError("err:") |
| 72 | +function ca:s-cast-castable($d) { |
| 73 | + let $doc := <e name="e"><f n="{$d}"/></e> |
| 74 | + let $el := $doc/descendant::*[exists(@n)] |
| 75 | + let $n := $el/@n, $ncname := xs:NCName($n) |
| 76 | + return <result name="{$n}" nc="{$ncname castable as xs:NCName}"/> |
| 77 | +}; |
| 78 | + |
| 79 | + |
0 commit comments