Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: introduce oracle testing #3

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/elixlsx/workbook.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ defmodule Elixlsx.Workbook do
@moduledoc ~S"""
Root structure for excel files.

Must contain at least one Elixlsx.Sheet object.

The datetime property can optionally be set to override
the "created at" date. It defaults to the current time.
"""
Expand Down
5 changes: 4 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ defmodule Elixlsx.Mixfile do
{:credo, "~> 1.6", only: [:dev, :test], runtime: false},
{:propcheck, "~> 1.4", only: [:dev, :test]},
{:ex_doc, ">= 0.0.0", only: [:dev], runtime: false},
{:dialyxir, "~> 1.0", only: [:dev], runtime: false}
{:dialyxir, "~> 1.0", only: [:dev], runtime: false},

# Oracle
{:xlsx_reader, "~> 0.8.0", only: [:test]}
]
end

Expand Down
2 changes: 2 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
"propcheck": {:hex, :propcheck, "1.4.1", "c12908dbe6f572032928548089b34ff9d40672d5d70f1562e3a9e9058d226cc9", [:mix], [{:libgraph, "~> 0.13", [hex: :libgraph, repo: "hexpm", optional: false]}, {:proper, "~> 1.4", [hex: :proper, repo: "hexpm", optional: false]}], "hexpm", "e1b088f574785c3c7e864da16f39082d5599b3aaf89086d3f9be6adb54464b19"},
"proper": {:hex, :proper, "1.4.0", "89a44b8c39d28bb9b4be8e4d715d534905b325470f2e0ec5e004d12484a79434", [:rebar3], [], "hexpm", "18285842185bd33efbda97d134a5cb5a0884384db36119fee0e3cfa488568cbb"},
"saxy": {:hex, :saxy, "1.5.0", "0141127f2d042856f135fb2d94e0beecda7a2306f47546dbc6411fc5b07e28bf", [:mix], [], "hexpm", "ea7bb6328fbd1f2aceffa3ec6090bfb18c85aadf0f8e5030905e84235861cf89"},
"triq": {:hex, :triq, "1.3.0", "d9ed60f3cd2b6bacbb721bc9873e67e07b02e5b97c63d40db35b12670a7f1bf4", [:rebar3], [], "hexpm", "e01eb99fc53099ded985bb0c629ea0d2b0bfcf5b9a4178e0a93b08dbe51aa8cd"},
"xlsx_reader": {:hex, :xlsx_reader, "0.8.5", "38eeee188a0cefcd02de6c3d92dadde86ab6d19c25af8715426fd4371ae578f7", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}, {:saxy, "~> 1.5.0", [hex: :saxy, repo: "hexpm", optional: false]}], "hexpm", "7ab63f243750c2b41fada3683ec22fd7d0415f0da54460bd61bef1296c952395"},
}
47 changes: 47 additions & 0 deletions test/oracle_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
defmodule OracleTest do
use ExUnit.Case

alias Elixlsx.Workbook
alias Elixlsx.Sheet

@oracle XlsxReader

defp check(bin) do
{:ok, package} = @oracle.open(bin, source: :binary)
{:ok, _sheets} = @oracle.sheets(package)

:ok
end

test "empty workbook" do
assert {:ok, {_, bin}} = Elixlsx.write_to_memory(%Workbook{}, "")
assert check(bin)
end

test "empty sheet" do
s = Sheet.with_name("1")
wk = %Workbook{} |> Workbook.append_sheet(s)

assert {:ok, {_, bin}} = Elixlsx.write_to_memory(wk, "")
assert check(bin)
end

test "multiple sheets" do
s1 = Sheet.with_name("1")
s2 = Sheet.with_name("2")
wk = %Workbook{} |> Workbook.append_sheet(s1) |> Workbook.append_sheet(s2)

assert {:ok, {_, bin}} = Elixlsx.write_to_memory(wk, "")
assert check(bin)
end

test "date cells" do
s = Sheet.with_name("1") |> Sheet.set_cell("A4", {{2015, 11, 30}, {21, 20, 38}}, yyyymmdd: true)

wk = %Workbook{} |> Workbook.append_sheet(s)

assert {:ok, {_, bin}} = Elixlsx.write_to_memory(wk, "")

assert check(bin)
end
end
Loading