serializable_proc 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/HISTORY.txt +5 -1
  2. data/README.rdoc +6 -123
  3. data/Rakefile +4 -28
  4. data/VERSION +1 -1
  5. data/lib/serializable_proc/binding.rb +11 -15
  6. data/lib/serializable_proc/isolatable.rb +59 -42
  7. data/lib/serializable_proc.rb +15 -18
  8. data/serializable_proc.gemspec +12 -53
  9. data/spec/bounded_vars/errors_spec.rb +12 -4
  10. data/spec/bounded_vars/local_vars_within_block_scope_spec.rb +7 -7
  11. data/spec/code_block/magic_vars_spec.rb +1 -1
  12. data/spec/proc_like/invoking_with_args_spec.rb +6 -2
  13. data/spec/proc_like/others_spec.rb +15 -7
  14. data/spec/spec_helper.rb +6 -16
  15. metadata +47 -45
  16. data/lib/serializable_proc/parsers/dynamic.rb +0 -13
  17. data/lib/serializable_proc/parsers/static.rb +0 -103
  18. data/lib/serializable_proc/parsers.rb +0 -30
  19. data/spec/code_block/errors_spec.rb +0 -65
  20. data/spec/code_block/multiple_arities_spec.rb +0 -159
  21. data/spec/code_block/optional_arity_spec.rb +0 -160
  22. data/spec/code_block/single_arity_spec.rb +0 -159
  23. data/spec/code_block/zero_arity_spec.rb +0 -159
  24. data/spec/extending/new_matcher_w_multiple_arities_spec.rb +0 -152
  25. data/spec/extending/new_matcher_w_optional_arity_spec.rb +0 -152
  26. data/spec/extending/new_matcher_w_single_arity_spec.rb +0 -152
  27. data/spec/extending/new_matcher_w_zero_arity_spec.rb +0 -152
  28. data/spec/extending/spec_helper.rb +0 -23
  29. data/spec/extending/subclassing_w_multiple_arities_spec.rb +0 -74
  30. data/spec/extending/subclassing_w_optional_arity_spec.rb +0 -74
  31. data/spec/extending/subclassing_w_single_arity_spec.rb +0 -74
  32. data/spec/extending/subclassing_w_zero_arity_spec.rb +0 -74
@@ -11,7 +11,9 @@ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
11
11
  end
12
12
 
13
13
  should 'return yield result given single arg' do
14
- s_proc = SerializableProc.new {|i| %w{b c}.map{|x| x*i } }
14
+ s_proc = SerializableProc.new do |i|
15
+ %w{b c}.map{|x| x*i }
16
+ end
15
17
  s_proc.send(invoke, 2).should.equal(%w{bb cc})
16
18
  end
17
19
 
@@ -37,7 +39,9 @@ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
37
39
 
38
40
  should 'return yield result given single arg' do
39
41
  x = 'a'
40
- s_proc = SerializableProc.new {|i| %w{b c}.map{|x| x*i } }
42
+ s_proc = SerializableProc.new do |i|
43
+ %w{b c}.map{|x| x*i }
44
+ end
41
45
  s_proc.send(invoke, 2, binding).should.equal(%w{bb cc})
42
46
  end
43
47
 
@@ -76,13 +76,19 @@ describe 'Being proc like' do
76
76
  end
77
77
 
78
78
  describe '>> arity' do
79
+ block1 = lambda { }
80
+ block2 = lambda {|x| }
81
+ block3 = lambda {|x,y| }
82
+ block4 = lambda {|*x| }
83
+ block5 = lambda {|x, *y| }
84
+ block6 = lambda {|(x,y)| }
79
85
  {
80
- __LINE__ => lambda { },
81
- __LINE__ => lambda {|x| },
82
- __LINE__ => lambda {|x,y| },
83
- __LINE__ => lambda {|*x| },
84
- __LINE__ => lambda {|x, *y| },
85
- __LINE__ => lambda {|(x,y)| },
86
+ __LINE__ => block1,
87
+ __LINE__ => block2,
88
+ __LINE__ => block3,
89
+ __LINE__ => block4,
90
+ __LINE__ => block5,
91
+ __LINE__ => block6,
86
92
  }.each do |debug, block|
87
93
  should "return arity of initializing block [##{debug}]" do
