Skip to content

Commit

Permalink
Doctests removed from GeoTIFFFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalimaha committed Mar 10, 2018
1 parent 915beb9 commit afa42fa
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 45 deletions.
53 changes: 9 additions & 44 deletions lib/geotiff_formatter.ex
@@ -1,15 +1,4 @@
defmodule GeoTIFFFormatter do
@doc ~S"""
Formats a single IFD.
### Examples:
iex> tag = %{:tag => "Spam", :type => "EGGS", :value => 42, :count => 1}
iex> ifd = %{:offset => 42, :entries => 42, :next_ifd => 0, :tags => [tag]}
iex> headers = %{:filename => 'spam', :endianess => :little, :first_ifd_offset => 42, :ifds => [ifd]}
iex> GeoTIFFFormatter.format_headers headers
"\n====================================================\nFilename: spam\nEndianess: little\nFirst IFD: 42\n\nAvailable IFDs\n----------------------------------------------------\n Offset: 42\n Entries: 42\n Next IFD: 0\n\n Spam [EGGS]: 42 {count: 1}\n----------------------------------------------------\n\n====================================================\n"
"""
def format_headers(headers) do
"""
Expand All @@ -24,47 +13,23 @@ defmodule GeoTIFFFormatter do
"""
end

@doc ~S"""
Formats a single IFD.
### Examples:
iex> tag = %{:tag => "Spam", :type => "EGGS", :value => 42, :count => 1}
iex> ifd = %{:offset => 42, :entries => 42, :next_ifd => 0, :tags => [tag]}
iex> GeoTIFFFormatter.format_ifd ifd
"----------------------------------------------------\n Offset: 42\n Entries: 42\n Next IFD: 0\n\n Spam [EGGS]: 42 {count: 1}\n----------------------------------------------------\n"
"""
def format_ifd(ifd) do
"""
----------------------------------------------------
Offset: #{ifd.offset}
Entries: #{ifd.entries}
Next IFD: #{ifd.next_ifd}
Offset: #{ifd.offset}
Entries: #{ifd.entries}
Next IFD: #{ifd.next_ifd}
#{Enum.map(ifd.tags, &(format_tag(&1))) |> Enum.join("\n")}
#{Enum.map(ifd.tags, &(format_tag(&1))) |> Enum.join("\n")}
----------------------------------------------------
"""
end

@doc ~S"""
Formats a single TIFF tag.
### Examples:
iex> tag = %{:tag => "Spam", :type => "EGGS", :value => 42, :count => 1}
iex> GeoTIFFFormatter.format_tag tag
" Spam [EGGS]: 42 {count: 1}"
iex> tag = %{:tag => "Spam", :type => "EGGS", :value => [4, 2, 42], :count => 12}
iex> GeoTIFFFormatter.format_tag tag
" Spam [EGGS]: [4, 2, 42] {count: 12}"
"""

def format_tag(tag) do
cond do
is_list(tag.value) ->
" #{tag.tag} [#{tag.type}]: #{"[" <> (Enum.join tag.value, ", ") <> "]"} {count: #{tag.count}}"
true ->
" #{tag.tag} [#{tag.type}]: #{tag.value} {count: #{tag.count}}"
if is_list(tag.value) do
"#{tag.tag} [#{tag.type}]: OFFSET {count: #{tag.count}}"
else
"#{tag.tag} [#{tag.type}]: #{tag.value} {count: #{tag.count}}"
end
end
end
46 changes: 45 additions & 1 deletion test/geotiff_formatter_test.exs
@@ -1,4 +1,48 @@
defmodule GeoTIFFFormatterTest do
use ExUnit.Case
doctest GeoTIFFFormatter

test 'format headers' do
expected_text = """
====================================================
Filename: spam.tiff
Endianess: little
First IFD: 42
Available IFDs
====================================================
"""
headers = %{
:filename => 'spam.tiff',
:endianess => :little,
:first_ifd_offset => 42,
:ifds => []
}

assert GeoTIFFFormatter.format_headers(headers) == expected_text
end

test 'format IFD' do
expected_text = """
----------------------------------------------------
Offset: 42
Entries: 100
Next IFD: 82
Spam [text]: eggs {count: 42}
----------------------------------------------------
"""
tag = %{ :tag => 'Spam', :type => 'text', :value => "eggs", :count => 42 }
ifd = %{ :offset => 42, :entries => 100, :next_ifd => 82, :tags => [ tag ] }

assert GeoTIFFFormatter.format_ifd(ifd) == expected_text
end

test 'format tag' do
tag = %{ :tag => 'Spam', :type => 'text', :value => "eggs", :count => 42 }
expected_text = "Spam [text]: eggs {count: 42}"

assert GeoTIFFFormatter.format_tag(tag) == expected_text
end
end

0 comments on commit afa42fa

Please sign in to comment.