aboutsummaryrefslogtreecommitdiff
path: root/ruby/name_TEST.rb
blob: 6e35cc399f3d35415657fd1a0c79b8748df69ec7 (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
#!/usr/bin/ruby
# vim: set sw=4 sts=4 et tw=80 :

require 'test/unit'
require 'Paludis'

module NameTestCaseBase
    def valid_name_foo
        return "foo"
    end

    def valid_name_bar
        return "bar"
    end

    def bad_name
        return "foo~"
    end

    def test_create
        x = name_type().new(valid_name_foo())
    end

    def test_assign
        x = name_type().new(valid_name_foo())
        y = x
    end

    def test_compare
        x = name_type().new(valid_name_foo())
        y = name_type().new(valid_name_foo())
        z = name_type().new(valid_name_bar())
        assert x == y
        assert y != z
        assert z < x
        assert x > z
        assert_raise TypeError do
            x < valid_name_foo()
        end
    end

    def test_create_errors
        assert_raise error_type() do
            x = name_type().new(bad_name())
        end
        assert_raise error_type() do
            x = name_type().new("")
        end
    end

    def test_to_s
        x = name_type().new(valid_name_foo())
        y = name_type().new(valid_name_bar())
        assert x.to_s == valid_name_foo()
        assert y.to_s == valid_name_bar()
    end
end

class TestCase_PackageNamePart < Test::Unit::TestCase
    include NameTestCaseBase

    def error_type
        return PackageNamePartError
    end

    def name_type
        return PackageNamePart
    end
end

class TestCase_CategoryNamePart < Test::Unit::TestCase
    include NameTestCaseBase

    def error_type
        return CategoryNamePartError
    end

    def name_type
        return CategoryNamePart
    end
end

class TestCase_UseFlagName < Test::Unit::TestCase
    include NameTestCaseBase

    def error_type
        return UseFlagNameError
    end

    def name_type
        return UseFlagName
    end
end

class TestCase_RepositoryName < Test::Unit::TestCase
    include NameTestCaseBase

    def error_type
        return RepositoryNameError
    end

    def name_type
        return RepositoryName
    end
end

class TestCase_SlotName < Test::Unit::TestCase
    include NameTestCaseBase

    def error_type
        return SlotNameError
    end

    def name_type
        return SlotName
    end
end

class TestCase_KeywordName < Test::Unit::TestCase
    include NameTestCaseBase

    def error_type
        return KeywordNameError
    end

    def name_type
        return KeywordName
    end
end