Skip to content

Commit d02a0ab

Browse files
committed
Add tests for opt choices and update completions
1 parent 486233b commit d02a0ab

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

completions/_tldr

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ _tldr() {
2929
--config-path"[Print the default config path and create the config directory]" \
3030
{-p,--platform}"[Specify the platform to use (linux, osx, windows, etc.)]:PLATFORM:_platforms" \
3131
{-L,--language}"[Specify the languages to use]:LANGUAGE_CODE:_languages" \
32+
--short-options"[Display short options wherever possible (e.g '-s')]" \
33+
--long-options"[Display long options wherever possible (e.g '--long')]" \
3234
{-o,--offline}"[Do not update the cache, even if it is stale]" \
3335
{-c,--compact}"[Strip empty lines from output]" \
3436
--no-compact"[Do not strip empty lines from output (overrides --compact)]" \

completions/tldr.bash

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ _tldr() {
77
local opts="-u -l -a -i -r -p -L -o -c -R -q -v -h \
88
--update --list --list-all --list-platforms --list-languages \
99
--info --render --clean-cache --gen-config --config-path --platform \
10-
--language --offline --compact --no-compact --raw --no-raw --quiet \
11-
--color --config --version --help"
10+
--language --short-options --long-options --offline --compact \
11+
--no-compact --raw --no-raw --quiet --color --config --version --help"
1212

1313
if [[ $cur == -* ]]; then
1414
mapfile -t COMPREPLY < <(compgen -W "$opts" -- "$cur")

completions/tldr.fish

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ complete -c tldr -s p -l platform -d "Specify the platform to use (linux, osx, w
33
"(tldr --offline --list-platforms 2> /dev/null)"
44
complete -c tldr -s L -l language -d "Specify the languages to use" -x -a \
55
"(tldr --offline --list-languages 2> /dev/null)"
6+
complete -c tldr -l short-options -d "Display short options wherever possible (e.g '-s')"
7+
complete -c tldr -l long-options -d "Display long options wherever possible (e.g '--long')"
68
complete -c tldr -l color -d "Specify when to enable color" -x -a "
79
auto\t'Display color if standard output is a terminal and NO_COLOR is not set'
810
always\t'Always display color'

tests/data/option-placeholder.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`foo {{[-s|--long]}}`

tests/tests.rs

+30
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::process::Command;
44
use assert_cmd::prelude::*;
55

66
const TEST_PAGE: &str = "tests/data/page.md";
7+
const TEST_PAGE_OPTION_PLACEHOLDERS: &str = "tests/data/option-placeholder.md";
78
const TEST_PAGE_RENDER: &str = "tests/data/page-render";
89
const TEST_PAGE_COMPACT_RENDER: &str = "tests/data/page-compact-render";
910

@@ -47,3 +48,32 @@ fn does_not_exist() {
4748
.assert()
4849
.failure();
4950
}
51+
52+
#[test]
53+
fn short_opts() {
54+
tlrc()
55+
.args(["--short-options", "--render", TEST_PAGE_OPTION_PLACEHOLDERS])
56+
.assert()
57+
.stdout(" foo -s\n\n");
58+
}
59+
60+
#[test]
61+
fn long_opts() {
62+
tlrc()
63+
.args(["--long-options", "--render", TEST_PAGE_OPTION_PLACEHOLDERS])
64+
.assert()
65+
.stdout(" foo --long\n\n");
66+
}
67+
68+
#[test]
69+
fn both_opts() {
70+
tlrc()
71+
.args([
72+
"--short-options",
73+
"--long-options",
74+
"--render",
75+
TEST_PAGE_OPTION_PLACEHOLDERS,
76+
])
77+
.assert()
78+
.stdout(" foo [-s|--long]\n\n");
79+
}

0 commit comments

Comments
 (0)