w3c / qt3tests

Tests for XPath and XQuery
27 stars 17 forks source link

map-merge-027 is dependent on implementation dependent order of keys #55

Closed faassen closed 7 months ago

faassen commented 11 months ago

Given the XPath expression:

let $m := map{'a': (1, 2), 'b': 2, 'c': 1, 'd': 3}
            return map:merge(
                for $key in map:keys($m) return for $val in map:get($m, $key) return map{$val : $key},
                map{'duplicates': 'combine'})

The test expects:

<assert>deep-equal($result(1), ("a", "c"))</assert>
<assert>deep-equal($result(2), ("a", "b"))</assert>
<assert>deep-equal($result(3), ("d"))</assert>

But isn't this dependent on the implementation-dependent order of keys?

If map:keys happens to produce ('d', 'c', 'b', 'a'):

then the inversion logic happens to produces a sequence with this structure:

({3: 'd'},  {'1': ''c'},  {'2': 'b'},  ({1: 'a'}, {2: 'a'}) 

then combining the values would result in: this map:

{1 : ('c', 'a'), 2 :  ('b', 'a'), 3: 'd'}

but that's not allowed according to the test.

A way to fix the test would be to sort the inverted sequence first.