Skip to content

Commit

Permalink
Map construction: combine → duplicate. qt4cg/qtspecs#1740
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianGruen committed Jan 31, 2025
1 parent 9b75251 commit e20c5a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 34 deletions.
21 changes: 5 additions & 16 deletions map/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
return map:build(1 to count($fortnight),
keys := function($n){$fortnight[$n]},
value := identity#1,
options := {'combine' : op('*')})
options := {'duplicates' : op('*')})
?Tuesday
</test>
<result>
Expand Down Expand Up @@ -167,17 +167,6 @@
</result>
</test-case>

<test-case name="map-build-012">
<description>duplicates option and combine option both present</description>
<created by="Michael Kay, Saxonica" on="2025-01-29"/>
<test>
map:build((1, 2, 3, 1.0e0), options:={'duplicates':'use-first', 'combine':concat#2})
</test>
<result>
<error code="FORG0013"/>
</result>
</test-case>

<test-case name="map-build-013">
<description>duplicates option with keys and values</description>
<created by="Michael Kay, Saxonica" on="2025-01-29"/>
Expand Down Expand Up @@ -406,7 +395,7 @@
<created by="Michael Kay" on="2024-03-13"/>
<modified by="Michael Kay, Saxonica" on="2025-01-29" change="combine is now part of options"/>
<test>let $m := map:build(tokenize("The cat sat on the mat"),
characters#1, upper-case#1, {'combine': concat#2})
characters#1, upper-case#1, {'duplicates': concat#2})
let $n := fold-left(tokenize("The cat sat on the mat"), map { }, fn($map, $item) {
let $v := upper-case($item)
return fold-left(characters($item), $map, fn($m, $k) {
Expand Down Expand Up @@ -467,11 +456,11 @@
<description>Test equivalence of another implementation given in spec</description>
<created by="Michael Kay" on="2025-01-29"/>
<test>let $m := map:build(tokenize("The cat sat on the mat"), characters#1, upper-case#1,
options := {'combine':concat#2})
options := {'duplicates':concat#2})
let $n := ((for $item in tokenize("The cat sat on the mat")
let $val := upper-case($item)
for $key in characters($item)
return map:pair($key, $val) ) => map:of-pairs({'combine':concat#2}))
return map:pair($key, $val) ) => map:of-pairs({'duplicates':concat#2}))
return deep-equal(trace(serialize($m, {'method':'adaptive'}), '$m'),
trace(serialize($n, {'method':'adaptive'}), '$n'))
</test>
Expand Down Expand Up @@ -636,7 +625,7 @@
<created by="Michael Kay" on="2024-06-26"/>
<test>map:build(("A", "B", "C", "A"),
value := fn($it, $pos){$pos},
options := {'combine' : op('+')})</test>
options := {'duplicates' : op('+')})</test>
<result>
<assert-deep-eq>map{"A":5, "B":2, "C":3}</assert-deep-eq>
</result>
Expand Down
23 changes: 5 additions & 18 deletions map/of-pairs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<test>map:of-pairs(((1 to 20) ! map{'key':., 'value':.+1},
map{'key':13, 'value':82},
map{'key':13, 'value':11}),
{'combine': op('+')})</test>
{'duplicates': op('+')})</test>
<result>
<all-of>
<assert-count>1</assert-count>
Expand All @@ -113,7 +113,7 @@
<test>map:of-pairs(((1 to 20) ! map{'key':., 'value':.+1},
map{'key':13, 'value':82},
map{'key':13, 'value':11}),
{'combine':function($a,$b){$b}})</test>
{'duplicates':function($a,$b){$b}})</test>
<result>
<all-of>
<assert-count>1</assert-count>
Expand All @@ -129,7 +129,7 @@
<created by="Michael Kay, Saxonica" on="2023-05-07"/>
<environment ref="map"/>
<test>map:of-pairs(((1 to 20) ! map{'key':., 'value':.+1}, map{'key':13, 'value':82}, map{'key':13, 'value':11}),
{'combine':function($a,$b){error(xs:QName('map:duplicates'))}})</test>
{'duplicates':function($a,$b){error(xs:QName('map:duplicates'))}})</test>
<result>
<error code="Q{http://www.w3.org/2005/xpath-functions/map}duplicates"/>
</result>
Expand All @@ -140,7 +140,7 @@
<created by="Michael Kay, Saxonica" on="2023-05-07"/>
<environment ref="map"/>
<test>map:of-pairs(((1 to 20) ! map{'key':., 'value':.+1}, map{'key':xs:float('NaN'), 'value':82}, map{'key':xs:double('NaN'), 'value':11}),
{'combine':op('+')})</test>
{'duplicates':op('+')})</test>
<result>
<all-of>
<assert-count>1</assert-count>
Expand Down Expand Up @@ -358,18 +358,5 @@
<result>
<assert-deep-eq>map{'26':42}</assert-deep-eq>
</result>
</test-case>

<test-case name="map-of-pairs-907">
<description>Can't have both combine and duplicates</description>
<created by="Michael Kay, Saxonica" on="205-01-29"/>
<environment ref="map"/>
<test><![CDATA[map:of-pairs(map:pairs({'a':1}),
{'duplicates':'use-last', 'combine':concat#2})]]></test>
<result>
<error code="FORG0013"/>
</result>
</test-case>


</test-case>
</test-set>

0 comments on commit e20c5a0

Please sign in to comment.