|
| 1 | +(: |
| 2 | + : eXist-db Open Source Native XML Database |
| 3 | + : Copyright (C) 2001 The eXist-db Authors |
| 4 | + : |
| 5 | + |
| 6 | + : http://www.exist-db.org |
| 7 | + : |
| 8 | + : This library is free software; you can redistribute it and/or |
| 9 | + : modify it under the terms of the GNU Lesser General Public |
| 10 | + : License as published by the Free Software Foundation; either |
| 11 | + : version 2.1 of the License, or (at your option) any later version. |
| 12 | + : |
| 13 | + : This library is distributed in the hope that it will be useful, |
| 14 | + : but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | + : Lesser General Public License for more details. |
| 17 | + : |
| 18 | + : You should have received a copy of the GNU Lesser General Public |
| 19 | + : License along with this library; if not, write to the Free Software |
| 20 | + : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | + :) |
| 22 | +xquery version "3.1"; |
| 23 | + |
| 24 | +module namespace mft="http://exist-db.org/xquery/test/maps"; |
| 25 | + |
| 26 | +import module namespace test="http://exist-db.org/xquery/xqsuite" at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql"; |
| 27 | + |
| 28 | +declare |
| 29 | + %test:assertEmpty |
| 30 | +function mft:find-map-001() { |
| 31 | + let $s := () |
| 32 | + return array:flatten(map:find($s, 17)) |
| 33 | +}; |
| 34 | + |
| 35 | +declare |
| 36 | + %test:args(1) |
| 37 | + %test:assertEquals("Sunday", "Dimanche") |
| 38 | + %test:args(8) |
| 39 | + %test:assertEmpty |
| 40 | +function mft:find-map-004($param) { |
| 41 | + let $m1 := map{1:"Sunday",2:"Monday",3:"Tuesday",4:"Wednesday",5:"Thursday",6:"Friday",7:"Saturday"} |
| 42 | + let $m2 := map{2:"Lundi",3:"Mardi",4:"Mercredi",5:"Jeudi",6:"Vendredi",7:"Samedi",1:"Dimanche"} |
| 43 | + let $s := ($m1,$m2) |
| 44 | + return array:flatten(map:find($s, $param)) |
| 45 | +}; |
| 46 | + |
| 47 | +declare |
| 48 | + %test:args(1) |
| 49 | + %test:assertEquals("Sunday", "Dimanche") |
| 50 | + %test:args(8) |
| 51 | + %test:assertEmpty |
| 52 | +function mft:find-map-004-all-values($param) { |
| 53 | + let $m1 := map{1:"Sunday",2:"Monday",3:"Tuesday",4:"Wednesday",5:"Thursday",6:"Friday",7:"Saturday"} |
| 54 | + let $m2 := map{2:"Lundi",3:"Mardi",4:"Mercredi",5:"Jeudi",6:"Vendredi",7:"Samedi",1:"Dimanche"} |
| 55 | + let $s := ($m1,$m2) |
| 56 | + return array:flatten(map:find($s, $param)) |
| 57 | +}; |
| 58 | + |
| 59 | +declare |
| 60 | + %test:args(1) |
| 61 | + %test:assertEquals("Sunday", "Dimanche") |
| 62 | + %test:args(8) |
| 63 | + %test:assertEmpty |
| 64 | +function mft:find-map-006-ignore-non-collection-in-seq($param) { |
| 65 | + let $m1 := map{1:"Sunday",2:"Monday",3:"Tuesday",4:"Wednesday",5:"Thursday",6:"Friday",7:"Saturday"} |
| 66 | + let $m2 := map{2:"Lundi",3:"Mardi",4:"Mercredi",5:"Jeudi",6:"Vendredi",7:"Samedi",1:"Dimanche"} |
| 67 | + let $s := ($m1,$m2,1) |
| 68 | + return array:flatten(map:find($s, $param)) |
| 69 | +}; |
| 70 | + |
| 71 | +declare |
| 72 | + %test:args(1) |
| 73 | + %test:assertEquals("Sunday", "Dimanche") |
| 74 | + %test:args(8) |
| 75 | + %test:assertEmpty |
| 76 | +function mft:find-map-006-ignore-non-collection-in-array($param) { |
| 77 | + let $m1 := map{1:"Sunday",2:"Monday",3:"Tuesday",4:"Wednesday",5:"Thursday",6:"Friday",7:"Saturday"} |
| 78 | + let $m2 := map{2:"Lundi",3:"Mardi",4:"Mercredi",5:"Jeudi",6:"Vendredi",7:"Samedi",1:"Dimanche"} |
| 79 | + let $s := [$m1,$m2,1] |
| 80 | + return array:flatten(map:find($s, $param)) |
| 81 | +}; |
| 82 | + |
| 83 | +declare |
| 84 | + %test:args(1) |
| 85 | + %test:assertEquals("Sunday", "Dimanche") |
| 86 | + %test:args(8) |
| 87 | + %test:assertEmpty |
| 88 | +function mft:find-map-007-inner-maps($param) { |
| 89 | + let $m1 := map{1:"Sunday",2:"Monday",3:"Tuesday",4:"Wednesday",5:"Thursday",6:"Friday",7:"Saturday"} |
| 90 | + let $m2 := map{2:"Lundi",3:"Mardi",4:"Mercredi",5:"Jeudi",6:"Vendredi",7:"Samedi",1:"Dimanche"} |
| 91 | + let $m3 := map{"fr":$m2} |
| 92 | + let $s := [$m1,$m3] |
| 93 | + return array:flatten(map:find($s, $param)) |
| 94 | +}; |
| 95 | + |
| 96 | +declare |
| 97 | + %test:args(6) |
| 98 | + %test:assertEmpty |
| 99 | + %test:args(7) |
| 100 | + %test:assertEquals("Saturday") |
| 101 | +function mft:find-map($param) { |
| 102 | + let $m := map { 7 : "Saturday" } |
| 103 | + return array:flatten(map:find($m, $param)) |
| 104 | +}; |
| 105 | + |
| 106 | +declare |
| 107 | + %test:args(6) |
| 108 | + %test:assertEmpty |
| 109 | + %test:args(5) |
| 110 | + %test:assertEquals("Thursday") |
| 111 | +function mft:find-seq($param) { |
| 112 | + let $m1 := map { 7 : "Saturday" } |
| 113 | + let $m2 := map { 5 : "Thursday" } |
| 114 | + let $s := ($m1,$m2) |
| 115 | + return array:flatten(map:find($s, $param)) |
| 116 | +}; |
| 117 | + |
| 118 | +declare variable $mft:inner-map := map { 5 : "Thursday", 6: "Friday" }; |
| 119 | + |
| 120 | +declare |
| 121 | + %test:args(3) |
| 122 | + %test:assertEmpty |
| 123 | + %test:args(5) |
| 124 | + %test:assertEquals("Thursday") |
| 125 | + %test:args(6) |
| 126 | + %test:assertEquals("Friday") |
| 127 | +function mft:find-inner($param) { |
| 128 | + let $s := [map { 7 : "Saturday" }, map { 4 : $mft:inner-map}] |
| 129 | + return array:flatten(map:find($s, $param)) |
| 130 | +}; |
| 131 | + |
| 132 | +declare |
| 133 | + %test:args(3) |
| 134 | + %test:assertFalse |
| 135 | + %test:args(4) |
| 136 | + %test:assertTrue |
| 137 | +function mft:find-inner-map($param) { |
| 138 | + let $s := [map { 7 : "Saturday" }, map { 4 : $mft:inner-map}] |
| 139 | + return fn:deep-equal(array:flatten(map:find($s, $param)), $mft:inner-map) |
| 140 | +}; |
| 141 | + |
| 142 | +(: from the xquery spec :) |
| 143 | +declare |
| 144 | + %test:args(0) |
| 145 | + %test:assertEquals('no', 'non', 'nein') |
| 146 | + %test:args(1) |
| 147 | + %test:assertEquals('yes', 'oui', 'ja', 'doch') |
| 148 | + %test:args(2) |
| 149 | + %test:assertEmpty |
| 150 | +function mft:find-spec($param) { |
| 151 | + let $responses := [map{0:'no', 1:'yes'}, map{0:'non', 1:'oui'}, |
| 152 | + map{0:'nein', 1:('ja', 'doch')}] |
| 153 | + return array:flatten(map:find($responses, $param)) |
| 154 | +}; |
| 155 | + |
0 commit comments