codemodels-ruby 0.1.5-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +3 -0
  3. data/README.md +6 -0
  4. data/Rakefile +13 -0
  5. data/codemodels-ruby.gemspec +33 -0
  6. data/lib/codemodels/ruby.rb +12 -0
  7. data/lib/codemodels/ruby/code.rb +14 -0
  8. data/lib/codemodels/ruby/info_extraction.rb +100 -0
  9. data/lib/codemodels/ruby/language.rb +17 -0
  10. data/lib/codemodels/ruby/metamodel.rb +481 -0
  11. data/lib/codemodels/ruby/model_building.rb +36 -0
  12. data/lib/codemodels/ruby/parser.rb +809 -0
  13. data/lib/codemodels/ruby/query.rb +25 -0
  14. data/lib/jars/com.google.collect_1.0.0.v201105210816.jar +0 -0
  15. data/lib/jars/com.google.inject_2.0.0.v201105231817.jar +0 -0
  16. data/lib/jars/com.ibm.icu_4.4.2.v20110208.jar +0 -0
  17. data/lib/jars/org.apache.commons.lang_2.4.0.v201005080502.jar +0 -0
  18. data/lib/jars/org.apache.commons.logging_1.1.1.jar +0 -0
  19. data/lib/jars/org.apache.log4j_1.2.16.jar +0 -0
  20. data/lib/jars/org.eclipse.core.runtime.compatibility_3.2.100.v20100505.jar +0 -0
  21. data/lib/jars/org.eclipse.core.runtime_3.7.0.v20110110.jar +0 -0
  22. data/test/data/012_add_comments_permissions.rb +14 -0
  23. data/test/data/darcs_adapter.rb +242 -0
  24. data/test/data/example_of_complex_class.rb +157 -0
  25. data/test/data/issues_helper_test.rb +271 -0
  26. data/test/data/status_test.rb +14 -0
  27. data/test/data/user_custom_field.rb +23 -0
  28. data/test/helper.rb +87 -0
  29. data/test/test_assignments.rb +14 -0
  30. data/test/test_blocks.rb +102 -0
  31. data/test/test_constants.rb +14 -0
  32. data/test/test_exception_handling.rb +35 -0
  33. data/test/test_info.rb +52 -0
  34. data/test/test_logic.rb +61 -0
  35. data/test/test_metamodel.rb +70 -0
  36. data/test/test_modules_and_classes.rb +81 -0
  37. data/test/test_not_variable_assignements.rb +75 -0
  38. data/test/test_operations.rb +440 -0
  39. data/test/test_parsing_complex.rb +49 -0
  40. data/test/test_parsing_literals.rb +92 -0
  41. data/test/test_statements.rb +169 -0
  42. data/test/test_terms_extraction.rb +240 -0
  43. data/test/test_values_extraction.rb +102 -0
  44. data/test/test_variables.rb +81 -0
  45. metadata +272 -0
