Skip to content
Newer
Older
100644 91 lines (76 sloc) 2.93 KB
3bb6cd3 @ConradIrwin Issue 284, Pry should respect input encoding.
ConradIrwin authored
1 # coding: utf-8
5a274b2 @banister added input_stack support to Pry
banister authored
2 require 'helper'
3
4 describe "Pry#input_stack" do
8f3e455 @kyrylo Tidy up tests and remove some repeating code
kyrylo authored
5 before do
6 @str_output = StringIO.new
7 end
8
5a274b2 @banister added input_stack support to Pry
banister authored
9 it 'should accept :input_stack as a config option' do
10 stack = [StringIO.new("test")]
11 Pry.new(:input_stack => stack).input_stack.should == stack
12 end
13
14 it 'should use defaults from Pry.config' do
15 Pry.config.input_stack = [StringIO.new("exit")]
16 Pry.new.input_stack.should == Pry.config.input_stack
17 Pry.config.input_stack = []
18 end
19
4e3853e @banister now using 'retry' (in read loop) to switch input objects in input_stack
banister authored
20 it 'should read from all input objects on stack and exit session (usingn repl)' do
5a274b2 @banister added input_stack support to Pry
banister authored
21 stack = [b = StringIO.new(":cloister\nexit\n"), c = StringIO.new(":baron\n")]
22 instance = Pry.new(:input => StringIO.new(":alex\n"),
8f3e455 @kyrylo Tidy up tests and remove some repeating code
kyrylo authored
23 :output => @str_output,
5a274b2 @banister added input_stack support to Pry
banister authored
24 :input_stack => stack)
25
26 instance.repl
8f3e455 @kyrylo Tidy up tests and remove some repeating code
kyrylo authored
27 @str_output.string.should =~ /:alex/
28 @str_output.string.should =~ /:baron/
29 @str_output.string.should =~ /:cloister/
5a274b2 @banister added input_stack support to Pry
banister authored
30 end
31
4e3853e @banister now using 'retry' (in read loop) to switch input objects in input_stack
banister authored
32 it 'input objects should be popped off stack as they are used up' do
33 stack = [StringIO.new(":cloister\n"), StringIO.new(":baron\n")]
34 instance = Pry.new(:input => StringIO.new(":alex\n"),
8f3e455 @kyrylo Tidy up tests and remove some repeating code
kyrylo authored
35 :output => @str_output,
4e3853e @banister now using 'retry' (in read loop) to switch input objects in input_stack
banister authored
36 :input_stack => stack)
37
38 stack.size.should == 2
39
40 instance.rep
8f3e455 @kyrylo Tidy up tests and remove some repeating code
kyrylo authored
41 @str_output.string.should =~ /:alex/
4e3853e @banister now using 'retry' (in read loop) to switch input objects in input_stack
banister authored
42 instance.rep
8f3e455 @kyrylo Tidy up tests and remove some repeating code
kyrylo authored
43 @str_output.string.should =~ /:baron/
4e3853e @banister now using 'retry' (in read loop) to switch input objects in input_stack
banister authored
44 stack.size.should == 1
45 instance.rep
8f3e455 @kyrylo Tidy up tests and remove some repeating code
kyrylo authored
46 @str_output.string.should =~ /:cloister/
4e3853e @banister now using 'retry' (in read loop) to switch input objects in input_stack
banister authored
47 stack.size.should == 0
48 end
49
50 it 'should revert to Pry.config.input when it runs out of input objects in input_stack' do
51 redirect_pry_io(StringIO.new(":rimbaud\nexit\n"), StringIO.new) do
52 stack = [StringIO.new(":cloister\n"), StringIO.new(":baron\n")]
53 instance = Pry.new(:input => StringIO.new(":alex\n"),
8f3e455 @kyrylo Tidy up tests and remove some repeating code
kyrylo authored
54 :output => @str_output,
4e3853e @banister now using 'retry' (in read loop) to switch input objects in input_stack
banister authored
55 :input_stack => stack)
56
57 instance.repl
8f3e455 @kyrylo Tidy up tests and remove some repeating code
kyrylo authored
58 @str_output.string.should =~ /:alex/
59 @str_output.string.should =~ /:baron/
60 @str_output.string.should =~ /:cloister/
61 @str_output.string.should =~ /:rimbaud/
4e3853e @banister now using 'retry' (in read loop) to switch input objects in input_stack
banister authored
62 end
63 end
64
65 it 'should display error and throw(:breakout) if at end of input after using up input_stack objects' do
66 catch(:breakout) do
8f3e455 @kyrylo Tidy up tests and remove some repeating code
kyrylo authored
67 redirect_pry_io(StringIO.new(":rimbaud\n"), @str_output) do
4e3853e @banister now using 'retry' (in read loop) to switch input objects in input_stack
banister authored
68 Pry.new(:input_stack => [StringIO.new(":a\n"), StringIO.new(":b\n")]).repl
69 end
70 end
8f3e455 @kyrylo Tidy up tests and remove some repeating code
kyrylo authored
71 @str_output.string.should =~ /Error: Pry ran out of things to read/
4e3853e @banister now using 'retry' (in read loop) to switch input objects in input_stack
banister authored
72 end
73
3bb6cd3 @ConradIrwin Issue 284, Pry should respect input encoding.
ConradIrwin authored
74 if "".respond_to?(:encoding)
7b251ac @ConradIrwin Clean line buffer after soiling it with Shift_JIS
ConradIrwin authored
75 after do
76 Pry.line_buffer = [""]
77 Pry.current_line = 1
78 end
3bb6cd3 @ConradIrwin Issue 284, Pry should respect input encoding.
ConradIrwin authored
79 it "should pass strings to Pry in the right encoding" do
80 input1 = "'f。。'.encoding.name" # utf-8, see coding declaration
81 input2 = input1.encode('Shift_JIS')
82
83 mock_pry(input1, input2).should == %{=> "UTF-8"\n=> "Shift_JIS"\n\n}
84 end
85
86 it "should be able to use unicode regexes on a UTF-8 terminal" do
1ae9303 @ConradIrwin Use a more rbx-friendly test for unicodeness
ConradIrwin authored
87 mock_pry('":-Þ" =~ /þ/i').should == %{=> 2\n\n}
3bb6cd3 @ConradIrwin Issue 284, Pry should respect input encoding.
ConradIrwin authored
88 end
89 end
5a274b2 @banister added input_stack support to Pry
banister authored
90 end
Something went wrong with that request. Please try again.