Browse Source

Fix some bugs uncovered in review

pull/108/head
Andrew Thompson 12 years ago
parent
commit
80e53076fc
1 changed files with 26 additions and 5 deletions
  1. +26
    -5
      src/lager_trunc_io.erl

+ 26
- 5
src/lager_trunc_io.erl View File

@ -161,7 +161,14 @@ print(Binary, Max, Options) when is_binary(Binary) ->
string:substr(B, 1, MaxSize); string:substr(B, 1, MaxSize);
false -> B false -> B
end, end,
try alist(In, Max -1, Options) of
MaxLen = case Options#print_options.force_strings of
true ->
Max;
false ->
%% make room for the leading doublequote
Max - 1
end,
try alist(In, MaxLen, Options) of
{L0, Len0} -> {L0, Len0} ->
case Options#print_options.force_strings of case Options#print_options.force_strings of
false -> false ->
@ -394,11 +401,17 @@ alist([H|T], Max, Options) when H =:= $\t; H =:= $\n; H =:= $\r; H =:= $\v; H =:
alist([H|T], Max, #print_options{force_strings=true} = Options) when is_integer(H) -> alist([H|T], Max, #print_options{force_strings=true} = Options) when is_integer(H) ->
{L, Len} = alist(T, Max-1, Options), {L, Len} = alist(T, Max-1, Options),
{[H|L], Len + 1}; {[H|L], Len + 1};
alist([H|T], Max, Options = #print_options{force_strings=true}) when is_binary(H) ->
alist([H|T], Max, Options = #print_options{force_strings=true}) when is_binary(H); is_list(H) ->
{List, Len} = print(H, Max, Options), {List, Len} = print(H, Max, Options),
%% no need to decrement depth, as we're in printable string mode
{Final, FLen} = alist(T, Max - Len, Options),
{[List|Final], FLen};
case (Max - Len) =< 0 of
true ->
%% no more room to print anything
{List, Len};
false ->
%% no need to decrement depth, as we're in printable string mode
{Final, FLen} = alist(T, Max - Len, Options),
{[List|Final], FLen+Len}
end;
alist(_, _, #print_options{force_strings=true}) -> alist(_, _, #print_options{force_strings=true}) ->
erlang:error(badarg); erlang:error(badarg);
alist([H|_L], _Max, _Options) -> alist([H|_L], _Max, _Options) ->
@ -658,6 +671,14 @@ list_printing_test() ->
iolist_printing_test() -> iolist_printing_test() ->
?assertEqual("iolist: HelloIamaniolist", ?assertEqual("iolist: HelloIamaniolist",
lists:flatten(format("iolist: ~s", [[$H, $e, $l, $l, $o, "I", ["am", [<<"an">>], [$i, $o, $l, $i, $s, $t]]]], 1000))), lists:flatten(format("iolist: ~s", [[$H, $e, $l, $l, $o, "I", ["am", [<<"an">>], [$i, $o, $l, $i, $s, $t]]]], 1000))),
?assertEqual("123...",
lists:flatten(format("~s", [[<<"123456789">>, "HellIamaniolist"]], 6))),
?assertEqual("123456...",
lists:flatten(format("~s", [[<<"123456789">>, "HellIamaniolist"]], 9))),
?assertEqual("123456789H...",
lists:flatten(format("~s", [[<<"123456789">>, "HellIamaniolist"]], 13))),
?assertEqual("123456789HellIamaniolist",
lists:flatten(format("~s", [[<<"123456789">>, "HellIamaniolist"]], 30))),
ok. ok.
tuple_printing_test() -> tuple_printing_test() ->

Loading…
Cancel
Save