bc3 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,7 +16,8 @@ class Test_snapshot < Test::Unit::TestCase
16
16
  assert_nothing_raised{ bc3 << BC3::File.new( filename: 'file', filesize: 1 )}
17
17
  assert_raise(ArgumentError){ bc3 << 1 }
18
18
 
19
- assert_equal(2, bc3.each.size)
19
+ assert_equal(1, bc3.each.size)
20
+ assert_equal(2, bc3.each(:files, :folders).size)
20
21
  end
21
22
  def test_hash()
22
23
  bc3 = BC3::Snapshot.new('x', $timestamp)
@@ -39,36 +40,36 @@ class Test_snapshot < Test::Unit::TestCase
39
40
  }, bc3.to_hash
40
41
  )
41
42
  end
42
- def test_newh_interface()
43
+ def test_new_hash_interface()
43
44
  #Test no-hash
44
- assert_raise(ArgumentError){ BC3::Snapshot.newh('x')}
45
- assert_raise(ArgumentError){ BC3::Snapshot.newh('1')}
45
+ assert_raise(ArgumentError){ BC3::Snapshot.new_hash('x')}
46
+ assert_raise(ArgumentError){ BC3::Snapshot.new_hash('1')}
46
47
  #Hash must contain snapshot and content
47
- assert_raise(ArgumentError){ BC3::Snapshot.newh({})}
48
- assert_raise(ArgumentError){ BC3::Snapshot.newh({snapshot: 'x' })}
49
- assert_raise(ArgumentError){ BC3::Snapshot.newh({snapshot: 'x' })}
50
- assert_raise(ArgumentError){ BC3::Snapshot.newh({snapshot: 'x', timestamp: $timestamp })}
48
+ assert_raise(ArgumentError){ BC3::Snapshot.new_hash({})}
49
+ assert_raise(ArgumentError){ BC3::Snapshot.new_hash({snapshot: 'x' })}
50
+ assert_raise(ArgumentError){ BC3::Snapshot.new_hash({snapshot: 'x' })}
51
+ assert_raise(ArgumentError){ BC3::Snapshot.new_hash({snapshot: 'x', timestamp: $timestamp })}
51
52
 
52
- assert_nothing_raised{ bc3 = BC3::Snapshot.newh({ snapshot: 'x', content: [] })}
53
+ assert_nothing_raised{ bc3 = BC3::Snapshot.new_hash({ snapshot: 'x', content: [] })}
53
54
  #Content must be an array
54
- assert_raise(ArgumentError){ bc3 = BC3::Snapshot.newh({ snapshot: 'x', content: :x })}
55
+ assert_raise(ArgumentError){ bc3 = BC3::Snapshot.new_hash({ snapshot: 'x', content: :x })}
55
56
  end
56
- def test_newh()
57
+ def test_new_hash()
57
58
  hash = { snapshot: 'x', timestamp: $timestamp,
58
59
  content: [
59
60
  filename: 'file1', filesize: 5, timestamp: $timestamp, crc: nil, attributes: BC3::Attrib::Archive,
60
61
  ]
61
62
  }
62
- assert_equal(hash, BC3::Snapshot.newh( hash ).to_hash)
63
+ assert_equal(hash, BC3::Snapshot.new_hash( hash ).to_hash)
63
64
 
64
65
  hash[:content] << { filename: 'file2', filesize: 15, timestamp: $timestamp, crc: nil, attributes: BC3::Attrib::Archive, }
65
- assert_equal(hash, BC3::Snapshot.newh( hash ).to_hash)
66
+ assert_equal(hash, BC3::Snapshot.new_hash( hash ).to_hash)
66
67
 
67
68
  hash[:content] << { dirname: 'dir1', timestamp: $timestamp, :content => [], attributes: BC3::Attrib::Directory, }
68
- assert_equal(hash, BC3::Snapshot.newh( hash ).to_hash)
69
+ assert_equal(hash, BC3::Snapshot.new_hash( hash ).to_hash)
69
70
  end
