codemodels-ruby 0.1.5-java
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/.gitignore +3 -0
- data/Gemfile +3 -0
- data/README.md +6 -0
- data/Rakefile +13 -0
- data/codemodels-ruby.gemspec +33 -0
- data/lib/codemodels/ruby.rb +12 -0
- data/lib/codemodels/ruby/code.rb +14 -0
- data/lib/codemodels/ruby/info_extraction.rb +100 -0
- data/lib/codemodels/ruby/language.rb +17 -0
- data/lib/codemodels/ruby/metamodel.rb +481 -0
- data/lib/codemodels/ruby/model_building.rb +36 -0
- data/lib/codemodels/ruby/parser.rb +809 -0
- data/lib/codemodels/ruby/query.rb +25 -0
- data/lib/jars/com.google.collect_1.0.0.v201105210816.jar +0 -0
- data/lib/jars/com.google.inject_2.0.0.v201105231817.jar +0 -0
- data/lib/jars/com.ibm.icu_4.4.2.v20110208.jar +0 -0
- data/lib/jars/org.apache.commons.lang_2.4.0.v201005080502.jar +0 -0
- data/lib/jars/org.apache.commons.logging_1.1.1.jar +0 -0
- data/lib/jars/org.apache.log4j_1.2.16.jar +0 -0
- data/lib/jars/org.eclipse.core.runtime.compatibility_3.2.100.v20100505.jar +0 -0
- data/lib/jars/org.eclipse.core.runtime_3.7.0.v20110110.jar +0 -0
- data/test/data/012_add_comments_permissions.rb +14 -0
- data/test/data/darcs_adapter.rb +242 -0
- data/test/data/example_of_complex_class.rb +157 -0
- data/test/data/issues_helper_test.rb +271 -0
- data/test/data/status_test.rb +14 -0
- data/test/data/user_custom_field.rb +23 -0
- data/test/helper.rb +87 -0
- data/test/test_assignments.rb +14 -0
- data/test/test_blocks.rb +102 -0
- data/test/test_constants.rb +14 -0
- data/test/test_exception_handling.rb +35 -0
- data/test/test_info.rb +52 -0
- data/test/test_logic.rb +61 -0
- data/test/test_metamodel.rb +70 -0
- data/test/test_modules_and_classes.rb +81 -0
- data/test/test_not_variable_assignements.rb +75 -0
- data/test/test_operations.rb +440 -0
- data/test/test_parsing_complex.rb +49 -0
- data/test/test_parsing_literals.rb +92 -0
- data/test/test_statements.rb +169 -0
- data/test/test_terms_extraction.rb +240 -0
- data/test/test_values_extraction.rb +102 -0
- data/test/test_variables.rb +81 -0
- metadata +272 -0
@@ -0,0 +1,271 @@
|
|
1
|
+
# Redmine - project management software
|
2
|
+
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
3
|
+
#
|
4
|
+
# This program is free software; you can redistribute it and/or
|
5
|
+
# modify it under the terms of the GNU General Public License
|
6
|
+
# as published by the Free Software Foundation; either version 2
|
7
|
+
# of the License, or (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
17
|
+
|
18
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
19
|
+
|
20
|
+
class IssuesHelperTest < ActionView::TestCase
|
21
|
+
include ApplicationHelper
|
22
|
+
include Redmine::I18n
|
23
|
+
include IssuesHelper
|
24
|
+
include CustomFieldsHelper
|
25
|
+
include ERB::Util
|
26
|
+
|
27
|
+
fixtures :projects, :trackers, :issue_statuses, :issues,
|
28
|
+
:enumerations, :users, :issue_categories,
|
29
|
+
:projects_trackers,
|
30
|
+
:roles,
|
31
|
+
:member_roles,
|
32
|
+
:members,
|
33
|
+
:enabled_modules,
|
34
|
+
:custom_fields,
|
35
|
+
:attachments,
|
36
|
+
:versions
|
37
|
+
|
38
|
+
def setup
|
39
|
+
super
|
40
|
+
set_language_if_valid('en')
|
41
|
+
User.current = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_issue_heading
|
45
|
+
assert_equal "Bug #1", issue_heading(Issue.find(1))
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_issues_destroy_confirmation_message_with_one_root_issue
|
49
|
+
assert_equal l(:text_issues_destroy_confirmation),
|
50
|
+
issues_destroy_confirmation_message(Issue.find(1))
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues
|
54
|
+
assert_equal l(:text_issues_destroy_confirmation),
|
55
|
+
issues_destroy_confirmation_message(Issue.find([1, 2]))
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_issues_destroy_confirmation_message_with_one_parent_issue
|
59
|
+
Issue.find(2).update_attribute :parent_issue_id, 1
|
60
|
+
assert_equal l(:text_issues_destroy_confirmation) + "\n" +
|
61
|
+
l(:text_issues_destroy_descendants_confirmation, :count => 1),
|
62
|
+
issues_destroy_confirmation_message(Issue.find(1))
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child
|
66
|
+
Issue.find(2).update_attribute :parent_issue_id, 1
|
67
|
+
assert_equal l(:text_issues_destroy_confirmation),
|
68
|
+
issues_destroy_confirmation_message(Issue.find([1, 2]))
|
69
|
+
end
|
70
|
+
|
71
|
+
test 'show_detail with no_html should show a changing attribute' do
|
72
|
+
detail = JournalDetail.new(:property => 'attr', :old_value => '40',
|
73
|
+
:value => '100', :prop_key => 'done_ratio')
|
74
|
+
assert_equal "% Done changed from 40 to 100", show_detail(detail, true)
|
75
|
+
end
|
76
|
+
|
77
|
+
test 'show_detail with no_html should show a new attribute' do
|
78
|
+
detail = JournalDetail.new(:property => 'attr', :old_value => nil,
|
79
|
+
:value => '100', :prop_key => 'done_ratio')
|
80
|
+
assert_equal "% Done set to 100", show_detail(detail, true)
|
81
|
+
end
|
82
|
+
|
83
|
+
test 'show_detail with no_html should show a deleted attribute' do
|
84
|
+
detail = JournalDetail.new(:property => 'attr', :old_value => '50',
|
85
|
+
:value => nil, :prop_key => 'done_ratio')
|
86
|
+
assert_equal "% Done deleted (50)", show_detail(detail, true)
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'show_detail with html should show a changing attribute with HTML highlights' do
|
90
|
+
detail = JournalDetail.new(:property => 'attr', :old_value => '40',
|
91
|
+
:value => '100', :prop_key => 'done_ratio')
|
92
|
+
html = show_detail(detail, false)
|
93
|
+
assert_include '<strong>% Done</strong>', html
|
94
|
+
assert_include '<i>40</i>', html
|
95
|
+
assert_include '<i>100</i>', html
|
96
|
+
end
|
97
|
+
|
98
|
+
test 'show_detail with html should show a new attribute with HTML highlights' do
|
99
|
+
detail = JournalDetail.new(:property => 'attr', :old_value => nil,
|
100
|
+
:value => '100', :prop_key => 'done_ratio')
|
101
|
+
html = show_detail(detail, false)
|
102
|
+
assert_include '<strong>% Done</strong>', html
|
103
|
+
assert_include '<i>100</i>', html
|
104
|
+
end
|
105
|
+
|
106
|
+
test 'show_detail with html should show a deleted attribute with HTML highlights' do
|
107
|
+
detail = JournalDetail.new(:property => 'attr', :old_value => '50',
|
108
|
+
:value => nil, :prop_key => 'done_ratio')
|
109
|
+
html = show_detail(detail, false)
|
110
|
+
assert_include '<strong>% Done</strong>', html
|
111
|
+
assert_include '<del><i>50</i></del>', html
|
112
|
+
end
|
113
|
+
|
114
|
+
test 'show_detail with a start_date attribute should format the dates' do
|
115
|
+
detail = JournalDetail.new(
|
116
|
+
:property => 'attr',
|
117
|
+
:old_value => '2010-01-01',
|
118
|
+
:value => '2010-01-31',
|
119
|
+
:prop_key => 'start_date'
|
120
|
+
)
|
121
|
+
with_settings :date_format => '%m/%d/%Y' do
|
122
|
+
assert_match "01/31/2010", show_detail(detail, true)
|
123
|
+
assert_match "01/01/2010", show_detail(detail, true)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
test 'show_detail with a due_date attribute should format the dates' do
|
128
|
+
detail = JournalDetail.new(
|
129
|
+
:property => 'attr',
|
130
|
+
:old_value => '2010-01-01',
|
131
|
+
:value => '2010-01-31',
|
132
|
+
:prop_key => 'due_date'
|
133
|
+
)
|
134
|
+
with_settings :date_format => '%m/%d/%Y' do
|
135
|
+
assert_match "01/31/2010", show_detail(detail, true)
|
136
|
+
assert_match "01/01/2010", show_detail(detail, true)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
test 'show_detail should show old and new values with a project attribute' do
|
141
|
+
detail = JournalDetail.new(:property => 'attr', :prop_key => 'project_id',
|
142
|
+
:old_value => 1, :value => 2)
|
143
|
+
assert_match 'eCookbook', show_detail(detail, true)
|
144
|
+
assert_match 'OnlineStore', show_detail(detail, true)
|
145
|
+
end
|
146
|
+
|
147
|
+
test 'show_detail should show old and new values with a issue status attribute' do
|
148
|
+
detail = JournalDetail.new(:property => 'attr', :prop_key => 'status_id',
|
149
|
+
:old_value => 1, :value => 2)
|
150
|
+
assert_match 'New', show_detail(detail, true)
|
151
|
+
assert_match 'Assigned', show_detail(detail, true)
|
152
|
+
end
|
153
|
+
|
154
|
+
test 'show_detail should show old and new values with a tracker attribute' do
|
155
|
+
detail = JournalDetail.new(:property => 'attr', :prop_key => 'tracker_id',
|
156
|
+
:old_value => 1, :value => 2)
|
157
|
+
assert_match 'Bug', show_detail(detail, true)
|
158
|
+
assert_match 'Feature request', show_detail(detail, true)
|
159
|
+
end
|
160
|
+
|
161
|
+
test 'show_detail should show old and new values with a assigned to attribute' do
|
162
|
+
detail = JournalDetail.new(:property => 'attr', :prop_key => 'assigned_to_id',
|
163
|
+
:old_value => 1, :value => 2)
|
164
|
+
assert_match 'Redmine Admin', show_detail(detail, true)
|
165
|
+
assert_match 'John Smith', show_detail(detail, true)
|
166
|
+
end
|
167
|
+
|
168
|
+
test 'show_detail should show old and new values with a priority attribute' do
|
169
|
+
detail = JournalDetail.new(:property => 'attr', :prop_key => 'priority_id',
|
170
|
+
:old_value => 4, :value => 5)
|
171
|
+
assert_match 'Low', show_detail(detail, true)
|
172
|
+
assert_match 'Normal', show_detail(detail, true)
|
173
|
+
end
|
174
|
+
|
175
|
+
test 'show_detail should show old and new values with a category attribute' do
|
176
|
+
detail = JournalDetail.new(:property => 'attr', :prop_key => 'category_id',
|
177
|
+
:old_value => 1, :value => 2)
|
178
|
+
assert_match 'Printing', show_detail(detail, true)
|
179
|
+
assert_match 'Recipes', show_detail(detail, true)
|
180
|
+
end
|
181
|
+
|
182
|
+
test 'show_detail should show old and new values with a fixed version attribute' do
|
183
|
+
detail = JournalDetail.new(:property => 'attr', :prop_key => 'fixed_version_id',
|
184
|
+
:old_value => 1, :value => 2)
|
185
|
+
assert_match '0.1', show_detail(detail, true)
|
186
|
+
assert_match '1.0', show_detail(detail, true)
|
187
|
+
end
|
188
|
+
|
189
|
+
test 'show_detail should show old and new values with a estimated hours attribute' do
|
190
|
+
detail = JournalDetail.new(:property => 'attr', :prop_key => 'estimated_hours',
|
191
|
+
:old_value => '5', :value => '6.3')
|
192
|
+
assert_match '5.00', show_detail(detail, true)
|
193
|
+
assert_match '6.30', show_detail(detail, true)
|
194
|
+
end
|
195
|
+
|
196
|
+
test 'show_detail should show old and new values with a custom field' do
|
197
|
+
detail = JournalDetail.new(:property => 'cf', :prop_key => '1',
|
198
|
+
:old_value => 'MySQL', :value => 'PostgreSQL')
|
199
|
+
assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true)
|
200
|
+
end
|
201
|
+
|
202
|
+
test 'show_detail should show added file' do
|
203
|
+
detail = JournalDetail.new(:property => 'attachment', :prop_key => '1',
|
204
|
+
:old_value => nil, :value => 'error281.txt')
|
205
|
+
assert_match 'error281.txt', show_detail(detail, true)
|
206
|
+
end
|
207
|
+
|
208
|
+
test 'show_detail should show removed file' do
|
209
|
+
detail = JournalDetail.new(:property => 'attachment', :prop_key => '1',
|
210
|
+
:old_value => 'error281.txt', :value => nil)
|
211
|
+
assert_match 'error281.txt', show_detail(detail, true)
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_show_detail_relation_added
|
215
|
+
detail = JournalDetail.new(:property => 'relation',
|
216
|
+
:prop_key => 'label_precedes',
|
217
|
+
:value => 1)
|
218
|
+
assert_equal "Precedes Bug #1: Can't print recipes added", show_detail(detail, true)
|
219
|
+
assert_match %r{<strong>Precedes</strong> <i><a href="/issues/1" class=".+">Bug #1</a>: Can't print recipes</i> added},
|
220
|
+
show_detail(detail, false)
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_show_detail_relation_added_with_inexistant_issue
|
224
|
+
inexistant_issue_number = 9999
|
225
|
+
assert_nil Issue.find_by_id(inexistant_issue_number)
|
226
|
+
detail = JournalDetail.new(:property => 'relation',
|
227
|
+
:prop_key => 'label_precedes',
|
228
|
+
:value => inexistant_issue_number)
|
229
|
+
assert_equal "Precedes Issue ##{inexistant_issue_number} added", show_detail(detail, true)
|
230
|
+
assert_equal "<strong>Precedes</strong> <i>Issue ##{inexistant_issue_number}</i> added", show_detail(detail, false)
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_show_detail_relation_added_should_not_disclose_issue_that_is_not_visible
|
234
|
+
issue = Issue.generate!(:is_private => true)
|
235
|
+
detail = JournalDetail.new(:property => 'relation',
|
236
|
+
:prop_key => 'label_precedes',
|
237
|
+
:value => issue.id)
|
238
|
+
|
239
|
+
assert_equal "Precedes Issue ##{issue.id} added", show_detail(detail, true)
|
240
|
+
assert_equal "<strong>Precedes</strong> <i>Issue ##{issue.id}</i> added", show_detail(detail, false)
|
241
|
+
end
|
242
|
+
|
243
|
+
def test_show_detail_relation_deleted
|
244
|
+
detail = JournalDetail.new(:property => 'relation',
|
245
|
+
:prop_key => 'label_precedes',
|
246
|
+
:old_value => 1)
|
247
|
+
assert_equal "Precedes deleted (Bug #1: Can't print recipes)", show_detail(detail, true)
|
248
|
+
assert_match %r{<strong>Precedes</strong> deleted \(<i><a href="/issues/1" class=".+">Bug #1</a>: Can't print recipes</i>\)},
|
249
|
+
show_detail(detail, false)
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_show_detail_relation_deleted_with_inexistant_issue
|
253
|
+
inexistant_issue_number = 9999
|
254
|
+
assert_nil Issue.find_by_id(inexistant_issue_number)
|
255
|
+
detail = JournalDetail.new(:property => 'relation',
|
256
|
+
:prop_key => 'label_precedes',
|
257
|
+
:old_value => inexistant_issue_number)
|
258
|
+
assert_equal "Precedes deleted (Issue #9999)", show_detail(detail, true)
|
259
|
+
assert_equal "<strong>Precedes</strong> deleted (<i>Issue #9999</i>)", show_detail(detail, false)
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_show_detail_relation_deleted_should_not_disclose_issue_that_is_not_visible
|
263
|
+
issue = Issue.generate!(:is_private => true)
|
264
|
+
detail = JournalDetail.new(:property => 'relation',
|
265
|
+
:prop_key => 'label_precedes',
|
266
|
+
:old_value => issue.id)
|
267
|
+
|
268
|
+
assert_equal "Precedes deleted (Issue ##{issue.id})", show_detail(detail, true)
|
269
|
+
assert_equal "<strong>Precedes</strong> deleted (<i>Issue ##{issue.id}</i>)", show_detail(detail, false)
|
270
|
+
end
|
271
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class StatusTest < Test::Unit::TestCase
|
4
|
+
include OpenIdAuthentication
|
5
|
+
|
6
|
+
def test_state_conditional
|
7
|
+
assert Result[:missing].missing?
|
8
|
+
assert Result[:missing].unsuccessful?
|
9
|
+
assert !Result[:missing].successful?
|
10
|
+
|
11
|
+
assert Result[:successful].successful?
|
12
|
+
assert !Result[:successful].unsuccessful?
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Redmine - project management software
|
2
|
+
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
3
|
+
#
|
4
|
+
# This program is free software; you can redistribute it and/or
|
5
|
+
# modify it under the terms of the GNU General Public License
|
6
|
+
# as published by the Free Software Foundation; either version 2
|
7
|
+
# of the License, or (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
17
|
+
|
18
|
+
class UserCustomField < CustomField
|
19
|
+
def type_name
|
20
|
+
:label_user_plural
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start do
|
3
|
+
add_filter "/test/"
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
require 'ruby-lightmodels'
|
8
|
+
|
9
|
+
module TestHelper
|
10
|
+
|
11
|
+
include LightModels
|
12
|
+
|
13
|
+
def assert_is_int(node,value)
|
14
|
+
assert node.is_a? Ruby::IntLiteral
|
15
|
+
assert_equal value, node.value
|
16
|
+
end
|
17
|
+
|
18
|
+
def assert_is_str(node,value)
|
19
|
+
assert node.is_a? Ruby::StringLiteral
|
20
|
+
assert_equal value, node.value
|
21
|
+
end
|
22
|
+
|
23
|
+
# DEPRECATED
|
24
|
+
def assert_right_class(node,clazz)
|
25
|
+
assert_class(clazz,node)
|
26
|
+
end
|
27
|
+
|
28
|
+
def assert_class(clazz,node)
|
29
|
+
assert node.is_a?(clazz), "Instead #{node.class}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def assert_simple_const(node,name)
|
33
|
+
assert_right_class node,Ruby::Constant
|
34
|
+
assert_equal name, node.name
|
35
|
+
assert_equal nil, node.container
|
36
|
+
end
|
37
|
+
|
38
|
+
def assert_node(node,clazz,values={})
|
39
|
+
assert_right_class node,clazz
|
40
|
+
assert_values node,values
|
41
|
+
end
|
42
|
+
|
43
|
+
def assert_values(node,values)
|
44
|
+
values.each do |name,expected_value|
|
45
|
+
getter = name
|
46
|
+
actual_value = node.send getter
|
47
|
+
assert_equal expected_value,actual_value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def relative_path(path)
|
52
|
+
File.join(File.dirname(__FILE__),path)
|
53
|
+
end
|
54
|
+
|
55
|
+
def read_test_data(filename)
|
56
|
+
dir = File.dirname(__FILE__)
|
57
|
+
dir = File.join(dir,'data')
|
58
|
+
path = File.join(dir,filename)
|
59
|
+
IO.read(path)
|
60
|
+
end
|
61
|
+
|
62
|
+
def assert_map_equal(exp,act,model=nil)
|
63
|
+
fail "Unexpected keys #{act.keys-exp.keys}. Actual map: #{act}" if (act.keys-exp.keys).count > 0
|
64
|
+
fail "Missing keys #{exp.keys-act.keys}. Actual map: #{act}" if (exp.keys-act.keys).count > 0
|
65
|
+
exp.each do |k,exp_v|
|
66
|
+
fail "For '#{k}' expected #{exp_v}, found #{act[k]}, model=#{model}" if act[k]!=exp_v
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def assert_all_attrs(expected,c)
|
72
|
+
actual = c.ecore.eAllAttributes
|
73
|
+
assert_equal expected.count,actual.count,"Expected #{expected.count} attrs, found #{actual.count}. They are #{actual.name}"
|
74
|
+
expected.each do |e|
|
75
|
+
assert actual.find {|a| a.name==e}, "Attribute #{e} not found"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def assert_all_refs(expected,c)
|
80
|
+
actual = c.ecore.eAllReferences
|
81
|
+
assert_equal expected.count,actual.count,"Expected #{expected.count} refs, found #{actual.count}. They are #{actual.name}"
|
82
|
+
expected.each do |e|
|
83
|
+
assert actual.find {|a| a.name==e}, "Reference #{e} not found"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestAssignments < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include TestHelper
|
6
|
+
include LightModels
|
7
|
+
|
8
|
+
def test_op_assignement
|
9
|
+
r = Ruby.parse("a.el ||= 2")
|
10
|
+
assert_node r, Ruby::OperatorAssignment, value: Ruby.int(2), operator_name: '||', element_name: 'el'
|
11
|
+
assert_node r.container, Ruby::Call
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
data/test/test_blocks.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestBlocks < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include TestHelper
|
6
|
+
include LightModels
|
7
|
+
|
8
|
+
def test_passing_block_do
|
9
|
+
root = Ruby.parse("[].select do |x|\nx\nend")
|
10
|
+
#puts "ROOT=#{root.inspect}"
|
11
|
+
assert_node root, Ruby::Call, name: 'select'
|
12
|
+
assert_equal 0,root.args.count
|
13
|
+
assert_not_nil root.block_arg
|
14
|
+
assert_node root.block_arg, Ruby::CodeBlock,
|
15
|
+
args:[Ruby::Argument.build('x')],
|
16
|
+
body: Ruby::BlockVarAccess.build('x')
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_passing_block_cb # cb: curly braces
|
20
|
+
root = Ruby.parse("[].select {|x| x }")
|
21
|
+
assert_node root, Ruby::Call, name: 'select'
|
22
|
+
assert_equal 0,root.args.count
|
23
|
+
assert_not_nil root.block_arg
|
24
|
+
assert_node root.block_arg, Ruby::CodeBlock,
|
25
|
+
args:[Ruby::Argument.build('x')],
|
26
|
+
body: Ruby::BlockVarAccess.build('x')
|
27
|
+
end
|
28
|
+
|
29
|
+
#iter blocks are treated differently from the JRubyParser
|
30
|
+
def test_passing_iter_block_do
|
31
|
+
root = Ruby.parse("[].each do |x|\nx\nend")
|
32
|
+
#puts "ROOT=#{root.inspect}"
|
33
|
+
assert_node root, Ruby::Call, name: 'each'
|
34
|
+
assert_equal 0,root.args.count
|
35
|
+
assert_not_nil root.block_arg
|
36
|
+
assert_node root.block_arg, Ruby::CodeBlock,
|
37
|
+
args:[Ruby::Argument.build('x')],
|
38
|
+
body: Ruby::BlockVarAccess.build('x')
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_passing_iter_block_cb # cb: curly braces
|
42
|
+
root = Ruby.parse("[].each {|x| x }")
|
43
|
+
assert_node root, Ruby::Call, name: 'each'
|
44
|
+
assert_equal 0,root.args.count
|
45
|
+
assert_not_nil root.block_arg
|
46
|
+
assert_node root.block_arg, Ruby::CodeBlock,
|
47
|
+
args:[Ruby::Argument.build('x')],
|
48
|
+
body: Ruby::BlockVarAccess.build('x')
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_block_passed_using_symbol
|
52
|
+
root = Ruby.parse('@issues.map(&:new_statuses_allowed_to)')
|
53
|
+
assert_node root, Ruby::Call, name: 'map'
|
54
|
+
assert_equal 0,root.args.count
|
55
|
+
assert_not_nil root.block_arg
|
56
|
+
assert_node root.block_arg, Ruby::BlockReference,
|
57
|
+
value: Ruby::Symbol.build('new_statuses_allowed_to')
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_block_passed_using_symbol_and_other_param
|
61
|
+
root = Ruby.parse('@issues.map(1,&:new_statuses_allowed_to)')
|
62
|
+
assert_node root, Ruby::Call, name: 'map'
|
63
|
+
assert_equal 1,root.args.count
|
64
|
+
assert_not_nil root.block_arg
|
65
|
+
assert_node root.block_arg, Ruby::BlockReference,
|
66
|
+
value: Ruby::Symbol.build('new_statuses_allowed_to')
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_begin_empty
|
70
|
+
root = Ruby.parse('begin;end')
|
71
|
+
assert_node root, Ruby::BeginEndBlock,
|
72
|
+
body: nil
|
73
|
+
assert_equal 0,root.rescue_clauses.count
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_begin_one_value
|
77
|
+
root = Ruby.parse('begin;1;end')
|
78
|
+
assert_node root, Ruby::BeginEndBlock,
|
79
|
+
body: Ruby.int(1)
|
80
|
+
assert_equal 0,root.rescue_clauses.count
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_begin_many_values
|
84
|
+
root = Ruby.parse('begin;1;2;end')
|
85
|
+
assert_node root, Ruby::BeginEndBlock, {}
|
86
|
+
assert root.body.is_a? Ruby::Block
|
87
|
+
assert_equal 2,root.body.contents.count
|
88
|
+
assert_is_int root.body.contents[0], 1
|
89
|
+
assert_is_int root.body.contents[1], 2
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_forward_block
|
93
|
+
root = Ruby.parse('def project_tree(projects, &block);Project.project_tree(projects, &block);end')
|
94
|
+
|
95
|
+
call_in_def = root.body
|
96
|
+
assert_equal 'project_tree',call_in_def.name
|
97
|
+
assert_equal 1, call_in_def.args.count # the block arg does not count!
|
98
|
+
assert_node call_in_def.block_arg,Ruby::BlockReference,
|
99
|
+
value: Ruby::LocalVarAccess.build(name: 'block')
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|