Closed faassen closed 7 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'):
map:keys
('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.
Given the XPath expression:
The test expects:
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:
then combining the values would result in: this map:
but that's not allowed according to the test.
A way to fix the test would be to sort the inverted sequence first.