70
- def test_newd()
71
- bc3 = BC3::Snapshot.newd( '../examples/folder1' )
71
+ def test_new_filesystem()
72
+ bc3 = BC3::Snapshot.new_filesystem( '../examples/folder1' )
72
73
 
73
74
  #timestamp change
74
75
  #~ assert_equal(%{
@@ -84,37 +85,224 @@ class Test_snapshot < Test::Unit::TestCase
84
85
 
85
86
  assert_equal(1, bc3.each.size)
86
87
  assert_equal(1, bc3.each(:files).size)
87
- assert_equal(1, bc3.each(:recursive).size)
88
+ #~ assert_equal(0, bc3.each(:recursive).size)#no files/folders defined
88
89
  assert_equal(1, bc3.each(:recursive, :files).size)
90
+ assert_equal(0, bc3.each(:recursive, :folders).size)
91
+ assert_equal(1, bc3.each(:recursive, :folders, :files).size)
89
92
 
90
93
  assert_equal('file1.txt', bc3.each.first.first)
91
94
 
92
95
  end
93
- def test_new_list()
94
- pend 'BC3::Snapshot.new_list'
95
- bc3 = BC3::Snapshot.new_list( 'dir', %w{
96
+ def test_new_filelist()
97
+ #~ pend 'BC3::Snapshot.new_filelist'
98
+ bc3 = BC3::Snapshot.new_filelist( 'dir', %{
96
99
  file
97
100
  folder/file1
98
101
  folder/subfolder/subfile1
99
102
  folder/subfolder2/
100
103
  }
101
104
  )
102
-
103
- assert_equal(2, bc3.each.size)
104
- assert_equal(1, bc3.each(:files).size)
105
- assert_equal(5, bc3.each(:recursive).size)
106
- assert_equal(2, bc3.each(:recursive, :files).size)
107
- assert_equal(3, bc3.each(:recursive, :folders).size)
108
105
 
109
106
  assert_equal( %w{
110
107
  file
111
- folder
108
+ folder/
109
+ folder/file1
110
+ folder/subfolder/
111
+ folder/subfolder/subfile1
112
+ folder/subfolder2/
113
+ }, bc3.each(:files, :folders ).keys)
114
+
115
+ assert_equal( %w{
116
+ file
117
+ folder/
118
+ }, bc3.each(:rootonly, :files, :folders ).keys)
119
+
120
+ assert_equal( %w{
121
+ folder/
122
+ folder/subfolder/
123
+ folder/subfolder2/
124
+ }, bc3.each(:folders ).keys)
125
+
126
+ assert_equal( %w{
127
+ file
112
128
  folder/file1
113
- folder/subfolder
114
129
  folder/subfolder/subfile1
115
- folder/subfolder2
116
- }, bc3.each(:recursive, :files).keys)
130
+ }, bc3.each(:files ).keys)
131
+
132
+
133
+ assert_equal(3, bc3.each.size)
134
+ assert_equal(3, bc3.each(:files).size)
135
+ assert_equal(3, bc3.each(:folders).size)
136
+ assert_equal(6, bc3.each(:folders, :files).size)
137
+
138
+ assert_equal(1, bc3.each(:rootonly, :files).size)
139
+ assert_equal(1, bc3.each(:rootonly, :folders).size)
140
+ assert_equal(2, bc3.each(:rootonly, :folders, :files).size)
141
+ end
142
+
143
+
144
+ def test_statistic()
145
+ bc3 = BC3::Snapshot.new_hash( YAML.load(%{
146
+ :snapshot: x
147
+ :content:
148
+ - :dirname: dir
149
+ :attributes: 16
150
+ :content: []
151
+
152
+ - :filename: file
153
+ :filesize: 1
154
+ :crc:
155
+ :attributes: 32
156
+ }))
157
+
158
+ stat = bc3.statistic
159
+ assert_kind_of(Hash, stat)
160
+ assert_equal(%w{folders files}, stat.keys) #no duplicates
161
+ assert_equal(1, stat['files'])
162
+ assert_equal(1, stat['folders'])
117
163
 
