riel 1.1.17 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,21 +4,96 @@
4
4
  require 'test/unit'
5
5
  require 'riel/enumerable'
6
6
 
7
+ class Range
8
+ include RIEL::EnumerableExt
9
+ end
10
+
11
+ class Array
12
+ include RIEL::EnumerableExt
13
+ end
14
+
7
15
  class EnumerableTestCase < Test::Unit::TestCase
8
- def test_collect_with_index
9
- assert_equal [ 0, 5, 12, 21, 32 ], (4 .. 8).collect_with_index { |val, idx| val * idx }
10
- assert_equal [ "", "b", "cc", "ddd" ], ('a' .. 'd').collect_with_index { |str, idx| str * idx }
16
+ def setup
17
+ @range = (4 .. 8)
18
+ end
19
+
20
+ def as_range
21
+ @range
22
+ end
23
+
24
+ def as_array
25
+ @range.to_a
26
+ end
27
+
28
+ def run_collect_with_index_test enum
29
+ assert_equal [ 0, 5, 12, 21, 32 ], enum.collect_with_index { |val, idx| val * idx }, "enum: #{enum.class}"
30
+ end
31
+
32
+ def test_array_collect_with_index
33
+ run_collect_with_index_test as_array
34
+ end
35
+
36
+ def test_range_collect_with_index
37
+ run_collect_with_index_test as_range
38
+ end
39
+
40
+ def run_select_with_index_multi_test enum
41
+ assert_equal [ 5, 6, 7, 8 ], enum.select_with_index { |val, idx| val >= 5 }, "enum: #{enum.class}"
42
+ end
43
+
44
+ def run_select_with_index_single_test enum
45
+ assert_equal [ 6 ], enum.select_with_index { |val, idx| val * idx == 12 }, "enum: #{enum.class}"
46
+ end
47
+
48
+ def run_select_with_index_none_test enum
49
+ assert_equal [], enum.select_with_index { |val, idx| idx - val > 0 }
11
50
  end
12
51
 
13
- def test_select_with_index
14
- assert_equal [ 5, 6, 7, 8 ], (4 .. 8).select_with_index { |val, idx| val >= 5 }
15
- assert_equal [ 6 ], (4 .. 8).select_with_index { |val, idx| val * idx == 12 }
16
- assert_equal [], (4 .. 8).select_with_index { |val, idx| idx - val > 0 }
52
+ def test_array_select_with_index_multi
53
+ run_select_with_index_multi_test as_array
54
+ end
55
+
56
+ def test_array_select_with_index_single
57
+ run_select_with_index_single_test as_array
58
+ end
59
+
60
+ def test_array_select_with_index_none
61
+ run_select_with_index_none_test as_array
62
+ end
63
+
64
+ def test_range_select_with_index_multi
65
+ run_select_with_index_multi_test as_range
66
+ end
67
+
68
+ def test_range_select_with_index_single
69
+ run_select_with_index_single_test as_range
70
+ end
71
+
72
+ def test_range_select_with_index_none
73
+ run_select_with_index_none_test as_range
74
+ end
75
+
76
+ def run_detect_with_index_match_test enum
77
+ assert_equal 5, enum.detect_with_index { |val, idx| val >= 5 }
78
+ end
79
+
80
+ def run_detect_with_index_no_match_test enum
81
+ assert_equal nil, enum.detect_with_index { |val, idx| idx - val > 0 }
82
+ end
83
+
84
+ def test_array_detect_with_index_match
85
+ run_detect_with_index_match_test as_array
86
+ end
87
+
88
+ def test_array_detect_with_index_no_match
89
+ run_detect_with_index_no_match_test as_array
90
+ end
91
+
92
+ def test_range_detect_with_index_match
93
+ run_detect_with_index_match_test as_range
17
94
  end
18
95
 
19
- def test_detect_with_index
20
- assert_equal 5, (4 .. 8).detect_with_index { |val, idx| val >= 5 }
21
- assert_equal 6, (4 .. 8).detect_with_index { |val, idx| val * idx == 12 }
22
- assert_equal nil, (4 .. 8).detect_with_index { |val, idx| idx - val > 0 }
96
+ def test_range_detect_with_index_no_match
97
+ run_detect_with_index_no_match_test as_range
23
98
  end
24
99
  end
@@ -19,4 +19,10 @@ class RegexpTestCase < Test::Unit::TestCase
19
19
  assert NegatedRegexp.new("a[b-z]").match("aa")
