|
| 1 | +(: |
| 2 | + : Copyright (C) 2014, Evolved Binary Ltd |
| 3 | + : |
| 4 | + : This file was originally ported from FusionDB to eXist-db by |
| 5 | + : Evolved Binary, for the benefit of the eXist-db Open Source community. |
| 6 | + : Only the ported code as it appears in this file, at the time that |
| 7 | + : it was contributed to eXist-db, was re-licensed under The GNU |
| 8 | + : Lesser General Public License v2.1 only for use in eXist-db. |
| 9 | + : |
| 10 | + : This license grant applies only to a snapshot of the code as it |
| 11 | + : appeared when ported, it does not offer or infer any rights to either |
| 12 | + : updates of this source code or access to the original source code. |
| 13 | + : |
| 14 | + : The GNU Lesser General Public License v2.1 only license follows. |
| 15 | + : |
| 16 | + : --------------------------------------------------------------------- |
| 17 | + : |
| 18 | + : Copyright (C) 2014, Evolved Binary Ltd |
| 19 | + : |
| 20 | + : This library is free software; you can redistribute it and/or |
| 21 | + : modify it under the terms of the GNU Lesser General Public |
| 22 | + : License as published by the Free Software Foundation; version 2.1. |
| 23 | + : |
| 24 | + : This library is distributed in the hope that it will be useful, |
| 25 | + : but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 | + : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 27 | + : Lesser General Public License for more details. |
| 28 | + : |
| 29 | + : You should have received a copy of the GNU Lesser General Public |
| 30 | + : License along with this library; if not, write to the Free Software |
| 31 | + : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 32 | + :) |
| 33 | +xquery version "1.0"; |
| 34 | + |
| 35 | +module namespace ord = "http://exist-db.org/test/order"; |
| 36 | + |
| 37 | +declare namespace test = "http://exist-db.org/xquery/xqsuite"; |
| 38 | + |
| 39 | +declare variable $ord:items as element(item)+ := ( |
| 40 | + <item> |
| 41 | + <ref>e1</ref> |
| 42 | + <msDesc type="Ll"/> |
| 43 | + </item> |
| 44 | + , |
| 45 | + <item> |
| 46 | + <ref>e2</ref> |
| 47 | + <msDesc type="P"/> |
| 48 | + </item> |
| 49 | + , |
| 50 | + <item> |
| 51 | + <ref>e3</ref> |
| 52 | + <msDesc type="Ll"/> |
| 53 | + </item> |
| 54 | + , |
| 55 | + <item> |
| 56 | + <ref>e4</ref> |
| 57 | + <msDesc/> |
| 58 | + </item> |
| 59 | +); |
| 60 | + |
| 61 | +declare |
| 62 | + %test:assertEquals("e2", "e1", "e3", "e4") |
| 63 | +function ord:default-order-for-empty-sequence-is-empty-least() { |
| 64 | + for $item in $ord:items |
| 65 | + let $sort-condition as xs:boolean? := $item/msDesc/@type eq 'P' |
| 66 | + order by $sort-condition descending |
| 67 | + return |
| 68 | + $item/ref/string() |
| 69 | +}; |
| 70 | + |
| 71 | +declare |
| 72 | + %test:assertEquals("e2", "e1", "e3", "e4") |
| 73 | +function ord:order-empty-sequence-as-empty-least() { |
| 74 | + for $item in $ord:items |
| 75 | + let $sort-condition as xs:boolean? := $item/msDesc/@type eq 'P' |
| 76 | + order by $sort-condition descending empty least |
| 77 | + return |
| 78 | + $item/ref/string() |
| 79 | +}; |
| 80 | + |
| 81 | +declare |
| 82 | + %test:assertEquals("e4", "e2", "e1", "e3") |
| 83 | +function ord:order-empty-sequence-as-empty-greatest() { |
| 84 | + for $item in $ord:items |
| 85 | + let $sort-condition as xs:boolean? := $item/msDesc/@type eq 'P' |
| 86 | + order by $sort-condition descending empty greatest |
| 87 | + return |
| 88 | + $item/ref/string() |
| 89 | +}; |
0 commit comments