Skip to content
This repository has been archived by the owner on Jun 1, 2021. It is now read-only.

Commit

Permalink
Add as as an alias of narrow
Browse files Browse the repository at this point in the history
  • Loading branch information
sd-yip committed Jan 27, 2019
1 parent c00b469 commit ac719b9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions core/src/main/scala/eyrie/syntax/ConvertibleSyntax.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ final class ConvertibleOps[A](private val a: A) extends AnyVal {

def narrowBy[Qual](implicit F: Convertible.ByQuality[Qual, A]): Option[F.Out] =
F.narrow(a)

def as[B](implicit F: Convertible[B, A]): Option[B] =
F.narrow(a)
}
16 changes: 15 additions & 1 deletion file/src/test/scala/eyrie/file/test/ConvertibleSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.nio.file.Paths
import eyrie.{Emptiness, False, Relativity, True}
import eyrie.file.FilePath.Internal
import eyrie.file.context.Sys
import eyrie.file.{FilePath, IdentityFilePath, RelativeFile}
import eyrie.file.{FilePath, IdentityFilePath, RelativeFile, RootDirectory}
import org.junit.runner.RunWith
import org.scalatest.FreeSpec
import org.scalatest.junit.JUnitRunner
Expand All @@ -16,6 +16,9 @@ object ConvertibleSpec {

val relativeFile: RelativeFile[Sys] =
Internal.RelativeFile(Paths.get("a/b/c"))

val empty: FilePath.Empty[Sys] =
Internal.RootDirectory(Paths.get("a/b/c").toAbsolutePath.getRoot)
}

@RunWith(classOf[JUnitRunner])
Expand Down Expand Up @@ -54,4 +57,15 @@ class ConvertibleSpec extends FreeSpec {
relativeFile.widenBy[Relativity]: FilePath.NonEmpty[Sys]
}
}
"FilePath.Empty" - {
"typed narrow should work" in {
empty.narrow[RootDirectory[Sys]]
}
"typed narrowBy should work" in {
empty.narrowBy[Relativity[False]]
}
"typed as should work" in {
empty.as[RootDirectory[Sys]]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ object PotentialDescendantSpec {

val filePath: FilePath[Sys] =
Internal.RootDirectory(Paths.get("a/b/c").getRoot)

val empty: FilePath.Empty[Sys] =
Internal.RootDirectory(Paths.get("a/b/c").getRoot)
}

@RunWith(classOf[JUnitRunner])
Expand All @@ -32,4 +35,9 @@ class PotentialDescendantSpec extends FreeSpec {
filePath.rootOption: Option[RootDirectory[Sys]]
}
}
"FilePath.Empty" - {
"rootOption should be Option of RootDirectory" in {
empty.rootOption: Option[RootDirectory[Sys]]
}
}
}

0 comments on commit ac719b9

Please sign in to comment.