From 2848b6ffe23a20067fd09fc394e2420a68d72813 Mon Sep 17 00:00:00 2001 From: William Melody Date: Mon, 7 Feb 2022 13:54:54 -0800 Subject: [PATCH] Add `helpers-string-is-url.bats`. --- test/helpers-string-is-url.bats | 95 +++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 test/helpers-string-is-url.bats diff --git a/test/helpers-string-is-url.bats b/test/helpers-string-is-url.bats new file mode 100644 index 000000000..eb3f67426 --- /dev/null +++ b/test/helpers-string-is-url.bats @@ -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}" ]] +}