Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 90 lines (79 sloc) 1.835 kb
c6d4b4b @mjackson Introduced compatibility with Ruby 1.9.2 rc2 (Thanks Simon Haydon). In
authored
1 require File.expand_path('../helper', __FILE__)
59dd128 @mjackson Fixed a bug with using super inside grammars.
authored
2
3f2ac45 @mjackson Added support for super keyword to PEG's
authored
3 class SuperTest < Test::Unit::TestCase
4 def test_terminal?
5 rule = Super.new
6 assert_equal(false, rule.terminal?)
7 end
8
456adbe @mjackson Introduced more lightweight parsing model
authored
9 def test_exec
1e83130 Convert to classes
Evan Phoenix authored
10 ghi = Rule.for('ghi')
3f2ac45 @mjackson Added support for super keyword to PEG's
authored
11 grammar1 = Grammar.new {
456adbe @mjackson Introduced more lightweight parsing model
authored
12 rule :a, 'abc'
3f2ac45 @mjackson Added support for super keyword to PEG's
authored
13 }
14 grammar2 = Grammar.new {
15 include grammar1
456adbe @mjackson Introduced more lightweight parsing model
authored
16 rule :a, any(ghi, sup)
3f2ac45 @mjackson Added support for super keyword to PEG's
authored
17 }
456adbe @mjackson Introduced more lightweight parsing model
authored
18 rule_2a = grammar2.rule(:a)
7f32be2 @mjackson Eliminate Label, Predicate, and List classes.
authored
19 rule_2a_als = rule_2a.rules[0]
c836f31 @mjackson Fixed Proxy and Label rule wrapping
authored
20 rule_2a_sup = rule_2a.rules[1]
3f2ac45 @mjackson Added support for super keyword to PEG's
authored
21
456adbe @mjackson Introduced more lightweight parsing model
authored
22 events = rule_2a.exec(Input.new('abc'))
c836f31 @mjackson Fixed Proxy and Label rule wrapping
authored
23 assert_equal([
e924053 @mjackson Eliminate Rule id's
authored
24 rule_2a,
7f32be2 @mjackson Eliminate Label, Predicate, and List classes.
authored
25 rule_2a_sup, CLOSE, 3,
c836f31 @mjackson Fixed Proxy and Label rule wrapping
authored
26 CLOSE, 3
27 ], events)
3f2ac45 @mjackson Added support for super keyword to PEG's
authored
28
456adbe @mjackson Introduced more lightweight parsing model
authored
29 events = rule_2a.exec(Input.new('ghi'))
7f32be2 @mjackson Eliminate Label, Predicate, and List classes.
authored
30 assert_equal([
31 rule_2a,
32 rule_2a_als, CLOSE, 3,
33 CLOSE, 3
34 ], events)
3f2ac45 @mjackson Added support for super keyword to PEG's
authored
35 end
36
456adbe @mjackson Introduced more lightweight parsing model
authored
37 def test_exec_miss
38 grammar1 = Grammar.new {
39 rule :a, 'abc'
40 }
41 grammar2 = Grammar.new {
42 include grammar1
43 rule :a, any('def', sup)
44 }
45 rule_2a = grammar2.rule(:a)
46 events = rule_2a.exec(Input.new('ghi'))
47 assert_equal([], events)
3f2ac45 @mjackson Added support for super keyword to PEG's
authored
48 end
49
456adbe @mjackson Introduced more lightweight parsing model
authored
50 def test_exec_aliased
03390d6 @mjackson Added tests for nested configurations of Alias and Super rules
authored
51 grammar1 = Grammar.new {
456adbe @mjackson Introduced more lightweight parsing model
authored
52 rule :a, 'abc'
53 rule :b, 'def'
03390d6 @mjackson Added tests for nested configurations of Alias and Super rules
authored
54 }
55 grammar2 = Grammar.new {
56 include grammar1
57 rule :a, any(sup, :b)
58 rule :b, sup
59 }
c836f31 @mjackson Fixed Proxy and Label rule wrapping
authored
60 rule_2a = grammar2.rule(:a)
61 rule_2a_sup = rule_2a.rules[0]
62 rule_2a_als = rule_2a.rules[1]
03390d6 @mjackson Added tests for nested configurations of Alias and Super rules
authored
63
456adbe @mjackson Introduced more lightweight parsing model
authored
64 events = rule_2a.exec(Input.new('abc'))
c836f31 @mjackson Fixed Proxy and Label rule wrapping
authored
65 assert_equal([
e924053 @mjackson Eliminate Rule id's
authored
66 rule_2a,
7f32be2 @mjackson Eliminate Label, Predicate, and List classes.
authored
67 rule_2a_sup, CLOSE, 3,
c836f31 @mjackson Fixed Proxy and Label rule wrapping
authored
68 CLOSE, 3
69 ], events)
59dd128 @mjackson Fixed a bug with using super inside grammars.
authored
70
456adbe @mjackson Introduced more lightweight parsing model
authored
71 events = rule_2a.exec(Input.new('def'))
c836f31 @mjackson Fixed Proxy and Label rule wrapping
authored
72 assert_equal([
e924053 @mjackson Eliminate Rule id's
authored
73 rule_2a,
7f32be2 @mjackson Eliminate Label, Predicate, and List classes.
authored
74 rule_2a_als, CLOSE, 3,
c836f31 @mjackson Fixed Proxy and Label rule wrapping
authored
75 CLOSE, 3
76 ], events)
59dd128 @mjackson Fixed a bug with using super inside grammars.
authored
77 end
78
3f2ac45 @mjackson Added support for super keyword to PEG's
authored
79 def test_to_s
80 rule = Super.new
81 assert_equal('super', rule.to_s)
82 end
7f32be2 @mjackson Eliminate Label, Predicate, and List classes.
authored
83
84 def test_to_s_with_label
85 rule = Super.new
86 rule.label = 'a_label'
87 assert_equal('a_label:super', rule.to_s)
88 end
3f2ac45 @mjackson Added support for super keyword to PEG's
authored
89 end
Something went wrong with that request. Please try again.