sleipnir-api 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/History.txt +32 -0
  2. data/Manifest.txt +20 -3
  3. data/Rakefile +11 -1
  4. data/TODO.txt +4 -10
  5. data/bin/grepnir +1 -1
  6. data/examples/close_dup.rb +1 -1
  7. data/examples/close_err.rb +12 -0
  8. data/examples/command_list.rb +135 -0
  9. data/examples/open_last_url_by_firefox.rb +44 -0
  10. data/examples/open_selected_links.rb +40 -0
  11. data/helper/rake.rb +3 -57
  12. data/helper/rake/rake.rb +58 -0
  13. data/helper/{rake_sh_filter.rb → rake/rake_sh_filter.rb} +0 -0
  14. data/helper/{util.rb → rake/util.rb} +0 -0
  15. data/lib/sleipnir_api/cli/grepnir.rb +2 -3
  16. data/lib/sleipnir_api/command.rb +126 -0
  17. data/lib/sleipnir_api/commands.rb +264 -0
  18. data/lib/sleipnir_api/profile.rb +166 -27
  19. data/lib/sleipnir_api/profile/ini.rb +202 -0
  20. data/lib/sleipnir_api/profile/key.rb +120 -0
  21. data/lib/sleipnir_api/profile/section.rb +147 -0
  22. data/lib/sleipnir_api/profile/util.rb +82 -0
  23. data/lib/sleipnir_api/searcher.rb +133 -0
  24. data/lib/sleipnir_api/security.rb +88 -18
  25. data/lib/sleipnir_api/sleipnir.rb +91 -7
  26. data/lib/sleipnir_api/tab.rb +68 -2
  27. data/lib/sleipnir_api/tabbed_ie.rb +33 -0
  28. data/lib/sleipnir_api/util.rb +25 -0
  29. data/lib/sleipnir_api/version.rb +2 -2
  30. data/scripts/gesture2rb.rb +42 -0
  31. data/scripts/make_gesture.rb +271 -0
  32. data/scripts/subcategory.csv +253 -0
  33. data/spec/sleipnir_api/profile_mock_spec.rb +80 -6
  34. data/spec/sleipnir_api/profile_section_mock_spec.rb +143 -0
  35. data/spec/sleipnir_api/profile_spec.rb +191 -0
  36. data/spec/sleipnir_api/security_spec.rb +58 -0
  37. data/spec/sleipnir_api/tab_mock_spec.rb +0 -5
  38. data/spec/sleipnir_api/tab_spec.rb +27 -0
  39. data/spec/spec_helper.rb +20 -0
  40. metadata +22 -5
  41. data/helper/helper.rb +0 -3
@@ -42,14 +42,12 @@ describe SleipnirAPI::Profile do
42
42
  end
43
43
 
44
44
  it "#get_string(:ini) should send GetProfileStringEx" do
45
- @mock.should_receive(:UserPath).and_return(@user_path)
46
45
  @mock.should_receive(:GetProfileStringEx).with(
47
46
  "section", "key", nil, File.expand_path("foo.ini", @user_path))
48
47
  @profile.get_string("section", "key", :ini => "foo.ini")
49
48
  end
50
49
 
51
50
  it "#get_string(:ini, :default) should send GetProfileStringEx" do
52
- @mock.should_receive(:UserPath).and_return(@user_path)
53
51
  @mock.should_receive(:GetProfileStringEx).with(
54
52
  "section", "key", "default value", "c:/foo.ini")
55
53
  @profile.get_string("section", "key", :ini => "c:/foo.ini", :default => "default value")
@@ -79,14 +77,12 @@ describe SleipnirAPI::Profile do
79
77
  end
80
78
 
81
79
  it "#get_int(:ini) should send GetProfileIntEx" do
82
- @mock.should_receive(:UserPath).and_return(@user_path)
83
80
  @mock.should_receive(:GetProfileIntEx).with(
84
81
  "section", "key", nil, File.expand_path("foo.ini", @user_path))
85
82
  @profile.get_int("section", "key", :ini => "foo.ini")
86
83
  end
87
84
 
