anchor.diff:                 C when C >= 0, C < $\s ->
                      [unihex(C) | Acc];
                  C when C >= 16#7f, C =< 16#10FFFF, State#encoder.utf8 ->
  -                   [xmerl_ucs:to_utf8(C) | Acc];
  +                   [unicode:characters_to_binary([C]) | Acc];
                  C when  C >= 16#7f, C =< 16#10FFFF, not State#encoder.utf8 ->
                      [unihex(C) | Acc];
                  C when C < 16#7f ->
                      [C | Acc];
                  _ ->
  +                   %% json_string_is_safe guarantees that this branch is dead
                      exit({json_encode, {bad_char, C}})
              end,
       json_encode_string_unicode(Cs, State, Acc1).
  
positive.code:         {16#10196, <<?Q, 16#F0, 16#90, 16#86, 16#96, ?Q>>} %% denarius
      ],
      lists:foreach(fun({CodePoint, UTF8}) ->
          Expect = list_to_binary(xmerl_ucs:to_utf8(CodePoint)),
          Expect = decode(UTF8)
      end, Good),
  
  
negative.code:                    {eep18, {P}},
                     {proplist, P}]].
  
  array_test() ->
      A = [<<"hello">>],
      ?assertEqual(A, decode(encode({array, A}))).
  
  bad_char_test() ->
      ?assertEqual(
         {'EXIT', {json_encode, {bad_char, 16#110000}}},
         catch json_string_is_safe([16#110000])).
  
  utf8_roundtrip_test_() ->
      %% These are the boundary cases for UTF8 encoding
      Codepoints = [%% 7 bits  -> 1 byte
                    16#00, 16#7f,
                    %% 11 bits -> 2 bytes
                    16#080, 16#07ff,
                    %% 16 bits -> 3 bytes
                    16#0800, 16#ffff,
                    16#d7ff, 16#e000,
                    %% 21 bits -> 4 bytes
                    16#010000, 16#10ffff],
      UTF8 = unicode:characters_to_binary(Codepoints),
      Encode = encoder([{utf8, true}]),
      [{"roundtrip escaped",
        ?_assertEqual(UTF8, decode(encode(UTF8)))},
       {"roundtrip utf8",
        ?_assertEqual(UTF8, decode(Encode(UTF8)))}].
  
  utf8_non_character_test_() ->
      S = unicode:characters_to_binary([16#ffff, 16#fffe]),
      [{"roundtrip escaped", ?_assertEqual(S, decode(encode(S)))},
       {"roundtrip utf8", ?_assertEqual(S, decode((encoder([{utf8, true}]))(S)))}].
  
  -endif.
  