diff --git a/.gitignore b/.gitignore index fc80ed8..629e7d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ +/doc +/_test +/.eunit +/docs ebin *.dump diff --git a/Rakefile b/Rakefile deleted file mode 100644 index d5ed2de..0000000 --- a/Rakefile +++ /dev/null @@ -1,25 +0,0 @@ -require 'rubygems' -require 'rake' - -ERLC_FLAGS = "+debug_info -W2 -o ebin" - -task :default => :test - -task :chdir do - Dir.chdir(File.join(File.dirname(__FILE__), *%w[.])) -end - -task :build => :chdir do - sh "mkdir -p ebin" - sh "erlc #{ERLC_FLAGS} src/*.erl" -end - -task :test => :chdir do - sh "mkdir -p ebin" - sh "erlc #{ERLC_FLAGS} -DTEST -I etest src/*.erl" - sh "test/run.es" -end - -task :console => :chdir do - sh "erl +Bc +K true -smp enable -pa ebin -sname local_console_#{$$} -kernel start_boot_server true" -end diff --git a/rebar b/rebar new file mode 100755 index 0000000..462730a Binary files /dev/null and b/rebar differ diff --git a/src/bert.app.src b/src/bert.app.src new file mode 100644 index 0000000..4228934 --- /dev/null +++ b/src/bert.app.src @@ -0,0 +1,7 @@ +{application, bert, + [ + {description, "BERT Serialization Library"}, + {vsn, "1.1.0"}, + {modules, [bert]}, + {applications, [kernel, stdlib]} + ]}. diff --git a/src/bert.erl b/src/bert.erl index 0faf7fb..7248f85 100644 --- a/src/bert.erl +++ b/src/bert.erl @@ -7,10 +7,6 @@ -export([encode/1, decode/1]). --ifdef(TEST). --include("test/bert_test.erl"). --endif. - %%--------------------------------------------------------------------------- %% Public API @@ -34,7 +30,7 @@ encode_term(Term) -> [] -> {bert, nil}; true -> {bert, true}; false -> {bert, false}; - Dict when is_record(Term, dict, 8) -> + Dict when is_tuple(Term) andalso element(1, Term) =:= dict -> {bert, dict, dict:to_list(Dict)}; List when is_list(Term) -> lists:map((fun encode_term/1), List); @@ -56,7 +52,8 @@ decode_term(Term) -> {bert, true} -> true; {bert, false} -> false; {bert, dict, Dict} -> - dict:from_list(Dict); + L = lists:map(fun decode_term/1, Dict), + dict:from_list(L); {bert, Other} -> {bert, Other}; List when is_list(Term) -> @@ -66,4 +63,4 @@ decode_term(Term) -> TList2 = lists:map((fun decode_term/1), TList), list_to_tuple(TList2); _Else -> Term - end. \ No newline at end of file + end. diff --git a/test/bert_test.erl b/test/bert_test.erl deleted file mode 100644 index 56dc1ba..0000000 --- a/test/bert_test.erl +++ /dev/null @@ -1,23 +0,0 @@ --include_lib("eunit/include/eunit.hrl"). - -%% encode - -encode_list_nesting_test() -> - Bert = term_to_binary([foo, {bert, true}]), - Bert = encode([foo, true]). - -encode_tuple_nesting_test() -> - Bert = term_to_binary({foo, {bert, true}}), - Bert = encode({foo, true}). - -%% decode - -decode_list_nesting_test() -> - Bert = term_to_binary([foo, {bert, true}]), - Term = [foo, true], - Term = decode(Bert). - -decode_tuple_nesting_test() -> - Bert = term_to_binary({foo, {bert, true}}), - Term = {foo, true}, - Term = decode(Bert). \ No newline at end of file diff --git a/test/bert_tests.erl b/test/bert_tests.erl new file mode 100644 index 0000000..142d827 --- /dev/null +++ b/test/bert_tests.erl @@ -0,0 +1,46 @@ +-module(bert_tests). +-include_lib("eunit/include/eunit.hrl"). +-import(bert, [encode/1, decode/1]). + +%% encode + +encode_list_nesting_test() -> + Bert = term_to_binary([foo, {bert, true}]), + Bert = encode([foo, true]). + +encode_tuple_nesting_test() -> + Bert = term_to_binary({foo, {bert, true}}), + Bert = encode({foo, true}). + +encode_dict_test() -> + Bert = term_to_binary({ bert, dict, + dict:to_list(dict:store(foo, true, dict:new())) }), + Bert = encode(dict:store(foo, true, dict:new())). + +%% decode + +decode_list_nesting_test() -> + Bert = term_to_binary([foo, {bert, true}]), + Term = [foo, true], + Term = decode(Bert). + +decode_tuple_nesting_test() -> + Bert = term_to_binary({foo, {bert, true}}), + Term = {foo, true}, + Term = decode(Bert). + +decode_dict_test() -> + Bert = term_to_binary({ bert, dict, + dict:to_list(dict:store(foo, true, dict:new())) }), + Term = dict:store(foo, true, dict:new()), + Term = decode(Bert). + +decode_dict_nesting_test() -> + Bert = term_to_binary({ bert, dict, + dict:to_list(dict:store(a, + { bert, dict, + dict:to_list(dict:store(b, "b", dict:new())) + }, + dict:new())) }), + Term = dict:store(a, dict:store(b, "b", dict:new()), dict:new()), + Term = decode(Bert). diff --git a/test/run.es b/test/run.es deleted file mode 100755 index 3942ab8..0000000 --- a/test/run.es +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env escript -%% -*- erlang -*- -%%! -pa ./ebin -sasl -boot start_sasl -noshell - -main(_) -> - bert:test().