rbindkeys 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,222 @@
1
+ # -*- coding:utf-8; mode:ruby; -*-
2
+
3
+ require 'rbindkeys'
4
+ require 'revdev'
5
+
6
+ include Rbindkeys
7
+
8
+ describe KeyEventHandler do
9
+ before do
10
+ @ope = mock DeviceOperator
11
+ @ope.stub(:pressed_key_set){ [] }
12
+ @resolver = mock BindResolver
13
+ @resolver2 = BindResolver.new
14
+ BindResolver.stub!(:new){@resolver}
15
+ @resolver.stub!(:two_stroke?){false}
16
+
17
+ @handler = KeyEventHandler.new @ope
18
+ end
19
+
20
+ describe "#handle" do
21
+ context "with a pressed event" do
22
+ before do
23
+ @event = Revdev::InputEvent.new nil, Revdev::EV_KEY, Revdev::KEY_K, 1
24
+ end
25
+ context "if handle_pressed_event return :through" do
26
+ before do
27
+ @handler.should_receive(:handle_press_event){:through}
28
+ end
29
+ it "shoud send @event" do
30
+ @ope.should_receive(:send_event).with(@event)
31
+ @handler.handle @event
32
+ end
33
+ end
34
+
35
+ context "if handle_pressed_event return :ignore" do
36
+ before do
37
+ @handler.should_receive(:handle_press_event){:ignore}
38
+ end
39
+ it "shoud ignore @event" do
40
+ @ope.should_not_receive(:send_event)
41
+ @handler.handle @event
42
+ end
43
+ end
44
+ end
45
+
46
+ context "with a released event" do
47
+ before do
48
+ @event = Revdev::InputEvent.new nil, Revdev::EV_KEY, Revdev::KEY_K, 0
49
+ @handler.should_receive(:handle_release_event){:ignore}
50
+ end
51
+ it "shoud ignore @event" do
52
+ @ope.should_not_receive(:send_event)
53
+ @handler.handle @event
54
+ end
55
+ end
56
+
57
+ context "with a pressing event" do
58
+ before do
59
+ @event = Revdev::InputEvent.new nil, Revdev::EV_KEY, Revdev::KEY_K, 2
60
+ @handler.should_receive(:handle_pressing_event){:ignore}
61
+ end
62
+ it "shoud ignore @event" do
63
+ @ope.should_not_receive(:send_event)
64
+ @handler.handle @event
65
+ end
66
+ end
67
+ end
68
+
69
+ describe "#handle_press_event" do
70
+ before do
71
+ @event = Revdev::InputEvent.new nil, Revdev::EV_KEY, 1, 1
72
+ end
73
+ context "with an event which hit a key bind" do
74
+ before do
75
+ @key_bind = KeyBind.new [0,1], [2,3]
76
+ @resolver.should_receive(:resolve).and_return(@key_bind)
77
+ end
78
+ it "should return :ignore, send messages to @ope and update @active_bind_set" do
79
+ @ope.should_receive(:press_key).with(2)
80
+ @ope.should_receive(:press_key).with(3)
81
+ @ope.should_receive(:release_key).with(0)
82
+ @handler.handle_press_event(@event).should == :ignore
83
+ @handler.active_bind_set.should == [@key_bind]
84
+ end
85
+ end
86
+ context "with an event which hit a BindResolver" do
87
+ before do
88
+ @key_bind = KeyBind.new [0,1], @resolver2
89
+ @resolver.should_receive(:resolve).and_return(@key_bind)
90
+ end
91
+ it "should return :ignore and update @bind_resolver" do
92
+ @handler.handle_press_event(@event).should == :ignore
93
+ @handler.bind_resolver.should == @resolver2
94
+ end
95
+ end
96
+ context "with an event which hit a Proc" do
97
+ before do
98
+ @proc = proc {
99
+ :foo
100
+ }
101
+ @key_bind = KeyBind.new [0,1], @proc
102
+ @resolver.should_receive(:resolve).and_return(@key_bind)
103
+ end
104
+ it "should return :ignore and update @bind_resolver" do
105
+ @handler.handle_press_event(@event).should == :foo
106
+ end
107
+ end
108
+ context "with an event which hit no one" do
109
+ before do
110
+ @resolver.should_receive(:resolve).and_return(:foo)
111
+ end
112
+ it "should return :foo" do
113
+ @handler.handle_press_event(@event).should == :foo
114
+ end
115
+ end
116
+ context "with an event which hit no one and 2 stroke @bind_resolver" do
117
+ before do
118
+ @resolver.should_receive(:resolve).and_return(:foo)
119
+ @resolver.stub(:two_stroke?){true}
120
+ end
121
+ it "should return :foo" do
122
+ @handler.handle_press_event(@event).should == :foo
123
+ # TODO check to change @bind_resolver to @default_bind_resolver or @window_bind_resolver
124
+ end
125
+ end
126
+ end
127
+
128
+ describe "#handle_release_event" do
129
+ before do
130
+ event = Revdev::InputEvent.new nil, Revdev::EV_KEY, 1, 1
131
+ @key_bind = KeyBind.new [0,1], [2,3]
132
+ @resolver.should_receive(:resolve).and_return(@key_bind)
133
+ @ope.should_receive(:press_key).with(2)
134
+ @ope.should_receive(:press_key).with(3)
135
+ @ope.should_receive(:release_key).with(0)
136
+ @handler.handle_press_event event
137
+ end
138
+ context "with an event which can be found in @active_bind_set" do
139
+ it "should return :ignore, update @active_bind_set and send messages to @ope" do
140
+ @ope.should_receive(:release_key).with(2)
141
+ @ope.should_receive(:release_key).with(3)
142
+ @event = Revdev::InputEvent.new nil, Revdev::EV_KEY, 1, 0
143
+ @handler.handle_release_event(@event).should == :ignore
144
+ @handler.active_bind_set.empty?.should be_true
145
+ end
146
+ it "should return :ignore and update @active_bind_set" do
147
+ @ope.should_receive(:release_key).with(2)
148
+ @ope.should_receive(:release_key).with(3)
149
+ @event = Revdev::InputEvent.new nil, Revdev::EV_KEY, 0, 0
150
+ @handler.handle_release_event(@event).should == :ignore
151
+ @handler.active_bind_set.empty?.should be_true
152
+ end
153
+ end
154
+ context "with an event which can not be found in @active_bind_set" do
155
+ it "should return :through" do
156
+ @event = Revdev::InputEvent.new nil, Revdev::EV_KEY, 10, 0
157
+ @handler.handle_release_event(@event).should == :through
158
+ end
159
+ end
160
+ end
161
+
162
+ describe "#handle_pressing_event" do
163
+ context "with an pressing event and empty @active_bind_set" do
164
+ it "should return :through" do
165
+ @event = Revdev::InputEvent.new nil, Revdev::EV_KEY, 1, 2
166
+ @handler.handle_pressing_event(@event).should == :through
167
+ end
168
+ end
169
+ context "with an pressing event and @active_bind_set which have length:1" do
170
+ before do
171
+ event = Revdev::InputEvent.new nil, Revdev::EV_KEY, 1, 1
172
+ @key_bind = KeyBind.new [0,1], [2,3]
173
+ @resolver.should_receive(:resolve).and_return(@key_bind)
174
+ @ope.should_receive(:press_key).with(2)
175
+ @ope.should_receive(:press_key).with(3)
176
+ @ope.should_receive(:release_key).with(0)
177
+ @handler.handle_press_event event
178
+ end
179
+ it "should return :ignore and send messages to @operator" do
180
+ @ope.should_receive(:pressing_key).with(2)
181
+ @ope.should_receive(:pressing_key).with(3)
182
+ @event = Revdev::InputEvent.new nil, Revdev::EV_KEY, 1, 2
183
+ @handler.handle_pressing_event(@event).should == :ignore
184
+ end
185
+ end
186
+ end
187
+
188
+ describe '#active_window_changed' do
189
+ before do
190
+ @window = mock ActiveWindowX::Window
191
+ @window.stub(:app_name).and_return('qux');
192
+ @resolver2 = mock BindResolver
193
+ BindResolver.stub!(:new){@resolver2}
194
+ end
195
+ context 'with a Window, which contains "foo" in the title,' do
196
+ before do
197
+ @window.stub(:title).and_return('foobar');
198
+ @handler.window nil, /foo/ do
199
+ end
200
+ end
201
+ it 'should change @bind_resolver' do
202
+ puts "phoooooo"
203
+ resolver = @handler.bind_resolver
204
+ @handler.active_window_changed(@window)
205
+ @handler.bind_resolver.should_not == resolver
206
+ end
207
+ end
208
+ context 'with a Window, which does not contain "foo" in the title,' do
209
+ before do
210
+ @window.stub(:title).and_return('barbaz');
211
+ @handler.window nil, /foo/ do
212
+ end
213
+ end
214
+ it 'should not change @bind_resolver' do
215
+ resolver = @handler.bind_resolver
216
+ @handler.active_window_changed(@window)
217
+ @handler.bind_resolver.should == resolver
218
+ end
219
+ end
220
+ end
221
+
222
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbindkeys
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Keiichiro Ui
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-06-06 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: revdev
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: ruinput
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: active_window_x
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ type: :development
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: rake
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ type: :development
89
+ version_requirements: *id005
90
+ - !ruby/object:Gem::Dependency
91
+ name: rspec
92
+ prerelease: false
93
+ requirement: &id006 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ type: :development
103
+ version_requirements: *id006
104
+ description: key remap
105
+ email:
106
+ - keiichiro.ui@gmail.com
107
+ executables:
108
+ - rbindkeys
109
+ extensions: []
110
+
111
+ extra_rdoc_files: []
112
+
113
+ files:
114
+ - .gitignore
115
+ - Gemfile
116
+ - LICENSE
117
+ - README.md
118
+ - Rakefile
119
+ - bin/rbindkeys
120
+ - lib/rbindkeys.rb
121
+ - lib/rbindkeys/bind_resolver.rb
122
+ - lib/rbindkeys/bind_set.rb
123
+ - lib/rbindkeys/bind_tree.rb
124
+ - lib/rbindkeys/cli.rb
125
+ - lib/rbindkeys/device.rb
126
+ - lib/rbindkeys/device_operator.rb
127
+ - lib/rbindkeys/fix_resolver.rb
128
+ - lib/rbindkeys/key_bind.rb
129
+ - lib/rbindkeys/key_event_handler.rb
130
+ - lib/rbindkeys/key_event_handler/configurer.rb
131
+ - lib/rbindkeys/log_utils.rb
132
+ - lib/rbindkeys/observer.rb
133
+ - lib/rbindkeys/version.rb
134
+ - lib/rbindkeys/virtual_device.rb
135
+ - lib/rbindkeys/window_matcher.rb
136
+ - rbindkeys.gemspec
137
+ - sample/emacs.rb
138
+ - sample/swap_left_ctrl_and_caps.rb
139
+ - spec/bind_resolver_spec.rb
140
+ - spec/bind_tree_bind_spec.rb
141
+ - spec/bind_tree_resolve_for_pressed_event_spec.rb
142
+ - spec/bind_tree_resolve_for_released_event_spec.rb
143
+ - spec/cli_spec.rb
144
+ - spec/device_operator_spec.rb
145
+ - spec/fix_resolver_spec.rb
146
+ - spec/key_event_handler/configurer_spec.rb
147
+ - spec/key_event_handler/handle_spec.rb
148
+ homepage: ""
149
+ licenses: []
150
+
151
+ post_install_message:
152
+ rdoc_options: []
153
+
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ hash: 3
162
+ segments:
163
+ - 0
164
+ version: "0"
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ hash: 3
171
+ segments:
172
+ - 0
173
+ version: "0"
174
+ requirements: []
175
+
176
+ rubyforge_project:
177
+ rubygems_version: 1.8.15
178
+ signing_key:
179
+ specification_version: 3
180
+ summary: key remap
181
+ test_files:
182
+ - spec/bind_resolver_spec.rb
183
+ - spec/bind_tree_bind_spec.rb
184
+ - spec/bind_tree_resolve_for_pressed_event_spec.rb
185
+ - spec/bind_tree_resolve_for_released_event_spec.rb
186
+ - spec/cli_spec.rb
187
+ - spec/device_operator_spec.rb
188
+ - spec/fix_resolver_spec.rb
189
+ - spec/key_event_handler/configurer_spec.rb
190
+ - spec/key_event_handler/handle_spec.rb