anchor.diff:      Expect = [{meta, [{total, length(?VALUES)}, {offset, 0}]}] ++ lists:reverse(rows()),
       ?_assertEquiv(Expect, Results).
   
  -should_collate_range(Db) ->
  -    ?_assertNot(
  -        begin
  -            {_, Error} = lists:foldl(fun(V, {Count, Error}) ->
  -                {ok, Results} = run_query(Db, [{start_key, V}, {end_key, V}]),
  -                Id = list_to_binary(integer_to_list(Count)),
  -                Expect = [
  -                    {meta, [{total, length(?VALUES)}, {offset, Count}]},
  -                    {row, [{id, Id}, {key, V}, {value, 0}]}
  -                ],
  -                case Results == Expect of
  -                    true -> {Count+1, Error};
  -                    _ -> {Count+1, true}
  -                end
  -            end, {0, false}, ?VALUES),
  -            Error
  -        end).
  +should_collate_range_(Db) ->
  +    Index = lists:zip(lists:seq(0, length(?VALUES)-1), ?VALUES),
  +    lists:map(fun(V) ->
  +        {ok, Results} = run_query(Db, [{start_key, V}, {end_key, V}]),
  +        Expect = [
  +            {meta, [{total, length(?VALUES)}, find_offset(Index, V)]} |
  +            find_matching_rows(Index, V)
  +        ],
  +        ?_assertEquiv(Expect, Results)
  +    end, ?VALUES).
  +
  +find_offset(Index, Value) ->
  +    [{Offset, _} | _] = lists:dropwhile(fun({_, V}) ->
  +        couch_ejson_compare:less(Value, V) =/= 0
  +    end, Index),
  +    {offset, Offset}.
  +
  +find_matching_rows(Index, Value) ->
  +    Matches = lists:filter(fun({_, V}) ->
  +        couch_ejson_compare:less(Value, V) =:= 0
  +    end, Index),
  +    lists:map(fun({Id, V}) ->
  +        {row, [{id, list_to_binary(integer_to_list(Id))}, {key, V}, {value, 0}]}
  +    end, Matches).
   
   should_collate_with_inclusive_end_fwd(Db) ->
       Opts = [{end_key, <<"b">>}, {inclusive_end, true}],
  
positive.code:     <<"B">>,
      <<"ba">>,
      <<"bb">>,
  
      [<<"a">>],
      [<<"b">>],
  
negative.code:                 [
                      fun should_collate_fwd/1,
                      fun should_collate_rev/1,
                      fun should_collate_range_/1,
                      fun should_collate_with_inclusive_end_fwd/1,
                      fun should_collate_with_inclusive_end_rev/1,
                      fun should_collate_without_inclusive_end_fwd/1,
  