sourcify 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/HISTORY.txt +4 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +154 -0
  6. data/Rakefile +114 -0
  7. data/VERSION +1 -0
  8. data/lib/sourcify.rb +12 -0
  9. data/lib/sourcify/proc.rb +53 -0
  10. data/lib/sourcify/proc/counter.rb +41 -0
  11. data/lib/sourcify/proc/lexer.rb +40 -0
  12. data/lib/sourcify/proc/lexer18.rb +224 -0
  13. data/lib/sourcify/proc/lexer19.rb +195 -0
  14. data/lib/sourcify/proc/parser.rb +74 -0
  15. data/sourcify.gemspec +109 -0
  16. data/spec/proc/19x_extras.rb +27 -0
  17. data/spec/proc/readme +5 -0
  18. data/spec/proc/to_sexp_variables_spec.rb +146 -0
  19. data/spec/proc/to_source_from_braced_block_w_nested_braced_block_spec.rb +33 -0
  20. data/spec/proc/to_source_from_braced_block_w_nested_hash_spec.rb +34 -0
  21. data/spec/proc/to_source_from_braced_block_wo_nesting_complication_spec.rb +46 -0
  22. data/spec/proc/to_source_from_do_end_block_w_nested_begin_spec.rb +35 -0
  23. data/spec/proc/to_source_from_do_end_block_w_nested_case_spec.rb +35 -0
  24. data/spec/proc/to_source_from_do_end_block_w_nested_class_spec.rb +89 -0
  25. data/spec/proc/to_source_from_do_end_block_w_nested_do_end_block_spec.rb +33 -0
  26. data/spec/proc/to_source_from_do_end_block_w_nested_for_spec.rb +132 -0
  27. data/spec/proc/to_source_from_do_end_block_w_nested_if_spec.rb +73 -0
  28. data/spec/proc/to_source_from_do_end_block_w_nested_method_spec.rb +33 -0
  29. data/spec/proc/to_source_from_do_end_block_w_nested_module_spec.rb +49 -0
  30. data/spec/proc/to_source_from_do_end_block_w_nested_unless_spec.rb +73 -0
  31. data/spec/proc/to_source_from_do_end_block_w_nested_until_spec.rb +176 -0
  32. data/spec/proc/to_source_from_do_end_block_w_nested_while_spec.rb +176 -0
  33. data/spec/proc/to_source_from_do_end_block_wo_nesting_complication_spec.rb +46 -0
  34. data/spec/proc/to_source_from_multi_blocks_w_many_matches_spec.rb +73 -0
  35. data/spec/proc/to_source_from_multi_blocks_w_single_match_spec.rb +31 -0
  36. data/spec/proc/to_source_from_multi_do_end_blocks_w_single_match_spec.rb +31 -0
  37. data/spec/proc/to_source_magic_file_var_spec.rb +127 -0
  38. data/spec/proc/to_source_magic_line_var_spec.rb +127 -0
  39. data/spec/proc/to_source_variables_spec.rb +29 -0
  40. data/spec/spec_helper.rb +41 -0
  41. metadata +159 -0
