xqsr3 0.8.3
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.
- checksums.yaml +7 -0
- data/LICENSE +27 -0
- data/README.md +26 -0
- data/lib/xqsr3/command_line_utilities/map_option_string.rb +137 -0
- data/lib/xqsr3/containers/frequency_map.rb +473 -0
- data/lib/xqsr3/containers/multi_map.rb +383 -0
- data/lib/xqsr3/diagnostics/exception_utilities.rb +216 -0
- data/lib/xqsr3/doc_.rb +116 -0
- data/lib/xqsr3/extensions/enumerable.rb +4 -0
- data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +71 -0
- data/lib/xqsr3/extensions/enumerable/unique.rb +102 -0
- data/lib/xqsr3/extensions/io.rb +3 -0
- data/lib/xqsr3/extensions/io/writelines.rb +66 -0
- data/lib/xqsr3/extensions/kernel.rb +3 -0
- data/lib/xqsr3/extensions/kernel/raise_with_options.rb +68 -0
- data/lib/xqsr3/extensions/string.rb +5 -0
- data/lib/xqsr3/extensions/string/ends_with.rb +8 -0
- data/lib/xqsr3/extensions/string/map_option_string.rb +8 -0
- data/lib/xqsr3/extensions/string/starts_with.rb +8 -0
- data/lib/xqsr3/extensions/string/to_symbol.rb +8 -0
- data/lib/xqsr3/extensions/test/unit.rb +5 -0
- data/lib/xqsr3/extensions/test/unit/assert_eql.rb +18 -0
- data/lib/xqsr3/extensions/test/unit/assert_not.rb +18 -0
- data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +18 -0
- data/lib/xqsr3/io/writelines.rb +192 -0
- data/lib/xqsr3/quality/parameter_checking.rb +343 -0
- data/lib/xqsr3/string_utilities/ends_with.rb +134 -0
- data/lib/xqsr3/string_utilities/starts_with.rb +127 -0
- data/lib/xqsr3/string_utilities/to_symbol.rb +145 -0
- data/lib/xqsr3/version.rb +68 -0
- data/test/unit/command_line_utilities/tc_map_option_string.rb +39 -0
- data/test/unit/command_line_utilities/ts_all.rb +13 -0
- data/test/unit/containers/tc_frequency_map.rb +738 -0
- data/test/unit/containers/tc_multi_map.rb +640 -0
- data/test/unit/containers/ts_all.rb +13 -0
- data/test/unit/diagnostics/tc_exception_utilities.rb +221 -0
- data/test/unit/diagnostics/ts_all.rb +13 -0
- data/test/unit/extensions/enumerable/tc_collect_with_index.rb +36 -0
- data/test/unit/extensions/enumerable/tc_unique.rb +47 -0
- data/test/unit/extensions/enumerable/ts_all.rb +13 -0
- data/test/unit/extensions/io/tc_writelines.rb +110 -0
- data/test/unit/extensions/io/ts_all.rb +13 -0
- data/test/unit/extensions/kernel/tc_raise_with_options.rb +239 -0
- data/test/unit/extensions/kernel/ts_all.rb +13 -0
- data/test/unit/extensions/string/tc_ends_with.rb +70 -0
- data/test/unit/extensions/string/tc_map_option_string.rb +37 -0
- data/test/unit/extensions/string/tc_starts_with.rb +70 -0
- data/test/unit/extensions/string/tc_to_symbol.rb +51 -0
- data/test/unit/extensions/string/ts_all.rb +13 -0
- data/test/unit/extensions/ts_all.rb +13 -0
- data/test/unit/io/tc_writelines.rb +200 -0
- data/test/unit/io/ts_all.rb +13 -0
- data/test/unit/quality/tc_parameter_checking.rb +181 -0
- data/test/unit/quality/ts_all.rb +13 -0
- data/test/unit/tc_version.rb +37 -0
- data/test/unit/ts_all.rb +13 -0
- metadata +101 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
#
|
3
|
+
# executes all other tests
|
4
|
+
|
5
|
+
this_file = File.expand_path(__FILE__)
|
6
|
+
this_dir = File.expand_path(File.dirname(__FILE__))
|
7
|
+
|
8
|
+
# all tc_*rb in current directory
|
9
|
+
Dir[File.join(this_dir, 'tc_*rb')].each { |file| require file }
|
10
|
+
|
11
|
+
# all ts_*rb in immediate sub-directories
|
12
|
+
Dir[File.join(this_dir, '*', 'ts_*rb')].each { |file| require file }
|
13
|
+
|
@@ -0,0 +1,239 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '../../../../lib')
|
4
|
+
|
5
|
+
require 'xqsr3/extensions/kernel/raise_with_options'
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class Test_X_Kernel_raise_with_options < Test::Unit::TestCase
|
10
|
+
|
11
|
+
class ArgumentErrorWithOptions < ArgumentError
|
12
|
+
|
13
|
+
def initialize(message = nil, **options)
|
14
|
+
|
15
|
+
super(message)
|
16
|
+
options ||= {}
|
17
|
+
@options = options
|
18
|
+
end
|
19
|
+
attr_reader :options
|
20
|
+
|
21
|
+
def exception(msg = nil, options = nil)
|
22
|
+
|
23
|
+
return self if msg.nil?
|
24
|
+
return self if msg.object_id == self.object_id
|
25
|
+
|
26
|
+
msg ||= self.message
|
27
|
+
options ||= {}
|
28
|
+
r = self.class.new msg, self.options.merge(options)
|
29
|
+
r
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def execute(&block)
|
34
|
+
|
35
|
+
block.call
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_0
|
39
|
+
|
40
|
+
# standard raise: message-only
|
41
|
+
begin
|
42
|
+
|
43
|
+
raise "abc"
|
44
|
+
|
45
|
+
assert false, "should not get here"
|
46
|
+
rescue => x
|
47
|
+
|
48
|
+
assert_kind_of(RuntimeError, x)
|
49
|
+
assert_equal "abc", x.message
|
50
|
+
end
|
51
|
+
|
52
|
+
# RWO: message-only
|
53
|
+
begin
|
54
|
+
|
55
|
+
raise_with_options "abc"
|
56
|
+
|
57
|
+
assert false, "should not get here"
|
58
|
+
rescue => x
|
59
|
+
|
60
|
+
assert_kind_of(RuntimeError, x)
|
61
|
+
assert_equal "abc", x.message
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_1
|
66
|
+
|
67
|
+
# standard raise: class
|
68
|
+
begin
|
69
|
+
|
70
|
+
raise ArgumentError
|
71
|
+
|
72
|
+
assert false, "should not get here"
|
73
|
+
rescue => x
|
74
|
+
|
75
|
+
assert_kind_of(ArgumentError, x)
|
76
|
+
assert_equal "ArgumentError", x.message
|
77
|
+
end
|
78
|
+
|
79
|
+
# RWO: class + message
|
80
|
+
begin
|
81
|
+
|
82
|
+
raise_with_options ArgumentError
|
83
|
+
|
84
|
+
assert false, "should not get here"
|
85
|
+
rescue => x
|
86
|
+
|
87
|
+
assert_kind_of(ArgumentError, x)
|
88
|
+
assert_equal "ArgumentError", x.message
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_2
|
93
|
+
|
94
|
+
# standard raise: class + message
|
95
|
+
begin
|
96
|
+
|
97
|
+
raise ArgumentError, "abc"
|
98
|
+
|
99
|
+
assert false, "should not get here"
|
100
|
+
rescue => x
|
101
|
+
|
102
|
+
assert_kind_of(ArgumentError, x)
|
103
|
+
assert_equal "abc", x.message
|
104
|
+
end
|
105
|
+
|
106
|
+
# RWO: class + message
|
107
|
+
begin
|
108
|
+
|
109
|
+
raise_with_options ArgumentError, "abc"
|
110
|
+
|
111
|
+
assert false, "should not get here"
|
112
|
+
rescue => x
|
113
|
+
|
114
|
+
assert_kind_of(ArgumentError, x)
|
115
|
+
assert_equal "abc", x.message
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_2_b_no_options
|
120
|
+
|
121
|
+
# standard raise: class + message
|
122
|
+
begin
|
123
|
+
|
124
|
+
raise ArgumentErrorWithOptions, "abc"
|
125
|
+
|
126
|
+
assert false, "should not get here"
|
127
|
+
rescue => x
|
128
|
+
|
129
|
+
assert_kind_of(ArgumentError, x)
|
130
|
+
assert_equal "abc", x.message
|
131
|
+
end
|
132
|
+
|
133
|
+
# RWO: class + message
|
134
|
+
begin
|
135
|
+
|
136
|
+
raise_with_options ArgumentErrorWithOptions, "abc"
|
137
|
+
|
138
|
+
assert false, "should not get here"
|
139
|
+
rescue => x
|
140
|
+
|
141
|
+
assert_kind_of(ArgumentError, x)
|
142
|
+
assert_equal "abc", x.message
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_2_b_with_options
|
147
|
+
|
148
|
+
# standard raise: class + message + options
|
149
|
+
begin
|
150
|
+
|
151
|
+
raise ArgumentErrorWithOptions.new("abc", blah: :blech, id: 23)
|
152
|
+
|
153
|
+
assert false, "should not get here"
|
154
|
+
rescue => x
|
155
|
+
|
156
|
+
assert_kind_of(ArgumentError, x)
|
157
|
+
assert_equal "abc", x.message
|
158
|
+
assert_equal ({ :blah => :blech, :id => 23 }), x.options
|
159
|
+
end
|
160
|
+
|
161
|
+
# RWO: class + message + options (raise-way)
|
162
|
+
begin
|
163
|
+
|
164
|
+
raise_with_options ArgumentErrorWithOptions.new("abc", blah: :blech, id: 23)
|
165
|
+
|
166
|
+
assert false, "should not get here"
|
167
|
+
rescue => x
|
168
|
+
|
169
|
+
assert_kind_of(ArgumentError, x)
|
170
|
+
assert_equal "abc", x.message
|
171
|
+
assert_equal ({ :blah => :blech, :id => 23 }), x.options
|
172
|
+
end
|
173
|
+
|
174
|
+
# RWO: class + message + options (raise_with_options-way)
|
175
|
+
begin
|
176
|
+
|
177
|
+
raise_with_options ArgumentErrorWithOptions, "abc", blah: :blech, id: 23
|
178
|
+
|
179
|
+
assert false, "should not get here"
|
180
|
+
rescue => x
|
181
|
+
|
182
|
+
assert_kind_of(ArgumentError, x)
|
183
|
+
assert_equal "abc", x.message
|
184
|
+
assert_equal ({ :blah => :blech, :id => 23 }), x.options
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
def test_with_backtrace
|
190
|
+
|
191
|
+
line_number = nil
|
192
|
+
|
193
|
+
# standard raise: class + message + stack trace
|
194
|
+
begin
|
195
|
+
|
196
|
+
begin
|
197
|
+
|
198
|
+
execute { line_number = __LINE__; raise ArgumentError }
|
199
|
+
rescue => x
|
200
|
+
|
201
|
+
raise x, "abc", x.backtrace
|
202
|
+
end
|
203
|
+
|
204
|
+
assert false, "should not get here"
|
205
|
+
rescue => x
|
206
|
+
|
207
|
+
assert_kind_of(ArgumentError, x)
|
208
|
+
assert_equal "abc", x.message
|
209
|
+
|
210
|
+
assert $@[0] =~ /^[^:]+:(\d+)/
|
211
|
+
assert_equal line_number.to_s, $1.to_s
|
212
|
+
end
|
213
|
+
|
214
|
+
# RWO: class + message + stack trace
|
215
|
+
begin
|
216
|
+
|
217
|
+
begin
|
218
|
+
|
219
|
+
execute { line_number = __LINE__; raise_with_options ArgumentErrorWithOptions, blah: :blech, id: 23 }
|
220
|
+
|
221
|
+
assert false, "should not get here"
|
222
|
+
rescue => x
|
223
|
+
|
224
|
+
raise x, "abc", x.backtrace
|
225
|
+
end
|
226
|
+
|
227
|
+
assert false, "should not get here"
|
228
|
+
rescue => x
|
229
|
+
|
230
|
+
assert_kind_of(ArgumentError, x)
|
231
|
+
assert_equal "abc", x.message
|
232
|
+
assert_equal ({ :blah => :blech, :id => 23 }), x.options
|
233
|
+
|
234
|
+
assert $@[0] =~ /^[^:]+:(\d+)/
|
235
|
+
assert_equal line_number.to_s, $1.to_s
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
#
|
3
|
+
# executes all other tests
|
4
|
+
|
5
|
+
this_file = File.expand_path(__FILE__)
|
6
|
+
this_dir = File.expand_path(File.dirname(__FILE__))
|
7
|
+
|
8
|
+
# all tc_*rb in current directory
|
9
|
+
Dir[File.join(this_dir, 'tc_*rb')].each { |file| require file }
|
10
|
+
|
11
|
+
# all ts_*rb in immediate sub-directories
|
12
|
+
Dir[File.join(this_dir, '*', 'ts_*rb')].each { |file| require file }
|
13
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '../../../../lib')
|
4
|
+
|
5
|
+
require 'xqsr3/extensions/string/ends_with'
|
6
|
+
|
7
|
+
require 'xqsr3/extensions/test/unit'
|
8
|
+
require 'test/unit'
|
9
|
+
|
10
|
+
require 'stringio'
|
11
|
+
|
12
|
+
class Test_String_ends_with < Test::Unit::TestCase
|
13
|
+
|
14
|
+
def test_String_has_method
|
15
|
+
|
16
|
+
assert ''.respond_to? :ends_with?
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_with_nil
|
20
|
+
|
21
|
+
assert ''.ends_with? nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_with_single_strings
|
25
|
+
|
26
|
+
assert ''.ends_with? ''
|
27
|
+
assert 'a'.ends_with? ''
|
28
|
+
assert 'a'.ends_with? 'a'
|
29
|
+
assert_not 'b'.ends_with? 'a'
|
30
|
+
assert_nil 'b'.ends_with? 'a'
|
31
|
+
assert 'ab'.ends_with? 'b'
|
32
|
+
assert 'abc'.ends_with? 'c'
|
33
|
+
assert 'abc'.ends_with? 'bc'
|
34
|
+
assert_not 'abc'.ends_with? 'ac'
|
35
|
+
assert_nil 'abc'.ends_with? 'ac'
|
36
|
+
|
37
|
+
assert 'abcdefghijklmnopqrstuvwxyz'.ends_with? ''
|
38
|
+
assert 'abcdefghijklmnopqrstuvwxyz'.ends_with? 'z'
|
39
|
+
assert 'abcdefghijklmnopqrstuvwxyz'.ends_with? 'yz'
|
40
|
+
assert 'abcdefghijklmnopqrstuvwxyz'.ends_with? 'xyz'
|
41
|
+
assert 'abcdefghijklmnopqrstuvwxyz'.ends_with? 'wxyz'
|
42
|
+
assert 'abcdefghijklmnopqrstuvwxyz'.ends_with? 'vwxyz'
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_multiple_strings
|
46
|
+
|
47
|
+
assert ''.ends_with? '', 'd'
|
48
|
+
assert_not ''.ends_with? 'c', 'd'
|
49
|
+
assert_nil ''.ends_with? 'c', 'd'
|
50
|
+
assert 'c'.ends_with? 'c', 'd'
|
51
|
+
assert 'd'.ends_with? 'c', 'd'
|
52
|
+
|
53
|
+
assert_equal 'd', 'abcd'.ends_with?('c', 'd')
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_with_array
|
57
|
+
|
58
|
+
prefixes = %w{ a c def }
|
59
|
+
|
60
|
+
assert_not ''.ends_with? *prefixes
|
61
|
+
assert_nil ''.ends_with? *prefixes
|
62
|
+
assert ''.ends_with? *prefixes, ''
|
63
|
+
assert 'abc'.ends_with? *prefixes
|
64
|
+
assert_not 'd'.ends_with? *prefixes
|
65
|
+
assert_nil 'd'.ends_with? *prefixes
|
66
|
+
assert 'abcdef'.ends_with? *prefixes
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '../../../../lib')
|
4
|
+
|
5
|
+
require 'xqsr3/extensions/string/map_option_string'
|
6
|
+
|
7
|
+
require 'xqsr3/extensions/test/unit'
|
8
|
+
require 'test/unit'
|
9
|
+
|
10
|
+
class Test_String_map_option_string < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def test_simple_uses
|
13
|
+
|
14
|
+
assert_nil 'abc'.map_option_string [ 'option-1', 'option-2' ]
|
15
|
+
|
16
|
+
assert_equal :abc, 'abc'.map_option_string([ 'abc' ])
|
17
|
+
|
18
|
+
assert_equal :option_1, 'option-1'.map_option_string([ 'option-1', 'option-2' ])
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_shortcuts
|
22
|
+
|
23
|
+
option_strings = [ '[n]ame-only', '[f]ull-[p]ath' ]
|
24
|
+
|
25
|
+
assert_equal :name_only, 'name-only'.map_option_string(option_strings)
|
26
|
+
assert_equal :full_path, 'full-path'.map_option_string(option_strings)
|
27
|
+
|
28
|
+
assert_equal :name_only, 'n'.map_option_string(option_strings)
|
29
|
+
assert_equal :full_path, 'fp'.map_option_string(option_strings)
|
30
|
+
|
31
|
+
%w{ a m e - o l y u l p a t h }.each do |shortcut|
|
32
|
+
|
33
|
+
assert_nil shortcut.map_option_string(option_strings)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '../../../../lib')
|
4
|
+
|
5
|
+
require 'xqsr3/extensions/string/starts_with'
|
6
|
+
|
7
|
+
require 'xqsr3/extensions/test/unit'
|
8
|
+
require 'test/unit'
|
9
|
+
|
10
|
+
require 'stringio'
|
11
|
+
|
12
|
+
class Test_String_starts_with < Test::Unit::TestCase
|
13
|
+
|
14
|
+
def test_String_has_method
|
15
|
+
|
16
|
+
assert ''.respond_to? :starts_with?
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_with_nil
|
20
|
+
|
21
|
+
assert ''.starts_with? nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_with_single_strings
|
25
|
+
|
26
|
+
assert ''.starts_with? ''
|
27
|
+
assert 'a'.starts_with? ''
|
28
|
+
assert 'a'.starts_with? 'a'
|
29
|
+
assert_not 'b'.starts_with? 'a'
|
30
|
+
assert_nil 'b'.starts_with? 'a'
|
31
|
+
assert 'ab'.starts_with? 'a'
|
32
|
+
assert 'abc'.starts_with? 'a'
|
33
|
+
assert 'abc'.starts_with? 'ab'
|
34
|
+
assert_not 'abc'.starts_with? 'ac'
|
35
|
+
assert_nil 'abc'.starts_with? 'ac'
|
36
|
+
|
37
|
+
assert 'abcdefghijklmnopqrstuvwxz'.starts_with? ''
|
38
|
+
assert 'abcdefghijklmnopqrstuvwxz'.starts_with? 'a'
|
39
|
+
assert 'abcdefghijklmnopqrstuvwxz'.starts_with? 'ab'
|
40
|
+
assert 'abcdefghijklmnopqrstuvwxz'.starts_with? 'abc'
|
41
|
+
assert 'abcdefghijklmnopqrstuvwxz'.starts_with? 'abcd'
|
42
|
+
assert 'abcdefghijklmnopqrstuvwxz'.starts_with? 'abcde'
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_multiple_strings
|
46
|
+
|
47
|
+
assert ''.starts_with? '', 'd'
|
48
|
+
assert_not ''.starts_with? 'c', 'd'
|
49
|
+
assert_nil ''.starts_with? 'c', 'd'
|
50
|
+
assert 'c'.starts_with? 'c', 'd'
|
51
|
+
assert 'd'.starts_with? 'c', 'd'
|
52
|
+
|
53
|
+
assert_equal 'a', 'abcd'.starts_with?('a', 'b')
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_with_array
|
57
|
+
|
58
|
+
prefixes = %w{ a c def }
|
59
|
+
|
60
|
+
assert_not ''.starts_with? *prefixes
|
61
|
+
assert_nil ''.starts_with? *prefixes
|
62
|
+
assert ''.starts_with? *prefixes, ''
|
63
|
+
assert 'abc'.starts_with? *prefixes
|
64
|
+
assert_not 'd'.starts_with? *prefixes
|
65
|
+
assert_nil 'd'.starts_with? *prefixes
|
66
|
+
assert 'defghi'.starts_with? *prefixes
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|