|
4 | 4 |
|
5 | 5 | module TestIRB
|
6 | 6 | class TestCompletion < Test::Unit::TestCase
|
| 7 | + def setup |
| 8 | + # make sure require completion candidates are not cached |
| 9 | + IRB::InputCompletor.class_variable_set(:@@files_from_load_path, nil) |
| 10 | + end |
| 11 | + |
7 | 12 | def test_nonstring_module_name
|
8 | 13 | begin
|
9 | 14 | require "irb/completion"
|
@@ -84,6 +89,43 @@ def test_complete_require
|
84 | 89 | end
|
85 | 90 | end
|
86 | 91 |
|
| 92 | + def test_complete_require_with_pathname_in_load_path |
| 93 | + temp_dir = Dir.mktmpdir |
| 94 | + File.write(File.join(temp_dir, "foo.rb"), "test") |
| 95 | + test_path = Pathname.new(temp_dir) |
| 96 | + $LOAD_PATH << test_path |
| 97 | + |
| 98 | + candidates = IRB::InputCompletor::CompletionProc.("'foo", "require ", "") |
| 99 | + assert_equal ["'foo"], candidates |
| 100 | + ensure |
| 101 | + $LOAD_PATH.pop if test_path |
| 102 | + FileUtils.remove_entry(temp_dir) if temp_dir |
| 103 | + end |
| 104 | + |
| 105 | + def test_complete_require_with_string_convertable_in_load_path |
| 106 | + temp_dir = Dir.mktmpdir |
| 107 | + File.write(File.join(temp_dir, "foo.rb"), "test") |
| 108 | + object = Object.new |
| 109 | + object.define_singleton_method(:to_s) { temp_dir } |
| 110 | + $LOAD_PATH << object |
| 111 | + |
| 112 | + candidates = IRB::InputCompletor::CompletionProc.("'foo", "require ", "") |
| 113 | + assert_equal ["'foo"], candidates |
| 114 | + ensure |
| 115 | + $LOAD_PATH.pop if object |
| 116 | + FileUtils.remove_entry(temp_dir) if temp_dir |
| 117 | + end |
| 118 | + |
| 119 | + def test_complete_require_with_malformed_object_in_load_path |
| 120 | + object = Object.new |
| 121 | + def object.to_s; raise; end |
| 122 | + $LOAD_PATH << object |
| 123 | + |
| 124 | + assert_empty IRB::InputCompletor::CompletionProc.("'foo", "require ", "") |
| 125 | + ensure |
| 126 | + $LOAD_PATH.pop if object |
| 127 | + end |
| 128 | + |
87 | 129 | def test_complete_require_library_name_first
|
88 | 130 | pend 'Need to use virtual library paths'
|
89 | 131 | candidates = IRB::InputCompletor::CompletionProc.("'csv", "require ", "")
|
|
0 commit comments