164
+ end
165
+
166
+ def test_statistic_dup()
167
+ bc3 = BC3::Snapshot.new_hash( YAML.load(%{
168
+ :snapshot: x
169
+ :content:
170
+ - :filename: file15
171
+ :filesize: 1
172
+ :crc: 15
173
+ :attributes: 32
174
+ - :filename: file15b
175
+ :filesize: 1
176
+ :crc: 15
177
+ :attributes: 32
178
+ - :filename: file16
179
+ :filesize: 1
180
+ :crc: 16
181
+ :attributes: 32
182
+ - :filename: file0
183
+ :filesize: 1
184
+ - :filename: file0b
185
+ :filesize: 1
186
+
187
+ }))
188
+
189
+ stat = bc3.statistic
190
+ assert_kind_of(Hash, stat)
191
+ assert_equal(%w{files duplicates_by_crc}, stat.keys) #no folders
192
+ assert_equal(5, stat['files'])
193
+ assert_equal(0, stat['folders']) #even there is no folder, the default of the hash is 0.
194
+
195
+ assert_kind_of(Hash, stat['duplicates_by_crc'])
196
+ assert_equal(1, stat['duplicates_by_crc'].size)
197
+ assert_equal(nil, stat['duplicates_by_crc'][16])
198
+ assert_equal(2, stat['duplicates_by_crc'][15].size)
199
+ assert_equal({15=>["file15", "file15b"]}, stat['duplicates_by_crc'])
200
+ end
201
+
202
+ def test_index()
203
+ #~ pend 'BC3::Snapshot.new_filelist'
204
+ bc3 = BC3::Snapshot.new_filelist( 'dir', %{
205
+ file
206
+ folder/file1
207
+ folder/subfolder/subfile1
208
+ folder/subfolder2/
209
+ } )
210
+ #extend object
211
+ class << bc3; attr_reader :index; end
212
+ assert_nil( bc3.index )
213
+ bc3.build_index
214
+ assert_kind_of( Hash, bc3.index )
215
+
216
+ bc3.reset_index()
217
+ assert_nil( bc3.index )
218
+ bc3.build_index
219
+ assert_kind_of( Hash, bc3.index )
220
+
221
+ #test index
222
+ assert_equal(%w{
223
+ file
224
+ folder/
225
+ folder/file1
226
+ folder/subfolder/
227
+ folder/subfolder/subfile1
228
+ folder/subfolder2/
229
+ }, bc3.index.keys)
230
+ end #test_index
231
+ def test_index_automatic_reset()
232
+ #~ pend 'BC3::Snapshot.new_filelist'
233
+ bc3 = BC3::Snapshot.new_filelist( 'dir', %{
234
+ file
235
+ folder/file1
236
+ folder/subfolder/subfile1
237
+ folder/subfolder2/
238
+ } )
239
+ #extend object
240
+ class << bc3; attr_reader :index; end
241
+ assert_nil( bc3.index )
242
+
243
+ bc3.build_index
244
+ assert_kind_of( Hash, bc3.index )
245
+
246
+ #Check changes in root
247
+ folder = bc3 << BC3::Folder.new('folder')
248
+ assert_nil( bc3.index )
249
+ =begin
250
+ Remark:
251
+ bc3 << folder = BC3::Folder.new('folder')
252
+ will not work.
253
+ The mixin mechanism throws away the given folder and
254
+ adds the content to the already existing folder.
255
+ =end
256
+
257
+ bc3.build_index
258
+ assert_kind_of( Hash, bc3.index )
259
+
260
+ #check changes in subdirectories
261
+ folder << BC3::Folder.new('folder')
262
+ assert_nil( bc3.index )
263
+
264
+ end #test_index_automatic_reset
265
+
266
+ def test_get()
267
+ bc3 = BC3::Snapshot.new('x')
268
+
269
+ bc3 << folder = BC3::Folder.new('dir')
270
+ bc3 << file = BC3::File.new( filename: 'file', filesize: 1 )
271
+ folder << file2 = BC3::File.new( filename: 'file', filesize: 1 )
272
+
273
+ assert_equal(folder, bc3['dir/'])
274
+ assert_equal(file, bc3['file'])
275
+ assert_equal(file2, bc3['dir/file'])
276
+
277
+ assert_not_equal(file2, bc3['file'])
278
+ assert_not_equal(file, bc3['dir/file'])
279
+ end
280
+ end #Test_snapshot
281
+
282
+ =begin
283
+ Tests with File creation
284
+ =end
285
+ class Test_snapshot_IO < Test::Unit::TestCase
286
+ TestFiles = %w{test.bcss test.yaml test.yml}
287
+
288
+ def self.startup
289
+ TestFiles.each{|f| File.delete(f) if File.exist?(f)}
290
+ end
291
+
292
+ def self.shutdown
293
+ TestFiles.each{|f| File.delete(f) if File.exist?(f)}
294
+ end
295
+ def test_save()
296
+ bc3 = BC3::Snapshot.new_filesystem( '../examples/folder1' )
297
+ #~ bc3 = BC3::Snapshot.new('x')
298
+ assert_nothing_raised{ bc3.save('test.bcss')}
299
+ assert_nothing_raised{ bc3.save('test.yaml')}
300
+ assert_nothing_raised{ bc3.save('test.yml')}
301
+ assert_raise(ArgumentError){ bc3.save('test.txt') }
302
+
303
+ assert_equal(File.read('test.yaml'), File.read('test.yml') )
304
+ assert_equal(File.read('test.yaml'), bc3.to_hash.to_yaml )
305
+ assert_equal(YAML.load(File.read('test.yaml')), bc3.to_hash )
118
306
 
