rtext 0.8.0 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +108 -84
- data/RText_Protocol +47 -4
- data/Rakefile +39 -46
- data/lib/rtext/context_builder.rb +49 -8
- data/lib/rtext/default_completer.rb +212 -163
- data/lib/rtext/default_service_provider.rb +3 -3
- data/lib/rtext/frontend/connector.rb +120 -53
- data/lib/rtext/frontend/context.rb +12 -12
- data/lib/rtext/instantiator.rb +11 -3
- data/lib/rtext/language.rb +5 -5
- data/lib/rtext/serializer.rb +1 -1
- data/lib/rtext/service.rb +264 -253
- data/lib/rtext/tokenizer.rb +1 -1
- data/test/completer_test.rb +606 -606
- data/test/context_builder_test.rb +952 -948
- data/test/frontend/context_test.rb +301 -205
- data/test/instantiator_test.rb +1773 -1691
- data/test/integration/model/test_metamodel3.ect4 +7 -0
- data/test/integration/test.rb +974 -918
- data/test/link_detector_test.rb +287 -287
- data/test/message_helper_test.rb +116 -118
- data/test/serializer_test.rb +1023 -1004
- data/test/tokenizer_test.rb +173 -173
- metadata +18 -19
- data/test/integration/backend.out +0 -13
- data/test/integration/frontend.log +0 -36049
data/test/link_detector_test.rb
CHANGED
@@ -1,287 +1,287 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
2
|
-
|
3
|
-
require '
|
4
|
-
require 'rgen/metamodel_builder'
|
5
|
-
require 'rtext/language'
|
6
|
-
require 'rtext/link_detector'
|
7
|
-
|
8
|
-
class LinkDetectorTest < Test
|
9
|
-
|
10
|
-
module TestMM
|
11
|
-
extend RGen::MetamodelBuilder::ModuleExtension
|
12
|
-
class TestNode2 < RGen::MetamodelBuilder::MMBase
|
13
|
-
has_attr 'name', String
|
14
|
-
end
|
15
|
-
class TestNode < RGen::MetamodelBuilder::MMBase
|
16
|
-
has_attr 'name', String
|
17
|
-
has_attr 'id', Integer
|
18
|
-
has_one 'related', TestNode
|
19
|
-
has_many 'others', TestNode
|
20
|
-
contains_many 'children', TestNode2, 'parent'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_before_command
|
25
|
-
ld = build_link_desc TestMM, <<-END
|
26
|
-
|TestNode SomeNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
27
|
-
END
|
28
|
-
assert_link_desc ld, :element => "TestNode", :feature => nil, :backward => true, :value => "TestNode", :scol => 1, :ecol => 8
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_in_command
|
32
|
-
ld = build_link_desc TestMM, <<-END
|
33
|
-
Test|Node SomeNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
34
|
-
END
|
35
|
-
assert_link_desc ld, :element => "TestNode", :feature => nil, :backward => true, :value => "TestNode", :scol => 1, :ecol => 8
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_end_of_command
|
39
|
-
ld = build_link_desc TestMM, <<-END
|
40
|
-
TestNod|e SomeNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
41
|
-
END
|
42
|
-
assert_link_desc ld, :element => "TestNode", :feature => nil, :backward => true, :value => "TestNode", :scol => 1, :ecol => 8
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_after_command
|
46
|
-
ld = build_link_desc TestMM, <<-END
|
47
|
-
TestNode| SomeNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
48
|
-
END
|
49
|
-
assert_nil ld
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_in_name
|
53
|
-
ld = build_link_desc TestMM, <<-END
|
54
|
-
TestNode So|meNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
55
|
-
END
|
56
|
-
assert_link_desc ld, :element => "TestNode", :feature => "name", :index => 0, :backward => false, :value => "SomeNode", :scol => 10, :ecol => 17
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_in_name_with_quotes
|
60
|
-
ld = build_link_desc TestMM, <<-END
|
61
|
-
TestNode "So|meNode", id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
62
|
-
END
|
63
|
-
assert_link_desc ld, :element => "TestNode", :feature => "name", :index => 0, :backward => false, :value => "SomeNode", :scol => 10, :ecol => 19
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_after_comma
|
67
|
-
ld = build_link_desc TestMM, <<-END
|
68
|
-
TestNode SomeNode,| id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
69
|
-
END
|
70
|
-
assert_nil ld
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_after_label
|
74
|
-
ld = build_link_desc TestMM, <<-END
|
75
|
-
TestNode SomeNode, id:| 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
76
|
-
END
|
77
|
-
assert_nil ld
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_beginning_of_labled_argument
|
81
|
-
ld = build_link_desc TestMM, <<-END
|
82
|
-
TestNode SomeNode, id: |1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
83
|
-
END
|
84
|
-
assert_link_desc ld, :element => "TestNode", :feature => "id", :index => 0, :backward => false, :value => 1234, :scol => 24, :ecol => 27
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_in_labled_argument
|
88
|
-
ld = build_link_desc TestMM, <<-END
|
89
|
-
TestNode SomeNode, id: 123|4, related: /Other/Node, others: [/NodeA, /Node/B]
|
90
|
-
END
|
91
|
-
assert_link_desc ld, :element => "TestNode", :feature => "id", :index => 0, :backward => false, :value => 1234, :scol => 24, :ecol => 27
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_after_labled_argument
|
95
|
-
ld = build_link_desc TestMM, <<-END
|
96
|
-
TestNode SomeNode, id: 1234|, related: /Other/Node, others: [/NodeA, /Node/B]
|
97
|
-
END
|
98
|
-
assert_nil ld
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_in_label
|
102
|
-
ld = build_link_desc TestMM, <<-END
|
103
|
-
TestNode SomeNode, id: 1234, re|lated: /Other/Node, others: [/NodeA, /Node/B]
|
104
|
-
END
|
105
|
-
assert_nil ld
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_in_reference
|
109
|
-
ld = build_link_desc TestMM, <<-END
|
110
|
-
TestNode SomeNode, id: 1234, related: /O|ther/Node, others: [/NodeA, /Node/B]
|
111
|
-
END
|
112
|
-
assert_link_desc ld, :element => "TestNode", :feature => "related", :index => 0, :backward => false, :value => "/Other/Node", :scol => 39, :ecol => 49
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_before_array
|
116
|
-
ld = build_link_desc TestMM, <<-END
|
117
|
-
TestNode SomeNode, id: 1234, related: /Other/Node, others: |[/NodeA, /Node/B]
|
118
|
-
END
|
119
|
-
assert_nil ld
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_ref_in_array
|
123
|
-
ld = build_link_desc TestMM, <<-END
|
124
|
-
TestNode SomeNode, id: 1234, related: /Other/Node, others: [|/NodeA, /Node/B]
|
125
|
-
END
|
126
|
-
assert_link_desc ld, :element => "TestNode", :feature => "others", :index => 0, :backward => false, :value => "/NodeA", :scol => 61, :ecol => 66
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_second_ref_in_array
|
130
|
-
ld = build_link_desc TestMM, <<-END
|
131
|
-
TestNode SomeNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/|B]
|
132
|
-
END
|
133
|
-
assert_link_desc ld, :element => "TestNode", :feature => "others", :index => 1, :backward => false, :value => "/Node/B", :scol => 69, :ecol => 75
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_backward_ref_name_in_command
|
137
|
-
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
138
|
-
|TestNode SomeNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
139
|
-
END
|
140
|
-
)
|
141
|
-
assert_link_desc ld, :element => "TestNode", :feature => nil, :backward => false, :value => "TestNode", :scol => 1, :ecol => 8
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_backward_ref_name_in_name
|
145
|
-
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
146
|
-
TestNode Som|eNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
147
|
-
END
|
148
|
-
)
|
149
|
-
assert_link_desc ld, :element => "TestNode", :feature => "name", :index => 0, :backward => true, :value => "SomeNode", :scol => 10, :ecol => 17
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_backward_ref_name_with_quotes
|
153
|
-
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
154
|
-
TestNode "Som|eNode", id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
155
|
-
END
|
156
|
-
)
|
157
|
-
assert_link_desc ld, :element => "TestNode", :feature => "name", :index => 0, :backward => true, :value => "SomeNode", :scol => 10, :ecol => 19
|
158
|
-
end
|
159
|
-
|
160
|
-
def test_backward_ref_id_in_id
|
161
|
-
ld = build_link_desc(TestMM, {:backward_ref => "id"}, <<-END
|
162
|
-
TestNode SomeNode, id: |1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
163
|
-
END
|
164
|
-
)
|
165
|
-
assert_link_desc ld, :element => "TestNode", :feature => "id", :index => 0, :backward => true, :value => 1234, :scol => 24, :ecol => 27
|
166
|
-
end
|
167
|
-
|
168
|
-
def test_command_only
|
169
|
-
ld = build_link_desc(TestMM, <<-END
|
170
|
-
Tes|tNode
|
171
|
-
END
|
172
|
-
)
|
173
|
-
assert_link_desc ld, :element => "TestNode", :feature => nil, :backward => true, :value => "TestNode", :scol => 1, :ecol => 8
|
174
|
-
end
|
175
|
-
|
176
|
-
def test_command_and_name_only
|
177
|
-
ld = build_link_desc(TestMM, <<-END
|
178
|
-
TestNode |SomeNode
|
179
|
-
END
|
180
|
-
)
|
181
|
-
assert_link_desc ld, :element => "TestNode", :feature => "name", :index => 0, :backward => false, :value => "SomeNode", :scol => 10, :ecol => 17
|
182
|
-
end
|
183
|
-
|
184
|
-
def test_command_and_name_only_backward_ref_name
|
185
|
-
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
186
|
-
TestNode |SomeNode
|
187
|
-
END
|
188
|
-
)
|
189
|
-
assert_link_desc ld, :element => "TestNode", :feature => "name", :index => 0, :backward => true, :value => "SomeNode", :scol => 10, :ecol => 17
|
190
|
-
end
|
191
|
-
|
192
|
-
def test_command_and_name_curly_no_ws
|
193
|
-
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
194
|
-
TestNode Some|Node{
|
195
|
-
END
|
196
|
-
)
|
197
|
-
assert_link_desc ld, :element => "TestNode", :element_name => "SomeNode", :feature => "name", :index => 0, :backward => true, :value => "SomeNode", :scol => 10, :ecol => 17
|
198
|
-
end
|
199
|
-
|
200
|
-
def test_child_within_command
|
201
|
-
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
202
|
-
TestNode SomeNode {
|
203
|
-
Test|Node2 SomeOtherNode
|
204
|
-
END
|
205
|
-
)
|
206
|
-
assert_link_desc ld, :element => "TestNode2", :feature => nil, :backward => false, :value => "TestNode2", :scol => 3, :ecol => 11
|
207
|
-
end
|
208
|
-
|
209
|
-
def test_child_with_label_after_command
|
210
|
-
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
211
|
-
TestNode SomeNode {
|
212
|
-
children:
|
213
|
-
TestNode2 |SomeOtherNode
|
214
|
-
END
|
215
|
-
)
|
216
|
-
assert_link_desc ld, :element => "TestNode2", :feature => "name", :index => 0, :backward => true, :value => "SomeOtherNode", :scol => 15, :ecol => 27
|
217
|
-
end
|
218
|
-
|
219
|
-
def test_child_with_label_within_command
|
220
|
-
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
221
|
-
TestNode SomeNode {
|
222
|
-
children:
|
223
|
-
Test|Node2 SomeOtherNode
|
224
|
-
END
|
225
|
-
)
|
226
|
-
assert_link_desc ld, :element => "TestNode2", :feature => nil, :backward => false, :value => "TestNode2", :scol => 5, :ecol => 13
|
227
|
-
end
|
228
|
-
|
229
|
-
def test_child_with_label_within_command_square_brackets
|
230
|
-
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
231
|
-
TestNode SomeNode {
|
232
|
-
children: [
|
233
|
-
Test|Node2 SomeOtherNode
|
234
|
-
END
|
235
|
-
)
|
236
|
-
assert_link_desc ld, :element => "TestNode2", :feature => nil, :backward => false, :value => "TestNode2", :scol => 5, :ecol => 13
|
237
|
-
end
|
238
|
-
|
239
|
-
def build_link_desc(mm, text, text2=nil)
|
240
|
-
if text.is_a?(Hash)
|
241
|
-
options = text
|
242
|
-
context_lines = text2.split("\n")
|
243
|
-
else
|
244
|
-
options = {}
|
245
|
-
context_lines = text.split("\n")
|
246
|
-
end
|
247
|
-
pos_in_line = context_lines.last.index("|")+1
|
248
|
-
context_lines.last.sub!("|", "")
|
249
|
-
lang = RText::Language.new(mm.ecore,
|
250
|
-
:unlabled_arguments => proc {|c| ["name"]},
|
251
|
-
:backward_ref_attribute => proc {|c|
|
252
|
-
if options[:backward_ref]
|
253
|
-
options[:backward_ref]
|
254
|
-
else
|
255
|
-
nil
|
256
|
-
end
|
257
|
-
})
|
258
|
-
RText::LinkDetector.new(lang).detect(context_lines, pos_in_line)
|
259
|
-
end
|
260
|
-
|
261
|
-
def assert_link_desc(ld, options)
|
262
|
-
if options[:element]
|
263
|
-
assert_equal options[:element], ld.element.class.ecore.name
|
264
|
-
else
|
265
|
-
assert_nil ld.element
|
266
|
-
end
|
267
|
-
if options[:element_name]
|
268
|
-
assert_equal options[:element_name], ld.element.name
|
269
|
-
end
|
270
|
-
if options[:feature]
|
271
|
-
assert_equal options[:feature], ld.feature.name
|
272
|
-
else
|
273
|
-
assert_nil ld.feature
|
274
|
-
end
|
275
|
-
if options[:index]
|
276
|
-
assert_equal options[:index], ld.index
|
277
|
-
else
|
278
|
-
assert_nil ld.index
|
279
|
-
end
|
280
|
-
assert_equal options[:backward], ld.backward
|
281
|
-
assert_equal options[:value], ld.value
|
282
|
-
assert_equal options[:scol], ld.scol
|
283
|
-
assert_equal options[:ecol], ld.ecol
|
284
|
-
end
|
285
|
-
|
286
|
-
end
|
287
|
-
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'rgen/metamodel_builder'
|
5
|
+
require 'rtext/language'
|
6
|
+
require 'rtext/link_detector'
|
7
|
+
|
8
|
+
class LinkDetectorTest < MiniTest::Test
|
9
|
+
|
10
|
+
module TestMM
|
11
|
+
extend RGen::MetamodelBuilder::ModuleExtension
|
12
|
+
class TestNode2 < RGen::MetamodelBuilder::MMBase
|
13
|
+
has_attr 'name', String
|
14
|
+
end
|
15
|
+
class TestNode < RGen::MetamodelBuilder::MMBase
|
16
|
+
has_attr 'name', String
|
17
|
+
has_attr 'id', Integer
|
18
|
+
has_one 'related', TestNode
|
19
|
+
has_many 'others', TestNode
|
20
|
+
contains_many 'children', TestNode2, 'parent'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_before_command
|
25
|
+
ld = build_link_desc TestMM, <<-END
|
26
|
+
|TestNode SomeNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
27
|
+
END
|
28
|
+
assert_link_desc ld, :element => "TestNode", :feature => nil, :backward => true, :value => "TestNode", :scol => 1, :ecol => 8
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_in_command
|
32
|
+
ld = build_link_desc TestMM, <<-END
|
33
|
+
Test|Node SomeNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
34
|
+
END
|
35
|
+
assert_link_desc ld, :element => "TestNode", :feature => nil, :backward => true, :value => "TestNode", :scol => 1, :ecol => 8
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_end_of_command
|
39
|
+
ld = build_link_desc TestMM, <<-END
|
40
|
+
TestNod|e SomeNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
41
|
+
END
|
42
|
+
assert_link_desc ld, :element => "TestNode", :feature => nil, :backward => true, :value => "TestNode", :scol => 1, :ecol => 8
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_after_command
|
46
|
+
ld = build_link_desc TestMM, <<-END
|
47
|
+
TestNode| SomeNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
48
|
+
END
|
49
|
+
assert_nil ld
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_in_name
|
53
|
+
ld = build_link_desc TestMM, <<-END
|
54
|
+
TestNode So|meNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
55
|
+
END
|
56
|
+
assert_link_desc ld, :element => "TestNode", :feature => "name", :index => 0, :backward => false, :value => "SomeNode", :scol => 10, :ecol => 17
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_in_name_with_quotes
|
60
|
+
ld = build_link_desc TestMM, <<-END
|
61
|
+
TestNode "So|meNode", id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
62
|
+
END
|
63
|
+
assert_link_desc ld, :element => "TestNode", :feature => "name", :index => 0, :backward => false, :value => "SomeNode", :scol => 10, :ecol => 19
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_after_comma
|
67
|
+
ld = build_link_desc TestMM, <<-END
|
68
|
+
TestNode SomeNode,| id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
69
|
+
END
|
70
|
+
assert_nil ld
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_after_label
|
74
|
+
ld = build_link_desc TestMM, <<-END
|
75
|
+
TestNode SomeNode, id:| 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
76
|
+
END
|
77
|
+
assert_nil ld
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_beginning_of_labled_argument
|
81
|
+
ld = build_link_desc TestMM, <<-END
|
82
|
+
TestNode SomeNode, id: |1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
83
|
+
END
|
84
|
+
assert_link_desc ld, :element => "TestNode", :feature => "id", :index => 0, :backward => false, :value => 1234, :scol => 24, :ecol => 27
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_in_labled_argument
|
88
|
+
ld = build_link_desc TestMM, <<-END
|
89
|
+
TestNode SomeNode, id: 123|4, related: /Other/Node, others: [/NodeA, /Node/B]
|
90
|
+
END
|
91
|
+
assert_link_desc ld, :element => "TestNode", :feature => "id", :index => 0, :backward => false, :value => 1234, :scol => 24, :ecol => 27
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_after_labled_argument
|
95
|
+
ld = build_link_desc TestMM, <<-END
|
96
|
+
TestNode SomeNode, id: 1234|, related: /Other/Node, others: [/NodeA, /Node/B]
|
97
|
+
END
|
98
|
+
assert_nil ld
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_in_label
|
102
|
+
ld = build_link_desc TestMM, <<-END
|
103
|
+
TestNode SomeNode, id: 1234, re|lated: /Other/Node, others: [/NodeA, /Node/B]
|
104
|
+
END
|
105
|
+
assert_nil ld
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_in_reference
|
109
|
+
ld = build_link_desc TestMM, <<-END
|
110
|
+
TestNode SomeNode, id: 1234, related: /O|ther/Node, others: [/NodeA, /Node/B]
|
111
|
+
END
|
112
|
+
assert_link_desc ld, :element => "TestNode", :feature => "related", :index => 0, :backward => false, :value => "/Other/Node", :scol => 39, :ecol => 49
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_before_array
|
116
|
+
ld = build_link_desc TestMM, <<-END
|
117
|
+
TestNode SomeNode, id: 1234, related: /Other/Node, others: |[/NodeA, /Node/B]
|
118
|
+
END
|
119
|
+
assert_nil ld
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_ref_in_array
|
123
|
+
ld = build_link_desc TestMM, <<-END
|
124
|
+
TestNode SomeNode, id: 1234, related: /Other/Node, others: [|/NodeA, /Node/B]
|
125
|
+
END
|
126
|
+
assert_link_desc ld, :element => "TestNode", :feature => "others", :index => 0, :backward => false, :value => "/NodeA", :scol => 61, :ecol => 66
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_second_ref_in_array
|
130
|
+
ld = build_link_desc TestMM, <<-END
|
131
|
+
TestNode SomeNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/|B]
|
132
|
+
END
|
133
|
+
assert_link_desc ld, :element => "TestNode", :feature => "others", :index => 1, :backward => false, :value => "/Node/B", :scol => 69, :ecol => 75
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_backward_ref_name_in_command
|
137
|
+
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
138
|
+
|TestNode SomeNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
139
|
+
END
|
140
|
+
)
|
141
|
+
assert_link_desc ld, :element => "TestNode", :feature => nil, :backward => false, :value => "TestNode", :scol => 1, :ecol => 8
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_backward_ref_name_in_name
|
145
|
+
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
146
|
+
TestNode Som|eNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
147
|
+
END
|
148
|
+
)
|
149
|
+
assert_link_desc ld, :element => "TestNode", :feature => "name", :index => 0, :backward => true, :value => "SomeNode", :scol => 10, :ecol => 17
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_backward_ref_name_with_quotes
|
153
|
+
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
154
|
+
TestNode "Som|eNode", id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
155
|
+
END
|
156
|
+
)
|
157
|
+
assert_link_desc ld, :element => "TestNode", :feature => "name", :index => 0, :backward => true, :value => "SomeNode", :scol => 10, :ecol => 19
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_backward_ref_id_in_id
|
161
|
+
ld = build_link_desc(TestMM, {:backward_ref => "id"}, <<-END
|
162
|
+
TestNode SomeNode, id: |1234, related: /Other/Node, others: [/NodeA, /Node/B]
|
163
|
+
END
|
164
|
+
)
|
165
|
+
assert_link_desc ld, :element => "TestNode", :feature => "id", :index => 0, :backward => true, :value => 1234, :scol => 24, :ecol => 27
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_command_only
|
169
|
+
ld = build_link_desc(TestMM, <<-END
|
170
|
+
Tes|tNode
|
171
|
+
END
|
172
|
+
)
|
173
|
+
assert_link_desc ld, :element => "TestNode", :feature => nil, :backward => true, :value => "TestNode", :scol => 1, :ecol => 8
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_command_and_name_only
|
177
|
+
ld = build_link_desc(TestMM, <<-END
|
178
|
+
TestNode |SomeNode
|
179
|
+
END
|
180
|
+
)
|
181
|
+
assert_link_desc ld, :element => "TestNode", :feature => "name", :index => 0, :backward => false, :value => "SomeNode", :scol => 10, :ecol => 17
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_command_and_name_only_backward_ref_name
|
185
|
+
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
186
|
+
TestNode |SomeNode
|
187
|
+
END
|
188
|
+
)
|
189
|
+
assert_link_desc ld, :element => "TestNode", :feature => "name", :index => 0, :backward => true, :value => "SomeNode", :scol => 10, :ecol => 17
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_command_and_name_curly_no_ws
|
193
|
+
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
194
|
+
TestNode Some|Node{
|
195
|
+
END
|
196
|
+
)
|
197
|
+
assert_link_desc ld, :element => "TestNode", :element_name => "SomeNode", :feature => "name", :index => 0, :backward => true, :value => "SomeNode", :scol => 10, :ecol => 17
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_child_within_command
|
201
|
+
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
202
|
+
TestNode SomeNode {
|
203
|
+
Test|Node2 SomeOtherNode
|
204
|
+
END
|
205
|
+
)
|
206
|
+
assert_link_desc ld, :element => "TestNode2", :feature => nil, :backward => false, :value => "TestNode2", :scol => 3, :ecol => 11
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_child_with_label_after_command
|
210
|
+
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
211
|
+
TestNode SomeNode {
|
212
|
+
children:
|
213
|
+
TestNode2 |SomeOtherNode
|
214
|
+
END
|
215
|
+
)
|
216
|
+
assert_link_desc ld, :element => "TestNode2", :feature => "name", :index => 0, :backward => true, :value => "SomeOtherNode", :scol => 15, :ecol => 27
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_child_with_label_within_command
|
220
|
+
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
221
|
+
TestNode SomeNode {
|
222
|
+
children:
|
223
|
+
Test|Node2 SomeOtherNode
|
224
|
+
END
|
225
|
+
)
|
226
|
+
assert_link_desc ld, :element => "TestNode2", :feature => nil, :backward => false, :value => "TestNode2", :scol => 5, :ecol => 13
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_child_with_label_within_command_square_brackets
|
230
|
+
ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
|
231
|
+
TestNode SomeNode {
|
232
|
+
children: [
|
233
|
+
Test|Node2 SomeOtherNode
|
234
|
+
END
|
235
|
+
)
|
236
|
+
assert_link_desc ld, :element => "TestNode2", :feature => nil, :backward => false, :value => "TestNode2", :scol => 5, :ecol => 13
|
237
|
+
end
|
238
|
+
|
239
|
+
def build_link_desc(mm, text, text2=nil)
|
240
|
+
if text.is_a?(Hash)
|
241
|
+
options = text
|
242
|
+
context_lines = text2.split("\n")
|
243
|
+
else
|
244
|
+
options = {}
|
245
|
+
context_lines = text.split("\n")
|
246
|
+
end
|
247
|
+
pos_in_line = context_lines.last.index("|")+1
|
248
|
+
context_lines.last.sub!("|", "")
|
249
|
+
lang = RText::Language.new(mm.ecore,
|
250
|
+
:unlabled_arguments => proc {|c| ["name"]},
|
251
|
+
:backward_ref_attribute => proc {|c|
|
252
|
+
if options[:backward_ref]
|
253
|
+
options[:backward_ref]
|
254
|
+
else
|
255
|
+
nil
|
256
|
+
end
|
257
|
+
})
|
258
|
+
RText::LinkDetector.new(lang).detect(context_lines, pos_in_line)
|
259
|
+
end
|
260
|
+
|
261
|
+
def assert_link_desc(ld, options)
|
262
|
+
if options[:element]
|
263
|
+
assert_equal options[:element], ld.element.class.ecore.name
|
264
|
+
else
|
265
|
+
assert_nil ld.element
|
266
|
+
end
|
267
|
+
if options[:element_name]
|
268
|
+
assert_equal options[:element_name], ld.element.name
|
269
|
+
end
|
270
|
+
if options[:feature]
|
271
|
+
assert_equal options[:feature], ld.feature.name
|
272
|
+
else
|
273
|
+
assert_nil ld.feature
|
274
|
+
end
|
275
|
+
if options[:index]
|
276
|
+
assert_equal options[:index], ld.index
|
277
|
+
else
|
278
|
+
assert_nil ld.index
|
279
|
+
end
|
280
|
+
assert_equal options[:backward], ld.backward
|
281
|
+
assert_equal options[:value], ld.value
|
282
|
+
assert_equal options[:scol], ld.scol
|
283
|
+
assert_equal options[:ecol], ld.ecol
|
284
|
+
end
|
285
|
+
|
286
|
+
end
|
287
|
+
|