aboutsummaryrefslogtreecommitdiff
path: root/ruby/version_spec_TEST.rb
blob: cf9c416dfa29bc604604a7af21d50f08612286c7 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env ruby
# vim: set sw=4 sts=4 et tw=80 :

#
# Copyright (c) 2006, 2007 Ciaran McCreesh
#
# This file is part of the Paludis package manager. Paludis is free software;
# you can redistribute it and/or modify it under the terms of the GNU General
# Public License version 2, as published by the Free Software Foundation.
#
# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA  02111-1307  USA
#

require 'test/unit'
require 'Paludis'

module Paludis
    class TestCase_VersionSpec < Test::Unit::TestCase
        def test_create
            v = VersionSpec.new("0")
        end

        def test_create_error
            assert_raise TypeError do
                v = VersionSpec.new(0)
            end

            assert_raise BadVersionSpecError do
                v = VersionSpec.new("1.0-r1-x")
            end
        end

        def test_compare
            v0 = VersionSpec.new("0")
            v1 = VersionSpec.new("0.1")
            v2 = VersionSpec.new("1.0")

            assert_operator v0, :<, v1
            assert_operator v0, :<, v2
            assert_operator v1, :<, v2

            assert_operator v0, :<=, v0
            assert_operator v0, :<=, v1
            assert_operator v0, :<=, v2
            assert_operator v1, :<=, v2
        end

        def test_to_s
            assert_equal "0.1_alpha2", VersionSpec.new("0.1_alpha2").to_s
        end

        def test_remove_revision
            assert_equal VersionSpec.new('0.1'), VersionSpec.new('0.1-r1').remove_revision
        end

        def test_version_only
            assert_equal 'r9', VersionSpec.new('0.1-r9').revision_only
        end

        def test_is_scm?
            assert_equal true, VersionSpec.new('scm').is_scm?
            assert_equal false, VersionSpec.new('0.1').is_scm?
        end

        def test_has_scm_part?
            assert_equal true, VersionSpec.new('scm').has_scm_part?
            assert_equal false, VersionSpec.new('0.1').has_scm_part?
        end

        def test_has_try_part?
            assert_equal true, VersionSpec.new('1.2-try3').has_try_part?
            assert_equal false, VersionSpec.new('0.1').has_try_part?
        end

        def test_bump
            assert_equal VersionSpec.new('2'), VersionSpec.new('1').bump
            assert_equal VersionSpec.new('2'), VersionSpec.new('1.2').bump
            assert_equal VersionSpec.new('1.3'), VersionSpec.new('1.2.3').bump
            assert_equal VersionSpec.new('1.3'), VersionSpec.new('1.2.3-r4').bump
            assert_equal VersionSpec.new('scm'), VersionSpec.new('scm').bump
        end
    end
end