anchor.diff:      ?assertEqual(<<"2">>, heartbeat()).
   
   message_test_() ->
  -    [?_assertEqual(<<"3:1::blabla">>, iolist_to_binary(message(1, "", "blabla"))),
  -     ?_assertEqual(<<"3:2::bla">>, iolist_to_binary(message(2, "", "bla"))),
  -     ?_assertEqual(<<"3:::bla">>, iolist_to_binary(message("", "", "bla"))),
  -     ?_assertEqual(<<"3:4+:b:bla">>, iolist_to_binary(message("4+", "b", "bla"))),
  -     ?_assertEqual(<<"3::/test:bla">>, iolist_to_binary(message("", "/test", "bla")))].
  +    [?_assertEqual(<<"3:1::blabla">>, message(1, <<"">>, <<"blabla">>)),
  +     ?_assertEqual(<<"3:2::bla">>, message(2, <<"">>, <<"bla">>)),
  +     ?_assertEqual(<<"3:::bla">>, message(<<"">>, <<"">>, <<"bla">>)),
  +     ?_assertEqual(<<"3:4+:b:bla">>, message(<<"4+">>, <<"b">>, <<"bla">>)),
  +     ?_assertEqual(<<"3::/test:bla">>, message(<<"">>, <<"/test">>, <<"bla">>))].
   
   json_test_() ->
       [?_assertEqual(<<"4:1::{\"a\":\"b\"}">>,
  -                  iolist_to_binary(json(1, "", [{<<"a">>,<<"b">>}]))),
  +		   json(1, <<"">>, [{<<"a">>,<<"b">>}])),
        %% No demo for this, but the specs specify it
        ?_assertEqual(<<"4:1:/test:{\"a\":\"b\"}">>,
  -                  iolist_to_binary(json(1, "/test", [{<<"a">>,<<"b">>}]))),
  +		   json(1, <<"/test">>, [{<<"a">>,<<"b">>}])),
        ?_assertEqual(<<"4:1+:/test:{\"a\":\"b\"}">>,
  -                  iolist_to_binary(json("1+", "/test", [{<<"a">>,<<"b">>}]))),
  +		   json(<<"1+">>, <<"/test">>, [{<<"a">>,<<"b">>}])),
        ?_assertEqual(<<"4::/test:{\"a\":\"b\"}">>,
  -         iolist_to_binary(json("", "/test", [{<<"a">>,<<"b">>}])))].
  -
  -event_test_() ->
  -    [
  -        ?_assertEqual(<<"5:1:/test:car", ?FRAME, "{\"a\":\"b\"}">>,
  -            iolist_to_binary(event(1,"/test","car",[{<<"a">>,<<"b">>}]))),
  -        ?_assertEqual(<<"5:::car", ?FRAME, "{\"a\":\"b\"}">>,
  -            iolist_to_binary(event("","",<<"car">>,[{<<"a">>,<<"b">>}]))),
  -        ?_assertEqual(<<"5:3+::car", ?FRAME, "{\"a\":\"b\"}">>,
  -            iolist_to_binary(event("3+","",<<"car">>,[{<<"a">>,<<"b">>}]))),
  -        ?_assertError(badarg, event("","","message",[])),
  -        ?_assertError(badarg, event("","",<<"message">>,[])),
  -        ?_assertError(badarg, event("","","connect",[])),
  -        ?_assertError(badarg, event("","",<<"connect">>,[])),
  -        ?_assertError(badarg, event("","","disconnect",[])),
  -        ?_assertError(badarg, event("","",<<"disconnect">>,[])),
  -        ?_assertError(badarg, event("","","open",[])),
  -        ?_assertError(badarg, event("","",<<"open">>,[])),
  -        ?_assertError(badarg, event("","","close",[])),
  -        ?_assertError(badarg, event("","",<<"close">>,[])),
  -        ?_assertError(badarg, event("","","error",[])),
  -        ?_assertError(badarg, event("","",<<"error">>,[])),
  -        ?_assertError(badarg, event("","","retry",[])),
  -        ?_assertError(badarg, event("","",<<"retry">>,[])),
  -        ?_assertError(badarg, event("","","reconnect",[])),
  -        ?_assertError(badarg, event("","",<<"reconnect">>,[]))
  -    ].
  -
  -ack_test_() ->
  -    [?_assertEqual(<<"6:::4">>, iolist_to_binary(ack(4))),
  -     ?_assertEqual(<<"6:::4+[\"A\",\"B\"]">>,
  -         iolist_to_binary(ack(4,[<<"A">>,<<"B">>])))].
  +		   json(<<"">>, <<"/test">>, [{<<"a">>,<<"b">>}]))].
   
   error_test_() ->
       %% No example, liberal interpretation
       [?_assertEqual(<<"7::end:you+die">>,
  -            iolist_to_binary(error("end","you","die"))),
  -        ?_assertEqual(<<"7:::you">>, iolist_to_binary(error("","you")))].
  +		   iolist_to_binary(error("end","you","die"))),
  +     ?_assertEqual(<<"7:::you">>, iolist_to_binary(error("","you")))].
   
   %% DECODING TESTS
   d_disconnect_test_() ->
  