88
94
  SerializableProc.new(&block).arity.should.equal(block.arity)
@@ -92,7 +98,9 @@ describe 'Being proc like' do
92
98
 
93
99
  describe '>> binding' do
94
100
  should 'raise NotImplementedError' do
95
- lambda { SerializableProc.new { x }.binding }.should.raise(NotImplementedError)
101
+ lambda {
102
+ SerializableProc.new { x }.binding
103
+ }.should.raise(NotImplementedError)
96
104
  end
97
105
  # should 'return binding that contains duplicated contextual reference values' do
98
106
  # x, @x, @@x, $x = 'lx', 'ix', 'cx', 'gx'
data/spec/spec_helper.rb CHANGED
@@ -2,15 +2,7 @@ require 'rubygems'
2
2
  require 'bacon'
3
3
  require 'tempfile'
4
4
  require 'ruby2ruby'
5
-
6
- $parse_tree_installed =
7
- begin
8
- require 'parse_tree'
9
- true
10
- rescue LoadError
11
- require 'ruby_parser'
12
- nil
13
- end
5
+ require 'ruby_parser'
14
6
 
15
7
  $LOAD_PATH.unshift(File.dirname(__FILE__))
16
8
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -20,7 +12,7 @@ Bacon.summary_on_exit
20
12
 
21
13
  class SerializableProc
22
14
 
23
- attr_reader :code, :file, :line
15
+ attr_reader :codes, :file, :line
24
16
 
25
17
  def binding_dump
26
18
  @binding.instance_variable_get(:@vars)
@@ -32,16 +24,14 @@ class SerializableProc
32
24
 
33
25
  def having_same_semantics_as(code2)
34
26
  to_code = lambda{|sexp| ::Ruby2Ruby.new.process(sexp) }
35
- to_sexp = $parse_tree_installed ?
36
- lambda{|code| Unifier.new.process(::ParseTree.translate(code)) } :
37
- lambda{|code| ::RubyParser.new.parse(code) }
27
+ to_sexp = lambda{|code| RubyParser.new.parse(code) }
38
28
  normalize = lambda{|code| to_code[to_sexp[code]].sub('lambda','proc') }
39
29
  lambda {|code1| normalize[code1].should.equal(normalize[code2]) }
40
30
  end
41
31
 
42
32
  def having_runnable_code_as(code)
43
33
  lambda do |s_proc|
44
- s_proc.code[:runnable].should.be having_same_semantics_as(code)
34
+ s_proc.codes[:runnable].should.be having_same_semantics_as(code)
45
35
  end
46
36
  end
47
37
 
@@ -51,7 +41,7 @@ class SerializableProc
51
41
 
52
42
  def having_expected_proc_attrs(file, line, code)
53
43
  lambda do |s_proc|
54
- s_proc.code[:runnable].should.be having_same_semantics_as(code)
44
+ s_proc.codes[:runnable].should.be having_same_semantics_as(code)
55
45
  s_proc.file.should.equal(file)
56
46
  s_proc.line.should.equal(line)
57
47
  end
@@ -92,7 +82,7 @@ class SerializableProc
92
82
  test_args.each do |line, block|
93
83
  should "handle proc variable [##{line}]" do
94
84
  s_proc = SerializableProc.new(&block)
95
- s_proc.code[:runnable].should.be having_same_semantics_as(code)
85
+ s_proc.codes[:runnable].should.be having_same_semantics_as(code)
96
86
  s_proc.file.should.equal(file)
97
87
  s_proc.line.should.equal(line.succ)
98
88
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serializable_proc
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 1
10
- version: 0.3.1
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - NgTzeYang
@@ -15,29 +15,62 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-18 00:00:00 +08:00
18
+ date: 2010-09-15 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: ruby2ruby
22
+ name: sourcify
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 23
29
+ hash: 85
30
30
  segments:
31
- - 1
31
+ - 0
32
32
  - 2
33
- - 4
34
- version: 1.2.4
33
+ - 2
34
+ - 1
35
+ version: 0.2.2.1
35
36
  type: :runtime
36
37
  version_requirements: *id001
37
38
  - !ruby/object:Gem::Dependency
38
- name: bacon
39
+ name: ruby2ruby
39
40
  prerelease: false
