Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chainsawriot committed Sep 25, 2023
1 parent 4c310cc commit 6891377
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions tests/testthat/test-get.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
test_that("all get functions work", {
url <- "https://user_1:[email protected]:8080/dir/../api?q=1#frag"
expect_equal(ada_get_username(url), "user_1")
expect_equal(ada_get_password(url), "password_1")
expect_equal(ada_get_host(url), "example.org:8080")
expect_equal(ada_get_hostname(url), "example.org")
expect_equal(ada_get_port(url), "8080")
expect_equal(ada_get_pathname(url), "/api")
expect_equal(ada_get_search(url), "?q=1")
expect_equal(ada_get_hash(url), "#frag")
url <- "https://user_1:[email protected]:8080/dir/../api?q=1#frag"
expect_equal(ada_get_username(url), "user_1")
expect_equal(ada_get_password(url), "password_1")
expect_equal(ada_get_host(url), "example.org:8080")
expect_equal(ada_get_hostname(url), "example.org")
expect_equal(ada_get_port(url), "8080")
expect_equal(ada_get_pathname(url), "/api")
expect_equal(ada_get_search(url), "?q=1")
expect_equal(ada_get_hash(url), "#frag")
})

get_functions <- c(ada_get_username, ada_get_password, ada_get_host, ada_get_hostname, ada_get_port, ada_get_pathname,
ada_get_search, ada_get_hash)

test_that("invalid urls should return NA, #26", {
url <- "thisisnoturl"
for (func in get_functions) {
expect_error(func(url), NA)
}
})

test_that("corners #31", {
for (func in get_functions) {
expect_error(func(c(NA, NA_character_, "")), NA)
}
for (func in get_functions) {
expect_error(func(NULL), NA)
}
})

test_that("decode can pass", {
expect_equal(ada_get_search("https://www.google.co.jp/search?q=\u30c9\u30a4\u30c4"), "?q=\u30c9\u30a4\u30c4")
expect_equal(ada_get_search("https://www.google.co.jp/search?q=\u30c9\u30a4\u30c4", decode = FALSE), "?q=%E3%83%89%E3%82%A4%E3%83%84")
})

0 comments on commit 6891377

Please sign in to comment.