Skip to content

Commit

Permalink
Close #356 - [refined4s-core] Add toUrl to Uri, and add toUri
Browse files Browse the repository at this point in the history
… to `toUrl`
  • Loading branch information
kevin-lee committed Aug 20, 2024
1 parent 5dae157 commit e2b9d83
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ object network {

extension (uri: Type) {
def toURI: URI = new URI(uri.value)

def toUrl: Url = Url(toURI.toURL)
}

}
Expand Down Expand Up @@ -96,6 +98,8 @@ object network {
extension (url: Type) {
@SuppressWarnings(Array("org.wartremover.warts.JavaNetURLConstructors"))
def toURL: URL = new URL(url.value)

def toUri: Uri = Uri(toURL.toURI)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ object networkSpec extends Properties {
property("test Uri.value", testUriValue),
property("test Uri.unapply", testUriUnapply),
property("test Uri.toURI", testUriToURI),
property("test Uri.toUrl", testUriToUrl),
example("test network.isValidateUri(valid URI String)", testNetworkIsValidateUriValid),
example("test network.isValidateUri(invalid URI String)", testNetworkIsValidateUriInvalid),
example("test network.isValidateUri(non-String literal)", testNetworkIsValidateUriWithInvalidLiteral),
Expand All @@ -39,6 +40,7 @@ object networkSpec extends Properties {
property("test Url.value", testUrlValue),
property("test Url.unapply", testUrlUnapply),
property("test Url.toURL", testUrlToURL),
property("test Url.toUri", testUrlToUri),
example("test network.isValidateUrl(valid URL String)", testNetworkIsValidateUrlValid),
example("test network.isValidateUrl(invalid URL String)", testNetworkIsValidateUrlInvalid),
example("test network.isValidateUrl(non-String literal)", testNetworkIsValidateUrlWithInvalidLiteral),
Expand Down Expand Up @@ -220,6 +222,16 @@ object networkSpec extends Properties {
actual ==== expected
}

def testUriToUrl: Property =
for {
uri <- networkGens.genUrlString.log("uri")
} yield {
val expected = Url.unsafeFrom(uri)
val actual = Uri.unsafeFrom(uri).toUrl

actual ==== expected
}

inline def runNetworkIsValidateUri(inline a: String): Boolean = ${ network.isValidateUri('a) }

def testNetworkIsValidateUriValid: Result = {
Expand Down Expand Up @@ -427,6 +439,16 @@ object networkSpec extends Properties {
actual ==== expected
}

def testUrlToUri: Property =
for {
uri <- networkGens.genUrlString.log("uri")
} yield {
val expected = Uri.unsafeFrom(uri)
val actual = Url.unsafeFrom(uri).toUri

actual ==== expected
}

inline def runNetworkIsValidateUrl(inline a: String): Boolean = ${ network.isValidateUrl('a) }

def testNetworkIsValidateUrlValid: Result = {
Expand Down

0 comments on commit e2b9d83

Please sign in to comment.