filigree 0.3.0 → 0.3.1

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.
@@ -18,174 +18,224 @@ require 'filigree/visitor'
18
18
  #######################
19
19
 
20
20
  class VisitorTester < Minitest::Test
21
-
21
+
22
22
  ####################
23
23
  # Internal Classes #
24
24
  ####################
25
-
25
+
26
26
  class Foo
27
27
  extend Filigree::Destructurable
28
-
28
+
29
29
  def initialize(a)
30
30
  @a = a
31
31
  end
32
-
32
+
33
33
  def destructure(_)
34
34
  [@a]
35
35
  end
36
-
36
+
37
37
  def visit(visitor)
38
38
  visitor.visit(self)
39
39
  end
40
40
  end
41
-
41
+
42
42
  class Bar
43
43
  extend Filigree::Destructurable
44
-
44
+
45
45
  def initialize(a, b)
46
46
  @a = a
47
47
  @b = b
48
48
  end
49
-
49
+
50
50
  def destructure(_)
51
51
  [@a, @b]
52
52
  end
53
-
53
+
54
54
  def visit(visitor)
55
55
  visitor(self)
56
56
  end
57
57
  end
58
-
58
+
59
59
  class Node
60
60
  extend Filigree::Destructurable
61
61
  include Filigree::Visitable
62
-
62
+
63
63
  def initialize(val, left = nil, right = nil)
64
64
  @val = val
65
65
  @left = left
66
66
  @right = right
67
67
  end
68
-
68
+
69
69
  def children
70
70
  [ @left, @right ]
71
71
  end
72
-
72
+
73
73
  def destructure(_)
74
74
  [ @val, @left, @right ]
75
75
  end
76
76
  end
77
-
77
+
78
78
  class SimpleVisitor
79
79
  include Filigree::Visitor
80
-
80
+
81
81
  on 1 do
82
82
  :one
83
83
  end
84
-
84
+
85
85
  on :two do |two|
86
86
  two
87
87
  end
88
-
88
+
89
89
  on /three/ do
90
90
  :three
91
91
  end
92
-
92
+
93
93
  on Foo.(4) do
94
94
  :four
95
95
  end
96
-
96
+
97
97
  on Foo.(n), -> { n == 5 } do
98
98
  :five
99
99
  end
100
-
100
+
101
101
  on Foo.(n), -> { n == 'six' } do
102
102
  n.to_sym
103
103
  end
104
104
  end
105
-
105
+
106
106
  class HelperMethodVisitor
107
107
  include Filigree::Visitor
108
-
108
+
109
109
  def helper(_)
110
110
  true
111
111
  end
112
-
112
+
113
113
  on Foo.(n), -> { helper(n) } do
114
114
  :foo
115
115
  end
116
116
  end
117
-
117
+
118
118
  class AdditiveVisitor
119
119
  include Filigree::Visitor
120
-
120
+
121
121
  attr_reader :total
122
-
122
+
123
123
  def initialize
124
124
  @total = 0
125
125
  end
126
-
126
+
127
127
  on(Foo.(Fixnum.as n)) do
128
128
  @total += n
129
129
  end
130
130
  end
131
-
131
+
132
132
  class MultiplicativeVisitor
133
133
  include Filigree::Visitor
134
-
134
+
135
135
  attr_reader :total
136
-
136
+
137
137
  def initialize
138
138
  @total = 1
139
139
  end
140
-
140
+
141
141
  on(Foo.(Fixnum.as n)) do
142
142
  @total *= n
143
143
  end
144
144
  end
145
-
145
+
146
146
  class NodeVisitor
147
147
  include Filigree::Visitor
148
-
148
+
149
149
  attr_reader :vals
150
-
150
+
151
151
  def initialize
152
152
  @vals = []
153
153
  end
154
-
154
+
155
155
  on(Node.(val, _, _)) do
156
156
  @vals << val
157
157
  end
158
158
  end
159
-
159
+
160
160
  class NumericVisitor
161
161
  include Filigree::Visitor
162
-
162
+
163
163
  on Numeric do |n|
164
164
  "Numeric: #{n}"
165
165
  end
166
166
  end
167
-
167
+
168
168
  class SubclassVisitor < NumericVisitor
169
+ strict_match true
170
+
169
171
  on Integer do |i|
170
172
  "Integer: #{i}"
171
173
  end
172
174
  end
