ikra 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. checksums.yaml +7 -0
  2. data/lib/ast/builder.rb +100 -0
  3. data/lib/ast/lexical_variables_enumerator.rb +34 -0
  4. data/lib/ast/method_definition.rb +37 -0
  5. data/lib/ast/nodes.rb +208 -0
  6. data/lib/ast/printer.rb +99 -0
  7. data/lib/ast/translator.rb +264 -0
  8. data/lib/ast/visitor.rb +173 -0
  9. data/lib/config/configuration.rb +18 -0
  10. data/lib/config/os_configuration.rb +56 -0
  11. data/lib/entity.rb +11 -0
  12. data/lib/ikra.rb +7 -0
  13. data/lib/parsing.rb +32 -0
  14. data/lib/resources/cuda/block_function_head.cpp +1 -0
  15. data/lib/resources/cuda/env_builder_copy_array.cpp +4 -0
  16. data/lib/resources/cuda/header.cpp +46 -0
  17. data/lib/resources/cuda/kernel.cpp +8 -0
  18. data/lib/resources/cuda/kernel_launcher.cpp +28 -0
  19. data/lib/resources/cuda/soa_header.cpp +4 -0
  20. data/lib/scope.rb +166 -0
  21. data/lib/sourcify/Gemfile +10 -0
  22. data/lib/sourcify/HISTORY.txt +88 -0
  23. data/lib/sourcify/LICENSE +20 -0
  24. data/lib/sourcify/README.rdoc +352 -0
  25. data/lib/sourcify/Rakefile +111 -0
  26. data/lib/sourcify/lib/sourcify.rb +44 -0
  27. data/lib/sourcify/lib/sourcify/common/parser/converter.rb +29 -0
  28. data/lib/sourcify/lib/sourcify/common/parser/raw_scanner/comment.rb +23 -0
  29. data/lib/sourcify/lib/sourcify/common/parser/raw_scanner/counter.rb +43 -0
  30. data/lib/sourcify/lib/sourcify/common/parser/raw_scanner/dstring.rb +58 -0
  31. data/lib/sourcify/lib/sourcify/common/parser/raw_scanner/extensions.rb +140 -0
  32. data/lib/sourcify/lib/sourcify/common/parser/raw_scanner/heredoc.rb +26 -0
  33. data/lib/sourcify/lib/sourcify/common/parser/source_code.rb +45 -0
  34. data/lib/sourcify/lib/sourcify/common/ragel/common.rl +5 -0
  35. data/lib/sourcify/lib/sourcify/common/ragel/expressions.rl +38 -0
  36. data/lib/sourcify/lib/sourcify/common/ragel/machines.rl +317 -0
  37. data/lib/sourcify/lib/sourcify/errors.rb +4 -0
  38. data/lib/sourcify/lib/sourcify/method.rb +138 -0
  39. data/lib/sourcify/lib/sourcify/method/methods.rb +3 -0
  40. data/lib/sourcify/lib/sourcify/method/methods/to_raw_source.rb +30 -0
  41. data/lib/sourcify/lib/sourcify/method/methods/to_sexp.rb +30 -0
  42. data/lib/sourcify/lib/sourcify/method/methods/to_source.rb +30 -0
  43. data/lib/sourcify/lib/sourcify/method/parser.rb +110 -0
  44. data/lib/sourcify/lib/sourcify/method/parser/converter.rb +8 -0
  45. data/lib/sourcify/lib/sourcify/method/parser/raw_scanner.rb +2494 -0
  46. data/lib/sourcify/lib/sourcify/method/parser/raw_scanner.rl +144 -0
  47. data/lib/sourcify/lib/sourcify/method/parser/raw_scanner_extensions.rb +68 -0
  48. data/lib/sourcify/lib/sourcify/method/parser/scanner.rb +52 -0
  49. data/lib/sourcify/lib/sourcify/method/parser/source_code.rb +8 -0
  50. data/lib/sourcify/lib/sourcify/patches.rb +63 -0
  51. data/lib/sourcify/lib/sourcify/proc.rb +183 -0
  52. data/lib/sourcify/lib/sourcify/proc/methods.rb +3 -0
  53. data/lib/sourcify/lib/sourcify/proc/methods/source_location.rb +61 -0
  54. data/lib/sourcify/lib/sourcify/proc/methods/to_raw_source.rb +20 -0
  55. data/lib/sourcify/lib/sourcify/proc/methods/to_sexp.rb +40 -0
  56. data/lib/sourcify/lib/sourcify/proc/methods/to_source.rb +48 -0
  57. data/lib/sourcify/lib/sourcify/proc/parser.rb +51 -0
  58. data/lib/sourcify/lib/sourcify/proc/parser/converter.rb +8 -0
  59. data/lib/sourcify/lib/sourcify/proc/parser/normalizer.rb +43 -0
  60. data/lib/sourcify/lib/sourcify/proc/parser/raw_scanner.rb +2498 -0
  61. data/lib/sourcify/lib/sourcify/proc/parser/raw_scanner.rl +149 -0
  62. data/lib/sourcify/lib/sourcify/proc/parser/raw_scanner_extensions.rb +74 -0
  63. data/lib/sourcify/lib/sourcify/proc/parser/scanner.rb +49 -0
  64. data/lib/sourcify/lib/sourcify/proc/parser/source_code.rb +8 -0
  65. data/lib/sourcify/lib/sourcify/version.rb +3 -0
  66. data/lib/sourcify/sourcify.gemspec +31 -0
  67. data/lib/sourcify/spec/dump_object_space_procs.rb +84 -0
  68. data/lib/sourcify/spec/method/encoding_from_def_end_block_spec.rb +33 -0
  69. data/lib/sourcify/spec/method/encoding_from_define_method_spec.rb +37 -0
  70. data/lib/sourcify/spec/method/others_from_def_end_block_spec.rb +49 -0
  71. data/lib/sourcify/spec/method/others_from_define_method_spec.rb +63 -0
  72. data/lib/sourcify/spec/method/raw_scanner/block_comment_spec.rb +8 -0
  73. data/lib/sourcify/spec/method/raw_scanner/double_colons_spec.rb +8 -0
  74. data/lib/sourcify/spec/method/raw_scanner/double_quote_str_w_interpolation_spec.rb +8 -0
  75. data/lib/sourcify/spec/method/raw_scanner/double_quote_str_wo_interpolation_spec.rb +8 -0
  76. data/lib/sourcify/spec/method/raw_scanner/heredoc_w_indent_spec.rb +8 -0
  77. data/lib/sourcify/spec/method/raw_scanner/heredoc_wo_indent_spec.rb +8 -0
  78. data/lib/sourcify/spec/method/raw_scanner/kw_block_start_alias1_spec.rb +20 -0
  79. data/lib/sourcify/spec/method/raw_scanner/kw_block_start_alias2_spec.rb +20 -0
  80. data/lib/sourcify/spec/method/raw_scanner/per_line_comment_spec.rb +8 -0
  81. data/lib/sourcify/spec/method/raw_scanner/single_quote_str_spec.rb +8 -0
  82. data/lib/sourcify/spec/method/raw_scanner/slash_operator_spec.rb +8 -0
  83. data/lib/sourcify/spec/method/raw_scanner/spec_helper.rb +80 -0
  84. data/lib/sourcify/spec/method/spec_helper.rb +1 -0
  85. data/lib/sourcify/spec/method/to_raw_source_spec.rb +31 -0
  86. data/lib/sourcify/spec/method/to_raw_source_w_specified_strip_enclosure_spec.rb +148 -0
  87. data/lib/sourcify/spec/method/to_sexp_from_def_end_block_w_variables_spec.rb +46 -0
  88. data/lib/sourcify/spec/method/to_sexp_from_def_end_block_within_irb_spec.rb +38 -0
  89. data/lib/sourcify/spec/method/to_sexp_from_def_end_block_within_pry_spec.rb +38 -0
  90. data/lib/sourcify/spec/method/to_sexp_from_define_method_w_multi_blocks_and_specified_attached_to_spec.rb +56 -0
  91. data/lib/sourcify/spec/method/to_sexp_from_define_method_w_variables_spec.rb +52 -0
  92. data/lib/sourcify/spec/method/to_sexp_from_define_method_within_irb_spec.rb +42 -0
  93. data/lib/sourcify/spec/method/to_sexp_from_define_method_within_pry_spec.rb +42 -0
  94. data/lib/sourcify/spec/method/to_sexp_w_specified_strip_enclosure_spec.rb +74 -0
  95. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_19_extras_spec.rb +23 -0
  96. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_begin_spec.rb +35 -0
  97. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_case_spec.rb +35 -0
  98. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_class_spec.rb +51 -0
  99. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_do_end_block_spec.rb +33 -0
  100. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_for_spec.rb +126 -0
  101. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_if_spec.rb +83 -0
  102. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_literal_keyword_spec.rb +141 -0
  103. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_method_spec.rb +33 -0
  104. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_module_spec.rb +59 -0
  105. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_unless_spec.rb +83 -0
  106. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_until_spec.rb +179 -0
  107. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_while_spec.rb +179 -0
  108. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_singleton_method_spec.rb +19 -0
  109. data/lib/sourcify/spec/method/to_source_from_def_end_block_within_irb_spec.rb +30 -0
  110. data/lib/sourcify/spec/method/to_source_from_def_end_block_within_pry_spec.rb +45 -0
  111. data/lib/sourcify/spec/method/to_source_from_def_end_w_multi_blocks_and_many_matches_spec.rb +30 -0
  112. data/lib/sourcify/spec/method/to_source_from_def_end_w_multi_blocks_and_single_match_spec.rb +36 -0
  113. data/lib/sourcify/spec/method/to_source_from_define_method_w_braced_block_spec.rb +113 -0
  114. data/lib/sourcify/spec/method/to_source_from_define_method_w_do_end_block_spec.rb +145 -0
  115. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_many_matches_spec.rb +56 -0
  116. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_single_match_spec.rb +73 -0
  117. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_and_many_matches_spec.rb +36 -0
  118. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_and_no_match_spec.rb +36 -0
  119. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_and_single_match_spec.rb +28 -0
  120. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_spec.rb +103 -0
  121. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_body_matcher_and_many_matches_spec.rb +36 -0
  122. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_body_matcher_and_no_match_spec.rb +36 -0
  123. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_body_matcher_and_single_match_spec.rb +28 -0
  124. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_ignore_nested_spec.rb +36 -0
  125. data/lib/sourcify/spec/method/to_source_from_define_method_within_irb_spec.rb +32 -0
  126. data/lib/sourcify/spec/method/to_source_from_define_method_within_pry_spec.rb +49 -0
  127. data/lib/sourcify/spec/method/to_source_magic_file_var_spec.rb +176 -0
  128. data/lib/sourcify/spec/method/to_source_magic_line_var_spec.rb +298 -0
  129. data/lib/sourcify/spec/method/to_source_w_specified_strip_enclosure_spec.rb +39 -0
  130. data/lib/sourcify/spec/no_method/unsupported_platform_spec.rb +26 -0
  131. data/lib/sourcify/spec/proc/19x_extras.rb +27 -0
  132. data/lib/sourcify/spec/proc/created_on_the_fly_proc_spec.rb +80 -0
  133. data/lib/sourcify/spec/proc/encoding_spec.rb +36 -0
  134. data/lib/sourcify/spec/proc/others_spec.rb +40 -0
  135. data/lib/sourcify/spec/proc/raw_scanner/block_comment_spec.rb +8 -0
  136. data/lib/sourcify/spec/proc/raw_scanner/double_colons_spec.rb +8 -0
  137. data/lib/sourcify/spec/proc/raw_scanner/double_quote_str_w_interpolation_spec.rb +8 -0
  138. data/lib/sourcify/spec/proc/raw_scanner/double_quote_str_wo_interpolation_spec.rb +8 -0
  139. data/lib/sourcify/spec/proc/raw_scanner/heredoc_w_indent_spec.rb +8 -0
  140. data/lib/sourcify/spec/proc/raw_scanner/heredoc_wo_indent_spec.rb +8 -0
  141. data/lib/sourcify/spec/proc/raw_scanner/kw_block_start_alias1_spec.rb +20 -0
  142. data/lib/sourcify/spec/proc/raw_scanner/kw_block_start_alias2_spec.rb +20 -0
  143. data/lib/sourcify/spec/proc/raw_scanner/per_line_comment_spec.rb +8 -0
  144. data/lib/sourcify/spec/proc/raw_scanner/single_quote_str_spec.rb +8 -0
  145. data/lib/sourcify/spec/proc/raw_scanner/slash_operator_spec.rb +8 -0
  146. data/lib/sourcify/spec/proc/raw_scanner/spec_helper.rb +63 -0
  147. data/lib/sourcify/spec/proc/readme +5 -0
  148. data/lib/sourcify/spec/proc/spec_helper.rb +1 -0
  149. data/lib/sourcify/spec/proc/to_raw_source_spec.rb +33 -0
  150. data/lib/sourcify/spec/proc/to_raw_source_w_specified_strip_enclosure_spec.rb +69 -0
  151. data/lib/sourcify/spec/proc/to_sexp_from_multi_blocks_w_specified_attached_to_spec.rb +46 -0
  152. data/lib/sourcify/spec/proc/to_sexp_variables_spec.rb +146 -0
  153. data/lib/sourcify/spec/proc/to_sexp_w_specified_strip_enclosure_spec.rb +60 -0
  154. data/lib/sourcify/spec/proc/to_sexp_within_irb_spec.rb +146 -0
  155. data/lib/sourcify/spec/proc/to_sexp_within_pry_spec.rb +149 -0
  156. data/lib/sourcify/spec/proc/to_source_from_braced_block_w_nested_braced_block_spec.rb +33 -0
  157. data/lib/sourcify/spec/proc/to_source_from_braced_block_w_nested_hash_spec.rb +82 -0
  158. data/lib/sourcify/spec/proc/to_source_from_braced_block_wo_nesting_complication_spec.rb +46 -0
  159. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_begin_spec.rb +35 -0
  160. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_case_spec.rb +35 -0
  161. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_class_spec.rb +89 -0
  162. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_do_end_block_spec.rb +33 -0
  163. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_for_spec.rb +132 -0
  164. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_if_spec.rb +87 -0
  165. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_literal_keyword_spec.rb +103 -0
  166. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_method_spec.rb +33 -0
  167. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_module_spec.rb +49 -0
  168. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_unless_spec.rb +87 -0
  169. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_until_spec.rb +189 -0
  170. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_while_spec.rb +189 -0
  171. data/lib/sourcify/spec/proc/to_source_from_do_end_block_wo_nesting_complication_spec.rb +46 -0
  172. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_many_matches_spec.rb +43 -0
  173. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_single_match_spec.rb +20 -0
  174. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_many_matches_spec.rb +45 -0
  175. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_no_match_spec.rb +45 -0
  176. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_single_match_spec.rb +22 -0
  177. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_spec.rb +84 -0
  178. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_many_matches_spec.rb +45 -0
  179. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_no_match_spec.rb +45 -0
  180. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_single_match_spec.rb +22 -0
  181. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_ignore_nested_spec.rb +43 -0
  182. data/lib/sourcify/spec/proc/to_source_from_multi_do_end_blocks_w_single_match_spec.rb +31 -0
  183. data/lib/sourcify/spec/proc/to_source_magic_file_var_spec.rb +127 -0
  184. data/lib/sourcify/spec/proc/to_source_magic_line_var_spec.rb +127 -0
  185. data/lib/sourcify/spec/proc/to_source_variables_spec.rb +29 -0
  186. data/lib/sourcify/spec/proc/to_source_w_specified_strip_enclosure_spec.rb +33 -0
  187. data/lib/sourcify/spec/proc/to_source_within_irb_spec.rb +38 -0
  188. data/lib/sourcify/spec/proc/to_source_within_pry_spec.rb +61 -0
  189. data/lib/sourcify/spec/raw_scanner/block_comment_shared_spec.rb +57 -0
  190. data/lib/sourcify/spec/raw_scanner/double_colons_shared_spec.rb +11 -0
  191. data/lib/sourcify/spec/raw_scanner/double_quote_str_w_interpolation_shared_spec.rb +60 -0
  192. data/lib/sourcify/spec/raw_scanner/double_quote_str_wo_interpolation_shared_spec.rb +86 -0
  193. data/lib/sourcify/spec/raw_scanner/heredoc_w_indent_shared_spec.rb +69 -0
  194. data/lib/sourcify/spec/raw_scanner/heredoc_wo_indent_shared_spec.rb +70 -0
  195. data/lib/sourcify/spec/raw_scanner/kw_block_start_alias1_shared_spec.rb +73 -0
  196. data/lib/sourcify/spec/raw_scanner/kw_block_start_alias2_shared_spec.rb +73 -0
  197. data/lib/sourcify/spec/raw_scanner/per_line_comment_shared_spec.rb +32 -0
  198. data/lib/sourcify/spec/raw_scanner/shared_specs.rb +3 -0
  199. data/lib/sourcify/spec/raw_scanner/single_quote_str_shared_spec.rb +79 -0
  200. data/lib/sourcify/spec/raw_scanner/slash_operator_shared_spec.rb +71 -0
  201. data/lib/sourcify/spec/run_build.sh +25 -0
  202. data/lib/sourcify/spec/spec_helper.rb +130 -0
  203. data/lib/symbolic/symbolic.rb +248 -0
  204. data/lib/symbolic/visitor.rb +51 -0
  205. data/lib/translator/block_translator.rb +123 -0
  206. data/lib/translator/command_translator.rb +421 -0
  207. data/lib/translator/last_returns_visitor.rb +57 -0
  208. data/lib/translator/local_variables_enumerator.rb +35 -0
  209. data/lib/translator/method_translator.rb +24 -0
  210. data/lib/translator/translator.rb +49 -0
  211. data/lib/type_aware_array.rb +71 -0
  212. data/lib/types/array_type.rb +51 -0
  213. data/lib/types/class_type.rb +128 -0
  214. data/lib/types/object_tracer.rb +162 -0
  215. data/lib/types/primitive_type.rb +73 -0
  216. data/lib/types/ruby_extension.rb +67 -0
  217. data/lib/types/ruby_type.rb +45 -0
  218. data/lib/types/type_inference.rb +382 -0
  219. data/lib/types/union_type.rb +155 -0
  220. metadata +321 -0