40
41
  requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 21
47
+ segments:
48
+ - 1
49
+ - 2
50
+ - 5
51
+ version: 1.2.5
52
+ type: :runtime
53
+ version_requirements: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: sexp_processor
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 13
63
+ segments:
64
+ - 3
65
+ - 0
66
+ - 5
67
+ version: 3.0.5
68
+ type: :runtime
69
+ version_requirements: *id003
70
+ - !ruby/object:Gem::Dependency
71
+ name: bacon
72
+ prerelease: false
73
+ requirement: &id004 !ruby/object:Gem::Requirement
41
74
  none: false
42
75
  requirements:
43
76
  - - ">="
@@ -47,8 +80,8 @@ dependencies:
47
80
  - 0
48
81
  version: "0"
49
82
  type: :development
50
- version_requirements: *id002
51
- description: "\n Give & take, serializing a ruby proc is possible, though not a perfect one.\n Requires either ParseTree (faster) or RubyParser (& Ruby2Ruby).\n "
83
+ version_requirements: *id004
84
+ description: "\n Give & take, serializing a ruby proc is possible, though not a perfect one (yet).\n "
52
85
  email: ngty77@gmail.com
53
86
  executables: []
54
87
 
@@ -70,9 +103,6 @@ files:
70
103
  - lib/serializable_proc/fixes.rb
71
104
  - lib/serializable_proc/isolatable.rb
72
105
  - lib/serializable_proc/marshalable.rb
73
- - lib/serializable_proc/parsers.rb
74
- - lib/serializable_proc/parsers/dynamic.rb
75
- - lib/serializable_proc/parsers/static.rb
76
106
  - serializable_proc.gemspec
77
107
  - spec/bounded_vars/class_vars_spec.rb
78
108
  - spec/bounded_vars/class_vars_within_block_scope_spec.rb
@@ -83,22 +113,8 @@ files:
83
113
  - spec/bounded_vars/instance_vars_within_block_scope_spec.rb
84
114
  - spec/bounded_vars/local_vars_spec.rb
85
115
  - spec/bounded_vars/local_vars_within_block_scope_spec.rb
86
- - spec/code_block/errors_spec.rb
87
116
  - spec/code_block/magic_vars_spec.rb
88
- - spec/code_block/multiple_arities_spec.rb
89
- - spec/code_block/optional_arity_spec.rb
90
117
  - spec/code_block/renaming_vars_spec.rb
91
- - spec/code_block/single_arity_spec.rb
92
- - spec/code_block/zero_arity_spec.rb
93
- - spec/extending/new_matcher_w_multiple_arities_spec.rb
94
- - spec/extending/new_matcher_w_optional_arity_spec.rb
95
- - spec/extending/new_matcher_w_single_arity_spec.rb
96
- - spec/extending/new_matcher_w_zero_arity_spec.rb
97
- - spec/extending/spec_helper.rb
98
- - spec/extending/subclassing_w_multiple_arities_spec.rb
99
- - spec/extending/subclassing_w_optional_arity_spec.rb
100
- - spec/extending/subclassing_w_single_arity_spec.rb
101
- - spec/extending/subclassing_w_zero_arity_spec.rb
102
118
  - spec/proc_like/extras_spec.rb
103
119
  - spec/proc_like/invoking_with_args_spec.rb
104
120
  - spec/proc_like/invoking_with_class_vars_spec.rb
@@ -112,7 +128,7 @@ has_rdoc: true
112
128
  homepage: http://github.com/ngty/serializable_proc
113
129
  licenses: []
114
130
 
115
- post_install_message: "\n /////////////////////////////////////////////////////////////////////////////////\n\n ** SerializableProc **\n\n You are installing SerializableProc on a ruby platform & version that supports\n ParseTree. With ParseTree, u can enjoy better performance of SerializableProc,\n as well as other dynamic code analysis goodness, as compared to the default\n implementation using RubyParser's less flexible static code analysis.\n\n Anyway, u have been informed, SerializableProc will fallback on its default\n implementation using RubyParser.\n\n /////////////////////////////////////////////////////////////////////////////////\n "
131
+ post_install_message:
116
132
  rdoc_options:
117
133
  - --charset=UTF-8
118
134
  require_paths:
