pdoc 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.
- data/README.markdown +34 -0
- data/Rakefile +46 -0
- data/bin/pdoc +58 -0
- data/lib/pdoc.rb +32 -0
- data/lib/pdoc/error.rb +4 -0
- data/lib/pdoc/generators.rb +6 -0
- data/lib/pdoc/generators/abstract_generator.rb +16 -0
- data/lib/pdoc/generators/html.rb +8 -0
- data/lib/pdoc/generators/html/helpers.rb +256 -0
- data/lib/pdoc/generators/html/page.rb +71 -0
- data/lib/pdoc/generators/html/syntax_highlighter.rb +41 -0
- data/lib/pdoc/generators/html/template.rb +37 -0
- data/lib/pdoc/generators/html/website.rb +194 -0
- data/lib/pdoc/generators/json.rb +15 -0
- data/lib/pdoc/generators/pythonesque.rb +105 -0
- data/lib/pdoc/models.rb +47 -0
- data/lib/pdoc/models/argument.rb +37 -0
- data/lib/pdoc/models/base.rb +107 -0
- data/lib/pdoc/models/callable.rb +19 -0
- data/lib/pdoc/models/class.rb +28 -0
- data/lib/pdoc/models/class_method.rb +18 -0
- data/lib/pdoc/models/class_property.rb +9 -0
- data/lib/pdoc/models/constant.rb +9 -0
- data/lib/pdoc/models/constructor.rb +14 -0
- data/lib/pdoc/models/container.rb +114 -0
- data/lib/pdoc/models/entity.rb +54 -0
- data/lib/pdoc/models/instance_method.rb +18 -0
- data/lib/pdoc/models/instance_property.rb +9 -0
- data/lib/pdoc/models/mixin.rb +10 -0
- data/lib/pdoc/models/namespace.rb +10 -0
- data/lib/pdoc/models/root.rb +27 -0
- data/lib/pdoc/models/section.rb +19 -0
- data/lib/pdoc/models/signature.rb +27 -0
- data/lib/pdoc/models/utility.rb +11 -0
- data/lib/pdoc/parser.rb +109 -0
- data/lib/pdoc/parser/argument_description_nodes.rb +21 -0
- data/lib/pdoc/parser/basic_nodes.rb +31 -0
- data/lib/pdoc/parser/description_nodes.rb +42 -0
- data/lib/pdoc/parser/documentation_nodes.rb +483 -0
- data/lib/pdoc/parser/ebnf_arguments_nodes.rb +58 -0
- data/lib/pdoc/parser/ebnf_expression_nodes.rb +227 -0
- data/lib/pdoc/parser/fragment.rb +55 -0
- data/lib/pdoc/parser/section_content_nodes.rb +19 -0
- data/lib/pdoc/parser/tags_nodes.rb +14 -0
- data/lib/pdoc/parser/treetop_files/argument_description.treetop +31 -0
- data/lib/pdoc/parser/treetop_files/basic.treetop +41 -0
- data/lib/pdoc/parser/treetop_files/description.treetop +7 -0
- data/lib/pdoc/parser/treetop_files/documentation.treetop +75 -0
- data/lib/pdoc/parser/treetop_files/ebnf_arguments.treetop +33 -0
- data/lib/pdoc/parser/treetop_files/ebnf_expression.treetop +70 -0
- data/lib/pdoc/parser/treetop_files/ebnf_javascript.treetop +54 -0
- data/lib/pdoc/parser/treetop_files/events.treetop +17 -0
- data/lib/pdoc/parser/treetop_files/section_content.treetop +8 -0
- data/lib/pdoc/parser/treetop_files/tags.treetop +31 -0
- data/lib/pdoc/runner.rb +110 -0
- data/lib/pdoc/treemaker.rb +94 -0
- data/pdoc.gemspec +31 -0
- data/templates/html/assets/images/pdoc/alias.png +0 -0
- data/templates/html/assets/images/pdoc/class.png +0 -0
- data/templates/html/assets/images/pdoc/class_deprecated.png +0 -0
- data/templates/html/assets/images/pdoc/class_method.png +0 -0
- data/templates/html/assets/images/pdoc/class_property.png +0 -0
- data/templates/html/assets/images/pdoc/constant.png +0 -0
- data/templates/html/assets/images/pdoc/constructor.png +0 -0
- data/templates/html/assets/images/pdoc/deprecated.png +0 -0
- data/templates/html/assets/images/pdoc/description.png +0 -0
- data/templates/html/assets/images/pdoc/information.png +0 -0
- data/templates/html/assets/images/pdoc/instance_method.png +0 -0
- data/templates/html/assets/images/pdoc/instance_property.png +0 -0
- data/templates/html/assets/images/pdoc/method.png +0 -0
- data/templates/html/assets/images/pdoc/method_deprecated.png +0 -0
- data/templates/html/assets/images/pdoc/mixin.png +0 -0
- data/templates/html/assets/images/pdoc/namespace.png +0 -0
- data/templates/html/assets/images/pdoc/property.png +0 -0
- data/templates/html/assets/images/pdoc/related_to.png +0 -0
- data/templates/html/assets/images/pdoc/search-background.png +0 -0
- data/templates/html/assets/images/pdoc/section-background.png +0 -0
- data/templates/html/assets/images/pdoc/section.png +0 -0
- data/templates/html/assets/images/pdoc/selected-section-background.png +0 -0
- data/templates/html/assets/images/pdoc/subclass.png +0 -0
- data/templates/html/assets/images/pdoc/superclass.png +0 -0
- data/templates/html/assets/images/pdoc/utility.png +0 -0
- data/templates/html/assets/javascripts/pdoc/application.js +478 -0
- data/templates/html/assets/javascripts/pdoc/prototype.js +4874 -0
- data/templates/html/assets/javascripts/pdoc/tabs.js +506 -0
- data/templates/html/assets/stylesheets/pdoc/api.css +677 -0
- data/templates/html/assets/stylesheets/pdoc/pygments.css +62 -0
- data/templates/html/helpers.rb +35 -0
- data/templates/html/index.erb +18 -0
- data/templates/html/item_index.js.erb +6 -0
- data/templates/html/layout.erb +67 -0
- data/templates/html/leaf.erb +22 -0
- data/templates/html/node.erb +30 -0
- data/templates/html/partials/class_relationships.erb +19 -0
- data/templates/html/partials/classes.erb +7 -0
- data/templates/html/partials/constructor.erb +5 -0
- data/templates/html/partials/description.erb +5 -0
- data/templates/html/partials/link_list.erb +1 -0
- data/templates/html/partials/method_signatures.erb +14 -0
- data/templates/html/partials/methodized_note.erb +9 -0
- data/templates/html/partials/mixins.erb +7 -0
- data/templates/html/partials/namespaces.erb +7 -0
- data/templates/html/partials/related_utilities.erb +5 -0
- data/templates/html/partials/relationships.erb +11 -0
- data/templates/html/partials/short_description_list.erb +7 -0
- data/templates/html/partials/title.erb +22 -0
- data/templates/html/section.erb +18 -0
- data/test/unit/parser/argument_description_test.rb +40 -0
- data/test/unit/parser/basic_test.rb +55 -0
- data/test/unit/parser/description_test.rb +34 -0
- data/test/unit/parser/documentation_test.rb +520 -0
- data/test/unit/parser/ebnf_arguments_test.rb +81 -0
- data/test/unit/parser/ebnf_expression_test.rb +382 -0
- data/test/unit/parser/ebnf_javascript_test.rb +37 -0
- data/test/unit/parser/events_test.rb +27 -0
- data/test/unit/parser/section_content_test.rb +44 -0
- data/test/unit/parser/tags_test.rb +39 -0
- data/test/unit/parser/test_fragment.rb +80 -0
- data/test/unit/parser_test_helper.rb +62 -0
- data/test/unit/runner/basic_test.rb +14 -0
- data/test/unit/templates/html_helpers_test.rb +25 -0
- metadata +222 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "parser_test_helper"))
|
|
2
|
+
|
|
3
|
+
class ArgumentsTest < Test::Unit::TestCase
|
|
4
|
+
include PDocTestHelper
|
|
5
|
+
include EbnfArguments
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
@parser = EbnfArgumentsParser.new
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_no_arguments
|
|
12
|
+
assert_parsed " "
|
|
13
|
+
assert_parsed ""
|
|
14
|
+
assert_equal [], parse(" ").to_a.map(&:name)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_one_required_argument
|
|
18
|
+
assert_parsed "content"
|
|
19
|
+
assert_parsed "{ position: '(top|bottom|before|after)' }"
|
|
20
|
+
assert_equal "content", parse("content").to_a.first.name
|
|
21
|
+
assert_equal nil, parse("content").to_a.first.default_value
|
|
22
|
+
assert !parse("content").to_a.first.optional?
|
|
23
|
+
assert_equal "elements...", parse("elements...").to_a.first.name
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_multiple_required_arguments
|
|
27
|
+
assert_parsed "foo,bar"
|
|
28
|
+
assert_parsed "foo , bar"
|
|
29
|
+
assert_parsed "foo , bar"
|
|
30
|
+
assert_equal ["foo", "bar"], parse("foo,bar").to_a.map(&:name)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_one_optional_argument
|
|
34
|
+
assert_parsed "[content]"
|
|
35
|
+
assert_parsed "[ content ]"
|
|
36
|
+
assert_parsed "[{ position: '(top|bottom|before|after)' }]"
|
|
37
|
+
assert_equal "content", parse("[content]").to_a.first.name
|
|
38
|
+
assert_equal OptionalArgument, parse("[content]").to_a.first.class
|
|
39
|
+
assert_equal nil, parse("[content]").to_a.first.default_value
|
|
40
|
+
assert parse("[content]").to_a.first.optional?
|
|
41
|
+
assert_equal "elements...", parse("[elements...]").to_a.first.name
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_default_value
|
|
45
|
+
assert_parsed "[content=foobar]"
|
|
46
|
+
assert_parsed "[ content=foobar ]"
|
|
47
|
+
assert_equal "content", parse("[content=foo]").to_a.first.name
|
|
48
|
+
assert_equal "foo", parse("[content=foo]").to_a.first.default_value
|
|
49
|
+
assert_equal "foo", parse("[content = foo]").to_a.first.default_value
|
|
50
|
+
assert parse("[content]").to_a.first.optional?
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_multiple_optional_arguments
|
|
54
|
+
assert_parsed "[foo][,bar]"
|
|
55
|
+
assert_parsed "[ foo ] [ , bar ]"
|
|
56
|
+
assert_equal ["foo", "bar"], parse("[foo][,bar]").to_a.map(&:name)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_multiple_mixed_arguments
|
|
60
|
+
assert_parsed "hello[,foo][,bar=43]"
|
|
61
|
+
assert_parsed "hello [ , foo ] [ , bar=43 ]"
|
|
62
|
+
assert_parsed "hello,world[,foo][,bar=43]"
|
|
63
|
+
assert_parsed "hello , world [ , foo ] [ , bar=43 ]"
|
|
64
|
+
assert_parsed "hello...[, world = foo]"
|
|
65
|
+
assert_equal ["foo", "bar"], parse("[foo],bar").to_a.map(&:name)
|
|
66
|
+
assert_equal "content", parse("hello[,content]").to_a.last.name
|
|
67
|
+
assert_equal "content", parse("hello[,content=foo]").to_a.last.name
|
|
68
|
+
assert_equal "foo", parse("hello[,content=foo]").to_a.last.default_value
|
|
69
|
+
assert parse("hello[,content=foo]").to_a.last.optional?
|
|
70
|
+
assert !parse("hello[,content=foo]").to_a.first.optional?
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_nested_optional_arguments
|
|
74
|
+
assert_parsed "hello[,foo[,bar]]"
|
|
75
|
+
assert_parsed "hello [ , foo = 3 [ , bar = 43 ]]"
|
|
76
|
+
assert_parsed "hello[,foo[,bar=43][,baz=26]]"
|
|
77
|
+
assert_parsed "[length = 30[, suffix = '...']]"
|
|
78
|
+
assert_equal ["foo", "bar"], parse("[foo[,bar]]").to_a.map(&:name)
|
|
79
|
+
assert_equal ["hello", "foo", "bar", "baz"], parse("hello[,foo[,bar=43][,baz=26]]").to_a.map(&:name)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "parser_test_helper"))
|
|
2
|
+
|
|
3
|
+
class EbnfExpressionTest < Test::Unit::TestCase
|
|
4
|
+
include PDocTestHelper
|
|
5
|
+
include EbnfExpression
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
@parser = EbnfExpressionParser.new
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_inspect
|
|
12
|
+
ebnf = "Ajax.Responders.responders -> Array"
|
|
13
|
+
assert_equal "#<EbnfExpression::KlassProperty @input=\"#{ebnf}\">", parse(ebnf).inspect
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_instance_property
|
|
17
|
+
ebnf = "Ajax.Response#responseJSON -> Array | Object | null"
|
|
18
|
+
assert_parsed ebnf
|
|
19
|
+
assert_equal InstanceProperty, parse(ebnf).class
|
|
20
|
+
assert_equal "Ajax.Response", parse(ebnf).namespace
|
|
21
|
+
assert_equal "responseJSON", parse(ebnf).name
|
|
22
|
+
assert_equal "Ajax.Response#responseJSON", parse(ebnf).full_name
|
|
23
|
+
assert_equal "Response", parse(ebnf).klass_name
|
|
24
|
+
assert_equal "Array | Object | null", parse(ebnf).returns
|
|
25
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
26
|
+
|
|
27
|
+
ebnf = "a123#b456 -> Array | Object | null"
|
|
28
|
+
assert_parsed ebnf
|
|
29
|
+
assert_equal InstanceProperty, parse(ebnf).class
|
|
30
|
+
assert_equal "a123", parse(ebnf).namespace
|
|
31
|
+
assert_equal "b456", parse(ebnf).name
|
|
32
|
+
assert_equal "a123#b456", parse(ebnf).full_name
|
|
33
|
+
assert_equal "a123", parse(ebnf).klass_name
|
|
34
|
+
assert_equal "Array | Object | null", parse(ebnf).returns
|
|
35
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_klass_property
|
|
39
|
+
ebnf = "Ajax.Responders.responders -> Array"
|
|
40
|
+
assert_parsed ebnf
|
|
41
|
+
assert_equal KlassProperty, parse(ebnf).class
|
|
42
|
+
assert_equal "Ajax.Responders", parse(ebnf).namespace
|
|
43
|
+
assert_equal "responders", parse(ebnf).name
|
|
44
|
+
assert_equal "Ajax.Responders.responders", parse(ebnf).full_name
|
|
45
|
+
assert_equal "Responders", parse(ebnf).klass_name
|
|
46
|
+
assert_equal "Array", parse(ebnf).returns
|
|
47
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
48
|
+
|
|
49
|
+
ebnf = "document.viewport.foo -> Bar"
|
|
50
|
+
assert_parsed ebnf
|
|
51
|
+
assert_equal KlassProperty, parse(ebnf).class
|
|
52
|
+
assert_equal "document.viewport", parse(ebnf).namespace
|
|
53
|
+
assert_equal "foo", parse(ebnf).name
|
|
54
|
+
assert_equal "document.viewport.foo", parse(ebnf).full_name
|
|
55
|
+
assert_equal "viewport", parse(ebnf).klass_name
|
|
56
|
+
assert_equal "Bar", parse(ebnf).returns
|
|
57
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def test_utility
|
|
61
|
+
ebnf = "$(element) -> Element | Array"
|
|
62
|
+
assert_parsed ebnf
|
|
63
|
+
assert_parsed "$$() -> Array"
|
|
64
|
+
assert_parsed "$w() -> Array"
|
|
65
|
+
assert_parsed "$A() -> Array"
|
|
66
|
+
assert_equal Utility, parse(ebnf).class
|
|
67
|
+
assert_equal "", parse(ebnf).namespace
|
|
68
|
+
assert_equal "$", parse(ebnf).name
|
|
69
|
+
assert_equal "$", parse(ebnf).full_name
|
|
70
|
+
assert_equal nil, parse(ebnf).klass_name
|
|
71
|
+
assert_equal %w[element], parse(ebnf).arguments.map(&:name)
|
|
72
|
+
assert_equal "Element | Array", parse(ebnf).returns
|
|
73
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_klass_method
|
|
77
|
+
ebnf = "Element.update(@element[,content]) -> Element"
|
|
78
|
+
assert_parsed ebnf
|
|
79
|
+
assert_equal KlassMethod, parse(ebnf).class
|
|
80
|
+
assert_equal "Element", parse(ebnf).namespace
|
|
81
|
+
assert_equal "update", parse(ebnf).name
|
|
82
|
+
assert_equal "Element.update", parse(ebnf).full_name
|
|
83
|
+
assert_equal "Element", parse(ebnf).klass_name
|
|
84
|
+
assert_equal %w[element content], parse(ebnf).arguments.map(&:name)
|
|
85
|
+
assert_equal "Element", parse(ebnf).returns
|
|
86
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
87
|
+
|
|
88
|
+
ebnf = "document.viewport.getWidth() -> Number"
|
|
89
|
+
assert_parsed ebnf
|
|
90
|
+
assert_equal KlassMethod, parse(ebnf).class
|
|
91
|
+
assert_equal "document.viewport", parse(ebnf).namespace
|
|
92
|
+
assert_equal "getWidth", parse(ebnf).name
|
|
93
|
+
assert_equal "document.viewport.getWidth", parse(ebnf).full_name
|
|
94
|
+
assert_equal "viewport", parse(ebnf).klass_name
|
|
95
|
+
assert_equal [], parse(ebnf).arguments
|
|
96
|
+
assert_equal "Number", parse(ebnf).returns
|
|
97
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def test_instance_method
|
|
101
|
+
ebnf = "Element#update([content]) -> Element"
|
|
102
|
+
assert_parsed ebnf
|
|
103
|
+
assert_equal InstanceMethod, parse(ebnf).class
|
|
104
|
+
assert_equal "Element", parse(ebnf).namespace
|
|
105
|
+
assert_equal "update", parse(ebnf).name
|
|
106
|
+
assert_equal "Element#update", parse(ebnf).full_name
|
|
107
|
+
assert_equal "Element", parse(ebnf).klass_name
|
|
108
|
+
assert_equal %w[content], parse(ebnf).arguments.map(&:name)
|
|
109
|
+
assert_equal "Element", parse(ebnf).returns
|
|
110
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def test_constructors
|
|
114
|
+
ebnf = "new Element(tagName[,attributes])"
|
|
115
|
+
assert_parsed ebnf
|
|
116
|
+
assert_equal Constructor, parse(ebnf).class
|
|
117
|
+
assert_equal "Element", parse(ebnf).namespace
|
|
118
|
+
assert_equal "new", parse(ebnf).name
|
|
119
|
+
assert_equal "new Element", parse(ebnf).full_name
|
|
120
|
+
assert_equal "Element", parse(ebnf).klass_name
|
|
121
|
+
assert_equal %w[tagName attributes], parse(ebnf).arguments.map(&:name)
|
|
122
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
123
|
+
|
|
124
|
+
ebnf = "new Ajax.Request(url[,options])"
|
|
125
|
+
assert_parsed ebnf
|
|
126
|
+
assert_equal Constructor, parse(ebnf).class
|
|
127
|
+
assert_equal "Ajax.Request", parse(ebnf).namespace
|
|
128
|
+
assert_equal "new", parse(ebnf).name
|
|
129
|
+
assert_equal "new Ajax.Request", parse(ebnf).full_name
|
|
130
|
+
assert_equal "Request", parse(ebnf).klass_name
|
|
131
|
+
assert_equal %w[url options], parse(ebnf).arguments.map(&:name)
|
|
132
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def test_klass
|
|
137
|
+
ebnf = "class Ajax.Base"
|
|
138
|
+
assert_parsed ebnf
|
|
139
|
+
assert_equal Klass, parse(ebnf).class
|
|
140
|
+
assert_equal "Ajax", parse(ebnf).namespace
|
|
141
|
+
assert_equal "Base", parse(ebnf).name
|
|
142
|
+
assert_equal "Ajax.Base", parse(ebnf).full_name
|
|
143
|
+
assert_equal nil, parse(ebnf).klass_name
|
|
144
|
+
assert_equal [], parse(ebnf).mixins
|
|
145
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
146
|
+
|
|
147
|
+
ebnf = "class Element"
|
|
148
|
+
assert_parsed ebnf
|
|
149
|
+
assert_equal Klass, parse(ebnf).class
|
|
150
|
+
assert_equal "", parse(ebnf).namespace
|
|
151
|
+
assert_equal "Element", parse(ebnf).name
|
|
152
|
+
assert_equal "Element", parse(ebnf).full_name
|
|
153
|
+
assert_equal nil, parse(ebnf).klass_name
|
|
154
|
+
assert !parse(ebnf).subklass?
|
|
155
|
+
assert_equal [], parse(ebnf).mixins
|
|
156
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
157
|
+
|
|
158
|
+
ebnf = "class Ajax.Request < Ajax.Base"
|
|
159
|
+
assert_parsed ebnf
|
|
160
|
+
assert_equal Klass, parse(ebnf).class
|
|
161
|
+
assert_equal "Ajax", parse(ebnf).namespace
|
|
162
|
+
assert_equal "Request", parse(ebnf).name
|
|
163
|
+
assert_equal "Ajax.Request", parse(ebnf).full_name
|
|
164
|
+
assert_equal nil, parse(ebnf).klass_name
|
|
165
|
+
assert parse(ebnf).subklass?
|
|
166
|
+
assert_equal "Base", parse(ebnf).superklass.name
|
|
167
|
+
assert_equal "Ajax", parse(ebnf).superklass.namespace
|
|
168
|
+
assert_equal [], parse(ebnf).mixins
|
|
169
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
170
|
+
|
|
171
|
+
ebnf = "class Array\n * includes Enumerable"
|
|
172
|
+
assert_parsed ebnf
|
|
173
|
+
assert_equal %w[Enumerable], parse(ebnf).mixins.map(&:name)
|
|
174
|
+
assert_equal [""], parse(ebnf).mixins.map(&:namespace)
|
|
175
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
176
|
+
|
|
177
|
+
ebnf = "class Array\n * includes Enumerable, Foo.Comparable"
|
|
178
|
+
assert_parsed ebnf
|
|
179
|
+
assert_equal %w[Enumerable Comparable], parse(ebnf).mixins.map(&:name)
|
|
180
|
+
assert_equal ["", "Foo"], parse(ebnf).mixins.map(&:namespace)
|
|
181
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def test_namespace
|
|
185
|
+
ebnf = "Prototype.Browser"
|
|
186
|
+
assert_parsed ebnf
|
|
187
|
+
assert_equal Namespace, parse(ebnf).class
|
|
188
|
+
assert_equal "Prototype", parse(ebnf).namespace
|
|
189
|
+
assert_equal "Browser", parse(ebnf).name
|
|
190
|
+
assert_equal "Prototype.Browser", parse(ebnf).full_name
|
|
191
|
+
assert_equal nil, parse(ebnf).klass_name
|
|
192
|
+
assert_equal [], parse(ebnf).mixins
|
|
193
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
194
|
+
|
|
195
|
+
ebnf = "Ajax"
|
|
196
|
+
assert_parsed ebnf
|
|
197
|
+
assert_equal Namespace, parse(ebnf).class
|
|
198
|
+
assert_equal "", parse(ebnf).namespace
|
|
199
|
+
assert_equal "Ajax", parse(ebnf).name
|
|
200
|
+
assert_equal "Ajax", parse(ebnf).full_name
|
|
201
|
+
assert_equal nil, parse(ebnf).klass_name
|
|
202
|
+
assert_equal [], parse(ebnf).mixins
|
|
203
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
204
|
+
|
|
205
|
+
ebnf = "scripty2"
|
|
206
|
+
assert_parsed ebnf
|
|
207
|
+
assert_equal Namespace, parse(ebnf).class
|
|
208
|
+
assert_equal "", parse(ebnf).namespace
|
|
209
|
+
assert_equal "scripty2", parse(ebnf).name
|
|
210
|
+
assert_equal "scripty2", parse(ebnf).full_name
|
|
211
|
+
assert_equal nil, parse(ebnf).klass_name
|
|
212
|
+
assert_equal [], parse(ebnf).mixins
|
|
213
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
214
|
+
|
|
215
|
+
ebnf = "Ajax\n * includes Enumerable"
|
|
216
|
+
assert_parsed ebnf
|
|
217
|
+
assert_equal Namespace, parse(ebnf).class
|
|
218
|
+
assert_equal "", parse(ebnf).namespace
|
|
219
|
+
assert_equal "Ajax", parse(ebnf).name
|
|
220
|
+
assert_equal "Ajax", parse(ebnf).full_name
|
|
221
|
+
assert_equal nil, parse(ebnf).klass_name
|
|
222
|
+
assert_equal %w[Enumerable], parse(ebnf).mixins.map(&:name)
|
|
223
|
+
assert_equal [""], parse(ebnf).mixins.map(&:namespace)
|
|
224
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
225
|
+
|
|
226
|
+
ebnf = "document"
|
|
227
|
+
assert_parsed ebnf
|
|
228
|
+
assert_equal Namespace, parse(ebnf).class
|
|
229
|
+
assert_equal "", parse(ebnf).namespace
|
|
230
|
+
assert_equal "document", parse(ebnf).name
|
|
231
|
+
assert_equal "document", parse(ebnf).full_name
|
|
232
|
+
assert_equal nil, parse(ebnf).klass_name
|
|
233
|
+
assert_equal [], parse(ebnf).mixins
|
|
234
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
235
|
+
|
|
236
|
+
ebnf = "document.viewport"
|
|
237
|
+
assert_parsed ebnf
|
|
238
|
+
assert_equal Namespace, parse(ebnf).class
|
|
239
|
+
assert_equal "document", parse(ebnf).namespace
|
|
240
|
+
assert_equal "viewport", parse(ebnf).name
|
|
241
|
+
assert_equal "document.viewport", parse(ebnf).full_name
|
|
242
|
+
assert_equal nil, parse(ebnf).klass_name
|
|
243
|
+
assert_equal [], parse(ebnf).mixins
|
|
244
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
def test_mixin
|
|
248
|
+
ebnf = "mixin Enumerable"
|
|
249
|
+
assert_parsed ebnf
|
|
250
|
+
assert_equal Mixin, parse(ebnf).class
|
|
251
|
+
assert_equal "", parse(ebnf).namespace
|
|
252
|
+
assert_equal "Enumerable", parse(ebnf).name
|
|
253
|
+
assert_equal "Enumerable", parse(ebnf).full_name
|
|
254
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def test_constant
|
|
258
|
+
ebnf = "Prototype.JSONFilter = /^\/\*-secure-([\s\S]*)\*\/\s*$/"
|
|
259
|
+
assert_parsed ebnf
|
|
260
|
+
assert_equal Constant, parse(ebnf).class
|
|
261
|
+
assert_equal "Prototype", parse(ebnf).namespace
|
|
262
|
+
assert_equal "JSONFilter", parse(ebnf).name
|
|
263
|
+
assert_equal "Prototype.JSONFilter", parse(ebnf).full_name
|
|
264
|
+
assert_equal "/^\/\*-secure-([\s\S]*)\*\/\s*$/", parse(ebnf).returns
|
|
265
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
266
|
+
|
|
267
|
+
ebnf = "s2.css.LENGTH = /^(([\+\-]?[0-9\.]+)(em|ex|px|in|cm|mm|pt|pc|\%))|0$/"
|
|
268
|
+
assert_parsed ebnf
|
|
269
|
+
assert_equal Constant, parse(ebnf).class
|
|
270
|
+
assert_equal "s2.css", parse(ebnf).namespace
|
|
271
|
+
assert_equal "LENGTH", parse(ebnf).name
|
|
272
|
+
assert_equal "s2.css.LENGTH", parse(ebnf).full_name
|
|
273
|
+
assert_equal "/^(([\+\-]?[0-9\.]+)(em|ex|px|in|cm|mm|pt|pc|\%))|0$/", parse(ebnf).returns
|
|
274
|
+
assert_equal ebnf, parse(ebnf).to_s
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def test_no_arguments
|
|
278
|
+
assert_parsed "Event#stop() -> a value"
|
|
279
|
+
assert_parsed "Event#stop( ) -> a value"
|
|
280
|
+
assert_equal [], parse("Event#stop() -> a value").arguments
|
|
281
|
+
assert_equal [], parse("Event#stop( ) -> a value").arguments
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
def test_one_required_argument
|
|
285
|
+
ebnf = "Event.stop(event) -> Event"
|
|
286
|
+
ebnf_with_space = "Event.stop( event ) -> Event"
|
|
287
|
+
|
|
288
|
+
assert_parsed ebnf
|
|
289
|
+
assert_parsed ebnf_with_space
|
|
290
|
+
assert_equal 1, parse(ebnf).arguments.length
|
|
291
|
+
assert_equal 1, parse(ebnf_with_space).arguments.length
|
|
292
|
+
assert_equal "event", parse(ebnf).arguments.first.name
|
|
293
|
+
assert_equal nil, parse(ebnf).arguments.first.default_value
|
|
294
|
+
assert_equal false, parse(ebnf).arguments.first.optional?
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
def test_multiple_required_arguments
|
|
298
|
+
ebnf = "Event.findElement(event,selector) -> Event"
|
|
299
|
+
ebnf_with_space = "Event.findElement( event , selector ) -> Event"
|
|
300
|
+
|
|
301
|
+
assert_parsed ebnf
|
|
302
|
+
assert_parsed ebnf_with_space
|
|
303
|
+
assert_equal 2, parse(ebnf).arguments.length
|
|
304
|
+
assert_equal 2, parse(ebnf_with_space).arguments.length
|
|
305
|
+
assert_equal ["event", "selector"], parse(ebnf).arguments.map(&:name)
|
|
306
|
+
assert_equal [nil, nil], parse(ebnf).arguments.map(&:default_value)
|
|
307
|
+
assert_equal [false, false], parse(ebnf).arguments.map(&:optional?)
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
def test_one_optional_argument
|
|
311
|
+
ebnf = "Element#update([content]) -> Element"
|
|
312
|
+
ebnf_with_space = "Element#update( [ content ] ) -> Element"
|
|
313
|
+
|
|
314
|
+
assert_parsed ebnf
|
|
315
|
+
assert_parsed ebnf_with_space
|
|
316
|
+
assert_equal 1, parse(ebnf).arguments.length
|
|
317
|
+
assert_equal 1, parse(ebnf_with_space).arguments.length
|
|
318
|
+
assert_equal "content", parse(ebnf).arguments.first.name
|
|
319
|
+
assert_equal nil, parse(ebnf).arguments.first.default_value
|
|
320
|
+
assert_equal true, parse(ebnf).arguments.first.optional?
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
def test_one_optional_argument_with_default_value
|
|
324
|
+
ebnf = "Element#update([content='']) -> Element"
|
|
325
|
+
ebnf_with_space = "Element#update( [ content='' ] ) -> Element"
|
|
326
|
+
|
|
327
|
+
assert_parsed ebnf
|
|
328
|
+
assert_parsed ebnf_with_space
|
|
329
|
+
assert_equal 1, parse(ebnf).arguments.length
|
|
330
|
+
assert_equal 1, parse(ebnf_with_space).arguments.length
|
|
331
|
+
assert_equal "content", parse(ebnf).arguments.first.name
|
|
332
|
+
assert_equal "''", parse(ebnf).arguments.first.default_value
|
|
333
|
+
assert_equal true, parse(ebnf).arguments.first.optional?
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
def test_multiple_optional_arguments
|
|
337
|
+
ebnf = "Element#down([selector][,index=0]) -> Element"
|
|
338
|
+
ebnf_with_space = "Element#down( [ selector ] [ , index=0 ] ) -> Element"
|
|
339
|
+
|
|
340
|
+
assert_parsed ebnf
|
|
341
|
+
assert_parsed ebnf_with_space
|
|
342
|
+
assert_equal 2, parse(ebnf).arguments.length
|
|
343
|
+
assert_equal 2, parse(ebnf_with_space).arguments.length
|
|
344
|
+
assert_equal ["selector", "index"], parse(ebnf).arguments.map(&:name)
|
|
345
|
+
assert_equal [nil, "0"], parse(ebnf).arguments.map(&:default_value)
|
|
346
|
+
assert_equal [true, true], parse(ebnf).arguments.map(&:optional?)
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
def test_multiple_mixed_arguments
|
|
350
|
+
ebnf = "Element.down(element[,selector][,index=0]) -> Element"
|
|
351
|
+
ebnf_with_space = "Element.down( element [ , selector ] [ , index=0 ] ) -> Element"
|
|
352
|
+
|
|
353
|
+
assert_parsed ebnf
|
|
354
|
+
assert_parsed ebnf_with_space
|
|
355
|
+
assert_equal 3, parse(ebnf).arguments.length
|
|
356
|
+
assert_equal 3, parse(ebnf_with_space).arguments.length
|
|
357
|
+
assert_equal ["element", "selector", "index"], parse(ebnf).arguments.map(&:name)
|
|
358
|
+
assert_equal [nil, nil, "0"], parse(ebnf).arguments.map(&:default_value)
|
|
359
|
+
assert_equal [false, true, true], parse(ebnf).arguments.map(&:optional?)
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
def test_methodized_argument
|
|
363
|
+
ebnf = "Element.down(@element[,selector][,index=0]) -> Element"
|
|
364
|
+
ebnf_with_space = "Element.down( @element [ , selector ] [ , index=0 ] ) -> Element"
|
|
365
|
+
ebnf2 = "Element.writeAttribute(@element, attribute[, value = true]) -> Element"
|
|
366
|
+
|
|
367
|
+
assert_parsed ebnf
|
|
368
|
+
assert_parsed ebnf_with_space
|
|
369
|
+
assert parse(ebnf).methodized?
|
|
370
|
+
assert parse(ebnf_with_space).methodized?
|
|
371
|
+
assert !parse("Event#stop() -> a value").methodized?
|
|
372
|
+
assert_equal 3, parse(ebnf).arguments.length
|
|
373
|
+
assert_equal 3, parse(ebnf2).arguments.length
|
|
374
|
+
assert_equal 3, parse(ebnf_with_space).arguments.length
|
|
375
|
+
assert_equal ["element", "selector", "index"], parse(ebnf).arguments.map(&:name)
|
|
376
|
+
assert_equal ['element', 'attribute', 'value'],parse(ebnf2).arguments.map(&:name)
|
|
377
|
+
assert_equal [nil, nil, "0"], parse(ebnf).arguments.map(&:default_value)
|
|
378
|
+
assert_equal [nil, nil, "true"], parse(ebnf2).arguments.map(&:default_value)
|
|
379
|
+
assert_equal [false, true, true], parse(ebnf).arguments.map(&:optional?)
|
|
380
|
+
assert_equal [false, false, true], parse(ebnf2).arguments.map(&:optional?)
|
|
381
|
+
end
|
|
382
|
+
end
|