xqsr3 0.38.1.1 → 0.39.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -6
- data/examples/count_word_frequencies.md +13 -13
- data/examples/count_word_frequencies.rb +5 -5
- data/lib/xqsr3/array_utilities/join_with_or.rb +53 -54
- data/lib/xqsr3/array_utilities.rb +2 -2
- data/lib/xqsr3/command_line_utilities/map_option_string.rb +66 -67
- data/lib/xqsr3/command_line_utilities.rb +2 -2
- data/lib/xqsr3/containers/frequency_map.rb +405 -404
- data/lib/xqsr3/containers/multi_map.rb +454 -453
- data/lib/xqsr3/containers.rb +3 -3
- data/lib/xqsr3/conversion/bool_parser.rb +56 -57
- data/lib/xqsr3/conversion/integer_parser.rb +92 -93
- data/lib/xqsr3/conversion.rb +3 -3
- data/lib/xqsr3/diagnostics/exception_utilities.rb +152 -151
- data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +99 -95
- data/lib/xqsr3/diagnostics/inspect_builder.rb +86 -86
- data/lib/xqsr3/diagnostics.rb +3 -3
- data/lib/xqsr3/doc_.rb +136 -136
- data/lib/xqsr3/extensions/array/join_with_or.rb +9 -9
- data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +18 -17
- data/lib/xqsr3/extensions/enumerable/detect_map.rb +41 -41
- data/lib/xqsr3/extensions/enumerable/unique.rb +32 -31
- data/lib/xqsr3/extensions/hash/deep_transform.rb +1 -1
- data/lib/xqsr3/extensions/hash/except.rb +16 -16
- data/lib/xqsr3/extensions/hash/has_match.rb +10 -10
- data/lib/xqsr3/extensions/hash/match.rb +10 -10
- data/lib/xqsr3/extensions/hash/slice.rb +11 -11
- data/lib/xqsr3/extensions/hash.rb +1 -1
- data/lib/xqsr3/extensions/integer/to_s_grp.rb +118 -0
- data/lib/xqsr3/extensions/integer.rb +3 -0
- data/lib/xqsr3/extensions/io/writelines.rb +34 -34
- data/lib/xqsr3/extensions/kernel/integer.rb +26 -26
- data/lib/xqsr3/extensions/kernel/raise_with_options.rb +15 -14
- data/lib/xqsr3/extensions/kernel.rb +1 -0
- data/lib/xqsr3/extensions/string/ends_with.rb +1 -1
- data/lib/xqsr3/extensions/string/map_option_string.rb +4 -5
- data/lib/xqsr3/extensions/string/nil_if_empty.rb +1 -1
- data/lib/xqsr3/extensions/string/nil_if_whitespace.rb +1 -1
- data/lib/xqsr3/extensions/string/quote_if.rb +1 -2
- data/lib/xqsr3/extensions/string/starts_with.rb +1 -1
- data/lib/xqsr3/extensions/string/to_bool.rb +8 -9
- data/lib/xqsr3/extensions/string/to_symbol.rb +1 -1
- data/lib/xqsr3/extensions/string/truncate.rb +1 -2
- data/lib/xqsr3/extensions/test/unit/assert_eql.rb +7 -7
- data/lib/xqsr3/extensions/test/unit/assert_false.rb +6 -7
- data/lib/xqsr3/extensions/test/unit/assert_not.rb +6 -7
- data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +7 -7
- data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +61 -62
- data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +7 -8
- data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +7 -8
- data/lib/xqsr3/extensions/test/unit/assert_true.rb +6 -7
- data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +36 -38
- data/lib/xqsr3/extensions.rb +5 -5
- data/lib/xqsr3/hash_utilities/deep_transform.rb +71 -71
- data/lib/xqsr3/hash_utilities/key_matching.rb +82 -82
- data/lib/xqsr3/hash_utilities.rb +3 -3
- data/lib/xqsr3/internal_/test_unit_version_.rb +130 -88
- data/lib/xqsr3/io/writelines.rb +125 -125
- data/lib/xqsr3/quality/parameter_checking.rb +452 -453
- data/lib/xqsr3/quality.rb +2 -2
- data/lib/xqsr3/string_utilities/ends_with.rb +64 -64
- data/lib/xqsr3/string_utilities/nil_if_empty.rb +33 -34
- data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +35 -35
- data/lib/xqsr3/string_utilities/quote_if.rb +55 -56
- data/lib/xqsr3/string_utilities/starts_with.rb +64 -64
- data/lib/xqsr3/string_utilities/to_symbol.rb +80 -80
- data/lib/xqsr3/string_utilities/truncate.rb +60 -61
- data/lib/xqsr3/string_utilities.rb +8 -8
- data/lib/xqsr3/version.rb +19 -20
- data/test/performance/frequency_map.rb +13 -27
- data/test/scratch/test_assert_raise_with_message.rb +12 -13
- data/test/unit/array_utilities/tc_join_with_or.rb +140 -142
- data/test/unit/command_line_utilities/tc_map_option_string.rb +18 -18
- data/test/unit/containers/tc_frequency_map.rb +607 -554
- data/test/unit/containers/tc_multi_map.rb +573 -522
- data/test/unit/conversion/tc_integer_parser.rb +73 -73
- data/test/unit/conversion/tc_to_bool.rb +26 -26
- data/test/unit/diagnostics/exceptions/tc_with_cause.rb +165 -165
- data/test/unit/diagnostics/tc_exception_utilities.rb +156 -156
- data/test/unit/extensions/enumerable/tc_collect_with_index.rb +14 -14
- data/test/unit/extensions/enumerable/tc_detect_map.rb +20 -20
- data/test/unit/extensions/enumerable/tc_unique.rb +34 -34
- data/test/unit/extensions/hash/tc_deep_transform.rb +22 -22
- data/test/unit/extensions/hash/tc_except.rb +28 -28
- data/test/unit/extensions/hash/tc_hash.rb +1 -1
- data/test/unit/extensions/hash/tc_slice.rb +14 -14
- data/test/unit/extensions/integer/tc_to_s_grp.rb +60 -0
- data/test/unit/extensions/integer/ts_all.rb +12 -0
- data/test/unit/extensions/io/tc_writelines.rb +77 -77
- data/test/unit/extensions/kernel/tc_integer.rb +75 -75
- data/test/unit/extensions/kernel/tc_raise_with_options.rb +155 -155
- data/test/unit/extensions/object/tc_inspect.rb +51 -51
- data/test/unit/extensions/string/tc_bool.tb +24 -24
- data/test/unit/extensions/string/tc_ends_with.rb +53 -53
- data/test/unit/extensions/string/tc_map_option_string.rb +15 -15
- data/test/unit/extensions/string/tc_nil_if_empty.rb +8 -8
- data/test/unit/extensions/string/tc_nil_if_whitespace.rb +8 -8
- data/test/unit/extensions/string/tc_quote_if.rb +18 -18
- data/test/unit/extensions/string/tc_starts_with.rb +53 -53
- data/test/unit/extensions/string/tc_to_symbol.rb +26 -26
- data/test/unit/extensions/string/tc_truncate.rb +18 -18
- data/test/unit/extensions/test/unit/tc_assert_raise_with_message.rb +16 -16
- data/test/unit/extensions/test/unit/tc_assert_subclass_of.rb +9 -9
- data/test/unit/extensions/test/unit/tc_assert_superclass_of.rb +9 -9
- data/test/unit/hash_utilities/tc_has_match.rb +70 -70
- data/test/unit/hash_utilities/tc_match.rb +83 -83
- data/test/unit/io/tc_writelines.rb +106 -108
- data/test/unit/quality/tc_parameter_checking.rb +390 -390
- data/test/unit/string_utilities/tc_truncate.rb +28 -28
- data/test/unit/tc_version.rb +15 -15
- metadata +6 -2
@@ -1,18 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#############################################################################
|
4
|
-
# File: test/performance/frequency_map.rb
|
5
|
-
#
|
6
|
-
# Purpose: COMPLETE_ME
|
7
|
-
#
|
8
|
-
# Created: 13th October 2018
|
9
|
-
# Updated: 13th October 2018
|
10
|
-
#
|
11
|
-
# Author: Matthew Wilson
|
12
|
-
#
|
13
|
-
# Copyright: <<TBD>>
|
14
|
-
#
|
15
|
-
#############################################################################
|
1
|
+
#! /usr/bin/env ruby
|
16
2
|
|
17
3
|
$:.unshift File.join(File.dirname($0), *(['..'] * 2), 'lib')
|
18
4
|
|
@@ -24,25 +10,25 @@ include ::Xqsr3::Containers
|
|
24
10
|
|
25
11
|
Benchmark.bm do |bm|
|
26
12
|
|
27
|
-
|
13
|
+
fm = FrequencyMap.new
|
28
14
|
|
29
|
-
|
15
|
+
(0...100000000).each do |n|
|
30
16
|
|
31
|
-
|
32
|
-
|
17
|
+
fm << (n % 4793)
|
18
|
+
end
|
33
19
|
|
34
|
-
|
20
|
+
bm.report('each ') do
|
35
21
|
|
36
|
-
|
22
|
+
fm.each do |k, freq|
|
37
23
|
|
38
|
-
|
39
|
-
|
24
|
+
end
|
25
|
+
end
|
40
26
|
|
41
|
-
|
27
|
+
bm.report('each (by f)') do
|
42
28
|
|
43
|
-
|
29
|
+
fm.each_by_frequency do |k, freq|
|
44
30
|
|
45
|
-
|
46
|
-
|
31
|
+
end
|
32
|
+
end
|
47
33
|
end
|
48
34
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#! /usr/bin/env ruby
|
2
2
|
|
3
3
|
$:.unshift File.join(File.dirname(__FILE__), '../../lib')
|
4
4
|
|
@@ -8,24 +8,23 @@ require 'test/unit'
|
|
8
8
|
|
9
9
|
class Test_assert_raise_with_message < Test::Unit::TestCase
|
10
10
|
|
11
|
-
|
11
|
+
class UnusedException < RuntimeError; end
|
12
12
|
|
13
|
-
|
13
|
+
class TestException < RuntimeError; end
|
14
14
|
|
15
|
-
|
15
|
+
def test_1
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
assert_raise_with_message(UnusedException, "abc") { raise TestException, 'abc' }
|
18
|
+
end
|
19
19
|
|
20
|
-
|
20
|
+
def test_2
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
assert_raise_with_message(TestException, "abcd") { raise TestException, 'abc' }
|
23
|
+
end
|
24
24
|
|
25
|
-
|
25
|
+
def test_3
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
assert_raise_with_message(TestException, /abc$/) { raise TestException, 'abcd' }
|
28
|
+
end
|
29
29
|
end
|
30
30
|
|
31
|
-
|
@@ -11,205 +11,203 @@ require 'test/unit'
|
|
11
11
|
|
12
12
|
class Test_Xqsr3_ArrayUtilities_join_with_or_by_module < Test::Unit::TestCase
|
13
13
|
|
14
|
-
|
14
|
+
JoinWithOr = ::Xqsr3::ArrayUtilities::JoinWithOr
|
15
15
|
|
16
|
-
|
16
|
+
def test_default
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
assert_equal '', JoinWithOr.join_with_or([])
|
19
|
+
assert_equal 'a', JoinWithOr.join_with_or([ 'a' ])
|
20
|
+
assert_equal 'a or b', JoinWithOr.join_with_or([ 'a', 'b' ])
|
21
|
+
assert_equal 'a, b, or c', JoinWithOr.join_with_or([ 'a', 'b', 'c' ])
|
22
|
+
assert_equal 'a, b, c, d, e, f, g, h, i, j, k, l, m, or n', JoinWithOr.join_with_or([ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' ])
|
23
|
+
end
|
24
24
|
|
25
|
-
|
25
|
+
def test_with_empty_options
|
26
26
|
|
27
|
-
|
27
|
+
options = {
|
28
28
|
|
29
|
-
|
29
|
+
}
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
31
|
+
assert_equal '', JoinWithOr.join_with_or([], **options)
|
32
|
+
assert_equal 'a', JoinWithOr.join_with_or([ 'a' ], **options)
|
33
|
+
assert_equal 'a or b', JoinWithOr.join_with_or([ 'a', 'b' ], **options)
|
34
|
+
assert_equal 'a, b, or c', JoinWithOr.join_with_or([ 'a', 'b', 'c' ], **options)
|
35
|
+
assert_equal 'a, b, c, d, e, f, g, h, i, j, k, l, m, or n', JoinWithOr.join_with_or([ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' ], **options)
|
36
|
+
end
|
37
37
|
|
38
|
-
|
38
|
+
def test_with_custom_or
|
39
39
|
|
40
|
-
|
40
|
+
options = {
|
41
41
|
|
42
|
-
|
43
|
-
|
42
|
+
:or => 'OR',
|
43
|
+
}
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
assert_equal '', JoinWithOr.join_with_or([], **options)
|
46
|
+
assert_equal 'a', JoinWithOr.join_with_or([ 'a' ], **options)
|
47
|
+
assert_equal 'a OR b', JoinWithOr.join_with_or([ 'a', 'b' ], **options)
|
48
|
+
assert_equal 'a, b, OR c', JoinWithOr.join_with_or([ 'a', 'b', 'c' ], **options)
|
49
|
+
assert_equal 'a, b, c, d, e, f, g, h, i, j, k, l, m, OR n', JoinWithOr.join_with_or([ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' ], **options)
|
50
|
+
end
|
51
51
|
|
52
|
-
|
52
|
+
def test_with_no_oxford
|
53
53
|
|
54
|
-
|
54
|
+
options = {
|
55
55
|
|
56
|
-
|
57
|
-
|
56
|
+
:oxford_comma => false,
|
57
|
+
}
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
59
|
+
assert_equal '', JoinWithOr.join_with_or([], **options)
|
60
|
+
assert_equal 'a', JoinWithOr.join_with_or([ 'a' ], **options)
|
61
|
+
assert_equal 'a or b', JoinWithOr.join_with_or([ 'a', 'b' ], **options)
|
62
|
+
assert_equal 'a, b or c', JoinWithOr.join_with_or([ 'a', 'b', 'c' ], **options)
|
63
|
+
assert_equal 'a, b, c, d, e, f, g, h, i, j, k, l, m or n', JoinWithOr.join_with_or([ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' ], **options)
|
64
|
+
end
|
65
65
|
|
66
|
-
|
66
|
+
def test_with_custom_quote_char
|
67
67
|
|
68
|
-
|
68
|
+
options = {
|
69
69
|
|
70
|
-
|
71
|
-
|
70
|
+
:quote_char => '"',
|
71
|
+
}
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
73
|
+
assert_equal '', JoinWithOr.join_with_or([], **options)
|
74
|
+
assert_equal '"a"', JoinWithOr.join_with_or([ 'a' ], **options)
|
75
|
+
assert_equal '"a" or "b"', JoinWithOr.join_with_or([ 'a', 'b' ], **options)
|
76
|
+
assert_equal '"a", "b", or "c"', JoinWithOr.join_with_or([ 'a', 'b', 'c' ], **options)
|
77
|
+
assert_equal '"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", or "n"', JoinWithOr.join_with_or([ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' ], **options)
|
78
|
+
end
|
79
79
|
|
80
|
-
|
80
|
+
def test_with_custom_separator
|
81
81
|
|
82
|
-
|
82
|
+
options = {
|
83
83
|
|
84
|
-
|
85
|
-
|
84
|
+
:separator => ';',
|
85
|
+
}
|
86
86
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
87
|
+
assert_equal '', JoinWithOr.join_with_or([], **options)
|
88
|
+
assert_equal 'a', JoinWithOr.join_with_or([ 'a' ], **options)
|
89
|
+
assert_equal 'a or b', JoinWithOr.join_with_or([ 'a', 'b' ], **options)
|
90
|
+
assert_equal 'a; b; or c', JoinWithOr.join_with_or([ 'a', 'b', 'c' ], **options)
|
91
|
+
assert_equal 'a; b; c; d; e; f; g; h; i; j; k; l; m; or n', JoinWithOr.join_with_or([ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' ], **options)
|
92
|
+
end
|
93
93
|
|
94
|
-
|
94
|
+
def test_with_custom_flags
|
95
95
|
|
96
|
-
|
96
|
+
options = {
|
97
97
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
98
|
+
:or => 'OR',
|
99
|
+
:oxford_comma => false,
|
100
|
+
:quote_char => '"',
|
101
|
+
:separator => ';',
|
102
|
+
}
|
103
103
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
104
|
+
assert_equal '', JoinWithOr.join_with_or([], **options)
|
105
|
+
assert_equal '"a"', JoinWithOr.join_with_or([ 'a' ], **options)
|
106
|
+
assert_equal '"a" OR "b"', JoinWithOr.join_with_or([ 'a', 'b' ], **options)
|
107
|
+
assert_equal '"a"; "b" OR "c"', JoinWithOr.join_with_or([ 'a', 'b', 'c' ], **options)
|
108
|
+
assert_equal '"a"; "b"; "c"; "d"; "e"; "f"; "g"; "h"; "i"; "j"; "k"; "l"; "m" OR "n"', JoinWithOr.join_with_or([ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' ], **options)
|
109
|
+
end
|
110
110
|
end
|
111
111
|
|
112
112
|
require 'xqsr3/extensions/array/join_with_or'
|
113
113
|
|
114
114
|
class Test_Xqsr3_ArrayUtilities_join_with_or_by_include < Test::Unit::TestCase
|
115
115
|
|
116
|
-
|
116
|
+
include ::Xqsr3::ArrayUtilities::JoinWithOr
|
117
117
|
|
118
|
-
|
118
|
+
def test_default
|
119
119
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
120
|
+
assert_equal '', [].join_with_or
|
121
|
+
assert_equal 'a', [ 'a' ].join_with_or
|
122
|
+
assert_equal 'a or b', [ 'a', 'b' ].join_with_or()
|
123
|
+
assert_equal 'a, b, or c', [ 'a', 'b', 'c' ].join_with_or()
|
124
|
+
assert_equal 'a, b, c, d, e, f, g, h, i, j, k, l, m, or n', [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' ].join_with_or()
|
125
|
+
end
|
126
126
|
|
127
|
-
|
127
|
+
def test_with_empty_options
|
128
128
|
|
129
|
-
|
129
|
+
options = {
|
130
130
|
|
131
|
-
|
131
|
+
}
|
132
132
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
133
|
+
assert_equal '', [].join_with_or(**options)
|
134
|
+
assert_equal 'a', [ 'a' ].join_with_or(**options)
|
135
|
+
assert_equal 'a or b', [ 'a', 'b' ].join_with_or(**options)
|
136
|
+
assert_equal 'a, b, or c', [ 'a', 'b', 'c' ].join_with_or(**options)
|
137
|
+
assert_equal 'a, b, c, d, e, f, g, h, i, j, k, l, m, or n', [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' ].join_with_or(**options)
|
138
|
+
end
|
139
139
|
|
140
|
-
|
140
|
+
def test_with_custom_or
|
141
141
|
|
142
|
-
|
142
|
+
options = {
|
143
143
|
|
144
|
-
|
145
|
-
|
144
|
+
:or => 'OR',
|
145
|
+
}
|
146
146
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
147
|
+
assert_equal '', [].join_with_or(**options)
|
148
|
+
assert_equal 'a', [ 'a' ].join_with_or(**options)
|
149
|
+
assert_equal 'a OR b', [ 'a', 'b' ].join_with_or(**options)
|
150
|
+
assert_equal 'a, b, OR c', [ 'a', 'b', 'c' ].join_with_or(**options)
|
151
|
+
assert_equal 'a, b, c, d, e, f, g, h, i, j, k, l, m, OR n', [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' ].join_with_or(**options)
|
152
|
+
end
|
153
153
|
|
154
|
-
|
154
|
+
def test_with_no_oxford
|
155
155
|
|
156
|
-
|
156
|
+
options = {
|
157
157
|
|
158
|
-
|
159
|
-
|
158
|
+
:oxford_comma => false,
|
159
|
+
}
|
160
160
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
161
|
+
assert_equal '', [].join_with_or(**options)
|
162
|
+
assert_equal 'a', [ 'a' ].join_with_or(**options)
|
163
|
+
assert_equal 'a or b', [ 'a', 'b' ].join_with_or(**options)
|
164
|
+
assert_equal 'a, b or c', [ 'a', 'b', 'c' ].join_with_or(**options)
|
165
|
+
assert_equal 'a, b, c, d, e, f, g, h, i, j, k, l, m or n', [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' ].join_with_or(**options)
|
166
|
+
end
|
167
167
|
|
168
|
-
|
168
|
+
def test_with_custom_quote_char
|
169
169
|
|
170
|
-
|
170
|
+
options = {
|
171
171
|
|
172
|
-
|
173
|
-
|
172
|
+
:quote_char => '"',
|
173
|
+
}
|
174
174
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
175
|
+
assert_equal '', [].join_with_or(**options)
|
176
|
+
assert_equal '"a"', [ 'a' ].join_with_or(**options)
|
177
|
+
assert_equal '"a" or "b"', [ 'a', 'b' ].join_with_or(**options)
|
178
|
+
assert_equal '"a", "b", or "c"', [ 'a', 'b', 'c' ].join_with_or(**options)
|
179
|
+
assert_equal '"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", or "n"', [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' ].join_with_or(**options)
|
180
|
+
end
|
181
181
|
|
182
|
-
|
182
|
+
def test_with_custom_separator
|
183
183
|
|
184
|
-
|
184
|
+
options = {
|
185
185
|
|
186
|
-
|
187
|
-
|
186
|
+
:separator => ';',
|
187
|
+
}
|
188
188
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
189
|
+
assert_equal '', [].join_with_or(**options)
|
190
|
+
assert_equal 'a', [ 'a' ].join_with_or(**options)
|
191
|
+
assert_equal 'a or b', [ 'a', 'b' ].join_with_or(**options)
|
192
|
+
assert_equal 'a; b; or c', [ 'a', 'b', 'c' ].join_with_or(**options)
|
193
|
+
assert_equal 'a; b; c; d; e; f; g; h; i; j; k; l; m; or n', [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' ].join_with_or(**options)
|
194
|
+
end
|
195
195
|
|
196
|
-
|
196
|
+
def test_with_custom_flags
|
197
197
|
|
198
|
-
|
198
|
+
options = {
|
199
199
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
200
|
+
:or => 'OR',
|
201
|
+
:oxford_comma => false,
|
202
|
+
:quote_char => '"',
|
203
|
+
:separator => ';',
|
204
|
+
}
|
205
205
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
206
|
+
assert_equal '', [].join_with_or(**options)
|
207
|
+
assert_equal '"a"', [ 'a' ].join_with_or(**options)
|
208
|
+
assert_equal '"a" OR "b"', [ 'a', 'b' ].join_with_or(**options)
|
209
|
+
assert_equal '"a"; "b" OR "c"', [ 'a', 'b', 'c' ].join_with_or(**options)
|
210
|
+
assert_equal '"a"; "b"; "c"; "d"; "e"; "f"; "g"; "h"; "i"; "j"; "k"; "l"; "m" OR "n"', [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' ].join_with_or(**options)
|
211
|
+
end
|
212
212
|
end
|
213
213
|
|
214
|
-
|
215
|
-
|
@@ -11,34 +11,34 @@ include ::Xqsr3::CommandLineUtilities
|
|
11
11
|
|
12
12
|
class Test_Xqsr3_CommandLineUtilities_map_option_string < Test::Unit::TestCase
|
13
13
|
|
14
|
-
|
14
|
+
def test_simple_uses
|
15
15
|
|
16
|
-
|
16
|
+
assert_nil MapOptionString.map_option_string_from_string 'abc', [ 'option-1', 'option-2' ]
|
17
17
|
|
18
|
-
|
18
|
+
assert_equal :abc, MapOptionString.map_option_string_from_string('abc', [ 'abc' ])
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
assert_equal :option_1, MapOptionString.map_option_string_from_string('option-1', [ 'option-1', 'option-2' ])
|
21
|
+
end
|
22
22
|
|
23
|
-
|
23
|
+
def test_shortcuts
|
24
24
|
|
25
|
-
|
25
|
+
option_strings = [ '[n]ame-only', '[f]ull-[p]ath' ]
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
assert_equal :name_only, MapOptionString.map_option_string_from_string('name-only', option_strings)
|
28
|
+
assert_equal :full_path, MapOptionString.map_option_string_from_string('full-path', option_strings)
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
assert_equal :name_only, MapOptionString.map_option_string_from_string('n', option_strings)
|
31
|
+
assert_equal :full_path, MapOptionString.map_option_string_from_string('fp', option_strings)
|
32
32
|
|
33
|
-
|
33
|
+
%w{ a m e - o l y u l p a t h }.each do |shortcut|
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
assert_nil MapOptionString.map_option_string_from_string(shortcut, option_strings)
|
36
|
+
end
|
37
|
+
end
|
38
38
|
|
39
|
-
|
39
|
+
def test_nil
|
40
40
|
|
41
|
-
|
42
|
-
|
41
|
+
assert_nil nil.map_option_string []
|
42
|
+
end
|
43
43
|
end
|
44
44
|
|