bindata 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bindata might be problematic. Click here for more details.

data/spec/base_spec.rb CHANGED
@@ -18,7 +18,7 @@ describe BinData::Base, "with mandatory parameters" do
18
18
  before(:all) do
19
19
  eval <<-END
20
20
  class MandatoryBase < BinData::Base
21
- mandatory_parameter :p1
21
+ bindata_mandatory_parameter :p1
22
22
  end
23
23
  END
24
24
  end
@@ -36,8 +36,8 @@ describe BinData::Base, "with default parameters" do
36
36
  before(:all) do
37
37
  eval <<-END
38
38
  class DefaultBase < BinData::Base
39
- default_parameter :p1 => "a"
40
- public :has_param?, :param
39
+ bindata_default_parameter :p1 => "a"
40
+ public :has_param?, :no_eval_param
41
41
  end
42
42
  END
43
43
  end
@@ -45,13 +45,13 @@ describe BinData::Base, "with default parameters" do
45
45
  it "should set default parameters if they are not specified" do
46
46
  obj = DefaultBase.new
47
47
  obj.should have_param(:p1)
48
- obj.param(:p1).should == "a"
48
+ obj.no_eval_param(:p1).should == "a"
49
49
  end
50
50
 
51
51
  it "should be able to override default parameters" do
52
52
  obj = DefaultBase.new(:p1 => "b")
53
53
  obj.should have_param(:p1)
54
- obj.param(:p1).should == "b"
54
+ obj.no_eval_param(:p1).should == "b"
55
55
  end
56
56
  end
57
57
 
@@ -59,8 +59,8 @@ describe BinData::Base, "with mutually exclusive parameters" do
59
59
  before(:all) do
60
60
  eval <<-END
61
61
  class MutexParamBase < BinData::Base
62
- optional_parameters :p1, :p2
63
- mutually_exclusive_parameters :p1, :p2
62
+ bindata_optional_parameters :p1, :p2
63
+ bindata_mutually_exclusive_parameters :p1, :p2
64
64
  end
65
65
  END
66
66
  end
@@ -83,10 +83,10 @@ describe BinData::Base, "with multiple parameters" do
83
83
  before(:all) do
84
84
  eval <<-END
85
85
  class WithParamBase < BinData::Base
86
- mandatory_parameter :p1
87
- optional_parameter :p2
88
- default_parameter :p3 => '3'
89
- public :has_param?, :eval_param, :param
86
+ bindata_mandatory_parameter :p1
87
+ bindata_optional_parameter :p2
88
+ bindata_default_parameter :p3 => '3'
89
+ public :has_param?, :eval_param, :no_eval_param
90
90
  end
91
91
  END
92
92
  end
@@ -96,10 +96,8 @@ describe BinData::Base, "with multiple parameters" do
96
96
  end
97
97
 
98
98
  it "should identify extra parameters" do
99
- env = mock("env")
100
- env.should_receive(:params=).with(:p4 => 4, :p5 => 5)
101
- env.should_receive(:data_object=)
102
- obj = WithParamBase.new({:p1 => 1, :p3 => 3, :p4 => 4, :p5 => 5}, env)
99
+ obj = WithParamBase.new({:p1 => 1, :p3 => 3, :p4 => 4, :p5 => 5})
100
+ obj.parameters.should == {:p4 => 4, :p5 => 5}
103
101
  end
104
102
 
105
103
  it "should only recall mandatory, default and optional parameters" do
@@ -122,17 +120,17 @@ describe BinData::Base, "with multiple parameters" do
122
120
 
123
121
  it "should be able to access without evaluating" do
124
122
  obj = WithParamBase.new(:p1 => :asym, :p3 => lambda {1 + 2})
125
- obj.param(:p1).should == :asym
126
- obj.param(:p2).should be_nil
127
- obj.param(:p3).should respond_to(:arity)
123
+ obj.no_eval_param(:p1).should == :asym
124
+ obj.no_eval_param(:p2).should be_nil
125
+ obj.no_eval_param(:p3).should respond_to(:arity)
128
126
  end
129
127
 
130
128
  it "should identify accepted parameters" do
131
- accepted_parameters = WithParamBase.accepted_parameters
132
- accepted_parameters.should include(:p1)
133
- accepted_parameters.should include(:p2)
134
- accepted_parameters.should include(:p3)
135
- accepted_parameters.should_not include(:p4)
129
+ internal_parameters = WithParamBase.internal_parameters
130
+ internal_parameters.should include(:p1)
131
+ internal_parameters.should include(:p2)
132
+ internal_parameters.should include(:p3)
133
+ internal_parameters.should_not include(:p4)
136
134
  end