20
20
  assert NegatedRegexp.new(".+").match("")
21
21
  end
22
+
23
+ def test_invalid_whole_word
24
+ assert_raises(RuntimeError) do
25
+ re = Regexp.create ':abc', wholewords: true
26
+ end
27
+ end
22
28
  end
@@ -39,7 +39,7 @@ class SizeConverterTestCase < Test::Unit::TestCase
39
39
  assert_equal data[offset + didx], conv, "size index: #{sidx}; data index: #{didx}; offset: #{offset}; decimal_places: #{dec_places}"
40
40
  end
41
41
 
42
- def run_test cls, offset
42
+ def run_size_test cls, offset
43
43
  SIZES.each_with_index do |data, sidx|
44
44
  assert_conversion cls, data, offset, 1, sidx
45
45
  (0 .. 2).each do |dec_places|
@@ -49,14 +49,14 @@ class SizeConverterTestCase < Test::Unit::TestCase
49
49
  end
50
50
 
51
51
  def test_default
52
- run_test SizeConverter, 0
52
+ run_size_test SizeConverter, 0
53
53
  end
54
54
 
55
55
  def test_human
56
- run_test SizeConverter::Human, 0
56
+ run_size_test SizeConverter::Human, 0
57
57
  end
58
58
 
59
59
  def test_si
60
- run_test SizeConverter::SI, 3
60
+ run_size_test SizeConverter::SI, 3
61
61
  end
62
62
  end
@@ -5,12 +5,12 @@ require 'pathname'
5
5
  require 'test/unit'
6
6
  require 'riel/string'
7
7
 
8
+ class String
9
+ include RIEL::StringExt
10
+ end
11
+
8
12
  class StringToRangeTestCase < Test::Unit::TestCase
9
13
  def run_string_to_range_test exp, str, args = Hash.new
10
- String.to_ranges(str, args).each_with_index do |rg, idx|
11
- assert_equal exp[idx], rg
12
- end
13
-
14
14
  str.to_ranges(args).each_with_index do |rg, idx|
15
15
  assert_equal exp[idx], rg
16
16
  end
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.17
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jeff Pace
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-05 00:00:00.000000000 Z
11
+ date: 2013-10-20 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rainbow
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 1.1.4
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 1.1.4
30
27
  description: This library extends the core Ruby libraries.
@@ -35,7 +32,6 @@ extra_rdoc_files:
35
32
  - README.md
36
33
  files:
37
34
  - lib/riel.rb
38
- - lib/riel/array.rb
39
35
  - lib/riel/command.rb
40
36
  - lib/riel/date.rb
41
37
  - lib/riel/dir.rb
@@ -47,13 +43,7 @@ files:
47
43
  - lib/riel/hash.rb
48
44
  - lib/riel/integer.rb
49
45
  - lib/riel/io.rb
50
- - lib/riel/log.rb
51
- - lib/riel/log/log.rb
52
- - lib/riel/log/loggable.rb
53
- - lib/riel/log/logger.rb
54
- - lib/riel/log/severity.rb
55
46
  - lib/riel/matchdata.rb
56
- - lib/riel/optproc.rb
57
47
  - lib/riel/pathname.rb
58
48
  - lib/riel/rcfile.rb
59
49
  - lib/riel/regexp.rb
@@ -62,7 +52,6 @@ files:
62
52
  - lib/riel/string.rb
63
53
  - lib/riel/tempfile.rb
64
54
  - lib/riel/timer.rb
65
- - test/riel/array_test.rb
66
55
  - test/riel/command_test.rb
67
56
  - test/riel/date_test.rb
68
57
  - test/riel/dir_test.rb
@@ -73,9 +62,7 @@ files:
73
62
  - test/riel/hash_test.rb
74
63
  - test/riel/integer_test.rb
75
64
  - test/riel/io_test.rb
76
- - test/riel/log/format_test.rb
77
65
  - test/riel/matchdata_test.rb
78
- - test/riel/optproc_test.rb
79
66
  - test/riel/pathname_test.rb
80
67
  - test/riel/rcfile_test.rb
81
68
  - test/riel/regexp_test.rb
@@ -83,37 +70,32 @@ files:
83
70
  - test/riel/size_converter_test.rb
84
71
  - test/riel/string_test.rb
85
72
  - test/riel/tempfile_test.rb