@@ -0,0 +1,102 @@
1
+ require 'helper'
2
+
3
+ class TestValuesExtraction < Test::Unit::TestCase
4
+
5
+ include LightModels
6
+ include LightModels::Ruby
7
+ include TestHelper
8
+
9
+ def setup
10
+ @addCommentsPermissions_model_node = Ruby.parse_code(read_test_data('012_add_comments_permissions.rb'))
11
+ @issuesHelperTest_model_node = Ruby.parse_code(read_test_data('issues_helper_test.rb'))
12
+ end
13
+
14
+ def test_values_extraction_addCommentsPermissions_method_1
15
+ m = @addCommentsPermissions_model_node.contents[1]
16
+ assert_node m,Def,{name: 'up'}
17
+ assert_map_equal(
18
+ {'up'=>1, 'Permission'=>2,'create'=>2,'controller'=>2,'news'=>2,
19
+ 'action'=>2,'add_comment'=>1,'destroy_comment'=>1,
20
+ 'description'=>2,'label_comment_add'=>1,'label_comment_delete'=>1,
21
+ 'sort'=>2,1130=>1,1133=>1,
22
+ 'is_public'=>2,false=>2,'mail_option'=>2,'mail_enabled'=>2,0=>4},
23
+ m.values_map)
24
+ @issuesHelperTest_model_node = Ruby.parse_code(read_test_data('issues_helper_test.rb'))
25
+ end
26
+
27
+ def test_values_extraction_issuesHelperTest_method_1
28
+ m = @issuesHelperTest_model_node.contents[1].contents[32]
29
+ assert_node m,Def,{name: 'test_show_detail_relation_added_with_inexistant_issue'}
30
+ assert_map_equal(
31
+ {'test_show_detail_relation_added_with_inexistant_issue'=>1,
32
+ 'inexistant_issue_number'=>5, 9999=>1,
33
+ 'assert_nil'=>1,'Issue'=>1,'find_by_id'=>1,
34
+ 'detail'=>3,'JournalDetail'=>1,'new'=>1,
35
+ 'property'=>1,'relation'=>1,
36
+ 'prop_key'=>1,'label_precedes'=>1,
37
+ 'value'=>1,'assert_equal'=>2,
38
+ 'Precedes Issue #'=>1,' added'=>1,
39
+ 'show_detail'=>2,false=>1,true=>1,
40
+ '<strong>Precedes</strong> <i>Issue #'=>1,
41
+ '</i> added'=>1},
42
+ m.values_map)
43
+ end
44
+
45
+ def test_values_from_arg_names
46
+ code = %q{
47
+ def mymethod(a=1, b=nil, c={})
48
+ end
49
+ }
50
+ m = Ruby.parse_code(code)
51
+ assert_node m,Def,{name: 'mymethod'}
52
+ assert_map_equal(
53
+ {'mymethod'=>1,1=>1,'a'=>1,'b'=>1,'c'=>1},
54
+ m.values_map)
55
+ end
56
+
57
+ def test_option_name_example
58
+ code = %q{
59
+ def option_name
60
+ OptionName
61
+ end
62
+ }
63
+ m = Ruby.parse_code(code)
64
+ assert_node m,Def,{name: 'option_name'}
65
+ assert_map_equal(
66
+ {
67
+ 'option_name'=>1,
68
+ 'OptionName' =>1
69
+ },m.values_map)
70
+ end
71
+
72
+ def test_comment_sorting_example
73
+ code = %q{
74
+ def comments_sorting; self[:comments_sorting] end
75
+ }
76
+ m = Ruby.parse_code(code)
77
+ #puts "Ser: #{JSON.pretty_generate(LightModels::Serialization.jsonize_obj(m))}"
78
+ assert_node m,Def,{name: 'comments_sorting'}
79
+ assert_map_equal(
80
+ {
81
+ 'comments_sorting'=>2,
82
+ '[]'=>1
83
+ },m.values_map)
84
+ end
85
+
86
+ def test_comment_sorting_assign_example
87
+ code = %q{
88
+ def comments_sorting=(order); self[:comments_sorting]=order end
89
+ }
90
+ m = Ruby.parse_code(code)
91
+
92
+ assert_node m,Def,{name: 'comments_sorting='}
93
+ # '[]' is not contained because this is an element assignment
94
+ assert_map_equal(
95
+ {
96
+ 'comments_sorting='=>1,
97
+ 'comments_sorting' =>1,
98
+ 'order' => 2
99
+ },m.values_map)
100
+ end
101
+
102
+ end
@@ -0,0 +1,81 @@
1
+ require 'helper'
2
+
3
+ class TestVariables < Test::Unit::TestCase
4
+
5
+ include TestHelper
6
+ include LightModels
7
+
8
+ def test_inst_var_access
9
+ root = Ruby.parse('@v')
10
+ assert_node root,Ruby::InstanceVarAccess,
11
+ name:'v'
12
+ end
13
+
14
+ def test_inst_var_assignment
15
+ root = Ruby.parse('@v = 1')
16
+ assert_node root, Ruby::InstanceVarAssignment,
17
+ name_assigned: 'v',
18
+ value: Ruby.int(1)
19
+ end
20
+
21
+ def test_local_var_access
22
+ root = Ruby.parse('v=10;v')
23
+ assert_node root.contents[1],Ruby::LocalVarAccess,
24
+ name:'v'
25
+ end
26
+
27
+ def test_local_var_assign
28
+ root = Ruby.parse('some_var = 10')
29
+
30
+ assert_right_class root, Ruby::LocalVarAssignment
31
+ assert_equal 'some_var',root.name_assigned
32
+ assert_is_int root.value, 10
33
+ end
34
+
35
+ def test_global_var_access
36
+ root = Ruby.parse('$v')
37
+
38
+ assert_right_class root, Ruby::GlobalVarAccess
39
+ assert_equal 'v',root.name
40
+ end
41
+
42
+ def test_global_var_assignement
43
+ root = Ruby.parse('$v = 10')
44
+
45
+ assert_right_class root, Ruby::GlobalVarAssignment
46
+ assert_equal 'v',root.name_assigned
47
+ assert_is_int root.value, 10
48
+ end
49
+
50
+ def test_class_var_access
51
+ root = Ruby.parse('@@v')
52
+
53
+ assert_right_class root, Ruby::ClassVarAccess
54
+ assert_equal 'v',root.name
55
+ end
56
+
57
+ def test_class_var_assignement
58
+ root = Ruby.parse('@@v = 10')
59
+
60
+ assert_right_class root, Ruby::ClassVarAssignment
61
+ assert_equal 'v',root.name_assigned
62
+ assert_is_int root.value, 10
63
+ end
64
+
65
+ def test_block_var_access
66
+ root = Ruby.parse('[].each {|x| x}')
67
+
68
+ code_block = root.block_arg
69
+ assert_node code_block.body, Ruby::BlockVarAccess,
70
+ name:'x'
71
+ end
72
+
73
+ def test_block_var_assignement
74
+ root = Ruby.parse('[].each {|x| x=1}')
75
+
76
+ code_block = root.block_arg
77
+ assert_node code_block.body, Ruby::BlockVarAssignment,
78
+ { name_assigned:'x', value: Ruby::IntLiteral.build(1) }
79
+ end
80
+
81
+ end
metadata ADDED
@@ -0,0 +1,272 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codemodels-ruby
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.5
6
+ platform: java
7
+ authors:
8
+ - Federico Tomassetti
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ none: false
28
+ prerelease: false
29
+ type: :runtime
30
+ - !ruby/object:Gem::Dependency
31
+ name: emf_jruby
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ none: false
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ none: false
44
+ prerelease: false
45
+ type: :runtime
46
+ - !ruby/object:Gem::Dependency
47
+ name: jruby-parser
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '='
51
+ - !ruby/object:Gem::Version
52
+ version: 0.5.0
53
+ none: false
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '='
57
+ - !ruby/object:Gem::Version
58
+ version: 0.5.0
59
+ none: false
60
+ prerelease: false
61
+ type: :runtime
62
+ - !ruby/object:Gem::Dependency
63
+ name: codemodels
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ none: false
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ none: false
76
+ prerelease: false
77
+ type: :runtime
78
+ - !ruby/object:Gem::Dependency
79
+ name: codemodels-java
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ none: false
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ none: false
92
+ prerelease: false
93
+ type: :runtime
94
+ - !ruby/object:Gem::Dependency
95
+ name: rgen
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ none: false
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ none: false
108
+ prerelease: false
109
+ type: :runtime
110
+ - !ruby/object:Gem::Dependency
111
+ name: bundler
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ~>
115
+ - !ruby/object:Gem::Version
116
+ version: '1.3'
117
+ none: false
118
+ requirement: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ~>
121
+ - !ruby/object:Gem::Version
122
+ version: '1.3'
123
+ none: false
124
+ prerelease: false
125
+ type: :development
126
+ - !ruby/object:Gem::Dependency
127
+ name: rake
128
+ version_requirements: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ none: false
134
+ requirement: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ none: false
140
+ prerelease: false
141
+ type: :development
142
+ - !ruby/object:Gem::Dependency
143
+ name: rubygems-tasks
144
+ version_requirements: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ none: false
150
+ requirement: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ none: false
156
+ prerelease: false
157
+ type: :development
158
+ - !ruby/object:Gem::Dependency
159
+ name: simplecov
160
+ version_requirements: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ none: false
166
+ requirement: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - '>='
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ none: false
172
+ prerelease: false
173
+ type: :development
174
+ description: Plugin of codemodels to build models from Ruby code. See http://github.com/ftomassetti/codemodels.
175
+ email: f.tomassetti@gmail.com
176
+ executables: []
177
+ extensions: []
178
+ extra_rdoc_files: []
179
+ files:
180
+ - .gitignore
181
+ - Gemfile
182
+ - README.md
183
+ - Rakefile
184
+ - codemodels-ruby.gemspec
185
+ - lib/codemodels/ruby.rb
186
+ - lib/codemodels/ruby/code.rb
187
+ - lib/codemodels/ruby/info_extraction.rb
188
+ - lib/codemodels/ruby/language.rb
189
+ - lib/codemodels/ruby/metamodel.rb
190
+ - lib/codemodels/ruby/model_building.rb
191
+ - lib/codemodels/ruby/parser.rb
192
+ - lib/codemodels/ruby/query.rb
193
+ - lib/jars/com.google.collect_1.0.0.v201105210816.jar
194
+ - lib/jars/com.google.inject_2.0.0.v201105231817.jar
195
+ - lib/jars/com.ibm.icu_4.4.2.v20110208.jar
196
+ - lib/jars/org.apache.commons.lang_2.4.0.v201005080502.jar
197
+ - lib/jars/org.apache.commons.logging_1.1.1.jar
198
+ - lib/jars/org.apache.log4j_1.2.16.jar
199
+ - lib/jars/org.eclipse.core.runtime.compatibility_3.2.100.v20100505.jar
200
+ - lib/jars/org.eclipse.core.runtime_3.7.0.v20110110.jar
201
+ - test/data/012_add_comments_permissions.rb
202
+ - test/data/darcs_adapter.rb
203
+ - test/data/example_of_complex_class.rb
204
+ - test/data/issues_helper_test.rb
205
+ - test/data/status_test.rb
206
+ - test/data/user_custom_field.rb
207
+ - test/helper.rb
208
+ - test/test_assignments.rb
209
+ - test/test_blocks.rb
210
+ - test/test_constants.rb
211
+ - test/test_exception_handling.rb
212
+ - test/test_info.rb
213
+ - test/test_logic.rb
214
+ - test/test_metamodel.rb
215
+ - test/test_modules_and_classes.rb
216
+ - test/test_not_variable_assignements.rb
217
+ - test/test_operations.rb
218
+ - test/test_parsing_complex.rb
219
+ - test/test_parsing_literals.rb
220
+ - test/test_statements.rb
221
+ - test/test_terms_extraction.rb
222
+ - test/test_values_extraction.rb
223
+ - test/test_variables.rb
224
+ homepage: http://federico-tomassetti.it
225
+ licenses:
226
+ - APACHE 2
227
+ post_install_message:
228
+ rdoc_options: []
229
+ require_paths:
230
+ - lib
231
+ required_ruby_version: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - '>='
234
+ - !ruby/object:Gem::Version
235
+ version: '0'
236
+ none: false
237
+ required_rubygems_version: !ruby/object:Gem::Requirement
238
+ requirements:
239
+ - - '>='
240
+ - !ruby/object:Gem::Version
241
+ version: '0'
242
+ none: false
243
+ requirements: []
244
+ rubyforge_project:
245
+ rubygems_version: 1.8.24
246
+ signing_key:
247
+ specification_version: 3
248
+ summary: Plugin of codemodels to build models from Ruby code.
249
+ test_files:
250
+ - test/data/012_add_comments_permissions.rb
251
+ - test/data/darcs_adapter.rb
252
+ - test/data/example_of_complex_class.rb
253
+ - test/data/issues_helper_test.rb
254
+ - test/data/status_test.rb
255
+ - test/data/user_custom_field.rb
256
+ - test/helper.rb
257
+ - test/test_assignments.rb
258
+ - test/test_blocks.rb
259
+ - test/test_constants.rb
260
+ - test/test_exception_handling.rb
261
+ - test/test_info.rb
262
+ - test/test_logic.rb
263
+ - test/test_metamodel.rb
264
+ - test/test_modules_and_classes.rb
265
+ - test/test_not_variable_assignements.rb
266
+ - test/test_operations.rb
267
+ - test/test_parsing_complex.rb
268
+ - test/test_parsing_literals.rb
269
+ - test/test_statements.rb
270
+ - test/test_terms_extraction.rb
271
+ - test/test_values_extraction.rb
272
+ - test/test_variables.rb