filigree 0.1.2

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/test/tc_types.rb ADDED
@@ -0,0 +1,116 @@
1
+ # Author: Chris Wailes <chris.wailes@gmail.com>
2
+ # Project: Filigree
3
+ # Date: 2013/05/04
4
+ # Description: Test cases for type checking.
5
+
6
+ ############
7
+ # Requires #
8
+ ############
9
+
10
+ # Gems
11
+ require 'minitest/autorun'
12
+
13
+ # Filigree
14
+ require 'filigree/types'
15
+
16
+ #######################
17
+ # Classes and Modules #
18
+ #######################
19
+
20
+ class TypeTester < Minitest::Test
21
+
22
+ class Foo
23
+ include Filigree::TypedClass
24
+
25
+ typed_ivar :foo, Integer
26
+ typed_ivar :bar, String
27
+ typed_ivar :baf, [Integer]
28
+ end
29
+
30
+ class Bar
31
+ include Filigree::TypedClass
32
+
33
+ typed_ivar :foo, Integer
34
+ typed_ivar :bar, String
35
+
36
+ default_constructor
37
+ end
38
+
39
+ class Baf
40
+ include Filigree::TypedClass
41
+
42
+ typed_ivar :foo, Integer
43
+ typed_ivar :bar, String, true
44
+
45
+ default_constructor
46
+ end
47
+
48
+ class Baz
49
+ include Filigree::TypedClass
50
+
51
+ typed_ivar :foo, Integer
52
+ typed_ivar :bar, String
53
+
54
+ default_constructor true
55
+ end
56
+
57
+ def setup
58
+
59
+ end
60
+
61
+ def test_check_type
62
+ assert check_type([], Array)
63
+
64
+ assert check_type(1, Fixnum)
65
+ assert check_type(nil, Fixnum, nil, true).nil?
66
+ assert check_type(1, Fixnum, nil, false, true)
67
+ assert check_type(nil, Fixnum, nil, true, true).nil?
68
+ assert check_type(1, Integer)
69
+
70
+ assert_raises(TypeError) { check_type(1, Integer, nil, false, true) }
71
+ assert_raises(TypeError) { check_type(1, Array) }
72
+ end
73
+
74
+ def test_check_array_type
75
+ assert check_array_type([1, 2, 3], Fixnum)
76
+ assert check_array_type([1, 2, 3], Fixnum, nil, true)
77
+ assert check_array_type([1, 2, 3], Integer)
78
+
79
+ assert_raises(TypeError) { check_array_type([1, 2, 3], Integer, nil, false, true) }
80
+ assert_raises(TypeError) { check_array_type([1, :hello, 'world'], Fixnum) }
81
+ assert_raises(TypeError) { check_array_type([1, 2, 3], Float, 'foo') }
82
+ end
83
+
84
+ def test_default_constructor
85
+ v0 = Bar.new(1, 'hello')
86
+
87
+ assert_equal 1, v0.foo
88
+ assert_equal 'hello', v0.bar
89
+
90
+ v1 = Baf.new(2)
91
+
92
+ assert_equal 2, v1.foo
93
+ assert_nil v1.bar
94
+
95
+ assert_raises(ArgumentError) { Baz.new(3) }
96
+
97
+ v2 = Baz.new(2, 'world')
98
+
99
+ assert_equal 2, v2.foo
100
+ assert_equal 'world', v2.bar
101
+ end
102
+
103
+ def test_typed_instance_vars
104
+ v0 = Foo.new
105
+
106
+ v0.foo = 1
107
+ v0.bar = 'hello'
108
+ v0.baf = [1,2,3]
109
+
110
+ assert_equal 1, v0.foo
111
+ assert_equal 'hello', v0.bar
112
+ assert_equal [1,2,3], v0.baf
113
+
114
+ assert_raises(TypeError) { v0.foo = 'world' }
115
+ end
116
+ end
@@ -0,0 +1,236 @@
1
+ # Author: Chris Wailes <chris.wailes@gmail.com>
2
+ # Project: Filigree
3
+ # Date: 2014/02/11
4
+ # Description: Test cases for the Visitor module.
5
+
6
+ ############
7
+ # Requires #
8
+ ############
9
+
10
+ # Gems
11
+ require 'minitest/autorun'
12
+
13
+ # Filigree
14
+ require 'filigree/visitor'
15
+
16
+ #######################
17
+ # Classes and Modules #
18
+ #######################
19
+
20
+ class VisitorTester < Minitest::Test
21
+
22
+ ####################
23
+ # Internal Classes #
24
+ ####################
25
+
26
+ class Foo
27
+ extend Filigree::Destructurable
28
+
29
+ def initialize(a)
30
+ @a = a
31
+ end
32
+
33
+ def destructure(_)
34
+ [@a]
35
+ end
36
+
37
+ def visit(visitor)
38
+ visitor.(self)
39
+ end
40
+ end
41
+
42
+ class Bar
43
+ extend Filigree::Destructurable
44
+
45
+ def initialize(a, b)
46
+ @a = a
47
+ @b = b
48
+ end
49
+
50
+ def destructure(_)
51
+ [@a, @b]
52
+ end
53
+
54
+ def visit(visitor)
55
+ visitor(self)
56
+ end
57
+ end
58
+
59
+ class Node
60
+ extend Filigree::Destructurable
61
+ include Filigree::Visitable
62
+
63
+ def initialize(val, left = nil, right = nil)
64
+ @val = val
65
+ @left = left
66
+ @right = right
67
+ end
68
+
69
+ def children
70
+ [ @left, @right ]
71
+ end
72
+
73
+ def destructure(_)
74
+ [ @val, @left, @right ]
75
+ end
76
+ end
77
+
78
+ class SimpleVisitor
79
+ include Filigree::Visitor
80
+
81
+ on 1 do
82
+ :one
83
+ end
84
+
85
+ on :two do |two|
86
+ two
87
+ end
88
+
89
+ on /three/ do
90
+ :three
91
+ end
92
+
93
+ on Foo.(4) do
94
+ :four
95
+ end
96
+
97
+ on Foo.(n), -> { n == 5 } do
98
+ :five
99
+ end
100
+
101
+ on Foo.(n), -> { n == 'six' } do
102
+ n.to_sym
103
+ end
104
+ end
105
+
106
+ class HelperMethodVisitor
107
+ include Filigree::Visitor
108
+
109
+ def helper(_)
110
+ true
111
+ end
112
+
113
+ on Foo.(n), -> { helper(n) } do
114
+ :foo
115
+ end
116
+ end
117
+
118
+ class AdditiveVisitor
119
+ include Filigree::Visitor
120
+
121
+ attr_reader :total
122
+
123
+ def initialize
124
+ @total = 0
125
+ end
126
+
127
+ on(Foo.(Fixnum.as n)) do
128
+ @total += n
129
+ end
130
+ end
131
+
132
+ class MultiplicativeVisitor
133
+ include Filigree::Visitor
134
+
135
+ attr_reader :total
136
+
137
+ def initialize
138
+ @total = 1
139
+ end
140
+
141
+ on(Foo.(Fixnum.as n)) do
142
+ @total *= n
143
+ end
144
+ end
145
+
146
+ class NodeVisitor
147
+ include Filigree::Visitor
148
+
149
+ attr_reader :vals
150
+
151
+ def initialize
152
+ @vals = []
153
+ end
154
+
155
+ on(Node.(val, _, _)) do
156
+ @vals << val
157
+ end
158
+ end
159
+
160
+ def setup
161
+ end
162
+
163
+ def test_simple_visitor
164
+ sv = SimpleVisitor.new
165
+
166
+ assert_equal :one, sv.(1)
167
+ assert_equal :two, sv.(:two)
168
+ assert_equal :three, sv.('three')
169
+ assert_equal :four, sv.(Foo.new(4))
170
+ assert_equal :five, sv.(Foo.new(5))
171
+ assert_equal :six, sv.(Foo.new('six'))
172
+ end
173
+
174
+ def test_stateful_visitor
175
+ av = AdditiveVisitor.new
176
+
177
+ assert_equal 1, Foo.new(1).visit(av)
178
+ assert_equal 3, Foo.new(2).visit(av)
179
+ assert_equal 42, Foo.new(39).visit(av)
180
+ end
181
+
182
+ def test_tour_guide
183
+ tg = Filigree::TourGuide.new(AdditiveVisitor.new, MultiplicativeVisitor.new)
184
+
185
+ Foo.new(1).visit(tg)
186
+ Foo.new(2).visit(tg)
187
+ Foo.new(39).visit(tg)
188
+
189
+ assert_equal 42, tg.visitors[0].total
190
+ assert_equal 78, tg.visitors[1].total
191
+ end
192
+
193
+ def test_visibility
194
+ hmv = HelperMethodVisitor.new
195
+
196
+ assert_equal :foo, hmv.(Foo.new(42))
197
+ end
198
+
199
+ def test_visitable
200
+ tree = Node.new('F',
201
+ Node.new('B',
202
+ Node.new('A'),
203
+ Node.new('D',
204
+ Node.new('C'),
205
+ Node.new('E')
206
+ ),
207
+ ),
208
+ Node.new('G',
209
+ Node.new('I',
210
+ Node.new('H')
211
+ )
212
+ )
213
+ )
214
+
215
+ # Test pre-order
216
+ nv = NodeVisitor.new
217
+ expected = ['F', 'B', 'A', 'D', 'C', 'E', 'G', 'I', 'H']
218
+ tree.visit(nv, :preorder)
219
+
220
+ assert_equal expected, nv.vals
221
+
222
+ # Test level-order
223
+ nv = NodeVisitor.new
224
+ expected = ['F', 'B', 'G', 'A', 'D', 'I', 'C', 'E', 'H']
225
+ tree.visit(nv, :inorder)
226
+
227
+ assert_equal expected, nv.vals
228
+
229
+ # Test post-order
230
+ nv = NodeVisitor.new
231
+ expected = ['A', 'C', 'E', 'D', 'B', 'H', 'I', 'G', 'F']
232
+ tree.visit(nv, :postorder)
233
+
234
+ assert_equal expected, nv.vals
235
+ end
236
+ end
@@ -0,0 +1,33 @@
1
+ # Author: Chris Wailes <chris.wailes@gmail.com>
2
+ # Project: Filigree
3
+ # Date: 2013/04/19
4
+ # Description: This file contains the test suit for Filigree. It requires the
5
+ # individual tests from their respective files.
6
+
7
+ ############
8
+ # Requires #
9
+ ############
10
+
11
+ # Filigree
12
+ require 'filigree/request_file'
13
+
14
+ request_file('simplecov', 'SimpleCov is not installed.') do
15
+ SimpleCov.start do
16
+ add_filter 'tc_*'
17
+ end
18
+ end
19
+
20
+ # Test Cases
21
+ require 'tc_abstract_class'
22
+ require 'tc_application'
23
+ require 'tc_array'
24
+ require 'tc_boolean'
25
+ require 'tc_class'
26
+ require 'tc_class_methods_module'
27
+ require 'tc_commands'
28
+ require 'tc_configuration'
29
+ require 'tc_match'
30
+ require 'tc_object'
31
+ require 'tc_string'
32
+ require 'tc_types'
33
+ require 'tc_visitor'
metadata ADDED
@@ -0,0 +1,247 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: filigree
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Chris Wailes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: flay
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: flog
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake-notes
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: reek
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubygems-tasks
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: yard
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: 0.8.1
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: 0.8.1
167
+ description: Filigree provides new classes and extensions to core library classes
168
+ that add functionality to Ruby.
169
+ email: chris.wailes@gmail.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - LICENSE
175
+ - AUTHORS
176
+ - README.md
177
+ - Rakefile
178
+ - lib/filigree/request_file.rb
179
+ - lib/filigree/class_methods_module.rb
180
+ - lib/filigree/visitor.rb
181
+ - lib/filigree/types.rb
182
+ - lib/filigree/object.rb
183
+ - lib/filigree/string.rb
184
+ - lib/filigree/commands.rb
185
+ - lib/filigree/abstract_class.rb
186
+ - lib/filigree/boolean.rb
187
+ - lib/filigree/application.rb
188
+ - lib/filigree/version.rb
189
+ - lib/filigree/configuration.rb
190
+ - lib/filigree/array.rb
191
+ - lib/filigree/match.rb
192
+ - lib/filigree/class.rb
193
+ - lib/filigree.rb
194
+ - test/tc_commands.rb
195
+ - test/tc_array.rb
196
+ - test/tc_types.rb
197
+ - test/tc_class.rb
198
+ - test/tc_string.rb
199
+ - test/tc_application.rb
200
+ - test/tc_match.rb
201
+ - test/tc_abstract_class.rb
202
+ - test/tc_object.rb
203
+ - test/tc_class_methods_module.rb
204
+ - test/tc_configuration.rb
205
+ - test/tc_boolean.rb
206
+ - test/tc_visitor.rb
207
+ - test/ts_filigree.rb
208
+ homepage: https://github.com/chriswailes/filigree
209
+ licenses:
210
+ - University of Illinois/NCSA Open Source License
211
+ metadata: {}
212
+ post_install_message:
213
+ rdoc_options: []
214
+ require_paths:
215
+ - lib
216
+ required_ruby_version: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - '>='
219
+ - !ruby/object:Gem::Version
220
+ version: 2.0.0
221
+ required_rubygems_version: !ruby/object:Gem::Requirement
222
+ requirements:
223
+ - - '>='
224
+ - !ruby/object:Gem::Version
225
+ version: '0'
226
+ requirements: []
227
+ rubyforge_project:
228
+ rubygems_version: 2.1.11
229
+ signing_key:
230
+ specification_version: 4
231
+ summary: Extra functionality for Ruby.
232
+ test_files:
233
+ - test/tc_commands.rb
234
+ - test/tc_array.rb
235
+ - test/tc_types.rb
236
+ - test/tc_class.rb
237
+ - test/tc_string.rb
238
+ - test/tc_application.rb
239
+ - test/tc_match.rb
240
+ - test/tc_abstract_class.rb
241
+ - test/tc_object.rb
242
+ - test/tc_class_methods_module.rb
243
+ - test/tc_configuration.rb
244
+ - test/tc_boolean.rb
245
+ - test/tc_visitor.rb
246
+ - test/ts_filigree.rb
247
+ has_rdoc: