associative arrays: to sort or not to sort?

BCS none at anon.com
Wed Jul 21 07:23:38 PDT 2010


Hello Mario,

>> Unless JSON requiers that the keys be in some order,
>> 
> No, JSON does not require the names of an object to be in alphabetical
> order.
> 
>> the correct solution is to make the check order independent. For
>> example:
>> string s = CallReturningJSON();
>> s = replace(s,`"a":23.54`, `X`);
>> s = replace(s,`"b":0.0012`, `X`);
>> s = replace(s,`{"nested":{X,X}}`, `X`);
>> s = replace(s,`"goodbye":[true,"or",false,["test",42,X]]`, `X`);
>> s = replace(s,`"array":[12,null,{}]`, `Y`);
>> s = replace(s,"is\n\ngreat", `Z`);
>> s = replace(s,`"json":Z`, `Y`);
>> s = replace(s,`"hello":{Y,Y}`, `X`);
>> assert(s == `{X,X}`);.
>
> But this is lengthy and seems to lack additional assert checks.
> 

It's a little wordy but it has one line per things it is checking. And adjusting 
it to give more asserts is trivial.

> 
> Until then, broken unit tests pass...
> 

Spot on. The unittest is broken. Not the thing it's testing and not foreach.

-- 
... <IXOYE><





More information about the Digitalmars-d-learn mailing list