rewrote test harness to use eunit and make it easier to add future tests

This commit is contained in:
alisdair sullivan 2010-05-23 22:40:35 -07:00
parent f5f1f588d4
commit ab67abd01a
37 changed files with 121 additions and 81 deletions

View file

@ -3,21 +3,15 @@
-export([start/4]).
-include("jsx_common.hrl").
callback(eof, Callbacks) ->
lists:reverse(Callbacks);
callback(Event, Callbacks) ->
[Event] ++ Callbacks.
%% this code is mostly autogenerated and mostly ugly. apologies. for more insight on
%% Callbacks or Opts, see the comments accompanying callback/2 (in this file) and
%% parse_opts/1 (in jsx.erl). Stack is a stack of flags used to track depth and to
%% keep track of whether we are returning from a value or a key inside objects. all
%% pops, peeks and pushes are inlined. the code that handles naked values and comments
%% is not optimized by the compiler for efficient matching, but you shouldn't be using
%% naked values or comments anyways, they are horrible and contrary to the spec.
%% Callbacks or Opts, see the comments accompanying decoder/2 (in jsx.erl). Stack
%% is a stack of flags used to track depth and to keep track of whether we are
%% returning from a value or a key inside objects. all pops, peeks and pushes are
%% inlined. the code that handles naked values and comments is not optimized by the
%% compiler for efficient matching, but you shouldn't be using naked values or comments
%% anyways, they are horrible and contrary to the spec.
start(<<?start_object/utf8, Rest/binary>>, Stack, Callbacks, Opts) ->
object(Rest, [key|Stack], callback(start_object, Callbacks), Opts);
@ -204,7 +198,7 @@ escaped_unicode(<<D/utf8, Rest/binary>>, Stack, Callbacks, Opts, String, [C, B,
string(Rest, Stack, Callbacks, Opts, [X] ++ String)
; codepoint ->
string(Rest, Stack, Callbacks, Opts, [X] ++ String)
; none ->
; _ ->
string(Rest, Stack, Callbacks, Opts, [?rsolidus, $u, A, B, C, D] ++ String)
end;
escaped_unicode(<<S/utf8, Rest/binary>>, Stack, Callbacks, Opts, String, Acc) when ?is_hex(S) ->
@ -422,6 +416,18 @@ maybe_comment_done(<<?solidus/utf8, Rest/binary>>, Resume) ->
Resume(Rest);
maybe_comment_done(<<>>, Resume) ->
fun(Stream) -> maybe_comment_done(Stream, Resume) end.
%% helper function for dispatching of parser events
callback(eof, {none, Callbacks}) ->
lists:reverse(Callbacks);
callback(Event, {none, Callbacks}) ->
{none, [Event] ++ Callbacks};
callback(Event, {Mod, State}) when is_atom(Mod) ->
{Mod, Mod:jsx_event(Event, State)};
callback(Event, {F, State}) when is_function(F) ->
{F, F(Event, State)}.