sourcify 0.5.0 → 0.6.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. data/.gitignore +1 -0
  2. data/HISTORY.txt +5 -0
  3. data/README.rdoc +86 -3
  4. data/Rakefile +47 -15
  5. data/lib/sourcify.rb +13 -0
  6. data/lib/sourcify/common/parser/converter.rb +29 -0
  7. data/lib/sourcify/common/parser/raw_scanner/comment.rb +23 -0
  8. data/lib/sourcify/common/parser/raw_scanner/counter.rb +43 -0
  9. data/lib/sourcify/common/parser/raw_scanner/dstring.rb +60 -0
  10. data/lib/sourcify/common/parser/raw_scanner/extensions.rb +121 -0
  11. data/lib/sourcify/common/parser/raw_scanner/heredoc.rb +26 -0
  12. data/lib/sourcify/common/parser/source_code.rb +33 -0
  13. data/lib/sourcify/common/ragel/common.rl +5 -0
  14. data/lib/sourcify/common/ragel/expressions.rl +38 -0
  15. data/lib/sourcify/{proc/scanner.rl → common/ragel/machines.rl} +10 -178
  16. data/lib/sourcify/errors.rb +4 -0
  17. data/lib/sourcify/method.rb +134 -0
  18. data/lib/sourcify/method/methods.rb +3 -0
  19. data/lib/sourcify/method/methods/to_raw_source.rb +30 -0
  20. data/lib/sourcify/method/methods/to_sexp.rb +30 -0
  21. data/lib/sourcify/method/methods/to_source.rb +30 -0
  22. data/lib/sourcify/method/parser.rb +104 -0
  23. data/lib/sourcify/method/parser/converter.rb +8 -0
  24. data/lib/sourcify/method/parser/raw_scanner.rb +2494 -0
  25. data/lib/sourcify/method/parser/raw_scanner.rl +144 -0
  26. data/lib/sourcify/method/parser/raw_scanner_extensions.rb +64 -0
  27. data/lib/sourcify/method/parser/scanner.rb +48 -0
  28. data/lib/sourcify/method/parser/source_code.rb +8 -0
  29. data/lib/sourcify/proc.rb +0 -2
  30. data/lib/sourcify/proc/parser.rb +2 -5
  31. data/lib/sourcify/proc/parser/converter.rb +2 -23
  32. data/lib/sourcify/proc/{scanner.rb → parser/raw_scanner.rb} +808 -806
  33. data/lib/sourcify/proc/parser/raw_scanner.rl +149 -0
  34. data/lib/sourcify/proc/parser/raw_scanner_extensions.rb +72 -0
  35. data/lib/sourcify/proc/parser/{code_scanner.rb → scanner.rb} +9 -5
  36. data/lib/sourcify/proc/parser/source_code.rb +2 -27
  37. data/lib/sourcify/version.rb +1 -1
  38. data/spec/method/others_from_def_end_block_spec.rb +49 -0
  39. data/spec/method/others_from_define_method_spec.rb +62 -0
  40. data/spec/method/raw_scanner/block_comment_spec.rb +8 -0
  41. data/spec/method/raw_scanner/double_colons_spec.rb +8 -0
  42. data/spec/method/raw_scanner/double_quote_str_w_interpolation_spec.rb +8 -0
  43. data/spec/method/raw_scanner/double_quote_str_wo_interpolation_spec.rb +8 -0
  44. data/spec/method/raw_scanner/heredoc_w_indent_spec.rb +8 -0
  45. data/spec/method/raw_scanner/heredoc_wo_indent_spec.rb +8 -0
  46. data/spec/method/raw_scanner/kw_block_start_alias1_spec.rb +20 -0
  47. data/spec/method/raw_scanner/kw_block_start_alias2_spec.rb +20 -0
  48. data/spec/method/raw_scanner/per_line_comment_spec.rb +8 -0
  49. data/spec/method/raw_scanner/single_quote_str_spec.rb +8 -0
  50. data/spec/method/raw_scanner/slash_operator_spec.rb +8 -0
  51. data/spec/method/raw_scanner/spec_helper.rb +80 -0
  52. data/spec/method/spec_helper.rb +1 -0
  53. data/spec/method/to_raw_source_spec.rb +31 -0
  54. data/spec/method/to_raw_source_w_specified_strip_enclosure_spec.rb +148 -0
  55. data/spec/method/to_sexp_from_def_end_block_w_variables_spec.rb +46 -0
  56. data/spec/method/to_sexp_from_def_end_block_within_irb_spec.rb +38 -0
  57. data/spec/method/to_sexp_from_define_method_w_multi_blocks_and_specified_attached_to_spec.rb +56 -0
  58. data/spec/method/to_sexp_from_define_method_w_variables_spec.rb +52 -0
  59. data/spec/method/to_sexp_from_define_method_within_irb_spec.rb +42 -0
  60. data/spec/method/to_sexp_w_specified_strip_enclosure_spec.rb +74 -0
  61. data/spec/method/to_source_from_def_end_block_w_19_extras_spec.rb +23 -0
  62. data/spec/method/to_source_from_def_end_block_w_nested_begin_spec.rb +35 -0
  63. data/spec/method/to_source_from_def_end_block_w_nested_case_spec.rb +35 -0
  64. data/spec/method/to_source_from_def_end_block_w_nested_class_spec.rb +51 -0
  65. data/spec/method/to_source_from_def_end_block_w_nested_do_end_block_spec.rb +33 -0
  66. data/spec/method/to_source_from_def_end_block_w_nested_for_spec.rb +126 -0
  67. data/spec/method/to_source_from_def_end_block_w_nested_if_spec.rb +82 -0
  68. data/spec/method/to_source_from_def_end_block_w_nested_literal_keyword_spec.rb +141 -0
  69. data/spec/method/to_source_from_def_end_block_w_nested_method_spec.rb +33 -0
  70. data/spec/method/to_source_from_def_end_block_w_nested_module_spec.rb +59 -0
  71. data/spec/method/to_source_from_def_end_block_w_nested_unless_spec.rb +82 -0
  72. data/spec/method/to_source_from_def_end_block_w_nested_until_spec.rb +179 -0
  73. data/spec/method/to_source_from_def_end_block_w_nested_while_spec.rb +179 -0
  74. data/spec/method/to_source_from_def_end_block_w_singleton_method_spec.rb +19 -0
  75. data/spec/method/to_source_from_def_end_block_within_irb_spec.rb +30 -0
  76. data/spec/method/to_source_from_def_end_w_multi_blocks_and_many_matches_spec.rb +30 -0
  77. data/spec/method/to_source_from_def_end_w_multi_blocks_and_single_match_spec.rb +36 -0
  78. data/spec/method/to_source_from_define_method_w_braced_block_spec.rb +113 -0
  79. data/spec/method/to_source_from_define_method_w_do_end_block_spec.rb +145 -0
  80. data/spec/method/to_source_from_define_method_w_multi_blocks_and_many_matches_spec.rb +56 -0
  81. data/spec/method/to_source_from_define_method_w_multi_blocks_and_single_match_spec.rb +73 -0
  82. data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_and_many_matches_spec.rb +36 -0
  83. data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_and_no_match_spec.rb +36 -0
  84. data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_and_single_match_spec.rb +28 -0
  85. data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_spec.rb +103 -0
  86. data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_body_matcher_and_many_matches_spec.rb +36 -0
  87. data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_body_matcher_and_no_match_spec.rb +36 -0
  88. data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_body_matcher_and_single_match_spec.rb +28 -0
  89. data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_ignore_nested_spec.rb +36 -0
  90. data/spec/method/to_source_from_define_method_within_irb_spec.rb +32 -0
  91. data/spec/method/to_source_magic_file_var_spec.rb +176 -0
  92. data/spec/method/to_source_magic_line_var_spec.rb +298 -0
  93. data/spec/method/to_source_w_specified_strip_enclosure_spec.rb +39 -0
  94. data/spec/no_method/unsupported_platform_spec.rb +26 -0
  95. data/spec/proc/raw_scanner/block_comment_spec.rb +8 -0
  96. data/spec/proc/raw_scanner/double_colons_spec.rb +8 -0
  97. data/spec/proc/raw_scanner/double_quote_str_w_interpolation_spec.rb +8 -0
  98. data/spec/proc/raw_scanner/double_quote_str_wo_interpolation_spec.rb +8 -0
  99. data/spec/proc/raw_scanner/heredoc_w_indent_spec.rb +8 -0
  100. data/spec/proc/raw_scanner/heredoc_wo_indent_spec.rb +8 -0
  101. data/spec/proc/raw_scanner/kw_block_start_alias1_spec.rb +20 -0
  102. data/spec/proc/raw_scanner/kw_block_start_alias2_spec.rb +20 -0
  103. data/spec/proc/raw_scanner/per_line_comment_spec.rb +8 -0
  104. data/spec/proc/raw_scanner/single_quote_str_spec.rb +8 -0
  105. data/spec/proc/raw_scanner/slash_operator_spec.rb +8 -0
  106. data/spec/proc/raw_scanner/spec_helper.rb +63 -0
  107. data/spec/{proc_scanner/block_comment_spec.rb → raw_scanner/block_comment_shared_spec.rb} +1 -5
  108. data/spec/{proc_scanner/double_colons_spec.rb → raw_scanner/double_colons_shared_spec.rb} +1 -5
  109. data/spec/{proc_scanner/double_quote_str_w_interpolation_spec.rb → raw_scanner/double_quote_str_w_interpolation_shared_spec.rb} +1 -5
  110. data/spec/{proc_scanner/double_quote_str_wo_interpolation_spec.rb → raw_scanner/double_quote_str_wo_interpolation_shared_spec.rb} +1 -5
  111. data/spec/raw_scanner/heredoc_w_indent_shared_spec.rb +69 -0
  112. data/spec/raw_scanner/heredoc_wo_indent_shared_spec.rb +70 -0
  113. data/spec/{proc_scanner/kw_do_alias1_spec.rb → raw_scanner/kw_block_start_alias1_shared_spec.rb} +10 -26
  114. data/spec/{proc_scanner/kw_do_alias2_spec.rb → raw_scanner/kw_block_start_alias2_shared_spec.rb} +10 -25
  115. data/spec/{proc_scanner/per_line_comment_spec.rb → raw_scanner/per_line_comment_shared_spec.rb} +1 -5
  116. data/spec/raw_scanner/shared_specs.rb +3 -0
  117. data/spec/{proc_scanner/single_quote_str_spec.rb → raw_scanner/single_quote_str_shared_spec.rb} +1 -5
  118. data/spec/{proc_scanner/slash_operator_spec.rb → raw_scanner/slash_operator_shared_spec.rb} +1 -5
  119. data/spec/run_spec.sh +7 -1
  120. data/spec/spec_helper.rb +8 -25
  121. metadata +204 -47
  122. data/.rvmrc +0 -1
  123. data/VERSION +0 -1
  124. data/lib/sourcify/proc/scanner/comment.rb +0 -21
  125. data/lib/sourcify/proc/scanner/counter.rb +0 -44
  126. data/lib/sourcify/proc/scanner/dstring.rb +0 -59
  127. data/lib/sourcify/proc/scanner/extensions.rb +0 -171
  128. data/lib/sourcify/proc/scanner/heredoc.rb +0 -24
  129. data/spec/proc_scanner/heredoc_spec.rb +0 -144
  130. data/spec/proc_scanner/spec_helper.rb +0 -33
