@@ -147,7 +147,14 @@ pub fn builtin_assert_equal(a: Val, b: Val) -> Result<bool> {
147
147
if equals ( & a, & b) ? {
148
148
return Ok ( true ) ;
149
149
}
150
- let format = JsonFormat :: std_to_json ( " " . to_owned ( ) , "\n " , ": " ) ;
150
+ // TODO: Use debug output format
151
+ let format = JsonFormat :: std_to_json (
152
+ " " . to_owned ( ) ,
153
+ "\n " ,
154
+ ": " ,
155
+ #[ cfg( feature = "exp-preserve-order" ) ]
156
+ true ,
157
+ ) ;
151
158
let a = a. manifest ( & format) . description ( "<a> manifestification" ) ?;
152
159
let b = b. manifest ( & format) . description ( "<b> manifestification" ) ?;
153
160
bail ! ( "assertion failed: A != B\n A: {a}\n B: {b}" )
@@ -161,8 +168,30 @@ pub fn builtin_merge_patch(target: Val, patch: Val) -> Result<Val> {
161
168
let Some ( target) = target. as_obj ( ) else {
162
169
return Ok ( Val :: Obj ( patch) ) ;
163
170
} ;
164
- let target_fields = target. fields ( ) . into_iter ( ) . collect :: < BTreeSet < IStr > > ( ) ;
165
- let patch_fields = patch. fields ( ) . into_iter ( ) . collect :: < BTreeSet < IStr > > ( ) ;
171
+ let target_fields = target
172
+ . fields (
173
+ // FIXME: Makes no sense to preserve order for BTreeSet, it would be better to use IndexSet here?
174
+ // But IndexSet won't allow fast ordered union...
175
+ // // Makes sense to preserve source ordering where possible.
176
+ // // May affect evaluation order, but it is not specified by jsonnet spec.
177
+ // #[cfg(feature = "exp-preserve-order")]
178
+ // true,
179
+ #[ cfg( feature = "exp-preserve-order" ) ]
180
+ false ,
181
+ )
182
+ . into_iter ( )
183
+ . collect :: < BTreeSet < IStr > > ( ) ;
184
+ let patch_fields = patch
185
+ . fields (
186
+ // No need to look at the patch field order, I think?
187
+ // New fields (that will be appended at the end) will be alphabeticaly-ordered,
188
+ // but it is fine for jsonpatch, I don't think people write jsonpatch in jsonnet,
189
+ // when they can use mixins.
190
+ #[ cfg( feature = "exp-preserve-order" ) ]
191
+ false ,
192
+ )
193
+ . into_iter ( )
194
+ . collect :: < BTreeSet < IStr > > ( ) ;
166
195
167
196
let mut out = ObjValueBuilder :: new ( ) ;
168
197
for field in target_fields. union ( & patch_fields) {
0 commit comments