riel 1.1.16 → 1.1.17

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.
Files changed (50) hide show
  1. data/README.md +2 -37
  2. data/lib/riel/log/log.rb +17 -24
  3. data/lib/riel/log/loggable.rb +13 -15
  4. data/lib/riel/log/logger.rb +34 -66
  5. data/lib/riel/log.rb +0 -63
  6. data/lib/riel/optproc.rb +0 -3
  7. data/lib/riel/string.rb +0 -2
  8. data/lib/riel.rb +1 -1
  9. data/test/riel/log/format_test.rb +48 -0
  10. data/test/riel/optproc_test.rb +1 -30
  11. data/test/riel/{log_stack_test.rb → testlog/log_stack_test.rb} +0 -0
  12. data/test/riel/testlog/log_test.rb +254 -0
  13. data/test/riel/testlog/loggable_test.rb +31 -0
  14. metadata +89 -133
  15. data/lib/riel/ansicolor.rb +0 -91
  16. data/lib/riel/asciitable/cell.rb +0 -82
  17. data/lib/riel/asciitable/column.rb +0 -26
  18. data/lib/riel/asciitable/row.rb +0 -105
  19. data/lib/riel/asciitable/table.rb +0 -295
  20. data/lib/riel/text/ansi/ansi_color.rb +0 -31
  21. data/lib/riel/text/ansi/ansi_colors.rb +0 -16
  22. data/lib/riel/text/ansi/ansi_highlight.rb +0 -69
  23. data/lib/riel/text/ansi/ansi_list.rb +0 -17
  24. data/lib/riel/text/ansi/ansi_palette.rb +0 -48
  25. data/lib/riel/text/ansi/attributes.rb +0 -21
  26. data/lib/riel/text/ansi/backgrounds.rb +0 -13
  27. data/lib/riel/text/ansi/color.rb +0 -62
  28. data/lib/riel/text/ansi/foregrounds.rb +0 -12
  29. data/lib/riel/text/ansi/grey.rb +0 -30
  30. data/lib/riel/text/ansi/grey_palette.rb +0 -36
  31. data/lib/riel/text/ansi/palette.rb +0 -18
  32. data/lib/riel/text/ansi/rgb_color.rb +0 -28
  33. data/lib/riel/text/ansi/rgb_highlighter.rb +0 -73
  34. data/lib/riel/text/ansi/rgb_palette.rb +0 -49
  35. data/lib/riel/text/highlight.rb +0 -130
  36. data/lib/riel/text/highlightable.rb +0 -85
  37. data/lib/riel/text/html_highlight.rb +0 -98
  38. data/lib/riel/text/non_highlight.rb +0 -17
  39. data/lib/riel/text/string.rb +0 -10
  40. data/lib/riel/text.rb +0 -4
  41. data/test/riel/asciitable/table_test.rb +0 -77
  42. data/test/riel/log_test.rb +0 -164
  43. data/test/riel/text/ansi/ansi_highlight_test.rb +0 -116
  44. data/test/riel/text/ansi/ansi_palette_test.rb +0 -65
  45. data/test/riel/text/ansi/grey_palette_test.rb +0 -39
  46. data/test/riel/text/ansi/rgb_highlighter_test.rb +0 -99
  47. data/test/riel/text/ansi/rgb_palette_test.rb +0 -122
  48. data/test/riel/text/highlightable_test.rb +0 -24
  49. data/test/riel/text/string_test.rb +0 -47
  50. data/test/riel/text_test.rb +0 -62