@@ -0,0 +1,39 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
2
+
3
+ describe 'Method#to_source' do
4
+ describe 'w specified {:strip_enclosure => ...}' do
5
+
6
+ describe '>> w true' do
7
+
8
+ options = {:strip_enclosure => true}
9
+
10
+ should 'strip enclosing proc wo arg' do
11
+ def m1; a+b; end
12
+ method(:m1).should.be having_source(%(a + b), options)
13
+ end
14
+
15
+ should 'strip enclosing proc w arg' do
16
+ def m2(a); a+b; end
17
+ method(:m2).should.be having_source(%(a+b), options)
18
+ end
19
+
20
+ end
21
+
22
+ describe '>> w false' do
23
+
24
+ options = {:strip_enclosure => false}
25
+
26
+ should 'not strip enclosing proc wo arg' do
27
+ def m3; a+b; end
28
+ method(:m3).should.be having_source(%(def m3; a+b; end), options)
29
+ end
30
+
31
+ should 'not strip enclosing proc w arg' do
32
+ def m4(a); a+b; end
33
+ method(:m4).should.be having_source(%(def m4(a); a+b; end), options)
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "Unsupported Platform" do
4
+
5
+ thing = Class.new do
6
+ def self.echo
7
+ end
8
+ end
9
+
10
+ should 'raise Sourcify::PlatformNotSupportedError when calling Method#to_source' do
11
+ lambda{ thing.method(:echo).to_source }.should.
12
+ raise(Sourcify::PlatformNotSupportedError)
13
+ end
14
+
15
+ should 'raise Sourcify::PlatformNotSupportedError when calling Method#to_sexp' do
16
+ lambda{ thing.method(:echo).to_sexp }.should.
17
+ raise(Sourcify::PlatformNotSupportedError)
18
+ end
19
+
20
+ should 'raise Sourcify::PlatformNotSupportedError when calling Method#to_raw_source' do
21
+ lambda{ thing.method(:echo).to_raw_source }.should.
22
+ raise(Sourcify::PlatformNotSupportedError)
23
+ end
24
+
25
+ end
26
+
@@ -0,0 +1,27 @@
1
+ shared 'Proc#to_source from { ... } block (1.9.*)' do
2
+
3
+ should 'handle simple (w label keys)' do
4
+ (
5
+ lambda {
6
+ {a: 1, b: 2}
7
+ }
8
+ ).should.be having_source(%Q\
9
+ proc do
10
+ {:a => 1, :b => 2}
11
+ end
12
+ \)
13
+ end
14
+
15
+ should 'handle nested (w label keys)' do
16
+ (
17
+ lambda {
18
+ {a: 1, b: {c: 3}}
19
+ }
20
+ ).should.be having_source(%Q\
21
+ proc do
22
+ {:a => 1, :b => {:c => 3}}
23
+ end
24
+ \)
25
+ end
26
+
27
+ end
@@ -0,0 +1,80 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
2
+
3
+ describe "Created on the fly proc" do
4
+ unless has_parsetree?
5
+
6
+ klass = Class.new do
7
+ def test(&block); block ; end
8
+ def blah; 1+2; end
9
+ end
10
+
11
+ describe 'Blah#to_proc raising Sourcify::CannotHandleCreatedOnTheFlyProcError' do
12
+
13
+ should "raise when created by :to_proc" do
14
+ lambda {
15
+ x, y = klass.new.method(:test).to_proc, lambda { 1+2 }
16
+ x.to_source
17
+ }.should.raise(Sourcify::CannotHandleCreatedOnTheFlyProcError)
18
+ end
19
+
20
+ should "not raise even with prepending #to_proc on the same line" do
21
+ x, y = klass.new.method(:test).to_proc, lambda { 1+2 }
22
+ y.to_source.should.not.be.nil
23
+ end
24
+
25
+ should "not raise even with appending #to_proc on the same line" do
26
+ x, y = lambda { 1+2 }, klass.new.method(:test).to_proc
27
+ x.to_source.should.not.be.nil
28
+ end
29
+
30
+ should "not raise even with nested #to_proc on the same line" do
31
+ x = lambda { klass.new.method(:test).to_proc }
32
+ x.to_source.should.not.be.nil
33
+ end
34
+
35
+ should "not raise with nested #to_proc on diff line" do
36
+ (
37
+ lambda do
38
+ klass.new.method(:test).to_proc
39
+ end
40
+ ).to_source.should.not.be.nil
41
+ end
42
+
43
+ end
44
+
45
+ describe '&:blah raising Sourcify::CannotHandleCreatedOnTheFlyProcError' do
46
+
47
+ should "raise when created by &:blah" do
48
+ lambda {
49
+ x, y = klass.new.test(&:blah), lambda { 1+2 }
50
+ x.to_source
51
+ }.should.raise(Sourcify::CannotHandleCreatedOnTheFlyProcError)
52
+ end
53
+
54
+ should "not raise even with prepending &:blah on the same line" do
55
+ x, y = klass.new.test(&:blah), lambda { 1+2 }
56
+ y.to_source.should.not.be.nil
57
+ end
58
+
59
+ should "not raise even with appending &:blah on the same line" do
60
+ x, y = lambda { 1+2 }, klass.new.test(&:blah)
61
+ x.to_source.should.not.be.nil
62
+ end
63
+
64
+ should "not raise even with nested &:blah on the same line" do
65
+ x = lambda { klass.new.test(&:blah) }
66
+ x.to_source.should.not.be.nil
67
+ end
68
+
69
+ should "not raise with nested &:blah on diff line" do
70
+ (
71
+ lambda do
72
+ klass.new.test(&:blah)
73
+ end
74
+ ).to_source.should.not.be.nil
75
+ end
76
+
77
+ end
78
+
79
+ end
80
+ end
@@ -0,0 +1,36 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # NOTE: The examples in this file are adapted from the original pull
4
+ # request submitted by tomykaira @ https://github.com/ngty/sourcify/pull/19.
5
+ #
6
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
7
+
8
+ describe "Encoding" do
9
+ next unless Sourcify::IS_19x
10
+
11
+ should "handle proc with UTF-8 string" do
12
+ lambda { "こんにちは" }.should.be having_sexp(
13
+ s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:str, "こんにちは"))
14
+ )
15
+ end
16
+
17
+ should "handle proc with unicode regexp" do
18
+ # NOTE: This specifically addresses https://github.com/ngty/sourcify/issues/15
19
+ lambda { /\p{Lu}/ }.should.be having_sexp(
20
+ s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:lit, /\p{Lu}/))
21
+ )
22
+ end
23
+
24
+ should "handle proc with UTF-8 heredoc" do
25
+ (
26
+ lambda do
27
+ <<-EOL
28
+ こんにちは
29
+ EOL
30
+ end
31
+ ).should.be having_sexp(
32
+ s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:str, " こんにちは\n"))
33
+ )
34
+ end
35
+
36
+ end
@@ -0,0 +1,40 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
2
+
3
+ describe "Misc" do
4
+
5
+ should 'handle accessing #to_sexp after #to_source' do
6
+ (s_proc = lambda { :test }).to_source
7
+ s_proc.should.be having_sexp(s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:lit, :test)))
8
+ end
9
+
10
+ should 'handle accessing #to_source after #to_sexp' do
11
+ (s_proc = lambda { :test }).to_sexp
12
+ s_proc.should.be having_source('proc { :test }')
13
+ end
14
+
15
+ should "handle proc with '/' char" do
16
+ (lambda { @x1/2 }).should.be having_source('proc { @x1/2 }')
17
+ end
18
+
19
+ should "handle lexer bug in missing trailing chars after '=>' operator" do
20
+ # This example addresses bug @ http://redmine.ruby-lang.org/issues/show/3765
21
+ {
22
+ __LINE__ => lambda { :test }
23
+ }.values.last.should.be having_source('proc { :test }')
24
+ end
25
+
26
+ should "handle lexer bug in missing trailing chars after '=>' operator" do
27
+ # This example addresses bug @ http://redmine.ruby-lang.org/issues/show/3765
28
+ {
29
+ __LINE__ => lambda do :test end
30
+ }.values.last.should.be having_source('proc { :test }')
31
+ end
32
+
33
+ unless has_parsetree?
34
+ should "raise Sourcify::CannotParseEvalCodeError when proc is created from eval" do
35
+ lambda { eval("proc {:test }").to_source }.should.
36
+ raise(Sourcify::CannotParseEvalCodeError)
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ unless has_parsetree?
4
+ describe "Proc's raw scanner > block comment (=begin ... =end)" do
5
+ extend Sourcify::Proc::Parser::RawScanner::Spec::GenericSupport
6
+ behaves_like "Block comment (=begin ... =end)"
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ unless has_parsetree?
4
+ describe "Proc's raw scanner > double colons" do
5
+ extend Sourcify::Proc::Parser::RawScanner::Spec::GenericSupport
6
+ behaves_like "Double colons"
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ unless has_parsetree?
4
+ describe "Proc's raw scanner > double quote strings (w interpolation)" do
5
+ extend Sourcify::Proc::Parser::RawScanner::Spec::GenericSupport
6
+ behaves_like "Double quote strings (w interpolation)"
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ unless has_parsetree?
4
+ describe "Proc's raw scanner > double quote strings (wo interpolation)" do
5
+ extend Sourcify::Proc::Parser::RawScanner::Spec::GenericSupport
6
+ behaves_like "Double quote strings (wo interpolation)"
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ unless has_parsetree?
4
+ describe "Proc's raw scanner > heredoc (w indent)" do
5
+ extend Sourcify::Proc::Parser::RawScanner::Spec::GenericSupport
6
+ behaves_like "Heredoc (w indent)"
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ unless has_parsetree?
4
+ describe "Proc's raw scanner > heredoc (wo indent)" do
5
+ extend Sourcify::Proc::Parser::RawScanner::Spec::GenericSupport
6
+ behaves_like "Heredoc (wo indent)"
7
+ end
8
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ unless has_parsetree?
4
+ describe "Proc's raw scanner > keyword block start alias #1 (incrementing counter by 1)" do
5
+
6
+ extend Sourcify::Proc::Parser::RawScanner::Spec::KwBlockStartSupport
7
+ behaves_like "Keyword block start alias #1 (incrementing counter by 1)"
8
+
9
+ kw_block_start_alias1.each do |kw|
10
+ should "increment counter with ... do #{kw} ..." do
11
+ kw_block_start_counter(<<EOL
12
+ aa do #{kw} bb ...
13
+ cc
14
+ EOL
15
+ ).should.equal([2,2])
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ unless has_parsetree?
4
+ describe "Proc's raw scanner > keyword block start alias #2 (incrementing counter by 0..1)" do
5
+
6
+ extend Sourcify::Proc::Parser::RawScanner::Spec::KwBlockStartSupport
7
+ behaves_like "Keyword block start alias #2 (incrementing counter by 0..1)"
8
+
9
+ kw_block_start_alias2.each do |kw|
10
+ should "increment counter with ... do #{kw} ..." do
11
+ kw_block_start_counter(<<EOL
12
+ aa do #{kw} bb ...
13
+ cc
14
+ EOL
15
+ ).should.equal([1,2])
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ unless has_parsetree?
4
+ describe "Proc's raw scanner > per line comment (# ...)" do
5
+ extend Sourcify::Proc::Parser::RawScanner::Spec::GenericSupport
6
+ behaves_like "Per line comment (# ...)"
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ unless has_parsetree?
4
+ describe "Proc's raw scanner > single quote strings (\', %q & %w)" do
5
+ extend Sourcify::Proc::Parser::RawScanner::Spec::GenericSupport
6
+ behaves_like 'Single quote strings (\', %q & %w)'
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ unless has_parsetree?
4
+ describe "Proc's raw scanner > slash operator" do
5
+ extend Sourcify::Proc::Parser::RawScanner::Spec::GenericSupport
6
+ behaves_like 'Slash operator'
7
+ end
8
+ end
@@ -0,0 +1,63 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+ require File.expand_path('../../../raw_scanner/shared_specs', __FILE__)
3
+
4
+ module Sourcify::Proc::Parser::RawScanner
5
+
6
+ SCANNER = self
7
+
8
+ class << self
9
+ attr_reader :tokens, :do_end_counter
10
+ end
11
+
12
+ module Spec
13
+
14
+ module GenericSupport
15
+ def self.extended(base)
16
+ base.instance_eval do
17
+ def process(data)
18
+ SCANNER.process(data)
19
+ SCANNER.tokens
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ module KwBlockStartSupport
26
+ def self.extended(base)
27
+ base.instance_eval do
28
+
29
+ before do
30
+ counter(:DoEndBlockCounter).class_eval do
31
+ alias_method :orig_started?, :started?
32
+ def started?; true; end
33
+ end
34
+ end
35
+
36
+ after do
37
+ counter(:DoEndBlockCounter).class_eval do
38
+ alias_method :started?, :orig_started?
39
+ end
40
+ end
41
+
42
+ def counter(type)
43
+ Sourcify::Proc::Parser::RawScanner::Extensions.const_get(type)
44
+ end
45
+
46
+ def kw_block_start_counter(data)
47
+ SCANNER.process(data)
48
+ SCANNER.do_end_counter.counts
49
+ end
50
+
51
+ def kw_block_start_alias1
52
+ %w{class def module begin case module if unless}
53
+ end
54
+
55
+ def kw_block_start_alias2
56
+ %w{while until for}
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ end
63
+ end