Skip to content

Commit

Permalink
Add helpers-string-is-url.bats.
Browse files Browse the repository at this point in the history
  • Loading branch information
xwmx committed Feb 7, 2022
1 parent 8ab7105 commit 2848b6f
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions test/helpers-string-is-url.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env bats

load test_helper

@test "'_string_is_url()' matches URLs." {
run "${_NB}" helpers string_is_url "file:///home/example"

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ "${status}" -eq 0 ]]
[[ -z "${output}" ]]

run "${_NB}" helpers string_is_url "ftp://example.com"

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ "${status}" -eq 0 ]]
[[ -z "${output}" ]]

run "${_NB}" helpers string_is_url "http://example.com"

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ "${status}" -eq 0 ]]
[[ -z "${output}" ]]

run "${_NB}" helpers string_is_url "https://example.com"

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ "${status}" -eq 0 ]]
[[ -z "${output}" ]]

run "${_NB}" helpers string_is_url "sftp://example.com"

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ "${status}" -eq 0 ]]
[[ -z "${output}" ]]
}

@test "'_string_is_url()' doesn't match non-URLs." {
run "${_NB}" helpers string_is_url "Not a URL."

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ "${status}" -eq 1 ]]
[[ -z "${output}" ]]

run "${_NB}" helpers string_is_url "not-a-url"

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ "${status}" -eq 1 ]]
[[ -z "${output}" ]]

run "${_NB}" helpers string_is_url "notaurl:"

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ "${status}" -eq 1 ]]
[[ -z "${output}" ]]

run "${_NB}" helpers string_is_url "notebook:example"

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ "${status}" -eq 1 ]]
[[ -z "${output}" ]]

run "${_NB}" helpers string_is_url "notebook:123"

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ "${status}" -eq 1 ]]
[[ -z "${output}" ]]

run "${_NB}" helpers string_is_url "notebook:example/123"

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ "${status}" -eq 1 ]]
[[ -z "${output}" ]]
}

0 comments on commit 2848b6f

Please sign in to comment.