hsume2-hirb 0.6.0.beta.1
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.
- data/.gemspec +21 -0
- data/CHANGELOG.rdoc +144 -0
- data/LICENSE.txt +22 -0
- data/README.rdoc +194 -0
- data/Rakefile +35 -0
- data/lib/bond/completions/hirb.rb +15 -0
- data/lib/hirb/console.rb +43 -0
- data/lib/hirb/dynamic_view.rb +113 -0
- data/lib/hirb/formatter.rb +126 -0
- data/lib/hirb/helpers/auto_table.rb +24 -0
- data/lib/hirb/helpers/object_table.rb +14 -0
- data/lib/hirb/helpers/parent_child_tree.rb +24 -0
- data/lib/hirb/helpers/tab_table.rb +24 -0
- data/lib/hirb/helpers/table/filters.rb +10 -0
- data/lib/hirb/helpers/table/resizer.rb +82 -0
- data/lib/hirb/helpers/table.rb +349 -0
- data/lib/hirb/helpers/tree.rb +181 -0
- data/lib/hirb/helpers/unicode_table.rb +15 -0
- data/lib/hirb/helpers/vertical_table.rb +37 -0
- data/lib/hirb/helpers.rb +18 -0
- data/lib/hirb/import_object.rb +10 -0
- data/lib/hirb/menu.rb +238 -0
- data/lib/hirb/pager.rb +105 -0
- data/lib/hirb/string.rb +44 -0
- data/lib/hirb/util.rb +96 -0
- data/lib/hirb/version.rb +3 -0
- data/lib/hirb/view.rb +270 -0
- data/lib/hirb/views/couch_db.rb +11 -0
- data/lib/hirb/views/misc_db.rb +15 -0
- data/lib/hirb/views/mongo_db.rb +14 -0
- data/lib/hirb/views/orm.rb +11 -0
- data/lib/hirb/views/rails.rb +19 -0
- data/lib/hirb/views.rb +8 -0
- data/lib/hirb.rb +82 -0
- data/lib/ripl/hirb.rb +15 -0
- data/test/auto_table_test.rb +30 -0
- data/test/console_test.rb +27 -0
- data/test/deps.rip +4 -0
- data/test/dynamic_view_test.rb +94 -0
- data/test/formatter_test.rb +176 -0
- data/test/hirb_test.rb +39 -0
- data/test/import_test.rb +9 -0
- data/test/menu_test.rb +255 -0
- data/test/object_table_test.rb +79 -0
- data/test/pager_test.rb +162 -0
- data/test/resizer_test.rb +62 -0
- data/test/table_test.rb +630 -0
- data/test/test_helper.rb +61 -0
- data/test/tree_test.rb +184 -0
- data/test/util_test.rb +59 -0
- data/test/view_test.rb +165 -0
- data/test/views_test.rb +13 -0
- metadata +184 -0
data/test/pager_test.rb
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
describe "Pager" do
|
4
|
+
def pager; View.pager; end
|
5
|
+
|
6
|
+
def create_pageable_string(inspect_mode=false, size={})
|
7
|
+
size = {:width=>pager.width, :height=>pager.height}.merge(size)
|
8
|
+
seed = inspect_mode ? "a" : "a\n"
|
9
|
+
if inspect_mode
|
10
|
+
seed * (size[:width] * size[:height] + 1)
|
11
|
+
else
|
12
|
+
seed * (size[:height] + 1)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "command_pager sets pager_command when command exists" do
|
17
|
+
Util.expects(:command_exists?).returns(true)
|
18
|
+
Pager.expects(:basic_pager)
|
19
|
+
Pager.command_pager 'blah', :pager_command=>'less'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "command_pager doesn't set pager_command when command doesn't exist" do
|
23
|
+
Util.expects(:command_exists?).returns(false)
|
24
|
+
Pager.expects(:basic_pager).never
|
25
|
+
Pager.command_pager 'blah', :pager_command=>'moreless'
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "default_pager" do
|
29
|
+
before_all { reset_config; Hirb.enable :pager=>true }
|
30
|
+
before { View.pager = nil; Pager.stubs(:pager_command).returns(nil) }
|
31
|
+
|
32
|
+
it "pages once in normal mode" do
|
33
|
+
$stdin.expects(:gets).returns("\n")
|
34
|
+
output = capture_stdout { pager.page(create_pageable_string, false) }
|
35
|
+
output.include?('quit').should == true
|
36
|
+
output.include?('finished').should == true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "doesn't page in normal mode" do
|
40
|
+
$stdin.expects(:gets).never
|
41
|
+
output = capture_stdout { pager.page("a\n", false) }
|
42
|
+
output.include?("a\n=== Pager finished. ===\n").should == true
|
43
|
+
end
|
44
|
+
|
45
|
+
it "pages once in inspect mode" do
|
46
|
+
$stdin.expects(:gets).returns("\n")
|
47
|
+
output = capture_stdout { pager.page(create_pageable_string(true), true) }
|
48
|
+
output.include?('quit').should == true
|
49
|
+
output.include?('finished').should == true
|
50
|
+
end
|
51
|
+
|
52
|
+
it "doesn't page in inspect mode" do
|
53
|
+
$stdin.expects(:gets).never
|
54
|
+
output = capture_stdout { pager.page("a", true) }
|
55
|
+
output.include?("a\n=== Pager finished. ===\n").should == true
|
56
|
+
end
|
57
|
+
after_all { Hirb.disable }
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "pager" do
|
61
|
+
before_all { reset_config; Hirb.enable }
|
62
|
+
before { View.pager = nil; View.formatter = nil }
|
63
|
+
|
64
|
+
def irb_eval(string)
|
65
|
+
context_stub = stub(:last_value=>string)
|
66
|
+
::IRB::Irb.new(context_stub).output_value
|
67
|
+
end
|
68
|
+
|
69
|
+
# this mode is called within @irb.output_value
|
70
|
+
describe "in inspect_mode" do
|
71
|
+
it "activates when output is wide enough" do
|
72
|
+
output = create_pageable_string(true)
|
73
|
+
pager.expects(:page).with(output.inspect, true)
|
74
|
+
View.expects(:render_output).returns(false)
|
75
|
+
irb_eval output
|
76
|
+
end
|
77
|
+
|
78
|
+
it "doesn't activate when output isn't wide enough" do
|
79
|
+
pager.expects(:page).never
|
80
|
+
View.expects(:render_output).returns(false)
|
81
|
+
irb_eval("a")
|
82
|
+
end
|
83
|
+
|
84
|
+
it "activates with an explicit width" do
|
85
|
+
View.config[:width] = 10
|
86
|
+
output = create_pageable_string true, :width=>10
|
87
|
+
pager.expects(:page).with(output.inspect, true)
|
88
|
+
View.expects(:render_output).returns(false)
|
89
|
+
irb_eval output
|
90
|
+
end
|
91
|
+
|
92
|
+
it "activates default_pager when pager command is invalid" do
|
93
|
+
Pager.expects(:pager_command).returns(nil)
|
94
|
+
output = create_pageable_string(true)
|
95
|
+
Pager.expects(:default_pager).with(output.inspect, anything)
|
96
|
+
View.expects(:render_output).returns(false)
|
97
|
+
capture_stdout { irb_eval output }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# this mode is called within View.render_output
|
102
|
+
describe "in normal mode" do
|
103
|
+
it "activates when output is long enough" do
|
104
|
+
output = create_pageable_string
|
105
|
+
View.formatter.expects(:format_output).returns(output)
|
106
|
+
pager.expects(:page).with(output, false)
|
107
|
+
irb_eval(output)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "doesn't activate when output isn't long enough" do
|
111
|
+
output = "a\n"
|
112
|
+
View.formatter.expects(:format_output).returns(output)
|
113
|
+
pager.expects(:page).never
|
114
|
+
capture_stdout { irb_eval(output) }
|
115
|
+
end
|
116
|
+
|
117
|
+
it "activates with an explicit height" do
|
118
|
+
View.config[:height] = 100
|
119
|
+
output = create_pageable_string false, :height=>100
|
120
|
+
View.formatter.expects(:format_output).returns(output)
|
121
|
+
pager.expects(:page).with(output, false)
|
122
|
+
irb_eval(output)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "activates default_pager when pager_command is invalid" do
|
126
|
+
Pager.expects(:pager_command).returns(nil)
|
127
|
+
output = create_pageable_string
|
128
|
+
Pager.expects(:default_pager).with(output, anything)
|
129
|
+
View.formatter.expects(:format_output).returns(output)
|
130
|
+
capture_stdout { irb_eval output }
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
it "activates pager_command with valid pager_command option" do
|
135
|
+
View.config[:pager_command] = "less"
|
136
|
+
View.expects(:render_output).returns(false)
|
137
|
+
Util.expects(:command_exists?).returns(true)
|
138
|
+
Pager.expects(:command_pager)
|
139
|
+
irb_eval create_pageable_string(true)
|
140
|
+
View.config[:pager_command] = nil
|
141
|
+
end
|
142
|
+
|
143
|
+
it "activates pager_command with pager_command option that has command options" do
|
144
|
+
View.config[:pager_command] = "less -r"
|
145
|
+
View.expects(:render_output).returns(false)
|
146
|
+
Util.expects(:command_exists?).with('less').returns(true)
|
147
|
+
Pager.expects(:command_pager)
|
148
|
+
irb_eval create_pageable_string(true)
|
149
|
+
View.config[:pager_command] = nil
|
150
|
+
end
|
151
|
+
|
152
|
+
it "doesn't activate pager_command with invalid pager_command option" do
|
153
|
+
View.config[:pager_command] = "moreless"
|
154
|
+
View.expects(:render_output).returns(false)
|
155
|
+
Util.expects(:command_exists?).returns(false)
|
156
|
+
Pager.expects(:default_pager)
|
157
|
+
irb_eval create_pageable_string(true)
|
158
|
+
View.config[:pager_command] = nil
|
159
|
+
end
|
160
|
+
end
|
161
|
+
after_all { Hirb.disable }
|
162
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
describe "Resizer" do
|
4
|
+
def table(options)
|
5
|
+
@table = Helpers::Table.new [options[:field_lengths].keys.inject({}) {|t,e| t[e] = '1'; t}]
|
6
|
+
@table.field_lengths = options[:field_lengths]
|
7
|
+
@table.width = options[:width]
|
8
|
+
@table.max_fields = options[:max_fields] if options[:max_fields]
|
9
|
+
@width, @field_lengths = @table.width, @table.field_lengths
|
10
|
+
@table
|
11
|
+
end
|
12
|
+
|
13
|
+
it "resize ensures columns total doesn't exceed max width" do
|
14
|
+
table :field_lengths=>{:f1=>135, :f2=>45, :f3=>4, :f4=>55}, :width=>195
|
15
|
+
Helpers::Table::Resizer.resize!(@table)
|
16
|
+
@field_lengths.values.inject {|a,e| a+=e}.should <= @width
|
17
|
+
end
|
18
|
+
|
19
|
+
it "resize sets columns by relative lengths" do
|
20
|
+
table :field_lengths=>{:a=>30, :b=>30, :c=>40}, :width=>60
|
21
|
+
Helpers::Table::Resizer.resize!(@table)
|
22
|
+
@field_lengths.values.inject {|a,e| a+=e}.should <= @width
|
23
|
+
@field_lengths.values.uniq.size.should.not == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
it "resize sets all columns roughly equal when adusting long fields don't work" do
|
27
|
+
table :field_lengths=>{:field1=>10, :field2=>15, :field3=>100}, :width=>20
|
28
|
+
Helpers::Table::Resizer.resize!(@table)
|
29
|
+
@field_lengths.values.inject {|a,e| a+=e}.should <= @width
|
30
|
+
@field_lengths.values.each {|e| e.should <= 4 }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "add_extra_width and max_fields" do
|
34
|
+
def table_and_resize(options={})
|
35
|
+
defaults = {:field_lengths=>{:f1=>135, :f2=>30, :f3=>4, :f4=>100}, :width=>195, :max_fields=>{:f1=>80, :f4=>30} }
|
36
|
+
@table = table defaults.merge(options)
|
37
|
+
# repeated from table since instance variables aren't copied b/n contexts
|
38
|
+
@width, @field_lengths = @table.width, @table.field_lengths
|
39
|
+
Helpers::Table::Resizer.resize! @table
|
40
|
+
end
|
41
|
+
|
42
|
+
it "doesn't add to already maxed out field" do
|
43
|
+
table_and_resize
|
44
|
+
@field_lengths[:f3].should == 4
|
45
|
+
end
|
46
|
+
|
47
|
+
it "restricted before adding width" do
|
48
|
+
table_and_resize
|
49
|
+
@field_lengths[:f4].should <= 30
|
50
|
+
end
|
51
|
+
|
52
|
+
it "adds to restricted field" do
|
53
|
+
table_and_resize
|
54
|
+
@field_lengths[:f1].should <= 80
|
55
|
+
end
|
56
|
+
|
57
|
+
it "adds to unrestricted field" do
|
58
|
+
table_and_resize :field_lengths=>{:f1=>135, :f2=>70, :f3=>4, :f4=>100}
|
59
|
+
@field_lengths[:f2].should == 70
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|