anchor.diff:         codepoint_to_bytes(16#10ffff)),
       ok.
   
  +bytes_foldl_test() ->
  +    ?assertEqual(
  +       <<"abc">>,
  +       bytes_foldl(fun (B, Acc) -> <<Acc/binary, B/binary>> end, <<>>, <<"abc">>)),
  +    ?assertEqual(
  +       <<"abc", 226, 152, 131, 228, 184, 173, 194, 133, 244,143,191,191>>,
  +       bytes_foldl(fun (B, Acc) -> <<Acc/binary, B/binary>> end, <<>>,
  +                   <<"abc", 226, 152, 131, 228, 184, 173, 194, 133, 244,143,191,191>>)),
  +    ok.
  +
  +bytes_to_codepoints_test() ->
  +    ?assertEqual(
  +       "abc" ++ [16#2603, 16#4e2d, 16#85, 16#10ffff],
  +       bytes_to_codepoints(<<"abc", 226, 152, 131, 228, 184, 173, 194, 133, 244,143,191,191>>)),
  +    ok.
  +
  +codepoint_foldl_test() ->
  +    ?assertEqual(
  +       "cba",
  +       codepoint_foldl(fun (C, Acc) -> [C | Acc] end, [], <<"abc">>)),
  +    ?assertEqual(
  +       [16#10ffff, 16#85, 16#4e2d, 16#2603 | "cba"],
  +       codepoint_foldl(fun (C, Acc) -> [C | Acc] end, [],
  +                       <<"abc", 226, 152, 131, 228, 184, 173, 194, 133, 244,143,191,191>>)),
  +    ok.
  +
  +len_test() ->
  +    ?assertEqual(
  +       29,
  +       len(<<"unicode snowman for you: ", 226, 152, 131, 228, 184, 173, 194, 133, 244, 143, 191, 191>>)),
  +    ok.
  +
  +codepoints_to_bytes_test() ->
  +    ?assertEqual(
  +       iolist_to_binary(lists:map(fun codepoint_to_bytes/1, lists:seq(1, 1000))),
  +       codepoints_to_bytes(lists:seq(1, 1000))),
  +    ok.
  +
   valid_utf8_bytes_test() ->
       ?assertEqual(
          <<"invalid U+11ffff: ">>,
  
positive.code: binary_skip_bytes(<<C, RestB/binary>>, L, N, Acc) ->
      binary_skip_bytes(RestB, L, 1 + N, [C | Acc]).
  
  %% @spec invalid_utf8_indexes(B::binary()) -> [integer()]
  %% @doc Return the 0-based indexes in B that are not valid UTF-8.
  invalid_utf8_indexes(B) ->
      invalid_utf8_indexes(B, 0, []).
  
  %% @private.
  invalid_utf8_indexes(<<C, Rest/binary>>, N, Acc) when C < 16#80 ->
      %% U+0000 - U+007F - 7 bits
      invalid_utf8_indexes(Rest, 1 + N, Acc);
  
negative.code: %%      invalid bytes.
  
  -module(mochiutf8).
  -export([valid_utf8_bytes/1, codepoint_to_bytes/1, bytes_to_codepoints/1]).
  -export([bytes_foldl/3, codepoint_foldl/3, read_codepoint/1, len/1]).
  
  %% External API
  
  -type unichar_low() :: 0..16#d7ff.
  -type unichar_high() :: 16#e000..16#10ffff.
  -type unichar() :: unichar_low() | unichar_high().
  
  -spec codepoint_to_bytes(unichar()) -> binary().
  %% @doc Convert a unicode codepoint to UTF-8 bytes.
  codepoint_to_bytes(C) when (C >= 16#00 andalso C =< 16#7f) ->
      %% U+0000 - U+007F - 7 bits
  