fedora-migrator /vendor/gems/facets-2.4.5/test/more/test_paramix.rb

Language Ruby Lines 171
MD5 Hash 8055c449f23a25e90ce5bfa8114155cc Estimated Cost $3,197 (why?)
Repository https://bitbucket.org/mediashelf/fedora-migrator View Raw File
  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
require 'facets/paramix.rb'
require 'test/unit'

class TC_Paramix_01 < Test::Unit::TestCase

  module M
    include Paramix

    def f
      mixin_params[M][:p]
    end

    def self.included(base)
      params = base.mixin_params[self]
      base.class_eval do
        define_method :check do
          params
        end
      end
    end
  end

  class C
    include M[:p => "check"]
  end

  class D
    include M[:p => "steak"]
  end

  def test_01_001
    c = C.new
    assert_equal( "check", c.mixin_params[M][:p] )
    assert_equal( "check", c.f )
  end

  def test_01_002
    d = D.new
    assert_equal( "steak", d.mixin_params[M][:p] )
    assert_equal( "steak", d.f )
  end

  def test_01_003
    assert_equal( {M=>{:p => "check"}}, C.mixin_parameters )
    assert_equal( {M=>{:p => "steak"}}, D.mixin_parameters )
  end

  def test_01_004
    c = C.new
    assert_equal( {:p => "check"}, c.check )
    d = D.new
    assert_equal( {:p => "steak"}, d.check )
  end

end

class TC_Paramix_02 < Test::Unit::TestCase

  module M
    # Manually define Paramix method.
    def self.[](parameters)
      Paramix.new(self, parameters) do
        define_method :check do
          mixin_params[M] # or parameters
        end
      end
    end

    def f
      mixin_params[M][:p]
    end
  end

  class C
    include M[:p => "check"]
  end

  class D
    include M[:p => "steak"]
  end

  def test_02_001
    c = C.new
    assert_equal( "check", c.mixin_params[M][:p] )
    assert_equal( "check", c.f )
  end

  def test_02_002
    d = D.new
    assert_equal( "steak", d.mixin_params[M][:p] )
    assert_equal( "steak", d.f )
  end

  def test_02_003
    assert_equal( {M=>{:p => "check"}}, C.mixin_parameters )
    assert_equal( {M=>{:p => "steak"}}, D.mixin_parameters )
  end

  def test_02_004
    c = C.new
    assert_equal( {:p => "check"}, c.check )
    d = D.new
    assert_equal( {:p => "steak"}, d.check )
  end

end

class TC_Paramix_03 < Test::Unit::TestCase

  module M
    include Paramix

    def f
      mixin_params[M][:p]
    end
  end

  class C
    extend M[:p => "mosh"]
  end

  class D
    extend M[:p => "many"]
  end

  def test_03_001
    assert_equal( "mosh", C.f )
  end

  def test_03_002
    assert_equal( "many", D.f )
  end

  def test_03_003
    assert_equal( {M=>{:p => "mosh"}}, (class << C; self; end).mixin_parameters )
    assert_equal( {M=>{:p => "many"}}, (class << D; self; end).mixin_parameters )
  end

end


class TC_Paramix_04 < Test::Unit::TestCase

  module O
    def self.[](parameters)
      Paramix.new(self, parameters) do
        attr_accessor mixin_parameters[O][:name]
      end
    end
  end

  class X
    include O[:name=>"x"]
  end

  def test_attribute
    o = X.new
    assert_nothing_raised{ o.x = 10 }
    assert_equal(10, o.x)
  end

  def test_ancestors
    assert(X.ancestors.include?(X))
    assert(X.ancestors.include?(O))
    assert(X.ancestors.include?(Object))
    assert(X.ancestors.include?(Kernel))
  end

end
Back to Top