@@ -152,21 +168,7 @@ test_files:
152
168
  - spec/proc_like/invoking_with_global_vars_spec.rb
153
169
  - spec/proc_like/marshalling_spec.rb
154
170
  - spec/code_block/magic_vars_spec.rb
155
- - spec/code_block/multiple_arities_spec.rb
156
- - spec/code_block/zero_arity_spec.rb
157
- - spec/code_block/errors_spec.rb
158
171
  - spec/code_block/renaming_vars_spec.rb
159
- - spec/code_block/single_arity_spec.rb
160
- - spec/code_block/optional_arity_spec.rb
161
- - spec/extending/subclassing_w_optional_arity_spec.rb
162
- - spec/extending/subclassing_w_single_arity_spec.rb
163
- - spec/extending/new_matcher_w_multiple_arities_spec.rb
164
- - spec/extending/subclassing_w_zero_arity_spec.rb
165
- - spec/extending/new_matcher_w_single_arity_spec.rb
166
- - spec/extending/subclassing_w_multiple_arities_spec.rb
167
- - spec/extending/new_matcher_w_optional_arity_spec.rb
168
- - spec/extending/new_matcher_w_zero_arity_spec.rb
169
- - spec/extending/spec_helper.rb
170
172
  - spec/bounded_vars/global_vars_within_block_scope_spec.rb
171
173
  - spec/bounded_vars/instance_vars_within_block_scope_spec.rb
172
174
  - spec/bounded_vars/errors_spec.rb