positive.code: id(<<Num, Rest/binary>>, Acc) when Num-$0 >= 0, Num-$0 =< 9 ->
      id(Rest, [Num|Acc]).
  
  endpoint(X) -> endpoint(X,"").
  
  endpoint(<<$:, Rest/binary>>, Acc) -> {lists:reverse(Acc), Rest};
  endpoint(<<X, Rest/binary>>, Acc) -> endpoint(Rest, [X|Acc]).
  
  event(X) ->
      [Event, JSON] = binary:split(X, ?BINFRAME),
      {Event, JSON}.
  
  p_ack(X) ->
      case binary:split(X, <<"+">>) of
          [H] -> list_to_integer(binary_to_list(H));
          [H|T] -> list_to_tuple([list_to_integer(binary_to_list(H))|T])
      end.
  
  reason(X) ->
     case list_to_tuple(binary:split(X, <<"+">>)) of
         {E} -> E;
         T -> T
     end.
  
  %%% Tests based off the examples on the page
  %%% ENCODING
  disconnect_test_() ->
      [?_assertEqual(<<"0::/test">>, iolist_to_binary(disconnect("/test"))),
       ?_assertEqual(<<"0">>, iolist_to_binary(disconnect("")))].
  
  connect_test_() -> []. % Only need to read, never to encode
  
  
negative.code: -compile([export_all, {no_auto_import, [error/2]}]).
  -include_lib("eunit/include/eunit.hrl").
  
  %% The source code was taken and modified from https://github.com/yrashk/socket.io-erlang/blob/master/src/socketio_data_v1.erl
  
  -define(FRAME, 16#fffd).
  
  disconnect(<<>>) ->
      <<"0">>;
  disconnect(Endpoint) ->
      <<"0::", Endpoint/binary>>.
  
  heartbeat() ->
      <<"2">>.
  
  message(Id, EndPoint, Msg) when is_integer(Id) ->
      IdBin = binary:list_to_bin(integer_to_list(Id)),
      <<"3:", IdBin/binary, ":", EndPoint/binary, ":", Msg/binary>>;
  message(Id, EndPoint, Msg) when is_binary(Id) ->
      <<"3:", Id/binary, ":", EndPoint/binary, ":", Msg/binary>>.
  
  json(Id, EndPoint, Msg) when is_integer(Id) ->
      IdBin = binary:list_to_bin(integer_to_list(Id)),
      JsonBin = jsx:term_to_json(Msg),
      <<"4:", IdBin/binary, ":", EndPoint/binary, ":", JsonBin/binary>>;
  json(Id, EndPoint, Msg) when is_binary(Id) ->
      JsonBin = jsx:term_to_json(Msg),
      <<"4:", Id/binary, ":", EndPoint/binary, ":", JsonBin/binary>>.
  
  error(EndPoint, Reason) ->
      [<<"7::">>, EndPoint, $:, Reason].
  error(EndPoint, Reason, Advice) ->
      [<<"7::">>, EndPoint, $:, Reason, $+, Advice].
  
  