Skip to content
This repository has been archived by the owner on Nov 28, 2017. It is now read-only.

Commit

Permalink
more tests get_extension
Browse files Browse the repository at this point in the history
  • Loading branch information
freke committed Dec 4, 2011
1 parent 0d2b0a3 commit b7b413f
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions test/protobuffs_compile_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -515,14 +515,17 @@ test_function_get_extension() ->
Name = "name",
Fields = [],
Extends = [],
Messages = [{Name,Fields,Extends}],
Messages1 = [{Name,Fields,Extends}],
Messages2 = [{Name,Fields,disallowed}],
Basename = ignored,
Enums = [],
Acc = [],

GetExtensionFmt1 = "get_extension(Record, fieldatom) when is_record(Record, ~s) ->"
GetExtensionFmt = "get_extension(_Record, _FieldName) ->"
" undefined.",
GetExtensionFmt1 = "get_extension(~s, ~s) when is_record(Record, ~s)->"
" get_extension(Record, 1);",
GetExtensionFmt2 = " get_extension(#~s{'$extensions' = Extensions}, Int)"
GetExtensionFmt2 = "get_extension(#~s{'$extensions' = Extensions}, Int)"
" when is_integer(Int) ->"
" case dict:find(Int, Extensions) of"
" {ok, {_Rule, Value, _Type, _Opts}} ->"
Expand All @@ -534,14 +537,29 @@ test_function_get_extension() ->
" end;"
" get_extension(_Record, _FieldName) ->"
" undefined.",
TemplateFunction = string_format(GetExtensionFmt1++GetExtensionFmt2,["pikachu","pikachu"]),
ExpectedFunction = string_format(GetExtensionFmt2,["name"]),
TemplateFunction = string_format(GetExtensionFmt1++GetExtensionFmt2,["Record","fieldatom","pikachu","pikachu"]),
ExpectedFunction1 = string_format(GetExtensionFmt2,["name"]),
ExpectedFunction2 = string_format(GetExtensionFmt,[]),

{ok,Function} = parse(TemplateFunction),
{ok,FilterdFunction} = parse(ExpectedFunction),
{ok,FilterdFunction1} = parse(ExpectedFunction1),
{ok,FilterdFunction2} = parse(ExpectedFunction2),

?debugFmt("~n~w~n",[[FilterdFunction2]]),
?debugFmt("~n~w~n",[protobuffs_compile_lib:filter_forms(Messages2,
[],
[Function],
Basename,
Acc)]),

[?_assertEqual([FilterdFunction],
protobuffs_compile_lib:filter_forms(Messages,
[?_assertEqual([FilterdFunction1],
protobuffs_compile_lib:filter_forms(Messages1,
[],
[Function],
Basename,
Acc)),
?_assertEqual([FilterdFunction2],
protobuffs_compile_lib:filter_forms(Messages2,
[],
[Function],
Basename,
Expand Down Expand Up @@ -575,13 +593,6 @@ test_function_set_extension() ->
{ok,FilterdFunction2} = parse(ExpectedFunction2),
{ok,FilterdFunction3} = parse(ExpectedFunction3),

?debugFmt("~n~w~n",[[FilterdFunction3]]),
?debugFmt("~n~w~n",[protobuffs_compile_lib:filter_forms(Messages3,
[],
[Function],
Basename,
Acc)]),

[?_assertEqual([FilterdFunction1],
protobuffs_compile_lib:filter_forms(Messages1,
[],
Expand Down

0 comments on commit b7b413f

Please sign in to comment.