137
135
  end
138
136
 
@@ -265,7 +263,7 @@ describe BinData::Base, "with :readwrite" do
265
263
  before(:all) do
266
264
  eval <<-END
267
265
  class NoIOBase < BinData::Base
268
- public :has_param?, :param
266
+ public :has_param?, :no_eval_param
269
267
  end
270
268
  END
271
269
  end
@@ -274,7 +272,7 @@ describe BinData::Base, "with :readwrite" do
274
272
  obj = NoIOBase.new(:readwrite => "a")
275
273
  obj.should_not have_param(:readwrite)
276
274
  obj.should have_param(:onlyif)
277
- obj.param(:onlyif).should == "a"
275
+ obj.no_eval_param(:onlyif).should == "a"
278
276
  end
279
277
  end
280
278
 
data/spec/bits_spec.rb CHANGED
File without changes
data/spec/choice_spec.rb CHANGED
@@ -30,11 +30,6 @@ describe BinData::Choice, "when instantiating" do
30
30
  lambda { BinData::Choice.new(args) }.should raise_error(TypeError)
31
31
  end
32
32
 
33
- it "should fail if :choices isn't an Array or Hash" do
34
- args = {:choices => :does_not_exist, :selection => 0}
35
- lambda { BinData::Choice.new(args) }.should raise_error(ArgumentError)
36
- end
37
-
38
33
  it "should fail if :choices Hash has a symbol as key" do
39
34
  args = {:choices => {:a => :int8}, :selection => 0}
40
35
  lambda { BinData::Choice.new(args) }.should raise_error(ArgumentError)
@@ -58,10 +53,15 @@ describe BinData::Choice, "with choices array" do
58
53
 
59
54
  it "should be able to select the choice" do
60
55
  @chooser.choice = 0
56
+ @data.selection.should == 0
61
57
  @data.value.should == 3
58
+
62
59
  @chooser.choice = 1
60
+ @data.selection.should == 1
63
61
  @data.value.should == 5
62
+
64
63
  @chooser.choice = 2
64
+ @data.selection.should == 2
65
65
  @data.value.should == 7
66
66
  end
67
67
 
@@ -105,8 +105,11 @@ describe BinData::Choice, "with sparse choices array" do
105
105
 
106
106
  it "should be able to select the choice" do
107
107
  @chooser.choice = 3
108
+ @data.selection.should == 3
108
109
  @data.value.should == 3
110
+
109
111
  @chooser.choice = 7
112
+ @data.selection.should == 7
110
113
  @data.value.should == 7
111
114
  end
112
115
 
@@ -134,8 +137,11 @@ describe BinData::Choice, "with choices hash" do
134
137
  it "should be able to select the choice" do
135
138
  @chooser.choice = 3
136
139
  @data.value.should == 3
140
+ @data.selection.should == 3
141
+
137
142
  @chooser.choice = 7
138
143
  @data.value.should == 7
144
+ @data.selection.should == 7
139
145
  end
140
146
 
141
147
  it "should not be able to select an invalid choice" do
data/spec/float_spec.rb CHANGED
File without changes
data/spec/int_spec.rb CHANGED
@@ -11,20 +11,24 @@ describe "All signed integers" do
11
11
  BinData::Int32le,
12
12
  BinData::Int32be,
13
13
  BinData::Int64le,
14
- BinData::Int64be].each do |klass|
14
+ BinData::Int64be,
15
+ BinData::Int128le,
16
+ BinData::Int128be].each do |klass|
15
17
  klass.new.value.should be_zero
16
18
  end
17
19
  end
18
20
 
19
21
  it "should pass these tests" do
20
22
  [
21
- [1, true, BinData::Int8],
22
- [2, false, BinData::Int16le],
23
- [2, true, BinData::Int16be],
24
- [4, false, BinData::Int32le],
25
- [4, true, BinData::Int32be],
26
- [8, false, BinData::Int64le],
27
- [8, true, BinData::Int64be],
23
+ [ 1, true, BinData::Int8],
24
+ [ 2, false, BinData::Int16le],
25
+ [ 2, true, BinData::Int16be],
26
+ [ 4, false, BinData::Int32le],
27
+ [ 4, true, BinData::Int32be],
28
+ [ 8, false, BinData::Int64le],
29
+ [ 8, true, BinData::Int64be],
30
+ [16, false, BinData::Int128le],
31
+ [16, true, BinData::Int128be],
28
32
  ].each do |nbytes, big_endian, klass|
29
33
  gen_int_test_data(nbytes, big_endian).each do |val, clamped_val, str|
30
34
  test_read_write(klass, val, clamped_val, str)
@@ -41,20 +45,24 @@ describe "All unsigned integers" do
41
45
  BinData::Uint32le,
42
46
  BinData::Uint32be,
43
47
  BinData::Uint64le,
44
- BinData::Uint64be].each do |klass|
48
+ BinData::Uint64be,
49
+ BinData::Uint128le,
50
+ BinData::Uint128be].each do |klass|
45
51
  klass.new.value.should be_zero
46
52
  end
47
53
  end
48
54
 
49
55
  it "should pass these tests" do
50
56
  [
51
- [1, true, BinData::Uint8],
52
- [2, false, BinData::Uint16le],
53
- [2, true, BinData::Uint16be],
54
- [4, false, BinData::Uint32le],
55
- [4, true, BinData::Uint32be],
56
- [8, false, BinData::Uint64le],
57
- [8, true, BinData::Uint64be],
57
+ [ 1, true, BinData::Uint8],
58
+ [ 2, false, BinData::Uint16le],
59
+ [ 2, true, BinData::Uint16be],
60
+ [ 4, false, BinData::Uint32le],
61
+ [ 4, true, BinData::Uint32be],
62
+ [ 8, false, BinData::Uint64le],
63
+ [ 8, true, BinData::Uint64be],
64
+ [16, false, BinData::Uint128le],
65
+ [16, true, BinData::Uint128be],
58
66
  ].each do |nbytes, big_endian, klass|
59
67
  gen_uint_test_data(nbytes, big_endian).each do |val, clamped_val, str|
60
68
  test_read_write(klass, val, clamped_val, str)
@@ -87,11 +95,14 @@ end
87
95
 
88
96
  # return test data for testing unsigned ints
89
97
  def gen_uint_test_data(nbytes, big_endian)
90
- raise "nbytes too big" if nbytes > 8
98
+ raise "nbytes too large" if nbytes > 16
91
99
  tests = []
92
100
 
101
+ max_value = (1 << (nbytes * 8)) - 1
102
+ min_value = 0
103
+
93
104
  # test the minimum value
94
- v = 0
105
+ v = min_value
95
106
  s = "\x00" * nbytes
96
107
  tests.push [v, v, big_endian ? s : s.reverse]
97
108
 
@@ -99,12 +110,12 @@ def gen_uint_test_data(nbytes, big_endian)
99
110
  tests.push [v-1, v, big_endian ? s : s.reverse]
100
111
 
101
112
  # test a value within range
102
- v = 0x123456789abcdef0 >> ((8-nbytes) * 8)
103
- s = "\x12\x34\x56\x78\x9a\xbc\xde\xf0".slice(0, nbytes)
113
+ v = 0x123456789abcdef0123456789abcdef0 >> ((16-nbytes) * 8)
114
+ s = "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x12\x34\x56\x78\x9a\xbc\xde\xf0".slice(0, nbytes)
104
115
  tests.push [v, v, big_endian ? s : s.reverse]
105
116
 
106
117
  # test the maximum value
107
- v = (1 << (nbytes * 8)) - 1
118
+ v = max_value
108
119
  s = "\xff" * nbytes
109
120
  tests.push [v, v, big_endian ? s : s.reverse]
110
121
 
@@ -116,12 +127,15 @@ end
116
127
 
117
128
  # return test data for testing signed ints
118
129
  def gen_int_test_data(nbytes, big_endian)
119
- raise "nbytes too big" if nbytes > 8
130
+ raise "nbytes too large" if nbytes > 16
120
131
  tests = []
121
132
 
133
+ max_value = (1 << (nbytes * 8 - 1)) - 1
134
+ min_value = -max_value - 1
135
+
122
136
  # test the minimum value
123
- v = -((1 << (nbytes * 8 - 1)) - 1) -1
124
- s = "\x80\x00\x00\x00\x00\x00\x00\x00".slice(0, nbytes)
137
+ v = min_value
138
+ s = "\x80" + "\x00" * (nbytes - 1)
125
139
  tests.push [v, v, big_endian ? s : s.reverse]
126
140
 
127
141
  # values below minimum should be clamped to minimum
@@ -133,12 +147,12 @@ def gen_int_test_data(nbytes, big_endian)
133
147
  tests.push [v, v, big_endian ? s : s.reverse]
134
148
 
135
149
  # test a +ve value within range
136
- v = 0x123456789abcdef0 >> ((8-nbytes) * 8)
137
- s = "\x12\x34\x56\x78\x9a\xbc\xde\xf0".slice(0, nbytes)
150
+ v = 0x123456789abcdef0123456789abcdef0 >> ((16-nbytes) * 8)
151
+ s = "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x12\x34\x56\x78\x9a\xbc\xde\xf0".slice(0, nbytes)
138
152
  tests.push [v, v, big_endian ? s : s.reverse]
139
153
 
140
154
  # test the maximum value
141
- v = (1 << (nbytes * 8 - 1)) - 1
155
+ v = max_value
142
156
  s = "\x7f" + "\xff" * (nbytes - 1)
143
157
  tests.push [v, v, big_endian ? s : s.reverse]
144
158
 
data/spec/io_spec.rb CHANGED
File without changes
data/spec/lazy_spec.rb CHANGED
@@ -1,127 +1,160 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require File.expand_path(File.dirname(__FILE__)) + '/spec_common'
4
+ require 'bindata/array'
5
+ require 'bindata/int'
4
6
  require 'bindata/lazy'
5
7
 
6
8
  # A mock data object with customizable fields.
7
9
  class MockDataObject
8
- def initialize(fields = {})
9
- fields.each do |k,v|
10
- self.class.send(:define_method, k.to_sym) { v }
10
+ def initialize(methods = {}, params = {}, parent = nil)
11
+ methods.each do |k,v|
12
+ meta = class << self ; self; end
13
+ meta.send(:define_method, k.to_sym) { v }
11
14
  end
15
+ @parameters = params
16
+ @parent = parent
12
17
  end
18
+ attr_accessor :parent, :parameters
13
19
  end
14
20
 
15
- describe BinData::LazyEvalEnv do
21
+ describe BinData::LazyEvaluator, "with no parents" do
16
22
  before(:each) do
17
- @do1 = MockDataObject.new(:f1 => 'f1')
18
- @e1 = BinData::LazyEvalEnv.new
19
- @e1.data_object = @do1
20
- @e1.add_variable(:v1, 'v1')
21
- @e1.add_variable(:v2, 'v2')
22
- end
23
-
24
- it "should accept symbols as a shortcut to lambda" do
25
- @e1.lazy_eval(lambda { o1 }, :o1 => 'o1').should == 'o1'
26
- @e1.lazy_eval(lambda { v1 }).should == 'v1'
27
- @e1.lazy_eval(:o1, :o1 => 'o1').should == 'o1'
28
- @e1.lazy_eval(:v1).should == 'v1'
29
- @e1.lazy_eval(:v2).should == 'v2'
23
+ methods = {:m1 => 'm1', :com => 'mC'}
24
+ params = {:p1 => 'p1', :com => 'pC'}
25
+ obj = MockDataObject.new(methods, params)
26
+ @ev = BinData::LazyEvaluator.new(obj)
30
27
  end
31
28
 
32
29
  it "should evaluate overrides" do
33
- @e1.lazy_eval(:o1, :o1 => 'o1').should == 'o1'
30
+ @ev.lazy_eval(lambda { o1 }, :o1 => 'o1').should == 'o1'
34
31
  end
35
32
 
36
- it "should evaluate variables" do
37
- @e1.lazy_eval(:v1).should == 'v1'
38
- @e1.lazy_eval(:v2).should == 'v2'
33
+ it "should not resolve any unknown methods" do
34
+ lambda { @ev.lazy_eval(lambda { unknown }) }.should raise_error(NameError)
35
+ lambda { @ev.lazy_eval(lambda { m1 }) }.should raise_error(NameError)
36
+ lambda { @ev.lazy_eval(lambda { p1 }) }.should raise_error(NameError)
39
37
  end
40
38
 
41
- it "should prioritise overrides over variables" do
42
- @e1.lazy_eval(:v1, :v1 => 'o1').should == 'o1'
39
+ it "should not have a parent" do
40
+ @ev.lazy_eval(lambda { parent }).should be_nil
43
41
  end
44
42
 
45
- it "should not resolve any unknown fields" do
46
- lambda { @e1.lazy_eval(:unknown) }.should raise_error(NameError)
47
- lambda { @e1.lazy_eval(:p1) }.should raise_error(NameError)
48
- lambda { @e1.lazy_eval(:f1) }.should raise_error(NameError)
43
+ it "should not resolve #index" do
44
+ lambda { @ev.lazy_eval(lambda { index }) }.should raise_error(NoMethodError)
49
45
  end
50
46
  end
51
47
 
52
- describe BinData::LazyEvalEnv, "with one parent" do
48
+ describe BinData::LazyEvaluator, "with one parent" do
53
49
  before(:each) do
54
- @do2 = MockDataObject.new(:f2 => 'f2', :common1 => 'f2', :common2 => 'f2')
55
- @do1 = MockDataObject.new
50
+ parent_methods = {:m1 => 'Pm1', :com => 'PmC', :mm => 3}
51
+ parent_params = {:p1 => 'Pp1', :com => 'PpC'}
52
+ parent_obj = MockDataObject.new(parent_methods, parent_params)
53
+
54
+ methods = {:m1 => 'm1', :com => 'mC'}
55
+ params = {:p1 => 'p1', :com => 'pC'}
56
+ obj = MockDataObject.new(methods, params, parent_obj)
56
57
 
57
- @e2 = BinData::LazyEvalEnv.new
58
- @e1 = BinData::LazyEvalEnv.new(@e2)
58
+ @ev = BinData::LazyEvaluator.new(obj)
59
+ end
59
60
 
60
- @e2.data_object = @do2
61
- @e1.data_object = @do1
61
+ it "should evaluate overrides" do
62
+ @ev.lazy_eval(lambda { p1 }, :p1 => 'o1').should == 'o1'
63
+ end
62
64
 
63
- @e1.add_variable(:common2, 'v1')
65
+ it "should not resolve any unknown methods" do
66
+ lambda { @ev.lazy_eval(lambda { unknown }) }.should raise_error(NameError)
67
+ end
64
68
 
65
- @e2.params = {:p2 => 'p2', :common1 => 'p2', :common2 => 'p2'}
66
- @e2.add_variable(:common2, 'v2')
69
+ it "should resolve parameters in the parent" do
70
+ @ev.lazy_eval(lambda { p1 }).should == 'Pp1'
67
71
  end
68
72
 
69
- it "should evaluate parent parameter" do
70
- @e1.lazy_eval(:p2).should == 'p2'
73
+ it "should resolve methods in the parent" do
74
+ @ev.lazy_eval(lambda { m1 }).should == 'Pm1'
71
75
  end
72
76
 
73
- it "should evaluate parent field" do
74
- @e1.lazy_eval(:f2).should == 'f2'
77
+ it "should resolve parameters in preference to methods in the parent" do
78
+ @ev.lazy_eval(lambda { com }).should == 'PpC'
75
79
  end
76
80
 
77
- it "should prefer parent param over parent field" do
78
- @e1.lazy_eval(:common1).should == 'p2'
81
+ it "should have a parent" do
82
+ @ev.lazy_eval(lambda { parent }).should_not be_nil
79
83
  end
80
84
 
81
- it "should prefer variable over parent param" do
82
- @e1.lazy_eval(:common2).should == 'v1'
85
+ it "should not resolve #index" do
86
+ lambda { @ev.lazy_eval(lambda { index }) }.should raise_error(NoMethodError)
83
87
  end
84
88
  end
85
89
 
86
- describe BinData::LazyEvalEnv, "when nested" do
90
+ describe BinData::LazyEvaluator, "with nested parents" do
87
91
  before(:each) do
88
- @do4 = MockDataObject.new(:f4 => 'f4')
89
- @do3 = MockDataObject.new(:f3 => 'f3')
90
- @do2 = MockDataObject.new(:f2 => 'f2', :fs2 => :s3)
91
- @do1 = MockDataObject.new(:f1 => 'f1')
92
+ pparent_methods = {:m1 => 'PPm1', :m2 => 'PPm2', :com => 'PPmC'}
93
+ pparent_params = {:p1 => 'PPp1', :p2 => 'PPp2', :com => 'PPpC'}
94
+ pparent_obj = MockDataObject.new(pparent_methods, pparent_params)
95
+
96
+ parent_methods = {:m1 => 'Pm1', :com => 'PmC', :sym1 => :m2}
97
+ parent_params = {:p1 => 'Pp1', :com => 'PpC'}
98
+ parent_obj = MockDataObject.new(parent_methods, parent_params, pparent_obj)
99
+
100
+ methods = {:m1 => 'm1', :com => 'mC'}
101
+ params = {:p1 => 'p1', :com => 'pC'}
102
+ obj = MockDataObject.new(methods, params, parent_obj)
92
103
 
