Created
March 13, 2012 11:02
-
-
Save bellthoven/2028139 to your computer and use it in GitHub Desktop.
Elixir patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/file.ex b/lib/file.ex | |
index b64161c..b5715fd 100644 | |
--- a/lib/file.ex | |
+++ b/lib/file.ex | |
@@ -53,6 +53,41 @@ defmodule File do | |
FN.basename(path, extension) | |
end | |
+ @doc """ | |
+ Returns a string with one or more paths components joint by the path separator. | |
+ This function should be used to convert a list of strings in a path. | |
+ | |
+ ## Examples | |
+ | |
+ File.join(["~", "foo"]) | |
+ #=> "~/foo" | |
+ File.join(["foo"]) | |
+ #=> "foo" | |
+ File.join(["/", "foo", "bar"]) | |
+ #=> "/foo/bar" | |
+ """ | |
+ def join(paths) do | |
+ FN.join(paths) | |
+ end | |
+ | |
+ @doc """ | |
+ Returns a list with the path splitted by the path separator. If an empty string | |
+ is given, then it returns the root path. | |
+ | |
+ ## Examples | |
+ | |
+ File.split("") | |
+ #=> ["/"] | |
+ File.split("foo") | |
+ #=> ["foo"] | |
+ File.split("/foo/bar") | |
+ #=> ["/", "foo", "bar"] | |
+ | |
+ """ | |
+ def split(path) do | |
+ FN.split(path) | |
+ end | |
+ | |
# Points to Elixir wildcard version that also handles "**". | |
def wildcard(path, relative_to // '.') do | |
Erlang.elixir_glob.wildcard(path, relative_to) | |
diff --git a/test/elixir/file_test.exs b/test/elixir/file_test.exs | |
index 9aa9254..701511e 100644 | |
--- a/test/elixir/file_test.exs | |
+++ b/test/elixir/file_test.exs | |
@@ -29,8 +29,22 @@ defmodule FileTest do | |
assert_equal "bar", File.basename("/foo/bar") | |
assert_equal "", File.basename("/") | |
- assert_equal "bar" , File.basename("~/foo/bar.ex", ".ex") | |
+ assert_equal "bar", File.basename("~/foo/bar.ex", ".ex") | |
assert_equal "bar.exs", File.basename("~/foo/bar.exs", ".ex") | |
assert_equal "bar.old", File.basename("~/for/bar.old.ex", ".ex") | |
end | |
+ | |
+ test :join do | |
+ assert_equal "", File.join([""]) | |
+ assert_equal "foo", File.join(["foo"]) | |
+ assert_equal "/foo/bar", File.join(["/", "foo", "bar"]) | |
+ assert_equal "~/foo/bar", File.join(["~", "foo", "bar"]) | |
+ end | |
+ | |
+ test :split do | |
+ assert_equal ["/"], File.split("") | |
+ assert_equal ["foo"], File.split("foo") | |
+ assert_equal ["/", "foo", "bar"], File.split("/foo/bar") | |
+ end | |
+ | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment