dslkit 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/install.rb DELETED
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rbconfig'
4
- require 'fileutils'
5
- include FileUtils::Verbose
6
-
7
- include Config
8
-
9
- src = File.join(*%w[lib dslkit])
10
- dst = File.join(CONFIG["sitelibdir"], 'dslkit')
11
- mkdir_p dst
12
- cd src do
13
- for file in Dir['*.rb']
14
- install file, File.join(dst, file)
15
- end
16
- end
17
- install File.join('lib', 'dslkit.rb'), File.join(CONFIG["sitelibdir"], 'dslkit.rb')
data/tests/runner.rb DELETED
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $:.unshift '../lib'
4
- $:.unshift 'tests'
5
-
6
- warn "Test polite."
7
- fork { load 'test_polite.rb' }
8
- Process.waitpid
9
- warn "Test rude."
10
- fork { load 'test_rude.rb' }
11
- Process.waitpid
data/tests/test_common.rb DELETED
@@ -1,202 +0,0 @@
1
- require 'test/unit'
2
- require 'tempfile'
3
-
4
- class TC_DSLKit < Test::Unit::TestCase
5
- def setup
6
- @tl = TL.new
7
- @tl2 = TL.new
8
- @ie = IE.new { foo }
9
- @c = C.new
10
- @da = DA.new
11
- @i = I.new
12
- end
13
-
14
- def test_thread_local
15
- assert_nil @tl.foo
16
- @tl.foo = 1
17
- assert_equal 1, @tl.foo
18
- new_foo = nil
19
- thread = Thread.new do
20
- @tl.foo = 2
21
- new_foo = @tl.foo
22
- end
23
- thread.join
24
- assert_equal 2, new_foo
25
- assert_equal 1, @tl.foo
26
- assert_equal @tl.baz, @tl2.baz
27
- end
28
-
29
- def test_instance_thread_local
30
- assert_nil @tl.baz
31
- @tl.baz = 1
32
- assert_equal 1, @tl.baz
33
- new_foo = nil
34
- thread = Thread.new do
35
- @tl.baz = 2
36
- new_foo = @tl.baz
37
- end
38
- thread.join
39
- assert_equal 2, new_foo
40
- assert_equal 1, @tl.baz
41
- assert_not_equal @tl.baz, @tl2.baz
42
- end
43
-
44
- def test_thread_global
45
- assert_nil @tl.bar
46
- @tl.bar = 1
47
- assert_equal 1, @tl.bar
48
- new_bar = nil
49
- thread = Thread.new do
50
- @tl.bar = 2
51
- new_bar = @tl.bar
52
- end
53
- thread.join
54
- assert_equal 2, new_bar
55
- assert_equal 2, @tl.bar
56
- end
57
-
58
- def test_instance_exec
59
- assert_equal :foo, @ie.foo
60
- assert_equal :foo, @ie.exec
61
- @ie.freeze
62
- assert_equal :foo, @ie.foo
63
- assert_equal :foo, @ie.exec
64
- end
65
-
66
- def test_constant
67
- assert_equal :foo, @c.foo
68
- assert_equal :baz, @c.bar
69
- end
70
-
71
- def test_dsl_accessor
72
- assert_nil @da.foo
73
- assert_equal :bar, @da.bar
74
- assert_equal :baz, @da.baz
75
- assert_equal [:qu, :ux], @da.quux
76
- @da.foo 1
77
- @da.bar 2
78
- @da.baz 3
79
- assert_equal 1, @da.foo
80
- assert_equal 2, @da.bar
81
- assert_equal 3, @da.baz
82
- end
83
-
84
- def test_dsl_reader
85
- assert_equal true, @da.on
86
- assert_equal false, @da.off
87
- assert_raises(ArgumentError) do
88
- @da.on false
89
- end
90
- assert_equal [ @da.on, @da.off ], @da.states
91
- assert_equal %w[a b c], @da.abc
92
- @da.abc << 'd'
93
- assert_equal %w[a b c d], @da.abc
94
- @da.instance_variable_set :@abc, %w[a b c]
95
- assert_equal %w[a b c], @da.abc
96
- end
97
-
98
- def test_dsl_accessor_multiple
99
- assert_nil @da.foo
100
- assert_equal :bar, @da.bar
101
- @da.foo 1, 2
102
- @da.bar [1, 2]
103
- assert_equal [1, 2], @da.foo
104
- assert_equal [1, 2], @da.bar
105
- @da.bar [1, 2, *@da.bar]
106
- assert_equal [1, 2] * 2, @da.bar
107
- end
108
-
109
- def test_interpreter
110
- assert_equal :foo, @i.interpret('foo')
111
- temp = Tempfile.new('foo')
112
- temp.write 'foo'
113
- temp.rewind
114
- assert_equal :foo, @i.interpret(temp)
115
- end
116
-
117
- def test_interpreter_with_args
118
- assert_equal 3, @i.interpret('|x| x + y', 1)
119
- temp = Tempfile.new('foo')
120
- temp.write '|x| x + y'
121
- temp.rewind
122
- assert_equal 3, @i.interpret(temp, 1)
123
- end
124
-
125
- def test_symbol_maker
126
- if defined? S
127
- s = S.new
128
- assert_equal(:foo, s.instance_exec { foo })
129
- assert_raises(NoMethodError) { s.instance_exec { foo 1 }}
130
- end
131
- end
132
-
133
- def test_constant_maker
134
- if defined? K
135
- assert_equal(:FOO, K::FOO)
136
- end
137
- end
138
-
139
- def test_deflect_block
140
- assert_raises(NoMethodError) { 1.foo }
141
- assert !D.deflect?(Integer, :foo)
142
- D.deflect(Integer, :foo, DSLKit::Deflect::Deflector.new { :foo }) do
143
- assert_equal :foo, 1.foo
144
- assert D.deflect?(Integer, :foo)
145
- end
146
- assert !D.deflect?(Integer, :foo)
147
- assert_raises(NoMethodError) { 1.foo }
148
- end
149
-
150
- def test_deflect
151
- assert_raises(NoMethodError) { 1.foo }
152
- assert !D.deflect?(Integer, :foo)
153
- D.deflect_start(Integer, :foo, DSLKit::Deflect::Deflector.new { :foo })
154
- assert_equal :foo, 1.foo
155
- assert D.deflect?(Integer, :foo)
156
- t = Thread.new do
157
- assert !D.deflect?(Integer, :foo)
158
- assert_raises(NoMethodError) { 1.foo }
159
- end
160
- t.join
161
- D.deflect_stop(Integer, :foo)
162
- assert !D.deflect?(Integer, :foo)
163
- assert_raises(NoMethodError) { 1.foo }
164
- end
165
-
166
- def test_deflect_method_missing
167
- assert_raises(NoMethodError) { 1.foo }
168
- assert !D.deflect?(Integer, :method_missing)
169
- D.deflect_start(Integer, :method_missing, DSLKit::Deflect::Deflector.new { :foo })
170
- assert_equal :foo, 1.foo
171
- assert D.deflect?(Integer, :method_missing)
172
- t = Thread.new do
173
- assert !D.deflect?(Integer, :method_missing)
174
- assert_raises(NoMethodError) { 1.foo }
175
- end
176
- t.join
177
- D.deflect_stop(Integer, :method_missing)
178
- assert !D.deflect?(Integer, :method_missing)
179
- assert_raises(NoMethodError) { 1.foo }
180
- end
181
-
182
- def test_delegate
183
- d = D2.new
184
- assert_equal 3, d.my_size1
185
- assert_equal 3, d.my_size2
186
- assert_equal 3, d.size
187
- assert_equal 3, d.length
188
- end
189
-
190
- if defined? D3
191
- def test_delegate
192
- d = D3.new []
193
- assert_equal 0, d.size
194
- d.push 1
195
- assert_equal [1], d.map { |x| x }
196
- d.push 2
197
- assert_equal [1, 2], d.map { |x| x }
198
- d.push 3
199
- assert_equal [1, 2, 3], d.map { |x| x }
200
- end
201
- end
202
- end
data/tests/test_rude.rb DELETED
@@ -1,84 +0,0 @@
1
- $:.unshift '../lib'
2
- $:.unshift 'tests'
3
- require 'dslkit/rude'
4
-
5
- class TL
6
- def initialize
7
- make_baz
8
- end
9
-
10
- thread_local :foo
11
-
12
- def make_baz
13
- instance_thread_local :baz
14
- end
15
-
16
- thread_global :bar
17
- end
18
-
19
- class IE
20
- def initialize(&block)
21
- @block = block
22
- end
23
-
24
- def exec
25
- instance_exec(&@block)
26
- end
27
-
28
- def foo
29
- :foo
30
- end
31
- end
32
-
33
- class C
34
- constant :foo
35
-
36
- constant :bar, :baz
37
- end
38
-
39
- class DA
40
- dsl_accessor :foo
41
-
42
- dsl_accessor :bar, :bar
43
-
44
- dsl_accessor :baz do :baz end
45
-
46
- dsl_accessor :quux, :qu, :ux
47
-
48
- dsl_reader :on, true
49
-
50
- dsl_reader :off, false
51
-
52
- dsl_reader :states do
53
- [ on, off ]
54
- end
55
-
56
- dsl_reader :abc, *%w[a b c]
57
- end
58
-
59
- class I
60
- def foo
61
- :foo
62
- end
63
-
64
- def y
65
- 2
66
- end
67
- end
68
-
69
- module D
70
- end
71
-
72
- class D2
73
- def initialize
74
- @ary = [ 1, 2, 3 ]
75
- end
76
- attr_reader :ary
77
-
78
- delegate :my_size1, :@ary, :size
79
- delegate :my_size2, :ary, :size
80
- delegate :size, :@ary
81
- delegate :length, :ary
82
- end
83
-
84
- require 'test_common'