@@ -0,0 +1,176 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe "Proc#to_source from do ... end block (w nested until block)" do
4
+
5
+ should 'handle w do' do
6
+ (
7
+ lambda do
8
+ until true do @x1 = 1 end
9
+ end
10
+ ).should.be having_source(%Q\
11
+ proc do
12
+ until true do @x1 = 1 end
13
+ end
14
+ \)
15
+ end
16
+
17
+ should 'handle w \ do' do
18
+ (
19
+ lambda do
20
+ until true \
21
+ do @x1 = 2 end
22
+ end
23
+ ).should.be having_source(%Q\
24
+ proc do
25
+ until true do @x1 = 2 end
26
+ end
27
+ \)
28
+ end
29
+
30
+ should 'handle wo do (w newline)' do
31
+ (
32
+ lambda do
33
+ until true
34
+ @x1 = 3
35
+ end
36
+ end
37
+ ).should.be having_source(%Q\
38
+ proc do
39
+ until true
40
+ @x1 = 3
41
+ end
42
+ end
43
+ \)
44
+ end
45
+
46
+ should 'handle wo do (w semicolon)' do
47
+ (
48
+ lambda do
49
+ until true; @x1 = 4; end
50
+ end
51
+ ).should.be having_source(%Q\
52
+ proc do
53
+ until true
54
+ @x1 = 4
55
+ end
56
+ end
57
+ \)
58
+ end
59
+
60
+ should 'handle nested wo do within w do' do
61
+ (
62
+ lambda do
63
+ until true do
64
+ until true; @x1 = 5; end
65
+ end
66
+ end
67
+ ).should.be having_source(%Q\
68
+ proc do
69
+ until true do
70
+ until true
71
+ @x1 = 5
72
+ end
73
+ end
74
+ end
75
+ \)
76
+ end
77
+
78
+ should 'handle nested wo do within wo do' do
79
+ (
80
+ lambda do
81
+ until true
82
+ until true; @x1 = 6; end
83
+ end
84
+ end
85
+ ).should.be having_source(%Q\
86
+ proc do
87
+ until true
88
+ until true
89
+ @x1 = 6
90
+ end
91
+ end
92
+ end
93
+ \)
94
+ end
95
+
96
+ should 'handle nested w do within wo do' do
97
+ (
98
+ lambda do
99
+ until true
100
+ until true do @x1 = 7 end
101
+ end
102
+ end
103
+ ).should.be having_source(%Q\
104
+ proc do
105
+ until true
106
+ until true
107
+ @x1 = 7
108
+ end
109
+ end
110
+ end
111
+ \)
112
+ end
113
+
114
+ should 'handle nested w do within w do' do
115
+ (
116
+ lambda do
117
+ until true do
118
+ until true do @x1 = 8 end
119
+ end
120
+ end
121
+ ).should.be having_source(%Q\
122
+ proc do
123
+ until true
124
+ until true
125
+ @x1 = 8
126
+ end
127
+ end
128
+ end
129
+ \)
130
+ end
131
+
132
+ should 'handle simple modifier' do
133
+ (
134
+ lambda do
135
+ @x1 = 9 until true
136
+ end
137
+ ).should.be having_source(%Q\
138
+ proc do
139
+ @x1 = 9 until true
140
+ end
141
+ \)
142
+ end
143
+
144
+ should 'handle block within modifier' do
145
+ (
146
+ lambda do
147
+ @x1 = 10 until (
148
+ until true do @x1 = 10 end
149
+ )
150
+ end
151
+ ).should.be having_source(%Q\
152
+ proc do
153
+ @x1 = 10 until (
154
+ until true do @x1 = 10 end
155
+ )
156
+ end
157
+ \)
158
+ end
159
+
160
+ should 'handle modifier within block' do
161
+ (
162
+ lambda do
163
+ until true
164
+ @x1 = 11 until true
165
+ end
166
+ end
167
+ ).should.be having_source(%Q\
168
+ proc do
169
+ until true
170
+ @x1 = 11 until true
171
+ end
172
+ end
173
+ \)
174
+ end
175
+
176
+ end
@@ -0,0 +1,176 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe "Proc#to_source from do ... end block (w nested while block)" do
4
+
5
+ should 'handle w do' do
6
+ (
7
+ lambda do
8
+ while true do @x1 = 1 end
9
+ end
10
+ ).should.be having_source(%Q\
11
+ proc do
12
+ while true do @x1 = 1 end
13
+ end
14
+ \)
15
+ end
16
+
17
+ should 'handle w \ do' do
18
+ (
19
+ lambda do
20
+ while true \
21
+ do @x1 = 2 end
22
+ end
23
+ ).should.be having_source(%Q\
24
+ proc do
25
+ while true do @x1 = 2 end
26
+ end
27
+ \)
28
+ end
29
+
30
+ should 'handle wo do (w newline)' do
31
+ (
32
+ lambda do
33
+ while true
34
+ @x1 = 3
35
+ end
36
+ end
37
+ ).should.be having_source(%Q\
38
+ proc do
39
+ while true
40
+ @x1 = 3
41
+ end
42
+ end
43
+ \)
44
+ end
45
+
46
+ should 'handle wo do (w semicolon)' do
47
+ (
48
+ lambda do
49
+ while true; @x1 = 4; end
50
+ end
51
+ ).should.be having_source(%Q\
52
+ proc do
53
+ while true
54
+ @x1 = 4
55
+ end
56
+ end
57
+ \)
58
+ end
59
+
60
+ should 'handle nested wo do within w do' do
61
+ (
62
+ lambda do
63
+ while true do
64
+ while true; @x1 = 5; end
65
+ end
66
+ end
67
+ ).should.be having_source(%Q\
68
+ proc do
69
+ while true do
70
+ while true
71
+ @x1 = 5
72
+ end
73
+ end
74
+ end
75
+ \)
76
+ end
77
+
78
+ should 'handle nested wo do within wo do' do
79
+ (
80
+ lambda do
81
+ while true
82
+ while true; @x1 = 6; end
83
+ end
84
+ end
85
+ ).should.be having_source(%Q\
86
+ proc do
87
+ while true
88
+ while true
89
+ @x1 = 6
90
+ end
91
+ end
92
+ end
93
+ \)
94
+ end
95
+
96
+ should 'handle nested w do within wo do' do
97
+ (
98
+ lambda do
99
+ while true
100
+ while true do @x1 = 7 end
101
+ end
102
+ end
103
+ ).should.be having_source(%Q\
104
+ proc do
105
+ while true
106
+ while true
107
+ @x1 = 7
108
+ end
109
+ end
110
+ end
111
+ \)
112
+ end
113
+
114
+ should 'handle nested w do within w do' do
115
+ (
116
+ lambda do
117
+ while true do
118
+ while true do @x1 = 8 end
119
+ end
120
+ end
121
+ ).should.be having_source(%Q\
122
+ proc do
123
+ while true
124
+ while true
125
+ @x1 = 8
126
+ end
127
+ end
128
+ end
129
+ \)
130
+ end
131
+
132
+ should 'handle simple modifier' do
133
+ (
134
+ lambda do
135
+ @x1 = 9 while true
136
+ end
137
+ ).should.be having_source(%Q\
138
+ proc do
139
+ @x1 = 9 while true
140
+ end
141
+ \)
142
+ end
143
+
144
+ should 'handle block within modifier' do
145
+ (
146
+ lambda do
147
+ @x1 = 10 while (
148
+ while true do @x1 = 10 end
149
+ )
150
+ end
151
+ ).should.be having_source(%Q\
152
+ proc do
153
+ @x1 = 10 while (
154
+ while true do @x1 = 10 end
155
+ )
156
+ end
157
+ \)
158
+ end
159
+
160
+ should 'handle modifier within block' do
161
+ (
162
+ lambda do
163
+ while true
164
+ @x1 = 11 while true
165
+ end
166
+ end
167
+ ).should.be having_source(%Q\
168
+ proc do
169
+ while true
170
+ @x1 = 11 while true
171
+ end
172
+ end
173
+ \)
174
+ end
175
+
176
+ end
@@ -0,0 +1,46 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe "Proc#to_source from do ... end block (wo nesting complication)" do
4
+
5
+ expected = 'proc { @x%s }'
6
+
7
+ should 'handle watever(..) do ... end' do
8
+ (
9
+ watever(:a, :b, {:c => 1}) do @x1 end
10
+ ).should.be having_source(expected%1)
11
+ end
12
+
13
+ should 'handle watever(..) \ do ... end' do
14
+ (
15
+ watever(:a, :b, {:c => 1}) \
16
+ do @x2 end
17
+ ).should.be having_source(expected%2)
18
+ end
19
+
20
+ should 'handle watever do ... end' do
21
+ (
22
+ watever do @x3 end
23
+ ).should.be having_source(expected%3)
24
+ end
25
+
26
+ should 'handle watever \ do ... end' do
27
+ (
28
+ watever \
29
+ do @x4 end
30
+ ).should.be having_source(expected%4)
31
+ end
32
+
33
+ should 'handle lambda do ... end' do
34
+ (
35
+ lambda do @x5 end
36
+ ).should.be having_source(expected%5)
37
+ end
38
+
39
+ should 'handle lambda \ do ... end' do
40
+ (
41
+ lambda \
42
+ do @x6 end
43
+ ).should.be having_source(expected%6)
44
+ end
45
+
46
+ end
@@ -0,0 +1,73 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe 'Proc#to_source from multi blocks w many matches' do
4
+
5
+ if Object.const_defined?(:ParseTree)
6
+
7
+ expected = 'proc { @x%s }'
8
+
9
+ should 'skip non-matching (all do...end blocks)' do
10
+ (
11
+ b1 = lambda do |a| @x1 end; b2 = lambda do @x1 end; b3 = lambda do @x10 end; b2
12
+ ).should.be having_source(expected%1)
13
+ end
14
+
15
+ should 'skip non-matching (all {...} blocks)' do
16
+ (
17
+ b1 = lambda {|a| @x2 }; b2 = lambda { @x2 }; b3 = lambda { @x20 }; b2
18
+ ).should.be having_source(expected%2)
19
+ end
20
+
21
+ should 'skip non-matching (mixed {...} with do...end blocks)' do
22
+ (
23
+ b1 = lambda {|a| @x3 }; b2 = lambda do @x3 end; b3 = lambda { @x30 } ; b2
24
+ ).should.be having_source(expected%3)
25
+ end
26
+
27
+ should 'skip non-matching (mixed do...end with {...} blocks)' do
28
+ (
29
+ b1 = lambda do |a| @x4 end; b2 = lambda { @x4 }; b3 = lambda do @x40 end; b2
30
+ ).should.be having_source(expected%4)
31
+ end
32
+
33
+ else
34
+
35
+ # Need this line since the parser file is dynamically required, otherwise we will get
36
+ # undefined constant error
37
+ require 'sourcify/proc/parser'
38
+
39
+ should 'raise Sourcify::MultipleMatchingProcsPerLineError (all do...end blocks)' do
40
+ lambda {
41
+ (
42
+ b1 = lambda do |a| @x1 end; b2 = lambda do @x1 end; b3 = lambda do @x1 end ; b2
43
+ ).to_source
44
+ }.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
45
+ end
46
+
47
+ should 'raise Sourcify::MultipleMatchingProcsPerLineError (all {...} blocks)' do
48
+ lambda {
49
+ (
50
+ b1 = lambda {|a| @x2 }; b2 = lambda { @x2 }; b3 = lambda { @x2 } ; b2
51
+ ).to_source
52
+ }.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
53
+ end
54
+
55
+ should 'raise Sourcify::MultipleMatchingProcsPerLineError (mixed {...} w do...end blocks)' do
56
+ lambda {
57
+ (
58
+ b1 = lambda {|a| @x3 }; b2 = lambda do @x3 end; b3 = lambda { @x4 } ; b2
59
+ ).to_source
60
+ }.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
61
+ end
62
+
63
+ should 'raise Sourcify::MultipleMatchingProcsPerLineError (mixed do...end w {...} blocks)' do
64
+ lambda {
65
+ (
66
+ b1 = lambda do |a| @x4 end; b2 = lambda { @x4 }; b3 = lambda do @x4 end ; b2
67
+ ).to_source
68
+ }.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
69
+ end
70
+
71
+ end
72
+
73
+ end