86
- - test/riel/testlog/log_stack_test.rb
87
- - test/riel/testlog/log_test.rb
88
- - test/riel/testlog/loggable_test.rb
89
73
  - test/riel/timer_test.rb
90
74
  - README.md
91
75
  homepage: http://www.incava.org/projects/riel
92
76
  licenses: []
77
+ metadata: {}
93
78
  post_install_message:
94
79
  rdoc_options: []
95
80
  require_paths:
96
81
  - lib
97
82
  required_ruby_version: !ruby/object:Gem::Requirement
98
- none: false
99
83
  requirements:
100
- - - ! '>='
84
+ - - '>='
101
85
  - !ruby/object:Gem::Version
102
86
  version: '0'
103
87
  required_rubygems_version: !ruby/object:Gem::Requirement
104
- none: false
105
88
  requirements:
106
- - - ! '>='
89
+ - - '>='
107
90
  - !ruby/object:Gem::Version
108
91
  version: '0'
109
92
  requirements: []
110
93
  rubyforge_project:
111
- rubygems_version: 1.8.23
94
+ rubygems_version: 2.0.6
112
95
  signing_key:
113
- specification_version: 3
96
+ specification_version: 4
114
97
  summary: Extensions to core Ruby code.
115
98
  test_files:
116
- - test/riel/array_test.rb
117
99
  - test/riel/command_test.rb
118
100
  - test/riel/date_test.rb
119
101
  - test/riel/dir_test.rb
@@ -124,9 +106,7 @@ test_files:
124
106
  - test/riel/hash_test.rb
125
107
  - test/riel/integer_test.rb
126
108
  - test/riel/io_test.rb
127
- - test/riel/log/format_test.rb
128
109
  - test/riel/matchdata_test.rb
129
- - test/riel/optproc_test.rb
130
110
  - test/riel/pathname_test.rb
131
111
  - test/riel/rcfile_test.rb
132
112
  - test/riel/regexp_test.rb
@@ -134,7 +114,4 @@ test_files:
134
114
  - test/riel/size_converter_test.rb
135
115
  - test/riel/string_test.rb
136
116
  - test/riel/tempfile_test.rb
137
- - test/riel/testlog/log_stack_test.rb
138
- - test/riel/testlog/log_test.rb
139
- - test/riel/testlog/loggable_test.rb
140
117
  - test/riel/timer_test.rb