119
307
  end
120
308
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bc3
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Knut Lickert
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-24 00:00:00 +01:00
18
+ date: 2011-01-30 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -35,21 +35,24 @@ dependencies:
35
35
  description: |
36
36
  Build and analyse Beyond Compare (BC3) Snapshot-Files.
37
37
  This gem allows flexible definition of BC3-snapshots and
38
- actions like snapshot merge...
38
+ actions like snapshot merge, snapshot search...
39
39
 
40
40
  More about Beyond compare at http://www.scootersoftware.com
41
41
 
42
42
  email: knut@lickert.net
43
43
  executables:
44
44
  - bc3_merge.rb
45
+ - bc3_search.rb
45
46
  extensions: []
46
47
 
47
48
  extra_rdoc_files:
48
49
  - BCSS_Binary_Format.txt
49
50
  - bin/bc3_merge.rb
51
+ - bin/bc3_search.rb
50
52
  files:
51
53
  - BCSS_Binary_Format.txt
52
54
  - bin/bc3_merge.rb
55
+ - bin/bc3_search.rb
53
56
  - lib/bc3.rb
54
57
  - lib/bc3/file.rb
55
58
  - lib/bc3/folder.rb
@@ -62,6 +65,7 @@ files:
62
65
  - unittest/unittest_bc3_folder.rb
63
66
  - unittest/unittest_bc3_snapshot.rb
64
67
  - unittest/unittest_bc3_merge.rb
68
+ - unittest/unittest_bc3_search.rb
65
69
  - examples/test_combine.rb
66
70
  - examples/test_filesystem.rb
67
71
  - examples/test_hardcoded.rb
@@ -70,7 +74,7 @@ files:
70
74
  - examples/folder1_2011-01-21.bcss
71
75
  - examples/folder2_2011-01-21.bcss
72
76
  has_rdoc: true
73
- homepage: http://www.scootersoftware.com/vbulletin/showthread.php?t=7210
77
+ homepage: http://gems.rubypla.net/bc3
74
78
  licenses: []
75
79
 
76
80
  post_install_message:
@@ -110,6 +114,7 @@ test_files:
110
114
  - unittest/unittest_bc3_folder.rb
111
115
  - unittest/unittest_bc3_snapshot.rb
112
116
  - unittest/unittest_bc3_merge.rb
117
+ - unittest/unittest_bc3_search.rb
113
118
  - examples/test_combine.rb
114
119
  - examples/test_filesystem.rb
115
120
  - examples/test_hardcoded.rb