cmpfs-ruby 0.2.1.1 → 0.2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +113 -2
- data/examples/compare_two_binary_files.rb +44 -0
- data/examples/compare_two_text_files.rb +44 -0
- data/lib/cmpfs/compare/api_1_9.rb +49 -28
- data/lib/cmpfs/compare/api_2.rb +49 -28
- data/lib/cmpfs/compare/binary/internal_.rb +8 -8
- data/lib/cmpfs/compare/text/internal_.rb +18 -18
- data/lib/cmpfs/version.rb +2 -2
- data/lib/cmpfs.rb +6 -6
- data/test/unit/compare/tc_compare_binary.rb +5 -5
- data/test/unit/compare/ts_all.rb +1 -1
- data/test/unit/tc_compare_binary.rb +5 -5
- data/test/unit/tc_compare_text.rb +13 -13
- data/test/unit/ts_all.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46fb5f08ba76dfb2e7850d848f46c57016635721b445974b280a8247d7d93ac0
|
4
|
+
data.tar.gz: 60baeea6023c1d8178ecfc5c54b3f8ab8fe9e2b562773785b5453c2a868d560a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed2d57ba6d485a995ef08244373e7518a2212fff1560cc23be8809100200a83759c37416c4e9a37e5dc878ad5facf58d99b1baef9221d350ecf828b8b6711151
|
7
|
+
data.tar.gz: e9b77bf3cb58c210afbc64db805a2a7898a0fd8507a8f2e470df66cdbdd58c5799c8ec68bd0e23f832d30d5e16ff030ea81965e958804b35d1e2eec1efab6ee7
|
data/README.md
CHANGED
@@ -4,10 +4,12 @@
|
|
4
4
|
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/cmpfs-ruby.svg)](https://badge.fury.io/rb/cmpfs-ruby)
|
6
6
|
|
7
|
+
|
7
8
|
## Introduction
|
8
9
|
|
9
10
|
Provides platform-independent facilities for comparing file contents, for both binary and text files
|
10
11
|
|
12
|
+
|
11
13
|
## Table of Contents <!-- omit in toc -->
|
12
14
|
|
13
15
|
- [Introduction](#introduction)
|
@@ -21,17 +23,122 @@ Provides platform-independent facilities for comparing file contents, for both b
|
|
21
23
|
- [Related projects](#related-projects)
|
22
24
|
- [License](#license)
|
23
25
|
|
26
|
+
|
24
27
|
## Installation
|
25
28
|
|
26
29
|
Install using `gem install cmpfs-ruby` or add it to your `Gemfile`.
|
27
30
|
|
31
|
+
|
28
32
|
## Components
|
29
33
|
|
30
|
-
|
34
|
+
The primary components provided are the functions:
|
35
|
+
|
36
|
+
* `CmpFS::Compare.compare_binary_files()`
|
37
|
+
* `CmpFS::Compare.compare_binary_streams()`
|
38
|
+
* `CmpFS::Compare.compare_binary()`
|
39
|
+
* `CmpFS::Compare.compare_text_files()`
|
40
|
+
* `CmpFS::Compare.compare_text_streams()`
|
41
|
+
* `CmpFS::Compare.compare_text()`
|
42
|
+
|
43
|
+
all of which are obtained when `extend`ing or `include`ing the `CmpFS` module.
|
44
|
+
|
31
45
|
|
32
46
|
## Examples
|
33
47
|
|
34
|
-
|
48
|
+
**examples/compare_two_binary_files.rb**:
|
49
|
+
```Ruby
|
50
|
+
#! /usr/bin/env ruby
|
51
|
+
|
52
|
+
$:.unshift File.join(File.dirname(__FILE__), '../lib')
|
53
|
+
|
54
|
+
|
55
|
+
require 'cmpfs'
|
56
|
+
|
57
|
+
|
58
|
+
include CmpFS
|
59
|
+
|
60
|
+
|
61
|
+
# command-line handling
|
62
|
+
|
63
|
+
lhs_path, rhs_path =
|
64
|
+
case ARGV.size
|
65
|
+
when 0, 1
|
66
|
+
|
67
|
+
if '--help' == ARGV[0]
|
68
|
+
|
69
|
+
$stdout.puts "#$0: <lhs-path> <rhs-path>"
|
70
|
+
|
71
|
+
exit 0
|
72
|
+
end
|
73
|
+
|
74
|
+
abort "#$0: not enough arguments; use --help for usage"
|
75
|
+
when 2
|
76
|
+
|
77
|
+
ARGV[0..2]
|
78
|
+
else
|
79
|
+
|
80
|
+
abort "#$0: too many arguments; use --help for usage"
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
# main()
|
85
|
+
|
86
|
+
|
87
|
+
$stdout.puts "binary comparison of '#{lhs_path}' with '#{rhs_path}':"
|
88
|
+
|
89
|
+
$stdout.puts "files are #{compare_binary(lhs_path, rhs_path) ? '' : 'not '}equal"
|
90
|
+
|
91
|
+
|
92
|
+
# ############################## end of file ############################# #
|
93
|
+
```
|
94
|
+
|
95
|
+
**examples/compare_two_text_files.rb**:
|
96
|
+
```Ruby
|
97
|
+
#! /usr/bin/env ruby
|
98
|
+
|
99
|
+
$:.unshift File.join(File.dirname(__FILE__), '../lib')
|
100
|
+
|
101
|
+
|
102
|
+
require 'cmpfs'
|
103
|
+
|
104
|
+
|
105
|
+
include CmpFS
|
106
|
+
|
107
|
+
|
108
|
+
# command-line handling
|
109
|
+
|
110
|
+
lhs_path, rhs_path =
|
111
|
+
case ARGV.size
|
112
|
+
when 0, 1
|
113
|
+
|
114
|
+
if '--help' == ARGV[0]
|
115
|
+
|
116
|
+
$stdout.puts "#$0: <lhs-path> <rhs-path>"
|
117
|
+
|
118
|
+
exit 0
|
119
|
+
end
|
120
|
+
|
121
|
+
abort "#$0: not enough arguments; use --help for usage"
|
122
|
+
when 2
|
123
|
+
|
124
|
+
ARGV[0..2]
|
125
|
+
else
|
126
|
+
|
127
|
+
abort "#$0: too many arguments; use --help for usage"
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
# main()
|
132
|
+
|
133
|
+
|
134
|
+
$stdout.puts "text comparison of '#{lhs_path}' with '#{rhs_path}':"
|
135
|
+
|
136
|
+
$stdout.puts "files are #{compare_text(lhs_path, rhs_path, skip_blank_lines: true, trim_lines: true) ? '' : 'not '}equal"
|
137
|
+
|
138
|
+
|
139
|
+
# ############################## end of file ############################# #
|
140
|
+
```
|
141
|
+
|
35
142
|
|
36
143
|
## Project Information
|
37
144
|
|
@@ -39,16 +146,20 @@ T.B.C.
|
|
39
146
|
|
40
147
|
[GitHub Page](https://github.com/synesissoftware/cmpfs.Ruby "GitHub Page")
|
41
148
|
|
149
|
+
|
42
150
|
### Contribution guidelines
|
43
151
|
|
44
152
|
Defect reports, feature requests, and pull requests are welcome on https://github.com/synesissoftware/cmpfs.Ruby.
|
45
153
|
|
154
|
+
|
46
155
|
### Dependencies
|
47
156
|
|
157
|
+
|
48
158
|
### Related projects
|
49
159
|
|
50
160
|
T.B.C.
|
51
161
|
|
162
|
+
|
52
163
|
### License
|
53
164
|
|
54
165
|
**cmpfs.Ruby** is released under the 3-clause BSD license. See [LICENSE](./LICENSE) for details.
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '../lib')
|
4
|
+
|
5
|
+
|
6
|
+
require 'cmpfs'
|
7
|
+
|
8
|
+
|
9
|
+
include CmpFS
|
10
|
+
|
11
|
+
|
12
|
+
# command-line handling
|
13
|
+
|
14
|
+
lhs_path, rhs_path =
|
15
|
+
case ARGV.size
|
16
|
+
when 0, 1
|
17
|
+
|
18
|
+
if '--help' == ARGV[0]
|
19
|
+
|
20
|
+
$stdout.puts "#$0: <lhs-path> <rhs-path>"
|
21
|
+
|
22
|
+
exit 0
|
23
|
+
end
|
24
|
+
|
25
|
+
abort "#$0: not enough arguments; use --help for usage"
|
26
|
+
when 2
|
27
|
+
|
28
|
+
ARGV[0..2]
|
29
|
+
else
|
30
|
+
|
31
|
+
abort "#$0: too many arguments; use --help for usage"
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
# main()
|
36
|
+
|
37
|
+
|
38
|
+
$stdout.puts "binary comparison of '#{lhs_path}' with '#{rhs_path}':"
|
39
|
+
|
40
|
+
$stdout.puts "files are #{compare_binary(lhs_path, rhs_path) ? '' : 'not '}equal"
|
41
|
+
|
42
|
+
|
43
|
+
# ############################## end of file ############################# #
|
44
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '../lib')
|
4
|
+
|
5
|
+
|
6
|
+
require 'cmpfs'
|
7
|
+
|
8
|
+
|
9
|
+
include CmpFS
|
10
|
+
|
11
|
+
|
12
|
+
# command-line handling
|
13
|
+
|
14
|
+
lhs_path, rhs_path =
|
15
|
+
case ARGV.size
|
16
|
+
when 0, 1
|
17
|
+
|
18
|
+
if '--help' == ARGV[0]
|
19
|
+
|
20
|
+
$stdout.puts "#$0: <lhs-path> <rhs-path>"
|
21
|
+
|
22
|
+
exit 0
|
23
|
+
end
|
24
|
+
|
25
|
+
abort "#$0: not enough arguments; use --help for usage"
|
26
|
+
when 2
|
27
|
+
|
28
|
+
ARGV[0..2]
|
29
|
+
else
|
30
|
+
|
31
|
+
abort "#$0: too many arguments; use --help for usage"
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
# main()
|
36
|
+
|
37
|
+
|
38
|
+
$stdout.puts "text comparison of '#{lhs_path}' with '#{rhs_path}':"
|
39
|
+
|
40
|
+
$stdout.puts "files are #{compare_text(lhs_path, rhs_path, skip_blank_lines: true, trim_lines: true) ? '' : 'not '}equal"
|
41
|
+
|
42
|
+
|
43
|
+
# ############################## end of file ############################# #
|
44
|
+
|
@@ -15,6 +15,18 @@ module CmpFS_Compare_Methods
|
|
15
15
|
|
16
16
|
# Compares two files, named by +lhs_path+ and +rhs_path+, in a binary
|
17
17
|
# (exact) manner
|
18
|
+
#
|
19
|
+
# === Signature
|
20
|
+
#
|
21
|
+
# * *Parameters:*
|
22
|
+
# - +lhs_path+:: (+String+) The name of a file
|
23
|
+
# - +rhs_path+:: (+String+) The name of a file
|
24
|
+
# - +options+:: (+Hash+) Options that control the behaviour of the method
|
25
|
+
#
|
26
|
+
# * *Options:*
|
27
|
+
#
|
28
|
+
# === Return
|
29
|
+
# +true+ if the files have exactly the same content; +false+ otherwise.
|
18
30
|
def compare_binary_files lhs_path, rhs_path, options = {}
|
19
31
|
|
20
32
|
options ||= {}
|
@@ -24,6 +36,19 @@ module CmpFS_Compare_Methods
|
|
24
36
|
|
25
37
|
# Compares two streams, +lhs_stm+ and +rhs_stm+, in a binary
|
26
38
|
# (exact) manner
|
39
|
+
#
|
40
|
+
# === Signature
|
41
|
+
#
|
42
|
+
# * *Parameters:*
|
43
|
+
# - +lhs_stm+:: (stream) A stream object
|
44
|
+
# - +rhs_stm+:: (stream) A stream object
|
45
|
+
# - +options+:: (+Hash+) Options that control the behaviour of the method
|
46
|
+
#
|
47
|
+
# * *Options:*
|
48
|
+
# - +:no_rewind+:: (boolean) Prevents the default behaviour of rewinding each stream before processing
|
49
|
+
#
|
50
|
+
# === Return
|
51
|
+
# +true+ if the streams have exactly the same content; +false+ otherwise.
|
27
52
|
def compare_binary_streams lhs_stm, rhs_stm, options = {}
|
28
53
|
|
29
54
|
options ||= {}
|
@@ -33,10 +58,17 @@ module CmpFS_Compare_Methods
|
|
33
58
|
|
34
59
|
# Compares two files/streams in a binary (exact) manner
|
35
60
|
#
|
36
|
-
#
|
61
|
+
# === Signature
|
37
62
|
#
|
38
|
-
#
|
63
|
+
# * *Parameters:*
|
64
|
+
# - +lhs+:: (+String+, stream) The name of a file, or a stream object
|
65
|
+
# - +rhs+:: (+String+, stream) The name of a file, or a stream object
|
66
|
+
# - +options+:: (+Hash+) Options that control the behaviour of the method
|
39
67
|
#
|
68
|
+
# * *Options:*
|
69
|
+
# - +:no_rewind+:: (boolean) Prevents the default behaviour of rewinding each stream before processing
|
70
|
+
#
|
71
|
+
# === Return
|
40
72
|
# +true+ if the files/streams have exactly the same content; +false+
|
41
73
|
# otherwise.
|
42
74
|
def compare_binary lhs, rhs, options = {}
|
@@ -53,18 +85,15 @@ module CmpFS_Compare_Methods
|
|
53
85
|
# === Signature
|
54
86
|
#
|
55
87
|
# * *Parameters:*
|
56
|
-
# - +lhs_path+:: (String) The name of a file
|
57
|
-
# - +rhs_path+:: (String) The name of a file
|
58
|
-
# - +options+:: (Hash) Options
|
88
|
+
# - +lhs_path+:: (+String+) The name of a file
|
89
|
+
# - +rhs_path+:: (+String+) The name of a file
|
90
|
+
# - +options+:: (+Hash+) Options that control the behaviour of the method
|
59
91
|
#
|
60
92
|
# * *Options:*
|
61
|
-
# - +:skip_blank_lines+:: (boolean) Determines whether blank lines
|
62
|
-
#
|
63
|
-
# - +:trim_lines+:: (boolean) Determines whether lines should be
|
64
|
-
# trimmed of leading and trailing space (including EOL sequence)
|
93
|
+
# - +:skip_blank_lines+:: (boolean) Determines whether blank lines should be skipped from the comparison
|
94
|
+
# - +:trim_lines+:: (boolean) Determines whether lines should be trimmed of leading and trailing space (including EOL sequence)
|
65
95
|
#
|
66
96
|
# === Return
|
67
|
-
#
|
68
97
|
# +true+ if the files/streams have exactly the same content; +false+
|
69
98
|
# otherwise.
|
70
99
|
def compare_text_files lhs_path, rhs_path, options = {}
|
@@ -82,18 +111,14 @@ module CmpFS_Compare_Methods
|
|
82
111
|
# * *Parameters:*
|
83
112
|
# - +lhs_stm+:: (stream) A stream object
|
84
113
|
# - +rhs_stm+:: (stream) A stream object
|
85
|
-
# - +options+:: (Hash) Options
|
114
|
+
# - +options+:: (+Hash+) Options that control the behaviour of the method
|
86
115
|
#
|
87
116
|
# * *Options:*
|
88
|
-
# - +:no_rewind+:: (boolean) Prevents the default behaviour of
|
89
|
-
#
|
90
|
-
# - +:
|
91
|
-
# should be skipped from the comparison
|
92
|
-
# - +:trim_lines+:: (boolean) Determines whether lines should be
|
93
|
-
# trimmed of leading and trailing space (including EOL sequence)
|
117
|
+
# - +:no_rewind+:: (boolean) Prevents the default behaviour of rewinding each stream before processing
|
118
|
+
# - +:skip_blank_lines+:: (boolean) Determines whether blank lines should be skipped from the comparison
|
119
|
+
# - +:trim_lines+:: (boolean) Determines whether lines should be trimmed of leading and trailing space (including EOL sequence)
|
94
120
|
#
|
95
121
|
# === Return
|
96
|
-
#
|
97
122
|
# +true+ if the files/streams have exactly the same content; +false+
|
98
123
|
# otherwise.
|
99
124
|
def compare_text_streams lhs_stm, rhs_stm, options = {}
|
@@ -109,20 +134,16 @@ module CmpFS_Compare_Methods
|
|
109
134
|
# === Signature
|
110
135
|
#
|
111
136
|
# * *Parameters:*
|
112
|
-
# - +lhs+:: (String
|
113
|
-
# - +rhs+:: (String
|
114
|
-
# - +options+:: (Hash) Options
|
137
|
+
# - +lhs+:: (+String+, stream) The name of a file, or a stream object
|
138
|
+
# - +rhs+:: (+String+, stream) The name of a file, or a stream object
|
139
|
+
# - +options+:: (+Hash+) Options that control the behaviour of the method
|
115
140
|
#
|
116
141
|
# * *Options:*
|
117
|
-
# - +:no_rewind+:: (boolean) Prevents the default behaviour of
|
118
|
-
#
|
119
|
-
# - +:
|
120
|
-
# should be skipped from the comparison
|
121
|
-
# - +:trim_lines+:: (boolean) Determines whether lines should be
|
122
|
-
# trimmed of leading and trailing space (including EOL sequence)
|
142
|
+
# - +:no_rewind+:: (boolean) Prevents the default behaviour of rewinding each stream before processing
|
143
|
+
# - +:skip_blank_lines+:: (boolean) Determines whether blank lines should be skipped from the comparison
|
144
|
+
# - +:trim_lines+:: (boolean) Determines whether lines should be trimmed of leading and trailing space (including EOL sequence)
|
123
145
|
#
|
124
146
|
# === Return
|
125
|
-
#
|
126
147
|
# +true+ if the files/streams have exactly the same content; +false+
|
127
148
|
# otherwise.
|
128
149
|
def compare_text lhs, rhs, options = {}
|
data/lib/cmpfs/compare/api_2.rb
CHANGED
@@ -15,6 +15,18 @@ module CmpFS_Compare_Methods
|
|
15
15
|
|
16
16
|
# Compares two files, named by +lhs_path+ and +rhs_path+, in a binary
|
17
17
|
# (exact) manner
|
18
|
+
#
|
19
|
+
# === Signature
|
20
|
+
#
|
21
|
+
# * *Parameters:*
|
22
|
+
# - +lhs_path+:: (+String+) The name of a file
|
23
|
+
# - +rhs_path+:: (+String+) The name of a file
|
24
|
+
# - +options+:: (+Hash+) Options that control the behaviour of the method
|
25
|
+
#
|
26
|
+
# * *Options:*
|
27
|
+
#
|
28
|
+
# === Return
|
29
|
+
# +true+ if the files have exactly the same content; +false+ otherwise.
|
18
30
|
def compare_binary_files lhs_path, rhs_path, **options
|
19
31
|
|
20
32
|
::CmpFS::Compare::Binary::Internal_.compare_binary_files_ lhs_path, rhs_path, options
|
@@ -22,6 +34,19 @@ module CmpFS_Compare_Methods
|
|
22
34
|
|
23
35
|
# Compares two streams, +lhs_stm+ and +rhs_stm+, in a binary
|
24
36
|
# (exact) manner
|
37
|
+
#
|
38
|
+
# === Signature
|
39
|
+
#
|
40
|
+
# * *Parameters:*
|
41
|
+
# - +lhs_stm+:: (stream) A stream object
|
42
|
+
# - +rhs_stm+:: (stream) A stream object
|
43
|
+
# - +options+:: (+Hash+) Options that control the behaviour of the method
|
44
|
+
#
|
45
|
+
# * *Options:*
|
46
|
+
# - +:no_rewind+:: (boolean) Prevents the default behaviour of rewinding each stream before processing
|
47
|
+
#
|
48
|
+
# === Return
|
49
|
+
# +true+ if the streams have exactly the same content; +false+ otherwise.
|
25
50
|
def compare_binary_streams lhs_stm, rhs_stm, **options
|
26
51
|
|
27
52
|
::CmpFS::Compare::Binary::Internal_.compare_binary_streams_ lhs_stm, rhs_stm, options
|
@@ -29,10 +54,17 @@ module CmpFS_Compare_Methods
|
|
29
54
|
|
30
55
|
# Compares two files/streams in a binary (exact) manner
|
31
56
|
#
|
32
|
-
#
|
57
|
+
# === Signature
|
33
58
|
#
|
34
|
-
#
|
59
|
+
# * *Parameters:*
|
60
|
+
# - +lhs+:: (+String+, stream) The name of a file, or a stream object
|
61
|
+
# - +rhs+:: (+String+, stream) The name of a file, or a stream object
|
62
|
+
# - +options+:: (+Hash+) Options that control the behaviour of the method
|
35
63
|
#
|
64
|
+
# * *Options:*
|
65
|
+
# - +:no_rewind+:: (boolean) Prevents the default behaviour of rewinding each stream before processing
|
66
|
+
#
|
67
|
+
# === Return
|
36
68
|
# +true+ if the files/streams have exactly the same content; +false+
|
37
69
|
# otherwise.
|
38
70
|
def compare_binary lhs, rhs, **options
|
@@ -47,18 +79,15 @@ module CmpFS_Compare_Methods
|
|
47
79
|
# === Signature
|
48
80
|
#
|
49
81
|
# * *Parameters:*
|
50
|
-
# - +lhs_path+:: (String) The name of a file
|
51
|
-
# - +rhs_path+:: (String) The name of a file
|
52
|
-
# - +options+:: (Hash) Options
|
82
|
+
# - +lhs_path+:: (+String+) The name of a file
|
83
|
+
# - +rhs_path+:: (+String+) The name of a file
|
84
|
+
# - +options+:: (+Hash+) Options that control the behaviour of the method
|
53
85
|
#
|
54
86
|
# * *Options:*
|
55
|
-
# - +:skip_blank_lines+:: (boolean) Determines whether blank lines
|
56
|
-
#
|
57
|
-
# - +:trim_lines+:: (boolean) Determines whether lines should be
|
58
|
-
# trimmed of leading and trailing space (including EOL sequence)
|
87
|
+
# - +:skip_blank_lines+:: (boolean) Determines whether blank lines should be skipped from the comparison
|
88
|
+
# - +:trim_lines+:: (boolean) Determines whether lines should be trimmed of leading and trailing space (including EOL sequence)
|
59
89
|
#
|
60
90
|
# === Return
|
61
|
-
#
|
62
91
|
# +true+ if the files/streams have exactly the same content; +false+
|
63
92
|
# otherwise.
|
64
93
|
def compare_text_files lhs_path, rhs_path, **options
|
@@ -74,18 +103,14 @@ module CmpFS_Compare_Methods
|
|
74
103
|
# * *Parameters:*
|
75
104
|
# - +lhs_stm+:: (stream) A stream object
|
76
105
|
# - +rhs_stm+:: (stream) A stream object
|
77
|
-
# - +options+:: (Hash) Options
|
106
|
+
# - +options+:: (+Hash+) Options that control the behaviour of the method
|
78
107
|
#
|
79
108
|
# * *Options:*
|
80
|
-
# - +:no_rewind+:: (boolean) Prevents the default behaviour of
|
81
|
-
#
|
82
|
-
# - +:
|
83
|
-
# should be skipped from the comparison
|
84
|
-
# - +:trim_lines+:: (boolean) Determines whether lines should be
|
85
|
-
# trimmed of leading and trailing space (including EOL sequence)
|
109
|
+
# - +:no_rewind+:: (boolean) Prevents the default behaviour of rewinding each stream before processing
|
110
|
+
# - +:skip_blank_lines+:: (boolean) Determines whether blank lines should be skipped from the comparison
|
111
|
+
# - +:trim_lines+:: (boolean) Determines whether lines should be trimmed of leading and trailing space (including EOL sequence)
|
86
112
|
#
|
87
113
|
# === Return
|
88
|
-
#
|
89
114
|
# +true+ if the files/streams have exactly the same content; +false+
|
90
115
|
# otherwise.
|
91
116
|
def compare_text_streams lhs_stm, rhs_stm, **options
|
@@ -99,20 +124,16 @@ module CmpFS_Compare_Methods
|
|
99
124
|
# === Signature
|
100
125
|
#
|
101
126
|
# * *Parameters:*
|
102
|
-
# - +lhs+:: (String
|
103
|
-
# - +rhs+:: (String
|
104
|
-
# - +options+:: (Hash) Options
|
127
|
+
# - +lhs+:: (+String+, stream) The name of a file, or a stream object
|
128
|
+
# - +rhs+:: (+String+, stream) The name of a file, or a stream object
|
129
|
+
# - +options+:: (+Hash+) Options that control the behaviour of the method
|
105
130
|
#
|
106
131
|
# * *Options:*
|
107
|
-
# - +:no_rewind+:: (boolean) Prevents the default behaviour of
|
108
|
-
#
|
109
|
-
# - +:
|
110
|
-
# should be skipped from the comparison
|
111
|
-
# - +:trim_lines+:: (boolean) Determines whether lines should be
|
112
|
-
# trimmed of leading and trailing space (including EOL sequence)
|
132
|
+
# - +:no_rewind+:: (boolean) Prevents the default behaviour of rewinding each stream before processing
|
133
|
+
# - +:skip_blank_lines+:: (boolean) Determines whether blank lines should be skipped from the comparison
|
134
|
+
# - +:trim_lines+:: (boolean) Determines whether lines should be trimmed of leading and trailing space (including EOL sequence)
|
113
135
|
#
|
114
136
|
# === Return
|
115
|
-
#
|
116
137
|
# +true+ if the files/streams have exactly the same content; +false+
|
117
138
|
# otherwise.
|
118
139
|
def compare_text lhs, rhs, **options
|
@@ -38,8 +38,8 @@ module Internal_
|
|
38
38
|
|
39
39
|
def self.compare_binary_ lhs, rhs, options
|
40
40
|
|
41
|
-
lhs_type
|
42
|
-
rhs_type
|
41
|
+
lhs_type = self.determine_param_type_ lhs
|
42
|
+
rhs_type = self.determine_param_type_ rhs
|
43
43
|
|
44
44
|
raise ArgumentError, "lhs is of unsupported type '#{lhs.class}'" unless lhs_type
|
45
45
|
raise ArgumentError, "rhs is of unsupported type '#{rhs.class}'" unless rhs_type
|
@@ -61,19 +61,19 @@ module Internal_
|
|
61
61
|
|
62
62
|
if :path == rhs_type
|
63
63
|
|
64
|
-
|
64
|
+
File.open(rhs, 'rb') do |rhs_f|
|
65
65
|
|
66
|
-
|
67
|
-
|
66
|
+
return self.compare_binary_streams_ lhs, rhs_f, options
|
67
|
+
end
|
68
68
|
end
|
69
69
|
when :path
|
70
70
|
|
71
71
|
if :path == lhs_type
|
72
72
|
|
73
|
-
|
73
|
+
File.open(lhs, 'rb') do |lhs_f|
|
74
74
|
|
75
|
-
|
76
|
-
|
75
|
+
return self.compare_binary_streams_ lhs_f, rhs, options
|
76
|
+
end
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -28,10 +28,10 @@ module Internal_
|
|
28
28
|
|
29
29
|
def self.next_line_or_nil_ en, options
|
30
30
|
|
31
|
-
skipping_blanks
|
32
|
-
trimming_lines
|
31
|
+
skipping_blanks = options[:skip_blank_lines]
|
32
|
+
trimming_lines = options[:trim_lines]
|
33
33
|
|
34
|
-
num_read
|
34
|
+
num_read = 0
|
35
35
|
|
36
36
|
begin
|
37
37
|
|
@@ -45,7 +45,7 @@ module Internal_
|
|
45
45
|
|
46
46
|
if line.empty? && skipping_blanks
|
47
47
|
|
48
|
-
|
48
|
+
next
|
49
49
|
end
|
50
50
|
|
51
51
|
return [ line, num_read ]
|
@@ -70,8 +70,8 @@ module Internal_
|
|
70
70
|
|
71
71
|
def self.compare_text_streams_ lhs_stm, rhs_stm, options
|
72
72
|
|
73
|
-
lhs_en
|
74
|
-
rhs_en
|
73
|
+
lhs_en = lhs_stm.each_line
|
74
|
+
rhs_en = rhs_stm.each_line
|
75
75
|
|
76
76
|
unless options[:no_rewind]
|
77
77
|
|
@@ -79,13 +79,13 @@ module Internal_
|
|
79
79
|
rhs_en.rewind if rhs_stm.respond_to?(:rewind)
|
80
80
|
end
|
81
81
|
|
82
|
-
lhs_ix
|
83
|
-
rhs_ix
|
82
|
+
lhs_ix = 0
|
83
|
+
rhs_ix = 0
|
84
84
|
|
85
85
|
loop do
|
86
86
|
|
87
|
-
lhs_ln, lhs_nr
|
88
|
-
rhs_ln, rhs_nr
|
87
|
+
lhs_ln, lhs_nr = self.next_line_or_nil_ lhs_en, options
|
88
|
+
rhs_ln, rhs_nr = self.next_line_or_nil_ rhs_en, options
|
89
89
|
|
90
90
|
if lhs_ln != rhs_ln
|
91
91
|
|
@@ -101,8 +101,8 @@ module Internal_
|
|
101
101
|
|
102
102
|
def self.compare_text_ lhs, rhs, options
|
103
103
|
|
104
|
-
lhs_type
|
105
|
-
rhs_type
|
104
|
+
lhs_type = self.determine_param_type_ lhs
|
105
|
+
rhs_type = self.determine_param_type_ rhs
|
106
106
|
|
107
107
|
raise ArgumentError, "lhs is of unsupported type '#{lhs.class}'" unless lhs_type
|
108
108
|
raise ArgumentError, "rhs is of unsupported type '#{rhs.class}'" unless rhs_type
|
@@ -124,19 +124,19 @@ module Internal_
|
|
124
124
|
|
125
125
|
if :path == rhs_type
|
126
126
|
|
127
|
-
|
127
|
+
File.open(rhs, 'r') do |rhs_f|
|
128
128
|
|
129
|
-
|
130
|
-
|
129
|
+
return self.compare_text_streams_ lhs, rhs_f, options
|
130
|
+
end
|
131
131
|
end
|
132
132
|
when :path
|
133
133
|
|
134
134
|
if :path == lhs_type
|
135
135
|
|
136
|
-
|
136
|
+
File.open(lhs, 'r') do |lhs_f|
|
137
137
|
|
138
|
-
|
139
|
-
|
138
|
+
return self.compare_text_streams_ lhs_f, rhs, options
|
139
|
+
end
|
140
140
|
end
|
141
141
|
end
|
142
142
|
end
|
data/lib/cmpfs/version.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# Purpose: Version for cmpfs.Ruby library
|
6
6
|
#
|
7
7
|
# Created: 1st March 2019
|
8
|
-
# Updated:
|
8
|
+
# Updated: 2nd April 2024
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/cmpfs.Ruby
|
11
11
|
#
|
@@ -51,7 +51,7 @@
|
|
51
51
|
module CmpFS
|
52
52
|
|
53
53
|
# Current version of the cmpfs.Ruby library
|
54
|
-
VERSION = '0.2.1.
|
54
|
+
VERSION = '0.2.1.2'
|
55
55
|
|
56
56
|
private
|
57
57
|
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
data/lib/cmpfs.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
|
2
2
|
# ######################################################################## #
|
3
|
-
# File:
|
3
|
+
# File: cmpfs.rb
|
4
4
|
#
|
5
|
-
# Purpose:
|
5
|
+
# Purpose: Primary require for cmpfs.Ruby library
|
6
6
|
#
|
7
|
-
# Created:
|
8
|
-
# Updated:
|
7
|
+
# Created: 1st March 2019
|
8
|
+
# Updated: 2nd April 2024
|
9
9
|
#
|
10
|
-
# Home:
|
10
|
+
# Home: http://github.com/synesissoftware/cmpfs.Ruby
|
11
11
|
#
|
12
|
-
# Author:
|
12
|
+
# Author: Matthew Wilson
|
13
13
|
#
|
14
14
|
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
15
15
|
# Copyright (c) 2019, Matthew Wilson and Synesis Software
|
@@ -15,12 +15,12 @@ class Test_CmpFS_Compare_compare_binary < Test::Unit::TestCase
|
|
15
15
|
|
16
16
|
def test__compare_binary__identical_1
|
17
17
|
|
18
|
-
lhs
|
19
|
-
rhs_eq
|
18
|
+
lhs = StringIO.new 'abcdefghijiklmno'
|
19
|
+
rhs_eq = StringIO.new 'abcdefghijiklmno'
|
20
20
|
|
21
21
|
assert CmpFS::Compare.compare_binary(lhs, rhs_eq), 'streams should be the same'
|
22
22
|
|
23
|
-
rhs_ne
|
23
|
+
rhs_ne = StringIO.new 'abcdefghijiklmn'
|
24
24
|
|
25
25
|
assert_false CmpFS::Compare.compare_binary(lhs, rhs_ne), 'streams should not be the same'
|
26
26
|
end
|
@@ -36,11 +36,11 @@ class Test_CmpFS_Compare_compare_binary < Test::Unit::TestCase
|
|
36
36
|
lhs_f.rewind
|
37
37
|
lhs_f.close
|
38
38
|
|
39
|
-
rhs_eq
|
39
|
+
rhs_eq = StringIO.new 'abcdefghijiklmno'
|
40
40
|
|
41
41
|
assert CmpFS::Compare.compare_binary(lhs_f.path, rhs_eq), 'streams should be the same'
|
42
42
|
|
43
|
-
rhs_ne
|
43
|
+
rhs_ne = StringIO.new 'abcdefghijiklmnop'
|
44
44
|
|
45
45
|
assert_false CmpFS::Compare.compare_binary(lhs_f.path, rhs_ne), 'streams should not be the same'
|
46
46
|
ensure
|
data/test/unit/compare/ts_all.rb
CHANGED
@@ -17,12 +17,12 @@ class Test_CmpFS_compare_binary < Test::Unit::TestCase
|
|
17
17
|
|
18
18
|
def test__compare_binary__identical_1
|
19
19
|
|
20
|
-
lhs
|
21
|
-
rhs_eq
|
20
|
+
lhs = StringIO.new 'abcdefghijiklmno'
|
21
|
+
rhs_eq = StringIO.new 'abcdefghijiklmno'
|
22
22
|
|
23
23
|
assert compare_binary(lhs, rhs_eq), 'streams should be the same'
|
24
24
|
|
25
|
-
rhs_ne
|
25
|
+
rhs_ne = StringIO.new 'abcdefghijiklmn'
|
26
26
|
|
27
27
|
assert_false compare_binary(lhs, rhs_ne), 'streams should not be the same'
|
28
28
|
end
|
@@ -38,11 +38,11 @@ class Test_CmpFS_compare_binary < Test::Unit::TestCase
|
|
38
38
|
lhs_f.rewind
|
39
39
|
lhs_f.close
|
40
40
|
|
41
|
-
rhs_eq
|
41
|
+
rhs_eq = StringIO.new 'abcdefghijiklmno'
|
42
42
|
|
43
43
|
assert compare_binary(lhs_f.path, rhs_eq), 'streams should be the same'
|
44
44
|
|
45
|
-
rhs_ne
|
45
|
+
rhs_ne = StringIO.new 'abcdefghijiklmnop'
|
46
46
|
|
47
47
|
assert_false compare_binary(lhs_f.path, rhs_ne), 'streams should not be the same'
|
48
48
|
ensure
|
@@ -17,19 +17,19 @@ class Test_CmpFS_compare_text < Test::Unit::TestCase
|
|
17
17
|
|
18
18
|
def test__compare_text__empty
|
19
19
|
|
20
|
-
lhs
|
21
|
-
rhs_eq
|
20
|
+
lhs = StringIO.new
|
21
|
+
rhs_eq = StringIO.new
|
22
22
|
|
23
23
|
assert compare_text(lhs, rhs_eq), 'streams should be the same'
|
24
24
|
end
|
25
25
|
|
26
26
|
def test__compare_text__blank_lines
|
27
27
|
|
28
|
-
lhs
|
28
|
+
lhs = StringIO.new <<END_OF_INPUT
|
29
29
|
|
30
30
|
|
31
31
|
END_OF_INPUT
|
32
|
-
rhs_eq
|
32
|
+
rhs_eq = StringIO.new <<END_OF_INPUT
|
33
33
|
|
34
34
|
|
35
35
|
END_OF_INPUT
|
@@ -39,12 +39,12 @@ END_OF_INPUT
|
|
39
39
|
|
40
40
|
def test__compare_text__identical_lines_1
|
41
41
|
|
42
|
-
lhs
|
42
|
+
lhs = StringIO.new <<END_OF_INPUT
|
43
43
|
line-1
|
44
44
|
line-2
|
45
45
|
|
46
46
|
END_OF_INPUT
|
47
|
-
rhs_eq
|
47
|
+
rhs_eq = StringIO.new <<END_OF_INPUT
|
48
48
|
line-1
|
49
49
|
line-2
|
50
50
|
|
@@ -55,12 +55,12 @@ END_OF_INPUT
|
|
55
55
|
|
56
56
|
def test__compare_text__different_lines_1
|
57
57
|
|
58
|
-
lhs
|
58
|
+
lhs = StringIO.new <<END_OF_INPUT
|
59
59
|
line-1
|
60
60
|
line-2
|
61
61
|
|
62
62
|
END_OF_INPUT
|
63
|
-
rhs_ne
|
63
|
+
rhs_ne = StringIO.new <<END_OF_INPUT
|
64
64
|
line-1
|
65
65
|
line2
|
66
66
|
|
@@ -71,12 +71,12 @@ END_OF_INPUT
|
|
71
71
|
|
72
72
|
def test__compare_text__different_lines_2
|
73
73
|
|
74
|
-
lhs
|
74
|
+
lhs = StringIO.new <<END_OF_INPUT
|
75
75
|
line-1
|
76
76
|
|
77
77
|
line-2
|
78
78
|
END_OF_INPUT
|
79
|
-
rhs_ne
|
79
|
+
rhs_ne = StringIO.new <<END_OF_INPUT
|
80
80
|
line-1
|
81
81
|
line-2
|
82
82
|
|
@@ -87,12 +87,12 @@ END_OF_INPUT
|
|
87
87
|
|
88
88
|
def test__compare_text__different_streams_with_permutations_of_trim_and_skip_1
|
89
89
|
|
90
|
-
lhs
|
90
|
+
lhs = StringIO.new <<END_OF_INPUT
|
91
91
|
line-1
|
92
92
|
|
93
93
|
line-2
|
94
94
|
END_OF_INPUT
|
95
|
-
rhs_eq
|
95
|
+
rhs_eq = StringIO.new <<END_OF_INPUT
|
96
96
|
line-1
|
97
97
|
line-2
|
98
98
|
END_OF_INPUT
|
@@ -102,7 +102,7 @@ END_OF_INPUT
|
|
102
102
|
assert_false compare_text(lhs, rhs_eq, trim_lines: true, skip_blank_lines: false), 'streams should not be the same'
|
103
103
|
assert compare_text(lhs, rhs_eq, trim_lines: true, skip_blank_lines: true), 'streams should be the same'
|
104
104
|
|
105
|
-
rhs_ne
|
105
|
+
rhs_ne = StringIO.new <<END_OF_INPUT
|
106
106
|
line-1
|
107
107
|
line2
|
108
108
|
END_OF_INPUT
|
data/test/unit/ts_all.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cmpfs-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.1.
|
4
|
+
version: 0.2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Wilson
|
@@ -41,6 +41,8 @@ extra_rdoc_files: []
|
|
41
41
|
files:
|
42
42
|
- LICENSE
|
43
43
|
- README.md
|
44
|
+
- examples/compare_two_binary_files.rb
|
45
|
+
- examples/compare_two_text_files.rb
|
44
46
|
- lib/cmpfs.rb
|
45
47
|
- lib/cmpfs/compare.rb
|
46
48
|
- lib/cmpfs/compare/api_1_9.rb
|