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
956c1d65
Commit
956c1d65
authored
12 years ago
by
Jack Nagel
Browse files
Options
Downloads
Patches
Plain Diff
Initial version comparison implementation
Signed-off-by:
Jack Nagel
<
jacknagel@gmail.com
>
parent
969ce2f6
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/test_versions.rb
+17
-1
17 additions, 1 deletion
Library/Homebrew/test/test_versions.rb
Library/Homebrew/version.rb
+19
-1
19 additions, 1 deletion
Library/Homebrew/version.rb
with
36 additions
and
2 deletions
Library/Homebrew/test/test_versions.rb
+
17
−
1
View file @
956c1d65
...
...
@@ -11,6 +11,10 @@ module VersionAssertions
def
assert_version_nil
url
assert_nil
Version
.
parse
(
url
)
end
def
assert_comparison
a
,
comparison
,
b
eval
"assert Version.new(a)
#{
comparison
}
Version.new(b)"
end
end
class
TestBadVersion
<
TestBall
...
...
@@ -21,7 +25,19 @@ class TestBadVersion < TestBall
end
end
class
VersionTests
<
Test
::
Unit
::
TestCase
class
VersionComparisonTests
<
Test
::
Unit
::
TestCase
include
VersionAssertions
def
test_version_comparisons
assert_comparison
'0.1'
,
'=='
,
'0.1.0'
assert_comparison
'0.1'
,
'!='
,
'0.2'
assert_comparison
'1.2.3'
,
'>'
,
'1.2.2'
assert_comparison
'1.2.3-p34'
,
'>'
,
'1.2.3-p33'
assert_comparison
'1.2.4'
,
'<'
,
'1.2.4.1'
end
end
class
VersionParsingTests
<
Test
::
Unit
::
TestCase
include
VersionAssertions
def
test_pathname_version
...
...
This diff is collapsed.
Click to expand it.
Library/Homebrew/version.rb
+
19
−
1
View file @
956c1d65
...
...
@@ -6,12 +6,30 @@ class Version
@version
=
val
.
to_s
.
strip
end
def
head?
@version
==
'HEAD'
end
def
nums
@version
.
scan
(
/\d+/
).
map
{
|
d
|
d
.
to_i
}
end
def
<
=>
(
other
)
@version
<=>
other
.
version
return
nil
unless
other
.
is_a?
Version
return
0
if
self
.
head?
and
other
.
head?
return
1
if
self
.
head?
and
not
other
.
head?
return
-
1
if
not
self
.
head?
and
other
.
head?
return
1
if
other
.
nil?
snums
=
self
.
nums
onums
=
other
.
nums
count
=
[
snums
.
length
,
onums
.
length
].
max
snums
.
fill
(
0
,
snums
.
length
,
count
-
snums
.
length
)
onums
.
fill
(
0
,
onums
.
length
,
count
-
onums
.
length
)
snums
<=>
onums
end
def
to_s
...
...
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