88
85
  it "#get_int(:ini, :default) should send GetProfileIntEx" do
89
- @mock.should_receive(:UserPath).and_return(@user_path)
90
86
  @mock.should_receive(:GetProfileIntEx).with(
91
87
  "section", "key", 123, "c:/foo.ini")
92
88
  @profile.get_int("section", "key", :ini => "c:/foo.ini", :default => 123)
@@ -96,12 +92,12 @@ describe SleipnirAPI::Profile do
96
92
 
97
93
  # write string
98
94
 
99
- it "#write_int should send WriteProfileString" do
95
+ it "#write_string should send WriteProfileString" do
100
96
  @mock.should_receive(:WriteProfileString).with("section", "key", "data")
101
97
  @profile.write_string("section", "key", "data")
102
98
  end
103
99
 
104
- it "#write_int(:cipher) should send WriteProfileStringCipher" do
100
+ it "#write_string(:cipher) should send WriteProfileStringCipher" do
105
101
  @mock.should_receive(:WriteProfileStringCipher).with("section", "key", "data")
106
102
  @profile.write_string("section", "key", "data", :cipher => true)
107
103
  end
@@ -126,3 +122,81 @@ describe SleipnirAPI::Profile do
126
122
  end
127
123
 
128
124
  end
125
+
126
+ describe SleipnirAPI::Profile, "new with cipher => true" do
127
+
128
+ before(:all) do
129
+ @pnir = SleipnirAPI.connect
130
+ @profile = @pnir.profile(:cipher => true)
131
+ @user_path = @pnir.user_path
132
+ @api = @pnir.instance_variable_get(:@api)
133
+ end
134
+
135
+ after(:all) do
136
+ @pnir.instance_variable_set(:@api, @api)
137
+ end
138
+
139
+ before do
140
+ @mock = mock("Sleipnir.API")
141
+ @pnir.instance_variable_set(:@api, @mock)
142
+ end
143
+
144
+ it "#write_int should send WriteProfileIntCipher" do
145
+ @mock.should_receive(:WriteProfileIntCipher).with("section", "key", 123)
146
+ @profile.write_int("section", "key", 123)
147
+ end
148
+
149
+ it "#write_string should send WriteProfileStringCipher" do
150
+ @mock.should_receive(:WriteProfileStringCipher).with("section", "key", "data")
151
+ @profile.write_string("section", "key", "data")
152
+ end
153
+
154
+ it "#get_string should send GetProfileStringCipher" do
155
+ @mock.should_receive(:GetProfileStringCipher).with("section", "key", nil)
156
+ @profile.get_string("section", "key")
157
+ end
158
+
159
+ it "#get_int(:default) should send GetProfileIntCipher" do
160
+ @mock.should_receive(:GetProfileIntCipher).with("section", "key", 123)
161
+ @profile.get_int("section", "key", :default => 123)
162
+ end
163
+
164
+ end
165
+
166
+ describe SleipnirAPI::Profile, "new with :ini => foo.ini" do
167
+
168
+ before(:all) do
169
+ @pnir = SleipnirAPI.connect
170
+ @profile = @pnir.profile(:cipher => true)
171
+ @user_path = @pnir.user_path
172
+ @api = @pnir.instance_variable_get(:@api)
173
+ end
174
+
175
+ after(:all) do
176
+ @pnir.instance_variable_set(:@api, @api)
177
+ end
178
+
179
+ before do
180
+ @mock = mock("Sleipnir.API")
181
+ @pnir.instance_variable_set(:@api, @mock)
182
+ end
183
+
184
+ it "#get_string(:ini) should send GetProfileStringEx" do
185
+ @mock.should_receive(:GetProfileStringEx).with(
186
+ "section", "key", nil, File.expand_path("foo.ini", @user_path))
187
+ @profile.get_string("section", "key", :ini => "foo.ini")
188
+ end
189
+
190
+ it "#get_string(:ini, :default) should send GetProfileStringEx" do
191
+ @mock.should_receive(:GetProfileStringEx).with(
192
+ "section", "key", "default value", "c:/foo.ini")
193
+ @profile.get_string("section", "key", :ini => "c:/foo.ini", :default => "default value")
194
+ end
195
+
196
+ it "#get_int(:ini) should send GetProfileIntEx" do
197
+ @mock.should_receive(:GetProfileIntEx).with(
198
+ "section", "key", nil, File.expand_path("foo.ini", @user_path))
199
+ @profile.get_int("section", "key", :ini => "foo.ini")
200
+ end
201
+
202
+ end
@@ -0,0 +1,143 @@
1
+ require File.join(File.dirname(__FILE__), "../spec_helper.rb")
2
+
3
+ describe SleipnirAPI::Profile::Section do
4
+
5
+ before(:all) do
6
+ @pnir = SleipnirAPI.connect
7
+ @profile = @pnir.profile
8
+ @section = @profile.Script.section("section")
9
+ @user_path = @pnir.user_path
10
+ @api = @pnir.instance_variable_get(:@api)
11
+ end
12
+
13
+ after(:all) do
14
+ @pnir.instance_variable_set(:@api, @api)
15
+ end
16
+
17
+ before do
18
+ @mock = mock("Sleipnir.API")
19
+ @pnir.instance_variable_set(:@api, @mock)
20
+ end
21
+
22
+
23
+ # get string
24
+
25
+ it "#get_string should send GetProfileString" do
26
+ @mock.should_receive(:GetProfileString).with("section", "key", nil)
27
+ @section.get_string("key")
28
+ end
29
+
30
+ it "#get_string(:default) should send GetProfileString" do
31
+ @mock.should_receive(:GetProfileString).with("section", "key", "default value")
32
+ @section.get_string("key", :default => "default value")
33
+ end
34
+
35
+ it "#get_string(:cipher) should send GetProfileStringCipher" do
36
+ @mock.should_receive(:GetProfileStringCipher).with("section", "key", nil)
37
+ @section.get_string("key", :cipher => true)
38
+ end
39
+
40
+ it "#get_string(:cipher, :default) should send GetProfileStringCipher" do
41
+ @mock.should_receive(:GetProfileStringCipher).with("section", "key", "default value")
42
+ @section.get_string("key", :cipher => true, :default => "default value")
43
+ end
44
+
45
+ it "#get_string(:ini) should raise ArgumentError" do
46
+ lambda { @section.get_string("key", :ini => "foo.ini") }.should raise_error(ArgumentError)
47
+ end
48
+
49
+
50
+ # get int
51
+
52
+ it "#get_int should send GetProfileInt" do
53
+ @mock.should_receive(:GetProfileInt).with("section", "key", nil)
54
+ @section.get_int("key")
55
+ end
56
+
57
+ it "#get_int(:default) should send GetProfileInt" do
58
+ @mock.should_receive(:GetProfileInt).with("section", "key", "default value")
59
+ @section.get_int("key", :default => "default value")
60
+ end
61
+
62
+ it "#get_int(:cipher) should send GetProfileIntCipher" do
63
+ @mock.should_receive(:GetProfileIntCipher).with("section", "key", nil)
64
+ @section.get_int("key", :cipher => true)
65
+ end
66
+
67
+ it "#get_int(:cipher, :default) should send GetProfileIntCipher" do
68
+ @mock.should_receive(:GetProfileIntCipher).with("section", "key", 123)
69
+ @section.get_int("key", :cipher => true, :default => 123)
70
+ end
71
+
72
+
73
+ # write string
74
+
75
+ it "#write_string should send WriteProfileString" do
76
+ @mock.should_receive(:WriteProfileString).with("section", "key", "data")
77
+ @section.write_string("key", "data")
78
+ end
79
+
80
+ it "#write_string(:cipher) should send WriteProfileStringCipher" do
81
+ @mock.should_receive(:WriteProfileStringCipher).with("section", "key", "data")
82
+ @section.write_string("key", "data", :cipher => true)
83
+ end
84
+
85
+ # write int
86
+
87
+ it "#write_int should send WriteProfileInt" do
88
+ @mock.should_receive(:WriteProfileInt).with("section", "key", 123)
89
+ @section.write_int("key", 123)
90
+ end
91
+
92
+ it "#write_int(:cipher) should send WriteProfileIntCipher" do
93
+ @mock.should_receive(:WriteProfileIntCipher).with("section", "key", 123)
94
+ @section.write_int("key", 123, :cipher => true)
95
+ end
96
+
97
+
98
+ # delete
99
+ it "#delete should send DeleteProfileKey" do
100
+ @mock.should_receive(:DeleteProfileKey).with("section", "key")
101
+ @section.delete("key")
102
+ end
103
+
104
+ end
105
+
106
+ describe SleipnirAPI::Profile::Section, "(proxy.ini)" do
107
+
108
+ before(:all) do
109
+ @pnir = SleipnirAPI.connect
110
+ @profile = @pnir.profile
111
+ @section = @profile.Proxy.Proxy
112
+ @user_path = @pnir.user_path
113
+ @api = @pnir.instance_variable_get(:@api)
114
+ end
115
+
116
+ after(:all) do
117
+ @pnir.instance_variable_set(:@api, @api)
118
+ end
119
+
120
+ before do
121
+ @mock = mock("Sleipnir.API")
122
+ @pnir.instance_variable_set(:@api, @mock)
123
+ end
124
+
125
+ # write string
126
+
127
+ it "#write_string should raise ReadOnlyError" do
128
+ lambda { @section.write_string("key", "data") }.should raise_error(SleipnirAPI::Profile::ReadOnlyError)
129
+ end
130
+
131
+ # write int
132
+
133
+ it "#write_int should raise ReadOnlyError" do
134
+ lambda { @section.write_int("key", "data") }.should raise_error(SleipnirAPI::Profile::ReadOnlyError)
135
+ end
136
+
137
+ # delete
138
+
139
+ it "#delete should raise ReadOnlyError" do
140
+ lambda { @section.delete("key") }.should raise_error(SleipnirAPI::Profile::ReadOnlyError)
141
+ end
142
+
143
+ end
@@ -0,0 +1,191 @@
1
+ require File.join(File.dirname(__FILE__), "../spec_helper.rb")
2
+
3
+ describe SleipnirAPI::Profile, "(script.ini)" do
4
+
5
+ before(:all) do
6
+ @pnir = SleipnirAPI.connect
7
+ @profile = @pnir.profile
8
+ @saver = FileSaver.new(@profile.script_ini_path)
9
+ end
10
+
11
+ after(:all) do
12
+ @saver.restore
13
+ end
14
+
15
+ it "Section#script_ini? should be true" do
16
+ @profile.Script.script_ini?.should be_true
17
+ @profile.script.script_ini?.should be_true
18
+ @profile.ini("sCrIpT.InI").script_ini?.should be_true
19
+ end
20
+
21
+ it "Section#read_only? should be false" do
22
+ @profile.Script.read_only?.should be_false
23
+ end
24
+
25
+ it "Section#path should return fullpath" do
26
+ @profile.Script.path.downcase.should == File.expand_path("Script.ini", @pnir.user_path).downcase
27
+ end
28
+
29
+ it "#list_key_format properly" do
30
+ @profile.list_key_format("Search-data%d").should == "Search-data%d"
31
+ @profile.list_key_format("Foo_Bar0_Name").should == "Foo_Bar%d_Name"
32
+ @profile.list_key_format("Foo0_Bar0_Name").should == "Foo0_Bar%d_Name"
33
+ @profile.list_key_format("Foo0_Bar000_Name").should == "Foo0_Bar%03d_Name"
34
+ @profile.list_key_format("Foo_Bar_Name").should == "Foo%d_Bar_Name"
35
+ @profile.list_key_format("Name").should == "Name%d"
36
+ end
37
+
38
+ it "#list should get sequential keys" do
39
+ sec = @profile.Script.MySection
40
+ sec.write_string("My_Key_0", "ABC")
41
+ sec.write_string("My_Key_1", "DEF")
42
+ sec.write_string("My_Key_2", "GHI")
43
+ sec.write_string("My_Key2", "jkl")
44
+
45
+ sec.write_int("Count", 3)
46
+ sec.list("My_Key_0").should == %w(ABC DEF GHI)
47
+ sec.list("My_Key_1").should == ["", "", ""]
48
+
49
+ sec.write_int("Count2", 2)
50
+ sec.list("My_Key_%d", "Count2").should == %w(ABC DEF)
51
+
52
+ sec.write_int("Count", 5)
53
+ sec.list("My_Key_%d").should == %w(ABC DEF GHI) + ["", ""]
54
+ end
55
+
56
+ it "#list should get sequential keys" do
57
+ sec = @profile.Script.MySection
58
+ sec.write_string("My_Key_000", "ABC")
59
+ sec.write_string("My_Key_001", "DEF")
60
+ sec.write_string("My_Key_002", "GHI")
61
+
62
+ sec.write_int("Count", 3)
63
+ sec.list("My_Key_000").should == %w(ABC DEF GHI)
64
+ end
65
+
66
+ it "#list can take a block" do
67
+ sec = @profile.Script.MySection
68
+ sec.write_string("My_Key_000", "000")
69
+ sec.write_string("My_Key_001", "001")
70
+ sec.write_string("My_Key_002", "002")
71
+
72
+ sec.write_int("Count", 3)
73
+ sec.list("My_Key_000") {|k| k }.should == %w(My_Key_000 My_Key_001 My_Key_002)
74
+ sec.list("My_Key_000") {|k| sec.get_int(k) }.should == [0, 1, 2]
75
+ sec.list("My_Key_000").should == %w(000 001 002)
76
+ end
77
+
78
+ it "option argument should inherit parent option (normal method)" do
79
+ profile = @pnir.profile
80
+ profile.get_int("NoSuchSection", "NoSuchKey").should == 0
81
+ profile = @pnir.profile(:default => 111)
82
+ profile.get_int("NoSuchSection", "NoSuchKey").should == 111
83
+
84
+ ini = profile.ini("Script.ini")
85
+ ini.get_int("NoSuchSection", "NoSuchKey").should == 111
86
+ ini = profile.ini("Script.ini", :default => 222)
87
+ ini.get_int("NoSuchSection", "NoSuchKey").should == 222
88
+
89
+ sec = ini.section("NoSuchSection")
90
+ sec.get_int("NoSuchKey").should == 222
91
+ sec = ini.section("NoSuchSection", :default => 333)
92
+ sec.get_int("NoSuchKey").should == 333
93
+
94
+ key = sec.key("NoSuchKey")
95
+ key.get_int.should == 333
96
+ key = sec.key("NoSuchKey", :default => 444)
97
+ key.get_int.should == 444
98
+
99
+ key.get_int(:default => 555).should == 555
100
+
101
+ sec.key("NoSuchKey").get_int.should === 333
102
+ ini.section("NoSuchSection").key("NoSuchKey").get_int.should === 222
103
+ profile.ini("Script.ini").section("NoSuchSection").key("NoSuchKey").get_int.should === 111
104
+ end
105
+
106
+ it "option argument should inherit parent option (method missing)" do
107
+ profile = @pnir.profile
108
+ profile.get_int("NoSuchSection", "NoSuchKey").should == 0
109
+ profile = @pnir.profile(:default => 111)
110
+ profile.get_int("NoSuchSection", "NoSuchKey").should == 111
111
+
112
+ ini = profile.Script
113
+ ini.get_int("NoSuchSection", "NoSuchKey").should == 111
114
+ ini = profile.Script(:default => 222)
115
+ ini.get_int("NoSuchSection", "NoSuchKey").should == 222
116
+
117
+ sec = ini.NoSuchSection
118
+ sec.get_int("NoSuchKey").should == 222
119
+ sec = ini.NoSuchSection(:default => 333)
120
+ sec.get_int("NoSuchKey").should == 333
121
+
122
+ key = sec.NoSuchKey
123
+ key.get_int.should == 333
124
+ key = sec.NoSuchKey(:default => 444)
125
+ key.get_int.should == 444
126
+
127
+ key.get_int(:default => 555).should == 555
128
+
129
+ sec.NoSuchKey.get_int.should === 333
130
+ ini.NoSuchSection.NoSuchKey.get_int.should === 222
131
+ profile.Script.NoSuchSection.NoSuchKey.get_int.should === 111
132
+ end
133
+
134
+ it "SleipnirAPI::Sleipnir#profile should return SleipnirAPI::Profile if ini file not specified" do
135
+ @pnir.profile.should be_an_instance_of(SleipnirAPI::Profile)
136
+ @pnir.profile(:cipher => true).should be_an_instance_of(SleipnirAPI::Profile)
137
+ @pnir.profile(:default => 123).should be_an_instance_of(SleipnirAPI::Profile)
138
+ end
139
+
140
+ it "SleipnirAPI::Sleipnir#profile should return SleipnirAPI::Profile::Ini if ini file specified" do
141
+ @pnir.profile(:Script).should be_an_instance_of(SleipnirAPI::Profile::Ini)
142
+ @pnir.profile("Proxy.ini").should be_an_instance_of(SleipnirAPI::Profile::Ini)
143
+ @pnir.profile(:Script, :default => 123).should be_an_instance_of(SleipnirAPI::Profile::Ini)
144
+ @pnir.profile("Proxy.ini", :default => 123).should be_an_instance_of(SleipnirAPI::Profile::Ini)
145
+ @pnir.profile(:ini => "Proxy.ini").should be_an_instance_of(SleipnirAPI::Profile::Ini)
146
+ @pnir.profile(:ini => "Proxy.ini", :default => 123).should be_an_instance_of(SleipnirAPI::Profile::Ini)
147
+ end
148
+
149
+ it "SleipnirAPI::Sleipnir#profile should return SleipnirAPI::Profile::Ini if ini file specified" do
150
+ @pnir.profile(:Script).should be_an_instance_of(SleipnirAPI::Profile::Ini)
151
+ @pnir.profile("Proxy.ini").should be_an_instance_of(SleipnirAPI::Profile::Ini)
152
+ @pnir.profile(:Script, :default => 123).should be_an_instance_of(SleipnirAPI::Profile::Ini)
153
+ @pnir.profile("Proxy.ini", :default => 123).should be_an_instance_of(SleipnirAPI::Profile::Ini)
154
+ @pnir.profile(:ini => "Proxy.ini").should be_an_instance_of(SleipnirAPI::Profile::Ini)
155
+ @pnir.profile(:ini => "Proxy.ini", :default => 123).should be_an_instance_of(SleipnirAPI::Profile::Ini)
156
+ end
157
+
158
+ it "SleipnirAPI::Profile#section should return SleipnirAPI::Profile::Section" do
159
+ @profile.Script.section("Foo").should be_an_instance_of(SleipnirAPI::Profile::Section)
160
+ @profile.Script.Foo.should be_an_instance_of(SleipnirAPI::Profile::Section)
161
+ end
162
+
163
+ it "SleipnirAPI::Section#key should return SleipnirAPI::Profile::Key" do
164
+ @profile.Script.section("Foo").key("Key").should be_an_instance_of(SleipnirAPI::Profile::Key)
165
+ @profile.Script.Foo.Key.should be_an_instance_of(SleipnirAPI::Profile::Key)
166
+ end
167
+
168
+ it "SleipnirAPI::Ini accessor" do
169
+ ini = @profile.Script
170
+ ini.name.should == "Script"
171
+ ini.parents.should == []
172
+ ini.nodes.should == [ini]
173
+ end
174
+
175
+ it "SleipnirAPI::Section accessor" do
176
+ ini = @profile.Script
177
+ sec = ini.MySection
178
+ sec.name.should == "MySection"
179
+ sec.parents.should == [ini]
180
+ sec.nodes.should == [ini, sec]
181
+ end
182
+
183
+ it "SleipnirAPI::Key accessor" do
184
+ ini = @profile.Script
185
+ sec = ini.MySection
186
+ key = sec.MyKey
187
+ key.name.should == "MyKey"
188
+ key.parents.should == [ini, sec]
189
+ key.nodes.should == [ini, sec, key]
190
+ end
191
+ end