Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
brew
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
brew
Commits
37f7e84e
Commit
37f7e84e
authored
8 years ago
by
Markus Reiter
Browse files
Options
Downloads
Patches
Plain Diff
Convert Options test to spec.
parent
2401de49
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Library/Homebrew/test/options_spec.rb
+148
-0
148 additions, 0 deletions
Library/Homebrew/test/options_spec.rb
Library/Homebrew/test/options_test.rb
+0
-148
0 additions, 148 deletions
Library/Homebrew/test/options_test.rb
with
148 additions
and
148 deletions
Library/Homebrew/test/options_spec.rb
0 → 100644
+
148
−
0
View file @
37f7e84e
require
"options"
describe
Option
do
subject
{
described_class
.
new
(
"foo"
)
}
specify
"#to_s"
do
expect
(
subject
.
to_s
).
to
eq
(
"--foo"
)
end
specify
"equality"
do
foo
=
Option
.
new
(
"foo"
)
bar
=
Option
.
new
(
"bar"
)
expect
(
subject
).
to
eq
(
foo
)
expect
(
subject
).
not_to
eq
(
bar
)
expect
(
subject
).
to
eql
(
foo
)
expect
(
subject
).
not_to
eql
(
bar
)
end
specify
"#description"
do
expect
(
subject
.
description
).
to
be_empty
expect
(
Option
.
new
(
"foo"
,
"foo"
).
description
).
to
eq
(
"foo"
)
end
specify
"#inspect"
do
expect
(
subject
.
inspect
).
to
eq
(
"#<Option:
\"
--foo
\"
>"
)
end
end
describe
DeprecatedOption
do
subject
{
described_class
.
new
(
"foo"
,
"bar"
)
}
specify
"#old"
do
expect
(
subject
.
old
).
to
eq
(
"foo"
)
end
specify
"#old_flag"
do
expect
(
subject
.
old_flag
).
to
eq
(
"--foo"
)
end
specify
"#current"
do
expect
(
subject
.
current
).
to
eq
(
"bar"
)
end
specify
"#current_flag"
do
expect
(
subject
.
current_flag
).
to
eq
(
"--bar"
)
end
specify
"equality"
do
foobar
=
DeprecatedOption
.
new
(
"foo"
,
"bar"
)
boofar
=
DeprecatedOption
.
new
(
"boo"
,
"far"
)
expect
(
foobar
).
to
eq
(
subject
)
expect
(
subject
).
to
eq
(
foobar
)
expect
(
boofar
).
not_to
eq
(
subject
)
expect
(
subject
).
not_to
eq
(
boofar
)
end
end
describe
Options
do
it
"removes duplicate options"
do
subject
<<
Option
.
new
(
"foo"
)
subject
<<
Option
.
new
(
"foo"
)
expect
(
subject
).
to
include
(
"--foo"
)
expect
(
subject
.
count
).
to
eq
(
1
)
end
it
"preserves existing member when adding a duplicate"
do
a
=
Option
.
new
(
"foo"
,
"bar"
)
b
=
Option
.
new
(
"foo"
,
"qux"
)
subject
<<
a
<<
b
expect
(
subject
.
count
).
to
eq
(
1
)
expect
(
subject
.
first
).
to
be
(
a
)
expect
(
subject
.
first
.
description
).
to
eq
(
a
.
description
)
end
specify
"#include?"
do
subject
<<
Option
.
new
(
"foo"
)
expect
(
subject
).
to
include
(
"--foo"
)
expect
(
subject
).
to
include
(
"foo"
)
expect
(
subject
).
to
include
(
Option
.
new
(
"foo"
))
end
describe
"#+"
do
it
"returns options"
do
expect
(
subject
+
Options
.
new
).
to
be_an_instance_of
(
Options
)
end
end
describe
"#-"
do
it
"returns options"
do
expect
(
subject
-
Options
.
new
).
to
be_an_instance_of
(
Options
)
end
end
specify
"#&"
do
foo
,
bar
,
baz
=
%w[foo bar baz]
.
map
{
|
o
|
Option
.
new
(
o
)
}
options
=
Options
.
new
<<
foo
<<
bar
subject
<<
foo
<<
baz
expect
((
subject
&
options
).
to_a
).
to
eq
([
foo
])
end
specify
"#|"
do
foo
,
bar
,
baz
=
%w[foo bar baz]
.
map
{
|
o
|
Option
.
new
(
o
)
}
options
=
Options
.
new
<<
foo
<<
bar
subject
<<
foo
<<
baz
expect
((
subject
|
options
).
sort
).
to
eq
([
foo
,
bar
,
baz
].
sort
)
end
specify
"#*"
do
subject
<<
Option
.
new
(
"aa"
)
<<
Option
.
new
(
"bb"
)
<<
Option
.
new
(
"cc"
)
expect
((
subject
*
"XX"
).
split
(
"XX"
).
sort
).
to
eq
(
%w[--aa --bb --cc]
)
end
describe
"<<"
do
it
"returns itself"
do
expect
(
subject
<<
Option
.
new
(
"foo"
)).
to
be
subject
end
end
specify
"#as_flags"
do
subject
<<
Option
.
new
(
"foo"
)
expect
(
subject
.
as_flags
).
to
eq
(
%w[--foo]
)
end
specify
"#to_a"
do
option
=
Option
.
new
(
"foo"
)
subject
<<
option
expect
(
subject
.
to_a
).
to
eq
([
option
])
end
specify
"#to_ary"
do
option
=
Option
.
new
(
"foo"
)
subject
<<
option
expect
(
subject
.
to_ary
).
to
eq
([
option
])
end
specify
"::create_with_array"
do
array
=
%w[--foo --bar]
option1
=
Option
.
new
(
"foo"
)
option2
=
Option
.
new
(
"bar"
)
expect
(
Options
.
create
(
array
).
sort
).
to
eq
([
option1
,
option2
].
sort
)
end
specify
"#inspect"
do
expect
(
subject
.
inspect
).
to
eq
(
"#<Options: []>"
)
subject
<<
Option
.
new
(
"foo"
)
expect
(
subject
.
inspect
).
to
eq
(
"#<Options: [#<Option:
\"
--foo
\"
>]>"
)
end
end
This diff is collapsed.
Click to expand it.
Library/Homebrew/test/options_test.rb
deleted
100644 → 0
+
0
−
148
View file @
2401de49
require
"testing_env"
require
"options"
class
OptionTests
<
Homebrew
::
TestCase
def
setup
super
@option
=
Option
.
new
(
"foo"
)
end
def
test_to_s
assert_equal
"--foo"
,
@option
.
to_s
end
def
test_equality
foo
=
Option
.
new
(
"foo"
)
bar
=
Option
.
new
(
"bar"
)
assert_equal
foo
,
@option
refute_equal
bar
,
@option
assert_eql
@option
,
foo
refute_eql
@option
,
bar
end
def
test_description
assert_empty
@option
.
description
assert_equal
"foo"
,
Option
.
new
(
"foo"
,
"foo"
).
description
end
def
test_inspect
assert_equal
"#<Option:
\"
--foo
\"
>"
,
@option
.
inspect
end
end
class
DeprecatedOptionTests
<
Homebrew
::
TestCase
def
setup
super
@deprecated_option
=
DeprecatedOption
.
new
(
"foo"
,
"bar"
)
end
def
test_old
assert_equal
"foo"
,
@deprecated_option
.
old
assert_equal
"--foo"
,
@deprecated_option
.
old_flag
end
def
test_current
assert_equal
"bar"
,
@deprecated_option
.
current
assert_equal
"--bar"
,
@deprecated_option
.
current_flag
end
def
test_equality
foobar
=
DeprecatedOption
.
new
(
"foo"
,
"bar"
)
boofar
=
DeprecatedOption
.
new
(
"boo"
,
"far"
)
assert_equal
foobar
,
@deprecated_option
refute_equal
boofar
,
@deprecated_option
assert_eql
@deprecated_option
,
foobar
refute_eql
@deprecated_option
,
boofar
end
end
class
OptionsTests
<
Homebrew
::
TestCase
def
setup
super
@options
=
Options
.
new
end
def
test_no_duplicate_options
@options
<<
Option
.
new
(
"foo"
)
@options
<<
Option
.
new
(
"foo"
)
assert_includes
@options
,
"--foo"
assert_equal
1
,
@options
.
count
end
def
test_preserves_existing_member_when_pushing_duplicate
a
=
Option
.
new
(
"foo"
,
"bar"
)
b
=
Option
.
new
(
"foo"
,
"qux"
)
@options
<<
a
<<
b
assert_equal
1
,
@options
.
count
assert_same
a
,
@options
.
first
assert_equal
a
.
description
,
@options
.
first
.
description
end
def
test_include
@options
<<
Option
.
new
(
"foo"
)
assert_includes
@options
,
"--foo"
assert_includes
@options
,
"foo"
assert_includes
@options
,
Option
.
new
(
"foo"
)
end
def
test_union_returns_options
assert_instance_of
Options
,
@options
+
Options
.
new
end
def
test_difference_returns_options
assert_instance_of
Options
,
@options
-
Options
.
new
end
def
test_shovel_returns_self
assert_same
@options
,
@options
<<
Option
.
new
(
"foo"
)
end
def
test_as_flags
@options
<<
Option
.
new
(
"foo"
)
assert_equal
%w[--foo]
,
@options
.
as_flags
end
def
test_to_a
option
=
Option
.
new
(
"foo"
)
@options
<<
option
assert_equal
[
option
],
@options
.
to_a
end
def
test_to_ary
option
=
Option
.
new
(
"foo"
)
@options
<<
option
assert_equal
[
option
],
@options
.
to_ary
end
def
test_intersection
foo
,
bar
,
baz
=
%w[foo bar baz]
.
map
{
|
o
|
Option
.
new
(
o
)
}
options
=
Options
.
new
<<
foo
<<
bar
@options
<<
foo
<<
baz
assert_equal
[
foo
],
(
@options
&
options
).
to_a
end
def
test_set_union
foo
,
bar
,
baz
=
%w[foo bar baz]
.
map
{
|
o
|
Option
.
new
(
o
)
}
options
=
Options
.
new
<<
foo
<<
bar
@options
<<
foo
<<
baz
assert_equal
[
foo
,
bar
,
baz
].
sort
,
(
@options
|
options
).
sort
end
def
test_times
@options
<<
Option
.
new
(
"aa"
)
<<
Option
.
new
(
"bb"
)
<<
Option
.
new
(
"cc"
)
assert_equal
%w[--aa --bb --cc]
,
(
@options
*
"XX"
).
split
(
"XX"
).
sort
end
def
test_create_with_array
array
=
%w[--foo --bar]
option1
=
Option
.
new
(
"foo"
)
option2
=
Option
.
new
(
"bar"
)
assert_equal
[
option1
,
option2
].
sort
,
Options
.
create
(
array
).
sort
end
def
test_inspect
assert_equal
"#<Options: []>"
,
@options
.
inspect
@options
<<
Option
.
new
(
"foo"
)
assert_equal
"#<Options: [#<Option:
\"
--foo
\"
>]>"
,
@options
.
inspect
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment