mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-15 19:56:59 +08:00
parser: fix tests
This commit is contained in:
parent
a9a0c415e7
commit
1e5a43d5f3
@ -319,15 +319,39 @@ describe Homebrew::CLI::Parser do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "usage banner generation" do
|
describe "usage banner generation" do
|
||||||
it "includes `[options]` if options are available" do
|
it "includes `[options]` if more than two non-global options are available" do
|
||||||
parser = described_class.new do
|
parser = described_class.new do
|
||||||
switch "--foo"
|
switch "--foo"
|
||||||
|
switch "--baz"
|
||||||
|
switch "--bar"
|
||||||
end
|
end
|
||||||
expect(parser.generate_help_text).to match(/\[options\]/)
|
expect(parser.generate_help_text).to match(/\[options\]/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't include `[options]` if options are available" do
|
it "includes individual options if less than two non-global options are available" do
|
||||||
allow(described_class).to receive(:global_options).and_return([])
|
parser = described_class.new do
|
||||||
|
switch "--foo"
|
||||||
|
switch "--bar"
|
||||||
|
end
|
||||||
|
expect(parser.generate_help_text).to match(/\[--foo\] \[--bar\]/)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "formats flags correctly when less than two non-global options are available" do
|
||||||
|
parser = described_class.new do
|
||||||
|
flag "--foo"
|
||||||
|
flag "--bar="
|
||||||
|
end
|
||||||
|
expect(parser.generate_help_text).to match(/\[--foo\] \[--bar=\]/)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "formats comma arrays correctly when less than two non-global options are available" do
|
||||||
|
parser = described_class.new do
|
||||||
|
comma_array "--foo"
|
||||||
|
end
|
||||||
|
expect(parser.generate_help_text).to match(/\[--foo=\]/)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't include `[options]` if non non-global options are available" do
|
||||||
parser = described_class.new
|
parser = described_class.new
|
||||||
expect(parser.generate_help_text).not_to match(/\[options\]/)
|
expect(parser.generate_help_text).not_to match(/\[options\]/)
|
||||||
end
|
end
|
||||||
@ -363,42 +387,42 @@ describe Homebrew::CLI::Parser do
|
|||||||
parser = described_class.new do
|
parser = described_class.new do
|
||||||
named_args :none
|
named_args :none
|
||||||
end
|
end
|
||||||
expect(parser.generate_help_text).to match(/\[options\]\n/)
|
expect(parser.generate_help_text).to match(/^Usage: [^\[]+$/s)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "shows the correct usage for a single typed argument" do
|
it "shows the correct usage for a single typed argument" do
|
||||||
parser = described_class.new do
|
parser = described_class.new do
|
||||||
named_args :formula, number: 1
|
named_args :formula, number: 1
|
||||||
end
|
end
|
||||||
expect(parser.generate_help_text).to match(/\[options\] formula\n/)
|
expect(parser.generate_help_text).to match(/^Usage: .* formula$/s)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "shows the correct usage for a subcommand argument with a maximum" do
|
it "shows the correct usage for a subcommand argument with a maximum" do
|
||||||
parser = described_class.new do
|
parser = described_class.new do
|
||||||
named_args %w[off on], max: 1
|
named_args %w[off on], max: 1
|
||||||
end
|
end
|
||||||
expect(parser.generate_help_text).to match(/\[options\] \[subcommand\]\n/)
|
expect(parser.generate_help_text).to match(/^Usage: .* \[subcommand\]$/s)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "shows the correct usage for multiple typed argument with no maximum or minimum" do
|
it "shows the correct usage for multiple typed argument with no maximum or minimum" do
|
||||||
parser = described_class.new do
|
parser = described_class.new do
|
||||||
named_args [:tap, :command]
|
named_args [:tap, :command]
|
||||||
end
|
end
|
||||||
expect(parser.generate_help_text).to match(/\[options\] \[tap|command ...\]\n/)
|
expect(parser.generate_help_text).to match(/^Usage: .* \[tap|command ...\]$/s)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "shows the correct usage for a subcommand argument with a minimum of 1" do
|
it "shows the correct usage for a subcommand argument with a minimum of 1" do
|
||||||
parser = described_class.new do
|
parser = described_class.new do
|
||||||
named_args :installed_formula, min: 1
|
named_args :installed_formula, min: 1
|
||||||
end
|
end
|
||||||
expect(parser.generate_help_text).to match(/\[options\] installed_formula \[...\]\n/)
|
expect(parser.generate_help_text).to match(/^Usage: .* installed_formula \[...\]$/s)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "shows the correct usage for a subcommand argument with a minimum greater than 1" do
|
it "shows the correct usage for a subcommand argument with a minimum greater than 1" do
|
||||||
parser = described_class.new do
|
parser = described_class.new do
|
||||||
named_args :installed_formula, min: 2
|
named_args :installed_formula, min: 2
|
||||||
end
|
end
|
||||||
expect(parser.generate_help_text).to match(/\[options\] installed_formula ...\n/)
|
expect(parser.generate_help_text).to match(/^Usage: .* installed_formula ...$/s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user