data/lib/riel/array.rb DELETED
@@ -1,19 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- # -*- ruby -*-
3
-
4
- class Array
5
- $-w = false
6
-
7
- # Wraps the array with brackets, and inserts a comma and a space between
8
- # elements.
9
-
10
- def to_s
11
- "[ " + collect { |e| e.to_s }.join(", ") + " ]"
12
- end
13
- $-w = true
14
-
15
- # $$$ this is the same as Array.sample
16
- def rand
17
- return self[Kernel.rand length]
18
- end
19
- end
data/lib/riel/log/log.rb DELETED
@@ -1,244 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- # -*- ruby -*-
3
- #
4
- # = log.rb
5
- #
6
- # Logging Module
7
- #
8
- # Author:: Jeff Pace <jpace@incava.org>
9
- # Documentation:: Author
10
- #
11
-
12
- require 'riel/log/logger'
13
- require 'riel/log/severity'
14
- require 'rubygems'
15
- require 'rainbow'
16
-
17
- #
18
- # == Log
19
- #
20
- # Very minimal logging output. If verbose is set, this displays the method and
21
- # line number whence called. It can be a mixin to a class, which displays the
22
- # class and method from where it called. If not in a class, it displays only the
23
- # method.
24
- #
25
- # Remember: all kids love log.
26
- #
27
- # == Examples
28
- #
29
- # See the unit tests in log_test.rb
30
- #
31
- # == Usage
32
- #
33
- # The most general usage is simply to call:
34
- #
35
- # Log.log "some message"
36
- #
37
- # That will simply log the given message.
38
- #
39
- # class YourClass
40
- # include Loggable
41
- #
42
- # def some_method(...)
43
- # log "my message"
44
- #
45
- # That will log from the given class and method, showing the line number from
46
- # which the logger was called.
47
- #
48
- # def another_method(...)
49
- # stack "my message"
50
- #
51
- # That will produce a stack trace from the given location.
52
- #
53
-
54
- module RIEL
55
- class Log
56
- $LOGGING_LEVEL = nil
57
-
58
- DEFAULT_FILENAME_WIDTH = -25
59
- DEFAULT_LINENUM_WIDTH = 4
60
- DEFAULT_FUNCTION_WIDTH = -20
61
-
62
- include Log::Severity
63
-
64
- # by default, class methods delegate to a single app-wide log.
65
-
66
- @@log = Logger.new
67
-
68
- # Returns the logger of the log. A class method delegating to an instance
69
- # method ... not so good. But temporary.
70
- def self.logger
71
- @@log
72
- end
73
-
74
- def self.method_missing meth, *args, &blk
75
- validcolors = Sickill::Rainbow::TERM_COLORS
76
- # only handling foregrounds, not backgrounds
77
- if code = validcolors[meth]
78
- add_color_method meth.to_s, code + 30
79
- send meth, *args, &blk
80
- else
81
- super
82
- end
83
- end
84
-
85
- def self.respond_to? meth
86
- validcolors = Sickill::Rainbow::TERM_COLORS
87
- validcolors.include?(meth) || super
88
- end
89
-
90
- def self.add_color_method color, code
91
- instmeth = Array.new
92
- instmeth << "def #{color} msg = \"\", lvl = Log::DEBUG, depth = 1, cname = nil, &blk"
93
- instmeth << " log(\"\\e[#{code}m\#{msg\}\\e[0m\", lvl, depth + 1, cname, &blk)"
94
- instmeth << "end"
95
- instance_eval instmeth.join("\n")
96
-
97
- clsmeth = Array.new
98
- clsmeth << "def #{color} msg = \"\", lvl = Log::DEBUG, depth = 1, cname = nil, &blk"
99
- clsmeth << " logger.#{color}(\"\\e[#{code}m\#{msg\}\\e[0m\", lvl, depth + 1, cname, &blk)"
100
- clsmeth << "end"
101
-
102
- class_eval clsmeth.join("\n")
103
- end
104
-
105
- def self.set_default_widths
106
- logger.set_default_widths
107
- end
108
-
109
- def self.verbose
110
- logger.verbose
111
- end
112
-
113
- def self.verbose= v
114
- logger.verbose = v && v != 0 ? DEBUG : FATAL
115
- end
116
-
117
- def self.level= lvl
118
- logger.level = lvl
119
- end
120
-
121
- def self.quiet
122
- logger.quiet
123
- end
124
-
125
- def self.quiet= q
126
- logger.quiet = q
127
- end
128
-
129
- def self.format
130
- logger.format
131
- end
132
-
133
- def self.format= fmt
134
- logger.format = fmt
135
- end
136
-
137
- # Assigns output to the given stream.
138
- def self.output= io
139
- logger.output = io
140
- end
141
-
142
- def self.output
143
- logger.output
144
- end
145
-
146
- # sets whether to colorize the entire line, or just the message.
147
- def self.colorize_line= col
148
- logger.colorize_line = col
149
- end
150
-
151
- def self.colorize_line
152
- logger.colorize_line
153
- end
154
-
155
- # Assigns output to a file with the given name. Returns the file; client
156
- # is responsible for closing it.
157
- def self.outfile= fname
158
- logger.outfile = fname
159
- end
160
-
161
- def self.outfile
162
- logger.outfile
163
- end
164
-
165
- # Creates a printf format for the given widths, for aligning output.
166
- def self.set_widths file_width, line_width, func_width
167
- logger.set_widths file_width, line_width, func_width
168
- end
169
-
170
- def self.ignore_file fname
171
- logger.ignore_file fname
172
- end
173
-
174
- def self.ignore_method methname
175
- logger.ignored_method methname
176
- end
177
-
178
- def self.ignore_class classname
179
- logger.ignored_class classname
180
- end
181
-
182
- def self.log_file fname
183
- logger.log_file fname
184
- end
185
-
186
- def self.log_method methname
187
- logger.log_method methname
188
- end
189
-
190
- def self.log_class classname
191
- logger.log_class classname
192
- end
193
-
194
- def self.debug msg = "", depth = 1, &blk
195
- logger.log msg, DEBUG, depth + 1, &blk
196
- end
197
-
198
- def self.info msg = "", depth = 1, &blk
199
- logger.log msg, INFO, depth + 1, &blk
200
- end
201
-
202
- def self.fatal msg = "", depth = 1, &blk
203
- logger.log msg, FATAL, depth + 1, &blk
204
- end
205
-
206
- def self.log msg = "", lvl = DEBUG, depth = 1, cname = nil, &blk
207
- logger.log msg, lvl, depth + 1, cname, &blk
208
- end
209
-
210
- def self.stack msg = "", lvl = DEBUG, depth = 1, cname = nil, &blk
211
- logger.stack msg, lvl, depth + 1, cname, &blk
212
- end
213
-
214
- def self.warn msg = "", depth = 1, &blk
215
- if verbose
216
- logger.log msg, WARN, depth + 1, &blk
217
- else
218
- $stderr.puts "WARNING: " + msg
219
- end
220
- end
221
-
222
- def self.error msg = "", depth = 1, &blk
223
- if verbose
224
- logger.log msg, ERROR, depth + 1, &blk
225
- else
226
- $stderr.puts "ERROR: " + msg
227
- end
228
- end
229
-
230
- def self.write msg, depth = 1, cname = nil, &blk
231
- if verbose
232
- stack msg, Log::WARN, depth + 1, cname, &blk
233
- elsif quiet
234
- # nothing
235
- else
236
- $stderr.puts msg
237
- end
238
- end
239
-
240
- def self.set_color lvl, color
241
- logger.set_color lvl, color
242
- end
243
- end
244
- end
@@ -1,101 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- # -*- ruby -*-
3
- #
4
- # = log.rb
5
- #
6
- # Logging Module
7
- #
8
- # Author:: Jeff Pace <jpace@incava.org>
9
- # Documentation:: Author
10
- #
11
-
12
- require 'riel/log/log'
13
- require 'rubygems'
14
- require 'rainbow'
15
-
16
- #
17
- # == Loggable
18
- #
19
- # Including this module in a class gives access to the logger methods.
20
- #
21
- # == Examples
22
- #
23
- # See the unit tests in log_test.rb
24
- #
25
- # == Usage
26
- #
27
- # class YourClass
28
- # include Loggable
29
- #
30
- # def some_method(...)
31
- # log "my message"
32
- #
33
- # That will log from the given class and method, showing the line number from
34
- # which the logger was called.
35
- #
36
- # def another_method(...)
37
- # stack "my message"
38
- #
39
- # That will produce a stack trace from the given location.
40
- #
41
-
42
- module RIEL
43
- module Loggable
44
- # Logs the given message, including the class whence invoked.
45
- def log msg = "", lvl = Log::DEBUG, depth = 1, &blk
46
- Log.log msg, lvl, depth + 1, self.class.to_s, &blk
47
- end
48
-
49
- def debug msg = "", depth = 1, &blk
50
- Log.log msg, Log::DEBUG, depth + 1, self.class.to_s, &blk
51
- end
52
-
53
- def info msg = "", depth = 1, &blk
54
- Log.log msg, Log::INFO, depth + 1, self.class.to_s, &blk
55
- end
56
-
57
- def warn msg = "", depth = 1, &blk
58
- Log.log msg, Log::WARN, depth + 1, self.class.to_s, &blk
59
- end
60
-
61
- def error msg = "", depth = 1, &blk
62
- Log.log msg, Log::ERROR, depth + 1, self.class.to_s, &blk
63
- end
64
-
65
- def fatal msg = "", depth = 1, &blk
66
- Log.log msg, Log::FATAL, depth + 1, self.class.to_s, &blk
67
- end
68
-
69
- def stack msg = "", lvl = Log::DEBUG, depth = 1, &blk
70
- Log.stack msg, lvl, depth + 1, self.class.to_s, &blk
71
- end
72
-
73
- def write msg = "", depth = 1, &blk
74
- Log.write msg, depth + 1, self.class.to_s, &blk
75
- end
76
-
77
- def method_missing meth, *args, &blk
78
- validcolors = Sickill::Rainbow::TERM_COLORS
79
- # only handling foregrounds, not backgrounds
80
- if code = validcolors[meth]
81
- add_color_method meth.to_s, code + 30
82
- send meth, *args, &blk
83
- else
84
- super
85
- end
86
- end
87
-
88
- def respond_to? meth
89
- validcolors = Sickill::Rainbow::TERM_COLORS
90
- validcolors.include?(meth) || super
91
- end
92
-
93
- def add_color_method color, code
94
- meth = Array.new
95
- meth << "def #{color}(msg = \"\", lvl = Log::DEBUG, depth = 1, cname = nil, &blk)"
96
- meth << " Log.#{color} msg, lvl, depth + 1, self.class.to_s, &blk"
97
- meth << "end"
98
- self.class.module_eval meth.join("\n")
99
- end
100
- end
101
- end