Skip to content

Commit

Permalink
uri / extension fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-williams committed Apr 5, 2017
1 parent b74f864 commit df80872
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name := "paths"
version := "1.0.1"
version := "1.0.2"
deps += libs.value('commons_io)
addScala212
6 changes: 3 additions & 3 deletions src/main/scala/org/hammerlab/paths/Path.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class Path(val path: JPath)
extends AnyVal
with Serializable {

override def toString: String = uri.toString
override def toString: String = path.toString

def uri: URI = path.toUri

def extension: String = getExtension(toString)
def extension: String = getExtension(basename)

def exists: Boolean = Files.exists(path)

Expand Down Expand Up @@ -80,7 +80,7 @@ class Path(val path: JPath)
/**
* Append `suffix` to the basename of this [[Path]].
*/
def +(suffix: String): Path = Path(toString + suffix)
def +(suffix: String): Path = Path(path.toString + suffix)

def /(basename: String): Path = Path(path.resolve(basename))

Expand Down
10 changes: 10 additions & 0 deletions src/test/scala/org/hammerlab/paths/PathTest.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.hammerlab.paths

import java.nio.file.Files
import java.nio.file.Files.createDirectory

import org.hammerlab.test.Suite
Expand All @@ -11,8 +12,17 @@ class PathTest

test("extensions") {
"abc.def".extension should be("def")
Path("abc.def") + ".ghi" should be(Path("abc.def.ghi"))
Path("abc.def") / "ghi" should be(Path("abc.def/ghi"))

"/abc/def.gh.ij".extension should be("ij")
"file:///foo/bar.baz".extension should be("baz")
Path("file:///foo/bar.baz") + ".qux" should be(Path("file:///foo/bar.baz.qux"))
Path("file:///foo/bar.baz") / "qux" should be(Path("file:///foo/bar.baz/qux"))

val dir = tmpPath(suffix = ".foo")
Files.createDirectory(dir)
dir.extension should be("foo")
}

test("removals") {
Expand Down

0 comments on commit df80872

Please sign in to comment.