Skip to content

Commit

Permalink
ENH doing mv right using defdelegate and adding some 2 test for it
Browse files Browse the repository at this point in the history
  • Loading branch information
lowks committed Feb 2, 2015
1 parent fb8b91d commit 43267d5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
9 changes: 7 additions & 2 deletions lib/radpath.ex
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ defmodule Radpath do
Radpath.rename(source, destination)
"""
def mv(source, destination) when is_bitstring(source), do: rename(source, destination)

@doc """
Expand All @@ -137,12 +136,18 @@ defmodule Radpath do
Radpath.rename(source, destination)
or
Radpath.mv(source, destination)
"""

def rename(source, destination) when is_bitstring(source) do
F.rename(source, destination)
end

defdelegate mv(source,destination), to: __MODULE__, as: :rename

@doc """
Gives you back the relative path:
Expand Down Expand Up @@ -307,4 +312,4 @@ defmodule Radpath do
Path.absname(path_str) <> "/"
end

end
end
43 changes: 38 additions & 5 deletions test/radpath_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ defmodule RadpathTests.RadpathFacts do
end
end

facts "Test rename" do
facts "Test rename and mv" do

fact "Test rename: Normal Usage" do
source_file = "/tmp/hoho.txt"
Expand All @@ -232,13 +232,46 @@ defmodule RadpathTests.RadpathFacts do
end
end

fact "Test mv: Normal Usage" do
source_file = "/tmp/hoho.txt"
dest_file = "/tmp/hehe.txt"
File.touch!(source_file)
try do
source_file |> path_exists()
Radpath.mv(source_file, dest_file)
source_file |> ! path_exists()
dest_file |> path_exists()
after
File.rm_rf dest_file
end
end

fact "Test rename: Source file does not exist" do
source_file = "/tmp/hoho.txt"
dest_file = "/tmp/hehe.txt"
source_file |> ! path_exists()
Radpath.rename(source_file, dest_file)
dest_file |> ! path_exists()
try do
source_file |> ! path_exists()
Radpath.rename(source_file, dest_file)
dest_file |> ! path_exists()
after
File.rm_rf source_file
File.rm_rf dest_file
end
end

fact "Test mv: Source file does not exist" do
source_file = "/tmp/hoho.txt"
dest_file = "/tmp/hehe.txt"
try do
source_file |> ! path_exists()
Radpath.mv(source_file, dest_file)
dest_file |> ! path_exists()
after
File.rm_rf source_file
File.rm_rf dest_file
end
end

end

facts "Test relative paths" do
Expand Down Expand Up @@ -295,4 +328,4 @@ defmodule RadpathTests.RadpathFacts do
Radpath.parent_path("/I/am/long/dir") |> "/I/am/long/"
end
end
end
end

0 comments on commit 43267d5

Please sign in to comment.