173
-
175
+
176
+ class NonStrictMatchVisitor
177
+ include Filigree::Visitor
178
+
179
+ on 42 do
180
+ 'hoopy frood'
181
+ end
182
+ end
183
+
184
+ class OrderingVisitor0
185
+ include Filigree::Visitor
186
+
187
+ on Foo.(a) do
188
+ "Foo: #{a}"
189
+ end
190
+
191
+ on Object do |obj|
192
+ "Object: #{obj}"
193
+ end
194
+
195
+ on _ do |w|
196
+ "Wildcard: #{w}"
197
+ end
198
+ end
199
+
200
+ class OrderingVisitor1
201
+ include Filigree::Visitor
202
+
203
+ on Foo.(a) do
204
+ "Foo: #{a}"
205
+ end
206
+
207
+ on _ do |w|
208
+ "Wildcard: #{w}"
209
+ end
210
+ end
211
+
174
212
  def setup
175
213
  end
176
-
214
+
215
+ def test_ordering
216
+ assert_equal "Foo: 42", OrderingVisitor0.new.visit(Foo.new(42))
217
+ assert_equal "Foo: 42", OrderingVisitor1.new.visit(Foo.new(42))
218
+ assert_equal "Wildcard: 42", OrderingVisitor1.new.visit(42)
219
+ end
220
+
177
221
  def test_inheritance
178
222
  sv = SubclassVisitor.new
179
-
223
+
180
224
  assert_equal "Numeric: 3.1415296", sv.visit(3.1415296)
181
225
  assert_equal "Integer: 42", sv.visit(42)
182
-
226
+
183
227
  assert_raises(MatchError) { sv.visit(:hoopy) }
184
228
  end
185
-
229
+
230
+ def test_nonstrict_matching
231
+ nsmv = NonStrictMatchVisitor.new
232
+
233
+ assert_nil(nsmv.visit 0)
234
+ end
235
+
186
236
  def test_simple_visitor
187
237
  sv = SimpleVisitor.new
188
-
238
+
189
239
  assert_equal :one, sv.visit(1)
190
240
  assert_equal :two, sv.visit(:two)
191
241
  assert_equal :three, sv.visit('three')
@@ -193,32 +243,32 @@ class VisitorTester < Minitest::Test
193
243
  assert_equal :five, sv.visit(Foo.new(5))
194
244
  assert_equal :six, sv.visit(Foo.new('six'))
195
245
  end
196
-
246
+
197
247
  def test_stateful_visitor
198
248
  av = AdditiveVisitor.new
199
-
249
+
200
250
  assert_equal 1, Foo.new(1).visit(av)
201
251
  assert_equal 3, Foo.new(2).visit(av)
202
252
  assert_equal 42, Foo.new(39).visit(av)
203
253
  end
204
-
254
+
205
255
  def test_tour_guide
206
256
  tg = Filigree::TourGuide.new(AdditiveVisitor.new, MultiplicativeVisitor.new)
207
-
257
+
208
258
  Foo.new(1).visit(tg)
209
259
  Foo.new(2).visit(tg)
210
260
  Foo.new(39).visit(tg)
211
-
261
+
212
262
  assert_equal 42, tg.visitors[0].total
213
263
  assert_equal 78, tg.visitors[1].total
214
264
  end
215
-
265
+
216
266
  def test_visibility
217
267
  hmv = HelperMethodVisitor.new
218
-
268
+
219
269
  assert_equal :foo, hmv.visit(Foo.new(42))
220
270
  end
221
-
271
+
222
272
  def test_visitable
223
273
  tree = Node.new('F',
224
274
  Node.new('B',
@@ -234,26 +284,26 @@ class VisitorTester < Minitest::Test
234
284
  )
235
285
  )
236
286
  )
237
-
287
+
238
288
  # Test pre-order
239
289
  nv = NodeVisitor.new
240
290
  expected = ['F', 'B', 'A', 'D', 'C', 'E', 'G', 'I', 'H']
241
291
  tree.visit(nv, :preorder)
242
-
292
+
243
293
  assert_equal expected, nv.vals
244
-
294
+
245
295
  # Test level-order
246
296
  nv = NodeVisitor.new
247
297
  expected = ['F', 'B', 'G', 'A', 'D', 'I', 'C', 'E', 'H']
248
298
  tree.visit(nv, :inorder)
249
-
299
+
250
300
  assert_equal expected, nv.vals
251
-
301
+
252
302
  # Test post-order
253
303
  nv = NodeVisitor.new
254
304
  expected = ['A', 'C', 'E', 'D', 'B', 'H', 'I', 'G', 'F']
255
305
  tree.visit(nv, :postorder)
256
-
306
+
257
307
  assert_equal expected, nv.vals
258
308
  end
259
309
  end
