manamana 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,483 @@
1
+
2
+ # line 1 "src/tdsl/lexer.rl"
3
+ # lib/manamana/tdsl/lexer.rb is autogenerated by
4
+ # ragel from src/tdsl/lexer.rl. Please edit the
5
+ # .rl file and not the .rb file.
6
+
7
+
8
+ # line 32 "src/tdsl/lexer.rl"
9
+
10
+
11
+
12
+ module ManaMana
13
+
14
+ module TDSL
15
+
16
+ class Lexer
17
+
18
+ def initialize
19
+
20
+ # line 21 "lib/manamana/tdsl/lexer.rb"
21
+ class << self
22
+ attr_accessor :_lexer_actions
23
+ private :_lexer_actions, :_lexer_actions=
24
+ end
25
+ self._lexer_actions = [
26
+ 0, 1, 0, 1, 1, 1, 2, 1,
27
+ 3, 1, 4, 1, 5, 1, 6, 1,
28
+ 7, 1, 8
29
+ ]
30
+
31
+ class << self
32
+ attr_accessor :_lexer_key_offsets
33
+ private :_lexer_key_offsets, :_lexer_key_offsets=
34
+ end
35
+ self._lexer_key_offsets = [
36
+ 0, 0, 1, 11, 23, 24, 25, 26,
37
+ 27, 28, 29, 30, 31, 32, 33, 34,
38
+ 35, 36, 37, 38, 39, 40, 41, 42,
39
+ 43, 44, 45, 46, 47, 48, 49, 50,
40
+ 51, 52, 53, 54, 55, 56, 57, 61,
41
+ 74, 89, 102, 103, 105, 106, 107, 108,
42
+ 109, 110, 111, 112, 113, 114, 115, 124,
43
+ 129, 133, 137, 142, 146, 150
44
+ ]
45
+
46
+ class << self
47
+ attr_accessor :_lexer_trans_keys
48
+ private :_lexer_trans_keys, :_lexer_trans_keys=
49
+ end
50
+ self._lexer_trans_keys = [
51
+ 32, 34, 39, 48, 57, 60, 61, 65,
52
+ 90, 97, 122, 9, 32, 34, 39, 48,
53
+ 57, 60, 61, 65, 90, 97, 122, 10,
54
+ 108, 101, 97, 110, 117, 112, 58, 114,
55
+ 101, 99, 111, 110, 100, 105, 116, 105,
56
+ 111, 110, 115, 99, 114, 105, 112, 116,
57
+ 101, 115, 116, 32, 67, 97, 115, 101,
58
+ 58, 9, 10, 13, 32, 9, 32, 43,
59
+ 46, 63, 40, 41, 48, 57, 65, 90,
60
+ 97, 122, 9, 10, 13, 32, 43, 46,
61
+ 63, 40, 41, 48, 57, 65, 90, 97,
62
+ 122, 9, 32, 43, 46, 63, 40, 41,
63
+ 48, 57, 65, 90, 97, 122, 10, 10,
64
+ 13, 10, 10, 10, 97, 114, 105, 97,
65
+ 98, 108, 101, 32, 42, 67, 80, 83,
66
+ 84, 86, 9, 13, 9, 10, 13, 32,
67
+ 126, 9, 10, 13, 32, 10, 13, 32,
68
+ 126, 9, 10, 13, 32, 126, 9, 10,
69
+ 13, 32, 10, 13, 32, 126, 10, 13,
70
+ 0
71
+ ]
72
+
73
+ class << self
74
+ attr_accessor :_lexer_single_lengths
75
+ private :_lexer_single_lengths, :_lexer_single_lengths=
76
+ end
77
+ self._lexer_single_lengths = [
78
+ 0, 1, 2, 4, 1, 1, 1, 1,
79
+ 1, 1, 1, 1, 1, 1, 1, 1,
80
+ 1, 1, 1, 1, 1, 1, 1, 1,
81
+ 1, 1, 1, 1, 1, 1, 1, 1,
82
+ 1, 1, 1, 1, 1, 1, 4, 5,
83
+ 7, 5, 1, 2, 1, 1, 1, 1,
84
+ 1, 1, 1, 1, 1, 1, 7, 3,
85
+ 4, 2, 3, 4, 2, 2
86
+ ]
87
+
88
+ class << self
89
+ attr_accessor :_lexer_range_lengths
90
+ private :_lexer_range_lengths, :_lexer_range_lengths=
91
+ end
92
+ self._lexer_range_lengths = [
93
+ 0, 0, 4, 4, 0, 0, 0, 0,
94
+ 0, 0, 0, 0, 0, 0, 0, 0,
95
+ 0, 0, 0, 0, 0, 0, 0, 0,
96
+ 0, 0, 0, 0, 0, 0, 0, 0,
97
+ 0, 0, 0, 0, 0, 0, 0, 4,
98
+ 4, 4, 0, 0, 0, 0, 0, 0,
99
+ 0, 0, 0, 0, 0, 0, 1, 1,
100
+ 0, 1, 1, 0, 1, 0
101
+ ]
102
+
103
+ class << self
104
+ attr_accessor :_lexer_index_offsets
105
+ private :_lexer_index_offsets, :_lexer_index_offsets=
106
+ end
107
+ self._lexer_index_offsets = [
108
+ 0, 0, 2, 9, 18, 20, 22, 24,
109
+ 26, 28, 30, 32, 34, 36, 38, 40,
110
+ 42, 44, 46, 48, 50, 52, 54, 56,
111
+ 58, 60, 62, 64, 66, 68, 70, 72,
112
+ 74, 76, 78, 80, 82, 84, 86, 91,
113
+ 101, 113, 123, 125, 128, 130, 132, 134,
114
+ 136, 138, 140, 142, 144, 146, 148, 157,
115
+ 162, 167, 171, 176, 181, 185
116
+ ]
117
+
118
+ class << self
119
+ attr_accessor :_lexer_indicies
120
+ private :_lexer_indicies, :_lexer_indicies=
121
+ end
122
+ self._lexer_indicies = [
123
+ 0, 1, 2, 2, 2, 2, 2, 2,
124
+ 1, 4, 4, 5, 5, 5, 5, 5,
125
+ 5, 3, 4, 3, 6, 1, 7, 1,
126
+ 8, 1, 9, 1, 10, 1, 11, 1,
127
+ 12, 1, 13, 1, 14, 1, 15, 1,
128
+ 16, 1, 17, 1, 18, 1, 19, 1,
129
+ 20, 1, 21, 1, 22, 1, 23, 1,
130
+ 11, 1, 24, 1, 25, 1, 26, 1,
131
+ 27, 1, 11, 1, 28, 1, 29, 1,
132
+ 30, 1, 31, 1, 32, 1, 33, 1,
133
+ 34, 1, 35, 1, 36, 1, 36, 37,
134
+ 38, 36, 1, 37, 37, 39, 39, 39,
135
+ 39, 39, 39, 39, 1, 41, 42, 43,
136
+ 41, 44, 44, 44, 44, 44, 44, 44,
137
+ 40, 41, 41, 44, 44, 44, 44, 44,
138
+ 44, 44, 40, 45, 40, 42, 43, 40,
139
+ 42, 40, 46, 40, 37, 1, 47, 1,
140
+ 48, 1, 49, 1, 50, 1, 51, 1,
141
+ 52, 1, 23, 1, 53, 54, 55, 56,
142
+ 57, 58, 59, 53, 1, 61, 4, 62,
143
+ 2, 60, 61, 4, 62, 61, 60, 4,
144
+ 62, 5, 60, 64, 45, 65, 39, 63,
145
+ 64, 45, 65, 64, 63, 45, 65, 44,
146
+ 63, 46, 66, 63, 0
147
+ ]
148
+
149
+ class << self
150
+ attr_accessor :_lexer_trans_targs
151
+ private :_lexer_trans_targs, :_lexer_trans_targs=
152
+ end
153
+ self._lexer_trans_targs = [
154
+ 2, 0, 55, 54, 3, 57, 6, 7,
155
+ 8, 9, 10, 11, 54, 13, 14, 15,
156
+ 16, 17, 18, 19, 20, 21, 22, 23,
157
+ 25, 26, 27, 28, 30, 31, 32, 33,
158
+ 34, 35, 36, 37, 38, 39, 46, 58,
159
+ 54, 41, 61, 44, 60, 40, 43, 48,
160
+ 49, 50, 51, 52, 53, 54, 1, 5,
161
+ 12, 24, 29, 47, 54, 56, 4, 54,
162
+ 59, 42, 45
163
+ ]
164
+
165
+ class << self
166
+ attr_accessor :_lexer_trans_actions
167
+ private :_lexer_trans_actions, :_lexer_trans_actions=
168
+ end
169
+ self._lexer_trans_actions = [
170
+ 0, 0, 5, 17, 0, 5, 0, 0,
171
+ 0, 0, 0, 0, 7, 0, 0, 0,
172
+ 0, 0, 0, 0, 0, 0, 0, 0,
173
+ 0, 0, 0, 0, 0, 0, 0, 0,
174
+ 0, 0, 0, 0, 0, 0, 0, 5,
175
+ 15, 0, 5, 0, 5, 0, 0, 0,
176
+ 0, 0, 0, 0, 0, 9, 0, 0,
177
+ 0, 0, 0, 0, 13, 5, 0, 11,
178
+ 5, 0, 0
179
+ ]
180
+
181
+ class << self
182
+ attr_accessor :_lexer_to_state_actions
183
+ private :_lexer_to_state_actions, :_lexer_to_state_actions=
184
+ end
185
+ self._lexer_to_state_actions = [
186
+ 0, 0, 0, 0, 0, 0, 0, 0,
187
+ 0, 0, 0, 0, 0, 0, 0, 0,
188
+ 0, 0, 0, 0, 0, 0, 0, 0,
189
+ 0, 0, 0, 0, 0, 0, 0, 0,
190
+ 0, 0, 0, 0, 0, 0, 0, 0,
191
+ 0, 0, 0, 0, 0, 0, 0, 0,
192
+ 0, 0, 0, 0, 0, 0, 1, 0,
193
+ 0, 0, 0, 0, 0, 0
194
+ ]
195
+
196
+ class << self
197
+ attr_accessor :_lexer_from_state_actions
198
+ private :_lexer_from_state_actions, :_lexer_from_state_actions=
199
+ end
200
+ self._lexer_from_state_actions = [
201
+ 0, 0, 0, 0, 0, 0, 0, 0,
202
+ 0, 0, 0, 0, 0, 0, 0, 0,
203
+ 0, 0, 0, 0, 0, 0, 0, 0,
204
+ 0, 0, 0, 0, 0, 0, 0, 0,
205
+ 0, 0, 0, 0, 0, 0, 0, 0,
206
+ 0, 0, 0, 0, 0, 0, 0, 0,
207
+ 0, 0, 0, 0, 0, 0, 3, 0,
208
+ 0, 0, 0, 0, 0, 0
209
+ ]
210
+
211
+ class << self
212
+ attr_accessor :_lexer_eof_trans
213
+ private :_lexer_eof_trans, :_lexer_eof_trans=
214
+ end
215
+ self._lexer_eof_trans = [
216
+ 0, 0, 0, 4, 4, 0, 0, 0,
217
+ 0, 0, 0, 0, 0, 0, 0, 0,
218
+ 0, 0, 0, 0, 0, 0, 0, 0,
219
+ 0, 0, 0, 0, 0, 0, 0, 0,
220
+ 0, 0, 0, 0, 0, 0, 0, 0,
221
+ 41, 41, 41, 41, 41, 41, 0, 0,
222
+ 0, 0, 0, 0, 0, 0, 0, 61,
223
+ 61, 61, 64, 64, 64, 64
224
+ ]
225
+
226
+ class << self
227
+ attr_accessor :lexer_start
228
+ end
229
+ self.lexer_start = 54;
230
+ class << self
231
+ attr_accessor :lexer_first_final
232
+ end
233
+ self.lexer_first_final = 54;
234
+ class << self
235
+ attr_accessor :lexer_error
236
+ end
237
+ self.lexer_error = 0;
238
+
239
+ class << self
240
+ attr_accessor :lexer_en_main
241
+ end
242
+ self.lexer_en_main = 54;
243
+
244
+
245
+ # line 43 "src/tdsl/lexer.rl"
246
+ # %% this just fixes syntax highlighting in TextMate et al.
247
+ end
248
+
249
+ def emit_label(token_array, data, ts, te)
250
+ value = data[ts...te].pack("c*").gsub(/\:/, '')
251
+ token_array << [value.upcase.to_sym, value]
252
+ end
253
+
254
+ def emit_line(token_array, data, ts, te)
255
+ value = data[ts...te].pack("c*").split.join(' ').gsub(/\* /, '').strip
256
+ token_array << [:LINE, value]
257
+ end
258
+
259
+ def emit_test_case(token_array, data, ts, te)
260
+ value = data[ts...te].pack("c*").split.join(' ').gsub(/Test Case\:/, '').strip
261
+ token_array << [:TEST_CASE, value]
262
+ end
263
+
264
+ def tokenize(data)
265
+ data = data.unpack("c*") if(data.is_a?(String))
266
+ eof = data.length
267
+ token_array = []
268
+
269
+
270
+ # line 271 "lib/manamana/tdsl/lexer.rb"
271
+ begin
272
+ p ||= 0
273
+ pe ||= data.length
274
+ cs = lexer_start
275
+ ts = nil
276
+ te = nil
277
+ act = 0
278
+ end
279
+
280
+ # line 67 "src/tdsl/lexer.rl"
281
+
282
+ # line 283 "lib/manamana/tdsl/lexer.rb"
283
+ begin
284
+ _klen, _trans, _keys, _acts, _nacts = nil
285
+ _goto_level = 0
286
+ _resume = 10
287
+ _eof_trans = 15
288
+ _again = 20
289
+ _test_eof = 30
290
+ _out = 40
291
+ while true
292
+ _trigger_goto = false
293
+ if _goto_level <= 0
294
+ if p == pe
295
+ _goto_level = _test_eof
296
+ next
297
+ end
298
+ if cs == 0
299
+ _goto_level = _out
300
+ next
301
+ end
302
+ end
303
+ if _goto_level <= _resume
304
+ _acts = _lexer_from_state_actions[cs]
305
+ _nacts = _lexer_actions[_acts]
306
+ _acts += 1
307
+ while _nacts > 0
308
+ _nacts -= 1
309
+ _acts += 1
310
+ case _lexer_actions[_acts - 1]
311
+ when 1 then
312
+ # line 1 "NONE"
313
+ begin
314
+ ts = p
315
+ end
316
+ # line 317 "lib/manamana/tdsl/lexer.rb"
317
+ end # from state action switch
318
+ end
319
+ if _trigger_goto
320
+ next
321
+ end
322
+ _keys = _lexer_key_offsets[cs]
323
+ _trans = _lexer_index_offsets[cs]
324
+ _klen = _lexer_single_lengths[cs]
325
+ _break_match = false
326
+
327
+ begin
328
+ if _klen > 0
329
+ _lower = _keys
330
+ _upper = _keys + _klen - 1
331
+
332
+ loop do
333
+ break if _upper < _lower
334
+ _mid = _lower + ( (_upper - _lower) >> 1 )
335
+
336
+ if data[p].ord < _lexer_trans_keys[_mid]
337
+ _upper = _mid - 1
338
+ elsif data[p].ord > _lexer_trans_keys[_mid]
339
+ _lower = _mid + 1
340
+ else
341
+ _trans += (_mid - _keys)
342
+ _break_match = true
343
+ break
344
+ end
345
+ end # loop
346
+ break if _break_match
347
+ _keys += _klen
348
+ _trans += _klen
349
+ end
350
+ _klen = _lexer_range_lengths[cs]
351
+ if _klen > 0
352
+ _lower = _keys
353
+ _upper = _keys + (_klen << 1) - 2
354
+ loop do
355
+ break if _upper < _lower
356
+ _mid = _lower + (((_upper-_lower) >> 1) & ~1)
357
+ if data[p].ord < _lexer_trans_keys[_mid]
358
+ _upper = _mid - 2
359
+ elsif data[p].ord > _lexer_trans_keys[_mid+1]
360
+ _lower = _mid + 2
361
+ else
362
+ _trans += ((_mid - _keys) >> 1)
363
+ _break_match = true
364
+ break
365
+ end
366
+ end # loop
367
+ break if _break_match
368
+ _trans += _klen
369
+ end
370
+ end while false
371
+ _trans = _lexer_indicies[_trans]
372
+ end
373
+ if _goto_level <= _eof_trans
374
+ cs = _lexer_trans_targs[_trans]
375
+ if _lexer_trans_actions[_trans] != 0
376
+ _acts = _lexer_trans_actions[_trans]
377
+ _nacts = _lexer_actions[_acts]
378
+ _acts += 1
379
+ while _nacts > 0
380
+ _nacts -= 1
381
+ _acts += 1
382
+ case _lexer_actions[_acts - 1]
383
+ when 2 then
384
+ # line 1 "NONE"
385
+ begin
386
+ te = p+1
387
+ end
388
+ when 3 then
389
+ # line 26 "src/tdsl/lexer.rl"
390
+ begin
391
+ te = p+1
392
+ begin emit_label(token_array, data, ts, te) end
393
+ end
394
+ when 4 then
395
+ # line 29 "src/tdsl/lexer.rl"
396
+ begin
397
+ te = p+1
398
+ end
399
+ when 5 then
400
+ # line 25 "src/tdsl/lexer.rl"
401
+ begin
402
+ te = p
403
+ p = p - 1; begin emit_test_case(token_array, data, ts, te) end
404
+ end
405
+ when 6 then
406
+ # line 27 "src/tdsl/lexer.rl"
407
+ begin
408
+ te = p
409
+ p = p - 1; begin emit_line(token_array, data, ts, te) end
410
+ end
411
+ when 7 then
412
+ # line 25 "src/tdsl/lexer.rl"
413
+ begin
414
+ begin p = ((te))-1; end
415
+ begin emit_test_case(token_array, data, ts, te) end
416
+ end
417
+ when 8 then
418
+ # line 27 "src/tdsl/lexer.rl"
419
+ begin
420
+ begin p = ((te))-1; end
421
+ begin emit_line(token_array, data, ts, te) end
422
+ end
423
+ # line 424 "lib/manamana/tdsl/lexer.rb"
424
+ end # action switch
425
+ end
426
+ end
427
+ if _trigger_goto
428
+ next
429
+ end
430
+ end
431
+ if _goto_level <= _again
432
+ _acts = _lexer_to_state_actions[cs]
433
+ _nacts = _lexer_actions[_acts]
434
+ _acts += 1
435
+ while _nacts > 0
436
+ _nacts -= 1
437
+ _acts += 1
438
+ case _lexer_actions[_acts - 1]
439
+ when 0 then
440
+ # line 1 "NONE"
441
+ begin
442
+ ts = nil; end
443
+ # line 444 "lib/manamana/tdsl/lexer.rb"
444
+ end # to state action switch
445
+ end
446
+ if _trigger_goto
447
+ next
448
+ end
449
+ if cs == 0
450
+ _goto_level = _out
451
+ next
452
+ end
453
+ p += 1
454
+ if p != pe
455
+ _goto_level = _resume
456
+ next
457
+ end
458
+ end
459
+ if _goto_level <= _test_eof
460
+ if p == eof
461
+ if _lexer_eof_trans[cs] > 0
462
+ _trans = _lexer_eof_trans[cs] - 1;
463
+ _goto_level = _eof_trans
464
+ next;
465
+ end
466
+ end
467
+ end
468
+ if _goto_level <= _out
469
+ break
470
+ end
471
+ end
472
+ end
473
+
474
+ # line 68 "src/tdsl/lexer.rl"
475
+
476
+ token_array
477
+ end
478
+
479
+ end
480
+
481
+ end
482
+
483
+ end
@@ -0,0 +1,149 @@
1
+ module ManaMana
2
+
3
+ module TDSL
4
+
5
+ class Node
6
+ attr_reader :children, :name
7
+
8
+ def initialize(name='', children=[])
9
+ @children = children
10
+ @name = name
11
+ end
12
+
13
+ def ==(other_node)
14
+ name == other_node.name && children == other_node.children
15
+ end
16
+ end
17
+
18
+ class PreconditionsNode < Node; end
19
+ class CleanupNode < Node; end
20
+ class ScriptNode < Node; end
21
+ class StepNode < Node; end
22
+
23
+ class RootNode < Node
24
+ def find(string)
25
+ children.find { |tc| tc.test string } || TestCaseNode.new
26
+ end
27
+ end
28
+
29
+ class VariablesNode < Node
30
+ def assignments
31
+ children
32
+ end
33
+ end
34
+
35
+ class AssignmentNode < Node
36
+ attr_reader :key, :value
37
+
38
+ def initialize(name = '', children = [])
39
+ @key, @value = name.split('=').map{ |n| n.strip }
40
+ end
41
+
42
+ def gsub!(string)
43
+ string.gsub! /\<#{ key }\>/, "\" + " + value + " + \""
44
+ end
45
+ end
46
+
47
+ class TestCaseNode < Node
48
+ attr_reader :regex
49
+
50
+ def initialize(name='', children={})
51
+ unless children.class == Hash
52
+ raise "Second parameter must be a Hash"
53
+ end
54
+
55
+ children[:variables] = children.delete(:variables) || VariablesNode.new
56
+ children[:preconditions] = children.delete(:preconditions) || PreconditionsNode.new
57
+ children[:cleanup] = children.delete(:cleanup) || CleanupNode.new
58
+ children[:script] = children.delete(:script) || ScriptNode.new
59
+
60
+ @regex = Regexp.new("^#{name}$", Regexp::IGNORECASE)
61
+
62
+ super name, children
63
+ end
64
+
65
+ def ==(other_node)
66
+ self.class == other_node.class &&
67
+ name == other_node.name &&
68
+ variables == other_node.variables &&
69
+ preconditions == other_node.preconditions &&
70
+ cleanup == other_node.cleanup &&
71
+ script == other_node.script
72
+ end
73
+
74
+ def test(string)
75
+ !(regex =~ string).nil?
76
+ end
77
+
78
+ def translate(requirement)
79
+ spec = ""
80
+ spec << " describe '#{ requirement }' do\n"
81
+ spec << " before do\n"
82
+
83
+ # Make the $1, $2, etc variables available to this spec
84
+ spec << " #{ regex.inspect } =~ \"#{ requirement }\"\n"
85
+
86
+ preconditions.each do |step|
87
+ str = step.name.dup
88
+ variables.each do |assignment|
89
+ assignment.gsub! str
90
+ end
91
+
92
+ spec << " Steps.call \"" + str + "\"\n"
93
+ end
94
+
95
+ spec << " end\n\n"
96
+
97
+ spec << " after do\n"
98
+
99
+ cleanup.each do |step|
100
+ str = step.name.dup
101
+ variables.each do |assignment|
102
+ assignment.gsub! str
103
+ end
104
+
105
+ spec << " Steps.call \"" + str + "\"\n"
106
+ end
107
+
108
+ spec << " end\n\n"
109
+
110
+ spec << " it 'must pass' do\n"
111
+
112
+ script.each do |step|
113
+ str = step.name.dup
114
+ variables.each do |assignment|
115
+ assignment.gsub! str
116
+ end
117
+
118
+ spec << " Steps.call \"" + str + "\"\n"
119
+ end
120
+
121
+ if script.length == 0
122
+ spec << " raise 'Undefined test case'\n"
123
+ end
124
+
125
+ spec << " end\n"
126
+ spec << " end\n"
127
+ spec
128
+ end
129
+
130
+ def variables
131
+ children[:variables].children
132
+ end
133
+
134
+ def preconditions
135
+ children[:preconditions].children
136
+ end
137
+
138
+ def cleanup
139
+ children[:cleanup].children
140
+ end
141
+
142
+ def script
143
+ children[:script].children
144
+ end
145
+ end
146
+
147
+ end
148
+
149
+ end