@@ -1,13 +0,0 @@
1
- class SerializableProc
2
- module Parsers
3
- class Dynamic < Base
4
- class << self
5
- def process(block)
6
- if Object.const_defined?(:ParseTree)
7
- sexp_derivatives(block.to_sexp)
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,103 +0,0 @@
1
- class SerializableProc
2
-
3
- class CannotAnalyseCodeError < Exception ; end
4
-
5
- module Parsers
6
- class Static < Base
7
- class << self
8
-
9
- def process(klass, file, line)
10
- const_set(:RUBY_PARSER, RubyParser.new) unless const_defined?(:RUBY_PARSER)
11
- @klass, @file, @line = klass, file, line
12
- extract_code_and_sexp
13
- end
14
-
15
- def matchers
16
- @matchers ||= []
17
- end
18
-
19
- private
20
-
21
- def extract_code_and_sexp
22
- sexp_str, remaining, @marker = extract_sexp_args
23
- while frag = remaining[/^([^\)]*\))/,1]
24
- begin
25
- sexp = normalized_eval(sexp_str += frag)
26
- return sexp_derivatives(sexp)
27
- rescue SyntaxError
28
- remaining.sub!(frag,'')
29
- end
30
- end
31
- end
32
-
33
- def normalized_eval(sexp_str)
34
- sexp = eval(sexp_str) # this will fail unless the sexp is valid
35
- sexp.delete(marker_sexp = s(:call, nil, :"#{@marker}", s(:arglist)))
36
- sexp.find_node(:block).delete(marker_sexp) rescue nil
37
- if (block = sexp.find_node(:block)) && block.to_a.size == 2
38
- sexp.gsub(block, Sexp.from_array(block.to_a[1]))
39
- else
40
- sexp
41
- end
42
- end
43
-
44
- def extract_sexp_args
45
- raw, marker = raw_sexp_and_marker
46
- regexp = Regexp.new(
47
- '^(.*(' + Regexp.quote('s(:iter, s(:call, nil, :') +
48
- '(?:proc|lambda)' + Regexp.quote(', s(:arglist') +
49
- '.*?' + Regexp.quote("s(:call, nil, :#{marker}, s(:arglist))") +
50
- '))(.*)$', Regexp::MULTILINE
51
- )
52
- [raw.match(regexp)[2..3], marker].flatten
53
- end
54
-
55
- def raw_sexp_and_marker
56
- begin
57
- raw_sexp_and_marker_by_lineno(@line)
58
- rescue CannotAnalyseCodeError
59
- # NOTE: Tmp fix for JRuby's buggy line-numbering within Proc#inspect
60
- RUBY_PLATFORM =~ /java/i ? (@line += 1 ; retry) : raise($!)
61
- ensure
62
- @raw_code = nil
63
- end
64
- end
65
-
66
- def raw_sexp_and_marker_by_lineno(lineno)
67
- (%W{#{@klass}\.new lambda|proc|Proc\.new} + matchers).each do |declarative|
68
- ensure_no_repeated_occurrence(lineno, declarative)
69
- args = raw_sexp_and_marker_args(lineno, declarative) and return args
70
- end
71
- raise CannotAnalyseCodeError.new('Cannot find specified initializer !!')
72
- end
73
-
74
- def ensure_no_repeated_occurrence(lineno, declarative)
75
- if raw_code[lineno.pred] =~ /^(.*?\W)?(#{declarative})(\W.*?\W(#{declarative}))+(\W.*)?$/
76
- msg = "Static code analysis can only handle single occurrence of '%s' per line !!" %
77
- declarative.split('|').join("'/'")
78
- raise CannotAnalyseCodeError.new(msg)
79
- end
80
- end
81
-
82
- def raw_sexp_and_marker_args(lineno, declarative)
83
- begin
84
- raise if (line = raw_code[lineno.pred]) !~ /^(.*?\W)?(#{declarative})(\W.*)?$/
85
- regexp = /^((.*?)(#{declarative})(\s*(?:do|\{)\s*(?:\|(?:[^\|]*)\|\s*)?)(.*)?)$/m
86
- prepend, type, block_start, append = line.match(regexp)[2..5]
87
- marker = "__serializable_proc_marker_#{lineno}__"
88
- raw_code[lineno.pred] = "#{prepend}proc#{block_start} #{marker}; #{append}"
89
- [RUBY_PARSER.parse(raw_code.join, @file).inspect, marker]
90
- rescue
91
- nil
92
- end
93
- end
94
-
95
- def raw_code
96
- @raw_code ||= File.readlines(@file)
97
- end
98
-
99
- end
100
- end
101
- end
102
- end
103
-
@@ -1,30 +0,0 @@
1
- class SerializableProc
2
- module Parsers
3
-
4
- RUBY_2_RUBY = Ruby2Ruby.new
5
-
6
- class Base
7
- class << self
8
-
9
- include Isolatable
10
-
11
- def sexp_derivatives(sexp, &fix_code)
12
- isexp = isolated_sexp(sexp)
13
- icode, code = [isexp, sexp].map do |_sexp|
14
- code = RUBY_2_RUBY.process(Sexp.from_array(_sexp.to_a))
15
- block_given? ? fix_code.call(code) : code
16
- end
17
- [
18
- {:runnable => icode, :extracted => code},
19
- {:runnable => isexp, :extracted => sexp}
20
- ]
21
- end
22
-
23
- end
24
- end
25
-
26
- end
27
- end
28
-
29
- require 'serializable_proc/parsers/dynamic'
30
- require 'serializable_proc/parsers/static'
@@ -1,65 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
-
3
- describe 'SerializableProc::CannotAnalyseCodeError' do
4
- unless $parse_tree_installed
5
-
6
- extend SerializableProc::Spec::Helpers
7
-
8
- should "raise if line has more than 1 'SerializableProc.new'" do
9
- lambda {
10
- SerializableProc.new {} ; SerializableProc.new { |arg| %w{a b}.map{|x| puts x } }
11
- }.should.be raising_cannot_analyse_error("'SerializableProc.new'")
12
- end
13
-
14
- should "raise if line has more than 1 'Proc.new'" do
15
- lambda {
16
- p1 = Proc.new {} ; p2 = Proc.new { |arg| %w{a b}.map{|x| puts x } }
17
- SerializableProc.new(&p2)
18
- }.should.be raising_cannot_analyse_error("'lambda'/'proc'/'Proc.new'")
19
- end
20
-
21
- should "raise if line has more than 1 'lambda'" do
22
- lambda {
23
- p1 = lambda {} ; p2 = lambda { |arg| %w{a b}.map{|x| puts x } }
24
- SerializableProc.new(&p2)
25
- }.should.be raising_cannot_analyse_error("'lambda'/'proc'/'Proc.new'")
26
- end
27
-
28
- should "raise if line has more than 1 'proc'" do
29
- lambda {
30
- p1 = proc {} ; p2 = proc { |arg| %w{a b}.map{|x| puts x } }
31
- SerializableProc.new(&p2)
32
- }.should.be raising_cannot_analyse_error("'lambda'/'proc'/'Proc.new'")
33
- end
34
-
35
- should "raise if line mixes 'lambda' & 'proc'" do
36
- lambda {
37
- p1 = lambda {} ; p2 = proc { |arg| %w{a b}.map{|x| puts x } }
38
- SerializableProc.new(&p2)
39
- }.should.be raising_cannot_analyse_error("'lambda'/'proc'/'Proc.new'")
40
- end
41
-
42
- should "raise if line mixes 'Proc.new' & 'proc'" do
43
- lambda {
44
- p1 = Proc.new {} ; p2 = proc { |arg| %w{a b}.map{|x| puts x } }
45
- SerializableProc.new(&p2)
46
- }.should.be raising_cannot_analyse_error("'lambda'/'proc'/'Proc.new'")
47
- end
48
-
49
- should "raise if line mixes 'Proc.new' & 'lambda'" do
50
- lambda {
51
- p1 = Proc.new {} ; p2 = lambda { |arg| %w{a b}.map{|x| puts x } }
52
- SerializableProc.new(&p2)
53
- }.should.be raising_cannot_analyse_error("'lambda'/'proc'/'Proc.new'")
54
- end
55
-
56
- should "raise if line does not have lambda, proc, Proc.new or SerializableProc.new" do
57
- lambda {
58
- def create_serializable_proc(&block) ; SerializableProc.new(&block) ; end
59
- create_serializable_proc { %w{a b}.map{|x| puts x } }
60
- }.should.raise(SerializableProc::CannotAnalyseCodeError).
61
- message.should.equal('Cannot find specified initializer !!')
62
- end
63
-
64
- end
65
- end
@@ -1,159 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
-
3
- describe 'Extracting multiple arities code block' do
4
-
5
- extend SerializableProc::Spec::Helpers
6
-
7
- expected_file = File.expand_path(__FILE__)
8
- expected_code = "lambda { |lvar_arg1, lvar_arg2| [\"a\", \"b\"].map { |lvar_x| puts(lvar_x) } }"
9
-
10
- should_handle_proc_variable expected_file, expected_code, {
11
- # ////////////////////////////////////////////////////////////////////////
12
- # >> Always newlinling
13
- # ////////////////////////////////////////////////////////////////////////
14
- __LINE__ =>
15
- lambda do |arg1, arg2|
16
- %w{a b}.map do |x|
17
- puts x
18
- end
19
- end,
20
- __LINE__ =>
21
- lambda { |arg1, arg2|
22
- %w{a b}.map{|x|
23
- puts x
24
- }
25
- },
26
- __LINE__ =>
27
- proc do |arg1, arg2|
28
- %w{a b}.map do |x|
29
- puts x
30
- end
31
- end,
32
- __LINE__ =>
33
- lambda { |arg1, arg2|
34
- %w{a b}.map{|x|
35
- puts x
36
- }
37
- },
38
- __LINE__ =>
39
- Proc.new do |arg1, arg2|
40
- %w{a b}.map do |x|
41
- puts x
42
- end
43
- end,
44
- __LINE__ =>
45
- Proc.new { |arg1, arg2|
46
- %w{a b}.map{|x|
47
- puts x
48
- }
49
- },
50
- # ////////////////////////////////////////////////////////////////////////
51
- # >> Partial newlining
52
- # ////////////////////////////////////////////////////////////////////////
53
- __LINE__ =>
54
- lambda do |arg1, arg2|
55
- %w{a b}.map do |x| puts x end
56
- end,
57
- __LINE__ =>
58
- lambda { |arg1, arg2|
59
- %w{a b}.map{|x| puts x }
60
- },
61
- __LINE__ =>
62
- proc do |arg1, arg2|
63
- %w{a b}.map do |x| puts x end
64
- end,
65
- __LINE__ =>
66
- lambda { |arg1, arg2|
67
- %w{a b}.map{|x| puts x }
68
- },
69
- __LINE__ =>
70
- Proc.new do |arg1, arg2|
71
- %w{a b}.map do |x| puts x end
72
- end,
73
- __LINE__ =>
74
- Proc.new { |arg1, arg2|
75
- %w{a b}.map{|x| puts x }
76
- },
77
- # ////////////////////////////////////////////////////////////////////////
78
- # >> No newlining
79
- # ////////////////////////////////////////////////////////////////////////
80
- __LINE__ =>
81
- lambda do |arg1, arg2| %w{a b}.map do |x| puts x end end,
82
- __LINE__ =>
83
- lambda { |arg1, arg2| %w{a b}.map{|x| puts x } },
84
- __LINE__ =>
85
- proc do |arg1, arg2| %w{a b}.map do |x| puts x end end,
86
- __LINE__ =>
87
- lambda { |arg1, arg2| %w{a b}.map{|x| puts x } },
88
- __LINE__ =>
89
- Proc.new do |arg1, arg2| %w{a b}.map do |x| puts x end end,
90
- __LINE__ =>
91
- Proc.new { |arg1, arg2| %w{a b}.map{|x| puts x } },
92
- }
93
-
94
- should "handle block using do ... end [##{__LINE__}]" do
95
- (
96
- SerializableProc.new do |arg1, arg2|
97
- %w{a b}.map{|x| puts x }
98
- end
99
- ).should.be having_expected_proc_attrs(expected_file, __LINE__ - 3, expected_code)
100
- end
101
-
102
- should "handle block using do ... end [##{__LINE__}]" do
103
- (SerializableProc.new do |arg1, arg2| %w{a b}.map{|x| puts x } end).
104
- should.be having_expected_proc_attrs(expected_file, __LINE__.pred, expected_code)
105
- end
106
-
107
- should "handle block using { ... } [##{__LINE__}]" do
108
- (
109
- SerializableProc.new { |arg1, arg2|
110
- %w{a b}.map{|x| puts x }
111
- }
112
- ).should.be having_expected_proc_attrs(expected_file, __LINE__ - 3, expected_code)
113
- end
114
-
115
- should "handle block using { ... } [##{__LINE__}]" do
116
- (SerializableProc.new { |arg1, arg2| %w{a b}.map{|x| puts x } }).
117
- should.be having_expected_proc_attrs(expected_file, __LINE__.pred, expected_code)
118
- end
119
-
120
- should "handle fanciful initializing with lambda { ... } [##{__LINE__}]" do
121
- (SerializableProc.new(&(lambda { |arg1, arg2| %w{a b}.map{|x| puts x } }))).
122
- should.be having_expected_proc_attrs(expected_file, __LINE__.pred, expected_code)
123
- end
124
-
125
- should "handle fanciful initializing with lambda do ... end [##{__LINE__}]" do
126
- (
127
- SerializableProc.new(&(lambda do |arg1, arg2|
128
- %w{a b}.map{|x| puts x }
129
- end))
130
- ).should.be having_expected_proc_attrs(expected_file, __LINE__ - 3, expected_code)
131
- end
132
-
133
- should "handle fanciful initializing with proc { ... } [##{__LINE__}]" do
134
- (SerializableProc.new(&(proc { |arg1, arg2| %w{a b}.map{|x| puts x } }))).
135
- should.be having_expected_proc_attrs(expected_file, __LINE__.pred, expected_code)
136
- end
137
-
138
- should "handle fanciful initializing with proc do ... end [##{__LINE__}]" do
139
- (
140
- SerializableProc.new(&(proc do |arg1, arg2|
141
- %w{a b}.map{|x| puts x }
142
- end))
143
- ).should.be having_expected_proc_attrs(expected_file, __LINE__ - 3, expected_code)
144
- end
145
-
146
- should "handle fanciful initializing with Proc.new { ... } [##{__LINE__}]" do
147
- (SerializableProc.new(&(Proc.new { |arg1, arg2| %w{a b}.map{|x| puts x } }))).
148
- should.be having_expected_proc_attrs(expected_file, __LINE__.pred, expected_code)
149
- end
150
-
151
- should "handle fanciful initializing with Proc.new do ... end [##{__LINE__}]" do
152
- (
153
- SerializableProc.new(&(Proc.new do |arg1, arg2|
154
- %w{a b}.map{|x| puts x }
155
- end))
156
- ).should.be having_expected_proc_attrs(expected_file, __LINE__ - 3, expected_code)
157
- end
158
-
159
- end