Revision 95470a2f
Von Sven Schöling vor mehr als 11 Jahren hinzugefügt
t/request/flatten.t | ||
---|---|---|
1 | 1 |
use Test::More; |
2 |
use Test::Deep; |
|
2 |
use Test::Deep qw(cmp_deeply);
|
|
3 | 3 |
use Data::Dumper; |
4 | 4 |
|
5 | 5 |
use_ok 'SL::Request', qw(flatten unflatten); |
... | ... | |
13 | 13 |
my $unflat = unflatten($flat); |
14 | 14 |
print Dumper($unflat) if DEBUG; |
15 | 15 |
|
16 |
cmp_deeply($flat, $_[1], $_[2]); |
|
17 |
cmp_deeply($unflat, $_[0], $_[2]); |
|
16 |
cmp_deeply($flat, $_[1], $_[2] . " flatten");
|
|
17 |
cmp_deeply($unflat, $_[0], $_[2] . " unflatten");
|
|
18 | 18 |
} |
19 | 19 |
|
20 | 20 |
f { |
... | ... | |
55 | 55 |
'q' => 4 |
56 | 56 |
}, |
57 | 57 |
} |
58 |
}, bag(
|
|
58 |
}, [
|
|
59 | 59 |
[ 'x' => 1, ], |
60 | 60 |
[ 'y.a' => 2, ], |
61 | 61 |
[ 'y.b.p' => 3, ], |
62 | 62 |
[ 'y.b.q' => 4 ], |
63 |
), 'Hash::Flatten 1';
|
|
63 |
], 'Hash::Flatten 1';
|
|
64 | 64 |
|
65 | 65 |
|
66 | 66 |
f { |
... | ... | |
70 | 70 |
}, |
71 | 71 |
'a' => [1,2,3], |
72 | 72 |
}, |
73 |
bag ( |
|
74 |
['x' => 1, ], |
|
73 |
[ |
|
75 | 74 |
['0.1' => 2, ], |
76 | 75 |
['a[]' => 1, ], |
77 | 76 |
['a[]' => 2, ], |
78 | 77 |
['a[]' => 3, ], |
79 |
), 'Hash::Flatten 2 - weird keys and values'; |
|
78 |
['x' => 1, ], |
|
79 |
], 'Hash::Flatten 2 - weird keys and values'; |
|
80 | 80 |
|
81 | 81 |
|
82 | 82 |
f { |
... | ... | |
95 | 95 |
}, |
96 | 96 |
] |
97 | 97 |
}, |
98 |
bag( |
|
98 |
[ |
|
99 |
[ 'ay.a' => 2, ], |
|
99 | 100 |
[ 'ay.b.p' => 3, ], |
100 | 101 |
[ 'ay.b.q' => 4, ], |
101 |
[ 'ay.a' => 2, ], |
|
102 | 102 |
[ 'x' => 1, ], |
103 | 103 |
[ 'y[]' => 'a', ], |
104 | 104 |
[ 'y[]' => 2 ], |
105 | 105 |
[ 'y[+].baz' => 'bum', ], |
106 |
), 'Hash::Flatten 3 - mixed';
|
|
106 |
], 'Hash::Flatten 3 - mixed';
|
|
107 | 107 |
|
108 | 108 |
f { |
109 | 109 |
'x' => 1, |
... | ... | |
117 | 117 |
'money', |
118 | 118 |
] |
119 | 119 |
}, |
120 |
bag(
|
|
120 |
[
|
|
121 | 121 |
[ 'x' => 1, ], |
122 |
[ 'y[][]' => 'his', ], |
|
123 |
[ 'y[][+][]' => 'parted', ], |
|
124 |
[ 'y[][][]' => 'from', ], |
|
125 | 122 |
[ 'y[+][]' => 'a', ], |
126 |
[ 'y[+][]' => 'easily', ], |
|
127 | 123 |
[ 'y[][]' => 'fool', ], |
128 | 124 |
[ 'y[][]' => 'is' ], |
125 |
[ 'y[+][]' => 'easily', ], |
|
126 |
[ 'y[][+][]' => 'parted', ], |
|
127 |
[ 'y[][][]' => 'from', ], |
|
128 |
[ 'y[][]' => 'his', ], |
|
129 | 129 |
[ 'y[]' => 'money', ], |
130 |
), 'Hash::Flatten 4 - array nesting';
|
|
130 |
], 'Hash::Flatten 4 - array nesting';
|
|
131 | 131 |
|
132 | 132 |
f { |
133 | 133 |
'x' => 1, |
... | ... | |
145 | 145 |
}, |
146 | 146 |
] |
147 | 147 |
}, |
148 |
bag( |
|
149 |
[ 'x' => 1, ], |
|
150 |
[ 's' => 'hey', ], |
|
148 |
[ |
|
151 | 149 |
[ 'ay.a' => 2, ], |
152 |
[ 'y[+].baz' => 'bum', ], |
|
153 | 150 |
[ 'ay.b.p' => 3, ], |
154 |
[ 'y[]' => 'a', ], |
|
155 | 151 |
[ 'ay.b.q' => 4, ], |
152 |
[ 's' => 'hey', ], |
|
153 |
[ 'x' => 1, ], |
|
154 |
[ 'y[]' => 'a', ], |
|
156 | 155 |
[ 'y[]' => 2 ], |
157 |
), 'Hash::Flatten 5 - deep mix'; |
|
156 |
[ 'y[+].baz' => 'bum', ], |
|
157 |
], 'Hash::Flatten 5 - deep mix'; |
|
158 | 158 |
|
159 | 159 |
done_testing(); |
Auch abrufbar als: Unified diff
Request::flatten sortiert jetzt Hashes nach keys.
Die Änderung war notwendig, weil in perl 5.18 die Hashrandomisierung deutlich
aggressiver ist. Flatten war vorher schon auf dem Papier nicht deterministisch,
das ist aber durch die Randomisierung von perl 5.10 bis 5.16 nie aufgefallen.
Der neue Algorithmus sorgt dafür dass die Datenstruktur
sowohl als
als auch als
zurückkommen kann, je nach Reihenfolge die keys zurückgibt.
Ab jetzt wird immer die erste Version forciert.