metadata CHANGED
@@ -1,167 +1,167 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filigree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wailes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-23 00:00:00.000000000 Z
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: flay
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: flog
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake-notes
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: reek
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rubygems-tasks
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - '>='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - '>='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: simplecov
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - '>='
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - '>='
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: yard
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - '>='
157
+ - - ">="
158
158
  - !ruby/object:Gem::Version
159
159
  version: 0.8.1
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - '>='
164
+ - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: 0.8.1
167
167
  description: Filigree provides new classes and extensions to core library classes
@@ -171,37 +171,37 @@ executables: []
171
171
  extensions: []
172
172
  extra_rdoc_files: []
173
173
  files:
174
- - LICENSE
175
174
  - AUTHORS
175
+ - LICENSE
176
176
  - README.md
177
177
  - Rakefile
178
- - lib/filigree/types.rb
179
- - lib/filigree/boolean.rb
180
- - lib/filigree/match.rb
181
- - lib/filigree/application.rb
178
+ - lib/filigree.rb
182
179
  - lib/filigree/abstract_class.rb
180
+ - lib/filigree/application.rb
181
+ - lib/filigree/boolean.rb
183
182
  - lib/filigree/class.rb
184
- - lib/filigree/string.rb
185
- - lib/filigree/version.rb
183
+ - lib/filigree/class_methods_module.rb
184
+ - lib/filigree/commands.rb
186
185
  - lib/filigree/configuration.rb
187
- - lib/filigree/visitor.rb
186
+ - lib/filigree/match.rb
188
187
  - lib/filigree/object.rb
189
- - lib/filigree/commands.rb
190
188
  - lib/filigree/request_file.rb
191
- - lib/filigree/class_methods_module.rb
192
- - lib/filigree.rb
189
+ - lib/filigree/string.rb
190
+ - lib/filigree/types.rb
191
+ - lib/filigree/version.rb
192
+ - lib/filigree/visitor.rb
193
+ - test/tc_abstract_class.rb
194
+ - test/tc_application.rb
193
195
  - test/tc_boolean.rb
194
- - test/tc_object.rb
195
- - test/tc_types.rb
196
- - test/tc_configuration.rb
196
+ - test/tc_class.rb
197
+ - test/tc_class_methods_module.rb
197
198
  - test/tc_commands.rb
199
+ - test/tc_configuration.rb
200
+ - test/tc_match.rb
201
+ - test/tc_object.rb
198
202
  - test/tc_string.rb
199
- - test/tc_abstract_class.rb
203
+ - test/tc_types.rb
200
204
  - test/tc_visitor.rb
201
- - test/tc_class_methods_module.rb
202
- - test/tc_match.rb
203
- - test/tc_class.rb
204
- - test/tc_application.rb
205
205
  - test/ts_filigree.rb
206
206
  homepage: https://github.com/chriswailes/filigree
207
207
  licenses:
@@ -213,32 +213,32 @@ require_paths:
213
213
  - lib
214
214
  required_ruby_version: !ruby/object:Gem::Requirement
215
215
  requirements:
216
- - - '>='
216
+ - - ">="
217
217
  - !ruby/object:Gem::Version
218
218
  version: 2.0.0
219
219
  required_rubygems_version: !ruby/object:Gem::Requirement
220
220
  requirements:
221
- - - '>='
221
+ - - ">="
222
222
  - !ruby/object:Gem::Version
223
223
  version: '0'
224
224
  requirements: []
225
225
  rubyforge_project:
226
- rubygems_version: 2.1.11
226
+ rubygems_version: 2.2.2
227
227
  signing_key:
228
228
  specification_version: 4
229
229
  summary: Extra functionality for Ruby.
230
230
  test_files:
231
- - test/tc_boolean.rb
232
- - test/tc_object.rb
233
- - test/tc_types.rb
234
- - test/tc_configuration.rb
235
231
  - test/tc_commands.rb
232
+ - test/tc_types.rb
233
+ - test/tc_class.rb
236
234
  - test/tc_string.rb
235
+ - test/tc_application.rb
236
+ - test/tc_match.rb
237
237
  - test/tc_abstract_class.rb
238
- - test/tc_visitor.rb
238
+ - test/tc_object.rb
239
239
  - test/tc_class_methods_module.rb
240
- - test/tc_match.rb
241
- - test/tc_class.rb
242
- - test/tc_application.rb
240
+ - test/tc_configuration.rb
241
+ - test/tc_boolean.rb
242
+ - test/tc_visitor.rb
243
243
  - test/ts_filigree.rb
244
244
  has_rdoc: