Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
/doc
/_test
/.eunit
/docs
ebin
*.dump
25 changes: 0 additions & 25 deletions Rakefile

This file was deleted.

Binary file added rebar
Binary file not shown.
7 changes: 7 additions & 0 deletions src/bert.app.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{application, bert,
[
{description, "BERT Serialization Library"},
{vsn, "1.1.0"},
{modules, [bert]},
{applications, [kernel, stdlib]}
]}.
11 changes: 4 additions & 7 deletions src/bert.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

-export([encode/1, decode/1]).

-ifdef(TEST).
-include("test/bert_test.erl").
-endif.

%%---------------------------------------------------------------------------
%% Public API

Expand All @@ -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);
Expand All @@ -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) ->
Expand All @@ -66,4 +63,4 @@ decode_term(Term) ->
TList2 = lists:map((fun decode_term/1), TList),
list_to_tuple(TList2);
_Else -> Term
end.
end.
23 changes: 0 additions & 23 deletions test/bert_test.erl

This file was deleted.

46 changes: 46 additions & 0 deletions test/bert_tests.erl
Original file line number Diff line number Diff line change
@@ -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).
6 changes: 0 additions & 6 deletions test/run.es

This file was deleted.