Skip to content

Commit

Permalink
added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
schochastics committed Oct 16, 2023
1 parent 80cdfc9 commit 9e2423c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/testthat/test-set.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,25 @@ test_that("all set functions work", {
expect_equal(ada_get_hash(ada_set_hash(url, "section1")), "#section1")
expect_equal(ada_get_protocol(ada_set_protocol(url, "ws:")), "ws:")
})

set_functions <- c(
ada_set_href, ada_set_username, ada_set_password, ada_set_host, ada_set_hostname, ada_set_port, ada_set_pathname,
ada_set_search, ada_set_hash, ada_set_protocol
)

test_that("invalid urls should return NA", {
url <- "thisisnoturl"
for (func in set_functions) {
expect_equal(func(url, "invalid"), NA_character_)
}
})

test_that("invalid component handling", {
url <- "https://user_1:[email protected]:8080/dir/../api?q=1#frag"
# expect_equal(ada_get_username(ada_set_username(url, "user_2")), "user_2")
# expect_equal(ada_get_password(ada_set_password(url, "hunter2")), "hunter2")
expect_equal(ada_get_host(ada_set_host(url, "example.de1234")), "example.org:8080")
expect_equal(ada_get_hostname(ada_set_hostname(url, "example.net")), "example.org")
expect_equal(ada_get_port(ada_set_port(url, "blabla")), "")
expect_equal(ada_get_protocol(ada_set_protocol(url, "abc:")), "https:")
})

0 comments on commit 9e2423c

Please sign in to comment.