Skip to content

Commit

Permalink
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spec/std/slice_spec.cr
Original file line number Diff line number Diff line change
@@ -234,6 +234,10 @@ describe "Slice" do
slice.hexstring.should eq("01020304")
end

it "does hexdump for empty slice" do
Bytes.empty.hexdump.should eq("")
end

it "does hexdump" do
ascii_table = <<-EOF
00000000 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f !"#$%&'()*+,-./
2 changes: 2 additions & 0 deletions src/slice.cr
Original file line number Diff line number Diff line change
@@ -329,6 +329,8 @@ struct Slice(T)
def hexdump
self.as(Slice(UInt8))

return "" if empty?

full_lines, leftover = size.divmod(16)
if leftover == 0
str_size = full_lines * 77 - 1

0 comments on commit aca9433

Please sign in to comment.