kuniri 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +43 -0
- data/.rspec +2 -0
- data/.travis.yml +18 -0
- data/.yardopts +1 -0
- data/COPYING +661 -0
- data/Gemfile +14 -0
- data/Guardfile +8 -0
- data/README.md +102 -0
- data/Rakefile +114 -0
- data/bin/kuniri +53 -0
- data/data/attribute_lang.rb +131 -0
- data/data/class_lang.rb +77 -0
- data/data/conditional_lang.rb +71 -0
- data/data/constructor_lang.rb +34 -0
- data/data/end_block_lang.rb +30 -0
- data/data/extern_requirement_lang.rb +45 -0
- data/data/function_behavior_lang.rb +113 -0
- data/data/lang_syntax.rb +111 -0
- data/data/module_namespace_lang.rb +43 -0
- data/data/repetition_lang.rb +62 -0
- data/data/token_lang.rb +55 -0
- data/data/variable_global_lang.rb +118 -0
- data/kuniri.gemspec +24 -0
- data/lib/kuniri/core/configuration/language_available.rb +7 -0
- data/lib/kuniri/core/configuration/log_available.rb +7 -0
- data/lib/kuniri/core/configuration/monitor_available.rb +13 -0
- data/lib/kuniri/core/kuniri.rb +78 -0
- data/lib/kuniri/core/setting.rb +143 -0
- data/lib/kuniri/error/configuration_file_error.rb +12 -0
- data/lib/kuniri/error/language_error.rb +12 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/attribute.rb +73 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/class.rb +51 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/comment.rb +57 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/conditional.rb +42 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/constructor.rb +52 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/end_block.rb +27 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/extern_requirement.rb +36 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/function_behavior.rb +55 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/module_namespace.rb +36 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/repetition.rb +42 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/variable_behaviour.rb +53 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/variable_global.rb +67 -0
- data/lib/kuniri/language/container_data/structured_and_oo/attribute_data.rb +26 -0
- data/lib/kuniri/language/container_data/structured_and_oo/basic_data.rb +18 -0
- data/lib/kuniri/language/container_data/structured_and_oo/class_data.rb +77 -0
- data/lib/kuniri/language/container_data/structured_and_oo/conditional_data.rb +23 -0
- data/lib/kuniri/language/container_data/structured_and_oo/constructor_data.rb +18 -0
- data/lib/kuniri/language/container_data/structured_and_oo/extern_requirement_data.rb +26 -0
- data/lib/kuniri/language/container_data/structured_and_oo/file_element.rb +77 -0
- data/lib/kuniri/language/container_data/structured_and_oo/function_abstract.rb +52 -0
- data/lib/kuniri/language/container_data/structured_and_oo/function_data.rb +21 -0
- data/lib/kuniri/language/container_data/structured_and_oo/method_data.rb +20 -0
- data/lib/kuniri/language/container_data/structured_and_oo/module_namespace_data.rb +18 -0
- data/lib/kuniri/language/container_data/structured_and_oo/repetition_data.rb +23 -0
- data/lib/kuniri/language/container_data/structured_and_oo/variable_global_data.rb +22 -0
- data/lib/kuniri/language/language.rb +222 -0
- data/lib/kuniri/language/language_factory.rb +48 -0
- data/lib/kuniri/language/ruby/attribute_ruby.rb +134 -0
- data/lib/kuniri/language/ruby/class_ruby.rb +83 -0
- data/lib/kuniri/language/ruby/comment_ruby.rb +84 -0
- data/lib/kuniri/language/ruby/conditional_ruby.rb +77 -0
- data/lib/kuniri/language/ruby/constructor_ruby.rb +36 -0
- data/lib/kuniri/language/ruby/end_block_ruby.rb +33 -0
- data/lib/kuniri/language/ruby/extern_requirement_ruby.rb +49 -0
- data/lib/kuniri/language/ruby/function_behavior_ruby.rb +120 -0
- data/lib/kuniri/language/ruby/module_namespace_ruby.rb +47 -0
- data/lib/kuniri/language/ruby/repetition_ruby.rb +68 -0
- data/lib/kuniri/language/ruby/ruby_syntax.rb +117 -0
- data/lib/kuniri/language/ruby/token_ruby.rb +59 -0
- data/lib/kuniri/language/ruby/variable_behaviour_ruby.rb +83 -0
- data/lib/kuniri/language/ruby/variable_global_ruby.rb +123 -0
- data/lib/kuniri/parser/parser.rb +45 -0
- data/lib/kuniri/parser/parser_xml.rb +128 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/attribute_state.rb +51 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/class_state.rb +94 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/comment_state.rb +76 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/conditional_state.rb +92 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/constructor_state.rb +71 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/function_state.rb +82 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/idle_state.rb +80 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/include_state.rb +59 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/method_state.rb +69 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/module_state.rb +79 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/oo_structured_state.rb +92 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/repetition_state.rb +85 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/token_state_machine.rb +8 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/variable_state.rb +49 -0
- data/lib/kuniri/util/html_logger.rb +41 -0
- data/lib/kuniri/util/logger.rb +34 -0
- data/lib/kuniri/util/txt_logger.rb +29 -0
- data/lib/kuniri/version.rb +3 -0
- data/lib/kuniri.rb +5 -0
- data/other/analyseFile.asta +0 -0
- data/spec/core/kuniri_spec.rb +14 -0
- data/spec/core/setting_spec.rb +114 -0
- data/spec/language/abstract_container/attribute_spec.rb +13 -0
- data/spec/language/abstract_container/class_spec.rb +13 -0
- data/spec/language/abstract_container/comment_spec.rb +31 -0
- data/spec/language/abstract_container/conditional_spec.rb +13 -0
- data/spec/language/abstract_container/constructor_spec.rb +13 -0
- data/spec/language/abstract_container/end_block_spec.rb +14 -0
- data/spec/language/abstract_container/module_namespace_spec.rb +13 -0
- data/spec/language/abstract_container/repetition_spec.rb +13 -0
- data/spec/language/container_data/structured_and_oo/attribute_data_spec.rb +32 -0
- data/spec/language/container_data/structured_and_oo/class_data_spec.rb +121 -0
- data/spec/language/container_data/structured_and_oo/conditional_data_spec.rb +34 -0
- data/spec/language/container_data/structured_and_oo/constructor_data_spec.rb +46 -0
- data/spec/language/container_data/structured_and_oo/extern_requirement_data_spec.rb +26 -0
- data/spec/language/container_data/structured_and_oo/file_element_spec.rb +91 -0
- data/spec/language/container_data/structured_and_oo/function_data_spec.rb +22 -0
- data/spec/language/container_data/structured_and_oo/module_namespace_spec.rb +20 -0
- data/spec/language/container_data/structured_and_oo/repetition_data_spec.rb +34 -0
- data/spec/language/container_data/structured_and_oo/variable_global_data_spec.rb +39 -0
- data/spec/language/language_factory_spec.rb +64 -0
- data/spec/language/language_spec.rb +74 -0
- data/spec/language/ruby/attribute_ruby_spec.rb +126 -0
- data/spec/language/ruby/class_ruby_spec.rb +102 -0
- data/spec/language/ruby/comment_ruby_spec.rb +78 -0
- data/spec/language/ruby/conditional_ruby_spec.rb +106 -0
- data/spec/language/ruby/constructor_ruby_spec.rb +57 -0
- data/spec/language/ruby/end_block_ruby_spec.rb +62 -0
- data/spec/language/ruby/function_behavior_ruby_spec.rb +246 -0
- data/spec/language/ruby/module_namespace_ruby_spec.rb +55 -0
- data/spec/language/ruby/repetition_ruby_spec.rb +33 -0
- data/spec/language/ruby/ruby_syntax_spec.rb +482 -0
- data/spec/language/ruby/variable_ruby_spec.rb +134 -0
- data/spec/parser/parser_spec.rb +25 -0
- data/spec/samples/rubySyntaxParts/attribute/simpleAttribute.rb +15 -0
- data/spec/samples/rubySyntaxParts/class/simpleClass.rb +19 -0
- data/spec/samples/rubySyntaxParts/comment/simple_multiple_line_comment_class.rb +33 -0
- data/spec/samples/rubySyntaxParts/comment/simple_multiple_line_comment_global.rb +20 -0
- data/spec/samples/rubySyntaxParts/comment/simple_single_line_comment_class.rb +23 -0
- data/spec/samples/rubySyntaxParts/comment/simple_single_line_comment_global.rb +16 -0
- data/spec/samples/rubySyntaxParts/conditionalStatment/constructorConditional.rb +28 -0
- data/spec/samples/rubySyntaxParts/conditionalStatment/methodConditional.rb +42 -0
- data/spec/samples/rubySyntaxParts/conditionalStatment/nestedConditional.rb +0 -0
- data/spec/samples/rubySyntaxParts/conditionalStatment/simpleConditional.rb +43 -0
- data/spec/samples/rubySyntaxParts/constructor/simpleConstructor.rb +27 -0
- data/spec/samples/rubySyntaxParts/extern/multipleLineExternRequirement.rb +0 -0
- data/spec/samples/rubySyntaxParts/extern/requireRelative.rb +6 -0
- data/spec/samples/rubySyntaxParts/extern/simpleExternRequirement.rb +14 -0
- data/spec/samples/rubySyntaxParts/fullCode/simpleCodeWithConditional.rb +18 -0
- data/spec/samples/rubySyntaxParts/fullCode/simpleFullCode.rb +19 -0
- data/spec/samples/rubySyntaxParts/function/simpleFunction.rb +29 -0
- data/spec/samples/rubySyntaxParts/method/simpleMethod.rb +13 -0
- data/spec/samples/rubySyntaxParts/module/simpleModule.rb +12 -0
- data/spec/samples/rubySyntaxParts/repetition/simpleRepetition.rb +28 -0
- data/spec/samples/rubySyntaxParts/variable/simpleVariable.rb +13 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/state_machine/OO_structured_fsm/attribute_state_spec.rb +44 -0
- data/spec/state_machine/OO_structured_fsm/class_state_spec.rb +90 -0
- data/spec/state_machine/OO_structured_fsm/comment_state_spec.rb +30 -0
- data/spec/state_machine/OO_structured_fsm/conditional_state_spec.rb +83 -0
- data/spec/state_machine/OO_structured_fsm/constructor_state_spec.rb +48 -0
- data/spec/state_machine/OO_structured_fsm/function_state_spec.rb +41 -0
- data/spec/state_machine/OO_structured_fsm/idle_state_spec.rb +101 -0
- data/spec/state_machine/OO_structured_fsm/include_state_spec.rb +62 -0
- data/spec/state_machine/OO_structured_fsm/method_state_spec.rb +42 -0
- data/spec/state_machine/OO_structured_fsm/module_state_spec.rb +54 -0
- data/spec/state_machine/OO_structured_fsm/oo_structured_state_spec.rb +0 -0
- data/spec/state_machine/OO_structured_fsm/repetition_state_spec.rb +83 -0
- data/spec/state_machine/OO_structured_fsm/variable_state_spec.rb +40 -0
- data/spec/util/html_logger_spec.rb +31 -0
- data/spec/util/logger_spec.rb +20 -0
- data/spec/util/txt_logger_spec.rb +31 -0
- metadata +326 -0
@@ -0,0 +1,482 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Languages::RubySyntax do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@syntax = Languages::RubySyntax.new
|
7
|
+
end
|
8
|
+
|
9
|
+
context "Extern requirement detections." do
|
10
|
+
|
11
|
+
it "Correct state transition (require_relative)." do
|
12
|
+
path = "spec/samples/rubySyntaxParts/extern/requireRelative.rb"
|
13
|
+
|
14
|
+
expect(@syntax.state)
|
15
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
16
|
+
|
17
|
+
@syntax.analyse_source(path)
|
18
|
+
|
19
|
+
expect(@syntax.state)
|
20
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "Correct data capture (require_relative)." do
|
24
|
+
path = "spec/samples/rubySyntaxParts/extern/requireRelative.rb"
|
25
|
+
|
26
|
+
@syntax.analyse_source(path)
|
27
|
+
expect(@syntax.fileElements[0].extern_requirements[0].name).to eq ("one")
|
28
|
+
expect(@syntax.fileElements[0].extern_requirements[1].name).to eq ("two")
|
29
|
+
expect(@syntax.fileElements[0].extern_requirements[2].name)
|
30
|
+
.to eq ("three")
|
31
|
+
expect(@syntax.fileElements[0].extern_requirements[3].name)
|
32
|
+
.to eq ("four")
|
33
|
+
expect(@syntax.fileElements[0].extern_requirements[4].name)
|
34
|
+
.to eq ("five")
|
35
|
+
expect(@syntax.fileElements[0].extern_requirements[5].name).to eq ("six")
|
36
|
+
expect(@syntax.fileElements[0].extern_requirements.size).to eq (6)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "Correct state transition (require)." do
|
40
|
+
path = "spec/samples/rubySyntaxParts/extern/simpleExternRequirement.rb"
|
41
|
+
|
42
|
+
expect(@syntax.state)
|
43
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
44
|
+
@syntax.analyse_source(path)
|
45
|
+
expect(@syntax.state)
|
46
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "Correct data capture (require)." do
|
50
|
+
path = "spec/samples/rubySyntaxParts/extern/simpleExternRequirement.rb"
|
51
|
+
|
52
|
+
@syntax.analyse_source(path)
|
53
|
+
expect(@syntax.fileElements[0].extern_requirements[0].name).to eq ("one")
|
54
|
+
expect(@syntax.fileElements[0].extern_requirements[1].name).to eq ("two")
|
55
|
+
expect(@syntax.fileElements[0].extern_requirements[2].name)
|
56
|
+
.to eq ("three")
|
57
|
+
expect(@syntax.fileElements[0].extern_requirements[3].name)
|
58
|
+
.to eq ("four")
|
59
|
+
expect(@syntax.fileElements[0].extern_requirements[4].name)
|
60
|
+
.to eq ("five")
|
61
|
+
expect(@syntax.fileElements[0].extern_requirements[5].name).to eq ("six")
|
62
|
+
expect(@syntax.fileElements[0].extern_requirements[6].name)
|
63
|
+
.to eq ("seven")
|
64
|
+
expect(@syntax.fileElements[0].extern_requirements[7].name)
|
65
|
+
.to eq ("eight")
|
66
|
+
expect(@syntax.fileElements[0].extern_requirements[8].name)
|
67
|
+
.to eq ("nine")
|
68
|
+
expect(@syntax.fileElements[0].extern_requirements.size).to eq (9)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
context "Global variable declarations." do
|
74
|
+
it "Correct state transition" do
|
75
|
+
path = "spec/samples/rubySyntaxParts/variable/simpleVariable.rb"
|
76
|
+
expect(@syntax.state)
|
77
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
78
|
+
@syntax.analyse_source(path)
|
79
|
+
expect(@syntax.state)
|
80
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "Correct data capture (global variable)." do
|
84
|
+
path = "spec/samples/rubySyntaxParts/variable/simpleVariable.rb"
|
85
|
+
|
86
|
+
@syntax.analyse_source(path)
|
87
|
+
expect(@syntax.fileElements[0].global_variables[0].name).to eq("one")
|
88
|
+
expect(@syntax.fileElements[0].global_variables[1].name).to eq("two")
|
89
|
+
expect(@syntax.fileElements[0].global_variables[2].name).to eq("three")
|
90
|
+
expect(@syntax.fileElements[0].global_variables[3].name).to eq("four")
|
91
|
+
expect(@syntax.fileElements[0].global_variables[4].name).to eq("five")
|
92
|
+
expect(@syntax.fileElements[0].global_variables[5].name).to eq("six")
|
93
|
+
expect(@syntax.fileElements[0].global_variables[6].name).to eq("seven")
|
94
|
+
expect(@syntax.fileElements[0].global_variables[7].name).to eq("eight")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "Global function" do
|
99
|
+
it "Correct state transition function." do
|
100
|
+
path = "spec/samples/rubySyntaxParts/function/simpleFunction.rb"
|
101
|
+
expect(@syntax.state)
|
102
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
103
|
+
@syntax.analyse_source(path)
|
104
|
+
expect(@syntax.state)
|
105
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "Correct data capture (global function)" do
|
109
|
+
path = "spec/samples/rubySyntaxParts/function/simpleFunction.rb"
|
110
|
+
|
111
|
+
@syntax.analyse_source(path)
|
112
|
+
expect(@syntax.fileElements[0].global_functions[0].name)
|
113
|
+
.to eq("simpleFunction1")
|
114
|
+
expect(@syntax.fileElements[0].global_functions[1].name)
|
115
|
+
.to eq("simpleFunction2")
|
116
|
+
expect(@syntax.fileElements[0].global_functions[2].name)
|
117
|
+
.to eq("simpleFunction3")
|
118
|
+
expect(@syntax.fileElements[0].global_functions[3].name)
|
119
|
+
.to eq("simpleFunction4")
|
120
|
+
expect(@syntax.fileElements[0].global_functions[4].name)
|
121
|
+
.to eq("simpleFunction5")
|
122
|
+
expect(@syntax.fileElements[0].global_functions[5].name)
|
123
|
+
.to eq("simpleFunction6")
|
124
|
+
expect(@syntax.fileElements[0].global_functions[6].name)
|
125
|
+
.to eq("simpleFunction7")
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context "Module declaration." do
|
130
|
+
it "Correct state transition." do
|
131
|
+
path = "spec/samples/rubySyntaxParts/module/simpleModule.rb"
|
132
|
+
expect(@syntax.state)
|
133
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
134
|
+
@syntax.analyse_source(path)
|
135
|
+
expect(@syntax.state)
|
136
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
137
|
+
end
|
138
|
+
|
139
|
+
it "Correct data capture (module)" do
|
140
|
+
path = "spec/samples/rubySyntaxParts/module/simpleModule.rb"
|
141
|
+
|
142
|
+
@syntax.analyse_source(path)
|
143
|
+
expect(@syntax.fileElements[0].modules[0].name)
|
144
|
+
.to eq("Xpto")
|
145
|
+
expect(@syntax.fileElements[0].modules[1].name)
|
146
|
+
.to eq("Abc")
|
147
|
+
expect(@syntax.fileElements[0].modules[2].name)
|
148
|
+
.to eq("Simple")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context "Class declaration" do
|
153
|
+
it "Correct state transition." do
|
154
|
+
path = "spec/samples/rubySyntaxParts/class/simpleClass.rb"
|
155
|
+
|
156
|
+
expect(@syntax.state)
|
157
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
158
|
+
@syntax.analyse_source(path)
|
159
|
+
expect(@syntax.state)
|
160
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
161
|
+
end
|
162
|
+
|
163
|
+
it "Correct data capture (class)." do
|
164
|
+
path = "spec/samples/rubySyntaxParts/class/simpleClass.rb"
|
165
|
+
|
166
|
+
@syntax.analyse_source(path)
|
167
|
+
expect(@syntax.fileElements[0].classes[0].name).to eq("Simple1")
|
168
|
+
expect(@syntax.fileElements[0].classes[1].name).to eq("Simple2")
|
169
|
+
expect(@syntax.fileElements[0].classes[2].name).to eq("Simple3")
|
170
|
+
expect(@syntax.fileElements[0].classes[3].name).to eq("Simple4")
|
171
|
+
expect(@syntax.fileElements[0].classes[4].name).to eq("Simple5")
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
context "Attribute line" do
|
177
|
+
it "Correct state transition." do
|
178
|
+
path = "spec/samples/rubySyntaxParts/attribute/simpleAttribute.rb"
|
179
|
+
|
180
|
+
expect(@syntax.state)
|
181
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
182
|
+
@syntax.analyse_source(path)
|
183
|
+
expect(@syntax.state)
|
184
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
185
|
+
end
|
186
|
+
|
187
|
+
it "Correct data capture (attribute)" do
|
188
|
+
path = "spec/samples/rubySyntaxParts/attribute/simpleAttribute.rb"
|
189
|
+
|
190
|
+
@syntax.analyse_source(path)
|
191
|
+
expect(@syntax.fileElements[0].classes[0].attributes[0].name)
|
192
|
+
.to eq("attribute1")
|
193
|
+
expect(@syntax.fileElements[0].classes[0].attributes[1].name)
|
194
|
+
.to eq("attribute2")
|
195
|
+
expect(@syntax.fileElements[0].classes[0].attributes[2].name)
|
196
|
+
.to eq("attribute3")
|
197
|
+
expect(@syntax.fileElements[0].classes[0].attributes[3].name)
|
198
|
+
.to eq("attribute4")
|
199
|
+
expect(@syntax.fileElements[0].classes[0].attributes[4].name)
|
200
|
+
.to eq("attribute5")
|
201
|
+
expect(@syntax.fileElements[0].classes[0].attributes[5].name)
|
202
|
+
.to eq("attribute6")
|
203
|
+
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
context "Method line" do
|
208
|
+
it "Correct state transition." do
|
209
|
+
path = "spec/samples/rubySyntaxParts/method/simpleMethod.rb"
|
210
|
+
|
211
|
+
expect(@syntax.state)
|
212
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
213
|
+
@syntax.analyse_source(path)
|
214
|
+
expect(@syntax.state)
|
215
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
216
|
+
end
|
217
|
+
|
218
|
+
it "Correct data capture (method)" do
|
219
|
+
path = "spec/samples/rubySyntaxParts/method/simpleMethod.rb"
|
220
|
+
|
221
|
+
@syntax.analyse_source(path)
|
222
|
+
expect(@syntax.fileElements[0].classes[0].methods[0].name)
|
223
|
+
.to eq("method1")
|
224
|
+
expect(@syntax.fileElements[0].classes[0].methods[1].name)
|
225
|
+
.to eq("method2")
|
226
|
+
expect(@syntax.fileElements[0].classes[0].methods[2].name)
|
227
|
+
.to eq("method3")
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
context "Constructor line" do
|
232
|
+
it "Correct state transition." do
|
233
|
+
path = "spec/samples/rubySyntaxParts/constructor/simpleConstructor.rb"
|
234
|
+
|
235
|
+
expect(@syntax.state)
|
236
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
237
|
+
@syntax.analyse_source(path)
|
238
|
+
expect(@syntax.state)
|
239
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
240
|
+
end
|
241
|
+
|
242
|
+
it "Correct data capture (constructor)" do
|
243
|
+
path = "spec/samples/rubySyntaxParts/constructor/simpleConstructor.rb"
|
244
|
+
|
245
|
+
@syntax.analyse_source(path)
|
246
|
+
expect(@syntax.fileElements[0].classes[0].constructors[0].name)
|
247
|
+
.to eq("initialize")
|
248
|
+
expect(@syntax.fileElements[0].classes[1].constructors[0].name)
|
249
|
+
.to eq("initialize")
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
context "Conditional line" do
|
254
|
+
it "Correct state transition (Global function)." do
|
255
|
+
path =
|
256
|
+
"spec/samples/rubySyntaxParts/conditionalStatment/simpleConditional.rb"
|
257
|
+
|
258
|
+
expect(@syntax.state)
|
259
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
260
|
+
@syntax.analyse_source(path)
|
261
|
+
expect(@syntax.state)
|
262
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
263
|
+
end
|
264
|
+
|
265
|
+
it "Correct data capture (conditional - Global function)" do
|
266
|
+
path =
|
267
|
+
"spec/samples/rubySyntaxParts/conditionalStatment/simpleConditional.rb"
|
268
|
+
|
269
|
+
@syntax.analyse_source(path)
|
270
|
+
expect(@syntax.fileElements[0].global_functions[0].name)
|
271
|
+
.to eq("simple1")
|
272
|
+
|
273
|
+
expect(@syntax.fileElements[0].global_functions[0]
|
274
|
+
.conditionals[0].expression).to eq("3 > 2")
|
275
|
+
expect(@syntax.fileElements[0].global_functions[0]
|
276
|
+
.conditionals[0].type).to eq("IF")
|
277
|
+
|
278
|
+
expect(@syntax.fileElements[0].global_functions[1].name)
|
279
|
+
.to eq("simple2")
|
280
|
+
expect(@syntax.fileElements[0].global_functions[1]
|
281
|
+
.conditionals[0].expression).to eq("7 > 2")
|
282
|
+
expect(@syntax.fileElements[0].global_functions[1]
|
283
|
+
.conditionals[0].type).to eq("IF")
|
284
|
+
|
285
|
+
expect(@syntax.fileElements[0].global_functions[1]
|
286
|
+
.conditionals[1].expression).to eq("\"a\" < \"k\"")
|
287
|
+
expect(@syntax.fileElements[0].global_functions[1]
|
288
|
+
.conditionals[1].type).to eq("IF")
|
289
|
+
end
|
290
|
+
|
291
|
+
it "Correct state transition (Method)." do
|
292
|
+
path =
|
293
|
+
"spec/samples/rubySyntaxParts/conditionalStatment/methodConditional.rb"
|
294
|
+
|
295
|
+
expect(@syntax.state)
|
296
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
297
|
+
@syntax.analyse_source(path)
|
298
|
+
expect(@syntax.state)
|
299
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
300
|
+
end
|
301
|
+
|
302
|
+
it "Correct data capture (conditional - method)" do
|
303
|
+
path =
|
304
|
+
"spec/samples/rubySyntaxParts/conditionalStatment/methodConditional.rb"
|
305
|
+
|
306
|
+
@syntax.analyse_source(path)
|
307
|
+
expect(@syntax.fileElements[0].classes[0].methods[0].name)
|
308
|
+
.to eq("method1")
|
309
|
+
|
310
|
+
expect(@syntax.fileElements[0].classes[0].methods[0].conditionals[0]
|
311
|
+
.expression).to eq("x > 3")
|
312
|
+
expect(@syntax.fileElements[0].classes[0].methods[0].conditionals[0]
|
313
|
+
.type).to eq("IF")
|
314
|
+
|
315
|
+
expect(@syntax.fileElements[0].classes[0].methods[1].name)
|
316
|
+
.to eq("method2")
|
317
|
+
expect(@syntax.fileElements[0].classes[0].methods[1].conditionals[0]
|
318
|
+
.expression).to eq("b && c")
|
319
|
+
expect(@syntax.fileElements[0].classes[0].methods[1].conditionals[0]
|
320
|
+
.type).to eq("IF")
|
321
|
+
|
322
|
+
expect(@syntax.fileElements[0].classes[0].methods[2].name)
|
323
|
+
.to eq("method3")
|
324
|
+
expect(@syntax.fileElements[0].classes[0].methods[2].conditionals[0]
|
325
|
+
.expression).to eq("b == 3")
|
326
|
+
expect(@syntax.fileElements[0].classes[0].methods[2].conditionals[1]
|
327
|
+
.expression).to eq("b < 7")
|
328
|
+
|
329
|
+
expect(@syntax.fileElements[0].classes[0].methods[2].conditionals[0]
|
330
|
+
.type).to eq("IF")
|
331
|
+
|
332
|
+
expect(@syntax.fileElements[0].classes[0].methods[3].name)
|
333
|
+
.to eq("method4")
|
334
|
+
expect(@syntax.fileElements[0].classes[0].methods[3].conditionals[0]
|
335
|
+
.expression).to eq("x")
|
336
|
+
end
|
337
|
+
|
338
|
+
it "Correct state transition (Constructor)." do
|
339
|
+
path =
|
340
|
+
"spec/samples/rubySyntaxParts/conditionalStatment/constructorConditional.rb"
|
341
|
+
|
342
|
+
expect(@syntax.state)
|
343
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
344
|
+
@syntax.analyse_source(path)
|
345
|
+
expect(@syntax.state)
|
346
|
+
.to be_instance_of(StateMachine::OOStructuredFSM::IdleState)
|
347
|
+
end
|
348
|
+
|
349
|
+
it "Correct data capture (conditional - method)" do
|
350
|
+
path =
|
351
|
+
"spec/samples/rubySyntaxParts/conditionalStatment/constructorConditional.rb"
|
352
|
+
|
353
|
+
@syntax.analyse_source(path)
|
354
|
+
expect(@syntax.fileElements[0].classes[0].constructors[0].name)
|
355
|
+
.to eq("initialize")
|
356
|
+
|
357
|
+
expect(@syntax.fileElements[0].classes[0].constructors[0].conditionals[0]
|
358
|
+
.expression).to eq("a > b")
|
359
|
+
expect(@syntax.fileElements[0].classes[0].constructors[0].conditionals[0]
|
360
|
+
.type).to eq("IF")
|
361
|
+
|
362
|
+
expect(@syntax.fileElements[0].classes[0].constructors[0].conditionals[1]
|
363
|
+
.expression).to eq("x")
|
364
|
+
expect(@syntax.fileElements[0].classes[0].constructors[0].conditionals[1]
|
365
|
+
.type).to eq("CASE")
|
366
|
+
|
367
|
+
expect(@syntax.fileElements[0].classes[0].constructors[0].conditionals[2]
|
368
|
+
.expression).to eq("u && y")
|
369
|
+
expect(@syntax.fileElements[0].classes[0].constructors[0].conditionals[2]
|
370
|
+
.type).to eq("IF")
|
371
|
+
|
372
|
+
expect(@syntax.fileElements[0].classes[0].constructors[0].conditionals[3]
|
373
|
+
.expression).to eq("u == 1")
|
374
|
+
expect(@syntax.fileElements[0].classes[0].constructors[0].conditionals[3]
|
375
|
+
.type).to eq("ELSIF")
|
376
|
+
end
|
377
|
+
|
378
|
+
it "Correct data capture (repetition[while] - Method)" do
|
379
|
+
path = "spec/samples/rubySyntaxParts/repetition/simpleRepetition.rb"
|
380
|
+
|
381
|
+
@syntax.analyse_source(path)
|
382
|
+
expect(@syntax.fileElements[0].classes[0].methods[0].name)
|
383
|
+
.to eq("simple1")
|
384
|
+
|
385
|
+
expect(@syntax.fileElements[0].classes[0].methods[0].repetitions[0]
|
386
|
+
.expression).to eq("i < num")
|
387
|
+
end
|
388
|
+
|
389
|
+
it "Correct data capture (repetiton[util] - Method)" do
|
390
|
+
path = "spec/samples/rubySyntaxParts/repetition/simpleRepetition.rb"
|
391
|
+
|
392
|
+
@syntax.analyse_source(path)
|
393
|
+
expect(@syntax.fileElements[0].classes[0].methods[1].name)
|
394
|
+
.to eq("simple2")
|
395
|
+
|
396
|
+
expect(@syntax.fileElements[0].classes[0].methods[1].repetitions[0]
|
397
|
+
.expression).to eq("i > num")
|
398
|
+
|
399
|
+
end
|
400
|
+
|
401
|
+
it "Correct data capture (repetition[for] - Method)" do
|
402
|
+
path = "spec/samples/rubySyntaxParts/repetition/simpleRepetition.rb"
|
403
|
+
|
404
|
+
@syntax.analyse_source(path)
|
405
|
+
expect(@syntax.fileElements[0].classes[0].methods[1].name)
|
406
|
+
.to eq("simple2")
|
407
|
+
|
408
|
+
expect(@syntax.fileElements[0].classes[0].methods[1].repetitions[1]
|
409
|
+
.expression).to eq("i in 0..5")
|
410
|
+
end
|
411
|
+
|
412
|
+
end
|
413
|
+
|
414
|
+
context "Comments" do
|
415
|
+
|
416
|
+
it "Correct single line comment capture - Globals" do
|
417
|
+
|
418
|
+
path = "spec/samples/rubySyntaxParts/comment/simple_single_line_comment_global.rb"
|
419
|
+
|
420
|
+
@syntax.analyse_source(path)
|
421
|
+
expect(@syntax.fileElements[0].comments).to eq(" First comment\n")
|
422
|
+
expect(@syntax.fileElements[0].global_functions[0].comments)
|
423
|
+
.to eq(" Comment 2\n")
|
424
|
+
expect(@syntax.fileElements[0].global_functions[1].comments)
|
425
|
+
.to eq(" Combo comment p1\n Combo comment p2\n")
|
426
|
+
expect(@syntax.fileElements[0].global_variables[0].comments)
|
427
|
+
.to eq(" Comment 4\n")
|
428
|
+
end
|
429
|
+
|
430
|
+
it "Correct single line comment capture - Class" do
|
431
|
+
|
432
|
+
path = "spec/samples/rubySyntaxParts/comment/simple_single_line_comment_class.rb"
|
433
|
+
|
434
|
+
@syntax.analyse_source(path)
|
435
|
+
expect(@syntax.fileElements[0].classes[0].comments)
|
436
|
+
.to eq(" Comment 1: class\n")
|
437
|
+
expect(@syntax.fileElements[0].classes[0].constructors[0].comments)
|
438
|
+
.to eq(" Comment 2: constructor\n")
|
439
|
+
expect(@syntax.fileElements[0].classes[0].methods[0].comments)
|
440
|
+
.to eq(" Comment 3: method\n")
|
441
|
+
expect(@syntax.fileElements[0].classes[0].methods[1].comments)
|
442
|
+
.to eq(" Comment 4: Combo 1\n Comment 5: Combo 2\n")
|
443
|
+
expect(@syntax.fileElements[0].classes[0].attributes[0].comments)
|
444
|
+
.to eq (" Comment 6: Attribute\n")
|
445
|
+
end
|
446
|
+
|
447
|
+
it "Correct multiple line comment capture - Global" do
|
448
|
+
|
449
|
+
path = "spec/samples/rubySyntaxParts/comment/simple_multiple_line_comment_global.rb"
|
450
|
+
|
451
|
+
@syntax.analyse_source(path)
|
452
|
+
expect(@syntax.fileElements[0].comments)
|
453
|
+
.to eq("Comment 1:\nMultiple line.\n")
|
454
|
+
expect(@syntax.fileElements[0].global_functions[0].comments)
|
455
|
+
.to eq("Global Function\nnumber one\nmultiple line\n")
|
456
|
+
expect(@syntax.fileElements[0].global_variables[0].comments)
|
457
|
+
.to eq("global\n")
|
458
|
+
end
|
459
|
+
|
460
|
+
it "Correct multiple line comment capture - Class" do
|
461
|
+
|
462
|
+
path = "spec/samples/rubySyntaxParts/comment/simple_multiple_line_comment_class.rb"
|
463
|
+
|
464
|
+
@syntax.analyse_source(path)
|
465
|
+
expect(@syntax.fileElements[0].classes[0].comments)
|
466
|
+
.to eq("This is the\nfirst class\nof this file.\n")
|
467
|
+
expect(@syntax.fileElements[0].classes[0].constructors[0].comments)
|
468
|
+
.to eq(" Constructor\n initialize\n")
|
469
|
+
expect(@syntax.fileElements[0].classes[0].methods[0].comments)
|
470
|
+
.to eq(" First method\n")
|
471
|
+
expect(@syntax.fileElements[0].classes[0].methods[1].comments)
|
472
|
+
.to eq(" methodTwo\n")
|
473
|
+
|
474
|
+
end
|
475
|
+
|
476
|
+
end
|
477
|
+
|
478
|
+
after :each do
|
479
|
+
@syntax = nil
|
480
|
+
end
|
481
|
+
|
482
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Languages::Ruby::VariableGlobalRuby do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
@variableRuby = Languages::Ruby::VariableGlobalRuby.new
|
7
|
+
end
|
8
|
+
|
9
|
+
context "Simple variable (one per line)" do
|
10
|
+
|
11
|
+
it "Capture simple variable." do
|
12
|
+
variable = @variableRuby.get_variable("one = 1")
|
13
|
+
expect(variable[0].name).to eq("one")
|
14
|
+
#expect(variable[0].value).to eq("1")
|
15
|
+
|
16
|
+
variable = @variableRuby.get_variable(" two = 2")
|
17
|
+
expect(variable[0].name).to eq("two")
|
18
|
+
#expect(variable[0].value).to eq("2")
|
19
|
+
|
20
|
+
variable = @variableRuby.get_variable("three = 'three_value'")
|
21
|
+
expect(variable[0].name).to eq("three")
|
22
|
+
#expect(variable[0].value).to eq("three_value")
|
23
|
+
|
24
|
+
variable = @variableRuby.get_variable("four = []")
|
25
|
+
expect(variable[0].name).to eq("four")
|
26
|
+
#expect(variable[0].value).to eq("[]")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "Capture simple variable with one @" do
|
30
|
+
variable = @variableRuby.get_variable("@one")
|
31
|
+
expect(variable[0].name).to eq("one")
|
32
|
+
|
33
|
+
variable = @variableRuby.get_variable("@four = 'four_value'")
|
34
|
+
expect(variable[0].name).to eq("four")
|
35
|
+
#expect(variable[0].value).to eq("four_value")
|
36
|
+
|
37
|
+
variable = @variableRuby.get_variable(" @five = 5")
|
38
|
+
expect(variable[0].name).to eq("five")
|
39
|
+
#expect(variable[0].value).to eq("5")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "Capture simple variable with two @@" do
|
43
|
+
variable = @variableRuby.get_variable("@@three")
|
44
|
+
expect(variable[0].name).to eq("three")
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
context "Special case" do
|
50
|
+
|
51
|
+
it "Ruby multiple line comment - =begin" do
|
52
|
+
variable = @variableRuby.get_variable("=begin")
|
53
|
+
expect(variable).to eq(nil)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
RSpec.shared_examples "Compare array" do |lineInput, arrayComp, description|
|
59
|
+
|
60
|
+
it ": #{description}" do
|
61
|
+
listResult = []
|
62
|
+
capturedList = @variableRuby.get_variable(lineInput)
|
63
|
+
capturedList.each do |element|
|
64
|
+
listResult.push(element.name)
|
65
|
+
end
|
66
|
+
expect(listResult).to match_array(arrayComp)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "Complex variable declaration (more then one per line)." do
|
71
|
+
lineParse = "one = 1, two = 2, three = 'three'"
|
72
|
+
arrayCompare = ["one", "two", "three"]
|
73
|
+
message = " -> Multiple variable in line WITH = and WITHOUT @."
|
74
|
+
include_examples "Compare array", lineParse, arrayCompare, message
|
75
|
+
|
76
|
+
lineParse = " one = 1, two=2, three = 'three' "
|
77
|
+
arrayCompare = ["one", "two", "three"]
|
78
|
+
message = " -> Multiple variable in line WITH = and WITHOUT @. (Not nice)"
|
79
|
+
include_examples "Compare array", lineParse, arrayCompare, message
|
80
|
+
|
81
|
+
lineParse = "@one, @two, @three"
|
82
|
+
arrayCompare = ["one", "two", "three"]
|
83
|
+
message = " -> Multiple variable in line ONLY WITH , and @."
|
84
|
+
include_examples "Compare array", lineParse, arrayCompare, message
|
85
|
+
|
86
|
+
lineParse = " @one , @two , @three "
|
87
|
+
arrayCompare = ["one", "two", "three"]
|
88
|
+
message = " -> Multiple variable in line ONLY WITH , and @. (Not nice)"
|
89
|
+
include_examples "Compare array", lineParse, arrayCompare, message
|
90
|
+
|
91
|
+
lineParse = "@one = 1, @two = 2, @three = 'three'"
|
92
|
+
arrayCompare = ["one", "two", "three"]
|
93
|
+
message = " -> Multiple variable in line WITH = and @."
|
94
|
+
include_examples "Compare array", lineParse, arrayCompare, message
|
95
|
+
|
96
|
+
lineParse = " @one = 1, @two =2 ,@three = 'three'"
|
97
|
+
arrayCompare = ["one", "two", "three"]
|
98
|
+
message = " -> Multiple variable in line WITH = and @. (Not nice)"
|
99
|
+
include_examples "Compare array", lineParse, arrayCompare, message
|
100
|
+
|
101
|
+
lineParse = " @one, @two = 3,@three "
|
102
|
+
arrayCompare = ["one", "two", "three"]
|
103
|
+
message = " -> Multiple variable in line WITH = and @. (Mixed)"
|
104
|
+
include_examples "Compare array", lineParse, arrayCompare, message
|
105
|
+
|
106
|
+
#it "Multiple declaration with assignment, simple case." do
|
107
|
+
lineParse = "one = two = three = 47"
|
108
|
+
arrayCompare = ["one", "two", "three"]
|
109
|
+
message = " -> Multiple variable ONLY WITH ="
|
110
|
+
include_examples "Compare array", lineParse, arrayCompare, message
|
111
|
+
|
112
|
+
lineParse = "one =two = three = 47"
|
113
|
+
arrayCompare = ["one", "two", "three"]
|
114
|
+
message = " -> Multiple variable ONLY WITH =. (Not nice)"
|
115
|
+
include_examples "Compare array", lineParse, arrayCompare, message
|
116
|
+
#end
|
117
|
+
|
118
|
+
lineParse = "@one = @two = @three = 59"
|
119
|
+
arrayCompare = ["one", "two", "three"]
|
120
|
+
message = " -> Multiple variable WITH = and @"
|
121
|
+
include_examples "Compare array", lineParse, arrayCompare, message
|
122
|
+
|
123
|
+
lineParse = " @one = @two = @three = 89 "
|
124
|
+
arrayCompare = ["one", "two", "three"]
|
125
|
+
message = " -> Multiple variable WITH = and @. (Not nice)"
|
126
|
+
include_examples "Compare array", lineParse, arrayCompare, message
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
after :all do
|
131
|
+
@variableRuby = nil
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Parser::Parser do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@filesProject = Dir[File.join("./", "**", "**.rb")]
|
7
|
+
@parser = Parser::Parser.new(@filesProject)
|
8
|
+
end
|
9
|
+
|
10
|
+
context "When start, find all the ruby files" do
|
11
|
+
it "Always get a list" do
|
12
|
+
expect(@parser.fileLanguage).to eq([])
|
13
|
+
end
|
14
|
+
|
15
|
+
it "Total of files to parse" do
|
16
|
+
@parser.start_parser
|
17
|
+
expect(@parser.fileLanguage.size).to eq(@filesProject.size)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
after :each do
|
22
|
+
@parser = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|