dslkit 0.2.0

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.
@@ -0,0 +1,180 @@
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
+ end
69
+
70
+ def test_dsl_accessor
71
+ assert_nil @da.foo
72
+ assert_equal :bar, @da.bar
73
+ assert_equal :baz, @da.baz
74
+ assert_equal [:qu, :ux], @da.quux
75
+ @da.foo 1
76
+ @da.bar 2
77
+ @da.baz 3
78
+ assert_equal 1, @da.foo
79
+ assert_equal 2, @da.bar
80
+ assert_equal 3, @da.baz
81
+ end
82
+
83
+ def test_dsl_reader
84
+ assert_equal true, @da.on
85
+ assert_equal false, @da.off
86
+ assert_raises(ArgumentError) do
87
+ @da.on false
88
+ end
89
+ assert_equal [ @da.on, @da.off ], @da.states
90
+ assert_equal %w[a b c], @da.abc
91
+ @da.abc << 'd'
92
+ assert_equal %w[a b c d], @da.abc
93
+ @da.instance_variable_set :@abc, %w[a b c]
94
+ assert_equal %w[a b c], @da.abc
95
+ end
96
+
97
+ def test_dsl_accessor_multiple
98
+ assert_nil @da.foo
99
+ assert_equal :bar, @da.bar
100
+ @da.foo 1, 2
101
+ @da.bar [1, 2]
102
+ assert_equal [1, 2], @da.foo
103
+ assert_equal [1, 2], @da.bar
104
+ @da.bar [1, 2, *@da.bar]
105
+ assert_equal [1, 2] * 2, @da.bar
106
+ end
107
+
108
+ def test_interpreter
109
+ assert_equal :foo, @i.interpret('foo')
110
+ temp = Tempfile.new('foo')
111
+ temp.write 'foo'
112
+ temp.rewind
113
+ assert_equal :foo, @i.interpret(temp)
114
+ end
115
+
116
+ def test_interpreter_with_args
117
+ assert_equal 3, @i.interpret('|x| x + y', 1)
118
+ temp = Tempfile.new('foo')
119
+ temp.write '|x| x + y'
120
+ temp.rewind
121
+ assert_equal 3, @i.interpret(temp, 1)
122
+ end
123
+
124
+ def test_symbol_maker
125
+ if defined? S
126
+ s = S.new
127
+ assert_equal(:foo, s.instance_exec { foo })
128
+ assert_raises(NoMethodError) { s.instance_exec { foo 1 }}
129
+ end
130
+ end
131
+
132
+ def test_constant_maker
133
+ if defined? K
134
+ assert_equal(:FOO, K::FOO)
135
+ end
136
+ end
137
+
138
+ def test_deflect_block
139
+ assert_raises(NoMethodError) { 1.foo }
140
+ assert !D.deflect?(Integer, :foo)
141
+ D.deflect(Integer, :foo, DSLKit::Deflect::Deflector.new { :foo }) do
142
+ assert_equal :foo, 1.foo
143
+ assert D.deflect?(Integer, :foo)
144
+ end
145
+ assert !D.deflect?(Integer, :foo)
146
+ assert_raises(NoMethodError) { 1.foo }
147
+ end
148
+
149
+ def test_deflect
150
+ assert_raises(NoMethodError) { 1.foo }
151
+ assert !D.deflect?(Integer, :foo)
152
+ D.deflect_start(Integer, :foo, DSLKit::Deflect::Deflector.new { :foo })
153
+ assert_equal :foo, 1.foo
154
+ assert D.deflect?(Integer, :foo)
155
+ t = Thread.new do
156
+ assert !D.deflect?(Integer, :foo)
157
+ assert_raises(NoMethodError) { 1.foo }
158
+ end
159
+ t.join
160
+ D.deflect_stop(Integer, :foo)
161
+ assert !D.deflect?(Integer, :foo)
162
+ assert_raises(NoMethodError) { 1.foo }
163
+ end
164
+
165
+ def test_deflect_method_missing
166
+ assert_raises(NoMethodError) { 1.foo }
167
+ assert !D.deflect?(Integer, :method_missing)
168
+ D.deflect_start(Integer, :method_missing, DSLKit::Deflect::Deflector.new { :foo })
169
+ assert_equal :foo, 1.foo
170
+ assert D.deflect?(Integer, :method_missing)
171
+ t = Thread.new do
172
+ assert !D.deflect?(Integer, :method_missing)
173
+ assert_raises(NoMethodError) { 1.foo }
174
+ end
175
+ t.join
176
+ D.deflect_stop(Integer, :method_missing)
177
+ assert !D.deflect?(Integer, :method_missing)
178
+ assert_raises(NoMethodError) { 1.foo }
179
+ end
180
+ end
@@ -0,0 +1,91 @@
1
+ $:.unshift '../lib'
2
+ $:.unshift 'tests'
3
+ require 'dslkit/polite'
4
+
5
+ class TL
6
+ def initialize
7
+ make_baz
8
+ end
9
+
10
+ extend DSLKit::ThreadLocal
11
+ thread_local :foo
12
+
13
+ include DSLKit::ThreadLocal
14
+ def make_baz
15
+ instance_thread_local :baz
16
+ end
17
+
18
+ extend DSLKit::ThreadGlobal
19
+ thread_global :bar
20
+ end
21
+
22
+ class IE
23
+ include DSLKit::InstanceExec
24
+
25
+ def initialize(&block)
26
+ @block = block
27
+ end
28
+
29
+ def exec
30
+ instance_exec(&@block)
31
+ end
32
+
33
+ def foo
34
+ :foo
35
+ end
36
+ end
37
+
38
+ class C
39
+ extend DSLKit::Constant
40
+
41
+ constant :foo, :foo
42
+ end
43
+
44
+ class DA
45
+ extend DSLKit::DSLAccessor
46
+
47
+ dsl_accessor :foo
48
+
49
+ dsl_accessor :bar, :bar
50
+
51
+ dsl_accessor :baz do :baz end
52
+
53
+ dsl_accessor :quux, :qu, :ux
54
+
55
+ dsl_reader :on, true
56
+
57
+ dsl_reader :off, false
58
+
59
+ dsl_reader :states do
60
+ [ on, off ]
61
+ end
62
+
63
+ dsl_reader :abc, *%w[a b c]
64
+ end
65
+
66
+ class I
67
+ include DSLKit::Interpreter
68
+
69
+ def foo
70
+ :foo
71
+ end
72
+
73
+ def y
74
+ 2
75
+ end
76
+ end
77
+
78
+ class S
79
+ include DSLKit::InstanceExec
80
+ include DSLKit::SymbolMaker
81
+ end
82
+
83
+ module K
84
+ extend DSLKit::ConstantMaker
85
+ end
86
+
87
+ module D
88
+ extend DSLKit::Deflect
89
+ end
90
+
91
+ require 'test_common'
@@ -0,0 +1,70 @@
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, :foo
35
+ end
36
+
37
+ class DA
38
+ dsl_accessor :foo
39
+
40
+ dsl_accessor :bar, :bar
41
+
42
+ dsl_accessor :baz do :baz end
43
+
44
+ dsl_accessor :quux, :qu, :ux
45
+
46
+ dsl_reader :on, true
47
+
48
+ dsl_reader :off, false
49
+
50
+ dsl_reader :states do
51
+ [ on, off ]
52
+ end
53
+
54
+ dsl_reader :abc, *%w[a b c]
55
+ end
56
+
57
+ class I
58
+ def foo
59
+ :foo
60
+ end
61
+
62
+ def y
63
+ 2
64
+ end
65
+ end
66
+
67
+ module D
68
+ end
69
+
70
+ require 'test_common'
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: dslkit
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.2.0
7
+ date: 2006-09-22 00:00:00 +02:00
8
+ summary: Kit for building DSLs in Ruby
9
+ require_paths:
10
+ - lib
11
+ email: flori@ping.de
12
+ homepage: http://dslkit.rubyforge.org
13
+ rubyforge_project: dslkit
14
+ description: This library contains recurring patterns, that are useful in the creation of internal Domain Specific Languages (DSL) in Ruby.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - Florian Frank
30
+ files:
31
+ - tests
32
+ - lib
33
+ - examples
34
+ - Rakefile
35
+ - GPL
36
+ - TODO
37
+ - VERSION
38
+ - CHANGES
39
+ - install.rb
40
+ - tests/test_common.rb
41
+ - tests/test_rude.rb
42
+ - tests/test_polite.rb
43
+ - tests/runner.rb
44
+ - lib/dslkit
45
+ - lib/dslkit.rb
46
+ - lib/dslkit/polite.rb
47
+ - lib/dslkit/rude.rb
48
+ - examples/recipe_common.rb
49
+ - examples/subtract.reg
50
+ - examples/mail.rb
51
+ - examples/null_pattern.rb
52
+ - examples/recipe.rb
53
+ - examples/mm.rb
54
+ - examples/multiply.reg
55
+ - examples/recipe2.rb
56
+ test_files:
57
+ - tests/runner.rb
58
+ rdoc_options: []
59
+
60
+ extra_rdoc_files: []
61
+
62
+ executables: []
63
+
64
+ extensions: []
65
+
66
+ requirements: []
67
+
68
+ dependencies: []
69
+