2020-04-06 22:01:39 +02:00
|
|
|
setup() {
|
|
|
|
source "${LIB}/pager.sh"
|
|
|
|
}
|
|
|
|
|
|
|
|
use_pager() {
|
|
|
|
unset BAT_PAGER
|
|
|
|
export PAGER="$1"
|
|
|
|
|
|
|
|
_configure_pager
|
2020-05-01 05:13:03 +02:00
|
|
|
_detect_pager
|
2020-04-06 22:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
use_bat_pager() {
|
|
|
|
unset PAGER
|
|
|
|
export BAT_PAGER="$1"
|
|
|
|
|
|
|
|
_configure_pager
|
2020-05-01 05:13:03 +02:00
|
|
|
_detect_pager
|
2020-04-06 22:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
test:less_detection() {
|
|
|
|
description "Identify less"
|
|
|
|
|
2020-05-01 05:13:03 +02:00
|
|
|
(use_pager "less" && expect_equal "$(pager_name)" "less")
|
|
|
|
(use_pager "less_but_renamed" && expect_equal "$(pager_name)" "less")
|
2020-05-01 06:47:59 +02:00
|
|
|
(use_pager "stty" && expect_equal "$(pager_name)" "stty")
|
2020-04-06 22:01:39 +02:00
|
|
|
}
|
|
|
|
|
2021-04-10 21:26:54 +02:00
|
|
|
test:bat_detection() {
|
|
|
|
description "Ensure bat is replaced with less as pager"
|
|
|
|
|
|
|
|
(use_pager "bat" && expect_equal "$(pager_name)" "less")
|
|
|
|
}
|
|
|
|
|
2020-04-06 22:01:39 +02:00
|
|
|
test:less_version() {
|
|
|
|
description "Identify less version"
|
|
|
|
|
2020-05-01 05:13:03 +02:00
|
|
|
(
|
|
|
|
export MOCK_LESS_VERSION=473
|
|
|
|
use_pager "less" && expect_equal "$(pager_version)" "473"
|
|
|
|
)
|
2020-04-06 22:01:39 +02:00
|
|
|
|
2020-05-01 05:13:03 +02:00
|
|
|
(
|
|
|
|
export MOCK_LESS_VERSION=551
|
|
|
|
use_pager "less" && expect_equal "$(pager_version)" "551"
|
|
|
|
)
|
2020-04-06 22:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
test:less_args() {
|
|
|
|
description "Automatically select appropriate less args"
|
|
|
|
|
2020-05-01 05:13:03 +02:00
|
|
|
# When pager is "less".
|
|
|
|
(
|
|
|
|
export MOCK_LESS_VERSION=473
|
|
|
|
use_pager "less"
|
|
|
|
expect array_contains "-R" in "${SCRIPT_PAGER_CMD[@]}"
|
|
|
|
expect array_contains "--quit-if-one-screen" in "${SCRIPT_PAGER_CMD[@]}"
|
|
|
|
expect array_contains "--no-init" in "${SCRIPT_PAGER_CMD[@]}"
|
|
|
|
)
|
|
|
|
|
|
|
|
# When pager is equivalent of "less".
|
|
|
|
(
|
|
|
|
export MOCK_LESS_VERSION=551
|
|
|
|
use_pager "less"
|
|
|
|
expect array_contains "-R" in "${SCRIPT_PAGER_CMD[@]}"
|
|
|
|
expect array_contains "--quit-if-one-screen" in "${SCRIPT_PAGER_CMD[@]}"
|
|
|
|
expect ! array_contains "--no-init" in "${SCRIPT_PAGER_CMD[@]}"
|
|
|
|
)
|
|
|
|
}
|
2020-04-06 22:01:39 +02:00
|
|
|
|
2020-05-01 05:13:03 +02:00
|
|
|
test:less_args_not_less() {
|
|
|
|
description "Don't give non-less pagers the less args"
|
2020-04-06 22:01:39 +02:00
|
|
|
|
|
|
|
use_pager "not_less"
|
2020-05-01 05:13:03 +02:00
|
|
|
echo "${SCRIPT_PAGER_CMD[@]}"
|
|
|
|
expect_equal "${#SCRIPT_PAGER_CMD[@]}" 1
|
2020-04-06 22:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
test:env_bat_pager() {
|
|
|
|
description "Check that BAT_PAGER is being used"
|
|
|
|
|
|
|
|
use_bat_pager "not_less"
|
2020-05-01 05:13:03 +02:00
|
|
|
expect_equal "${SCRIPT_PAGER_CMD[0]}" "not_less"
|
2020-04-06 22:01:39 +02:00
|
|
|
|
|
|
|
use_bat_pager "not_less but not_more"
|
2020-05-01 05:13:03 +02:00
|
|
|
expect_equal "${SCRIPT_PAGER_CMD[0]}" "not_less"
|
2020-04-06 22:01:39 +02:00
|
|
|
expect_equal "${SCRIPT_PAGER_CMD[1]}" "but"
|
|
|
|
expect_equal "${SCRIPT_PAGER_CMD[2]}" "not_more"
|
|
|
|
}
|
2020-05-01 05:13:03 +02:00
|
|
|
|
|
|
|
test:args_copied_from_pager() {
|
|
|
|
description "Check that the pager args are correct with PAGER."
|
|
|
|
|
|
|
|
use_pager "less --some-argument"
|
|
|
|
expect_equal "${SCRIPT_PAGER_CMD[0]}" "less"
|
|
|
|
expect_not_equal "${SCRIPT_PAGER_CMD[1]}" "--some-argument"
|
|
|
|
}
|
|
|
|
|
|
|
|
test:args_copied_from_bat_pager() {
|
|
|
|
description "Check that the pager args are correct with PAGER."
|
|
|
|
|
|
|
|
use_bat_pager "less --some-argument"
|
|
|
|
assert_equal "${#SCRIPT_PAGER_CMD[@]}" 2
|
|
|
|
expect_equal "${SCRIPT_PAGER_CMD[0]}" "less"
|
|
|
|
expect_equal "${SCRIPT_PAGER_CMD[1]}" "--some-argument"
|
|
|
|
}
|