bencodr 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +0 -0
- data/.document +0 -0
- data/.gitignore +3 -1
- data/.rvmrc +1 -0
- data/Gemfile +3 -0
- data/LICENSE +0 -0
- data/{README.rdoc → README.md} +88 -53
- data/Rakefile +4 -44
- data/bencodr.gemspec +18 -75
- data/lib/bencodr.rb +23 -40
- data/lib/bencodr/dictionary.rb +19 -47
- data/lib/bencodr/ext.rb +38 -0
- data/lib/bencodr/integer.rb +17 -47
- data/lib/bencodr/io.rb +21 -56
- data/lib/bencodr/list.rb +19 -45
- data/lib/bencodr/object.rb +36 -0
- data/lib/bencodr/parser.rb +0 -14
- data/lib/bencodr/string.rb +17 -46
- data/lib/bencodr/version.rb +3 -0
- data/spec/bencode_spec.rb +17 -22
- data/spec/bencodr/dictionary_spec.rb +1 -74
- data/spec/bencodr/ext_spec.rb +66 -0
- data/spec/bencodr/integer_spec.rb +1 -67
- data/spec/bencodr/io_spec.rb +28 -30
- data/spec/bencodr/list_spec.rb +1 -31
- data/spec/bencodr/object_spec.rb +9 -0
- data/spec/bencodr/parser_spec.rb +38 -173
- data/spec/bencodr/string_spec.rb +1 -68
- data/spec/custom_matchers.rb +87 -0
- data/spec/samples/bencode.rb.torrent +0 -0
- data/spec/samples/mini.bencode +0 -0
- data/spec/samples/python.torrent +0 -0
- data/spec/shared_examples.rb +91 -0
- data/spec/spec_helper.rb +8 -9
- metadata +55 -28
- data/VERSION +0 -1
- data/autotest/discover.rb +0 -3
- data/spec/spec.opts +0 -1
data/spec/bencodr/string_spec.rb
CHANGED
@@ -1,73 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
|
3
|
-
require "spec"
|
4
2
|
require "spec_helper"
|
5
3
|
|
6
|
-
describe String do
|
7
|
-
describe "#bencodr" do
|
8
|
-
it "should encode a string" do
|
9
|
-
"string".bencode.should == "6:string"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should encode a zero length string" do
|
13
|
-
"".bencode.should == "0:"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe Symbol do
|
19
|
-
describe "#bencodr" do
|
20
|
-
it "should encode a symbol" do
|
21
|
-
:symbol.bencode.should == "6:symbol"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe URI::Generic do
|
27
|
-
describe "#bencodr" do
|
28
|
-
it "should encode a http uri" do
|
29
|
-
uri = URI.parse("http://github.com/blatyo/bencodr")
|
30
|
-
uri.bencode.should == "32:http://github.com/blatyo/bencodr"
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should encode a https uri" do
|
34
|
-
uri = URI.parse("https://github.com/blatyo/bencodr")
|
35
|
-
uri.bencode.should == "33:https://github.com/blatyo/bencodr"
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should encode a ftp uri" do
|
39
|
-
uri = URI.parse("ftp://github.com/blatyo/bencodr")
|
40
|
-
uri.bencode.should == "31:ftp://github.com/blatyo/bencodr"
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should encode a ldap uri" do
|
44
|
-
uri = URI.parse("ldap://github.com/blatyo/bencodr")
|
45
|
-
uri.bencode.should == "32:ldap://github.com/blatyo/bencodr"
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should encode a mailto uri" do
|
49
|
-
uri = URI.parse("mailto:sudo@sudoers.su")
|
50
|
-
uri.bencode.should == "22:mailto:sudo@sudoers.su"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
4
|
describe BEncodr::String do
|
56
|
-
|
57
|
-
context "once an object has been registered as a BEncode string" do
|
58
|
-
before :all do
|
59
|
-
BEncodr::String.register Range
|
60
|
-
end
|
61
|
-
|
62
|
-
context "an instance of that object" do
|
63
|
-
it "should respond to bencodr" do
|
64
|
-
(1..2).should respond_to :bencode
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should encode to a bencoded string" do
|
68
|
-
(1..2).bencode.should == "4:1..2"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
5
|
+
it_behaves_like "BEncodr::String", BEncodr::String
|
73
6
|
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
RSpec::Matchers.define :bencode_to do |expected|
|
2
|
+
match do |actual|
|
3
|
+
actual.bencode.should equal(expected)
|
4
|
+
end
|
5
|
+
|
6
|
+
failure_message_for_should do |actual|
|
7
|
+
"expected that #{actual} would bencode to #{expected}"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
RSpec::Matchers.define :bencode do |actual|
|
12
|
+
chain :to do |_expected|
|
13
|
+
@_expected = _expected
|
14
|
+
end
|
15
|
+
|
16
|
+
match do |klass|
|
17
|
+
klass.bencode(actual).should == @_expected
|
18
|
+
end
|
19
|
+
|
20
|
+
failure_message_for_should do |klass|
|
21
|
+
"expected #{klass.name} to bencode #{actual} to #{@_expected}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
RSpec::Matchers.define :parse do |actual|
|
26
|
+
chain :as do |type|
|
27
|
+
@type = type
|
28
|
+
end
|
29
|
+
|
30
|
+
chain :to do |_expected|
|
31
|
+
@_expected = _expected
|
32
|
+
end
|
33
|
+
|
34
|
+
match do |klass|
|
35
|
+
scanner = StringScanner.new(actual)
|
36
|
+
klass.send(:"parse_#{@type}", scanner).should == @_expected
|
37
|
+
end
|
38
|
+
|
39
|
+
failure_message_for_should do |klass|
|
40
|
+
"expected #{klass.name} to bdencode #{actual} as #{@type} to #{@_expected}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
RSpec::Matchers.define :generate_parse_error do |expected|
|
45
|
+
chain :for do |type|
|
46
|
+
@type = type
|
47
|
+
end
|
48
|
+
|
49
|
+
chain :with do |_actual|
|
50
|
+
@_actual = _actual
|
51
|
+
end
|
52
|
+
|
53
|
+
match do |klass|
|
54
|
+
scanner = StringScanner.new(@_actual)
|
55
|
+
lambda do
|
56
|
+
klass.send(:"parse_#{@type}", scanner)
|
57
|
+
end.should raise_error(expected)
|
58
|
+
end
|
59
|
+
|
60
|
+
failure_message_for_should do |klass|
|
61
|
+
"expected #{klass.name} to generate parse error #{expected.name} for #{@type} with #{actual}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
RSpec::Matchers.define :bdecode_to do |expected|
|
66
|
+
match do |actual|
|
67
|
+
actual.bdecode.should == expected
|
68
|
+
end
|
69
|
+
|
70
|
+
failure_message_for_should do |actual|
|
71
|
+
"expected that #{actual} would bdecode to #{expected}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
RSpec::Matchers.define :bdecode do |actual|
|
76
|
+
chain :to do |_expected|
|
77
|
+
@_expected = _expected
|
78
|
+
end
|
79
|
+
|
80
|
+
match do |klass|
|
81
|
+
klass.bdecode(actual).should == @_expected
|
82
|
+
end
|
83
|
+
|
84
|
+
failure_message_for_should do |actual|
|
85
|
+
"expected that #{klass.name} would bdecode #{actual} to #{expected}"
|
86
|
+
end
|
87
|
+
end
|
File without changes
|
data/spec/samples/mini.bencode
CHANGED
File without changes
|
data/spec/samples/python.torrent
CHANGED
File without changes
|
@@ -0,0 +1,91 @@
|
|
1
|
+
shared_examples_for "BEncodr::String" do |obj|
|
2
|
+
subject{ obj }
|
3
|
+
|
4
|
+
describe "#bencode" do
|
5
|
+
it{ should bencode("string").to("6:string") }
|
6
|
+
it{ should bencode("").to("0:") }
|
7
|
+
it{ should bencode(:symbol).to("6:symbol") }
|
8
|
+
it{ should bencode(URI.parse("http://github.com/blatyo/bencodr")).to("32:http://github.com/blatyo/bencodr") }
|
9
|
+
it{ should bencode(URI.parse("https://github.com/blatyo/bencodr")).to("33:https://github.com/blatyo/bencodr") }
|
10
|
+
it{ should bencode(URI.parse("ftp://github.com/blatyo/bencodr")).to("31:ftp://github.com/blatyo/bencodr") }
|
11
|
+
it{ should bencode(URI.parse("ldap://github.com/blatyo/bencodr")).to("32:ldap://github.com/blatyo/bencodr") }
|
12
|
+
it{ should bencode(URI.parse("mailto:sudo@sudoers.su")).to("22:mailto:sudo@sudoers.su") }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
shared_examples_for "BEncodr::Integer" do |obj|
|
17
|
+
subject{ obj }
|
18
|
+
|
19
|
+
describe "#bencodr" do
|
20
|
+
it{ should bencode(1).to("i1e") }
|
21
|
+
it{ should bencode(-1).to("i-1e") }
|
22
|
+
it{ should bencode(10_000_000_000).to("i10000000000e") }
|
23
|
+
it{ should bencode(-10_000_000_000).to("i-10000000000e") }
|
24
|
+
it{ should bencode(1.1).to("i1e") }
|
25
|
+
it{ should bencode(-1.1).to("i-1e") }
|
26
|
+
it{ should bencode(1e10).to("i10000000000e") }
|
27
|
+
it{ should bencode(-1e10).to("i-10000000000e") }
|
28
|
+
it{ should bencode(Time.at(4)).to("i4e") }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
shared_examples_for "BEncodr::List" do |obj|
|
33
|
+
subject{ obj }
|
34
|
+
|
35
|
+
describe "#bencode" do
|
36
|
+
it{ should bencode([]).to("le") }
|
37
|
+
it{ should bencode([:e, "a", 1, Time.at(11)]).to("l1:e1:ai1ei11ee") }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
shared_examples_for "BEncodr::Dictionary" do |obj|
|
42
|
+
subject{ obj }
|
43
|
+
|
44
|
+
describe "#bencode" do
|
45
|
+
it{ should bencode({}).to("de") }
|
46
|
+
it{ should bencode({:a => 1, "A" => 1, 1=> 1}).to("d1:1i1e1:Ai1e1:ai1ee")}
|
47
|
+
|
48
|
+
context "a key should always be encoded as a string" do
|
49
|
+
it{ should bencode({"string" => "string"}).to("d6:string6:stringe") }
|
50
|
+
it{ should bencode({:symbol => :symbol}).to("d6:symbol6:symbole") }
|
51
|
+
it{ should bencode({1 => 1}).to("d1:1i1ee")}
|
52
|
+
it{ should bencode({1.1 => 1.1}).to("d3:1.1i1ee") }
|
53
|
+
it{ should bencode({{} => {}}).to("d2:{}dee") }
|
54
|
+
|
55
|
+
it{
|
56
|
+
uri = URI.parse("http://github.com/blatyo/bencode")
|
57
|
+
should bencode({uri => uri}).to("d32:http://github.com/blatyo/bencode32:http://github.com/blatyo/bencodee")
|
58
|
+
}
|
59
|
+
|
60
|
+
it{
|
61
|
+
time = Time.utc(0)
|
62
|
+
should bencode({time => time}).to("d23:0000-01-01 00:00:00 UTCi-62167219200ee")
|
63
|
+
}
|
64
|
+
|
65
|
+
it{
|
66
|
+
array = (1..4).to_a
|
67
|
+
should bencode({array => array}).to("d12:[1, 2, 3, 4]li1ei2ei3ei4eee")
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
shared_examples_for "BEncode decoder" do |klass|
|
74
|
+
subject{ klass }
|
75
|
+
|
76
|
+
it{ should bdecode("6:string").to("string") }
|
77
|
+
it{ should bdecode("0:").to("") }
|
78
|
+
it{ should bdecode("6:symbol").to("symbol") }
|
79
|
+
it{ should bdecode("32:http://github.com/blatyo/bencodr").to("http://github.com/blatyo/bencodr") }
|
80
|
+
it{ should bdecode("33:https://github.com/blatyo/bencodr").to("https://github.com/blatyo/bencodr") }
|
81
|
+
it{ should bdecode("31:ftp://github.com/blatyo/bencodr").to("ftp://github.com/blatyo/bencodr") }
|
82
|
+
it{ should bdecode("32:ldap://github.com/blatyo/bencodr").to("ldap://github.com/blatyo/bencodr") }
|
83
|
+
it{ should bdecode("22:mailto:sudo@sudoers.su").to("mailto:sudo@sudoers.su") }
|
84
|
+
end
|
85
|
+
|
86
|
+
shared_examples_for "a BEncodr extension" do |obj, klass|
|
87
|
+
subject{ obj }
|
88
|
+
|
89
|
+
it{ should respond_to(:bencode) }
|
90
|
+
it{ should be_a(klass) }
|
91
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'bencodr')
|
2
|
+
require 'rspec'
|
3
|
+
require 'fuubar'
|
4
|
+
require 'custom_matchers'
|
5
|
+
require 'shared_examples'
|
2
6
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
require 'spec'
|
7
|
-
require 'spec/autorun'
|
8
|
-
|
9
|
-
Spec::Runner.configure do |config|
|
10
|
-
|
7
|
+
Rspec.configure do |c|
|
8
|
+
c.formatter = Fuubar
|
9
|
+
c.color_enabled = true
|
11
10
|
end
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bencodr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease:
|
5
|
+
version: 2.0.0
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Allen Madsen
|
@@ -9,101 +10,127 @@ autorequire:
|
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
12
|
|
12
|
-
date:
|
13
|
+
date: 2011-06-11 00:00:00 -04:00
|
13
14
|
default_executable:
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: rspec
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.1.0
|
17
25
|
type: :development
|
18
|
-
|
19
|
-
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
20
32
|
requirements:
|
21
33
|
- - ">="
|
22
34
|
- !ruby/object:Gem::Version
|
23
|
-
version: 1.
|
24
|
-
version:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: yard
|
35
|
+
version: 1.0.0
|
27
36
|
type: :development
|
28
|
-
|
29
|
-
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: fuubar
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
30
43
|
requirements:
|
31
44
|
- - ">="
|
32
45
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
|
35
|
-
|
36
|
-
|
46
|
+
version: 0.0.1
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
description: This gem provides a way to encode and decode bencode used by the Bit Torrent protocol. Normal ruby objects can be marshalled as bencode and demarshalled back to ruby.
|
50
|
+
email:
|
51
|
+
- blatyo@gmail.com
|
37
52
|
executables: []
|
38
53
|
|
39
54
|
extensions: []
|
40
55
|
|
41
|
-
extra_rdoc_files:
|
42
|
-
|
43
|
-
- README.rdoc
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
44
58
|
files:
|
45
59
|
- .autotest
|
46
60
|
- .document
|
47
61
|
- .gitignore
|
62
|
+
- .rvmrc
|
63
|
+
- Gemfile
|
48
64
|
- LICENSE
|
49
|
-
- README.
|
65
|
+
- README.md
|
50
66
|
- Rakefile
|
51
|
-
- VERSION
|
52
|
-
- autotest/discover.rb
|
53
67
|
- bencodr.gemspec
|
54
68
|
- lib/bencodr.rb
|
55
69
|
- lib/bencodr/dictionary.rb
|
70
|
+
- lib/bencodr/ext.rb
|
56
71
|
- lib/bencodr/integer.rb
|
57
72
|
- lib/bencodr/io.rb
|
58
73
|
- lib/bencodr/list.rb
|
74
|
+
- lib/bencodr/object.rb
|
59
75
|
- lib/bencodr/parser.rb
|
60
76
|
- lib/bencodr/string.rb
|
77
|
+
- lib/bencodr/version.rb
|
61
78
|
- spec/bencode_spec.rb
|
62
79
|
- spec/bencodr/dictionary_spec.rb
|
80
|
+
- spec/bencodr/ext_spec.rb
|
63
81
|
- spec/bencodr/integer_spec.rb
|
64
82
|
- spec/bencodr/io_spec.rb
|
65
83
|
- spec/bencodr/list_spec.rb
|
84
|
+
- spec/bencodr/object_spec.rb
|
66
85
|
- spec/bencodr/parser_spec.rb
|
67
86
|
- spec/bencodr/string_spec.rb
|
87
|
+
- spec/custom_matchers.rb
|
68
88
|
- spec/samples/bencode.rb.torrent
|
69
89
|
- spec/samples/mini.bencode
|
70
90
|
- spec/samples/python.torrent
|
71
|
-
- spec/
|
91
|
+
- spec/shared_examples.rb
|
72
92
|
- spec/spec_helper.rb
|
73
93
|
has_rdoc: true
|
74
94
|
homepage: http://github.com/blatyo/bencodr
|
75
95
|
licenses: []
|
76
96
|
|
77
97
|
post_install_message:
|
78
|
-
rdoc_options:
|
79
|
-
|
98
|
+
rdoc_options: []
|
99
|
+
|
80
100
|
require_paths:
|
81
101
|
- lib
|
82
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
83
104
|
requirements:
|
84
105
|
- - ">="
|
85
106
|
- !ruby/object:Gem::Version
|
86
107
|
version: "0"
|
87
|
-
version:
|
88
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
89
110
|
requirements:
|
90
111
|
- - ">="
|
91
112
|
- !ruby/object:Gem::Version
|
92
|
-
version:
|
93
|
-
version:
|
113
|
+
version: 1.3.6
|
94
114
|
requirements: []
|
95
115
|
|
96
116
|
rubyforge_project:
|
97
|
-
rubygems_version: 1.
|
117
|
+
rubygems_version: 1.6.2
|
98
118
|
signing_key:
|
99
119
|
specification_version: 3
|
100
|
-
summary: This gem provides a way to encode and
|
120
|
+
summary: This gem provides a way to encode and decode bencode used by the Bit Torrent protocol.
|
101
121
|
test_files:
|
102
122
|
- spec/bencode_spec.rb
|
103
123
|
- spec/bencodr/dictionary_spec.rb
|
124
|
+
- spec/bencodr/ext_spec.rb
|
104
125
|
- spec/bencodr/integer_spec.rb
|
105
126
|
- spec/bencodr/io_spec.rb
|
106
127
|
- spec/bencodr/list_spec.rb
|
128
|
+
- spec/bencodr/object_spec.rb
|
107
129
|
- spec/bencodr/parser_spec.rb
|
108
130
|
- spec/bencodr/string_spec.rb
|
131
|
+
- spec/custom_matchers.rb
|
132
|
+
- spec/samples/bencode.rb.torrent
|
133
|
+
- spec/samples/mini.bencode
|
134
|
+
- spec/samples/python.torrent
|
135
|
+
- spec/shared_examples.rb
|
109
136
|
- spec/spec_helper.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.2.0
|