mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	This commit was manufactured by cvs2svn to create branch 'ruby_1_8'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7453 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									ced3d3c870
								
							
						
					
					
						commit
						61ab3618f3
					
				
					 7 changed files with 424 additions and 0 deletions
				
			
		
							
								
								
									
										73
									
								
								test/readline/test_readline.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								test/readline/test_readline.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,73 @@
 | 
			
		|||
begin
 | 
			
		||||
  require "readline"
 | 
			
		||||
rescue LoadError
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
if defined?(Readline)
 | 
			
		||||
 | 
			
		||||
require "test/unit"
 | 
			
		||||
require "tempfile"
 | 
			
		||||
 | 
			
		||||
class TestReadline < Test::Unit::TestCase
 | 
			
		||||
  def test_readline
 | 
			
		||||
    stdin = Tempfile.new("test_readline_stdin")
 | 
			
		||||
    stdout = Tempfile.new("test_readline_stdout")
 | 
			
		||||
    begin
 | 
			
		||||
      stdin.write("hello\n")
 | 
			
		||||
      stdin.close
 | 
			
		||||
      stdout.close
 | 
			
		||||
      line = replace_stdio(stdin.path, stdout.path) { Readline.readline("> ") }
 | 
			
		||||
      assert_equal("hello", line)
 | 
			
		||||
      assert_equal(true, line.tainted?)
 | 
			
		||||
      stdout.open
 | 
			
		||||
      assert_equal("> ", stdout.read(2))
 | 
			
		||||
      assert_raises(SecurityError) do
 | 
			
		||||
        Thread.start {
 | 
			
		||||
          $SAFE = 1
 | 
			
		||||
          replace_stdio(stdin.path, stdout.path) do
 | 
			
		||||
            Readline.readline("> ".taint)
 | 
			
		||||
          end
 | 
			
		||||
        }.join
 | 
			
		||||
      end
 | 
			
		||||
      assert_raises(SecurityError) do
 | 
			
		||||
        Thread.start {
 | 
			
		||||
          $SAFE = 4
 | 
			
		||||
          replace_stdio(stdin.path, stdout.path) { Readline.readline("> ") }
 | 
			
		||||
        }.join
 | 
			
		||||
      end
 | 
			
		||||
    ensure
 | 
			
		||||
      stdin.close(true)
 | 
			
		||||
      stdout.close(true)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_completion_append_character
 | 
			
		||||
    Readline.completion_append_character = "x"
 | 
			
		||||
    assert_equal("x", Readline.completion_append_character)
 | 
			
		||||
    Readline.completion_append_character = "xyz"
 | 
			
		||||
    assert_equal("x", Readline.completion_append_character)
 | 
			
		||||
    Readline.completion_append_character = nil
 | 
			
		||||
    assert_equal(nil, Readline.completion_append_character)
 | 
			
		||||
    Readline.completion_append_character = ""
 | 
			
		||||
    assert_equal(nil, Readline.completion_append_character)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def replace_stdio(stdin_path, stdout_path)
 | 
			
		||||
    orig_stdin = STDIN.dup
 | 
			
		||||
    orig_stdout = STDOUT.dup
 | 
			
		||||
    STDIN.reopen(stdin_path, "r")
 | 
			
		||||
    STDOUT.reopen(stdout_path, "w")
 | 
			
		||||
    begin
 | 
			
		||||
      yield
 | 
			
		||||
    ensure
 | 
			
		||||
      STDIN.reopen(orig_stdin)
 | 
			
		||||
      STDOUT.reopen(orig_stdout)
 | 
			
		||||
      orig_stdin.close
 | 
			
		||||
      orig_stdout.close
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue