plist4r 0.2.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.yardopts +11 -0
- data/LICENSE +3 -1
- data/README.rdoc +25 -122
- data/Rakefile +14 -0
- data/VERSION +1 -1
- data/bin/plist4r +2 -0
- data/ext/osx_plist/Makefile +157 -0
- data/ext/osx_plist/extconf.rb +9 -0
- data/ext/osx_plist/plist.c +606 -0
- data/ext/osx_plist/plist.o +0 -0
- data/lib/plist4r.rb +6 -3
- data/lib/plist4r/application.rb +1 -2
- data/lib/plist4r/backend.rb +102 -34
- data/lib/plist4r/backend/c_f_property_list.rb +65 -0
- data/lib/plist4r/backend/c_f_property_list/LICENSE +19 -0
- data/lib/plist4r/backend/c_f_property_list/README +34 -0
- data/lib/plist4r/backend/c_f_property_list/cfpropertylist.rb +6 -0
- data/lib/plist4r/backend/c_f_property_list/rbBinaryCFPropertyList.rb +663 -0
- data/lib/plist4r/backend/c_f_property_list/rbCFPlistError.rb +26 -0
- data/lib/plist4r/backend/c_f_property_list/rbCFPropertyList.rb +348 -0
- data/lib/plist4r/backend/c_f_property_list/rbCFTypes.rb +241 -0
- data/lib/plist4r/backend/c_f_property_list/rbXMLCFPropertyList.rb +116 -0
- data/lib/plist4r/backend/example.rb +37 -52
- data/lib/plist4r/backend/haml.rb +47 -36
- data/lib/plist4r/backend/libxml4r.rb +24 -20
- data/lib/plist4r/backend/osx_plist.rb +82 -0
- data/lib/plist4r/backend/ruby_cocoa.rb +172 -54
- data/lib/plist4r/backend/test/data_types.rb +163 -0
- data/lib/plist4r/backend/test/harness.rb +255 -0
- data/lib/plist4r/backend/test/output.rb +47 -0
- data/lib/plist4r/backend_base.rb +4 -2
- data/lib/plist4r/{options.rb → cli.rb} +2 -1
- data/lib/plist4r/commands.rb +13 -8
- data/lib/plist4r/config.rb +36 -9
- data/lib/plist4r/docs/Backends.html +59 -0
- data/lib/plist4r/docs/DeveloperGuide.rdoc +53 -0
- data/lib/plist4r/docs/EditingPlistFiles.rdoc +88 -0
- data/lib/plist4r/docs/InfoPlistExample.rdoc +33 -0
- data/lib/plist4r/docs/LaunchdPlistExample.rdoc +33 -0
- data/lib/plist4r/docs/PlistKeyNames.rdoc +47 -0
- data/lib/plist4r/mixin/array_dict.rb +61 -0
- data/lib/plist4r/mixin/data_methods.rb +178 -54
- data/lib/plist4r/mixin/haml4r.rb +4 -0
- data/lib/plist4r/mixin/haml4r/css_attributes.rb +19 -0
- data/lib/plist4r/mixin/haml4r/examples.rb +261 -0
- data/lib/plist4r/mixin/haml4r/haml_table_example.rb +79 -0
- data/lib/plist4r/mixin/haml4r/table.rb +157 -0
- data/lib/plist4r/mixin/haml4r/table_cell.rb +160 -0
- data/lib/plist4r/mixin/haml4r/table_cells.rb +485 -0
- data/lib/plist4r/mixin/haml4r/table_section.rb +101 -0
- data/lib/plist4r/mixin/ordered_hash.rb +9 -1
- data/lib/plist4r/mixin/popen4.rb +1 -1
- data/lib/plist4r/mixin/ruby_stdlib.rb +154 -1
- data/lib/plist4r/mixin/script.rb +133 -0
- data/lib/plist4r/mixin/table.rb +435 -0
- data/lib/plist4r/plist.rb +272 -94
- data/lib/plist4r/plist_cache.rb +42 -43
- data/lib/plist4r/plist_type.rb +31 -74
- data/lib/plist4r/plist_type/info.rb +157 -3
- data/lib/plist4r/plist_type/launchd.rb +54 -48
- data/lib/plist4r/plist_type/plist.rb +1 -3
- data/plist4r.gemspec +74 -14
- data/spec/{examples.rb → launchd_examples.rb} +131 -139
- data/spec/plist4r/application_spec.rb +37 -0
- data/spec/plist4r/backend_spec.rb +256 -0
- data/spec/plist4r/cli_spec.rb +25 -0
- data/spec/plist4r/commands_spec.rb +20 -0
- data/spec/plist4r/config_spec.rb +38 -0
- data/spec/plist4r/mixin/array_dict_spec.rb +120 -0
- data/spec/plist4r/mixin/data_methods_spec.rb +96 -0
- data/spec/plist4r/mixin/haml4r/examples.rb +261 -0
- data/spec/plist4r/mixin/ruby_stdlib_spec.rb +228 -0
- data/spec/plist4r/plist_cache_spec.rb +261 -0
- data/spec/plist4r/plist_spec.rb +841 -23
- data/spec/plist4r/plist_type_spec.rb +126 -0
- data/spec/plist4r_spec.rb +53 -27
- data/spec/scratchpad.rb +226 -0
- data/spec/spec_helper.rb +5 -1
- metadata +109 -23
- data/lib/plist4r/backend/plutil.rb +0 -25
- data/lib/plist4r/mixin.rb +0 -7
- data/plists/array_mini.xml +0 -14
- data/plists/example_big_binary.plist +0 -0
- data/plists/example_medium_binary_launchd.plist +0 -0
- data/plists/example_medium_launchd.xml +0 -53
- data/plists/mini.xml +0 -12
- data/test.rb +0 -40
@@ -0,0 +1,96 @@
|
|
1
|
+
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Plist4r::DataMethods, "#set_or_return" do
|
5
|
+
before(:each) do
|
6
|
+
class DataMethodsClass
|
7
|
+
include Plist4r::DataMethods
|
8
|
+
end
|
9
|
+
@data_methods = DataMethodsClass.new
|
10
|
+
@data_methods.instance_eval { @plist = Plist4r::Plist.new }
|
11
|
+
@integer_keys = ["IntegerKey1","IntegerKey2"]
|
12
|
+
@string_keys = ["StringKey1","StringKey2"]
|
13
|
+
@valid_keys = { :integer => @integer_keys, :string => @string_keys }
|
14
|
+
DataMethodsClass::ValidKeys = @valid_keys
|
15
|
+
@plist = @data_methods.instance_eval { @plist }
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should follow the default calling path when the supplied key is a known plist key" do
|
19
|
+
@key = @integer_keys.first
|
20
|
+
@integer_keys.stub(:include?).and_return(true)
|
21
|
+
@data_methods.stub(:set_or_return_of_type)
|
22
|
+
@valid_keys.should_receive(:each).and_yield(:integer,@integer_keys).and_yield(:string,@string_keys)
|
23
|
+
@integer_keys.should_receive(:include?).with(@key)
|
24
|
+
@string_keys.should_not_receive(:include?).with(@key)
|
25
|
+
@data_methods.should_receive(:set_or_return_of_type)
|
26
|
+
@data_methods.set_or_return(@key, "value")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should follow the alternate calling path when the supplied key is not a known plist key" do
|
30
|
+
@key = @integer_keys.first
|
31
|
+
@integer_keys.stub(:include?).and_return(false)
|
32
|
+
@string_keys.stub(:include?).and_return(false)
|
33
|
+
@data_methods.stub(:set_or_return_of_type)
|
34
|
+
@valid_keys.should_receive(:each).and_yield(:integer,@integer_keys).and_yield(:string,@string_keys)
|
35
|
+
@integer_keys.should_receive(:include?).with(@key)
|
36
|
+
@string_keys.should_receive(:include?).with(@key)
|
37
|
+
@plist.stub(:strict_keys).and_return(false)
|
38
|
+
@plist.should_receive(:strict_keys)
|
39
|
+
@data_methods.should_receive(:set_or_return_of_type)
|
40
|
+
@data_methods.set_or_return(@key, "value")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should raise an error when strict_keys is true" do
|
44
|
+
@key = @integer_keys.first
|
45
|
+
@integer_keys.stub(:include?).and_return(false)
|
46
|
+
@string_keys.stub(:include?).and_return(false)
|
47
|
+
@data_methods.stub(:set_or_return_of_type)
|
48
|
+
@valid_keys.should_receive(:each).and_yield(:integer,@integer_keys).and_yield(:string,@string_keys)
|
49
|
+
@integer_keys.should_receive(:include?).with(@key)
|
50
|
+
@string_keys.should_receive(:include?).with(@key)
|
51
|
+
@plist.stub(:strict_keys).and_return(true)
|
52
|
+
@plist.should_receive(:strict_keys)
|
53
|
+
@data_methods.should_not_receive(:set_or_return_of_type)
|
54
|
+
lambda { @data_methods.set_or_return(@key, "value") }.should raise_error(Exception)
|
55
|
+
end
|
56
|
+
|
57
|
+
after(:each) do
|
58
|
+
class DataMethodsClass
|
59
|
+
remove_const(:ValidKeys)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe Plist4r::DataMethods, "#set_or_return_of_type" do
|
65
|
+
before(:each) do
|
66
|
+
class DataMethodsClass
|
67
|
+
include Plist4r::DataMethods
|
68
|
+
|
69
|
+
alias_method :validate_value_orig, :validate_value
|
70
|
+
def validate_value key_type, key, value
|
71
|
+
end
|
72
|
+
end
|
73
|
+
@data_methods = DataMethodsClass.new
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should return the value of the stored @orig hash key, if the supplied value is nil" do
|
77
|
+
@data_methods.instance_eval { @orig = { "Key1" => "value1", "Key2" => "value2" } }
|
78
|
+
@data_methods.set_or_return_of_type(:key_type,"Key1").should == "value1"
|
79
|
+
@data_methods.set_or_return_of_type(:key_type,"Key2").should == "value2"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should follow the alternate calling path when supplied value is not nil" do
|
83
|
+
@data_methods.instance_eval { @hash = {} }
|
84
|
+
@data_methods.set_or_return_of_type(:key_type,"Key1","value1")
|
85
|
+
@data_methods.set_or_return_of_type(:key_type,"Key2","value2")
|
86
|
+
|
87
|
+
@data_methods.instance_eval { @hash["Key1"] }.should == "value1"
|
88
|
+
@data_methods.instance_eval { @hash["Key2"] }.should == "value2"
|
89
|
+
end
|
90
|
+
|
91
|
+
after(:each) do
|
92
|
+
class DataMethodsClass
|
93
|
+
alias_method :validate_value, :validate_value_orig
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,261 @@
|
|
1
|
+
|
2
|
+
require 'haml'
|
3
|
+
require 'plist4r/mixin/haml4r/table'
|
4
|
+
|
5
|
+
# def table
|
6
|
+
# t = Haml4r::Table.new :size => [0..5, 0..5]
|
7
|
+
# t.cell 0,0, "foo"
|
8
|
+
# t.cell 0,0
|
9
|
+
#
|
10
|
+
# t.cell 2,0, "pineapples"
|
11
|
+
# t.cell 4,0, "some_string"
|
12
|
+
# t.fill 0..5, 1..4, 0
|
13
|
+
# puts t.inspect
|
14
|
+
# end
|
15
|
+
# table
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
def haml4r_table
|
20
|
+
# t = Haml4r::Table.new :size => [0..5, 0..5]
|
21
|
+
# t.cell 0,0, "foo"
|
22
|
+
# t.cell 0,0
|
23
|
+
|
24
|
+
# t.cell 2,0, "pineapples"
|
25
|
+
# t.cell 4,0, "some_string"
|
26
|
+
# t.fill 0..5, 1..4, 0
|
27
|
+
# puts t.inspect
|
28
|
+
# puts ""
|
29
|
+
|
30
|
+
# puts "col_range = #{t.col_range}"
|
31
|
+
# puts "row_range = #{t.row_range}"
|
32
|
+
# puts "size = #{t.size}.inspect"
|
33
|
+
# puts ""
|
34
|
+
|
35
|
+
# puts "pad_all \"empty\""
|
36
|
+
# t.pad_all "empty"
|
37
|
+
# puts t.inspect
|
38
|
+
# puts ""
|
39
|
+
|
40
|
+
# puts "crop 0..2, 0..2"
|
41
|
+
# t2 = t.crop 0..2, 0..2
|
42
|
+
# puts t2.inspect
|
43
|
+
# puts ""
|
44
|
+
|
45
|
+
# puts "fill 0..2, 1..2, \"fill\""
|
46
|
+
# t.fill 0..2, 1..2, "fill"
|
47
|
+
# puts t.inspect
|
48
|
+
# puts ""
|
49
|
+
|
50
|
+
# puts "fill_all, \"fill\""
|
51
|
+
# t2.fill_all "fill"
|
52
|
+
# puts t2.inspect
|
53
|
+
# puts ""
|
54
|
+
|
55
|
+
# puts "inverse_fill, 1..1, 1..1, \"inverse\""
|
56
|
+
# # t2.inverse_fill 1..1, 1..1, "inverse"
|
57
|
+
# t2.inverse_fill 1, 1, "inverse"
|
58
|
+
# puts t2.inspect
|
59
|
+
# puts ""
|
60
|
+
|
61
|
+
# puts "t3"
|
62
|
+
# fruit = %w[ apples strawberries banana grapefruit mango papaya]
|
63
|
+
# day = %w[ mon tues wed thurs fri sat]
|
64
|
+
# t3 = Haml4r::Table.new :size => [0..5, 0..5]
|
65
|
+
# (0..5).each do |col|
|
66
|
+
# (0..2).each do |row|
|
67
|
+
# t3.cell col,row, fruit[col]
|
68
|
+
# # t3.cell col,row, "S " << (97+col).chr << " " << (97+row).chr
|
69
|
+
# end
|
70
|
+
# (3..5).each do |row|
|
71
|
+
# t3.cell col,row, day[col]
|
72
|
+
# end
|
73
|
+
# end
|
74
|
+
# puts t3.inspect
|
75
|
+
# puts ""
|
76
|
+
|
77
|
+
# puts "transpose"
|
78
|
+
# t3.transpose
|
79
|
+
# puts t3.inspect
|
80
|
+
# puts ""
|
81
|
+
#
|
82
|
+
# puts "transpose 3..5, 3..5"
|
83
|
+
# t3.transpose 3..5, 3..5
|
84
|
+
# puts t3.inspect
|
85
|
+
# puts ""
|
86
|
+
#
|
87
|
+
# puts "transpose 3..5, 3..5"
|
88
|
+
# t3.transpose 3..5, 3..5
|
89
|
+
# puts t3.inspect
|
90
|
+
# puts ""
|
91
|
+
#
|
92
|
+
# puts "transpose 0..3, 0..2"
|
93
|
+
# t3.transpose 0..3, 0..2
|
94
|
+
# puts t3.inspect
|
95
|
+
# puts ""
|
96
|
+
|
97
|
+
# puts "col_replace 0, (row 3)"
|
98
|
+
# # t3.col_replace 0, t3.row(3)
|
99
|
+
# t3.col_replace 0..1, "col 0..1"
|
100
|
+
# # t3.col 0, t3.col(5)
|
101
|
+
# puts t3.inspect
|
102
|
+
# puts ""
|
103
|
+
|
104
|
+
# puts "row_replace 0, (col 5)"
|
105
|
+
# puts t3.col(5).transpose.inspect
|
106
|
+
# t3.row_replace 1, t3.col(5).transpose
|
107
|
+
# # t3.row_replace 1, "row 1"
|
108
|
+
# puts t3.inspect
|
109
|
+
# puts ""
|
110
|
+
|
111
|
+
# puts "translate 0..2, 0..2, [3,3]"
|
112
|
+
# t3.translate 0..2, 0..2, [3,3]
|
113
|
+
# puts t3.inspect
|
114
|
+
# puts ""
|
115
|
+
|
116
|
+
# puts "t3.cells(0..1, 2..2)"
|
117
|
+
# puts t3.cells(0..1,2..2).inspect
|
118
|
+
# puts ""
|
119
|
+
|
120
|
+
# puts "col_insert 3..4, 3..4, t3.cells(0..1, 2..2)"
|
121
|
+
# t3.col_insert 3..4, 3..4, t3.cells(0..1,2..2)
|
122
|
+
# puts t3.inspect
|
123
|
+
# puts ""
|
124
|
+
|
125
|
+
end
|
126
|
+
# haml4r_table
|
127
|
+
|
128
|
+
def haml4r_haml_table_cells
|
129
|
+
# t = Haml4r::TableCells.new :size => [0..3, 0..5]
|
130
|
+
# puts t.inspect
|
131
|
+
# puts ""
|
132
|
+
#
|
133
|
+
# puts "t.each content = Date::DAYNAMES[i]"
|
134
|
+
# i = 0
|
135
|
+
# require 'date'
|
136
|
+
# t.each 1..2, 1..3 do |c|
|
137
|
+
# c.content = Date::DAYNAMES[i]
|
138
|
+
# i +=1
|
139
|
+
# end
|
140
|
+
# puts t.inspect
|
141
|
+
# puts ""
|
142
|
+
#
|
143
|
+
# t.cell(1,1).content = "foos"
|
144
|
+
# c = t.content
|
145
|
+
# puts "t.content => #{c.class}"
|
146
|
+
# puts c.inspect
|
147
|
+
# puts c.cell(0,0).class
|
148
|
+
# puts c.cell(1,1).class
|
149
|
+
# puts ""
|
150
|
+
#
|
151
|
+
# puts "t.content = \"depeche mode\""
|
152
|
+
# t.content = "depeche mode"
|
153
|
+
# puts t.inspect
|
154
|
+
# puts t.cell(0,0).class
|
155
|
+
# puts t.cell(1,1).class
|
156
|
+
# puts ""
|
157
|
+
end
|
158
|
+
# haml4r_haml_table_cells
|
159
|
+
|
160
|
+
def haml4r_haml_table_cell
|
161
|
+
# puts "table cell"
|
162
|
+
# c = Haml4r::TableCell.new
|
163
|
+
# puts c.inspect
|
164
|
+
# puts ""
|
165
|
+
# c.content = "jeremy"
|
166
|
+
# puts c.inspect
|
167
|
+
# puts ""
|
168
|
+
end
|
169
|
+
# haml4r_haml_table_cell
|
170
|
+
|
171
|
+
def haml4r_haml_table_cell_spans
|
172
|
+
# t = Haml4r::TableCells.new :size => [0..3, 0..5]
|
173
|
+
# # puts t.inspect
|
174
|
+
# # puts ""
|
175
|
+
#
|
176
|
+
# puts "t.each(1..2, 1..3) content = Date::DAYNAMES[i]"
|
177
|
+
# i = 0
|
178
|
+
# require 'date'
|
179
|
+
# t.each 1..2, 1..3 do |c|
|
180
|
+
# c.content = Date::DAYNAMES[i]
|
181
|
+
# i +=1
|
182
|
+
# end
|
183
|
+
# puts t.inspect
|
184
|
+
# puts ""
|
185
|
+
#
|
186
|
+
# puts "t.span_cells 0..3, 4..5, :content => \"foos\""
|
187
|
+
# t.span_cells 0..3, 4..5, :content => "foos"
|
188
|
+
# puts t.inspect
|
189
|
+
# puts ""
|
190
|
+
#
|
191
|
+
# puts "t.cell(0,4).content = \"bar\""
|
192
|
+
# t.cell(0,4).content = "bar"
|
193
|
+
# t.cell(0,4).css_class = "bar"
|
194
|
+
# t.cell(0,4).css_class += " of_trouble"
|
195
|
+
# puts t.inspect
|
196
|
+
# puts ""
|
197
|
+
#
|
198
|
+
# puts "t.to_s"
|
199
|
+
# puts t
|
200
|
+
# puts ""
|
201
|
+
end
|
202
|
+
# haml4r_haml_table_cell_spans
|
203
|
+
|
204
|
+
def haml4r_haml_table
|
205
|
+
t = Haml4r::Table.new :size => [1..3, 1..2]
|
206
|
+
|
207
|
+
t.col_range.each do |col|
|
208
|
+
t.row_range.each do |row|
|
209
|
+
t.cell(col,row).content = "val#{col}#{row}"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
t.col_header = Haml4r::TableSection.new
|
214
|
+
t.col_header.size [t.body.col_range,1..2]
|
215
|
+
t.col_header.span_cells 1..3, 1, :content => "Open"
|
216
|
+
t.col_header.col_range.each do |col|
|
217
|
+
t.col_header.cell(col,2).content = "x#{col}"
|
218
|
+
end
|
219
|
+
|
220
|
+
t.row_header = Haml4r::TableSection.new
|
221
|
+
t.row_header.size [1,t.body.row_range]
|
222
|
+
t.row_header.row_range.each do |row|
|
223
|
+
t.row_header.cell(1,row).content = "y#{row}"
|
224
|
+
end
|
225
|
+
|
226
|
+
puts t.inspect
|
227
|
+
puts ""
|
228
|
+
|
229
|
+
puts "t.to_s"
|
230
|
+
puts t
|
231
|
+
puts ""
|
232
|
+
end
|
233
|
+
# haml4r_haml_table
|
234
|
+
|
235
|
+
def haml4r_transpose_test
|
236
|
+
t = Haml4r::Table.new :size => [0..6, 2..8]
|
237
|
+
puts "strip = t.body.cells(1..5, 3..3) ; strip.span"
|
238
|
+
strip = t.body.cells(1..5, 3..3)
|
239
|
+
strip.span_cells
|
240
|
+
# strip.first.content = "foo"
|
241
|
+
strip.content = "foo"
|
242
|
+
strip.cell(6,3).content = "james"
|
243
|
+
|
244
|
+
strip.map!(1..6,3) do |c|
|
245
|
+
c.content += " bar"
|
246
|
+
end
|
247
|
+
|
248
|
+
puts t.inspect
|
249
|
+
puts ""
|
250
|
+
|
251
|
+
puts "t.body.transpose 1..5,3..3"
|
252
|
+
t.body.transpose 1..5, 3..3
|
253
|
+
# t.body.transpose 1..4, 3..3
|
254
|
+
# t.body.cell(1,7).content = "bar"
|
255
|
+
puts t.body.inspect
|
256
|
+
puts ""
|
257
|
+
|
258
|
+
end
|
259
|
+
# haml4r_transpose_test
|
260
|
+
|
261
|
+
|
@@ -0,0 +1,228 @@
|
|
1
|
+
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Object, "#method_name" do
|
5
|
+
before(:each) do
|
6
|
+
class Object
|
7
|
+
def test_method_name
|
8
|
+
method_name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
@object = Object.new
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return the name of the current method" do
|
15
|
+
@object.test_method_name.should == "test_method_name"
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:all) do
|
19
|
+
class Object
|
20
|
+
undef :test_method_name
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe Object, "#deep_clone" do
|
26
|
+
before(:each) do
|
27
|
+
@object = Object.new
|
28
|
+
@object2 = Object.new
|
29
|
+
@mershal_dump = Marshal.dump(@object)
|
30
|
+
Marshal.stub!(:dump).and_return(@marshal_dump)
|
31
|
+
Marshal.stub!(:load).with(@marshal_dump).and_return(@object2)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should call Marshal.dump with @object" do
|
35
|
+
Marshal.should_receive(:dump).with(@object)
|
36
|
+
@object.deep_clone
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should call Marshal.load with @marshal_dump" do
|
40
|
+
Marshal.should_receive(:load).with(@marshal_dump)
|
41
|
+
@object.deep_clone
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return @object2" do
|
45
|
+
@object.deep_clone.should == @object2
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe Array, "#multidim?" do
|
50
|
+
before(:each) do
|
51
|
+
@empty_array = []
|
52
|
+
@flat_array = [1,2,3]
|
53
|
+
@mixed_array = [[1],2,[3]]
|
54
|
+
@multi_array = [[1],[2],[3]]
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return false for an empty array" do
|
58
|
+
@empty_array.multidim?.should == false
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should return false for a flat array" do
|
62
|
+
@flat_array.multidim?.should == false
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return false for a mixed array" do
|
66
|
+
@mixed_array.multidim?.should == false
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should return true for a multidimensional array" do
|
70
|
+
@multi_array.multidim?.should == true
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe Array, "#to_ranges" do
|
75
|
+
before(:each) do
|
76
|
+
@a1 = [3,4,5,1,6,9,8]
|
77
|
+
@r1 = [1..1,3..6,8..9]
|
78
|
+
|
79
|
+
@a2 = [19,3,18,15,17,2,16]
|
80
|
+
@r2 = [2..3,15..19]
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should convert an array of integers into an array of ranges" do
|
84
|
+
@a1.to_ranges.should == @r1
|
85
|
+
@a2.to_ranges.should == @r2
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe Hash, "#merge_array_of_hashes_of_arrays" do
|
90
|
+
before(:each) do
|
91
|
+
@aohoa1 = {}
|
92
|
+
|
93
|
+
@aohoa2 = [
|
94
|
+
{ :array1 => [:a], :array2 => [:a,:b], :array3 => [:a,:b,:c] },
|
95
|
+
{ :array1 => [:aa], :array2 => [:aa,:bb], :array3 => [:aa,:bb,:cc] },
|
96
|
+
{ :array1 => [:aaa], :array2 => [:aaa,:bbb], :array3 => [:aaa,:bbb,:ccc] }
|
97
|
+
]
|
98
|
+
|
99
|
+
@aohoa3 = {
|
100
|
+
:array1 => [:a,:aa,:aaa],
|
101
|
+
:array2 => [:a,:b,:aa,:bb,:aaa,:bbb],
|
102
|
+
:array3 => [:a,:b,:c,:aa,:bb,:cc,:aaa,:bbb,:ccc]
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should raise an error if the supplied argument is not an aohoa" do
|
107
|
+
@not_a_aohoa1 = false
|
108
|
+
lambda { @aohoa1.merge_array_of_hashes_of_arrays @not_a_aohoa1 }.should raise_error(Exception)
|
109
|
+
|
110
|
+
@not_a_aohoa2 = [
|
111
|
+
false,
|
112
|
+
{ :array1 => [11], :array2 => [11,22], :array3 => [11,22,33], },
|
113
|
+
{ :array1 => [111], :array2 => [111,222], :array3 => [111,222,333], },
|
114
|
+
]
|
115
|
+
lambda { @aohoa1.merge_array_of_hashes_of_arrays @not_a_aohoa2 }.should raise_error(Exception)
|
116
|
+
|
117
|
+
@not_a_aohoa3 = [
|
118
|
+
{ :array1 => [1], :array2 => [1,2], :array3 => [1,2,3], },
|
119
|
+
false,
|
120
|
+
{ :array1 => [111], :array2 => [111,222], :array3 => [111,222,333], },
|
121
|
+
]
|
122
|
+
lambda { @aohoa1.merge_array_of_hashes_of_arrays @not_a_aohoa3 }.should raise_error(Exception)
|
123
|
+
|
124
|
+
@not_a_aohoa4 = [
|
125
|
+
{ :array1 => [1], :array2 => [1,2], :array3 => [1,2,3], },
|
126
|
+
{ :array1 => [11], :array2 => [11,22], :array3 => [11,22,33], },
|
127
|
+
{ :array1 => false, :array2 => [111,222], :array3 => [111,222,333], },
|
128
|
+
]
|
129
|
+
lambda { @aohoa1.merge_array_of_hashes_of_arrays @not_a_aohoa4 }.should raise_error(Exception)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should merge together 2 aohoa" do
|
133
|
+
@aohoa1.merge_array_of_hashes_of_arrays(@aohoa2).should == @aohoa3
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe Hash, "#merge_array_of_hashes_of_arrays!" do
|
138
|
+
before(:each) do
|
139
|
+
@aohoa1 = {}
|
140
|
+
|
141
|
+
@aohoa2 = [
|
142
|
+
{ :array1 => [:a], :array2 => [:a,:b], :array3 => [:a,:b,:c] },
|
143
|
+
{ :array1 => [:aa], :array2 => [:aa,:bb], :array3 => [:aa,:bb,:cc] },
|
144
|
+
{ :array1 => [:aaa], :array2 => [:aaa,:bbb], :array3 => [:aaa,:bbb,:ccc] }
|
145
|
+
]
|
146
|
+
|
147
|
+
@aohoa3 = {
|
148
|
+
:array1 => [:a,:aa,:aaa],
|
149
|
+
:array2 => [:a,:b,:aa,:bb,:aaa,:bbb],
|
150
|
+
:array3 => [:a,:b,:c,:aa,:bb,:cc,:aaa,:bbb,:ccc]
|
151
|
+
}
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should call merge_array_of_hashes_of_arrays in place" do
|
155
|
+
@aohoa1 = {}
|
156
|
+
@aohoa1.merge_array_of_hashes_of_arrays!(@aohoa2)
|
157
|
+
@aohoa1.should == @aohoa3
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe Range, "#size" do
|
162
|
+
it "should return the size of @range" do
|
163
|
+
@range = 0..3
|
164
|
+
@range.size.should == 4
|
165
|
+
|
166
|
+
@range = 5..5
|
167
|
+
@range.size.should == 1
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe Range, "#&" do
|
172
|
+
it "should return the intersection of 2 discrete ranges" do
|
173
|
+
(1..3).&(5..9).should == nil
|
174
|
+
(1..3).&(4..9).should == nil
|
175
|
+
(1..3).&(3..9).should == (3..3)
|
176
|
+
(1..9).&(3..8).should == (3..8)
|
177
|
+
(1..6).&(3..9).should == (3..6)
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should raise an error when the supplied argument is not a Range" do
|
181
|
+
not_a_range = false
|
182
|
+
lambda { (1..3).&(not_a_range) }.should raise_error(Exception)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe Range, "#include_range?" do
|
187
|
+
it "should return true if self wholely includes the supplied range" do
|
188
|
+
(1..3).include_range?(1..1).should == true
|
189
|
+
(1..3).include_range?(3..3).should == true
|
190
|
+
(1..3).include_range?(1..9).should == false
|
191
|
+
(1..9).include_range?(3..8).should == true
|
192
|
+
(1..6).include_range?(3..9).should == false
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should raise an error when the supplied argument is not a Range" do
|
196
|
+
not_a_range = false
|
197
|
+
lambda { (1..3).include_range?(not_a_range) }.should raise_error(Exception)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe String, "#camelcase" do
|
202
|
+
it "should return the CamelCased version of string" do
|
203
|
+
"".camelcase.should == ""
|
204
|
+
"string".camelcase.should == "String"
|
205
|
+
"word1_word2".camelcase.should == "Word1Word2"
|
206
|
+
"Word1Word2".camelcase.should == "Word1Word2"
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
describe String, "#snake_case" do
|
211
|
+
it "should return the snake_cased version of string" do
|
212
|
+
"".snake_case.should == ""
|
213
|
+
"String".snake_case.should == "string"
|
214
|
+
"Word1Word2".snake_case.should == "word1_word2"
|
215
|
+
"word1_word2".snake_case.should == "word1_word2"
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
describe Float, "#round" do
|
220
|
+
it "should round self to the supplied number of decimal places" do
|
221
|
+
@f = 0.123456789
|
222
|
+
@f.round(0).to_s.should == "0.0"
|
223
|
+
@f.round(1).to_s.should == "0.1"
|
224
|
+
@f.round(2).to_s.should == "0.12"
|
225
|
+
@f.round(3).to_s.should == "0.123"
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|