93
- @e4 = BinData::LazyEvalEnv.new
94
- @e3 = BinData::LazyEvalEnv.new(@e4)
95
- @e2 = BinData::LazyEvalEnv.new(@e3)
96
- @e1 = BinData::LazyEvalEnv.new(@e2)
104
+ @ev = BinData::LazyEvaluator.new(obj)
105
+ end
97
106
 
98
- @e4.data_object = @do4
99
- @e3.data_object = @do3
100
- @e2.data_object = @do2
101
- @e1.data_object = @do1
107
+ it "should accept symbols as a shortcut to lambdas" do
108
+ @ev.lazy_eval(:p1).should == 'Pp1'
109
+ @ev.lazy_eval(:p2).should == 'PPp2'
110
+ @ev.lazy_eval(:m1).should == 'Pm1'
111
+ @ev.lazy_eval(:m2).should == 'PPm2'
112
+ end
102
113
 
103
- @e4.params = {:p4 => 'p4', :s4 => 's4', :l4 => 'l4'}
104
- @e3.params = {:p3 => 'p3', :s3 => :s4, :s4 => 'xx', :l3 => lambda { l4 }}
105
- @e2.params = {:p2 => 'p2', :s2 => :s3, :l2 => lambda { l3 }}
114
+ it "should not resolve any unknown methods" do
115
+ lambda { @ev.lazy_eval(lambda { unknown }) }.should raise_error(NameError)
116
+ end
106
117
 
107
- @e2.add_variable(:v2, 'v2')
118
+ it "should resolve parameters in the parent" do
119
+ @ev.lazy_eval(lambda { p1 }).should == 'Pp1'
108
120
  end
109
121
 
110
- it "should access parent environments" do
111
- @e1.lazy_eval(lambda { parent.p3 }).should == 'p3'
112
- @e1.lazy_eval(lambda { parent.parent.p4 }).should == 'p4'
122
+ it "should resolve methods in the parent" do
123
+ @ev.lazy_eval(lambda { m1 }).should == 'Pm1'
113
124
  end
114
125
 
115
- it "should cascade lambdas" do
116
- @e1.lazy_eval(lambda { l2 }).should == 'l4'
117
- @e1.lazy_eval(lambda { s2 }).should == 's4'
126
+ it "should resolve parameters in the parent's parent" do
127
+ @ev.lazy_eval(lambda { p2 }).should == 'PPp2'
118
128
  end
119
129
 
120
- it "should access parent environments by cascading" do
121
- @e1.lazy_eval(lambda { p3 }).should == 'p3'
122
- @e1.lazy_eval(lambda { p4 }).should == 'p4'
123
- @e1.lazy_eval(lambda { v2 }).should == 'v2'
124
- @e1.lazy_eval(lambda { s3 }).should == 's4'
125
- @e1.lazy_eval(lambda { fs2 }).should == 's4'
130
+ it "should resolve methods in the parent's parent" do
131
+ @ev.lazy_eval(lambda { m2 }).should == 'PPm2'
132
+ end
133
+
134
+ it "should resolve parameters in preference to methods in the parent" do
135
+ @ev.lazy_eval(lambda { com }).should == 'PpC'
136
+ end
137
+
138
+ it "should resolve methods in the parent explicitly" do
139
+ @ev.lazy_eval(lambda { parent.m1 }).should == 'PPm1'
140
+ end
141
+
142
+ it "should cascade lambdas " do
143
+ @ev.lazy_eval(lambda { sym1 }).should == 'PPm2'
144
+ end
145
+
146
+ it "should not resolve #index" do
147
+ lambda { @ev.lazy_eval(lambda { index }) }.should raise_error(NoMethodError)
148
+ end
149
+ end
150
+
151
+ # This spec seems out of place, but :index is implemented in lazy.rb so this
152
+ # is the best place for it.
153
+ describe BinData::LazyEvaluator, "with BinData::Array" do
154
+ it "should use correct index" do
155
+ arr = BinData::Array.new(:type =>
156
+ [:uint8, { :value => lambda { index * 10 } }],
157
+ :initial_length => 3)
158
+ arr.snapshot.should == [0, 10, 20]
126
159
  end
127
160
  end