Skip to content

Commit 16b6d3f

Browse files
committed
Split nil to empty array
1 parent 958170f commit 16b6d3f

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/ltree.ex

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ defmodule Hierarch.LTree do
5757
@doc """
5858
Split string path into an arry
5959
"""
60+
def split(nil), do: []
6061
def split(""), do: []
6162
def split(path) when is_binary(path) do
6263
String.split(path, @separator)

test/ltree_test.exs

+8
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,12 @@ defmodule Hierarch.LtreeTest do
4242
assert root_id == "Top"
4343
end
4444
end
45+
46+
describe "split/1" do
47+
test "works" do
48+
assert [] == LTree.split(nil)
49+
assert [] == LTree.split("")
50+
assert ["Top", "Science"] == LTree.split("Top.Science")
51+
end
52+
end
4553
end

0 commit comments

Comments
 (0)