solve 0.8.2 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.0.0-p247
@@ -1,25 +0,0 @@
1
- require 'forwardable'
2
-
3
- module Solve
4
- class Solver
5
- class ConstraintRow
6
- extend Forwardable
7
-
8
- attr_reader :source
9
-
10
- def_delegator :dependency, :name
11
- def_delegator :dependency, :constraint
12
-
13
- # @param [Solve::Dependency] dependency
14
- # @param [String, Symbol] source
15
- def initialize(dependency, source)
16
- @dependency = dependency
17
- @source = source
18
- end
19
-
20
- private
21
-
22
- attr_reader :dependency
23
- end
24
- end
25
- end
@@ -1,31 +0,0 @@
1
- module Solve
2
- class Solver
3
- class ConstraintTable
4
- attr_reader :rows
5
-
6
- def initialize
7
- @rows = Array.new
8
- end
9
-
10
- # @param [Solve::Dependency] dependency
11
- # @param [String, Symbol] source
12
- #
13
- # @return [Array<ConstraintRow>]
14
- def add(dependency, source)
15
- @rows << ConstraintRow.new(dependency, source)
16
- end
17
-
18
- def constraints_on_artifact(name)
19
- @rows.select do |row|
20
- row.name == name
21
- end.map { |row| row.constraint }
22
- end
23
-
24
- def remove_constraints_from_source!(source)
25
- from_source, others = @rows.partition { |row| row.source == source }
26
- @rows = others
27
- from_source
28
- end
29
- end
30
- end
31
- end
@@ -1,43 +0,0 @@
1
- module Solve
2
- class Solver
3
- class VariableRow
4
- attr_reader :artifact
5
- attr_reader :value
6
- attr_reader :sources
7
-
8
- # @param [String] artifact
9
- # @param [String, Symbol] source
10
- def initialize(artifact, source)
11
- @artifact = artifact
12
- @value = nil
13
- @sources = Array(source)
14
- end
15
-
16
- # @param [String, Symbol] source
17
- def add_source(source)
18
- @sources << source
19
- end
20
-
21
- def last_source
22
- @sources.last
23
- end
24
-
25
- def bind(value)
26
- @value = value
27
- end
28
-
29
- def unbind
30
- @value = nil
31
- end
32
-
33
- def bound?
34
- !@value.nil?
35
- end
36
-
37
- # @param [String, Symbol] source
38
- def remove_source(source)
39
- @sources.delete(source)
40
- end
41
- end
42
- end
43
- end
@@ -1,55 +0,0 @@
1
- module Solve
2
- class Solver
3
- class VariableTable
4
- attr_reader :rows
5
-
6
- def initialize
7
- @rows = Array.new
8
- end
9
-
10
- # @param [String] artifact
11
- # @param [String] source
12
- def add(artifact, source)
13
- row = rows.detect { |row| row.artifact == artifact }
14
- if row.nil?
15
- @rows << VariableRow.new(artifact, source)
16
- else
17
- row.add_source(source)
18
- end
19
- end
20
-
21
- def first_unbound
22
- @rows.detect { |row| row.bound? == false }
23
- end
24
-
25
- # @param [String] artifact
26
- def find_artifact(artifact)
27
- @rows.detect { |row| row.artifact == artifact }
28
- end
29
-
30
- # @param [String] source
31
- def remove_all_with_only_this_source!(source)
32
- with_only_this_source, others = @rows.partition { |row| row.sources == [source] }
33
- @rows = others
34
- with_only_this_source
35
- end
36
-
37
- # @param [String] source
38
- def all_from_source(source)
39
- @rows.select { |row| row.sources.include?(source) }
40
- end
41
-
42
- # @param [String] artifact
43
- def before(artifact)
44
- artifact_index = @rows.index { |row| row.artifact == artifact }
45
- (artifact_index == 0) ? nil : @rows[artifact_index - 1]
46
- end
47
-
48
- # @param [String] artifact
49
- def all_after(artifact)
50
- artifact_index = @rows.index { |row| row.artifact == artifact }
51
- @rows[(artifact_index+1)..-1]
52
- end
53
- end
54
- end
55
- end
data/lib/solve/tracers.rb DELETED
@@ -1,50 +0,0 @@
1
- module Solve
2
- module Tracers
3
- class << self
4
- # @param [#say] ui
5
- #
6
- # @returns [AbstractTracer]
7
- def build(ui)
8
- unless ui.respond_to?(:say)
9
- Solve::Tracers::Silent.new
10
- else
11
- Solve::Tracers::HumanReadable.new(ui)
12
- end
13
- end
14
- end
15
-
16
- class AbstractTracer
17
- class << self
18
- private
19
-
20
- def must_define(*args)
21
- args.each do |method|
22
- define_method(method.to_sym) do |*args|
23
- raise AbstractFunction, "##{method} must be defined on #{self.class}"
24
- end
25
- end
26
- end
27
- end
28
-
29
- TRACER_METHODS = [
30
- :start,
31
- :searching_for,
32
- :add_constraint,
33
- :possible_values,
34
- :trying,
35
- :backtrack,
36
- :cannot_backtrack,
37
- :solution,
38
- :reset_domain,
39
- :unbind,
40
- :remove_variable,
41
- :remove_constraint,
42
- ]
43
-
44
- must_define *TRACER_METHODS
45
- end
46
- end
47
- end
48
-
49
- require_relative 'tracers/human_readable'
50
- require_relative 'tracers/silent'
@@ -1,67 +0,0 @@
1
- module Solve
2
- module Tracers
3
- class HumanReadable < AbstractTracer
4
- extend Forwardable
5
-
6
- attr_reader :ui
7
-
8
- def_delegator :ui, :say
9
-
10
- # @param [#say] ui
11
- def initialize(ui)
12
- @ui = ui
13
- end
14
-
15
- def start
16
- say("Attempting to find a solution")
17
- end
18
-
19
- def searching_for(unbound_variable, constraints, possible_values)
20
- say("Searching for a value for #{unbound_variable.artifact}")
21
- say("Constraints are #{constraints.join("\n\t")}")
22
- possible_values(possible_values)
23
- end
24
-
25
- def possible_values(possible_values)
26
- say("Possible values are #{possible_values.map(&:to_s).join("\n\t")}")
27
- end
28
-
29
- def trying(artifact)
30
- say("Attempting to use #{artifact.to_s}")
31
- end
32
-
33
- def backtrack(unbound_variable)
34
- say("Could not find an acceptable value for #{unbound_variable.artifact.to_s}")
35
- end
36
-
37
- def cannot_backtrack
38
- say("Cannot backtrack any further")
39
- end
40
-
41
- def solution(solution)
42
- say("Found Solution")
43
- say(solution.inspect)
44
- end
45
-
46
- def add_constraint(dependency, source)
47
- say("Adding constraint #{dependency.name} #{dependency.constraint} from #{source.to_s}")
48
- end
49
-
50
- def reset_domain(variable)
51
- say("Resetting possible values for #{variable.artifact.to_s}")
52
- end
53
-
54
- def unbind(variable)
55
- say("Unbinding #{variable.artifact.to_s}")
56
- end
57
-
58
- def remove_variable(variable)
59
- say("Removed variable #{variable.artifact.to_s}")
60
- end
61
-
62
- def remove_constraint(constraint)
63
- say("Removed constraint #{constraint.name} #{constraint.constraint}")
64
- end
65
- end
66
- end
67
- end
@@ -1,17 +0,0 @@
1
- module Solve
2
- module Tracers
3
- class Silent < AbstractTracer
4
- class << self
5
- def empty_method(*args)
6
- args.each do |method|
7
- define_method(method.to_sym) do |*args|
8
- end
9
- end
10
- end
11
- end
12
-
13
- empty_method *AbstractTracer::TRACER_METHODS
14
- end
15
- end
16
- end
17
-
data/lib/solve/version.rb DELETED
@@ -1,140 +0,0 @@
1
- module Solve
2
- class Version
3
- class << self
4
- # @param [#to_s] version_string
5
- #
6
- # @raise [InvalidVersionFormat]
7
- #
8
- # @return [Array]
9
- def split(version_string)
10
- case version_string.to_s
11
- when /^(\d+)\.(\d+)\.(\d+)(-([0-9a-z\-\.]+))?(\+([0-9a-z\-\.]+))?$/i
12
- [ $1.to_i, $2.to_i, $3.to_i, $5, $7 ]
13
- when /^(\d+)\.(\d+)\.(\d+)?$/
14
- [ $1.to_i, $2.to_i, $3.to_i ]
15
- when /^(\d+)\.(\d+)?$/
16
- [ $1.to_i, $2.to_i, 0 ]
17
- when /^(\d+)$/
18
- [ $1.to_i, 0, 0 ]
19
- else
20
- raise Errors::InvalidVersionFormat.new(version_string)
21
- end
22
- end
23
- end
24
-
25
- include Comparable
26
-
27
- attr_reader :major
28
- attr_reader :minor
29
- attr_reader :patch
30
- attr_reader :pre_release
31
- attr_reader :build
32
-
33
- # @overload initialize(version_array)
34
- # @param [Array] version_array
35
- #
36
- # @example
37
- # Version.new([1, 2, 3, 'rc.1', 'build.1']) => #<Version: @major=1, @minor=2, @patch=3, @pre_release='rc.1', @build='build.1'>
38
- #
39
- # @overload initialize(version_string)
40
- # @param [#to_s] version_string
41
- #
42
- # @example
43
- # Version.new("1.2.3-rc.1+build.1") => #<Version: @major=1, @minor=2, @patch=3, @pre_release='rc.1', @build='build.1'>
44
- #
45
- # @overload initialize(version)
46
- # @param [Solve::Version] version
47
- #
48
- # @example
49
- # Version.new(Version.new("1.2.3-rc.1+build.1")) => #<Version: @major=1, @minor=2, @pre_release='rc.1', @build='build.1'>
50
- #
51
- def initialize(*args)
52
- if args.first.is_a?(Array)
53
- @major, @minor, @patch, @pre_release, @build = args.first
54
- else
55
- @major, @minor, @patch, @pre_release, @build = self.class.split(args.first.to_s)
56
- end
57
-
58
- @major ||= 0
59
- @minor ||= 0
60
- @patch ||= 0
61
- @pre_release ||= nil
62
- @build ||= nil
63
- end
64
-
65
- # @param [Solve::Version] other
66
- #
67
- # @return [Integer]
68
- def <=>(other)
69
- [:major, :minor, :patch].each do |release|
70
- ans = self.send(release) <=> other.send(release)
71
- return ans if ans != 0
72
- end
73
- ans = pre_release_and_build_presence_score <=> other.pre_release_and_build_presence_score
74
- return ans if ans != 0
75
- ans = identifiers_comparaison(other, :pre_release)
76
- return ans if ans != 0
77
- if build && other.build
78
- return identifiers_comparaison(other, :build)
79
- else
80
- return build.to_s <=> other.build.to_s
81
- end
82
- 0
83
- end
84
-
85
- # @return [Array]
86
- def identifiers(release)
87
- send(release).to_s.split('.').map do |str|
88
- str.to_i.to_s == str ? str.to_i : str
89
- end
90
- end
91
-
92
- def pre_release?
93
- !!pre_release
94
- end
95
-
96
- def zero?
97
- [major, minor, patch].all? { |n| n == 0 }
98
- end
99
-
100
- # @return [Integer]
101
- def pre_release_and_build_presence_score
102
- pre_release ? 0 : (build.nil? ? 1 : 2)
103
- end
104
-
105
- # @param [Solve::Version] other
106
- #
107
- # @return [Integer]
108
- def identifiers_comparaison(other, release)
109
- [identifiers(release).length, other.identifiers(release).length].max.times do |i|
110
- if identifiers(release)[i].class == other.identifiers(release)[i].class
111
- ans = identifiers(release)[i] <=> other.identifiers(release)[i]
112
- return ans if ans != 0
113
- elsif identifiers(release)[i] && other.identifiers(release)[i]
114
- return identifiers(release)[i].class.to_s <=> other.identifiers(release)[i].class.to_s
115
- elsif identifiers(release)[i] || other.identifiers(release)[i]
116
- return other.identifiers(release)[i].class.to_s <=> identifiers(release)[i].class.to_s
117
- end
118
- end
119
- 0
120
- end
121
-
122
- # @param [Solve::Version] other
123
- #
124
- # @return [Boolean]
125
- def eql?(other)
126
- other.is_a?(Version) && self == other
127
- end
128
-
129
- def inspect
130
- "#<#{self.class.to_s} #{to_s}>"
131
- end
132
-
133
- def to_s
134
- str = "#{major}.#{minor}.#{patch}"
135
- str += "-#{pre_release}" if pre_release
136
- str += "+#{build}" if build
137
- str
138
- end
139
- end
140
- end
@@ -1,708 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec::Matchers.define :satisfies do |*args|
4
- match do |constraint|
5
- constraint.satisfies?(*args).should be_true
6
- end
7
- end
8
-
9
- describe Solve::Constraint do
10
- let(:valid_string) { ">= 0.0.0" }
11
- let(:invalid_string) { "x23u7089213.*" }
12
-
13
- describe "ClassMethods" do
14
- subject { Solve::Constraint }
15
-
16
- describe "::new" do
17
- it "returns a new instance of Constraint" do
18
- subject.new(valid_string).should be_a(Solve::Constraint)
19
- end
20
-
21
- it "assigns the parsed operator to the operator attribute" do
22
- subject.new(valid_string).operator.should eql(">=")
23
- end
24
-
25
- it "assigns the parsed operator to the operator attribute with no separation between operator and version" do
26
- subject.new(">=0.0.0").operator.should eql(">=")
27
- end
28
-
29
- it "assigns the parsed version string as an instance of Version to the version attribute" do
30
- result = subject.new(valid_string)
31
-
32
- result.version.should be_a(Solve::Version)
33
- result.version.to_s.should eql("0.0.0")
34
- end
35
-
36
- it "sets a default of '>= 0.0.0' if given a nil value" do
37
- subject.new(nil).to_s.should eql(">= 0.0.0")
38
- end
39
-
40
- it "sets a default of '>= 0.0.0' if given a blank string" do
41
- subject.new('').to_s.should eql(">= 0.0.0")
42
- end
43
-
44
- context "given a string that does not match the Constraint REGEXP" do
45
- it "raises an InvalidConstraintFormat error" do
46
- lambda {
47
- subject.new(invalid_string)
48
- }.should raise_error(Solve::Errors::InvalidConstraintFormat)
49
- end
50
- end
51
-
52
- context "given a constraint that does not include a minor version (~>)" do
53
- it "has a nil value for minor" do
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)
65
- end
66
- end
67
-
68
- context "given a constraint that does not include a patch version (~>)" do
69
- it "has a nil value for patch" do
70
- subject.new("~> 1.2").patch.should be_nil
71
- end
72
- end
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
-
80
- context "given a constraint that does not include a build version" do
81
- it "has a nil value for build" do
82
- subject.new(">= 1.2.3-alpha").build.should be_nil
83
- end
84
- end
85
-
86
- context "given a constraint that does not include a pre release version" do
87
- it "has a nil value for pre release" do
88
- subject.new(">= 1.2.3+build").pre_release.should be_nil
89
- end
90
- end
91
- end
92
-
93
- describe "::split" do
94
- let(:constraint_string) { nil }
95
-
96
- subject { described_class.split(constraint_string) }
97
-
98
- context "given a constraint containing the elements (operator, major, minor, patch, pre_release, build)" do
99
- let(:constraint_string) { ">= 1.2.3-alpha+build" }
100
-
101
- it "returns an array with the constraint operator at index 0" do
102
- subject[0].should eql(">=")
103
- end
104
-
105
- it "returns an array with the major version in index 1" do
106
- subject[1].should eql(1)
107
- end
108
-
109
- it "returns an array with the minor version at index 2" do
110
- subject[2].should eql(2)
111
- end
112
-
113
- it "returns an array with the patch version at index 3" do
114
- subject[3].should eql(3)
115
- end
116
-
117
- it "returns an array with the pre release version at index 4" do
118
- subject[4].should eql("alpha")
119
- end
120
-
121
- it "returns an array with the build version at index 5" do
122
- subject[5].should eql("build")
123
- end
124
- end
125
-
126
- context "given a constraint containing the elements (operator, major, minor, patch, pre_release)" do
127
- let(:constraint_string) { ">= 1.2.3-alpha" }
128
-
129
- it "returns an array with the constraint operator at index 0" do
130
- subject[0].should eql(">=")
131
- end
132
-
133
- it "returns an array with the major version in index 1" do
134
- subject[1].should eql(1)
135
- end
136
-
137
- it "returns an array with the minor version at index 2" do
138
- subject[2].should eql(2)
139
- end
140
-
141
- it "returns an array with the patch version at index 3" do
142
- subject[3].should eql(3)
143
- end
144
-
145
- it "returns an array with the pre release version at index 4" do
146
- subject[4].should eql("alpha")
147
- end
148
-
149
- it "returns an array with a nil value at index 5" do
150
- subject[5].should be_nil
151
- end
152
- end
153
-
154
- context "given a constraint containing the elements (operator, major, minor, patch)" do
155
- let(:constraint_string) { ">= 1.2.3" }
156
-
157
- it "returns an array with the constraint operator at index 0" do
158
- subject[0].should eql(">=")
159
- end
160
-
161
- it "returns an array with the major version in index 1" do
162
- subject[1].should eql(1)
163
- end
164
-
165
- it "returns an array with the minor version at index 2" do
166
- subject[2].should eql(2)
167
- end
168
-
169
- it "returns an array with the patch version at index 3" do
170
- subject[3].should eql(3)
171
- end
172
-
173
- it "returns an array with a nil value at index 4" do
174
- subject[4].should be_nil
175
- end
176
-
177
- it "returns an array with a nil value at index 5" do
178
- subject[5].should be_nil
179
- end
180
- end
181
-
182
- context "given a constraint containing the elements (operator, major, minor)" do
183
- let(:constraint_string) { ">= 1.2" }
184
-
185
- it "returns an array with the constraint operator at index 0" do
186
- subject[0].should eql(">=")
187
- end
188
-
189
- it "returns an array with the major version in index 1" do
190
- subject[1].should eql(1)
191
- end
192
-
193
- it "returns an array with the minor version at index 2" do
194
- subject[2].should eql(2)
195
- end
196
-
197
- it "returns an array with a nil value at index 3" do
198
- subject[3].should be_nil
199
- end
200
-
201
- it "returns an array with a nil value at index 4" do
202
- subject[4].should be_nil
203
- end
204
-
205
- it "returns an array with a nil value at index 5" do
206
- subject[5].should be_nil
207
- end
208
- end
209
-
210
- context "given a constraint containing the elements (operator, major)" do
211
- let(:constraint_string) { ">= 1" }
212
-
213
- it "returns an array with the constraint operator at index 0" do
214
- subject[0].should eql(">=")
215
- end
216
-
217
- it "returns an array with the major version in index 1" do
218
- subject[1].should eql(1)
219
- end
220
-
221
- it "returns an array with a nil value at index 2" do
222
- subject[2].should be_nil
223
- end
224
-
225
- it "returns an array with a nil value at index 3" do
226
- subject[3].should be_nil
227
- end
228
-
229
- it "returns an array with a nil value at index 4" do
230
- subject[4].should be_nil
231
- end
232
-
233
- it "returns an array with a nil value at index 5" do
234
- subject[5].should be_nil
235
- end
236
- end
237
-
238
- context "given a constraint which is missing an operator" do
239
- let(:constraint_string) { "1.2.3" }
240
-
241
- it "returns an equality operator at index 0" do
242
- subject[0].should eql("=")
243
- end
244
- end
245
-
246
- context "given a string that does not match the Constraint REGEXP" do
247
- let(:constraint_string) { "x23u7089213.*" }
248
-
249
- it "raises an InvalidConstraintFormat error" do
250
- expect {
251
- subject.split(invalid_string)
252
- }.to raise_error(Solve::Errors::InvalidConstraintFormat)
253
- end
254
- end
255
-
256
- context "given a string that does not contain an operator" do
257
- let(:constraint_string) { "1.2.3" }
258
-
259
- it "returns a constraint constraint with a default operator (=)" do
260
- subject[0].should eql("=")
261
- end
262
- end
263
- end
264
- end
265
-
266
- describe "#satisfies?" do
267
- subject { Solve::Constraint.new("= 1.0.0") }
268
-
269
- it { should satisfies("1.0.0") }
270
-
271
- it "accepts a Version for version" do
272
- should satisfies(Solve::Version.new("1.0.0"))
273
- end
274
-
275
- context "strictly greater than (>) pre-release constraint" do
276
- subject { Solve::Constraint.new("> 1.0.0-alpha") }
277
-
278
- it { should_not satisfies("0.9.9+build") }
279
- it { should_not satisfies("1.0.0-alpha") }
280
- it { should satisfies("1.0.0-alpha.2") }
281
- it { should satisfies("1.0.0") }
282
- it { should satisfies("1.0.0+build") }
283
- it { should satisfies("1.0.1-beta") }
284
- it { should satisfies("1.0.1") }
285
- it { should satisfies("1.0.1+build.2") }
286
- it { should satisfies("2.0.0") }
287
- end
288
-
289
- context "strictly greater than (>)" do
290
- subject { Solve::Constraint.new("> 1.0.0") }
291
-
292
- it { should_not satisfies("0.9.9+build") }
293
- it { should_not satisfies("1.0.0-alpha") }
294
- it { should_not satisfies("1.0.0-alpha.2") }
295
- it { should_not satisfies("1.0.0") }
296
- it { should satisfies("1.0.0+build") }
297
- it { should_not satisfies("1.0.1-beta") }
298
- it { should satisfies("1.0.1") }
299
- it { should satisfies("1.0.1+build.2") }
300
- it { should satisfies("2.0.0") }
301
- end
302
-
303
- context "strictly greater than (>) build constraint" do
304
- subject { Solve::Constraint.new("> 1.0.0+build") }
305
-
306
- it { should_not satisfies("0.9.9+build") }
307
- it { should_not satisfies("1.0.0-alpha") }
308
- it { should_not satisfies("1.0.0-alpha.2") }
309
- it { should_not satisfies("1.0.0") }
310
- it { should_not satisfies("1.0.0+build") }
311
- it { should_not satisfies("1.0.1-beta") }
312
- it { should satisfies("1.0.1") }
313
- it { should satisfies("1.0.1+build.2") }
314
- it { should satisfies("2.0.0") }
315
- end
316
-
317
- context "greater than or equal to (>) zero pre-release constraint" do
318
- subject { Solve::Constraint.new("> 0.0.0-alpha") }
319
-
320
- it { should satisfies("0.9.9+build") }
321
- it { should satisfies("1.0.0-alpha") }
322
- it { should satisfies("1.0.0-alpha.2") }
323
- it { should satisfies("1.0.0") }
324
- it { should satisfies("1.0.0+build") }
325
- it { should satisfies("1.0.1-beta") }
326
- it { should satisfies("1.0.1") }
327
- it { should satisfies("1.0.1+build.2") }
328
- it { should satisfies("2.0.0") }
329
- end
330
-
331
- context "greater than or equal to (>) zero constraint" do
332
- subject { Solve::Constraint.new("> 0.0.0") }
333
-
334
- it { should satisfies("0.9.9+build") }
335
- it { should satisfies("1.0.0-alpha") }
336
- it { should satisfies("1.0.0-alpha.2") }
337
- it { should satisfies("1.0.0") }
338
- it { should satisfies("1.0.0+build") }
339
- it { should satisfies("1.0.1-beta") }
340
- it { should satisfies("1.0.1") }
341
- it { should satisfies("1.0.1+build.2") }
342
- it { should satisfies("2.0.0") }
343
- end
344
-
345
- context "greater than or equal to (>) zero build constraint" do
346
- subject { Solve::Constraint.new("> 0.0.0+build") }
347
-
348
- it { should satisfies("0.9.9+build") }
349
- it { should satisfies("1.0.0-alpha") }
350
- it { should satisfies("1.0.0-alpha.2") }
351
- it { should satisfies("1.0.0") }
352
- it { should satisfies("1.0.0+build") }
353
- it { should satisfies("1.0.1-beta") }
354
- it { should satisfies("1.0.1") }
355
- it { should satisfies("1.0.1+build.2") }
356
- it { should satisfies("2.0.0") }
357
- end
358
-
359
- context "strictly less than (<) pre-release constraint" do
360
- subject { Solve::Constraint.new("< 1.0.0-alpha.3") }
361
-
362
- it { should satisfies("0.9.9+build") }
363
- it { should satisfies("1.0.0-alpha") }
364
- it { should satisfies("1.0.0-alpha.2") }
365
- it { should_not satisfies("1.0.0") }
366
- it { should_not satisfies("1.0.0+build") }
367
- it { should_not satisfies("1.0.1-beta") }
368
- it { should_not satisfies("1.0.1") }
369
- it { should_not satisfies("1.0.1+build.2") }
370
- it { should_not satisfies("2.0.0") }
371
- end
372
-
373
- context "strictly less than (<)" do
374
- subject { Solve::Constraint.new("< 1.0.0") }
375
-
376
- it { should satisfies("0.9.9+build") }
377
- it { should satisfies("1.0.0-alpha") }
378
- it { should satisfies("1.0.0-alpha.2") }
379
- it { should_not satisfies("1.0.0") }
380
- it { should_not satisfies("1.0.0+build") }
381
- it { should_not satisfies("1.0.1-beta") }
382
- it { should_not satisfies("1.0.1") }
383
- it { should_not satisfies("1.0.1+build.2") }
384
- it { should_not satisfies("2.0.0") }
385
- end
386
-
387
- context "strictly less than (<) build constraint" do
388
- subject { Solve::Constraint.new("< 1.0.0+build.20") }
389
-
390
- it { should satisfies("0.9.9+build") }
391
- it { should satisfies("1.0.0-alpha") }
392
- it { should satisfies("1.0.0-alpha.2") }
393
- it { should satisfies("1.0.0") }
394
- it { should satisfies("1.0.0+build") }
395
- it { should_not satisfies("1.0.1-beta") }
396
- it { should_not satisfies("1.0.1") }
397
- it { should_not satisfies("1.0.1+build.2") }
398
- it { should_not satisfies("2.0.0") }
399
- end
400
-
401
- context "strictly equal to (=)" do
402
- subject { Solve::Constraint.new("= 1.0.0") }
403
-
404
- it { should_not satisfies("0.9.9+build") }
405
- it { should satisfies("1.0.0") }
406
- it { should_not satisfies("1.0.1") }
407
- it { should_not satisfies("1.0.0-alpha") }
408
- end
409
-
410
- context "greater than or equal to (>=) pre-release constraint" do
411
- subject { Solve::Constraint.new(">= 1.0.0-alpha") }
412
-
413
- it { should_not satisfies("0.9.9+build") }
414
- it { should satisfies("1.0.0-alpha") }
415
- it { should satisfies("1.0.0-alpha.2") }
416
- it { should satisfies("1.0.0") }
417
- it { should satisfies("1.0.0+build") }
418
- it { should satisfies("1.0.1-beta") }
419
- it { should satisfies("1.0.1") }
420
- it { should satisfies("1.0.1+build.2") }
421
- it { should satisfies("2.0.0") }
422
- end
423
-
424
- context "greater than or equal to (>=)" do
425
- subject { Solve::Constraint.new(">= 1.0.0") }
426
-
427
- it { should_not satisfies("0.9.9+build") }
428
- it { should_not satisfies("1.0.0-alpha") }
429
- it { should_not satisfies("1.0.0-alpha.2") }
430
- it { should satisfies("1.0.0") }
431
- it { should satisfies("1.0.0+build") }
432
- it { should_not satisfies("1.0.1-beta") }
433
- it { should satisfies("1.0.1") }
434
- it { should satisfies("1.0.1+build.2") }
435
- it { should satisfies("2.0.0") }
436
- end
437
-
438
- context "greater than or equal to (>=) build constraint" do
439
- subject { Solve::Constraint.new(">= 1.0.0+build") }
440
-
441
- it { should_not satisfies("0.9.9+build") }
442
- it { should_not satisfies("1.0.0-alpha") }
443
- it { should_not satisfies("1.0.0-alpha.2") }
444
- it { should_not satisfies("1.0.0") }
445
- it { should satisfies("1.0.0+build") }
446
- it { should_not satisfies("1.0.1-beta") }
447
- it { should satisfies("1.0.1") }
448
- it { should satisfies("1.0.1+build.2") }
449
- it { should satisfies("2.0.0") }
450
- end
451
-
452
- context "greater than or equal to (>=) zero pre-release constraint" do
453
- subject { Solve::Constraint.new(">= 0.0.0-alpha") }
454
-
455
- it { should satisfies("0.9.9+build") }
456
- it { should satisfies("1.0.0-alpha") }
457
- it { should satisfies("1.0.0-alpha.2") }
458
- it { should satisfies("1.0.0") }
459
- it { should satisfies("1.0.0+build") }
460
- it { should satisfies("1.0.1-beta") }
461
- it { should satisfies("1.0.1") }
462
- it { should satisfies("1.0.1+build.2") }
463
- it { should satisfies("2.0.0") }
464
- end
465
-
466
- context "greater than or equal to (>=) zero constraint" do
467
- subject { Solve::Constraint.new(">= 0.0.0") }
468
-
469
- it { should satisfies("0.9.9+build") }
470
- it { should satisfies("1.0.0-alpha") }
471
- it { should satisfies("1.0.0-alpha.2") }
472
- it { should satisfies("1.0.0") }
473
- it { should satisfies("1.0.0+build") }
474
- it { should satisfies("1.0.1-beta") }
475
- it { should satisfies("1.0.1") }
476
- it { should satisfies("1.0.1+build.2") }
477
- it { should satisfies("2.0.0") }
478
- end
479
-
480
- context "greater than or equal to (>=) zero build constraint" do
481
- subject { Solve::Constraint.new(">= 0.0.0+build") }
482
-
483
- it { should satisfies("0.9.9+build") }
484
- it { should satisfies("1.0.0-alpha") }
485
- it { should satisfies("1.0.0-alpha.2") }
486
- it { should satisfies("1.0.0") }
487
- it { should satisfies("1.0.0+build") }
488
- it { should satisfies("1.0.1-beta") }
489
- it { should satisfies("1.0.1") }
490
- it { should satisfies("1.0.1+build.2") }
491
- it { should satisfies("2.0.0") }
492
- end
493
-
494
- context "lower than or equal to (<=) pre-release constraint" do
495
- subject { Solve::Constraint.new("<= 1.0.0") }
496
-
497
- it { should satisfies("0.9.9+build") }
498
- it { should satisfies("1.0.0-alpha") }
499
- it { should satisfies("1.0.0-alpha.2") }
500
- it { should satisfies("1.0.0") }
501
- it { should_not satisfies("1.0.0+build") }
502
- it { should_not satisfies("1.0.1-beta") }
503
- it { should_not satisfies("1.0.1") }
504
- it { should_not satisfies("1.0.1+build.2") }
505
- it { should_not satisfies("2.0.0") }
506
- end
507
-
508
- context "lower than or equal to (<=)" do
509
- subject { Solve::Constraint.new("<= 1.0.0-alpha") }
510
-
511
- it { should satisfies("0.9.9+build") }
512
- it { should satisfies("1.0.0-alpha") }
513
- it { should_not satisfies("1.0.0-alpha.2") }
514
- it { should_not satisfies("1.0.0") }
515
- it { should_not satisfies("1.0.0+build") }
516
- it { should_not satisfies("1.0.1-beta") }
517
- it { should_not satisfies("1.0.1") }
518
- it { should_not satisfies("1.0.1+build.2") }
519
- it { should_not satisfies("2.0.0") }
520
- end
521
-
522
- context "lower than or equal to (<=) build constraint" do
523
- subject { Solve::Constraint.new("<= 1.0.0+build") }
524
-
525
- it { should satisfies("0.9.9+build") }
526
- it { should satisfies("1.0.0-alpha") }
527
- it { should satisfies("1.0.0-alpha.2") }
528
- it { should satisfies("1.0.0") }
529
- it { should satisfies("1.0.0+build") }
530
- it { should_not satisfies("1.0.1-beta") }
531
- it { should_not satisfies("1.0.1") }
532
- it { should_not satisfies("1.0.1+build.2") }
533
- it { should_not satisfies("2.0.0") }
534
- end
535
-
536
- %w[~> ~].each do |operator|
537
- describe "aproximately (#{operator})" do
538
- context "when the last value in the constraint is for minor" do
539
- subject { Solve::Constraint.new("#{operator} 1.2") }
540
-
541
- it { should_not satisfies("1.1.0") }
542
- it { should_not satisfies("1.2.0-alpha") }
543
- it { should satisfies("1.2.0") }
544
- it { should satisfies("1.2.3") }
545
- it { should satisfies("1.2.3+build") }
546
- it { should satisfies("1.3") }
547
- it { should satisfies("1.3.0") }
548
- it { should_not satisfies("2.0.0-0") }
549
- it { should_not satisfies("2.0.0") }
550
- end
551
-
552
- context "when the last value in the constraint is for patch" do
553
- subject { Solve::Constraint.new("#{operator} 1.2.0") }
554
-
555
- it { should_not satisfies("1.1.0") }
556
- it { should_not satisfies("1.2.3-alpha") }
557
- it { should satisfies("1.2.2") }
558
- it { should satisfies("1.2.3") }
559
- it { should satisfies("1.2.5+build") }
560
- it { should_not satisfies("1.3.0-0") }
561
- it { should_not satisfies("1.3.0") }
562
- end
563
-
564
- context "when the last value in the constraint is for pre_release with a last numeric identifier" do
565
- subject { Solve::Constraint.new("#{operator} 1.2.3-4") }
566
-
567
- it { should_not satisfies("1.2.3") }
568
- it { should satisfies("1.2.3-4") }
569
- it { should satisfies("1.2.3-10") }
570
- it { should satisfies("1.2.3-10.5+build.33") }
571
- it { should_not satisfies("1.2.3--") }
572
- it { should_not satisfies("1.2.3-alpha") }
573
- it { should_not satisfies("1.2.3") }
574
- it { should_not satisfies("1.2.4") }
575
- it { should_not satisfies("1.3.0") }
576
- end
577
-
578
- context "when the last value in the constraint is for pre_release with a last non-numeric identifier" do
579
- subject { Solve::Constraint.new("#{operator} 1.2.3-alpha") }
580
-
581
- it { should_not satisfies("1.2.3-4") }
582
- it { should_not satisfies("1.2.3--") }
583
- it { should satisfies("1.2.3-alpha") }
584
- it { should satisfies("1.2.3-alpha.0") }
585
- it { should satisfies("1.2.3-beta") }
586
- it { should satisfies("1.2.3-omega") }
587
- it { should satisfies("1.2.3-omega.4") }
588
- it { should_not satisfies("1.2.3") }
589
- it { should_not satisfies("1.3.0") }
590
- end
591
-
592
- context "when the last value in the constraint is for build with a last numeric identifier and a pre-release" do
593
- subject { Solve::Constraint.new("#{operator} 1.2.3-alpha+5") }
594
-
595
- it { should_not satisfies("1.2.3-alpha") }
596
- it { should_not satisfies("1.2.3-alpha.4") }
597
- it { should_not satisfies("1.2.3-alpha.4+4") }
598
- it { should satisfies("1.2.3-alpha+5") }
599
- it { should satisfies("1.2.3-alpha+5.5") }
600
- it { should satisfies("1.2.3-alpha+10") }
601
- it { should_not satisfies("1.2.3-alpha+-") }
602
- it { should_not satisfies("1.2.3-alpha+build") }
603
- it { should_not satisfies("1.2.3-beta") }
604
- it { should_not satisfies("1.2.3") }
605
- it { should_not satisfies("1.3.0") }
606
- end
607
-
608
- context "when the last value in the constraint is for build with a last non-numeric identifier and a pre-release" do
609
- subject { Solve::Constraint.new("#{operator} 1.2.3-alpha+build") }
610
-
611
- it { should_not satisfies("1.2.3-alpha") }
612
- it { should_not satisfies("1.2.3-alpha.4") }
613
- it { should_not satisfies("1.2.3-alpha.4+4") }
614
- it { should satisfies("1.2.3-alpha+build") }
615
- it { should satisfies("1.2.3-alpha+build.5") }
616
- it { should satisfies("1.2.3-alpha+preview") }
617
- it { should satisfies("1.2.3-alpha+zzz") }
618
- it { should_not satisfies("1.2.3-alphb") }
619
- it { should_not satisfies("1.2.3-beta") }
620
- it { should_not satisfies("1.2.3") }
621
- it { should_not satisfies("1.3.0") }
622
- end
623
-
624
- context "when the last value in the constraint is for build with a last numeric identifier" do
625
- subject { Solve::Constraint.new("#{operator} 1.2.3+5") }
626
-
627
- it { should_not satisfies("1.2.3") }
628
- it { should_not satisfies("1.2.3-alpha") }
629
- it { should_not satisfies("1.2.3+4") }
630
- it { should satisfies("1.2.3+5") }
631
- it { should satisfies("1.2.3+99") }
632
- it { should_not satisfies("1.2.3+5.build") }
633
- it { should_not satisfies("1.2.3+-") }
634
- it { should_not satisfies("1.2.3+build") }
635
- it { should_not satisfies("1.2.4") }
636
- it { should_not satisfies("1.3.0") }
637
- end
638
-
639
- context "when the last value in the constraint is for build with a last non-numeric identifier" do
640
- subject { Solve::Constraint.new("#{operator} 1.2.3+build") }
641
-
642
- it { should_not satisfies("1.2.3-alpha") }
643
- it { should_not satisfies("1.2.3") }
644
- it { should_not satisfies("1.2.3+5") }
645
- it { should satisfies("1.2.3+build") }
646
- it { should satisfies("1.2.3+build.5") }
647
- it { should satisfies("1.2.3+preview") }
648
- it { should satisfies("1.2.3+zzz") }
649
- it { should_not satisfies("1.2.4-0") }
650
- it { should_not satisfies("1.2.4") }
651
- it { should_not satisfies("1.2.5") }
652
- it { should_not satisfies("1.3.0") }
653
- end
654
- end
655
- end
656
- end
657
-
658
- describe "#eql?" do
659
- subject { Solve::Constraint.new("= 1.0.0") }
660
-
661
- it "returns true if the other object is a Solve::Constraint with the same operator and version" do
662
- other = Solve::Constraint.new("= 1.0.0")
663
- subject.should eql(other)
664
- end
665
-
666
- it "returns false if the other object is a Solve::Constraint with the same operator and different version" do
667
- other = Solve::Constraint.new("= 9.9.9")
668
- subject.should_not eql(other)
669
- end
670
-
671
- it "returns false if the other object is a Solve::Constraint with the same version and different operator" do
672
- other = Solve::Constraint.new("> 1.0.0")
673
- subject.should_not eql(other)
674
- end
675
-
676
- it "returns false if the other object is not a Solve::Constraint" do
677
- other = "chicken"
678
- subject.should_not eql(other)
679
- end
680
- end
681
-
682
- describe "#to_s" do
683
- let(:constraint_string) { ">= 1.2.3-alpha+123" }
684
- subject { described_class.new(constraint_string).to_s }
685
-
686
- it { should eq(constraint_string) }
687
-
688
- context "when the constraint does not contain a minor or patch value" do
689
- let(:constraint_string) { "~> 1" }
690
- it { should eq(constraint_string) }
691
- end
692
-
693
- context "when the constraint does not contain a patch value" do
694
- let(:constraint_string) { "~> 1.2" }
695
- it { should eq(constraint_string) }
696
- end
697
-
698
- context "when the constraint does not contain a build value" do
699
- let(:constraint_string) { ">= 1.2.0-alpha"}
700
- it { should eq(constraint_string) }
701
- end
702
-
703
- context "when the constraint contains a pre_release value" do
704
- let(:constraint_string) { ">= 1.2.0+123"}
705
- it { should eq(constraint_string) }
706
- end
707
- end
708
- end