From f24c178421140005c74d28bc32ef6218552d5838 Mon Sep 17 00:00:00 2001 From: JF Burdet Date: Wed, 1 Mar 2023 17:41:23 +0100 Subject: [PATCH 1/5] Change test case to reflect actual xls content Opening ./test/test_data/missing_styles.xlsx in libre office and office365 shows '21.06.2019 02:39:12' So testing against 02:39:11 was a mistake. (now tests are broken) --- test/xlsxir_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/xlsxir_test.exs b/test/xlsxir_test.exs index 3090e76..ead2518 100644 --- a/test/xlsxir_test.exs +++ b/test/xlsxir_test.exs @@ -119,7 +119,7 @@ defmodule XlsxirTest do expected_rows = [ ["Tag", "Type", "Status", "Commissioned"], - ["abc123", "InProgress", "Complete", ~N[2019-06-21 02:39:11]] + ["abc123", "InProgress", "Complete", ~N[2019-06-21 02:39:12]] ] assert get_list(pid) == expected_rows From 8cff4e9763f3204dc66368d78888df2b42095c74 Mon Sep 17 00:00:00 2001 From: JF Burdet Date: Wed, 1 Mar 2023 17:43:46 +0100 Subject: [PATCH 2/5] Adding a test case This is the use case that made me discover the bug that will be fixed in next commit. 0.395833333333333 should be interpreted as 9h30mn0s but actual code interprets it as 9h29mn59s --- test/convert_time_test.exs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/convert_time_test.exs b/test/convert_time_test.exs index 1bd3843..22d8aec 100644 --- a/test/convert_time_test.exs +++ b/test/convert_time_test.exs @@ -9,7 +9,9 @@ defmodule ConvertTimeTest do '0.5' => {12, 0, 0}, '0.29166666666666669' => {7, 0, 0}, '0.64583333333333337' => {15, 30, 0}, - '0.754'=> {18, 5, 45}} + '0.754'=> {18, 5, 45}, + '0.395833333333333' => {9, 30, 0} + } test "converts fractions to the appropriate numbers" do From a6afd45df784e3130416d7cacd6215c365893492 Mon Sep 17 00:00:00 2001 From: JF Burdet Date: Wed, 1 Mar 2023 17:44:13 +0100 Subject: [PATCH 3/5] Removing uneeded empty config.exs file --- config/config.exs | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 config/config.exs diff --git a/config/config.exs b/config/config.exs deleted file mode 100644 index b1a43bf..0000000 --- a/config/config.exs +++ /dev/null @@ -1,7 +0,0 @@ -# This file is responsible for configuring your application -# and its dependencies with the aid of the Mix.Config module. -use Mix.Config - -# when extracting to file, files will be extracted -# in a sub directory in the `:extract_base_dir` directory. -# config :xlsxir, extract_base_dir: "temp" From fb351551faf50446ba7f951e82756638a975423a Mon Sep 17 00:00:00 2001 From: JF Burdet Date: Wed, 1 Mar 2023 17:45:20 +0100 Subject: [PATCH 4/5] Fixing datetime code --- lib/xlsxir/convert_datetime.ex | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/xlsxir/convert_datetime.ex b/lib/xlsxir/convert_datetime.ex index bc0a3b7..79a6ef0 100644 --- a/lib/xlsxir/convert_datetime.ex +++ b/lib/xlsxir/convert_datetime.ex @@ -30,9 +30,11 @@ defmodule Xlsxir.ConvertDateTime do end defp convert_from_serial(time) when is_float(time) and time >= 0 and time < 1.0 do - {hours, min_fraction} = split_float(time * 24) - {minutes, sec_fraction} = split_float(min_fraction * 60) - {seconds, _} = split_float(sec_fraction * 60) + total_seconds = (time * 86400) |> Float.round(2) |> trunc() + + hours = div(total_seconds, 60 * 60) + minutes = div(total_seconds - hours * 60 * 60, 60) + seconds = total_seconds - hours * 60 * 60 - minutes * 60 {hours, minutes, seconds} end From 3dd40f58a58d7ef0fa4bbe980048858794bfaa82 Mon Sep 17 00:00:00 2001 From: JF Burdet Date: Wed, 1 Mar 2023 17:46:25 +0100 Subject: [PATCH 5/5] Adding format + 'mix format' This commit has no functional changes, only applying now standard 'mix format' command --- .formatter.exs | 4 + lib/xlsxir.ex | 1 - lib/xlsxir/convert_date.ex | 46 +++--- lib/xlsxir/convert_datetime.ex | 13 +- lib/xlsxir/parse_string.ex | 25 ++-- lib/xlsxir/unzip.ex | 88 +++++++----- lib/xlsxir/xlsx_file.ex | 4 +- lib/xlsxir/xml_file.ex | 2 +- mix.exs | 31 ++-- test/convert_date_test.exs | 256 ++++++++++++++++++++++----------- test/convert_time_test.exs | 18 +-- test/doc_test.exs | 2 +- test/sax_parser_test.exs | 2 +- test/stream_test.exs | 8 +- test/xml_file_test.exs | 12 +- 15 files changed, 316 insertions(+), 196 deletions(-) create mode 100644 .formatter.exs diff --git a/.formatter.exs b/.formatter.exs new file mode 100644 index 0000000..d2cda26 --- /dev/null +++ b/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/lib/xlsxir.ex b/lib/xlsxir.ex index 03fa492..1c0a170 100644 --- a/lib/xlsxir.ex +++ b/lib/xlsxir.ex @@ -4,7 +4,6 @@ defmodule Xlsxir do use Application def start(_type, _args) do - children = [ %{id: Xlsxir.StateManager, start: {Xlsxir.StateManager, :start_link, []}, type: :worker} ] diff --git a/lib/xlsxir/convert_date.ex b/lib/xlsxir/convert_date.ex index 1210b87..b4f4de4 100644 --- a/lib/xlsxir/convert_date.ex +++ b/lib/xlsxir/convert_date.ex @@ -18,20 +18,27 @@ defmodule Xlsxir.ConvertDate do {1975, 4, 30} """ def from_serial(serial) do - f_serial = serial - |> convert_char_number - |> is_float - |> case do - false -> List.to_integer(serial) - true -> serial - |> List.to_float() - |> Float.floor - |> round - end + f_serial = + serial + |> convert_char_number + |> is_float + |> case do + false -> + List.to_integer(serial) + + true -> + serial + |> List.to_float() + |> Float.floor() + |> round + end # Convert to gregorian days and get date from that - gregorian = f_serial - 2 + # adjust two days for first and last day since base year - date_to_days({1900, 1, 1}) # Add days in base year 1900 + # adjust two days for first and last day since base year + # Add days in base year 1900 + gregorian = + f_serial - 2 + + date_to_days({1900, 1, 1}) gregorian |> days_to_date @@ -50,11 +57,14 @@ defmodule Xlsxir.ConvertDate do str |> String.match?(~r/[.eE]/) |> case do - false -> List.to_integer(number) - true -> case Float.parse(str) do - {f, _} -> f - _ -> raise "Invalid Float" - end - end + false -> + List.to_integer(number) + + true -> + case Float.parse(str) do + {f, _} -> f + _ -> raise "Invalid Float" + end + end end end diff --git a/lib/xlsxir/convert_datetime.ex b/lib/xlsxir/convert_datetime.ex index 79a6ef0..c2b95cb 100644 --- a/lib/xlsxir/convert_datetime.ex +++ b/lib/xlsxir/convert_datetime.ex @@ -18,14 +18,16 @@ defmodule Xlsxir.ConvertDateTime do ~N[2012-12-18 14:26:00] """ def from_charlist('0'), do: {0, 0, 0} + def from_charlist(charlist) do charlist - |> List.to_float + |> List.to_float() |> from_float end def from_float(n) when is_float(n) do - n = if n > 59, do: n - 1, else: n # Lotus bug + # Lotus bug + n = if n > 59, do: n - 1, else: n convert_from_serial(n) end @@ -38,6 +40,7 @@ defmodule Xlsxir.ConvertDateTime do {hours, minutes, seconds} end + defp convert_from_serial(n) when is_float(n) do {whole_days, fractional_day} = split_float(n) {hours, minutes, seconds} = convert_from_serial(fractional_day) @@ -50,9 +53,11 @@ defmodule Xlsxir.ConvertDateTime do end defp split_float(f) do - whole = f - |> Float.floor + whole = + f + |> Float.floor() |> round + {whole, f - whole} end end diff --git a/lib/xlsxir/parse_string.ex b/lib/xlsxir/parse_string.ex index b8e20d2..da85e7f 100644 --- a/lib/xlsxir/parse_string.ex +++ b/lib/xlsxir/parse_string.ex @@ -22,22 +22,27 @@ defmodule Xlsxir.ParseString do %__MODULE__{tid: GenServer.call(Xlsxir.StateManager, :new_table)} end - def sax_event_handler({:startElement,_,'si',_,_}, %__MODULE__{tid: tid, index: index}), do: %__MODULE__{tid: tid, index: index} + def sax_event_handler({:startElement, _, 'si', _, _}, %__MODULE__{tid: tid, index: index}), + do: %__MODULE__{tid: tid, index: index} - def sax_event_handler({:startElement,_,'family',_,_}, state) do + def sax_event_handler({:startElement, _, 'family', _, _}, state) do %{state | family: true} end - def sax_event_handler({:characters, value}, - %__MODULE__{family_string: fam_str} = state) do - value = value |> to_string - %{state | family_string: fam_str <> value} + def sax_event_handler( + {:characters, value}, + %__MODULE__{family_string: fam_str} = state + ) do + value = value |> to_string + %{state | family_string: fam_str <> value} end - def sax_event_handler({:endElement,_,'si',_}, - %__MODULE__{family_string: fam_str, tid: tid, index: index} = state) do - :ets.insert(tid, {index, fam_str}) - %{state | index: index + 1} + def sax_event_handler( + {:endElement, _, 'si', _}, + %__MODULE__{family_string: fam_str, tid: tid, index: index} = state + ) do + :ets.insert(tid, {index, fam_str}) + %{state | index: index + 1} end def sax_event_handler(_, state), do: state diff --git a/lib/xlsxir/unzip.ex b/lib/xlsxir/unzip.ex index 6d4fb40..a3afffa 100644 --- a/lib/xlsxir/unzip.ex +++ b/lib/xlsxir/unzip.ex @@ -1,5 +1,4 @@ defmodule Xlsxir.Unzip do - alias Xlsxir.XmlFile @moduledoc """ @@ -39,7 +38,7 @@ defmodule Xlsxir.Unzip do path = String.to_charlist(path) case valid_extract_request?(path, index) do - :ok -> {:ok, path} + :ok -> {:ok, path} {:error, reason} -> {:error, reason} end end @@ -68,47 +67,57 @@ defmodule Xlsxir.Unzip do def validate_path_all_indexes(path) do path = String.to_charlist(path) + case :zip.list_dir(path) do - {:ok, file_list} -> - indexes = file_list - |> Enum.filter(fn (file) -> - case file do - {:zip_file, filename, _, _, _, _} -> - filename |> to_string |> String.starts_with?("xl/worksheets/sheet") - _ -> - nil - end - end) - |> Enum.map(fn ({:zip_file, filename, _, _, _, _}) -> - index = filename - |> to_string - |> String.replace_prefix("xl/worksheets/sheet", "") - |> String.replace_suffix(".xml", "") - |> String.to_integer - index - 1 - end) - |> Enum.sort + {:ok, file_list} -> + indexes = + file_list + |> Enum.filter(fn file -> + case file do + {:zip_file, filename, _, _, _, _} -> + filename |> to_string |> String.starts_with?("xl/worksheets/sheet") + + _ -> + nil + end + end) + |> Enum.map(fn {:zip_file, filename, _, _, _, _} -> + index = + filename + |> to_string + |> String.replace_prefix("xl/worksheets/sheet", "") + |> String.replace_suffix(".xml", "") + |> String.to_integer() + + index - 1 + end) + |> Enum.sort() + {:ok, indexes} - {:error, _reason} -> {:error, @filetype_error} + + {:error, _reason} -> + {:error, @filetype_error} end end defp valid_extract_request?(path, index) do case :zip.list_dir(path) do - {:ok, file_list} -> search_file_list(file_list, index) + {:ok, file_list} -> search_file_list(file_list, index) {:error, _reason} -> {:error, @filetype_error} end end defp search_file_list(file_list, index) do - sheet = 'xl/worksheets/sheet#{index + 1}.xml' - results = file_list - |> Enum.map(fn file -> - case file do - {:zip_file, ^sheet, _, _, _, _} -> :ok - _ -> nil - end - end) + sheet = 'xl/worksheets/sheet#{index + 1}.xml' + + results = + file_list + |> Enum.map(fn file -> + case file do + {:zip_file, ^sheet, _, _, _, _} -> :ok + _ -> nil + end + end) if Enum.member?(results, :ok) do :ok @@ -144,14 +153,17 @@ defmodule Xlsxir.Unzip do |> to_charlist |> extract_from_zip(file_list, to) |> case do - {:error, reason} -> {:error, reason} - {:ok, []} -> {:error, @xml_not_found_error} - {:ok, files_list} -> {:ok, build_xml_files(files_list)} - end + {:error, reason} -> {:error, reason} + {:ok, []} -> {:error, @xml_not_found_error} + {:ok, files_list} -> {:ok, build_xml_files(files_list)} + end end - defp extract_from_zip(path, file_list, :memory), do: :zip.extract(path, [{:file_list, file_list}, :memory]) - defp extract_from_zip(path, file_list, {:file, dest_path}), do: :zip.extract(path, [{:file_list, file_list}, {:cwd, dest_path}]) + defp extract_from_zip(path, file_list, :memory), + do: :zip.extract(path, [{:file_list, file_list}, :memory]) + + defp extract_from_zip(path, file_list, {:file, dest_path}), + do: :zip.extract(path, [{:file_list, file_list}, {:cwd, dest_path}]) defp build_xml_files(files_list) do files_list @@ -165,6 +177,6 @@ defmodule Xlsxir.Unzip do # When extracting to temp file defp build_xml_file(file_path) do - %XmlFile{name: Path.basename(file_path), path: to_string(file_path)} + %XmlFile{name: Path.basename(file_path), path: to_string(file_path)} end end diff --git a/lib/xlsxir/xlsx_file.ex b/lib/xlsxir/xlsx_file.ex index ac2f9a4..ee1a993 100644 --- a/lib/xlsxir/xlsx_file.ex +++ b/lib/xlsxir/xlsx_file.ex @@ -115,7 +115,7 @@ defmodule Xlsxir.XlsxFile do defp fill_empty_cells_at_end(tid, end_column, index) when is_integer(index) do build_and_replace(tid, end_column, index) - nex_index= :ets.next(tid, index) + nex_index = :ets.next(tid, index) fill_empty_cells_at_end(tid, end_column, nex_index) end @@ -133,7 +133,7 @@ defmodule Xlsxir.XlsxFile do empty_cells = Xlsxir.ParseWorksheet.fill_empty_cells(from, to, index, []) new_cells = cells ++ empty_cells - true = :ets.insert(tid, {index, new_cells}) + true = :ets.insert(tid, {index, new_cells}) end @doc """ diff --git a/lib/xlsxir/xml_file.ex b/lib/xlsxir/xml_file.ex index 45bdb28..2ad31d3 100644 --- a/lib/xlsxir/xml_file.ex +++ b/lib/xlsxir/xml_file.ex @@ -5,7 +5,7 @@ defmodule Xlsxir.XmlFile do (located in the `path` field) """ - defstruct [name: nil, path: nil, content: nil] + defstruct name: nil, path: nil, content: nil @doc """ Open an XmlFile diff --git a/mix.exs b/mix.exs index dbac462..b2e364c 100644 --- a/mix.exs +++ b/mix.exs @@ -3,17 +3,17 @@ defmodule Xlsxir.Mixfile do def project do [ - app: :xlsxir, - version: "1.6.4", - name: "Xlsxir", - source_url: "https://github.com/jsonkenl/xlsxir", - elixir: "~> 1.4", - build_embedded: Mix.env == :prod, - start_permanent: Mix.env == :prod, - description: description(), - package: package(), - deps: deps(), - docs: [main: "overview", extras: ["CHANGELOG.md", "NUMBER_STYLES.md", "OVERVIEW.md"]] + app: :xlsxir, + version: "1.6.4", + name: "Xlsxir", + source_url: "https://github.com/jsonkenl/xlsxir", + elixir: "~> 1.4", + build_embedded: Mix.env() == :prod, + start_permanent: Mix.env() == :prod, + description: description(), + package: package(), + deps: deps(), + docs: [main: "overview", extras: ["CHANGELOG.md", "NUMBER_STYLES.md", "OVERVIEW.md"]] ] end @@ -27,7 +27,7 @@ defmodule Xlsxir.Mixfile do defp deps do [ {:ex_doc, "~> 0.19", only: :dev, runtime: false}, - #{:earmark, github: "pragdave/earmark", override: true, only: :dev}, + # {:earmark, github: "pragdave/earmark", override: true, only: :dev}, {:erlsom, "~> 1.5"} ] end @@ -43,10 +43,9 @@ defmodule Xlsxir.Mixfile do maintainers: ["Jason Kennell"], licenses: ["MIT License"], links: %{ - "Github" => "https://github.com/jsonkenl/xlsxir", - "Change Log" => "https://hexdocs.pm/xlsxir/changelog.html" - } + "Github" => "https://github.com/jsonkenl/xlsxir", + "Change Log" => "https://hexdocs.pm/xlsxir/changelog.html" + } ] end - end diff --git a/test/convert_date_test.exs b/test/convert_date_test.exs index 942a3b2..61c99dc 100644 --- a/test/convert_date_test.exs +++ b/test/convert_date_test.exs @@ -4,22 +4,36 @@ defmodule ConvertDateTest do import Xlsxir.ConvertDate - def test_one_data(), do: ['42005', '42036', '42064', '42095', '42125', '42156', '42186', '42217', '42248', '42278', '42309', '42339'] + def test_one_data(), + do: [ + '42005', + '42036', + '42064', + '42095', + '42125', + '42156', + '42186', + '42217', + '42248', + '42278', + '42309', + '42339' + ] - def test_one_results() do + def test_one_results() do [ - {2015,1,1}, - {2015,2,1}, - {2015,3,1}, - {2015,4,1}, - {2015,5,1}, - {2015,6,1}, - {2015,7,1}, - {2015,8,1}, - {2015,9,1}, - {2015,10,1}, - {2015,11,1}, - {2015,12,1} + {2015, 1, 1}, + {2015, 2, 1}, + {2015, 3, 1}, + {2015, 4, 1}, + {2015, 5, 1}, + {2015, 6, 1}, + {2015, 7, 1}, + {2015, 8, 1}, + {2015, 9, 1}, + {2015, 10, 1}, + {2015, 11, 1}, + {2015, 12, 1} ] end @@ -27,23 +41,38 @@ defmodule ConvertDateTest do assert Enum.map(test_one_data(), &from_serial/1) == test_one_results() end - def test_two_data(), do: ['42035', '42063', '42094', '42124', '42155', '42185', '42216', '42247', '42277', '42308', '42338', '42369', '44530'] + def test_two_data(), + do: [ + '42035', + '42063', + '42094', + '42124', + '42155', + '42185', + '42216', + '42247', + '42277', + '42308', + '42338', + '42369', + '44530' + ] - def test_two_results() do + def test_two_results() do [ - {2015,1,31}, - {2015,2,28}, - {2015,3,31}, - {2015,4,30}, - {2015,5,31}, - {2015,6,30}, - {2015,7,31}, - {2015,8,31}, - {2015,9,30}, - {2015,10,31}, - {2015,11,30}, - {2015,12,31}, - {2021,11,30} + {2015, 1, 31}, + {2015, 2, 28}, + {2015, 3, 31}, + {2015, 4, 30}, + {2015, 5, 31}, + {2015, 6, 30}, + {2015, 7, 31}, + {2015, 8, 31}, + {2015, 9, 30}, + {2015, 10, 31}, + {2015, 11, 30}, + {2015, 12, 31}, + {2021, 11, 30} ] end @@ -51,22 +80,36 @@ defmodule ConvertDateTest do assert Enum.map(test_two_data(), &from_serial/1) == test_two_results() end - def test_three_data(), do: ['42019', '42050', '42078', '42109', '42139', '42170', '42200', '42231', '42262', '42292', '42323', '42353'] + def test_three_data(), + do: [ + '42019', + '42050', + '42078', + '42109', + '42139', + '42170', + '42200', + '42231', + '42262', + '42292', + '42323', + '42353' + ] - def test_three_results() do + def test_three_results() do [ - {2015,1,15}, - {2015,2,15}, - {2015,3,15}, - {2015,4,15}, - {2015,5,15}, - {2015,6,15}, - {2015,7,15}, - {2015,8,15}, - {2015,9,15}, - {2015,10,15}, - {2015,11,15}, - {2015,12,15} + {2015, 1, 15}, + {2015, 2, 15}, + {2015, 3, 15}, + {2015, 4, 15}, + {2015, 5, 15}, + {2015, 6, 15}, + {2015, 7, 15}, + {2015, 8, 15}, + {2015, 9, 15}, + {2015, 10, 15}, + {2015, 11, 15}, + {2015, 12, 15} ] end @@ -74,22 +117,36 @@ defmodule ConvertDateTest do assert Enum.map(test_three_data(), &from_serial/1) == test_three_results() end - def test_four_data(), do: ['42370', '42401', '42430', '42461', '42491', '42522', '42552', '42583', '42614', '42644', '42675', '42705'] + def test_four_data(), + do: [ + '42370', + '42401', + '42430', + '42461', + '42491', + '42522', + '42552', + '42583', + '42614', + '42644', + '42675', + '42705' + ] - def test_four_results() do + def test_four_results() do [ - {2016,1,1}, - {2016,2,1}, - {2016,3,1}, - {2016,4,1}, - {2016,5,1}, - {2016,6,1}, - {2016,7,1}, - {2016,8,1}, - {2016,9,1}, - {2016,10,1}, - {2016,11,1}, - {2016,12,1} + {2016, 1, 1}, + {2016, 2, 1}, + {2016, 3, 1}, + {2016, 4, 1}, + {2016, 5, 1}, + {2016, 6, 1}, + {2016, 7, 1}, + {2016, 8, 1}, + {2016, 9, 1}, + {2016, 10, 1}, + {2016, 11, 1}, + {2016, 12, 1} ] end @@ -97,22 +154,36 @@ defmodule ConvertDateTest do assert Enum.map(test_four_data(), &from_serial/1) == test_four_results() end - def test_five_data(), do: ['42400', '42429', '42460', '42490', '42521', '42551', '42582', '42613', '42643', '42674', '42704', '42735'] + def test_five_data(), + do: [ + '42400', + '42429', + '42460', + '42490', + '42521', + '42551', + '42582', + '42613', + '42643', + '42674', + '42704', + '42735' + ] - def test_five_results() do + def test_five_results() do [ - {2016,1,31}, - {2016,2,29}, - {2016,3,31}, - {2016,4,30}, - {2016,5,31}, - {2016,6,30}, - {2016,7,31}, - {2016,8,31}, - {2016,9,30}, - {2016,10,31}, - {2016,11,30}, - {2016,12,31} + {2016, 1, 31}, + {2016, 2, 29}, + {2016, 3, 31}, + {2016, 4, 30}, + {2016, 5, 31}, + {2016, 6, 30}, + {2016, 7, 31}, + {2016, 8, 31}, + {2016, 9, 30}, + {2016, 10, 31}, + {2016, 11, 30}, + {2016, 12, 31} ] end @@ -120,27 +191,40 @@ defmodule ConvertDateTest do assert Enum.map(test_five_data(), &from_serial/1) == test_five_results() end - def test_six_data(), do: ['42384', '42415', '42444', '42475', '42505', '42536', '42566', '42597', '42628', '42658', '42689', '42719'] + def test_six_data(), + do: [ + '42384', + '42415', + '42444', + '42475', + '42505', + '42536', + '42566', + '42597', + '42628', + '42658', + '42689', + '42719' + ] - def test_six_results() do + def test_six_results() do [ - {2016,1,15}, - {2016,2,15}, - {2016,3,15}, - {2016,4,15}, - {2016,5,15}, - {2016,6,15}, - {2016,7,15}, - {2016,8,15}, - {2016,9,15}, - {2016,10,15}, - {2016,11,15}, - {2016,12,15} + {2016, 1, 15}, + {2016, 2, 15}, + {2016, 3, 15}, + {2016, 4, 15}, + {2016, 5, 15}, + {2016, 6, 15}, + {2016, 7, 15}, + {2016, 8, 15}, + {2016, 9, 15}, + {2016, 10, 15}, + {2016, 11, 15}, + {2016, 12, 15} ] end test "middle of every month in leap year (2016)" do assert Enum.map(test_six_data(), &from_serial/1) == test_six_results() end - end diff --git a/test/convert_time_test.exs b/test/convert_time_test.exs index 22d8aec..ab56a9d 100644 --- a/test/convert_time_test.exs +++ b/test/convert_time_test.exs @@ -4,15 +4,15 @@ defmodule ConvertTimeTest do import Xlsxir.ConvertDateTime - @test_data %{'0.0' => {0, 0 , 0}, - '0.25' => {6, 0, 0}, - '0.5' => {12, 0, 0}, - '0.29166666666666669' => {7, 0, 0}, - '0.64583333333333337' => {15, 30, 0}, - '0.754'=> {18, 5, 45}, - '0.395833333333333' => {9, 30, 0} - } - + @test_data %{ + '0.0' => {0, 0, 0}, + '0.25' => {6, 0, 0}, + '0.5' => {12, 0, 0}, + '0.29166666666666669' => {7, 0, 0}, + '0.64583333333333337' => {15, 30, 0}, + '0.754' => {18, 5, 45}, + '0.395833333333333' => {9, 30, 0} + } test "converts fractions to the appropriate numbers" do for {input, expected} <- @test_data do diff --git a/test/doc_test.exs b/test/doc_test.exs index fd6e87b..2489069 100644 --- a/test/doc_test.exs +++ b/test/doc_test.exs @@ -5,4 +5,4 @@ defmodule DocTest do doctest Xlsxir.ConvertDate doctest Xlsxir.SaxParser doctest Xlsxir.XlsxFile -end \ No newline at end of file +end diff --git a/test/sax_parser_test.exs b/test/sax_parser_test.exs index 64ce90c..35b6bfb 100644 --- a/test/sax_parser_test.exs +++ b/test/sax_parser_test.exs @@ -14,7 +14,7 @@ defmodule SaxParserTest do defp find_string(tid, index) do :ets.lookup(tid, index) - |> List.first + |> List.first() |> elem(1) end end diff --git a/test/stream_test.exs b/test/stream_test.exs index 7c57abe..3c33b4d 100644 --- a/test/stream_test.exs +++ b/test/stream_test.exs @@ -8,17 +8,17 @@ defmodule StreamTest do test "produces a stream" do s = stream_list(path(), 8) assert %Stream{} = s - assert 51 == s |> Enum.map(&(&1)) |> length + assert 51 == s |> Enum.map(& &1) |> length end test "stream can run multiple times" do s = stream_list(path(), 8) assert %Stream{} = s # First run should proceed normally - assert {:ok, _} = Task.yield( Task.async( fn() -> s |> Stream.run() end ), 2000) + assert {:ok, _} = Task.yield(Task.async(fn -> s |> Stream.run() end), 2000) # second run will hang on missing fs resources (before fix) and hang (default 60s) - assert {:ok, _} = Task.yield( Task.async( fn() -> s |> Stream.run() end ), 2000) + assert {:ok, _} = Task.yield(Task.async(fn -> s |> Stream.run() end), 2000) # third run because reasons - assert {:ok, _} = Task.yield( Task.async( fn() -> s |> Stream.run() end ), 2000) + assert {:ok, _} = Task.yield(Task.async(fn -> s |> Stream.run() end), 2000) end end diff --git a/test/xml_file_test.exs b/test/xml_file_test.exs index c66bbff..08b4419 100644 --- a/test/xml_file_test.exs +++ b/test/xml_file_test.exs @@ -4,15 +4,18 @@ defmodule XmlFileTest do def no_shared_path(), do: "./test/test_data/noShared.xlsx" test "open memory XmlFile" do - assert {:ok, _file_pid} = Xlsxir.XmlFile.open(%Xlsxir.XmlFile{content: File.read!("./test/test_data/test/xl/styles.xml")}) + assert {:ok, _file_pid} = + Xlsxir.XmlFile.open(%Xlsxir.XmlFile{ + content: File.read!("./test/test_data/test/xl/styles.xml") + }) end test "open filepath XmlFile" do - assert {:ok, _file_pid} = Xlsxir.XmlFile.open(%Xlsxir.XmlFile{path: "./test/test_data/test/xl/styles.xml"}) + assert {:ok, _file_pid} = + Xlsxir.XmlFile.open(%Xlsxir.XmlFile{path: "./test/test_data/test/xl/styles.xml"}) end test "parses xlsx without sharedStings and styles" do - # here is a spec which sayeth there shalt always be shared strings: # # https://msdn.microsoft.com/en-us/library/office/gg278314.aspx @@ -26,7 +29,6 @@ defmodule XmlFileTest do s = Xlsxir.stream_list(no_shared_path(), 0) assert %Stream{} = s - assert 3 == s |> Enum.map(&(&1)) |> length + assert 3 == s |> Enum.map(& &1) |> length end - end