-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from chainsawriot/fix31
Fix #31
- Loading branch information
Showing
10 changed files
with
94 additions
and
192 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,71 @@ | ||
#' Check if URL has credentials | ||
.has <- function(url, func) { | ||
if (is.null(url)) { | ||
return(logical(0)) | ||
} | ||
func(url) | ||
} | ||
|
||
#' Check if URL has a certain component | ||
#' | ||
#' These functions check if URL has a certain component. | ||
#' @inheritParams ada_url_parse | ||
#' @return logical | ||
#' @return logical, `NA` if not a valid URL. | ||
#' @examples | ||
#' ada_has_credentials("https://user_1:[email protected]:8080/dir/../api?q=1#frag") | ||
#' url <- c("https://user_1:[email protected]:8080/dir/../api?q=1#frag") | ||
#' ada_has_credentials(url) | ||
#' ada_has_empty_hostname(url) | ||
#' ada_has_hostname(url) | ||
#' ada_has_non_empty_username(url) | ||
#' ada_has_non_empty_password(url) | ||
#' ada_has_port(url) | ||
#' ada_has_hash(url) | ||
#' ada_has_search(url) | ||
#' ## these functions are vectorized | ||
#' urls <- c("http://www.google.com", "http://www.google.com:80", "noturl") | ||
#' ada_has_port(urls) | ||
#' @export | ||
ada_has_credentials <- function(url) { | ||
Rcpp_ada_has_credentials(url) | ||
.has(url, Rcpp_ada_has_credentials) | ||
} | ||
|
||
#' Check if URL has an empty hostname | ||
#' @inheritParams ada_url_parse | ||
#' @return logical | ||
#' @examples | ||
#' ada_has_empty_hostname("https://user_1:[email protected]:8080/dir/../api?q=1#frag") | ||
#' @rdname ada_has_credentials | ||
#' @export | ||
ada_has_empty_hostname <- function(url) { | ||
Rcpp_ada_has_empty_hostname(url) | ||
.has(url, Rcpp_ada_has_empty_hostname) | ||
} | ||
|
||
#' Check if URL has a hostname | ||
#' @inheritParams ada_url_parse | ||
#' @return logical | ||
#' @examples | ||
#' ada_has_hostname("https://user_1:[email protected]:8080/dir/../api?q=1#frag") | ||
#' @rdname ada_has_credentials | ||
#' @export | ||
ada_has_hostname <- function(url) { | ||
Rcpp_ada_has_hostname(url) | ||
.has(url, Rcpp_ada_has_hostname) | ||
} | ||
|
||
#' Check if URL has a non empty username | ||
#' @inheritParams ada_url_parse | ||
#' @return logical | ||
#' @examples | ||
#' ada_has_non_empty_username("https://user_1:[email protected]:8080/dir/../api?q=1#frag") | ||
#' @rdname ada_has_credentials | ||
#' @export | ||
ada_has_non_empty_username <- function(url) { | ||
Rcpp_ada_has_non_empty_username(url) | ||
.has(url, Rcpp_ada_has_non_empty_username) | ||
} | ||
|
||
#' Check if URL has a non empty password | ||
#' @inheritParams ada_url_parse | ||
#' @return logical | ||
#' @examples | ||
#' ada_has_non_empty_password("https://user_1:[email protected]:8080/dir/../api?q=1#frag") | ||
#' @rdname ada_has_credentials | ||
#' @export | ||
ada_has_non_empty_password <- function(url) { | ||
Rcpp_ada_has_non_empty_password(url) | ||
.has(url, Rcpp_ada_has_non_empty_password) | ||
} | ||
|
||
#' Check if URL has a port | ||
#' @inheritParams ada_url_parse | ||
#' @return logical | ||
#' @examples | ||
#' ada_has_port("https://user_1:[email protected]:8080/dir/../api?q=1#frag") | ||
#' @rdname ada_has_credentials | ||
#' @export | ||
ada_has_port <- function(url) { | ||
Rcpp_ada_has_port(url) | ||
.has(url, Rcpp_ada_has_port) | ||
} | ||
|
||
#' Check if URL has a hash | ||
#' @inheritParams ada_url_parse | ||
#' @return logical | ||
#' @examples | ||
#' ada_has_hash("https://user_1:[email protected]:8080/dir/../api?q=1#frag") | ||
#' @rdname ada_has_credentials | ||
#' @export | ||
ada_has_hash <- function(url) { | ||
Rcpp_ada_has_hash(url) | ||
.has(url, Rcpp_ada_has_hash) | ||
} | ||
|
||
#' Check if URL has a search | ||
#' @inheritParams ada_url_parse | ||
#' @return logical | ||
#' @examples | ||
#' ada_has_search("https://user_1:[email protected]:8080/dir/../api?q=1#frag") | ||
#' @rdname ada_has_credentials | ||
#' @export | ||
ada_has_search <- function(url) { | ||
Rcpp_ada_has_search(url) | ||
.has(url, Rcpp_ada_has_search) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,32 @@ test_that("all has functions work", { | |
url <- "https://user_1:[email protected]:8080/dir/../api?q=1#frag" | ||
expect_true(ada_has_credentials(url)) | ||
expect_false(ada_has_empty_hostname(url)) | ||
expect_true(ada_has_hash(url)) | ||
expect_true(ada_has_hostname(url)) | ||
expect_true(ada_has_non_empty_password(url)) | ||
expect_true(ada_has_non_empty_username(url)) | ||
expect_true(ada_has_port(url)) | ||
expect_true(ada_has_hash(url)) | ||
expect_true(ada_has_search(url)) | ||
}) | ||
|
||
has_functions <- c(ada_has_credentials, ada_has_empty_hostname, ada_has_hostname, ada_has_non_empty_username, ada_has_non_empty_password, ada_has_port, ada_has_hash, ada_has_search) | ||
|
||
test_that("invalid urls should return NA, #26", { | ||
url <- "thisisnoturl" | ||
for (func in has_functions) { | ||
expect_error(func(url), NA) | ||
} | ||
}) | ||
|
||
test_that("corners #31", { | ||
for (func in has_functions) { | ||
expect_error(func(c(NA, NA_character_, "")), NA) | ||
} | ||
for (func in has_functions) { | ||
expect_error(func(NULL), NA) | ||
} | ||
}) | ||
|
||
test_that("ada_has_credentials is vectorized ref #3", { | ||
expect_error(res <- ada_has_credentials(c("https://admin:[email protected]/basic_auth", "https://www.google.com")), NA) | ||
expect_error(res <- ada_has_credentials(c("https://admin:[email protected]/basic_auth", "https://www.google.com")), NA) | ||
}) |