aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Nord <[email protected]>2012-10-18 12:28:58 +0200
committerHenrik Nord <[email protected]>2012-10-18 12:29:00 +0200
commitf0332a299d3c6eea7089483f05a7e6f580e40f3c (patch)
tree45205298465ad4f549182f5c40087c2429d9b058
parentb30b0a3c0197c2b500849b01f7f9d6f7c6eb831a (diff)
parentc83931cbb3516563949d283fe46453a35cd35977 (diff)
downloadotp-f0332a299d3c6eea7089483f05a7e6f580e40f3c.tar.gz
otp-f0332a299d3c6eea7089483f05a7e6f580e40f3c.tar.bz2
otp-f0332a299d3c6eea7089483f05a7e6f580e40f3c.zip
Merge branch 'at/binary-depth-printing'
* at/binary-depth-printing: Fix printing the empty binary at depth 1 with ~W OTP-10504
-rw-r--r--lib/stdlib/src/io_lib.erl4
-rw-r--r--lib/stdlib/test/io_SUITE.erl17
2 files changed, 17 insertions, 4 deletions
diff --git a/lib/stdlib/src/io_lib.erl b/lib/stdlib/src/io_lib.erl
index ab62b72519..513d904c39 100644
--- a/lib/stdlib/src/io_lib.erl
+++ b/lib/stdlib/src/io_lib.erl
@@ -253,10 +253,10 @@ write_ref(Ref) ->
write_binary(B, D) when is_integer(D) ->
[$<,$<,write_binary_body(B, D),$>,$>].
-write_binary_body(_B, 1) ->
- "...";
write_binary_body(<<>>, _D) ->
"";
+write_binary_body(_B, 1) ->
+ "...";
write_binary_body(<<X:8>>, _D) ->
[integer_to_list(X)];
write_binary_body(<<X:8,Rest/bitstring>>, D) ->
diff --git a/lib/stdlib/test/io_SUITE.erl b/lib/stdlib/test/io_SUITE.erl
index bb02a879c2..74fcdcc7d2 100644
--- a/lib/stdlib/test/io_SUITE.erl
+++ b/lib/stdlib/test/io_SUITE.erl
@@ -27,7 +27,8 @@
otp_6282/1, otp_6354/1, otp_6495/1, otp_6517/1, otp_6502/1,
manpage/1, otp_6708/1, otp_7084/1, otp_7421/1,
io_lib_collect_line_3_wb/1, cr_whitespace_in_string/1,
- io_fread_newlines/1, otp_8989/1, io_lib_fread_literal/1]).
+ io_fread_newlines/1, otp_8989/1, io_lib_fread_literal/1,
+ io_lib_print_binary_depth_one/1]).
%-define(debug, true).
@@ -62,7 +63,8 @@ all() ->
otp_6282, otp_6354, otp_6495, otp_6517, otp_6502,
manpage, otp_6708, otp_7084, otp_7421,
io_lib_collect_line_3_wb, cr_whitespace_in_string,
- io_fread_newlines, otp_8989, io_lib_fread_literal].
+ io_fread_newlines, otp_8989, io_lib_fread_literal,
+ io_lib_print_binary_depth_one].
groups() ->
[].
@@ -2021,3 +2023,14 @@ io_lib_fread_literal(Suite) when is_list(Suite) ->
?line {done,{error,{fread,input}},_} = io_lib:fread(C2, eof, " d"),
?line {done,{ok,[]},[]} = io_lib:fread(C2, "d\n", " d"),
ok.
+
+io_lib_print_binary_depth_one(doc) ->
+ "Test binaries printed with a depth of one behave correctly";
+io_lib_print_binary_depth_one(Suite) when is_list(Suite) ->
+ ?line "<<>>" = fmt("~W", [<<>>, 1]),
+ ?line "<<>>" = fmt("~P", [<<>>, 1]),
+ ?line "<<...>>" = fmt("~W", [<<1>>, 1]),
+ ?line "<<...>>" = fmt("~P", [<<1>>, 1]),
+ ?line "<<...>>" = fmt("~W", [<<1:7>>, 1]),
+ ?line "<<...>>" = fmt("~P", [<<1:7>>, 1]),
+ ok.