antlr3 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/ANTLR-LICENSE.txt +26 -0
  2. data/History.txt +66 -0
  3. data/README.txt +139 -0
  4. data/bin/antlr4ruby +33 -0
  5. data/java/RubyTarget.java +524 -0
  6. data/java/antlr-full-3.2.1.jar +0 -0
  7. data/lib/antlr3.rb +176 -0
  8. data/lib/antlr3/constants.rb +88 -0
  9. data/lib/antlr3/debug.rb +701 -0
  10. data/lib/antlr3/debug/event-hub.rb +210 -0
  11. data/lib/antlr3/debug/record-event-listener.rb +25 -0
  12. data/lib/antlr3/debug/rule-tracer.rb +55 -0
  13. data/lib/antlr3/debug/socket.rb +360 -0
  14. data/lib/antlr3/debug/trace-event-listener.rb +92 -0
  15. data/lib/antlr3/dfa.rb +247 -0
  16. data/lib/antlr3/dot.rb +174 -0
  17. data/lib/antlr3/error.rb +657 -0
  18. data/lib/antlr3/main.rb +561 -0
  19. data/lib/antlr3/modes/ast-builder.rb +41 -0
  20. data/lib/antlr3/modes/filter.rb +56 -0
  21. data/lib/antlr3/profile.rb +322 -0
  22. data/lib/antlr3/recognizers.rb +1280 -0
  23. data/lib/antlr3/streams.rb +985 -0
  24. data/lib/antlr3/streams/interactive.rb +91 -0
  25. data/lib/antlr3/streams/rewrite.rb +412 -0
  26. data/lib/antlr3/test/call-stack.rb +57 -0
  27. data/lib/antlr3/test/config.rb +23 -0
  28. data/lib/antlr3/test/core-extensions.rb +269 -0
  29. data/lib/antlr3/test/diff.rb +165 -0
  30. data/lib/antlr3/test/functional.rb +207 -0
  31. data/lib/antlr3/test/grammar.rb +371 -0
  32. data/lib/antlr3/token.rb +592 -0
  33. data/lib/antlr3/tree.rb +1415 -0
  34. data/lib/antlr3/tree/debug.rb +163 -0
  35. data/lib/antlr3/tree/visitor.rb +84 -0
  36. data/lib/antlr3/tree/wizard.rb +481 -0
  37. data/lib/antlr3/util.rb +149 -0
  38. data/lib/antlr3/version.rb +27 -0
  39. data/samples/ANTLRv3Grammar.g +621 -0
  40. data/samples/Cpp.g +749 -0
  41. data/templates/AST.stg +335 -0
  42. data/templates/ASTDbg.stg +40 -0
  43. data/templates/ASTParser.stg +153 -0
  44. data/templates/ASTTreeParser.stg +272 -0
  45. data/templates/Dbg.stg +192 -0
  46. data/templates/Ruby.stg +1514 -0
  47. data/test/functional/ast-output/auto-ast.rb +797 -0
  48. data/test/functional/ast-output/construction.rb +555 -0
  49. data/test/functional/ast-output/hetero-nodes.rb +753 -0
  50. data/test/functional/ast-output/rewrites.rb +1327 -0
  51. data/test/functional/ast-output/tree-rewrite.rb +1662 -0
  52. data/test/functional/debugging/debug-mode.rb +689 -0
  53. data/test/functional/debugging/profile-mode.rb +165 -0
  54. data/test/functional/debugging/rule-tracing.rb +74 -0
  55. data/test/functional/delegation/import.rb +379 -0
  56. data/test/functional/lexer/basic.rb +559 -0
  57. data/test/functional/lexer/filter-mode.rb +245 -0
  58. data/test/functional/lexer/nuances.rb +47 -0
  59. data/test/functional/lexer/properties.rb +104 -0
  60. data/test/functional/lexer/syn-pred.rb +32 -0
  61. data/test/functional/lexer/xml.rb +206 -0
  62. data/test/functional/main/main-scripts.rb +245 -0
  63. data/test/functional/parser/actions.rb +224 -0
  64. data/test/functional/parser/backtracking.rb +244 -0
  65. data/test/functional/parser/basic.rb +282 -0
  66. data/test/functional/parser/calc.rb +98 -0
  67. data/test/functional/parser/ll-star.rb +143 -0
  68. data/test/functional/parser/nuances.rb +165 -0
  69. data/test/functional/parser/predicates.rb +103 -0
  70. data/test/functional/parser/properties.rb +242 -0
  71. data/test/functional/parser/rule-methods.rb +132 -0
  72. data/test/functional/parser/scopes.rb +274 -0
  73. data/test/functional/token-rewrite/basic.rb +318 -0
  74. data/test/functional/token-rewrite/via-parser.rb +100 -0
  75. data/test/functional/tree-parser/basic.rb +750 -0
  76. data/test/unit/sample-input/file-stream-1 +2 -0
  77. data/test/unit/sample-input/teststreams.input2 +2 -0
  78. data/test/unit/test-dfa.rb +52 -0
  79. data/test/unit/test-exceptions.rb +44 -0
  80. data/test/unit/test-recognizers.rb +55 -0
  81. data/test/unit/test-scheme.rb +62 -0
  82. data/test/unit/test-streams.rb +459 -0
  83. data/test/unit/test-tree-wizard.rb +535 -0
  84. data/test/unit/test-trees.rb +854 -0
  85. metadata +205 -0
