xqsr3 0.38.2 → 0.39.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 +15 -6
- data/examples/count_word_frequencies.md +12 -12
- data/examples/count_word_frequencies.rb +4 -4
- data/lib/xqsr3/array_utilities/join_with_or.rb +47 -47
- data/lib/xqsr3/array_utilities.rb +2 -2
- data/lib/xqsr3/command_line_utilities/map_option_string.rb +60 -60
- data/lib/xqsr3/command_line_utilities.rb +2 -2
- data/lib/xqsr3/containers/frequency_map.rb +399 -399
- data/lib/xqsr3/containers/multi_map.rb +448 -448
- data/lib/xqsr3/containers.rb +3 -3
- data/lib/xqsr3/conversion/bool_parser.rb +51 -51
- data/lib/xqsr3/conversion/integer_parser.rb +87 -87
- data/lib/xqsr3/conversion.rb +3 -3
- data/lib/xqsr3/diagnostics/exception_utilities.rb +145 -145
- data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +90 -90
- data/lib/xqsr3/diagnostics/inspect_builder.rb +80 -80
- data/lib/xqsr3/diagnostics.rb +3 -3
- data/lib/xqsr3/doc_.rb +130 -130
- data/lib/xqsr3/extensions/array/join_with_or.rb +9 -9
- data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +12 -12
- data/lib/xqsr3/extensions/enumerable/detect_map.rb +35 -35
- data/lib/xqsr3/extensions/enumerable/unique.rb +29 -28
- 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 +28 -28
- data/lib/xqsr3/extensions/kernel/integer.rb +20 -20
- data/lib/xqsr3/extensions/kernel/raise_with_options.rb +8 -8
- 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 -4
- 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 -1
- data/lib/xqsr3/extensions/string/starts_with.rb +1 -1
- data/lib/xqsr3/extensions/string/to_bool.rb +8 -8
- data/lib/xqsr3/extensions/string/to_symbol.rb +1 -1
- data/lib/xqsr3/extensions/string/truncate.rb +1 -1
- data/lib/xqsr3/extensions/test/unit/assert_eql.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_false.rb +9 -6
- data/lib/xqsr3/extensions/test/unit/assert_not.rb +9 -6
- data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +61 -61
- data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_true.rb +9 -6
- data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +39 -36
- data/lib/xqsr3/extensions.rb +5 -5
- data/lib/xqsr3/hash_utilities/deep_transform.rb +65 -65
- data/lib/xqsr3/hash_utilities/key_matching.rb +77 -77
- data/lib/xqsr3/hash_utilities.rb +3 -3
- data/lib/xqsr3/internal_/test_unit_version_.rb +83 -83
- data/lib/xqsr3/io/writelines.rb +122 -120
- data/lib/xqsr3/quality/parameter_checking.rb +445 -445
- data/lib/xqsr3/quality.rb +2 -2
- data/lib/xqsr3/string_utilities/ends_with.rb +59 -59
- data/lib/xqsr3/string_utilities/nil_if_empty.rb +28 -28
- data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +29 -29
- data/lib/xqsr3/string_utilities/quote_if.rb +50 -50
- data/lib/xqsr3/string_utilities/starts_with.rb +59 -59
- data/lib/xqsr3/string_utilities/to_symbol.rb +75 -75
- data/lib/xqsr3/string_utilities/truncate.rb +55 -55
- data/lib/xqsr3/string_utilities.rb +8 -8
- data/lib/xqsr3/version.rb +12 -12
- data/test/performance/frequency_map.rb +12 -12
- data/test/scratch/test_assert_raise_with_message.rb +11 -11
- data/test/unit/array_utilities/tc_join_with_or.rb +140 -140
- data/test/unit/command_line_utilities/tc_map_option_string.rb +18 -18
- data/test/unit/containers/tc_frequency_map.rb +591 -591
- data/test/unit/containers/tc_multi_map.rb +558 -558
- data/test/unit/conversion/tc_integer_parser.rb +72 -72
- data/test/unit/conversion/tc_to_bool.rb +25 -25
- 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_slice.rb +13 -13
- 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 +149 -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 +50 -50
- 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 +166 -106
- data/test/unit/quality/tc_parameter_checking.rb +389 -389
- data/test/unit/string_utilities/tc_truncate.rb +27 -27
- data/test/unit/tc_version.rb +15 -15
- metadata +6 -2
@@ -11,57 +11,57 @@ require 'stringio'
|
|
11
11
|
|
12
12
|
class Test_Hash_except < Test::Unit::TestCase
|
13
13
|
|
14
|
-
|
14
|
+
def test_no_pairs_empty_keys
|
15
15
|
|
16
|
-
|
16
|
+
h = {}
|
17
17
|
|
18
|
-
|
18
|
+
assert_equal h, h.except([])
|
19
19
|
|
20
|
-
|
20
|
+
i = {}
|
21
21
|
|
22
|
-
|
22
|
+
i.except!(*[])
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
assert_equal h, i
|
25
|
+
end
|
26
26
|
|
27
|
-
|
27
|
+
def test_no_pairs_some_keys
|
28
28
|
|
29
|
-
|
29
|
+
h = {}
|
30
30
|
|
31
|
-
|
31
|
+
assert_equal h, h.except('a', :b)
|
32
32
|
|
33
|
-
|
33
|
+
i = {}
|
34
34
|
|
35
|
-
|
35
|
+
i.except! 'a', :b
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
assert_equal h, i
|
38
|
+
end
|
39
39
|
|
40
|
-
|
40
|
+
def test_no_pairs_some_non_matching_keys
|
41
41
|
|
42
|
-
|
42
|
+
h = { a: 'a', 'b' => :b }
|
43
43
|
|
44
|
-
|
44
|
+
assert_equal h, h.except('a', :b)
|
45
45
|
|
46
|
-
|
46
|
+
i = h.dup
|
47
47
|
|
48
|
-
|
48
|
+
i.except! 'a', :b
|
49
49
|
|
50
|
-
|
51
|
-
|
50
|
+
assert_equal h, i
|
51
|
+
end
|
52
52
|
|
53
|
-
|
53
|
+
def test_no_pairs_some_matching_keys
|
54
54
|
|
55
|
-
|
55
|
+
h = { a: 'a', 'b' => :b }
|
56
56
|
|
57
|
-
|
57
|
+
assert_equal ({ 'b' => :b }), h.except(:a, :b, :c)
|
58
58
|
|
59
|
-
|
59
|
+
i = h.dup
|
60
60
|
|
61
|
-
|
61
|
+
i.except! :a, :b, :c
|
62
62
|
|
63
|
-
|
64
|
-
|
63
|
+
assert_equal ({ 'b' => :b }), i
|
64
|
+
end
|
65
65
|
end
|
66
66
|
|
67
67
|
|
@@ -6,26 +6,26 @@ require 'xqsr3/extensions/hash/slice'
|
|
6
6
|
|
7
7
|
class Test_Hash_slice < Test::Unit::TestCase
|
8
8
|
|
9
|
-
|
9
|
+
def test_empty
|
10
10
|
|
11
|
-
|
11
|
+
assert_equal ({}), ({}.slice())
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
assert_equal ({}), ({}.slice(:abc, 'def'))
|
14
|
+
end
|
15
15
|
|
16
|
-
|
16
|
+
def test_none_matching
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
assert_equal ({}), ({ abc: 'abc', 'def' => :def }.slice())
|
19
|
+
end
|
20
20
|
|
21
|
-
|
21
|
+
def test_all_matching
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
assert_equal ({ abc: 'abc', 'def' => :def }), ({ abc: 'abc', 'def' => :def }.slice(:abc, 'def'))
|
24
|
+
end
|
25
25
|
|
26
|
-
|
26
|
+
def test_some_matching
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
assert_equal ({ abc: 'abc' }), ({ abc: 'abc', 'def' => :def }.slice(:abc, 'ghi'))
|
29
|
+
end
|
30
30
|
end
|
31
31
|
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '../../../../lib')
|
4
|
+
|
5
|
+
require 'xqsr3/extensions/integer/to_s_grp'
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class Test_X_Integer_to_s_grp < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def test_no_args
|
12
|
+
|
13
|
+
assert_equal "87654321", 87654321.to_s_grp
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_single_number
|
17
|
+
|
18
|
+
assert_equal "87,654,321", 87654321.to_s_grp(3)
|
19
|
+
assert_equal "87,65,43,21", 87654321.to_s_grp(2)
|
20
|
+
assert_equal "8,7,6,5,4,3,2,1", 87654321.to_s_grp(1)
|
21
|
+
|
22
|
+
assert_equal "876,54321", 87654321.to_s_grp(5)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_array_with_single_number
|
26
|
+
|
27
|
+
assert_equal "87,654,321", 87654321.to_s_grp([3])
|
28
|
+
assert_equal "87,65,43,21", 87654321.to_s_grp([2])
|
29
|
+
assert_equal "8,7,6,5,4,3,2,1", 87654321.to_s_grp([1])
|
30
|
+
|
31
|
+
assert_equal "876,54321", 87654321.to_s_grp([5])
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_with_multiple_numbers
|
35
|
+
|
36
|
+
assert_equal "87,654,321", 87654321.to_s_grp(3, 3)
|
37
|
+
assert_equal "87,65,43,21", 87654321.to_s_grp(2, 2, 2)
|
38
|
+
assert_equal "8,7,6,5,4,3,2,1", 87654321.to_s_grp(1, 1, 1, 1, 1, 1, 1)
|
39
|
+
|
40
|
+
assert_equal "876,54321", 87654321.to_s_grp(5, 5)
|
41
|
+
|
42
|
+
assert_equal "8,76,54,321", 87654321.to_s_grp(3, 2, 2)
|
43
|
+
assert_equal "8,76,54,321", 87654321.to_s_grp(3, 2)
|
44
|
+
assert_equal "8,76,543,21", 87654321.to_s_grp(2, 3, 2)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_array_with_multiple_numbers
|
48
|
+
|
49
|
+
assert_equal "87,654,321", 87654321.to_s_grp([3, 3])
|
50
|
+
assert_equal "87,65,43,21", 87654321.to_s_grp([2, 2, 2])
|
51
|
+
assert_equal "8,7,6,5,4,3,2,1", 87654321.to_s_grp([1, 1, 1, 1, 1, 1, 1])
|
52
|
+
|
53
|
+
assert_equal "876,54321", 87654321.to_s_grp([5, 5])
|
54
|
+
|
55
|
+
assert_equal "8,76,54,321", 87654321.to_s_grp([3, 2, 2])
|
56
|
+
assert_equal "8,76,54,321", 87654321.to_s_grp([3, 2])
|
57
|
+
assert_equal "8,76,543,21", 87654321.to_s_grp([2, 3, 2])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -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
|
+
|
@@ -10,137 +10,209 @@ require 'stringio'
|
|
10
10
|
|
11
11
|
class Test_IO_writelines < Test::Unit::TestCase
|
12
12
|
|
13
|
-
|
13
|
+
def test_single_string
|
14
14
|
|
15
|
-
|
15
|
+
input = 'abc'
|
16
16
|
|
17
|
-
|
17
|
+
s = StringIO.new '', 'a'
|
18
18
|
|
19
|
-
|
19
|
+
r = ::IO.writelines s, input
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
assert_equal 1, r
|
22
|
+
assert_equal "abc\n", s.string
|
23
|
+
end
|
24
24
|
|
25
|
-
|
25
|
+
def test_single_string_nolasteol
|
26
26
|
|
27
|
-
|
27
|
+
input = 'abc'
|
28
28
|
|
29
|
-
|
29
|
+
s = StringIO.new '', 'a'
|
30
30
|
|
31
|
-
|
31
|
+
r = ::IO.writelines s, input, no_last_eol: true
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
assert_equal 1, r
|
34
|
+
assert_equal "abc", s.string
|
35
|
+
end
|
36
36
|
|
37
|
-
|
37
|
+
def test_single_string_in_array
|
38
38
|
|
39
|
-
|
39
|
+
input = [ 'abc' ]
|
40
40
|
|
41
|
-
|
41
|
+
s = StringIO.new '', 'a'
|
42
42
|
|
43
|
-
|
43
|
+
r = ::IO.writelines s, input
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
assert_equal 1, r
|
46
|
+
assert_equal "abc\n", s.string
|
47
|
+
end
|
48
48
|
|
49
|
-
|
49
|
+
def test_single_string_in_hash
|
50
50
|
|
51
|
-
|
51
|
+
input = { 'abc' => '' }
|
52
52
|
|
53
|
-
|
53
|
+
s = StringIO.new '', 'a'
|
54
54
|
|
55
|
-
|
55
|
+
r = ::IO.writelines s, input
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
assert_equal 1, r
|
58
|
+
assert_equal "abc\n", s.string
|
59
|
+
end
|
60
60
|
|
61
|
-
|
61
|
+
def test_single_string_in_hash_nolasteol
|
62
62
|
|
63
|
-
|
63
|
+
input = { 'abc' => '' }
|
64
64
|
|
65
|
-
|
65
|
+
s = StringIO.new '', 'a'
|
66
66
|
|
67
|
-
|
67
|
+
r = ::IO.writelines s, input, no_last_eol: true
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
69
|
+
assert_equal 1, r
|
70
|
+
assert_equal "abc", s.string
|
71
|
+
end
|
72
72
|
|
73
|
-
|
73
|
+
def test_two_strings_in_array
|
74
74
|
|
75
|
-
|
75
|
+
input = [ 'abc', 'def' ]
|
76
76
|
|
77
|
-
|
77
|
+
s = StringIO.new '', 'a'
|
78
78
|
|
79
|
-
|
79
|
+
r = ::IO.writelines s, input
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
81
|
+
assert_equal 2, r
|
82
|
+
assert_equal "abc\ndef\n", s.string
|
83
|
+
end
|
84
84
|
|
85
|
-
|
85
|
+
def test_two_strings_in_array_with_suppressed_eol
|
86
86
|
|
87
|
-
|
87
|
+
input = [ 'abc', 'def' ]
|
88
88
|
|
89
|
-
|
89
|
+
s = StringIO.new '', 'a'
|
90
90
|
|
91
|
-
|
91
|
+
r = ::IO.writelines s, input, ''
|
92
92
|
|
93
|
-
|
94
|
-
|
95
|
-
|
93
|
+
assert_equal 2, r
|
94
|
+
assert_equal "abcdef", s.string
|
95
|
+
end
|
96
96
|
|
97
|
-
|
97
|
+
def test_two_strings_in_hash
|
98
98
|
|
99
|
-
|
99
|
+
input = { 'ab' => 'c', 'de' => 'f' }
|
100
100
|
|
101
|
-
|
101
|
+
s = StringIO.new '', 'a'
|
102
102
|
|
103
|
-
|
103
|
+
r = ::IO.writelines s, input
|
104
104
|
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
assert_equal 2, r
|
106
|
+
assert_equal "abc\ndef\n", s.string
|
107
|
+
end
|
108
108
|
|
109
|
-
|
109
|
+
def test_two_strings_in_hash_nolasteol
|
110
110
|
|
111
|
-
|
111
|
+
input = { 'ab' => 'c', 'de' => 'f' }
|
112
112
|
|
113
|
-
|
113
|
+
s = StringIO.new '', 'a'
|
114
114
|
|
115
|
-
|
115
|
+
r = ::IO.writelines s, input, no_last_eol: true
|
116
116
|
|
117
|
-
|
118
|
-
|
119
|
-
|
117
|
+
assert_equal 2, r
|
118
|
+
assert_equal "abc\ndef", s.string
|
119
|
+
end
|
120
120
|
|
121
|
-
|
121
|
+
def test_two_strings_in_hash_with_col_sep
|
122
122
|
|
123
|
-
|
123
|
+
input = { 'ab' => 'c', 'de' => 'f' }
|
124
124
|
|
125
|
-
|
125
|
+
s = StringIO.new '', 'a'
|
126
126
|
|
127
|
-
|
127
|
+
r = ::IO.writelines s, input, column_separator: "\t"
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
|
129
|
+
assert_equal 2, r
|
130
|
+
assert_equal "ab\tc\nde\tf\n", s.string
|
131
|
+
end
|
132
132
|
|
133
|
-
|
133
|
+
def test_two_strings_in_hash_with_line_sep
|
134
134
|
|
135
|
-
|
135
|
+
input = { 'ab' => 'c', 'de' => 'f' }
|
136
136
|
|
137
|
-
|
137
|
+
s = StringIO.new '', 'a'
|
138
138
|
|
139
|
-
|
139
|
+
r = ::IO.writelines s, input, line_separator: '+'
|
140
140
|
|
141
|
-
|
142
|
-
|
143
|
-
|
141
|
+
assert_equal 2, r
|
142
|
+
assert_equal "abc+def+", s.string
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_two_strings_in_hash_with_line_sep_and_col_sep
|
146
|
+
|
147
|
+
input = { 'ab' => 'c', 'de' => 'f' }
|
148
|
+
|
149
|
+
s = StringIO.new '', 'a'
|
150
|
+
|
151
|
+
r = ::IO.writelines s, input, line_separator: '+', column_separator: "\t"
|
152
|
+
|
153
|
+
assert_equal 2, r
|
154
|
+
assert_equal "ab\tc+de\tf+", s.string
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_two_strings_in_hash_with_line_sep_and_col_sep_and_nolasteol
|
158
|
+
|
159
|
+
input = { 'ab' => 'c', 'de' => 'f' }
|
160
|
+
|
161
|
+
s = StringIO.new '', 'a'
|
162
|
+
|
163
|
+
r = ::IO.writelines s, input, line_separator: '+', column_separator: "\t", no_last_eol: true
|
164
|
+
|
165
|
+
assert_equal 2, r
|
166
|
+
assert_equal "ab\tc+de\tf", s.string
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_two_strings_in_hash_with_arguments_of_line_sep
|
170
|
+
|
171
|
+
input = { 'ab' => 'c', 'de' => 'f' }
|
172
|
+
|
173
|
+
s = StringIO.new '', 'a'
|
174
|
+
|
175
|
+
r = ::IO.writelines s, input, '+'
|
176
|
+
|
177
|
+
assert_equal 2, r
|
178
|
+
assert_equal "abc+def+", s.string
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_two_strings_in_hash_with_arguments_of_line_sep_and_col_sep
|
182
|
+
|
183
|
+
input = { 'ab' => 'c', 'de' => 'f' }
|
184
|
+
|
185
|
+
s = StringIO.new '', 'a'
|
186
|
+
|
187
|
+
r = ::IO.writelines s, input, '+', '-'
|
188
|
+
|
189
|
+
assert_equal 2, r
|
190
|
+
assert_equal "ab-c+de-f+", s.string
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_ten_strings_in_array
|
194
|
+
|
195
|
+
input = (0...10).map { |i| i.to_s }
|
196
|
+
|
197
|
+
s = StringIO.new
|
198
|
+
|
199
|
+
r = ::IO.writelines s, input
|
200
|
+
|
201
|
+
assert_equal 10, r
|
202
|
+
assert_equal "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n", s.string
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_strings_with_cr_in_array
|
206
|
+
|
207
|
+
input = [ "abc\n", "def\n", "ghi\n" ]
|
208
|
+
|
209
|
+
s = StringIO.new
|
210
|
+
|
211
|
+
r = ::IO.writelines s, input
|
212
|
+
|
213
|
+
assert_equal 3, r
|
214
|
+
assert_equal "abc\ndef\nghi\n", s.string
|
215
|
+
end
|
144
216
|
end
|
145
217
|
|
146
218
|
|
@@ -10,81 +10,81 @@ require 'test/unit'
|
|
10
10
|
|
11
11
|
class Test_X_Kernel_Integer < Test::Unit::TestCase
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
13
|
+
class SomeRandomException < Exception; end
|
14
|
+
|
15
|
+
def test_Integer_with_valid_values
|
16
|
+
|
17
|
+
assert_equal(0, Integer(0))
|
18
|
+
assert_equal(+1, Integer(1))
|
19
|
+
assert_equal(+1, Integer(+1))
|
20
|
+
assert_equal(-1, Integer(-1))
|
21
|
+
|
22
|
+
assert_equal(0, Integer('0'))
|
23
|
+
assert_equal(+1, Integer('1'))
|
24
|
+
assert_equal(+1, Integer('+1'))
|
25
|
+
assert_equal(-1, Integer('-1'))
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_Integer_with_invalid_values
|
29
|
+
|
30
|
+
assert_raise(TypeError) { Integer nil }
|
31
|
+
assert_raise(ArgumentError) { Integer '' }
|
32
|
+
assert_raise(ArgumentError) { Integer 'abc' }
|
33
|
+
assert_raise(ArgumentError) { Integer 'zero' }
|
34
|
+
assert_raise(ArgumentError) { Integer 'plus 1' }
|
35
|
+
assert_raise(ArgumentError) { Integer '/0' }
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_Integer_with_invalid_values_returning_nil
|
39
|
+
|
40
|
+
assert_nil Integer(nil, nil: true)
|
41
|
+
assert_nil Integer('', nil: true)
|
42
|
+
assert_nil Integer('abc', nil: true)
|
43
|
+
assert_nil Integer('zero', nil: true)
|
44
|
+
assert_nil Integer('plus 1', nil: true)
|
45
|
+
assert_nil Integer('/0', nil: true)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_Integer_with_invalid_values_returning_0
|
49
|
+
|
50
|
+
assert_equal 0, Integer(nil, default: 0)
|
51
|
+
assert_equal 0, Integer('', default: 0)
|
52
|
+
assert_equal 0, Integer('abc', default: 0)
|
53
|
+
assert_equal 0, Integer('zero', default: 0)
|
54
|
+
assert_equal 0, Integer('plus 1', default: 0)
|
55
|
+
assert_equal 0, Integer('/0', default: 0)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_Integer_with_invalid_values_returning_sentinel
|
59
|
+
|
60
|
+
assert_equal :sentinel, Integer(nil, default: :sentinel)
|
61
|
+
assert_equal :sentinel, Integer('', default: :sentinel)
|
62
|
+
assert_equal :sentinel, Integer('abc', default: :sentinel)
|
63
|
+
assert_equal :sentinel, Integer('zero', default: :sentinel)
|
64
|
+
assert_equal :sentinel, Integer('plus 1', default: :sentinel)
|
65
|
+
assert_equal :sentinel, Integer('/0', default: :sentinel)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_Integer_with_invalid_values_returning_sentinel_of_nil
|
69
|
+
|
70
|
+
assert_equal nil, Integer(nil, default: nil)
|
71
|
+
assert_equal nil, Integer('', default: nil)
|
72
|
+
assert_equal nil, Integer('abc', default: nil)
|
73
|
+
assert_equal nil, Integer('zero', default: nil)
|
74
|
+
assert_equal nil, Integer('plus 1', default: nil)
|
75
|
+
assert_equal nil, Integer('/0', default: nil)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_Integer_with_invalid_values_and_block
|
79
|
+
|
80
|
+
assert_equal nil, Integer(nil) { nil }
|
81
|
+
assert_equal nil, Integer('blah') { nil }
|
82
|
+
|
83
|
+
assert_equal 'one', Integer(nil) { 'one' }
|
84
|
+
assert_equal 'one', Integer('blah') { 'one' }
|
85
|
+
|
86
|
+
assert_raise(SomeRandomException) { Integer(nil) { raise SomeRandomException.new } }
|
87
|
+
end
|
88
88
|
end
|
89
89
|
|
90
90
|
|