diff options
| author | Markus Reiter | 2017-03-05 06:31:36 +0100 |
|---|---|---|
| committer | Markus Reiter | 2017-03-05 23:08:14 +0100 |
| commit | 9fc6c7b2be300ff35dc52d80f4dc38d36d52ddc2 (patch) | |
| tree | 43e99a683329471c1dc965dcc92daccb57df7e8d /Library/Homebrew/test/cask/dsl/version_spec.rb | |
| parent | 67ec76d1492fbb03959a782a85c4fb985d6a5884 (diff) | |
| download | brew-9fc6c7b2be300ff35dc52d80f4dc38d36d52ddc2.tar.bz2 | |
Move Cask specs into `brew tests`.
Diffstat (limited to 'Library/Homebrew/test/cask/dsl/version_spec.rb')
| -rw-r--r-- | Library/Homebrew/test/cask/dsl/version_spec.rb | 232 |
1 files changed, 232 insertions, 0 deletions
diff --git a/Library/Homebrew/test/cask/dsl/version_spec.rb b/Library/Homebrew/test/cask/dsl/version_spec.rb new file mode 100644 index 000000000..acf3db3ab --- /dev/null +++ b/Library/Homebrew/test/cask/dsl/version_spec.rb @@ -0,0 +1,232 @@ +describe Hbc::DSL::Version do + shared_examples "expectations hash" do |input_name, expectations| + expectations.each do |input_value, expected_output| + context "when #{input_name} is #{input_value.inspect}" do + let(input_name.to_sym) { input_value } + it { is_expected.to eq expected_output } + end + end + end + + shared_examples "version equality" do + let(:raw_version) { "1.2.3" } + + context "when other is nil" do + let(:other) { nil } + it { is_expected.to be false } + end + + context "when other is a String" do + context "when other == self.raw_version" do + let(:other) { "1.2.3" } + it { is_expected.to be true } + end + + context "when other != self.raw_version" do + let(:other) { "1.2.3.4" } + it { is_expected.to be false } + end + end + + context "when other is a #{described_class}" do + context "when other.raw_version == self.raw_version" do + let(:other) { described_class.new("1.2.3") } + it { is_expected.to be true } + end + + context "when other.raw_version != self.raw_version" do + let(:other) { described_class.new("1.2.3.4") } + it { is_expected.to be false } + end + end + end + + let(:version) { described_class.new(raw_version) } + + describe "#==" do + subject { version == other } + include_examples "version equality" + end + + describe "#eql?" do + subject { version.eql?(other) } + include_examples "version equality" + end + + shared_examples "version expectations hash" do |method, hash| + subject { version.send(method) } + include_examples "expectations hash", :raw_version, + { :latest => "latest", + "latest" => "latest", + "" => "", + nil => "" }.merge(hash) + end + + describe "#latest?" do + include_examples "version expectations hash", :latest?, + :latest => true, + "latest" => true, + "" => false, + nil => false, + "1.2.3" => false + end + + describe "string manipulation helpers" do + describe "#major" do + include_examples "version expectations hash", :major, + "1" => "1", + "1.2" => "1", + "1.2.3" => "1", + "1.2.3_4-5" => "1" + end + + describe "#minor" do + include_examples "version expectations hash", :minor, + "1" => "", + "1.2" => "2", + "1.2.3" => "2", + "1.2.3_4-5" => "2" + end + + describe "#patch" do + include_examples "version expectations hash", :patch, + "1" => "", + "1.2" => "", + "1.2.3" => "3", + "1.2.3_4-5" => "3" + end + + describe "#major_minor" do + include_examples "version expectations hash", :major_minor, + "1" => "1", + "1.2" => "1.2", + "1.2.3" => "1.2", + "1.2.3_4-5" => "1.2" + end + + describe "#major_minor_patch" do + include_examples "version expectations hash", :major_minor_patch, + "1" => "1", + "1.2" => "1.2", + "1.2.3" => "1.2.3", + "1.2.3_4-5" => "1.2.3" + end + + describe "#before_comma" do + include_examples "version expectations hash", :before_comma, + "1.2.3" => "1.2.3", + "1.2.3," => "1.2.3", + ",abc" => "", + "1.2.3,abc" => "1.2.3" + end + + describe "#after_comma" do + include_examples "version expectations hash", :after_comma, + "1.2.3" => "", + "1.2.3," => "", + ",abc" => "abc", + "1.2.3,abc" => "abc" + end + + describe "#before_colon" do + include_examples "version expectations hash", :before_colon, + "1.2.3" => "1.2.3", + "1.2.3:" => "1.2.3", + ":abc" => "", + "1.2.3:abc" => "1.2.3" + end + + describe "#after_colon" do + include_examples "version expectations hash", :after_colon, + "1.2.3" => "", + "1.2.3:" => "", + ":abc" => "abc", + "1.2.3:abc" => "abc" + end + + describe "#dots_to_hyphens" do + include_examples "version expectations hash", :dots_to_hyphens, + "1.2.3_4-5" => "1-2-3_4-5" + end + + describe "#dots_to_underscores" do + include_examples "version expectations hash", :dots_to_underscores, + "1.2.3_4-5" => "1_2_3_4-5" + end + + describe "#dots_to_slashes" do + include_examples "version expectations hash", :dots_to_slashes, + "1.2.3_4-5" => "1/2/3_4-5" + end + + describe "#hyphens_to_dots" do + include_examples "version expectations hash", :hyphens_to_dots, + "1.2.3_4-5" => "1.2.3_4.5" + end + + describe "#hyphens_to_underscores" do + include_examples "version expectations hash", :hyphens_to_underscores, + "1.2.3_4-5" => "1.2.3_4_5" + end + + describe "#hyphens_to_slashes" do + include_examples "version expectations hash", :hyphens_to_slashes, + "1.2.3_4-5" => "1.2.3_4/5" + end + + describe "#underscores_to_dots" do + include_examples "version expectations hash", :underscores_to_dots, + "1.2.3_4-5" => "1.2.3.4-5" + end + + describe "#underscores_to_hyphens" do + include_examples "version expectations hash", :underscores_to_hyphens, + "1.2.3_4-5" => "1.2.3-4-5" + end + + describe "#underscores_to_slashes" do + include_examples "version expectations hash", :underscores_to_slashes, + "1.2.3_4-5" => "1.2.3/4-5" + end + + describe "#slashes_to_dots" do + include_examples "version expectations hash", :slashes_to_dots, + "1.2.3/abc" => "1.2.3.abc" + end + + describe "#slashes_to_hyphens" do + include_examples "version expectations hash", :slashes_to_hyphens, + "1.2.3/abc" => "1.2.3-abc" + end + + describe "#slashes_to_underscores" do + include_examples "version expectations hash", :slashes_to_underscores, + "1.2.3/abc" => "1.2.3_abc" + end + + describe "#no_dots" do + include_examples "version expectations hash", :no_dots, + "1.2.3_4-5" => "123_4-5" + end + + describe "#no_hyphens" do + include_examples "version expectations hash", :no_hyphens, + "1.2.3_4-5" => "1.2.3_45" + end + + describe "#no_underscores" do + include_examples "version expectations hash", :no_underscores, + "1.2.3_4-5" => "1.2.34-5" + end + + describe "#no_slashes" do + include_examples "version expectations hash", :no_slashes, + "1.2.3/abc" => "1.2.3abc" + end + + describe "#no_dividers" do + include_examples "version expectations hash", :no_dividers, + "1.2.3_4-5" => "12345" + end + end +end |
