aboutsummaryrefslogtreecommitdiff
path: root/ruby/choice_TEST.rb
blob: 1ebe0822d10849aae2c45612957dc069471517fb (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env ruby
# vim: set sw=4 sts=4 et tw=80 :

#
# Copyright (c) 2008 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'

Paludis::Log.instance.log_level = Paludis::LogLevel::Warning

module Paludis
    module TestStuff
        def env
            unless @env
                @env = NoConfigEnvironment.new("choice_TEST_dir/testrepo/", '/var/empty')
            end
            @env
        end

        def pid
            env.package_database.fetch_repository("testrepo").package_ids("foo/bar").first
        end

        def choices
            pid.choices_key.value
        end

        def use_choice
            choices.each do | choice |
                return choice if choice.raw_name == "USE"
            end
            raise "oops"
        end

        def linguas_choice
            choices.each do | choice |
                return choice if choice.raw_name == "LINGUAS"
            end
            raise "oops"
        end

        def use_flag1
            choices.find_by_name_with_prefix("flag1")
        end

        def use_flag2
            choices.find_by_name_with_prefix("flag2")
        end

        def linguas_en
            choices.find_by_name_with_prefix("linguas_en")
        end
    end

    class TestCase_Choices < Test::Unit::TestCase
        include TestStuff

        def test_choices
            assert choices
        end

        def test_each
            count = 0
            choices.each do | choice |
                assert_kind_of Choice, choice
                count += 1
            end
            assert count > 0
        end

        def test_find_by_name_with_prefix
            assert_kind_of ChoiceValue, choices.find_by_name_with_prefix("flag1")
            assert_nil choices.find_by_name_with_prefix("monkey")
        end

        def test_has_matching_contains_every_value_prefix
            assert choices.has_matching_contains_every_value_prefix("linguas_de")
            assert ! choices.has_matching_contains_every_value_prefix("giant_hamster")
        end
    end

    class TestCase_Choice < Test::Unit::TestCase
        include TestStuff

        def test_choice
            assert use_choice
            assert linguas_choice
        end

        def test_each
            count = 0
            use_choice.each do | choice |
                assert_kind_of ChoiceValue, choice
                count += 1
            end
            assert count > 0
        end

        def test_raw_name
            assert_equal "USE", use_choice.raw_name
            assert_equal "LINGUAS", linguas_choice.raw_name
        end

        def test_human_name
            assert_equal "USE", use_choice.human_name
            assert_equal "linguas", linguas_choice.human_name
        end

        def test_prefix
            assert_equal "", use_choice.prefix
            assert_equal "linguas", linguas_choice.prefix
        end

        def test_contains_every_value
            assert ! use_choice.contains_every_value?
            assert linguas_choice.contains_every_value?
        end

        def test_hidden
            assert ! use_choice.hidden?
            assert ! linguas_choice.hidden?
        end

        def test_show_with_no_prefix
            assert use_choice.show_with_no_prefix?
            assert ! linguas_choice.show_with_no_prefix?
        end

        def test_consider_added_or_changed
            assert use_choice.consider_added_or_changed?
            assert linguas_choice.consider_added_or_changed?
        end
    end

    class TestCase_ChoiceValue < Test::Unit::TestCase
        include TestStuff

        def test_choice_value
            assert use_flag1
            assert use_flag2
            assert linguas_en
        end

        def test_unprefixed_name
            assert_equal "flag1", use_flag1.unprefixed_name
            assert_equal "flag2", use_flag2.unprefixed_name
            assert_equal "en", linguas_en.unprefixed_name
        end

        def test_name_with_prefix
            assert_equal "flag1", use_flag1.name_with_prefix
            assert_equal "flag2", use_flag2.name_with_prefix
            assert_equal "linguas_en", linguas_en.name_with_prefix
        end

        def test_enabled
            assert use_flag1.enabled?
            assert ! use_flag2.enabled?
            assert ! linguas_en.enabled?
        end

        def test_locked
            assert ! use_flag1.locked?
            assert ! use_flag2.locked?
            assert ! linguas_en.locked?
        end

        def test_description
            assert_equal "", use_flag1.description
            assert_equal "", use_flag2.description
            assert_equal "", linguas_en.description
        end

        def test_explicitly_listed
            assert use_flag1.explicitly_listed?
            assert use_flag2.explicitly_listed?
            assert linguas_en.explicitly_listed?
        end
    end
end

#!/usr/bin/ruby
# vim: set sw=4 sts=4 et tw=80 :