summaryrefslogtreecommitdiff
path: root/spec/bundler/version_ranges_spec.rb
blob: bca044b0c01ac069bcb3abbd1af7a1a1d714d942 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

require "bundler/version_ranges"

RSpec.describe Bundler::VersionRanges do
  describe ".empty?" do
    shared_examples_for "empty?" do |exp, *req|
      it "returns #{exp} for #{req}" do
        r = Gem::Requirement.new(*req)
        ranges = described_class.for(r)
        expect(described_class.empty?(*ranges)).to eq(exp), "expected `#{r}` #{exp ? "" : "not "}to be empty"
      end
    end

    include_examples "empty?", false
    include_examples "empty?", false, "!= 1"
    include_examples "empty?", false, "!= 1", "= 2"
    include_examples "empty?", false, "!= 1", "> 1"
    include_examples "empty?", false, "!= 1", ">= 1"
    include_examples "empty?", false, "= 1", ">= 0.1", "<= 1.1"
    include_examples "empty?", false, "= 1", ">= 1", "<= 1"
    include_examples "empty?", false, "= 1", "~> 1"
    include_examples "empty?", false, ">= 0.z", "= 0"
    include_examples "empty?", false, ">= 0"
    include_examples "empty?", false, ">= 1.0.0", "< 2.0.0"
    include_examples "empty?", false, "~> 1"
    include_examples "empty?", false, "~> 2.0", "~> 2.1"
    include_examples "empty?", true, ">= 4.1.0", "< 5.0", "= 5.2.1"
    include_examples "empty?", true, "< 5.0", "< 5.3", "< 6.0", "< 6", "= 5.2.0", "> 2", ">= 3.0", ">= 3.1", ">= 3.2", ">= 4.0.0", ">= 4.1.0", ">= 4.2.0", ">= 4.2", ">= 4"
    include_examples "empty?", true, "!= 1", "< 2", "> 2"
    include_examples "empty?", true, "!= 1", "<= 1", ">= 1"
    include_examples "empty?", true, "< 2", "> 2"
    include_examples "empty?", true, "< 2", "> 2", "= 2"
    include_examples "empty?", true, "= 1", "!= 1"
    include_examples "empty?", true, "= 1", "= 2"
    include_examples "empty?", true, "= 1", "~> 2"
    include_examples "empty?", true, ">= 0", "<= 0.a"
    include_examples "empty?", true, "~> 2.0", "~> 3"
  end
end