Project

General

Profile

Bug #5802 ยป 0002-test-in-both-cases-of-Readline.completion_append_cha.patch

no6v (Nobuhiro IMAI), 12/24/2011 12:39 AM

View differences:

test/readline/test_readline.rb
130 130
        return
131 131
      end
132 132

  
133
      stdin = Tempfile.new("test_readline_stdin")
134
      stdout = Tempfile.new("test_readline_stdout")
135
      begin
136
        actual_text = nil
137
        actual_line_buffer = nil
138
        actual_point = nil
139
        Readline.completion_proc = proc { |text|
140
          actual_text = text
141
          actual_point = Readline.point
142
          actual_line_buffer = Readline.line_buffer
143
          stdin.write(" finish\n")
144
          stdin.close
145
          stdout.close
146
          ["complete"]
147
        }
148
        stdin.write("first second\t")
149
        stdin.flush
150
        replace_stdio(stdin.path, stdout.path) {
151
          Readline.readline("> ", false)
152
        }
153
        assert_equal("first second", actual_line_buffer)
154
        assert_equal(12, actual_point)
155
        assert_equal("first complete finish", Readline.line_buffer)
156
        assert_equal(Encoding.find("locale"), Readline.line_buffer.encoding)
157
        assert_equal(true, Readline.line_buffer.tainted?)
158
        assert_equal(21, Readline.point)
159
      ensure
160
        stdin.close(true)
161
        stdout.close(true)
133
      [" ", nil].each do |append_character|
134
        Readline.completion_append_character = append_character
135
        stdin = Tempfile.new("test_readline_stdin")
136
        stdout = Tempfile.new("test_readline_stdout")
137
        begin
138
          actual_text = nil
139
          actual_line_buffer = nil
140
          actual_point = nil
141
          Readline.completion_proc = proc { |text|
142
            actual_text = text
143
            actual_point = Readline.point
144
            actual_line_buffer = Readline.line_buffer
145
            stdin.write("%sfinish\n" % (" " unless append_character))
146
            stdin.close
147
            stdout.close
148
            ["complete"]
149
          }
150
          stdin.write("first second\t")
151
          stdin.flush
152
          replace_stdio(stdin.path, stdout.path) {
153
            Readline.readline("> ", false)
154
          }
155
          assert_equal("first second", actual_line_buffer)
156
          assert_equal(12, actual_point)
157
          assert_equal("first complete finish", Readline.line_buffer)
158
          assert_equal(Encoding.find("locale"), Readline.line_buffer.encoding)
159
          assert_equal(true, Readline.line_buffer.tainted?)
160
          assert_equal(21, Readline.point)
161
        ensure
162
          stdin.close(true)
163
          stdout.close(true)
164
        end
162 165
      end
163 166
    end
164 167
  end
165
-