cmpfs-ruby 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +31 -0
- data/README.md +47 -0
- data/lib/cmpfs.rb +77 -0
- data/lib/cmpfs/compare.rb +104 -0
- data/lib/cmpfs/compare/api_1_9.rb +139 -0
- data/lib/cmpfs/compare/api_2.rb +127 -0
- data/lib/cmpfs/compare/binary/internal_.rb +96 -0
- data/lib/cmpfs/compare/text/internal_.rb +159 -0
- data/lib/cmpfs/version.rb +71 -0
- data/test/unit/compare/tc_compare_binary.rb +103 -0
- data/test/unit/compare/ts_all.rb +12 -0
- data/test/unit/tc_compare_binary.rb +107 -0
- data/test/unit/tc_compare_text.rb +65 -0
- data/test/unit/tc_version.rb +37 -0
- data/test/unit/ts_all.rb +12 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7a5d807fbdecc4dcd49ac7cdda8b3de14cfa1249
|
4
|
+
data.tar.gz: 19ad4d748a6811d1dca9a4974ec4962fbf7477a1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b8764ee5e224d4be12e69e73086bb576aa211e6cf02d4c98a230e46c75e98c37ca4bdafb739ca07ffa43d3756633650c5a79833774a284d2d8632be64e0355ad
|
7
|
+
data.tar.gz: 8bddd4fa549ed5c977c0fbeb4d564be20fc394be832ad37c0c2c9e2226cb8df04cbdf35742c7f75a48751ffbd365b7d65e0d8bfc0947b0c23367d0e4745256d8
|
data/LICENSE
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
cmpfs.Ruby
|
2
|
+
|
3
|
+
Copyright (c) 2019, Matthew Wilson and Synesis Software
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
* Redistributions of source code must retain the above copyright notice, this
|
10
|
+
list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
14
|
+
and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
* Neither the names of cmpfs or cmpfs.Ruby nor the names of the copyright
|
17
|
+
holder nor the names of its contributors may be used to endorse or promote
|
18
|
+
products derived from this software without specific prior written
|
19
|
+
permission.
|
20
|
+
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
22
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
23
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
24
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
25
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
26
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
27
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
29
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# cmpfs.Ruby
|
2
|
+
**Com**pare **F**ile-**S**ystem entities, for **Ruby**
|
3
|
+
|
4
|
+
## Introduction
|
5
|
+
|
6
|
+
T.B.C.
|
7
|
+
|
8
|
+
## Table of Contents
|
9
|
+
|
10
|
+
1. [Introduction](#introduction)
|
11
|
+
2. [Installation](#installation)
|
12
|
+
3. [Components](#components)
|
13
|
+
4. [Examples](#examples)
|
14
|
+
5. [Project Information](#project-information)
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Install using `gem install cmpfs-ruby` or add it to your `Gemfile`.
|
19
|
+
|
20
|
+
## Components
|
21
|
+
|
22
|
+
T.B.C.
|
23
|
+
|
24
|
+
## Examples
|
25
|
+
|
26
|
+
T.B.C.
|
27
|
+
|
28
|
+
## Project Information
|
29
|
+
|
30
|
+
### Where to get help
|
31
|
+
|
32
|
+
[GitHub Page](https://github.com/synesissoftware/cmpfs.Ruby "GitHub Page")
|
33
|
+
|
34
|
+
### Contribution guidelines
|
35
|
+
|
36
|
+
Defect reports, feature requests, and pull requests are welcome on https://github.com/synesissoftware/cmpfs.Ruby.
|
37
|
+
|
38
|
+
### Dependencies
|
39
|
+
|
40
|
+
### Related projects
|
41
|
+
|
42
|
+
T.B.C.
|
43
|
+
|
44
|
+
### License
|
45
|
+
|
46
|
+
**cmpfs.Gp** is released under the 3-clause BSD license. See [LICENSE](./LICENSE) for details.
|
47
|
+
|
data/lib/cmpfs.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
|
2
|
+
# ######################################################################## #
|
3
|
+
# File: cmpfs.rb
|
4
|
+
#
|
5
|
+
# Purpose: Primary require for cmpfs.Ruby library
|
6
|
+
#
|
7
|
+
# Created: 1st March 2019
|
8
|
+
# Updated: 13th March 2019
|
9
|
+
#
|
10
|
+
# Home: http://github.com/synesissoftware/cmpfs.Ruby
|
11
|
+
#
|
12
|
+
# Author: Matthew Wilson
|
13
|
+
#
|
14
|
+
# Copyright (c) 2019, Matthew Wilson and Synesis Software
|
15
|
+
# All rights reserved.
|
16
|
+
#
|
17
|
+
# Redistribution and use in source and binary forms, with or without
|
18
|
+
# modification, are permitted provided that the following conditions are
|
19
|
+
# met:
|
20
|
+
#
|
21
|
+
# * Redistributions of source code must retain the above copyright
|
22
|
+
# notice, this list of conditions and the following disclaimer.
|
23
|
+
#
|
24
|
+
# * Redistributions in binary form must reproduce the above copyright
|
25
|
+
# notice, this list of conditions and the following disclaimer in the
|
26
|
+
# documentation and/or other materials provided with the distribution.
|
27
|
+
#
|
28
|
+
# * Neither the names of the copyright holder nor the names of its
|
29
|
+
# contributors may be used to endorse or promote products derived from
|
30
|
+
# this software without specific prior written permission.
|
31
|
+
#
|
32
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
33
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
34
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
35
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
36
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
37
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
38
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
39
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
40
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
41
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
42
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
43
|
+
#
|
44
|
+
# ######################################################################## #
|
45
|
+
|
46
|
+
|
47
|
+
=begin
|
48
|
+
=end
|
49
|
+
|
50
|
+
require 'cmpfs/compare'
|
51
|
+
require 'cmpfs/version'
|
52
|
+
|
53
|
+
## Root module for *cmpfs*
|
54
|
+
module CmpFS
|
55
|
+
|
56
|
+
def self.extended receiver
|
57
|
+
|
58
|
+
receiver.class_eval do
|
59
|
+
|
60
|
+
extend CmpFS::Compare
|
61
|
+
end
|
62
|
+
|
63
|
+
$stderr.puts "#{receiver} extended by #{CmpFS}" if $DEBUG
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.included receiver
|
67
|
+
|
68
|
+
receiver.class_eval do
|
69
|
+
|
70
|
+
include CmpFS::Compare
|
71
|
+
end
|
72
|
+
|
73
|
+
$stderr.puts "#{receiver} included #{CmpFS}" if $DEBUG
|
74
|
+
end
|
75
|
+
|
76
|
+
end # module CmpFS
|
77
|
+
|
@@ -0,0 +1,104 @@
|
|
1
|
+
|
2
|
+
# ######################################################################## #
|
3
|
+
# File: cmpfs/version.rb
|
4
|
+
#
|
5
|
+
# Purpose: Version for cmpfs.Ruby library
|
6
|
+
#
|
7
|
+
# Created: 1st March 2019
|
8
|
+
# Updated: 13th March 2019
|
9
|
+
#
|
10
|
+
# Home: http://github.com/synesissoftware/cmpfs.Ruby
|
11
|
+
#
|
12
|
+
# Author: Matthew Wilson
|
13
|
+
#
|
14
|
+
# Copyright (c) 2019, Matthew Wilson and Synesis Software
|
15
|
+
# All rights reserved.
|
16
|
+
#
|
17
|
+
# Redistribution and use in source and binary forms, with or without
|
18
|
+
# modification, are permitted provided that the following conditions are
|
19
|
+
# met:
|
20
|
+
#
|
21
|
+
# * Redistributions of source code must retain the above copyright
|
22
|
+
# notice, this list of conditions and the following disclaimer.
|
23
|
+
#
|
24
|
+
# * Redistributions in binary form must reproduce the above copyright
|
25
|
+
# notice, this list of conditions and the following disclaimer in the
|
26
|
+
# documentation and/or other materials provided with the distribution.
|
27
|
+
#
|
28
|
+
# * Neither the names of the copyright holder nor the names of its
|
29
|
+
# contributors may be used to endorse or promote products derived from
|
30
|
+
# this software without specific prior written permission.
|
31
|
+
#
|
32
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
33
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
34
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
35
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
36
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
37
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
38
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
39
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
40
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
41
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
42
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
43
|
+
#
|
44
|
+
# ######################################################################## #
|
45
|
+
|
46
|
+
|
47
|
+
if RUBY_VERSION >= '2'
|
48
|
+
|
49
|
+
require 'cmpfs/compare/api_2'
|
50
|
+
else
|
51
|
+
|
52
|
+
require 'cmpfs/compare/api_1_9'
|
53
|
+
end
|
54
|
+
|
55
|
+
=begin
|
56
|
+
=end
|
57
|
+
|
58
|
+
module CmpFS
|
59
|
+
|
60
|
+
# The comparison module, which may be used directly, and which may be
|
61
|
+
# extended or included
|
62
|
+
#
|
63
|
+
# Important functions:
|
64
|
+
#
|
65
|
+
# - +CmpFS::Compare.compare_binary_files()+
|
66
|
+
# - +CmpFS::Compare.compare_binary_streams()+
|
67
|
+
# - +CmpFS::Compare.compare_binary()+
|
68
|
+
#
|
69
|
+
# - +CmpFS::Compare.compare_text_files()+
|
70
|
+
# - +CmpFS::Compare.compare_text_streams()+
|
71
|
+
# - +CmpFS::Compare.compare_text()+
|
72
|
+
#
|
73
|
+
#
|
74
|
+
module Compare
|
75
|
+
|
76
|
+
def self.extended receiver
|
77
|
+
|
78
|
+
receiver.class_eval do
|
79
|
+
|
80
|
+
extend CmpFS_Compare_Methods
|
81
|
+
end
|
82
|
+
|
83
|
+
$stderr.puts "#{receiver} extended by #{CmpFS_Compare_Methods}" if $DEBUG
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.included receiver
|
87
|
+
|
88
|
+
receiver.class_eval do
|
89
|
+
|
90
|
+
include CmpFS_Compare_Methods
|
91
|
+
end
|
92
|
+
|
93
|
+
$stderr.puts "#{receiver} included #{CmpFS_Compare_Methods}" if $DEBUG
|
94
|
+
end
|
95
|
+
|
96
|
+
extend CmpFS_Compare_Methods
|
97
|
+
include CmpFS_Compare_Methods
|
98
|
+
|
99
|
+
end # module Compare
|
100
|
+
end # module CmpFS
|
101
|
+
|
102
|
+
# ############################## end of file ############################# #
|
103
|
+
|
104
|
+
|
@@ -0,0 +1,139 @@
|
|
1
|
+
|
2
|
+
if RUBY_VERSION >= '2'
|
3
|
+
|
4
|
+
abort "This file required Ruby 1+: RUBY_VERSION='#{RUBY_VERSION}'"
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'cmpfs/compare/binary/internal_'
|
8
|
+
require 'cmpfs/compare/text/internal_'
|
9
|
+
|
10
|
+
module CmpFS
|
11
|
+
module Compare
|
12
|
+
|
13
|
+
module CmpFS_Compare_Methods
|
14
|
+
|
15
|
+
# Compares two files, named by +lhs_path+ and +rhs_path+, in a binary
|
16
|
+
# (exact) manner
|
17
|
+
def compare_binary_files lhs_path, rhs_path, options = {}
|
18
|
+
|
19
|
+
options ||= {}
|
20
|
+
|
21
|
+
::CmpFS::Compare::Binary::Internal_.compare_binary_files_ lhs_path, rhs_path, options
|
22
|
+
end
|
23
|
+
|
24
|
+
# Compares two streams, +lhs_stm+ and +rhs_stm+, in a binary
|
25
|
+
# (exact) manner
|
26
|
+
def compare_binary_streams lhs_stm, rhs_stm, options = {}
|
27
|
+
|
28
|
+
options ||= {}
|
29
|
+
|
30
|
+
::CmpFS::Compare::Binary::Internal_.compare_binary_streams_ lhs_stm, rhs_stm, options
|
31
|
+
end
|
32
|
+
|
33
|
+
# Compares two files/streams in a binary (exact) manner
|
34
|
+
#
|
35
|
+
# == Signature
|
36
|
+
#
|
37
|
+
# == Return
|
38
|
+
#
|
39
|
+
# +true+ if the files/streams have exactly the same content; +false+
|
40
|
+
# otherwise.
|
41
|
+
def compare_binary lhs, rhs, options = {}
|
42
|
+
|
43
|
+
options ||= {}
|
44
|
+
|
45
|
+
::CmpFS::Compare::Binary::Internal_.compare_binary_ lhs, rhs, options
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
# Compares two files, named by +lhs_path+ and +rhs_path+, in a textual
|
50
|
+
# manner according to the given +options+
|
51
|
+
#
|
52
|
+
# === Signature
|
53
|
+
#
|
54
|
+
# * *Parameters:*
|
55
|
+
# - +lhs_path+:: (String) The name of a file
|
56
|
+
# - +rhs_path+:: (String) The name of a file
|
57
|
+
# - +options+:: (Hash) Options
|
58
|
+
#
|
59
|
+
# * *Options:*
|
60
|
+
# - +:skip_blank_lines+:: (boolean) Determines whether blank lines
|
61
|
+
# should be skipped from the comparison
|
62
|
+
# - +:trim_lines+:: (boolean) Determines whether lines should be
|
63
|
+
# trimmed of leading and trailing space (including EOL sequence)
|
64
|
+
#
|
65
|
+
# === Return
|
66
|
+
#
|
67
|
+
# +true+ if the files/streams have exactly the same content; +false+
|
68
|
+
# otherwise.
|
69
|
+
def compare_text_files lhs_path, rhs_path, options = {}
|
70
|
+
|
71
|
+
options |= {}
|
72
|
+
|
73
|
+
::CmpFS::Compare::Text::Internal_.compare_text_files_ lhs_path, rhs_path, options
|
74
|
+
end
|
75
|
+
|
76
|
+
# Compares two streams, named by +lhs_stm+ and +rhs_stm+, in a textual
|
77
|
+
# manner according to the given +options+
|
78
|
+
#
|
79
|
+
# === Signature
|
80
|
+
#
|
81
|
+
# * *Parameters:*
|
82
|
+
# - +lhs_stm+:: (stream) A stream object
|
83
|
+
# - +rhs_stm+:: (stream) A stream object
|
84
|
+
# - +options+:: (Hash) Options
|
85
|
+
#
|
86
|
+
# * *Options:*
|
87
|
+
# - +:no_rewind+:: (boolean) Prevents the default behaviour of
|
88
|
+
# rewinding the stream before processing
|
89
|
+
# - +:skip_blank_lines+:: (boolean) Determines whether blank lines
|
90
|
+
# should be skipped from the comparison
|
91
|
+
# - +:trim_lines+:: (boolean) Determines whether lines should be
|
92
|
+
# trimmed of leading and trailing space (including EOL sequence)
|
93
|
+
#
|
94
|
+
# === Return
|
95
|
+
#
|
96
|
+
# +true+ if the files/streams have exactly the same content; +false+
|
97
|
+
# otherwise.
|
98
|
+
def compare_text_streams lhs_stm, rhs_stm, options = {}
|
99
|
+
|
100
|
+
options ||= {}
|
101
|
+
|
102
|
+
::CmpFS::Compare::Text::Internal_.compare_text_streams_ lhs_stm, rhs_stm, options
|
103
|
+
end
|
104
|
+
|
105
|
+
# Compares two files/streams, named by +lhs+ and +rhs+, in a textual
|
106
|
+
# manner according to the given +options+
|
107
|
+
#
|
108
|
+
# === Signature
|
109
|
+
#
|
110
|
+
# * *Parameters:*
|
111
|
+
# - +lhs+:: (String, stream) The name of a file, or a stream object
|
112
|
+
# - +rhs+:: (String, stream) The name of a file, or a stream object
|
113
|
+
# - +options+:: (Hash) Options
|
114
|
+
#
|
115
|
+
# * *Options:*
|
116
|
+
# - +:no_rewind+:: (boolean) Prevents the default behaviour of
|
117
|
+
# rewinding the stream before processing
|
118
|
+
# - +:skip_blank_lines+:: (boolean) Determines whether blank lines
|
119
|
+
# should be skipped from the comparison
|
120
|
+
# - +:trim_lines+:: (boolean) Determines whether lines should be
|
121
|
+
# trimmed of leading and trailing space (including EOL sequence)
|
122
|
+
#
|
123
|
+
# === Return
|
124
|
+
#
|
125
|
+
# +true+ if the files/streams have exactly the same content; +false+
|
126
|
+
# otherwise.
|
127
|
+
def compare_text lhs, rhs, options = {}
|
128
|
+
|
129
|
+
options ||= {}
|
130
|
+
|
131
|
+
::CmpFS::Compare::Text::Internal_.compare_text_ lhs, rhs, options
|
132
|
+
end
|
133
|
+
end # module CmpFS_Compare_Methods
|
134
|
+
end # module Compare
|
135
|
+
end # module CmpFS
|
136
|
+
|
137
|
+
# ############################## end of file ############################# #
|
138
|
+
|
139
|
+
|
@@ -0,0 +1,127 @@
|
|
1
|
+
|
2
|
+
unless RUBY_VERSION >= '2'
|
3
|
+
|
4
|
+
abort "This file required Ruby 2+: RUBY_VERSION='#{RUBY_VERSION}'"
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'cmpfs/compare/binary/internal_'
|
8
|
+
require 'cmpfs/compare/text/internal_'
|
9
|
+
|
10
|
+
module CmpFS
|
11
|
+
module Compare
|
12
|
+
|
13
|
+
module CmpFS_Compare_Methods
|
14
|
+
|
15
|
+
# Compares two files, named by +lhs_path+ and +rhs_path+, in a binary
|
16
|
+
# (exact) manner
|
17
|
+
def compare_binary_files lhs_path, rhs_path, **options
|
18
|
+
|
19
|
+
::CmpFS::Compare::Binary::Internal_.compare_binary_files_ lhs_path, rhs_path, options
|
20
|
+
end
|
21
|
+
|
22
|
+
# Compares two streams, +lhs_stm+ and +rhs_stm+, in a binary
|
23
|
+
# (exact) manner
|
24
|
+
def compare_binary_streams lhs_stm, rhs_stm, **options
|
25
|
+
|
26
|
+
::CmpFS::Compare::Binary::Internal_.compare_binary_streams_ lhs_stm, rhs_stm, options
|
27
|
+
end
|
28
|
+
|
29
|
+
# Compares two files/streams in a binary (exact) manner
|
30
|
+
#
|
31
|
+
# == Signature
|
32
|
+
#
|
33
|
+
# == Return
|
34
|
+
#
|
35
|
+
# +true+ if the files/streams have exactly the same content; +false+
|
36
|
+
# otherwise.
|
37
|
+
def compare_binary lhs, rhs, **options
|
38
|
+
|
39
|
+
::CmpFS::Compare::Binary::Internal_.compare_binary_ lhs, rhs, options
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
# Compares two files, named by +lhs_path+ and +rhs_path+, in a textual
|
44
|
+
# manner according to the given +options+
|
45
|
+
#
|
46
|
+
# === Signature
|
47
|
+
#
|
48
|
+
# * *Parameters:*
|
49
|
+
# - +lhs_path+:: (String) The name of a file
|
50
|
+
# - +rhs_path+:: (String) The name of a file
|
51
|
+
# - +options+:: (Hash) Options
|
52
|
+
#
|
53
|
+
# * *Options:*
|
54
|
+
# - +:skip_blank_lines+:: (boolean) Determines whether blank lines
|
55
|
+
# should be skipped from the comparison
|
56
|
+
# - +:trim_lines+:: (boolean) Determines whether lines should be
|
57
|
+
# trimmed of leading and trailing space (including EOL sequence)
|
58
|
+
#
|
59
|
+
# === Return
|
60
|
+
#
|
61
|
+
# +true+ if the files/streams have exactly the same content; +false+
|
62
|
+
# otherwise.
|
63
|
+
def compare_text_files lhs_path, rhs_path, **options
|
64
|
+
|
65
|
+
::CmpFS::Compare::Text::Internal_.compare_text_files_ lhs_path, rhs_path, options
|
66
|
+
end
|
67
|
+
|
68
|
+
# Compares two streams, named by +lhs_stm+ and +rhs_stm+, in a textual
|
69
|
+
# manner according to the given +options+
|
70
|
+
#
|
71
|
+
# === Signature
|
72
|
+
#
|
73
|
+
# * *Parameters:*
|
74
|
+
# - +lhs_stm+:: (stream) A stream object
|
75
|
+
# - +rhs_stm+:: (stream) A stream object
|
76
|
+
# - +options+:: (Hash) Options
|
77
|
+
#
|
78
|
+
# * *Options:*
|
79
|
+
# - +:no_rewind+:: (boolean) Prevents the default behaviour of
|
80
|
+
# rewinding the stream before processing
|
81
|
+
# - +:skip_blank_lines+:: (boolean) Determines whether blank lines
|
82
|
+
# should be skipped from the comparison
|
83
|
+
# - +:trim_lines+:: (boolean) Determines whether lines should be
|
84
|
+
# trimmed of leading and trailing space (including EOL sequence)
|
85
|
+
#
|
86
|
+
# === Return
|
87
|
+
#
|
88
|
+
# +true+ if the files/streams have exactly the same content; +false+
|
89
|
+
# otherwise.
|
90
|
+
def compare_text_streams lhs_stm, rhs_stm, **options
|
91
|
+
|
92
|
+
::CmpFS::Compare::Text::Internal_.compare_text_streams_ lhs_stm, rhs_stm, options
|
93
|
+
end
|
94
|
+
|
95
|
+
# Compares two files/streams, named by +lhs+ and +rhs+, in a textual
|
96
|
+
# manner according to the given +options+
|
97
|
+
#
|
98
|
+
# === Signature
|
99
|
+
#
|
100
|
+
# * *Parameters:*
|
101
|
+
# - +lhs+:: (String, stream) The name of a file, or a stream object
|
102
|
+
# - +rhs+:: (String, stream) The name of a file, or a stream object
|
103
|
+
# - +options+:: (Hash) Options
|
104
|
+
#
|
105
|
+
# * *Options:*
|
106
|
+
# - +:no_rewind+:: (boolean) Prevents the default behaviour of
|
107
|
+
# rewinding the stream before processing
|
108
|
+
# - +:skip_blank_lines+:: (boolean) Determines whether blank lines
|
109
|
+
# should be skipped from the comparison
|
110
|
+
# - +:trim_lines+:: (boolean) Determines whether lines should be
|
111
|
+
# trimmed of leading and trailing space (including EOL sequence)
|
112
|
+
#
|
113
|
+
# === Return
|
114
|
+
#
|
115
|
+
# +true+ if the files/streams have exactly the same content; +false+
|
116
|
+
# otherwise.
|
117
|
+
def compare_text lhs, rhs, **options
|
118
|
+
|
119
|
+
::CmpFS::Compare::Text::Internal_.compare_text_ lhs, rhs, options
|
120
|
+
end
|
121
|
+
end # module CmpFS_Compare_Methods
|
122
|
+
end # module Compare
|
123
|
+
end # module CmpFS
|
124
|
+
|
125
|
+
# ############################## end of file ############################# #
|
126
|
+
|
127
|
+
|
@@ -0,0 +1,96 @@
|
|
1
|
+
|
2
|
+
#require 'xqsr3'
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
require 'stringio'
|
6
|
+
|
7
|
+
module CmpFS
|
8
|
+
module Compare
|
9
|
+
module Binary
|
10
|
+
|
11
|
+
module Internal_
|
12
|
+
|
13
|
+
def self.determine_param_type_ p
|
14
|
+
|
15
|
+
case p
|
16
|
+
when ::IO, ::StringIO
|
17
|
+
|
18
|
+
return :io
|
19
|
+
when ::String
|
20
|
+
|
21
|
+
return :path
|
22
|
+
else
|
23
|
+
|
24
|
+
return :path if p.respond_to?(:to_str)
|
25
|
+
|
26
|
+
return nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.compare_binary_files_ lhs_path, rhs_path, options
|
31
|
+
|
32
|
+
FileUtils.compare_file lhs_path, rhs_path
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.compare_binary_streams_ lhs_stm, rhs_stm, options
|
36
|
+
|
37
|
+
FileUtils.compare_stream lhs_stm, rhs_stm
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.compare_binary_ lhs, rhs, options
|
41
|
+
|
42
|
+
|
43
|
+
lhs_type = self.determine_param_type_ lhs
|
44
|
+
rhs_type = self.determine_param_type_ rhs
|
45
|
+
|
46
|
+
raise ArgumentError, "lhs is of unsupported type '#{lhs.class}'" unless lhs_type
|
47
|
+
raise ArgumentError, "rhs is of unsupported type '#{rhs.class}'" unless rhs_type
|
48
|
+
|
49
|
+
if lhs_type == rhs_type
|
50
|
+
|
51
|
+
case lhs_type
|
52
|
+
when :io
|
53
|
+
|
54
|
+
return self.compare_binary_streams_ lhs, rhs, options
|
55
|
+
when :path
|
56
|
+
|
57
|
+
return self.compare_binary_files_ lhs, rhs, options
|
58
|
+
end
|
59
|
+
else
|
60
|
+
|
61
|
+
case lhs_type
|
62
|
+
when :io
|
63
|
+
|
64
|
+
if :path == rhs_type
|
65
|
+
|
66
|
+
File.open(rhs, 'rb') do |rhs_f|
|
67
|
+
|
68
|
+
return self.compare_binary_streams_ lhs, rhs_f, options
|
69
|
+
end
|
70
|
+
end
|
71
|
+
when :path
|
72
|
+
|
73
|
+
if :path == lhs_type
|
74
|
+
|
75
|
+
File.open(lhs, 'rb') do |lhs_f|
|
76
|
+
|
77
|
+
return self.compare_binary_streams_ lhs_f, rhs, options
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
warn "#{__method__}: incompatible types (#{lhs.type}, #{rhs.type})"
|
84
|
+
|
85
|
+
nil
|
86
|
+
end
|
87
|
+
|
88
|
+
end # module Internal_
|
89
|
+
|
90
|
+
end # module Binary
|
91
|
+
end # module Compare
|
92
|
+
end # module CmpFS
|
93
|
+
|
94
|
+
# ############################## end of file ############################# #
|
95
|
+
|
96
|
+
|
@@ -0,0 +1,159 @@
|
|
1
|
+
|
2
|
+
#require 'xqsr3'
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
require 'stringio'
|
6
|
+
|
7
|
+
module CmpFS
|
8
|
+
module Compare
|
9
|
+
module Text
|
10
|
+
|
11
|
+
module Internal_
|
12
|
+
|
13
|
+
def self.determine_param_type_ p
|
14
|
+
|
15
|
+
case p
|
16
|
+
when ::IO, ::StringIO
|
17
|
+
|
18
|
+
return :io
|
19
|
+
when ::String
|
20
|
+
|
21
|
+
return :path
|
22
|
+
else
|
23
|
+
|
24
|
+
return :path if p.respond_to?(:to_str)
|
25
|
+
|
26
|
+
return nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.next_line_or_nil_ en, options
|
31
|
+
|
32
|
+
trimming_lines = options[:trim_lines]
|
33
|
+
skipping_blanks = options[:skip_blank_lines]
|
34
|
+
|
35
|
+
num_read = 0
|
36
|
+
|
37
|
+
begin
|
38
|
+
|
39
|
+
loop do
|
40
|
+
|
41
|
+
line = en.next
|
42
|
+
|
43
|
+
num_read += 1
|
44
|
+
|
45
|
+
line = line.strip if trimming_lines
|
46
|
+
|
47
|
+
if line.empty? && skipping_blanks
|
48
|
+
|
49
|
+
next
|
50
|
+
end
|
51
|
+
|
52
|
+
return [ line, num_read ]
|
53
|
+
end
|
54
|
+
rescue StopIteration
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
return [ nil, num_read ]
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.compare_text_files_ lhs_path, rhs_path, options
|
62
|
+
|
63
|
+
File.open(lhs_path, 'r') do |lhs_stm|
|
64
|
+
|
65
|
+
File.open(rhs_path, 'r') do |rhs_stm|
|
66
|
+
|
67
|
+
self.compare_text_streams_ lhs_stm, rhs_stm, options.merge(no_rewind: true)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.compare_text_streams_ lhs_stm, rhs_stm, options
|
73
|
+
|
74
|
+
lhs_en = lhs_stm.each_line
|
75
|
+
rhs_en = rhs_stm.each_line
|
76
|
+
|
77
|
+
unless options[:no_rewind]
|
78
|
+
|
79
|
+
lhs_en.rewind if lhs_stm.respond_to?(:rewind)
|
80
|
+
rhs_en.rewind if rhs_stm.respond_to?(:rewind)
|
81
|
+
end
|
82
|
+
|
83
|
+
lhs_ix = 0
|
84
|
+
rhs_ix = 0
|
85
|
+
|
86
|
+
loop do
|
87
|
+
|
88
|
+
lhs_ln, lhs_nr = self.next_line_or_nil_ lhs_en, options
|
89
|
+
rhs_ln, rhs_nr = self.next_line_or_nil_ rhs_en, options
|
90
|
+
|
91
|
+
if lhs_ln != rhs_ln
|
92
|
+
|
93
|
+
return false
|
94
|
+
else
|
95
|
+
|
96
|
+
return true if lhs_ln.nil?
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
return true
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.compare_text_ lhs, rhs, options
|
104
|
+
|
105
|
+
lhs_type = self.determine_param_type_ lhs
|
106
|
+
rhs_type = self.determine_param_type_ rhs
|
107
|
+
|
108
|
+
raise ArgumentError, "lhs is of unsupported type '#{lhs.class}'" unless lhs_type
|
109
|
+
raise ArgumentError, "rhs is of unsupported type '#{rhs.class}'" unless rhs_type
|
110
|
+
|
111
|
+
if lhs_type == rhs_type
|
112
|
+
|
113
|
+
case lhs_type
|
114
|
+
when :io
|
115
|
+
|
116
|
+
return self.compare_text_streams_ lhs, rhs, options
|
117
|
+
when :path
|
118
|
+
|
119
|
+
return self.compare_text_files_ lhs, rhs, options
|
120
|
+
end
|
121
|
+
else
|
122
|
+
|
123
|
+
case lhs_type
|
124
|
+
when :io
|
125
|
+
|
126
|
+
if :path == rhs_type
|
127
|
+
|
128
|
+
File.open(rhs, 'r') do |rhs_f|
|
129
|
+
|
130
|
+
return self.compare_text_streams_ lhs, rhs_f, options
|
131
|
+
end
|
132
|
+
end
|
133
|
+
when :path
|
134
|
+
|
135
|
+
if :path == lhs_type
|
136
|
+
|
137
|
+
File.open(lhs, 'r') do |lhs_f|
|
138
|
+
|
139
|
+
return self.compare_text_streams_ lhs_f, rhs, options
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
warn "#{__method__}: incompatible types (#{lhs.type}, #{rhs.type})"
|
146
|
+
|
147
|
+
nil
|
148
|
+
end
|
149
|
+
|
150
|
+
end # module Internal_
|
151
|
+
|
152
|
+
end # module Text
|
153
|
+
end # module Compare
|
154
|
+
end # module CmpFS
|
155
|
+
|
156
|
+
# ############################## end of file ############################# #
|
157
|
+
|
158
|
+
|
159
|
+
|
@@ -0,0 +1,71 @@
|
|
1
|
+
|
2
|
+
# ######################################################################## #
|
3
|
+
# File: cmpfs/version.rb
|
4
|
+
#
|
5
|
+
# Purpose: Version for cmpfs.Ruby library
|
6
|
+
#
|
7
|
+
# Created: 1st March 2019
|
8
|
+
# Updated: 13th March 2019
|
9
|
+
#
|
10
|
+
# Home: http://github.com/synesissoftware/cmpfs.Ruby
|
11
|
+
#
|
12
|
+
# Author: Matthew Wilson
|
13
|
+
#
|
14
|
+
# Copyright (c) 2019, Matthew Wilson and Synesis Software
|
15
|
+
# All rights reserved.
|
16
|
+
#
|
17
|
+
# Redistribution and use in source and binary forms, with or without
|
18
|
+
# modification, are permitted provided that the following conditions are
|
19
|
+
# met:
|
20
|
+
#
|
21
|
+
# * Redistributions of source code must retain the above copyright
|
22
|
+
# notice, this list of conditions and the following disclaimer.
|
23
|
+
#
|
24
|
+
# * Redistributions in binary form must reproduce the above copyright
|
25
|
+
# notice, this list of conditions and the following disclaimer in the
|
26
|
+
# documentation and/or other materials provided with the distribution.
|
27
|
+
#
|
28
|
+
# * Neither the names of the copyright holder nor the names of its
|
29
|
+
# contributors may be used to endorse or promote products derived from
|
30
|
+
# this software without specific prior written permission.
|
31
|
+
#
|
32
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
33
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
34
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
35
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
36
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
37
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
38
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
39
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
40
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
41
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
42
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
43
|
+
#
|
44
|
+
# ######################################################################## #
|
45
|
+
|
46
|
+
|
47
|
+
=begin
|
48
|
+
=end
|
49
|
+
|
50
|
+
module CmpFS
|
51
|
+
|
52
|
+
# Current version of the cmpfs.Ruby library
|
53
|
+
VERSION = '0.2.0'
|
54
|
+
|
55
|
+
private
|
56
|
+
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
57
|
+
public
|
58
|
+
# Major version of the cmpfs.Ruby library
|
59
|
+
VERSION_MAJOR = VERSION_PARTS_[0] # :nodoc:
|
60
|
+
# Minor version of the cmpfs.Ruby library
|
61
|
+
VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
|
62
|
+
# Revision version of the cmpfs.Ruby library
|
63
|
+
VERSION_PATCH = VERSION_PARTS_[2] # :nodoc:
|
64
|
+
|
65
|
+
VERSION_REVISION = VERSION_PATCH # :nodoc:
|
66
|
+
|
67
|
+
end # module CmpFS
|
68
|
+
|
69
|
+
# ############################## end of file ############################# #
|
70
|
+
|
71
|
+
|
@@ -0,0 +1,103 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '../../../lib')
|
4
|
+
|
5
|
+
require 'cmpfs/compare'
|
6
|
+
|
7
|
+
require 'xqsr3/extensions/test/unit'
|
8
|
+
require 'test/unit'
|
9
|
+
|
10
|
+
require 'stringio'
|
11
|
+
require 'tempfile'
|
12
|
+
|
13
|
+
class Test_CmpFS_Compare_compare_binary < Test::Unit::TestCase
|
14
|
+
|
15
|
+
def test_compare_binary_identical_1
|
16
|
+
|
17
|
+
lhs = StringIO.new 'abcdefghijiklmno'
|
18
|
+
rhs_eq = StringIO.new 'abcdefghijiklmno'
|
19
|
+
|
20
|
+
assert CmpFS::Compare.compare_binary(lhs, rhs_eq), 'streams should be the same'
|
21
|
+
|
22
|
+
rhs_ne = StringIO.new 'abcdefghijiklmn'
|
23
|
+
|
24
|
+
assert_false CmpFS::Compare.compare_binary(lhs, rhs_ne), 'streams should not be the same'
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_compare_binary_identical_2
|
28
|
+
|
29
|
+
lhs_f = Tempfile.new('compare_binary-2')
|
30
|
+
|
31
|
+
begin
|
32
|
+
|
33
|
+
lhs_f << 'abcdefghijiklmno'
|
34
|
+
|
35
|
+
lhs_f.rewind
|
36
|
+
lhs_f.close
|
37
|
+
|
38
|
+
rhs_eq = StringIO.new 'abcdefghijiklmno'
|
39
|
+
|
40
|
+
assert CmpFS::Compare.compare_binary(lhs_f.path, rhs_eq), 'streams should be the same'
|
41
|
+
|
42
|
+
rhs_ne = StringIO.new 'abcdefghijiklmnop'
|
43
|
+
|
44
|
+
assert_false CmpFS::Compare.compare_binary(lhs_f.path, rhs_ne), 'streams should not be the same'
|
45
|
+
ensure
|
46
|
+
|
47
|
+
lhs_f.unlink
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_compare_binary_identical_3
|
52
|
+
|
53
|
+
lhs_f = Tempfile.new('compare_binary-3')
|
54
|
+
|
55
|
+
begin
|
56
|
+
|
57
|
+
lhs_f << 'abcdefghijiklmno'
|
58
|
+
|
59
|
+
lhs_f.rewind
|
60
|
+
lhs_f.close
|
61
|
+
|
62
|
+
|
63
|
+
rhs_eq_f = Tempfile.new('compare_binary-3')
|
64
|
+
|
65
|
+
begin
|
66
|
+
|
67
|
+
rhs_eq_f << 'abcdefghijiklmno'
|
68
|
+
|
69
|
+
rhs_eq_f.rewind
|
70
|
+
rhs_eq_f.close
|
71
|
+
|
72
|
+
assert CmpFS::Compare.compare_binary(lhs_f.path, rhs_eq_f.path), 'streams should be the same'
|
73
|
+
ensure
|
74
|
+
|
75
|
+
rhs_eq_f.unlink
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
rhs_ne_f = Tempfile.new('compare_binary-3')
|
80
|
+
|
81
|
+
begin
|
82
|
+
|
83
|
+
rhs_ne_f << 'xyz'
|
84
|
+
|
85
|
+
rhs_ne_f.rewind
|
86
|
+
rhs_ne_f.close
|
87
|
+
|
88
|
+
assert_false CmpFS::Compare.compare_binary(lhs_f.path, rhs_ne_f.path), 'streams should not be the same'
|
89
|
+
ensure
|
90
|
+
|
91
|
+
rhs_ne_f.unlink
|
92
|
+
end
|
93
|
+
|
94
|
+
ensure
|
95
|
+
|
96
|
+
lhs_f.unlink
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# ############################## end of file ############################# #
|
102
|
+
|
103
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# executes all other tests
|
4
|
+
|
5
|
+
this_dir = File.expand_path(File.dirname(__FILE__))
|
6
|
+
|
7
|
+
# all tc_*rb in current directory
|
8
|
+
Dir[File.join(this_dir, 'tc_*rb')].each { |file| require file }
|
9
|
+
|
10
|
+
# all ts_*rb in immediate sub-directories
|
11
|
+
Dir[File.join(this_dir, '*', 'ts_*rb')].each { |file| require file }
|
12
|
+
|
@@ -0,0 +1,107 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '../../lib')
|
4
|
+
|
5
|
+
require 'cmpfs'
|
6
|
+
|
7
|
+
require 'xqsr3/extensions/test/unit'
|
8
|
+
require 'test/unit'
|
9
|
+
|
10
|
+
require 'stringio'
|
11
|
+
require 'tempfile'
|
12
|
+
|
13
|
+
class Test_CmpFS_compare_binary < Test::Unit::TestCase
|
14
|
+
|
15
|
+
include ::CmpFS
|
16
|
+
|
17
|
+
def test_compare_binary_identical_1
|
18
|
+
|
19
|
+
lhs = StringIO.new 'abcdefghijiklmno'
|
20
|
+
rhs_eq = StringIO.new 'abcdefghijiklmno'
|
21
|
+
|
22
|
+
assert compare_binary(lhs, rhs_eq), 'streams should be the same'
|
23
|
+
|
24
|
+
rhs_ne = StringIO.new 'abcdefghijiklmn'
|
25
|
+
|
26
|
+
assert_false compare_binary(lhs, rhs_ne), 'streams should not be the same'
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_compare_binary_identical_2
|
30
|
+
|
31
|
+
lhs_f = Tempfile.new('compare_binary-2')
|
32
|
+
|
33
|
+
begin
|
34
|
+
|
35
|
+
lhs_f << 'abcdefghijiklmno'
|
36
|
+
|
37
|
+
lhs_f.rewind
|
38
|
+
lhs_f.close
|
39
|
+
|
40
|
+
rhs_eq = StringIO.new 'abcdefghijiklmno'
|
41
|
+
|
42
|
+
assert compare_binary(lhs_f.path, rhs_eq), 'streams should be the same'
|
43
|
+
|
44
|
+
rhs_ne = StringIO.new 'abcdefghijiklmnop'
|
45
|
+
|
46
|
+
assert_false compare_binary(lhs_f.path, rhs_ne), 'streams should not be the same'
|
47
|
+
ensure
|
48
|
+
|
49
|
+
lhs_f.unlink
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_compare_binary_identical_3
|
54
|
+
|
55
|
+
lhs_f = Tempfile.new('compare_binary-3')
|
56
|
+
|
57
|
+
begin
|
58
|
+
|
59
|
+
lhs_f << 'abcdefghijiklmno'
|
60
|
+
|
61
|
+
lhs_f.rewind
|
62
|
+
lhs_f.close
|
63
|
+
|
64
|
+
|
65
|
+
rhs_eq_f = Tempfile.new('compare_binary-3')
|
66
|
+
|
67
|
+
begin
|
68
|
+
|
69
|
+
rhs_eq_f << 'abcdefghijiklmno'
|
70
|
+
|
71
|
+
rhs_eq_f.rewind
|
72
|
+
rhs_eq_f.close
|
73
|
+
|
74
|
+
|
75
|
+
assert compare_binary(lhs_f.path, rhs_eq_f.path), 'streams should be the same'
|
76
|
+
ensure
|
77
|
+
|
78
|
+
rhs_eq_f.unlink
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
rhs_ne_f = Tempfile.new('compare_binary-3')
|
83
|
+
|
84
|
+
begin
|
85
|
+
|
86
|
+
rhs_ne_f << 'xyz'
|
87
|
+
|
88
|
+
rhs_ne_f.rewind
|
89
|
+
rhs_ne_f.close
|
90
|
+
|
91
|
+
|
92
|
+
assert_false compare_binary(lhs_f.path, rhs_ne_f.path), 'streams should not be the same'
|
93
|
+
ensure
|
94
|
+
|
95
|
+
rhs_ne_f.unlink
|
96
|
+
end
|
97
|
+
|
98
|
+
ensure
|
99
|
+
|
100
|
+
lhs_f.unlink
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# ############################## end of file ############################# #
|
106
|
+
|
107
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '../../lib')
|
4
|
+
|
5
|
+
require 'cmpfs'
|
6
|
+
|
7
|
+
require 'xqsr3/extensions/test/unit'
|
8
|
+
require 'test/unit'
|
9
|
+
|
10
|
+
require 'stringio'
|
11
|
+
require 'tempfile'
|
12
|
+
|
13
|
+
class Test_CmpFS_compare_text < Test::Unit::TestCase
|
14
|
+
|
15
|
+
include ::CmpFS
|
16
|
+
|
17
|
+
def test_compare_text_identical_1
|
18
|
+
|
19
|
+
lhs = StringIO.new
|
20
|
+
rhs_eq = StringIO.new
|
21
|
+
|
22
|
+
lhs << "line-1\n"
|
23
|
+
rhs_eq << "line-1\n"
|
24
|
+
|
25
|
+
lhs << "line-2\n"
|
26
|
+
rhs_eq << "line-2\n"
|
27
|
+
|
28
|
+
assert compare_text(lhs, rhs_eq), 'streams should be the same'
|
29
|
+
|
30
|
+
rhs_ne = StringIO.new
|
31
|
+
|
32
|
+
rhs_ne << "line-1\n"
|
33
|
+
rhs_ne << "line2\n"
|
34
|
+
|
35
|
+
assert_false compare_text(lhs, rhs_ne), 'streams should not be the same'
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_compare_text_same_with_blank_lines_1
|
39
|
+
|
40
|
+
lhs = StringIO.new
|
41
|
+
rhs_eq = StringIO.new
|
42
|
+
|
43
|
+
lhs << "line-1\n"
|
44
|
+
lhs << "\n"
|
45
|
+
rhs_eq << "line-1\n"
|
46
|
+
|
47
|
+
lhs << " line-2\n"
|
48
|
+
rhs_eq << "line-2\n"
|
49
|
+
|
50
|
+
assert_false compare_text(lhs, rhs_eq), 'streams should not be the same'
|
51
|
+
assert compare_text(lhs, rhs_eq, trim_lines: true, skip_blank_lines: true), 'streams should be the same'
|
52
|
+
|
53
|
+
rhs_ne = StringIO.new
|
54
|
+
|
55
|
+
rhs_ne << "line-1\n"
|
56
|
+
rhs_ne << "line2\n"
|
57
|
+
|
58
|
+
assert_false compare_text(lhs, rhs_ne), 'streams should not be the same'
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
# ############################## end of file ############################# #
|
64
|
+
|
65
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '../../lib')
|
4
|
+
|
5
|
+
require 'cmpfs/version'
|
6
|
+
|
7
|
+
require 'xqsr3/extensions/test/unit'
|
8
|
+
require 'test/unit'
|
9
|
+
|
10
|
+
class Test_version < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def test_has_VERSION
|
13
|
+
|
14
|
+
assert defined? CmpFS::VERSION
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_has_VERSION_MAJOR
|
18
|
+
|
19
|
+
assert defined? CmpFS::VERSION_MAJOR
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_has_VERSION_MINOR
|
23
|
+
|
24
|
+
assert defined? CmpFS::VERSION_MINOR
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_has_VERSION_REVISION
|
28
|
+
|
29
|
+
assert defined? CmpFS::VERSION_REVISION
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_VERSION_has_consistent_format
|
33
|
+
|
34
|
+
assert_equal CmpFS::VERSION, "#{CmpFS::VERSION_MAJOR}.#{CmpFS::VERSION_MINOR}.#{CmpFS::VERSION_PATCH}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
data/test/unit/ts_all.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# executes all other tests
|
4
|
+
|
5
|
+
this_dir = File.expand_path(File.dirname(__FILE__))
|
6
|
+
|
7
|
+
# all tc_*rb in current directory
|
8
|
+
Dir[File.join(this_dir, 'tc_*rb')].each { |file| require file }
|
9
|
+
|
10
|
+
# all ts_*rb in immediate sub-directories
|
11
|
+
Dir[File.join(this_dir, '*', 'ts_*rb')].each { |file| require file }
|
12
|
+
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cmpfs-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Wilson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: xqsr3
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.31'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.31'
|
27
|
+
description: |
|
28
|
+
Compare File-System entities, for Ruby is a library that provides comparison
|
29
|
+
functions for file-system entities - files and streams - including binary and
|
30
|
+
filtering textual comparisons.
|
31
|
+
email: matthew@synesis.com.au
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- lib/cmpfs/compare/api_1_9.rb
|
37
|
+
- lib/cmpfs/compare/api_2.rb
|
38
|
+
- lib/cmpfs/compare/binary/internal_.rb
|
39
|
+
- lib/cmpfs/compare/text/internal_.rb
|
40
|
+
- lib/cmpfs/compare.rb
|
41
|
+
- lib/cmpfs/version.rb
|
42
|
+
- lib/cmpfs.rb
|
43
|
+
- test/unit/compare/tc_compare_binary.rb
|
44
|
+
- test/unit/compare/ts_all.rb
|
45
|
+
- test/unit/tc_compare_binary.rb
|
46
|
+
- test/unit/tc_compare_text.rb
|
47
|
+
- test/unit/tc_version.rb
|
48
|
+
- test/unit/ts_all.rb
|
49
|
+
- README.md
|
50
|
+
- LICENSE
|
51
|
+
homepage: http://github.com/synesissoftware/cmpfs.Ruby
|
52
|
+
licenses:
|
53
|
+
- BSD 3-Clause
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ~>
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '2.0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.0.14.1
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: CmpFS.Ruby
|
75
|
+
test_files: []
|