solve 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -4,3 +4,5 @@ bundler_args: --without development
4
4
  rvm:
5
5
  - 1.9.2
6
6
  - 1.9.3
7
+ - 2.0.0
8
+ - jruby-19mode
@@ -96,7 +96,7 @@ module Solve
96
96
  # @param [Solve::Version] target_version
97
97
  #
98
98
  # @return [Boolean]
99
- def compare_aprox(constraint, target_version)
99
+ def compare_approx(constraint, target_version)
100
100
  min = constraint.version
101
101
  max = if constraint.patch.nil?
102
102
  Version.new([min.major + 1, 0, 0, 0])
@@ -115,17 +115,26 @@ module Solve
115
115
  end
116
116
  end
117
117
 
118
- OPERATORS = {
119
- "~>" => method(:compare_aprox),
120
- ">=" => method(:compare_gte),
121
- "<=" => method(:compare_lte),
122
- "=" => method(:compare_equal),
123
- "~" => method(:compare_aprox),
124
- ">" => method(:compare_gt),
125
- "<" => method(:compare_lt)
118
+ OPERATOR_TYPES = {
119
+ "~>" => :approx,
120
+ "~" => :approx,
121
+ ">=" => :greater_than_equal,
122
+ "<=" => :less_than_equal,
123
+ "=" => :equal,
124
+ ">" => :greater_than,
125
+ "<" => :less_than,
126
126
  }.freeze
127
127
 
128
- REGEXP = /^(#{OPERATORS.keys.join('|')})\s?(.+)$/
128
+ COMPARE_FUNS = {
129
+ approx: method(:compare_approx),
130
+ greater_than_equal: method(:compare_gte),
131
+ greater_than: method(:compare_gt),
132
+ less_than_equal: method(:compare_lte),
133
+ less_than: method(:compare_lt),
134
+ equal: method(:compare_equal)
135
+ }.freeze
136
+
137
+ REGEXP = /^(#{OPERATOR_TYPES.keys.join('|')})\s?(.+)$/
129
138
 
130
139
  attr_reader :operator
131
140
  attr_reader :major
@@ -141,7 +150,11 @@ module Solve
141
150
  end
142
151
 
143
152
  @operator, @major, @minor, @patch, @pre_release, @build = self.class.split(constraint)
144
- @compare_fun = OPERATORS.fetch(self.operator)
153
+
154
+ unless operator_type == :approx
155
+ @minor ||= 0
156
+ @patch ||= 0
157
+ end
145
158
  end
146
159
 
147
160
  # Return the Solve::Version representation of the major, minor, and patch
@@ -160,6 +173,15 @@ module Solve
160
173
  )
161
174
  end
162
175
 
176
+ # @return [Symbol]
177
+ def operator_type
178
+ unless type = OPERATOR_TYPES.fetch(operator)
179
+ raise RuntimeError, "unknown operator type: #{operator}"
180
+ end
181
+
182
+ type
183
+ end
184
+
163
185
  # Returns true or false if the given version would be satisfied by
164
186
  # the version constraint.
165
187
  #
@@ -173,7 +195,7 @@ module Solve
173
195
  return false
174
196
  end
175
197
 
176
- @compare_fun.call(self, target_version)
198
+ compare(target_version)
177
199
  end
178
200
 
179
201
  # @param [Object] other
@@ -187,11 +209,21 @@ module Solve
187
209
  alias_method :eql?, :==
188
210
 
189
211
  def to_s
190
- str = operator
191
- str += " #{major}.#{minor}.#{patch}"
212
+ str = "#{operator} #{major}"
213
+ str += ".#{minor}" if minor
214
+ str += ".#{patch}" if patch
192
215
  str += "-#{pre_release}" if pre_release
193
216
  str += "+#{build}" if build
194
217
  str
195
218
  end
219
+
220
+ private
221
+
222
+ # @param [Solve::Version] target
223
+ #
224
+ # @return [Boolean]
225
+ def compare(target)
226
+ COMPARE_FUNS.fetch(operator_type).call(self, target)
227
+ end
196
228
  end
197
229
  end
@@ -1,3 +1,3 @@
1
1
  module Solve
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
@@ -49,18 +49,34 @@ describe Solve::Constraint do
49
49
  end
50
50
  end
51
51
 
52
- context "given a constraint that does not include a minor version" do
52
+ context "given a constraint that does not include a minor version (~>)" do
53
53
  it "has a nil value for minor" do
54
- subject.new(">= 1").minor.should be_nil
54
+ expect(subject.new("~> 1").minor).to be_nil
55
+ end
56
+
57
+ it "has a nil value for patch" do
58
+ expect(subject.new("~> 1").patch).to be_nil
59
+ end
60
+ end
61
+
62
+ context "given a constraint that does not include a minor version (=)" do
63
+ it "has a 0 for minor" do
64
+ subject.new("= 1").minor.should eq(0)
55
65
  end
56
66
  end
57
67
 
58
- context "given a constraint that does not include a patch version" do
68
+ context "given a constraint that does not include a patch version (~>)" do
59
69
  it "has a nil value for patch" do
60
70
  subject.new("~> 1.2").patch.should be_nil
61
71
  end
62
72
  end
63
73
 
74
+ context "given a constraint that does not include a patch version (=)" do
75
+ it "has a 0 for patch" do
76
+ subject.new("= 1.2").patch.should eq(0)
77
+ end
78
+ end
79
+
64
80
  context "given a constraint that does not include a build version" do
65
81
  it "has a nil value for build" do
66
82
  subject.new(">= 1.2.3-alpha").build.should be_nil
@@ -441,7 +457,6 @@ describe Solve::Constraint do
441
457
  end
442
458
 
443
459
  describe "#eql?" do
444
-
445
460
  subject { Solve::Constraint.new("= 1.0.0") }
446
461
 
447
462
  it "returns true if the other object is a Solve::Constraint with the same operator and version" do
@@ -464,4 +479,31 @@ describe Solve::Constraint do
464
479
  subject.should_not eql(other)
465
480
  end
466
481
  end
482
+
483
+ describe "#to_s" do
484
+ let(:constraint_string) { ">= 1.2.3-alpha+123" }
485
+ subject { described_class.new(constraint_string).to_s }
486
+
487
+ it { should eq(constraint_string) }
488
+
489
+ context "when the constraint does not contain a minor or patch value" do
490
+ let(:constraint_string) { "~> 1" }
491
+ it { should eq(constraint_string) }
492
+ end
493
+
494
+ context "when the constraint does not contain a patch value" do
495
+ let(:constraint_string) { "~> 1.2" }
496
+ it { should eq(constraint_string) }
497
+ end
498
+
499
+ context "when the constraint does not contain a build value" do
500
+ let(:constraint_string) { ">= 1.2.0-alpha"}
501
+ it { should eq(constraint_string) }
502
+ end
503
+
504
+ context "when the constraint contains a pre_release value" do
505
+ let(:constraint_string) { ">= 1.2.0+123"}
506
+ it { should eq(constraint_string) }
507
+ end
508
+ end
467
509
  end
@@ -261,7 +261,7 @@ describe Solve::Version do
261
261
  end
262
262
 
263
263
  it "returns 0 as the second element" do
264
- subject.split("1")[2].should eql(0)
264
+ subject.split("1")[1].should eql(0)
265
265
  end
266
266
 
267
267
  it "returns 0 as the third element" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solve
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-05-06 00:00:00.000000000 Z
14
+ date: 2013-05-07 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: json
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  segments:
96
96
  - 0
97
- hash: -856939986988863331
97
+ hash: -3360162225470919551
98
98
  requirements: []
99
99
  rubyforge_project:
100
100
  rubygems_version: 1.8.23