@@ -0,0 +1,535 @@
1
+ #!/usr/bin/ruby
2
+ # encoding: utf-8
3
+
4
+ require 'antlr3'
5
+ require 'antlr3/tree/wizard'
6
+ require 'test/unit'
7
+ require 'spec'
8
+
9
+
10
+ include ANTLR3
11
+ include ANTLR3::AST
12
+
13
+ class TestTreePatternLexer < Test::Unit::TestCase
14
+
15
+ # vvvvvvvv tests vvvvvvvvv
16
+
17
+ def test_open
18
+ lexer = Wizard::TreePatternLexer.new('(')
19
+ type = lexer.next_token
20
+ assert_equal(type, :open)
21
+ assert_equal(lexer.text, '')
22
+ assert_equal(lexer.error, false)
23
+ end
24
+
25
+ def test_close
26
+ lexer = Wizard::TreePatternLexer.new(')')
27
+ type = lexer.next_token
28
+ assert_equal(type, :close)
29
+ assert_equal(lexer.text, '')
30
+ assert_equal(lexer.error, false)
31
+ end
32
+
33
+ def test_percent
34
+ lexer = Wizard::TreePatternLexer.new('%')
35
+ type = lexer.next_token
36
+ assert_equal(type, :percent)
37
+ assert_equal(lexer.text, '')
38
+ assert_equal(lexer.error, false)
39
+ end
40
+
41
+ def test_dot
42
+ lexer = Wizard::TreePatternLexer.new('.')
43
+ type = lexer.next_token
44
+ assert_equal(type, :dot)
45
+ assert_equal(lexer.text, '')
46
+ assert_equal(lexer.error, false)
47
+ end
48
+
49
+ def test_eof
50
+ lexer = Wizard::TreePatternLexer.new(" \n \r \t ")
51
+ type = lexer.next_token
52
+ assert_equal(type, EOF)
53
+ assert_equal(lexer.text, '')
54
+ assert_equal(lexer.error, false)
55
+ end
56
+
57
+ def test_id
58
+ lexer = Wizard::TreePatternLexer.new('__whatever_1__')
59
+ type = lexer.next_token
60
+ assert_equal(:identifier, type)
61
+ assert_equal('__whatever_1__', lexer.text)
62
+ assert( !(lexer.error) )
63
+ end
64
+
65
+ def test_arg
66
+ lexer = Wizard::TreePatternLexer.new('[ \]bla\n]')
67
+ type = lexer.next_token
68
+ assert_equal(type, :argument)
69
+ assert_equal(' ]bla\n', lexer.text)
70
+ assert( !(lexer.error) )
71
+ end
72
+
73
+ def test_error
74
+ lexer = Wizard::TreePatternLexer.new("1")
75
+ type = lexer.next_token
76
+ assert_equal(type, EOF)
77
+ assert_equal(lexer.text, '')
78
+ assert_equal(lexer.error, true)
79
+ end
80
+
81
+ end
82
+
83
+
84
+ class TestTreePatternParser < Test::Unit::TestCase
85
+ def setup
86
+ @adaptor = CommonTreeAdaptor.new
87
+ @pattern_adaptor = Wizard::TreePatternTreeAdaptor.new
88
+ @tokens = Array.new(5, '') + %w(A B C D E ID VAR)
89
+ @wizard = Wizard.new(@adaptor, @tokens)
90
+ end
91
+
92
+ # vvvvvvvv tests vvvvvvvvv
93
+ def test_single_node
94
+ lexer = Wizard::TreePatternLexer.new('ID')
95
+ parser = Wizard::TreePatternParser.new(lexer, @wizard, @adaptor)
96
+ tree = parser.pattern
97
+
98
+ assert_instance_of(CommonTree, tree)
99
+ assert_equal(10, tree.type)
100
+ assert_equal('ID', tree.text)
101
+ end
102
+
103
+ def test_single_node_with_arg
104
+ lexer = Wizard::TreePatternLexer.new('ID[foo]')
105
+ parser = Wizard::TreePatternParser.new(lexer, @wizard, @adaptor)
106
+ tree = parser.pattern
107
+
108
+ assert_instance_of(CommonTree, tree)
109
+ assert_equal(10, tree.type)
110
+ assert_equal('foo', tree.text)
111
+ end
112
+
113
+ def test_single_level_tree
114
+ lexer = Wizard::TreePatternLexer.new('(A B)')
115
+ parser = Wizard::TreePatternParser.new(lexer, @wizard, @adaptor)
116
+ tree = parser.pattern
117
+
118
+ assert_instance_of(CommonTree, tree)
119
+ assert_equal(5, tree.type)
120
+ assert_equal('A', tree.text)
121
+ assert_equal(tree.child_count, 1)
122
+ assert_equal(tree.child(0).type, 6)
123
+ assert_equal(tree.child(0).text, 'B')
124
+ end
125
+
126
+ def test_nil
127
+ lexer = Wizard::TreePatternLexer.new('nil')
128
+ parser = Wizard::TreePatternParser.new(lexer, @wizard, @adaptor)
129
+ tree = parser.pattern
130
+
131
+ assert_instance_of(CommonTree, tree)
132
+ assert_equal(0, tree.type)
133
+ assert_nil tree.text
134
+ end
135
+
136
+ def test_wildcard
137
+ lexer = Wizard::Wizard::TreePatternLexer.new('(.)')
138
+ parser = Wizard::Wizard::TreePatternParser.new(lexer, @wizard, @adaptor)
139
+ tree = parser.pattern
140
+
141
+ assert_instance_of(Wizard::WildcardTreePattern, tree)
142
+ end
143
+
144
+ def test_label
145
+ lexer = Wizard::TreePatternLexer.new('(%a:A)')
146
+ parser = Wizard::TreePatternParser.new(lexer, @wizard, @pattern_adaptor)
147
+ tree = parser.pattern
148
+
149
+ assert_instance_of(Wizard::TreePattern, tree)
150
+ assert_equal('a', tree.label)
151
+ end
152
+
153
+ def test_error_1
154
+ lexer = Wizard::TreePatternLexer.new(')')
155
+ parser = Wizard::TreePatternParser.new(lexer, @wizard, @adaptor)
156
+ tree = parser.pattern
157
+
158
+ assert_nil tree
159
+ end
160
+
161
+ def test_error_2
162
+ lexer = Wizard::TreePatternLexer.new('()')
163
+ parser = Wizard::TreePatternParser.new(lexer, @wizard, @adaptor)
164
+ tree = parser.pattern
165
+
166
+ assert_nil tree
167
+ end
168
+
169
+ def test_error_3
170
+ lexer = Wizard::TreePatternLexer.new('(A ])')
171
+ parser = Wizard::TreePatternParser.new(lexer, @wizard, @adaptor)
172
+ tree = parser.pattern
173
+
174
+ assert_nil tree
175
+ end
176
+
177
+ end
178
+
179
+
180
+ class TestTreeWizard < Test::Unit::TestCase
181
+
182
+ def setup
183
+ @adaptor = ANTLR3::CommonTreeAdaptor.new
184
+ @tokens = Array.new(5, '') + %w(A B C D E ID VAR)
185
+ @wizard = Wizard.new(@adaptor, @tokens)
186
+ end
187
+
188
+ # vvvvvvvv tests vvvvvvvvv
189
+ def test_init
190
+ wiz = Wizard.new(@adaptor, %w(a b))
191
+
192
+ assert_equal(wiz.adaptor, @adaptor)
193
+ assert_equal(wiz.token_name_to_type_map, { 'a' => 0, 'b' => 1 })
194
+ end
195
+
196
+ def test_token_type
197
+ wiz = Wizard.new(@adaptor, @tokens)
198
+ assert_equal(wiz.token_type('A'), 5)
199
+ assert_equal(wiz.token_type('VAR'), 11)
200
+ assert_equal(wiz.token_type('invalid'), INVALID_TOKEN_TYPE)
201
+ end
202
+
203
+ def test_single_node
204
+ wiz = Wizard.new(@adaptor, @tokens)
205
+ t = wiz.create("ID")
206
+
207
+ assert_equal(t.to_string_tree, 'ID')
208
+ end
209
+
210
+ def test_single_node_with_arg
211
+ wiz = Wizard.new(@adaptor, @tokens)
212
+ t = wiz.create("ID[foo]")
213
+
214
+ assert_equal(t.to_string_tree, 'foo')
215
+ end
216
+
217
+ def test_single_node_tree
218
+ wiz = Wizard.new(@adaptor, @tokens)
219
+ t = wiz.create("(A)")
220
+
221
+ assert_equal(t.to_string_tree, 'A')
222
+ end
223
+
224
+ def test_single_level_tree
225
+ wiz = Wizard.new(@adaptor, @tokens)
226
+ t = wiz.create("(A B C D)")
227
+
228
+ assert_equal(t.to_string_tree, '(A B C D)')
229
+ end
230
+
231
+ def test_list_tree
232
+ wiz = Wizard.new(@adaptor, @tokens)
233
+ t = wiz.create("(nil A B C)")
234
+
235
+ assert_equal(t.to_string_tree, 'A B C')
236
+ end
237
+
238
+ def test_invalid_list_tree
239
+ wiz = Wizard.new(@adaptor, @tokens)
240
+ t = wiz.create("A B C")
241
+
242
+ assert_nil t
243
+ end
244
+
245
+ def test_double_level_tree
246
+ wiz = Wizard.new(@adaptor, @tokens)
247
+ t = wiz.create("(A (B C) (B D) E)")
248
+
249
+ assert_equal(t.to_string_tree, "(A (B C) (B D) E)")
250
+ end
251
+
252
+ SIMPLIFY_MAP = lambda do |imap|
253
+ Hash[
254
+ imap.map { |type, nodes| [type, nodes.map { |n| n.to_s }] }
255
+ ]
256
+ end
257
+
258
+ def test_single_node_index
259
+ wiz = Wizard.new(@adaptor, @tokens)
260
+ tree = wiz.create("ID")
261
+ index_map = SIMPLIFY_MAP[wiz.index(tree)]
262
+
263
+ assert_equal(index_map, { 10 => %w(ID) })
264
+ end
265
+
266
+
267
+ def test_no_repeats_index
268
+ wiz = Wizard.new(@adaptor, @tokens)
269
+ tree = wiz.create("(A B C D)")
270
+ index_map = SIMPLIFY_MAP[wiz.index(tree)]
271
+
272
+ assert_equal(index_map,
273
+ 8 => %w(D), 6 => %w(B),
274
+ 7 => %w(C), 5 => %w(A)
275
+ )
276
+ end
277
+
278
+ def test_repeats_index
279
+ wiz = Wizard.new(@adaptor, @tokens)
280
+ tree = wiz.create("(A B (A C B) B D D)")
281
+ index_map = SIMPLIFY_MAP[wiz.index(tree)]
282
+
283
+ assert_equal(index_map,
284
+ 8 => %w(D D), 6 => %w(B B B),
285
+ 7 => %w(C), 5 => %w(A A)
286
+ )
287
+ end
288
+
289
+
290
+ def test_no_repeats_visit
291
+ tree = @wizard.create("(A B C D)")
292
+
293
+ elements = []
294
+ @wizard.visit(tree, @wizard.token_type('B')) do |node, parent, child_index, labels|
295
+ elements << node.to_s
296
+ end
297
+
298
+ assert_equal(%w(B), elements)
299
+ end
300
+
301
+
302
+ def test_no_repeats_visit2
303
+ tree = @wizard.create("(A B (A C B) B D D)")
304
+
305
+ elements = []
306
+ @wizard.visit(tree, @wizard.token_type('C')) do |node, parent, child_index, labels|
307
+ elements << node.to_s
308
+ end
309
+
310
+ assert_equal(%w(C), elements)
311
+ end
312
+
313
+
314
+ def test_repeats_visit
315
+ tree = @wizard.create("(A B (A C B) B D D)")
316
+
317
+ elements = []
318
+ @wizard.visit(tree, @wizard.token_type('B')) do |node, parent, child_index, labels|
319
+ elements << node.to_s
320
+ end
321
+
322
+ assert_equal(%w(B B B), elements)
323
+ end
324
+
325
+
326
+ def test_repeats_visit2
327
+ tree = @wizard.create("(A B (A C B) B D D)")
328
+
329
+ elements = []
330
+ @wizard.visit(tree, @wizard.token_type('A')) do |node, parent, child_index, labels|
331
+ elements << node.to_s
332
+ end
333
+
334
+ assert_equal(%w(A A), elements)
335
+ end
336
+
337
+ def context(node, parent, index)
338
+ '%s@%s[%d]' % [node.to_s, (parent || 'nil').to_s, index]
339
+ end
340
+
341
+ def test_repeats_visit_with_context
342
+ tree = @wizard.create("(A B (A C B) B D D)")
343
+
344
+ elements = []
345
+ @wizard.visit(tree, @wizard.token_type('B')) do |node, parent, child_index, labels|
346
+ elements << context(node, parent, child_index)
347
+ end
348
+
349
+ assert_equal(['B@A[0]', 'B@A[1]', 'B@A[2]'], elements)
350
+ end
351
+
352
+
353
+ def test_repeats_visit_with_null_parent_and_context
354
+ tree = @wizard.create("(A B (A C B) B D D)")
355
+
356
+ elements = []
357
+ @wizard.visit(tree, @wizard.token_type('A')) do |node, parent, child_index, labels|
358
+ elements << context(node, parent, child_index)
359
+ end
360
+
361
+ assert_equal(['A@nil[0]', 'A@A[1]'], elements)
362
+ end
363
+
364
+
365
+ def test_visit_pattern
366
+ tree = @wizard.create("(A B C (A B) D)")
367
+
368
+ elements = []
369
+ @wizard.visit(tree, '(A B)') do |node, parent, child_index, labels|
370
+ elements << node.to_s
371
+ end
372
+
373
+ assert_equal(%w(A), elements)
374
+ end
375
+
376
+
377
+ def test_visit_pattern_multiple
378
+ tree = @wizard.create("(A B C (A B) (D (A B)))")
379
+
380
+ elements = []
381
+ @wizard.visit(tree, '(A B)') do |node, parent, child_index, labels|
382
+ elements << context(node, parent, child_index)
383
+ end
384
+
385
+ assert_equal( %w(A@A[2] A@D[0]) , elements )
386
+ end
387
+
388
+ def labeled_context(node, parent, index, labels, *names)
389
+ suffix = names.map { |n| labels[n].to_s }.join('&')
390
+ '%s@%s[%d]%s' % [node.to_s, (parent || 'nil').to_s, index, suffix]
391
+ end
392
+
393
+ def test_visit_pattern_multiple_with_labels
394
+ tree = @wizard.create("(A B C (A[foo] B[bar]) (D (A[big] B[dog])))")
395
+
396
+ elements = []
397
+ @wizard.visit(tree, '(%a:A %b:B)') do |node, parent, child_index, labels|
398
+ elements << labeled_context(node, parent, child_index, labels, 'a', 'b')
399
+ end
400
+
401
+ assert_equal( ['foo@A[2]foo&bar', 'big@D[0]big&dog'] , elements )
402
+ end
403
+
404
+
405
+ def test_parse
406
+ tree = @wizard.create("(A B C)")
407
+ assert @wizard.parse(tree, "(A B C)")
408
+ end
409
+
410
+ def test_parse_single_node
411
+ tree = @wizard.create('A')
412
+ assert @wizard.parse(tree, 'A')
413
+ end
414
+
415
+ def test_parse_single_node_fails
416
+ tree = @wizard.create('A')
417
+ assert( !(@wizard.parse(tree, 'B')) )
418
+ end
419
+
420
+
421
+ def test_parse_flat_tree
422
+ tree = @wizard.create('(nil A B C)')
423
+ assert @wizard.parse(tree, '(nil A B C)')
424
+ end
425
+
426
+ def test_parse_flat_tree_fails
427
+ tree = @wizard.create('(nil A B C)')
428
+ assert( !(@wizard.parse(tree, '(nil A B)')) )
429
+ end
430
+
431
+ def test_parse_flat_tree_fails2
432
+ tree = @wizard.create('(nil A B C)')
433
+ assert( !(@wizard.parse(tree, '(nil A B A)')) )
434
+ end
435
+
436
+ def test_wildcard
437
+ tree = @wizard.create('(A B C)')
438
+ assert @wizard.parse(tree, '(A . .)')
439
+ end
440
+
441
+ def test_parse_with_text
442
+ tree = @wizard.create('(A B[foo] C[bar])')
443
+ assert @wizard.parse(tree, '(A B[foo] C)')
444
+ end
445
+
446
+ def test_parse_with_text_fails
447
+ tree = @wizard.create('(A B C)')
448
+ assert( !(@wizard.parse(tree, '(A[foo] B C)')) )
449
+ end
450
+
451
+ def test_parse_labels
452
+ tree = @wizard.create('(A B C)')
453
+ labels = {}
454
+ assert @wizard.parse(tree, '(%a:A %b:B %c:C)', labels)
455
+ assert_equal('A', labels['a'].to_s)
456
+ assert_equal('B', labels['b'].to_s)
457
+ assert_equal('C', labels['c'].to_s)
458
+ end
459
+
460
+ def test_parse_with_wildcard_labels
461
+ tree = @wizard.create('(A B C)')
462
+ labels = {}
463
+ assert @wizard.parse(tree, '(A %b:. %c:.)', labels)
464
+ assert_equal('B', labels['b'].to_s)
465
+ assert_equal('C', labels['c'].to_s)
466
+ end
467
+
468
+
469
+ def test_parse_labels_and_test_text
470
+ tree = @wizard.create('(A B[foo] C)')
471
+ labels = {}
472
+ assert @wizard.parse(tree, '(%a:A %b:B[foo] %c:C)', labels)
473
+ assert_equal('A', labels['a'].to_s)
474
+ assert_equal('foo', labels['b'].to_s)
475
+ assert_equal('C', labels['c'].to_s)
476
+ end
477
+
478
+ def test_parse_labels_in_nested_tree
479
+ tree = @wizard.create('(A (B C) (D E))')
480
+ labels = {}
481
+ assert @wizard.parse(tree, '(%a:A (%b:B %c:C) (%d:D %e:E))', labels)
482
+ assert_equal('A', labels['a'].to_s)
483
+ assert_equal('B', labels['b'].to_s)
484
+ assert_equal('C', labels['c'].to_s)
485
+ assert_equal('D', labels['d'].to_s)
486
+ assert_equal('E', labels['e'].to_s)
487
+ end
488
+
489
+
490
+ def test_equals
491
+ tree1 = @wizard.create("(A B C)")
492
+ tree2 = @wizard.create("(A B C)")
493
+ assert @wizard.equals(tree1, tree2)
494
+ end
495
+
496
+
497
+ def test_equals_with_text
498
+ tree1 = @wizard.create("(A B[foo] C)")
499
+ tree2 = @wizard.create("(A B[foo] C)")
500
+ assert @wizard.equals(tree1, tree2)
501
+ end
502
+
503
+
504
+ def test_equals_with_mismatched_text
505
+ tree1 = @wizard.create("(A B[foo] C)")
506
+ tree2 = @wizard.create("(A B C)")
507
+ assert( !(@wizard.equals(tree1, tree2)) )
508
+ end
509
+
510
+
511
+ def test_equals_with_mismatched_list
512
+ tree1 = @wizard.create("(A B C)")
513
+ tree2 = @wizard.create("(A B A)")
514
+ assert( !(@wizard.equals(tree1, tree2)) )
515
+ end
516
+
517
+ def test_equals_with_mismatched_list_length
518
+ tree1 = @wizard.create("(A B C)")
519
+ tree2 = @wizard.create("(A B)")
520
+ assert( !(@wizard.equals(tree1, tree2)) )
521
+ end
522
+
523
+ def test_find_pattern
524
+ tree = @wizard.create("(A B C (A[foo] B[bar]) (D (A[big] B[dog])))")
525
+ subtrees = @wizard.find(tree, "(A B)").map { |t| t.to_s }
526
+ assert_equal(%w(foo big), subtrees)
527
+ end
528
+
529
+ def test_find_token_type
530
+ tree = @wizard.create("(A B C (A[foo] B[bar]) (D (A[big] B[dog])))")
531
+ subtrees = @wizard.find(tree, @wizard.token_type('A')).map { |t| t.to_s }
532
+ assert_equal(%w(A foo big), subtrees)
533
+ end
534
+ end
535
+