Skip to content

Commit c3a67b0

Browse files
committed
improve CompletionBuilder spec
1 parent a9ed8af commit c3a67b0

8 files changed

Lines changed: 166 additions & 2 deletions

File tree

lib/bashly.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ module Bashly
66
autoloads 'bashly/refinements', %i[ComposeRefinements]
77

88
autoloads 'bashly', %i[
9-
CLI Config ConfigValidator Library LibrarySource LibrarySourceConfig
10-
MessageStrings RenderContext RenderSource Settings VERSION Watch
9+
CLI CompletionBuilder Config ConfigValidator Library LibrarySource
10+
LibrarySourceConfig MessageStrings RenderContext RenderSource Settings
11+
VERSION Watch
1112
]
1213

1314
autoloads 'bashly/concerns', %i[
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
patterns:
3+
- cli [root options]
4+
- cli images|img [root_global options] [images options]
5+
- cli images|img list|ls [root_global options] [images_global options] [images_list
6+
options]
7+
options:
8+
root:
9+
- "--help|-h"
10+
- "--version|-v"
11+
- "--debug"
12+
root_global:
13+
- "--debug"
14+
images:
15+
- "--help|-h"
16+
- "--verbose"
17+
images_global:
18+
- "--verbose"
19+
images_list:
20+
- "--help|-h"
21+
- "--env <env>"
22+
tokens:
23+
env:
24+
- prod
25+
- dev
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
patterns:
3+
- cli [root options]
4+
options:
5+
root:
6+
- "--help|-h"
7+
- "--force|-f"
8+
- "--verbose"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
patterns:
3+
- cli [root options]
4+
- cli upload [upload options] <source> <target> <extra>
5+
options:
6+
root:
7+
- "--help|-h"
8+
- "--version|-v"
9+
upload:
10+
- "--help|-h"
11+
- "--user|-u <user>"
12+
- "--tag <tag>"
13+
tokens:
14+
user:
15+
- "+user"
16+
tag:
17+
source:
18+
- "+directory"
19+
- README.md
20+
- "$(git branch)"
21+
- "++literal"
22+
target:
23+
- "+file"
24+
- README.md
25+
extra:
26+
- "+file"
27+
- README.md
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
patterns:
3+
- cli [root options] <root_file_3>
4+
options:
5+
root:
6+
- "--help|-h"
7+
- "--version|-v"
8+
- "--file <file>"
9+
- "--root-file <root_file>"
10+
- "--root-file-2 <root_file_2>"
11+
tokens:
12+
file:
13+
- one
14+
root_file:
15+
- two
16+
root_file_2:
17+
- three
18+
root_file_3:
19+
- four
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
describe CompletionBuilder do
2+
fixtures = load_fixture('completion_builder')
3+
4+
describe '#call' do
5+
fixtures.each do |fixture, options|
6+
context "with :#{fixture}" do
7+
let(:command) { Script::Command.new options['command'] }
8+
let(:builder) do
9+
described_class.new command, with_version: options.fetch('with_version', true)
10+
end
11+
12+
it 'returns pattern config data' do
13+
expect(builder.call.to_yaml)
14+
.to match_approval("completion_builder/#{fixture}")
15+
end
16+
end
17+
end
18+
end
19+
end

spec/bashly/settings_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@
103103
end
104104
end
105105

106+
describe '::argfile_var' do
107+
it 'returns its default value' do
108+
expect(subject.argfile_var).to eq 'ARGFILE'
109+
end
110+
end
111+
106112
describe '::extra_lib_dirs' do
107113
context 'when set using env var as a comma delimited string' do
108114
before { ENV['BASHLY_EXTRA_LIB_DIRS'] = 'one,two' }
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
:root_options:
2+
with_version: false
3+
command:
4+
name: cli
5+
flags:
6+
- long: --force
7+
short: -f
8+
- long: --verbose
9+
10+
:source_resolution:
11+
command:
12+
name: cli
13+
commands:
14+
- name: upload
15+
completions: [<file>, README.md]
16+
args:
17+
- name: source
18+
completions: [<directory>, README.md, $(git branch), +literal]
19+
- name: target
20+
- name: extra
21+
flags:
22+
- long: --user
23+
short: -u
24+
arg: user
25+
completions: [<user>]
26+
- long: --tag
27+
arg: tag
28+
29+
:aliases_and_global_flags:
30+
command:
31+
name: cli
32+
flags:
33+
- long: --debug
34+
commands:
35+
- name: images
36+
alias: img
37+
flags:
38+
- long: --verbose
39+
commands:
40+
- name: list
41+
alias: ls
42+
flags:
43+
- long: --env
44+
arg: env
45+
allowed: [prod, dev]
46+
47+
:token_collisions:
48+
command:
49+
name: cli
50+
flags:
51+
- long: --file
52+
allowed: [one]
53+
- long: --root-file
54+
allowed: [two]
55+
- long: --root-file-2
56+
allowed: [three]
57+
args:
58+
- name: file
59+
allowed: [four]

0 commit comments

Comments
 (0)