@@ -1,77 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- # -*- ruby -*-
3
-
4
- require 'rubygems'
5
- require 'test/unit'
6
- require 'riel/asciitable/table'
7
- require 'stringio'
8
-
9
- module RIEL::ASCIITable
10
- class TableTest < Test::Unit::TestCase
11
- class DogData < TableData
12
- def initialize
13
- @data = Array.new
14
- add_dog 'lucky', 'mixed', 'Illinois'
15
- add_dog 'frisky', 'dachshund', 'Illinois'
16
- add_dog 'boots', 'beagle', 'Indiana'
17
- add_dog 'sandy', 'ridgeback', 'Indiana'
18
- add_dog 'cosmo', 'retriever', 'Virginia'
19
- end
20
-
21
- def add_dog name, breed, state
22
- @data << [name, breed, state ]
23
- end
24
-
25
- def keys
26
- @data.collect { |dog| dog[0] }
27
- end
28
-
29
- def fields
30
- [ :breed, :state ]
31
- end
32
-
33
- def value key, field, index
34
- @data.assoc(key.to_s)[fields.index(field) + 1]
35
- end
36
- end
37
-
38
- class MyTable < Table
39
- attr_reader :data
40
-
41
- def initialize
42
- @data = DogData.new
43
- super Hash.new
44
- end
45
-
46
- def headings
47
- %w{ name } + @data.fields.collect { |x| x.to_s }
48
- end
49
- end
50
-
51
- def test_defaults
52
- table = MyTable.new
53
- origout = $stdout
54
- sio = StringIO.new
55
- $stdout = sio
56
- table.print
57
- sio.flush
58
- str = sio.string
59
- $stdout = origout
60
-
61
- expected = [
62
- "| name | breed | state |\n",
63
- "| ------------ | ------------ | ------------ |\n",
64
- "| lucky | mixed | Illinois |\n",
65
- "| frisky | dachshund | Illinois |\n",
66
- "| boots | beagle | Indiana |\n",
67
- "| sandy | ridgeback | Indiana |\n",
68
- "| cosmo | retriever | Virginia |\n",
69
- ]
70
- puts "-------------------------------------------------------"
71
- puts str
72
- puts "-------------------------------------------------------"
73
-
74
- assert_equal expected.join(''), str
75
- end
76
- end
77
- end
@@ -1,164 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- # -*- ruby -*-
3
-
4
- require 'pathname'
5
- require 'test/unit'
6
- require 'stringio'
7
- require 'riel/log'
8
-
9
- class LogTestCase < Test::Unit::TestCase
10
- include Loggable
11
-
12
- def test_no_output
13
- # I could make this an instance variable, but I want to check the method
14
- # names in the output string.
15
-
16
- log = Proc.new {
17
- Log.log "hello, world?"
18
- Log.debug "hello, world?"
19
- Log.info "hello, world?"
20
- Log.warn "EXPECTED OUTPUT TO STDERR: hello, world." # will go to stderr
21
- Log.error "EXPECTED OUTPUT TO STDERR: hello, world." # will go to stderr
22
- Log.stack "hello, world?"
23
- }
24
-
25
- run_test(@nonverbose_setup, log)
26
- end
27
-
28
- def test_output_arg
29
- log = Proc.new {
30
- Log.log "hello, world?"
31
- Log.debug "hello, world?"
32
- Log.info "hello, world?"
33
- Log.warn "hello, world?"
34
- Log.error "hello, world?"
35
- Log.stack "hello, world?"
36
- }
37
-
38
- expected_output = [
39
- "[ ...test/riel/log_test.rb: 30] {test_output_arg } hello, world?",
40
- "[ ...test/riel/log_test.rb: 31] {test_output_arg } hello, world?",
41
- "[ ...test/riel/log_test.rb: 32] {test_output_arg } hello, world?",
42
- "[ ...test/riel/log_test.rb: 33] {test_output_arg } hello, world?",
43
- "[ ...test/riel/log_test.rb: 34] {test_output_arg } hello, world?",
44
- "[ ...test/riel/log_test.rb: 35] {test_output_arg } hello, world?",
45
- "[ ...test/riel/log_test.rb: 163] {call } ",
46
- "[ ...test/riel/log_test.rb: 163] {run_test } ",
47
- "[ ...test/riel/log_test.rb: 68] {test_output_arg } ",
48
- ]
49
-
50
- # run_test @verbose_setup, log, *expected_output
51
- end
52
-
53
- def test_output_block
54
- log = Proc.new {
55
- Log.log { "output block" }
56
- }
57
-
58
- Log.set_default_widths
59
- # run_test @verbose_setup, log, "[ ...test/riel/log_test.rb: 73] {test_output_block } output block"
60
-
61
- info_setup = Proc.new {
62
- Log.level = Log::INFO
63
- Log.output = StringIO.new
64
- }
65
-
66
- evaluated = false
67
- log = Proc.new {
68
- Log.debug { evaluated = true; "hello, world?" }
69
- }
70
-
71
- # run_test info_setup, log
72
-
73
- assert_equal false, evaluated
74
- end
75
-
76
- def test_instance_log
77
- log = Proc.new {
78
- log "hello, world?"
79
- }
80
-
81
- Log.set_widths(-15, 4, -40)
82
- # the class name is different in 1.8 and 1.9, so we won't test it.
83
- # run_test(@verbose_setup, log, "[ ...log_test.rb: 96] {LogTestCase#test_instance_log } hello, world?")
84
- run_test @verbose_setup, log, nil
85
-
86
- Log.set_default_widths
87
- end
88
-
89
- def test_colors
90
- log = Proc.new {
91
- white "white wedding"
92
- blue "blue iris"
93
- on_cyan "red"
94
- }
95
-
96
- # test_col has become 'block in test colors' in 1.9
97
- # run_test(@verbose_setup, log,
98
- # "[ ...test/riel/log_test.rb: 107] {LogTestCase#test_col} \e[37mwhite wedding\e[0m",
99
- # "[ ...test/riel/log_test.rb: 108] {LogTestCase#test_col} \e[34mblue iris\e[0m",
100
- # "[ ...test/riel/log_test.rb: 109] {LogTestCase#test_col} \e[46mred\e[0m")
101
-
102
- Log.set_default_widths
103
- end
104
-
105
- def test_format
106
- log = Proc.new {
107
- Log.log "format"
108
- }
109
-
110
- Log.set_default_widths
111
- # run_test(@verbose_setup, log, "[ ...test/riel/log_test.rb: 122] {test_format } format")
112
-
113
- # Log.set_widths(file_width, line_width, func_width)
114
-
115
- #run_format_test(log, -25, 8, 30, "[ ...test/riel/log_test.rb: 122] { test_format} format")
116
- #run_format_test(log, 25, 8, 30, "[ ...test/riel/log_test.rb: 122] { test_format} format")
117
- #run_format_test(log, 25, "08", 30, "[ ...test/riel/log_test.rb:00000122] { test_format} format")
118
-
119
- # useless feature of truncating line numbers, but so it goes ...
120
- # run_format_test(log, 4, 2, -10, "[ ...:12] {test_forma} format")
121
-
122
- Log.set_default_widths
123
- end
124
-
125
- def run_format_test log, file_width, line_width, func_width, expected
126
- Log.set_widths file_width, line_width, func_width
127
- run_test @verbose_setup, log, expected
128
- end
129
-
130
- # the ctor is down here so the lines above are less likely to change.
131
- def initialize test, name = nil
132
- @nonverbose_setup = Proc.new {
133
- Log.verbose = false
134
- Log.output = StringIO.new
135
- }
136
-
137
- @verbose_setup = Proc.new {
138
- Log.verbose = true
139
- Log.output = StringIO.new
140
- }
141
-
142
- super test
143
- end
144
-
145
- def run_test setup, log, *expected
146
- io = setup.call
147
-
148
- log.call
149
-
150
- assert_not_nil io
151
- str = io.string
152
- assert_not_nil str
153
-
154
- lines = str.split "\n"
155
-
156
- (0 ... expected.size).each do |idx|
157
- if expected[idx]
158
- assert_equal expected[idx], lines[idx], "index: #{idx}"
159
- end
160
- end
161
-
162
- Log.output = io
163
- end
164
- end
@@ -1,116 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- # -*- ruby -*-
3
-
4
- require 'test/unit'
5
- require 'riel/text/highlightable'
6
- require 'riel/text/ansi/ansi_highlight'
7
- require 'riel/text/string'
8
-
9
- class AnsiHighlightTestCase < Test::Unit::TestCase
10
- def run_ansi_test str, input, *chars
11
- escape_sequence = chars.collect { |ch| "\e[#{ch}m" }.join("")
12
- assert_equal "#{escape_sequence}#{str}\e[0m", input
13
- end
14
-
15
- def setup
16
- Text::Highlightable.add_to String
17
- end
18
-
19
- def test_ansi_highlight
20
- str = "precision"
21
-
22
- run_ansi_test str, str.none, 0
23
- run_ansi_test str, str.bold, 1
24
- run_ansi_test str, str.underline, 4
25
- run_ansi_test str, str.underscore, 4
26
- run_ansi_test str, str.blink, 5 # every geocities site circa 1998
27
- run_ansi_test str, str.negative, 7
28
- run_ansi_test str, str.concealed, 8
29
-
30
- run_ansi_test str, str.black, 30
31
- run_ansi_test str, str.red, 31
32
- run_ansi_test str, str.green, 32
33
- run_ansi_test str, str.yellow, 33
34
- run_ansi_test str, str.blue, 34
35
- run_ansi_test str, str.magenta, 35
36
- run_ansi_test str, str.cyan, 36
37
- run_ansi_test str, str.white, 37
38
-
39
- run_ansi_test str, str.on_black, 40
40
- run_ansi_test str, str.on_red, 41
41
- run_ansi_test str, str.on_green, 42
42
- run_ansi_test str, str.on_yellow, 43
43
- run_ansi_test str, str.on_blue, 44
44
- run_ansi_test str, str.on_magenta, 45
45
- run_ansi_test str, str.on_cyan, 46
46
- run_ansi_test str, str.on_white, 47
47
-
48
- run_ansi_test str, str.none_on_white, 0, 47
49
- run_ansi_test str, str.none_on_black, 0, 40
50
- run_ansi_test str, str.none_on_blue, 0, 44
51
- run_ansi_test str, str.red_on_white, 31, 47
52
- run_ansi_test str, str.bold_red_on_white, 1, 31, 47
53
- end
54
-
55
- def test_highlighter
56
- hl = Text::ANSIHighlighter.instance
57
- assert_equal "\e[1m", hl.code('bold')
58
- end
59
-
60
- def test_gsub
61
- hl = Text::ANSIHighlighter.instance
62
- assert_equal "...\e[34mthis\e[0m... is blue", hl.gsub("...this... is blue", %r{this}, "blue")
63
- assert_equal "...\e[34m\e[42mthis\e[0m... is blue", hl.gsub("...this... is blue", %r{this}, "blue on green")
64
- end
65
-
66
- def test_grey
67
- str = "123".grey(14)
68
- assert_equal "\x1b[38;5;246m123\e[0m", str
69
- end
70
-
71
- def test_on_grey
72
- str = "123".on_grey(4)
73
- assert_equal "\x1b[48;5;236m123\e[0m", str
74
- end
75
-
76
- def test_gray
77
- str = "123".gray(14)
78
- assert_equal "\x1b[38;5;246m123\e[0m", str
79
- end
80
-
81
- def test_on_gray
82
- str = "123".on_gray(4)
83
- assert_equal "\x1b[48;5;236m123\e[0m", str
84
- end
85
-
86
- def test_multiple
87
- str = "ABC".bold.blue.on_green
88
- assert_equal "\e[42m\e[34m\e[1mABC\e[0m\e[0m\e[0m", str
89
- end
90
-
91
- def test_multiple_add_to
92
- Text::Highlightable.add_to Integer
93
- str = "ABC".blue
94
- int = 123.red
95
- # puts str + int.to_s
96
- assert_equal "\e[34mABC\e[0m\e[31m123\e[0m", str + int
97
- end
98
-
99
- def assert_to_codes expected, rgbstr
100
- hl = Text::ANSIHighlighter.instance
101
- codes = hl.to_codes rgbstr
102
- assert_equal expected, codes
103
- end
104
-
105
- def test_to_codes_one_color
106
- assert_to_codes "\e[34m", 'blue'
107
- end
108
-
109
- def test_to_codes_decoration_color
110
- assert_to_codes "\e[1m\e[34m", 'bold blue'
111
- end
112
-
113
- def test_to_codes_background_color
114
- assert_to_codes "\e[44m", 'on_blue'
115
- end
116
- end
@@ -1,65 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- # -*- ruby -*-
3
-
4
- require 'riel/text/ansi/ansi_palette'
5
- require 'riel/text/ansi/palette_tc'
6
-
7
- module Text
8
- class ANSIPaletteTest < PaletteTest
9
- def cls
10
- ANSIPalette
11
- end
12
-
13
- def test_ansi_foregrounds
14
- expected = [
15
- "ansi foregrounds\n",
16
- "0/. 1/. 2/. 3/. 4/. 5/. 6/. 7/. \n",
17
- "\n",
18
- ]
19
-
20
- assert_print expected, :print_foregrounds
21
- end
22
-
23
- def test_ansi_backgrounds
24
- expected = [
25
- "ansi backgrounds\n",
26
- "./0 ./1 ./2 ./3 ./4 ./5 ./6 ./7 \n",
27
- "\n",
28
- ]
29
-
30
- assert_print expected, :print_backgrounds
31
- end
32
-
33
- def test_ansi_combinations
34
- expected = [
35
- "ansi combinations\n",
36
- "bg: 000\n",
37
- "0/. 1/. 2/. 3/. 4/. 5/. 6/. 7/. \n",
38
- "\n",
39
- "bg: 001\n",
40
- "0/. 1/. 2/. 3/. 4/. 5/. 6/. 7/. \n",
41
- "\n",
42
- "bg: 002\n",
43
- "0/. 1/. 2/. 3/. 4/. 5/. 6/. 7/. \n",
44
- "\n",
45
- "bg: 003\n",
46
- "0/. 1/. 2/. 3/. 4/. 5/. 6/. 7/. \n",
47
- "\n",
48
- "bg: 004\n",
49
- "0/. 1/. 2/. 3/. 4/. 5/. 6/. 7/. \n",
50
- "\n",
51
- "bg: 005\n",
52
- "0/. 1/. 2/. 3/. 4/. 5/. 6/. 7/. \n",
53
- "\n",
54
- "bg: 006\n",
55
- "0/. 1/. 2/. 3/. 4/. 5/. 6/. 7/. \n",
56
- "\n",
57
- "bg: 007\n",
58
- "0/. 1/. 2/. 3/. 4/. 5/. 6/. 7/. \n",
59
- "\n",
60
- ]
61
-
62
- assert_print expected, :print_combinations
63
- end
64
- end
65
- end
@@ -1,39 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- # -*- ruby -*-
3
-
4
- require 'riel/text/ansi/grey_palette'
5
- require 'riel/text/ansi/palette_tc'
6
-
7
- module Text
8
- class GreyPaletteTest < PaletteTest
9
- def cls
10
- GreyPalette
11
- end
12
-
13
- def test_foregrounds
14
- expected = [
15
- "grey foreground colors\n",
16
- "232 233 234 235 236 237 \n",
17
- "238 239 240 241 242 243 \n",
18
- "244 245 246 247 248 249 \n",
19
- "250 251 252 253 254 255 \n",
20
- "\n",
21
- ]
22
-
23
- assert_print expected, :print_foregrounds
24
- end
25
-
26
- def test_backgrounds
27
- expected = [
28
- "grey background colors\n",
29
- "232 233 234 235 236 237 \n",
30
- "238 239 240 241 242 243 \n",
31
- "244 245 246 247 248 249 \n",
32
- "250 251 252 253 254 255 \n",
33
- "\n",
34
- ]
35
-
36
- assert_print expected, :print_backgrounds
37
- end
38
- end
39
- end
@@ -1,99 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- # -*- ruby -*-
3
-
4
- require 'test/unit'
5
- require 'riel/text/highlightable'
6
- require 'riel/text/ansi/rgb_highlighter'
7
- require 'riel/text/string'
8
-
9
- class RGBHighlighterTest < Test::Unit::TestCase
10
- def setup
11
- String.highlight
12
- @hl = Text::ANSIHighlighter.instance
13
- end
14
-
15
- def test_rgb
16
- str = "123".rgb(1, 2, 3)
17
- assert_equal "\x1b[38;5;67m123\e[0m", str
18
- end
19
-
20
- def test_on_rgb
21
- str = "123".on_rgb(1, 2, 3)
22
- assert_equal "\x1b[48;5;67m123\e[0m", str
23
- end
24
-
25
- def test_rgb_chained
26
- str = "gaudy".rgb(4, 1, 2).on_rgb(1, 5, 3)
27
- puts "str: #{str}"
28
- assert_equal "\x1b[48;5;85m\x1b[38;5;168mgaudy\e[0m\e[0m", str
29
- end
30
-
31
- def test_rgb_bold_underline
32
- str = "hey!".rgb(0, 3, 5).on_rgb(5, 2, 1).bold.underline
33
- puts "str: #{str}"
34
- assert_equal "\e[4m\e[1m\e[48;5;209m\x1b[38;5;39mhey!\e[0m\e[0m\e[0m\e[0m", str
35
- end
36
-
37
- def assert_to_codes expected, rgbstr
38
- codes = @hl.to_codes rgbstr
39
- assert_equal expected, codes
40
- end
41
-
42
- def test_to_rgb_code
43
- code = @hl.to_rgb_code 1, 3, 5
44
- assert_equal "\e[38;5;75m", code
45
- end
46
-
47
- def test_to_rgb_code_background
48
- code = @hl.to_rgb_code 1, 3, 5, :bg
49
- assert_equal "\e[48;5;75m", code
50
- end
51
-
52
- def test_to_codes_rgb_foreground
53
- assert_to_codes "\e[38;5;75m", '135'
54
- end
55
-
56
- def test_to_codes_rgb_onbackground
57
- assert_to_codes "\e[48;5;75m", 'on135'
58
- end
59
-
60
- def test_to_codes_rgb_on_background
61
- assert_to_codes "\e[48;5;75m", 'on_135'
62
- end
63
-
64
- def test_rgb_fg_alias
65
- @hl.add_alias :teal, 1, 4, 4
66
-
67
- str = "ABC".teal
68
- assert_equal "\x1b[38;5;80mABC\e[0m", str
69
- end
70
-
71
- def test_rgb_bg_alias
72
- @hl.add_alias :on_maroon, 1, 0, 2
73
-
74
- str = "ABC".on_maroon
75
- assert_equal "\x1b[48;5;54mABC\e[0m", str
76
- end
77
-
78
- def add_rrggbb name, red, green, blue
79
- rr, gg, bb = @hl.rrggbb(red, green, blue)
80
- @hl.add_alias name, rr, gg, bb
81
- end
82
-
83
- def test_rgb_multiple_aliases
84
- add_rrggbb :on_dahlia_mauve, 168, 83, 135
85
- add_rrggbb :mauve_chalk, 228, 211, 210
86
-
87
- str = "mauve chalk on dahlia".mauve_chalk.on_dahlia_mauve
88
- puts str
89
- assert_equal "\x1b[48;5;133m\x1b[38;5;224mmauve chalk on dahlia\e[0m\e[0m", str
90
- end
91
-
92
- def test_rrggbb
93
- rr, gg, bb = @hl.rrggbb(122, 212, 67)
94
- puts "rr, gg, bb: #{rr}, #{gg}, #{bb}"
95
-
96
- rr, gg, bb = @hl.rrggbb(121, 211, 62)
97
- puts "rr, gg, bb: #{rr}, #{gg}, #{bb}"
98
- end
99
- end