5
5
6
6
module TestIRB
7
7
class ExtendCommand < Test ::Unit ::TestCase
8
+ class TestInputMethod < ::IRB ::InputMethod
9
+ attr_reader :list , :line_no
10
+
11
+ def initialize ( list = [ ] )
12
+ super ( "test" )
13
+ @line_no = 0
14
+ @list = list
15
+ end
16
+
17
+ def gets
18
+ @list [ @line_no ] &.tap { @line_no += 1 }
19
+ end
20
+
21
+ def eof?
22
+ @line_no >= @list . size
23
+ end
24
+
25
+ def encoding
26
+ Encoding . default_external
27
+ end
28
+
29
+ def reset
30
+ @line_no = 0
31
+ end
32
+ end
33
+
8
34
def setup
9
35
@pwd = Dir . pwd
10
36
@tmpdir = File . join ( Dir . tmpdir , "test_reline_config_#{ $$} " )
@@ -44,12 +70,12 @@ def test_irb_info_multiline
44
70
IRB . conf [ :USE_SINGLELINE ] = false
45
71
IRB . conf [ :VERBOSE ] = false
46
72
workspace = IRB ::WorkSpace . new ( self )
47
- irb = IRB ::Irb . new ( workspace )
73
+ irb = IRB ::Irb . new ( workspace , TestInputMethod . new ( [ ] ) )
48
74
IRB . conf [ :MAIN_CONTEXT ] = irb . context
49
75
expected = %r{
50
76
Ruby\s version: .+\n
51
77
IRB\s version:\s irb .+\n
52
- InputMethod:\s ReidlineInputMethod \s with \s Reline .+ and .+ \n
78
+ InputMethod:\s Abstract \s InputMethod \n
53
79
\. irbrc\s path: .+\n
54
80
RUBY_PLATFORM: .+
55
81
}x
@@ -64,12 +90,12 @@ def test_irb_info_singleline
64
90
IRB . conf [ :USE_SINGLELINE ] = true
65
91
IRB . conf [ :VERBOSE ] = false
66
92
workspace = IRB ::WorkSpace . new ( self )
67
- irb = IRB ::Irb . new ( workspace )
93
+ irb = IRB ::Irb . new ( workspace , TestInputMethod . new ( [ ] ) )
68
94
IRB . conf [ :MAIN_CONTEXT ] = irb . context
69
95
expected = %r{
70
96
Ruby\s version: .+\n
71
97
IRB\s version:\s irb .+\n
72
- InputMethod:\s ReadlineInputMethod \s with .+ and .+ \n
98
+ InputMethod:\s Abstract \s InputMethod \n
73
99
\. irbrc\s path: .+\n
74
100
RUBY_PLATFORM: .+
75
101
}x
@@ -87,12 +113,12 @@ def test_irb_info_multiline_without_rc_files
87
113
IRB . conf [ :USE_SINGLELINE ] = false
88
114
IRB . conf [ :VERBOSE ] = false
89
115
workspace = IRB ::WorkSpace . new ( self )
90
- irb = IRB ::Irb . new ( workspace )
116
+ irb = IRB ::Irb . new ( workspace , TestInputMethod . new ( [ ] ) )
91
117
IRB . conf [ :MAIN_CONTEXT ] = irb . context
92
118
expected = %r{
93
119
Ruby\s version: .+\n
94
120
IRB\s version:\s irb .+\n
95
- InputMethod:\s ReidlineInputMethod \s with \s Reline \s [^ ]+(?! \s and \s .+) \n
121
+ InputMethod:\s Abstract \s InputMethod \n
96
122
RUBY_PLATFORM: .+\n
97
123
\z
98
124
}x
@@ -114,12 +140,12 @@ def test_irb_info_singleline_without_rc_files
114
140
IRB . conf [ :USE_SINGLELINE ] = true
115
141
IRB . conf [ :VERBOSE ] = false
116
142
workspace = IRB ::WorkSpace . new ( self )
117
- irb = IRB ::Irb . new ( workspace )
143
+ irb = IRB ::Irb . new ( workspace , TestInputMethod . new ( [ ] ) )
118
144
IRB . conf [ :MAIN_CONTEXT ] = irb . context
119
145
expected = %r{
120
146
Ruby\s version: .+\n
121
147
IRB\s version:\s irb .+\n
122
- InputMethod:\s ReadlineInputMethod \s with \s (?~.* \s and \s .+) \n
148
+ InputMethod:\s Abstract \s InputMethod \n
123
149
RUBY_PLATFORM: .+\n
124
150
\z
125
151
}x
@@ -130,32 +156,6 @@ def test_irb_info_singleline_without_rc_files
130
156
IRB . const_set ( :IRBRC_EXT , ext_backup )
131
157
end
132
158
133
- class TestInputMethod < ::IRB ::InputMethod
134
- attr_reader :list , :line_no
135
-
136
- def initialize ( list = [ ] )
137
- super ( "test" )
138
- @line_no = 0
139
- @list = list
140
- end
141
-
142
- def gets
143
- @list [ @line_no ] &.tap { @line_no += 1 }
144
- end
145
-
146
- def eof?
147
- @line_no >= @list . size
148
- end
149
-
150
- def encoding
151
- Encoding . default_external
152
- end
153
-
154
- def reset
155
- @line_no = 0
156
- end
157
- end
158
-
159
159
def test_measure
160
160
IRB . init_config ( nil )
161
161
IRB . conf [ :PROMPT ] = {
@@ -376,15 +376,14 @@ def test_irb_load
376
376
end
377
377
378
378
def test_ls
379
+ input = TestInputMethod . new ( [
380
+ "ls Object.new.tap { |o| o.instance_variable_set(:@a, 1) }\n " ,
381
+ ] )
379
382
IRB . init_config ( nil )
380
383
workspace = IRB ::WorkSpace . new ( self )
384
+ irb = IRB ::Irb . new ( workspace , input )
381
385
IRB . conf [ :VERBOSE ] = false
382
- irb = IRB ::Irb . new ( workspace )
383
386
IRB . conf [ :MAIN_CONTEXT ] = irb . context
384
- input = TestInputMethod . new ( [
385
- "ls Object.new.tap { |o| o.instance_variable_set(:@a, 1) }\n " ,
386
- ] )
387
- irb = IRB ::Irb . new ( IRB ::WorkSpace . new ( Object . new ) , input )
388
387
irb . context . return_format = "=> %s\n "
389
388
out , err = capture_output do
390
389
irb . eval_input
@@ -394,15 +393,14 @@ def test_ls
394
393
end
395
394
396
395
def test_whereami
396
+ input = TestInputMethod . new ( [
397
+ "whereami\n " ,
398
+ ] )
397
399
IRB . init_config ( nil )
398
400
workspace = IRB ::WorkSpace . new ( self )
401
+ irb = IRB ::Irb . new ( workspace , input )
399
402
IRB . conf [ :VERBOSE ] = false
400
- irb = IRB ::Irb . new ( workspace )
401
403
IRB . conf [ :MAIN_CONTEXT ] = irb . context
402
- input = TestInputMethod . new ( [
403
- "whereami\n " ,
404
- ] )
405
- irb = IRB ::Irb . new ( IRB ::WorkSpace . new ( Object . new ) , input )
406
404
irb . context . return_format = "=> %s\n "
407
405
out , err = capture_output do
408
406
irb . eval_input
0 commit comments