@@ -0,0 +1,56 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
2
+
3
+ describe 'Method#to_source (from #define_method)' do
4
+ describe 'w multi blocks and many matches' do
5
+
6
+ if has_parsetree?
7
+ # TODO: Should we support this ??
8
+ else
9
+
10
+ before { @thing = Object.new }
11
+ error = Sourcify::MultipleMatchingProcsPerLineError
12
+
13
+ describe 'w do...end block' do
14
+ should "raise #{error} w no nesting on same line" do
15
+ b1 = lambda do |a| @x end; b2 = lambda do @x end; b3 = lambda do @x end
16
+ @thing.class.send(:define_method, :m1, &b2)
17
+ lambda { @thing.method(:m1).to_source }.should.raise(error)
18
+ end
19
+
20
+ should "raise #{error} w single level nesting on same line" do
21
+ b1 = lambda do |a| @x end; b2 = lambda do lambda do @x end end
22
+ @thing.class.send(:define_method, :m2, &b2)
23
+ lambda { @thing.method(:m2).to_source }.should.raise(error)
24
+ end
25
+
26
+ should "raise #{error} w multi level nesting on same line" do
27
+ b2 = (lambda do |a| lambda do lambda do @x end end end).call(1)
28
+ @thing.class.send(:define_method, :m3, &b2)
29
+ lambda { @thing.method(:m3).to_source }.should.raise(error)
30
+ end
31
+ end
32
+
33
+ describe 'w braced block' do
34
+ should "raise #{error} w no nesting on same line" do
35
+ b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x }
36
+ @thing.class.send(:define_method, :m1, &b2)
37
+ lambda { @thing.method(:m1).to_source }.should.raise(error)
38
+ end
39
+
40
+ should "raise #{error} w single level nesting on same line" do
41
+ b1 = lambda {|a| @x }; b2 = lambda { lambda { @x } }
42
+ @thing.class.send(:define_method, :m2, &b2)
43
+ lambda { @thing.method(:m2).to_source }.should.raise(error)
44
+ end
45
+
46
+ should "raise #{error} w multi level nesting on same line" do
47
+ b2 = (lambda {|a| lambda { lambda { @x } } }).call(1)
48
+ @thing.class.send(:define_method, :m3, &b2)
49
+ lambda { @thing.method(:m3).to_source }.should.raise(error)
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,73 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
2
+
3
+ describe 'Method#to_source (from define_method)' do
4
+ describe 'w single blocks and many matches' do
5
+
6
+ before { @thing = Object.new }
7
+
8
+ describe 'w do...end block' do
9
+ should 'skip non-matching w no nesting on same line' do
10
+ b1 = lambda do |a| @x1 end; b2 = lambda do |b| @x2 end
11
+ @thing.class.send(:define_method, :m1, &b2)
12
+ @thing.method(:m1).should.be having_source(%(
13
+ def m1(b)
14
+ @x2
15
+ end
16
+ ))
17
+ end
18
+
19
+ should 'skip non-matching w single level nesting on same line' do
20
+ b2 = (lambda do |a| lambda do |b| @x2 end end).call(1)
21
+ @thing.class.send(:define_method, :m2, &b2)
22
+ @thing.method(:m2).should.be having_source(%(
23
+ def m2(b)
24
+ @x2
25
+ end
26
+ ))
27
+ end
28
+
29
+ should 'skip non-matching w multi level nesting on same line' do
30
+ b2 = (lambda do |a| lambda do |b| b2 = lambda do |c| @x3 end end end).call(1).call(1)
31
+ @thing.class.send(:define_method, :m3, &b2)
32
+ @thing.method(:m3).should.be having_source(%(
33
+ def m3(c)
34
+ @x3
35
+ end
36
+ ))
37
+ end
38
+ end
39
+
40
+ describe 'w braced block' do
41
+ should 'skip non-matching w no nesting on same line' do
42
+ b1 = lambda {|a| @x1 }; b2 = lambda {|b| @x2 }
43
+ @thing.class.send(:define_method, :m1, &b2)
44
+ @thing.method(:m1).should.be having_source(%(
45
+ def m1(b)
46
+ @x2
47
+ end
48
+ ))
49
+ end
50
+
51
+ should 'skip non-matching w single level nesting on same line' do
52
+ b2 = (lambda {|a| lambda {|b| @x2 } }).call(1)
53
+ @thing.class.send(:define_method, :m2, &b2)
54
+ @thing.method(:m2).should.be having_source(%(
55
+ def m2(b)
56
+ @x2
57
+ end
58
+ ))
59
+ end
60
+
61
+ should 'skip non-matching w multi level nesting on same line' do
62
+ b2 = (lambda {|a| lambda {|b| b2 = lambda {|c| @x3 } } }).call(1).call(1)
63
+ @thing.class.send(:define_method, :m3, &b2)
64
+ @thing.method(:m3).should.be having_source(%(
65
+ def m3(c)
66
+ @x3
67
+ end
68
+ ))
69
+ end
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,36 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
2
+
3
+ describe 'Method#to_source (from define_method)' do
4
+ describe 'w specified {:attached_to => ...} & single match' do
5
+
6
+ before { @thing = Object.new }
7
+ options = {:attached_to => :lambda}
8
+
9
+ if has_parsetree?
10
+ # TODO: Should we support this ??
11
+ else
12
+
13
+ error = Sourcify::MultipleMatchingProcsPerLineError
14
+
15
+ should "raise #{error} w no nesting on same line" do
16
+ b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x }
17
+ @thing.class.send(:define_method, :m1, &b2)
18
+ lambda { @thing.method(:m1).to_source(options) }.should.raise(error)
19
+ end
20
+
21
+ should "raise #{error} w single level nesting on same line" do
22
+ b1 = lambda {|a| @x }; b2 = lambda { lambda { @x } }
23
+ @thing.class.send(:define_method, :m2, &b2)
24
+ lambda { @thing.method(:m2).to_source(options) }.should.raise(error)
25
+ end
26
+
27
+ should "raise #{error} w multi level nesting on same line" do
28
+ b2 = (lambda {|a| lambda { lambda { @x } } }).call(1)
29
+ @thing.class.send(:define_method, :m3, &b2)
30
+ lambda { @thing.method(:m3).to_source(options) }.should.raise(error)
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
2
+
3
+ describe 'Method#to_source (from define_method)' do
4
+ describe 'w specified {:attached_to => ...} & no match' do
5
+
6
+ before { @thing = Object.new }
7
+ options = {:attached_to => :forever}
8
+
9
+ if has_parsetree?
10
+ # TODO: Should we support this ??
11
+ else
12
+
13
+ error = Sourcify::NoMatchingProcError
14
+
15
+ should "raise #{error} w no nesting on same line" do
16
+ b1 = lambda {|a| @x }; b2 = watever { @x }; b3 = lambda { @x }
17
+ @thing.class.send(:define_method, :m1, &b2)
18
+ lambda { @thing.method(:m1).to_source(options) }.should.raise(error)
19
+ end
20
+
21
+ should "raise #{error} w single level nesting on same line" do
22
+ b1 = lambda {|a| @x }; b2 = watever { lambda { @x } }
23
+ @thing.class.send(:define_method, :m2, &b2)
24
+ lambda { @thing.method(:m2).to_source(options) }.should.raise(error)
25
+ end
26
+
27
+ should "raise #{error} w multi level nesting on same line" do
28
+ b2 = (lambda {|a| watever { lambda { @x } } }).call(1)
29
+ @thing.class.send(:define_method, :m3, &b2)
30
+ lambda { @thing.method(:m3).to_source(options) }.should.raise(error)
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,28 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
2
+
3
+ describe 'Method#to_source (from define_method)' do
4
+ describe 'w specified {:attached_to => ...} & single match' do
5
+
6
+ before { @thing = Object.new }
7
+ options = {:attached_to => :watever}
8
+
9
+ should 'handle no nesting on same line' do
10
+ b1 = lambda {|a| @x1+1 }; b2 = watever { @x1+2 }; b3 = lambda { @x1+3 }
11
+ @thing.class.send(:define_method, :m1, &b2)
12
+ @thing.method(:m1).should.be having_source('def m1; @x1+2; end', options)
13
+ end
14
+
15
+ should 'handle single level nesting on same line' do
16
+ b1 = lambda {|a| @x2+1 }; b2 = watever { lambda { @x2+2 } }
17
+ @thing.class.send(:define_method, :m2, &b2)
18
+ @thing.method(:m2).should.be having_source('def m2; lambda { @x2+2 }; end', options)
19
+ end
20
+
21
+ should 'handle multi level nesting on same line' do
22
+ b2 = (lambda {|a| watever { lambda { @x3 } } }).call(1)
23
+ @thing.class.send(:define_method, :m3, &b2)
24
+ @thing.method(:m3).should.be having_source('def m3; lambda { @x3 }; end', options)
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,103 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
2
+
3
+ describe 'Method#to_source (from define_method)' do
4
+ describe 'w specified {:attached_to => ...}' do
5
+
6
+ if has_parsetree?
7
+ # TODO: Should we support this ??
8
+ else
9
+
10
+ before { @thing = Object.new }
11
+
12
+ err1 = Sourcify::MultipleMatchingProcsPerLineError
13
+ err2 = Sourcify::NoMatchingProcError
14
+
15
+ describe '>> w :attached_to as regexp' do
16
+
17
+ should "raise Sourcify::MultipleMatchingProcsPerLineError for multiple matches" do
18
+ b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x }
19
+ @thing.class.send(:define_method, :m1, &b2)
20
+ lambda { @thing.method(:m1).to_source(:attached_to => /^(?:.*?\W|)lambda(?:\W)/) }.should.raise(err1)
21
+ end
22
+
23
+ should "raise Sourcify::NoMatchingProcError for no match" do
24
+ b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x }
25
+ @thing.class.send(:define_method, :m2, &b2)
26
+ lambda { @thing.method(:m2).to_source(:attached_to => /^(?:.*?\W|)proc(?:\W)/) }.should.raise(err2)
27
+ end
28
+
29
+ should "handle for single match" do
30
+ b1 = lambda {|a| @x1 }; b2 = proc { @x2 }; b3 = lambda { @x3 }
31
+ @thing.class.send(:define_method, :m3, &b2)
32
+ @thing.method(:m3).should.be having_source('def m3; @x2; end', :attached_to => /^(?:.*?\W|)proc(?:\W)/)
33
+ end
34
+
35
+ end
36
+
37
+ describe '>> w :attached_to as string' do
38
+
39
+ should "raise Sourcify::MultipleMatchingProcsPerLineError for multiple matches" do
40
+ b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x }
41
+ @thing.class.send(:define_method, :m1, &b2)
42
+ lambda { @thing.method(:m1).to_source(:attached_to => 'lambda') }.should.raise(err1)
43
+ end
44
+
45
+ should "raise Sourcify::NoMatchingProcError for no match" do
46
+ b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x }
47
+ @thing.class.send(:define_method, :m2, &b2)
48
+ lambda { @thing.method(:m2).to_source(:attached_to => 'proc') }.should.raise(err2)
49
+ end
50
+
51
+ should "handle for single match" do
52
+ b1 = lambda {|a| @x1 }; b2 = proc { @x2 }; b3 = lambda { @x3 }
53
+ @thing.class.send(:define_method, :m3, &b2)
54
+ @thing.method(:m3).should.be having_source('def m3; @x2; end', :attached_to => 'proc')
55
+ end
56
+
57
+ end
58
+
59
+ describe '>> w :attached_to as symbol' do
60
+
61
+ should "raise Sourcify::MultipleMatchingProcsPerLineError for multiple matches" do
62
+ b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x }
63
+ @thing.class.send(:define_method, :m1, &b2)
64
+ lambda { @thing.method(:m1).to_source(:attached_to => :lambda) }.should.raise(err1)
65
+ end
66
+
67
+ should "raise Sourcify::NoMatchingProcError for no match" do
68
+ b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x }
69
+ @thing.class.send(:define_method, :m2, &b2)
70
+ lambda { @thing.method(:m2).to_source(:attached_to => :proc) }.should.raise(err2)
71
+ end
72
+
73
+ should "handle for single match" do
74
+ b1 = lambda {|a| @x1 }; b2 = proc { @x2 }; b3 = lambda { @x3 }
75
+ @thing.class.send(:define_method, :m3, &b2)
76
+ @thing.method(:m3).should.be having_source('def m3; @x2; end', :attached_to => :proc)
77
+ end
78
+
79
+ end
80
+
81
+ describe '>> w false start as a result of preceding hash' do
82
+
83
+ option = {:attached_to => :watever}
84
+ aa = :aa
85
+
86
+ should 'handle for do ... end block' do
87
+ x = watever({aa => 1, :bb => 3}) do :blah end
88
+ @thing.class.send(:define_method, :m1, &x)
89
+ @thing.method(:m1).should.be having_source('def m1; :blah; end', option)
90
+ end
91
+
92
+ should 'handle for { ... } block' do
93
+ x = watever({aa => 1, :bb => 3}) { :blah }
94
+ @thing.class.send(:define_method, :m2, &x)
95
+ @thing.method(:m2).should.be having_source('def m2; :blah; end', option)
96
+ end
97
+
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1,36 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
2
+
3
+ describe 'Method#to_source (from define_method)' do
4
+ describe 'w specified body matcher & single match' do
5
+
6
+ before { @thing = Object.new }
7
+ matcher = lambda {|code| code =~ /^(.*\W|)alert\W/ }
8
+
9
+ if has_parsetree?
10
+ # TODO: Should we support this ??
11
+ else
12
+
13
+ error = Sourcify::MultipleMatchingProcsPerLineError
14
+
15
+ should "raise #{error} w no nesting on same line" do
16
+ b1 = lambda {|a| @x }; b2 = lambda { alert(1) }; b3 = lambda { alert(2) }
17
+ @thing.class.send(:define_method, :m1, &b2)
18
+ lambda { @thing.method(:m1).to_source(&matcher) }.should.raise(error)
19
+ end
20
+
21
+ should "raise #{error} w single level nesting on same line" do
22
+ b1 = lambda {|a| @x }; b2 = lambda { lambda { alert(1) } }
23
+ @thing.class.send(:define_method, :m2, &b2)
24
+ lambda { @thing.method(:m2).to_source(&matcher) }.should.raise(error)
25
+ end
26
+
27
+ should "raise #{error} w multi level nesting on same line" do
28
+ b2 = (lambda {|a| lambda { lambda { alert(1) } } }).call(1)
29
+ @thing.class.send(:define_method, :m3, &b2)
30
+ lambda { @thing.method(:m3).to_source(&matcher) }.should.raise(error)
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
2
+
3
+ describe 'Method#to_source (from define_method)' do
4
+ describe 'w specified body matcher & no match' do
5
+
6
+ before { @thing = Object.new }
7
+ matcher = lambda {|code| code =~ /^(.*\W|)def\W/ }
8
+
9
+ if has_parsetree?
10
+ # TODO: Should we support this ??
11
+ else
12
+
13
+ error = Sourcify::NoMatchingProcError
14
+
15
+ should "raise #{error} w no nesting on same line" do
16
+ b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x }
17
+ @thing.class.send(:define_method, :m1, &b2)
18
+ lambda { @thing.method(:m1).to_source(&matcher) }.should.raise(error)
19
+ end
20
+
21
+ should "raise #{error} w single level nesting on same line" do
22
+ b1 = lambda {|a| @x }; b2 = lambda { lambda { @x } }
23
+ @thing.class.send(:define_method, :m2, &b2)
24
+ lambda { @thing.method(:m2).to_source(&matcher) }.should.raise(error)
25
+ end
26
+
27
+ should "raise #{error} w multi level nesting on same line" do
28
+ b2 = (lambda {|a| lambda { lambda { @x } } }).call(1)
29
+ @thing.class.send(:define_method, :m3, &b2)
30
+ lambda { @thing.method(:m3).to_source(&matcher) }.should.raise(error)
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,28 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
2
+
3
+ describe 'Method#to_source (from define_method)' do
4
+ describe 'w specified body matcher & single match' do
5
+
6
+ before { @thing = Object.new }
7
+ matcher = lambda {|code| code =~ /^(.*\W|)alert\W/ }
8
+
9
+ should 'handle no nesting on same line' do
10
+ b1 = lambda {|a| @x1+1 }; b2 = lambda { @x1+2 }; b3 = lambda { alert(1) }
11
+ @thing.class.send(:define_method, :m1, &b3)
12
+ @thing.method(:m1).should.be having_source('def m1; alert(1); end', &matcher)
13
+ end
14
+
15
+ should 'handle single level nesting on same line' do
16
+ b1 = lambda {|a| @x2+1 }; b2 = lambda { alert(1); lambda { @x2+3 } }
17
+ @thing.class.send(:define_method, :m2, &b2)
18
+ @thing.method(:m2).should.be having_source('def m2; alert(1); lambda { @x2+3 }; end', &matcher)
19
+ end
20
+
21
+ should 'handle multi level nesting on same line' do
22
+ b2 = (lambda {|a| lambda { alert(1); lambda { @x3+3 } } }).call(1)
23
+ @thing.class.send(:define_method, :m3, &b2)
24
+ @thing.method(:m3).should.be having_source('def m3; alert(1); lambda { @x3+3 }; end', &matcher)
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,36 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
2
+
3
+ describe 'Method#to_source w specified {:ignore_nested => ...} (for defind_method)' do
4
+
5
+ before { @thing = Object.new }
6
+ options = {:ignore_nested => true}
7
+
8
+ if has_parsetree?
9
+ # TODO: Should we support parsetree ??
10
+ else
11
+
12
+ should "raise Sourcify::MultipleMatchingProcsPerLineError w no nesting on same line" do
13
+ b1 = lambda {|a| @x1+1 }; b2 = lambda { @x1+2 }; b3 = lambda { @x1+3 }
14
+ @thing.class.send(:define_method, :m1, &b2)
15
+ lambda { @thing.method(:m1).to_source(options) }.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
16
+ end
17
+
18
+ should "handle w single level nesting on same line" do
19
+ b1 = lambda {|a| @x2+1 }; b2 = lambda { lambda { @x2+3 } }
20
+ @thing.class.send(:define_method, :m2, &b2)
21
+ @thing.method(:m2).should.be having_source(%(
22
+ def m2
23
+ lambda { @x2+3 }
24
+ end
25
+ ), options)
26
+ end
27
+
28
+ should "raise Sourcify::NoMatchingProcError w multi level nesting on same line (w outermost having diff arity)" do
29
+ b2 = (lambda {|a| lambda { lambda { @x3 } } }).call(1)
30
+ @thing.class.send(:define_method, :m3, &b2)
31
+ lambda { @thing.method(:m3).to_source(options) }.should.raise(Sourcify::NoMatchingProcError)
32
+ end
33
+
34
+ end
35
+
36
+ end