Ascii85 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -16,11 +16,12 @@ Gem::Specification.new do |s|
16
16
  s.rubyforge_project = "Ascii85"
17
17
 
18
18
  s.add_development_dependency "bundler", ">= 1.0.0"
19
- s.add_development_dependency "rspec", ">= 2.4.0"
19
+ s.add_development_dependency "minitest",">= 2.6.0"
20
+ s.add_development_dependency "rake", ">= 0.9.2"
20
21
 
21
- s.files = `git ls-files`.split("\n")
22
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.files = `git ls-files`.split("\n") - ['.gitignore']
23
+ s.test_files = `git ls-files -- spec/*`.split("\n")
23
24
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
25
  s.require_paths = ["lib"]
25
- s.extra_rdoc_files = ['README.rdoc']
26
+ s.extra_rdoc_files = ['README.rdoc', 'LICENSE']
26
27
  end
@@ -1,3 +1,9 @@
1
+ === 1.0.2 / 2012-09-16
2
+
3
+ * Changed test runner from RSpec to MiniSpec
4
+ * Support for rubygems-test
5
+ * Minor changes to make packaging easier
6
+
1
7
  === 1.0.1 / 2011-05-05
2
8
 
3
9
  * Removed hoe dependency in favor of bundler
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2009 Johannes Holzfuß
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -1,9 +1,9 @@
1
1
  = Ascii85
2
2
 
3
- * http://ascii85.rubyforge.org
3
+ * http://rubyforge.org/projects/ascii85
4
4
 
5
5
 
6
- == DESCRIPTION:
6
+ == Description
7
7
 
8
8
  Ascii85 is a simple gem that provides methods for encoding/decoding Adobe's
9
9
  binary-to-text encoding of the same name.
@@ -12,7 +12,12 @@ See http://www.adobe.com/products/postscript/pdfs/PLRM.pdf page 131 and
12
12
  http://en.wikipedia.org/wiki/Ascii85 for more information about the format.
13
13
 
14
14
 
15
- == SYNOPSIS:
15
+ == Installation
16
+
17
+ * sudo gem install Ascii85
18
+
19
+
20
+ == Usage
16
21
 
17
22
  require 'rubygems'
18
23
  require 'ascii85'
@@ -46,31 +51,7 @@ command-line:
46
51
  --version Output version information
47
52
 
48
53
 
49
- == INSTALL:
50
-
51
- * sudo gem install Ascii85
52
-
53
-
54
- == LICENSE:
55
-
56
- (The MIT License)
57
-
58
- Copyright (c) 2009 Johannes Holzfuß
59
-
60
- Permission is hereby granted, free of charge, to any person obtaining a copy of
61
- this software and associated documentation files (the "Software"), to deal in
62
- the Software without restriction, including without limitation the rights to
63
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
64
- of the Software, and to permit persons to whom the Software is furnished to do
65
- so, subject to the following conditions:
66
-
67
- The above copyright notice and this permission notice shall be included in all
68
- copies or substantial portions of the Software.
54
+ == License
69
55
 
70
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
71
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
72
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
73
- THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
74
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
75
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
76
- SOFTWARE.
56
+ Ascii85 is distributed under the MIT License. See the accompanying LICENSE file
57
+ for details.
data/Rakefile CHANGED
@@ -1,9 +1,12 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
- require "rspec/core/rake_task"
4
+ require 'rake/testtask'
5
5
 
6
- desc "Run all specs"
7
- RSpec::Core::RakeTask.new(:specs)
6
+ Rake::TestTask.new do |t|
7
+ t.test_files = FileList['spec/**/*_spec.rb']
8
+ end
8
9
 
9
- task :default => :specs
10
+ task :specs => :test
11
+ task :tests => :test
12
+ task :default => :test
@@ -1,3 +1,3 @@
1
1
  module Ascii85
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -10,7 +10,7 @@
10
10
  # the format.
11
11
  #
12
12
  # Author:: Johannes Holzfuß (DataWraith@web.de)
13
- # License:: Distributed under the MIT License (see README.rdoc)
13
+ # License:: Distributed under the MIT License (see LICENSE file)
14
14
  #
15
15
 
16
16
 
@@ -42,7 +42,7 @@ module Ascii85
42
42
  return '' if to_encode.empty?
43
43
 
44
44
  # Deal with multi-byte encodings
45
- if to_encode.methods.include?(:bytesize)
45
+ if to_encode.respond_to?(:bytesize)
46
46
  input_size = to_encode.bytesize
47
47
  else
48
48
  input_size = to_encode.size
@@ -125,41 +125,37 @@ module Ascii85
125
125
 
126
126
  input = str.to_s
127
127
 
128
- # Try to compile the regular expression for finding the input between
129
- # the <~ and ~> delimiters. In order to work properly with different
130
- # input encodings, the RegExp itself is re-encoded to the input encoding
131
- # if possible. Thanks to Myrddin Emrys for suggesting this approach
132
- # (http://is.gd/5x18O)
133
- begin
134
- regex = "<~(.*?)?~>"
135
-
136
- if regex.methods.include?(:encode)
137
- regex = regex.encode(input.encoding)
138
- end
139
- regex = Regexp.compile(regex, Regexp::MULTILINE)
140
-
141
- # Find the actual data to be decoded
142
- input = input.match(regex)
143
-
144
- rescue EncodingError
145
- raise ArgumentError, "Incompatible input encoding: #{str.encoding.inspect}"
128
+ opening_delim = '<~'
129
+ closing_delim = '~>'
130
+
131
+ # Make sure the delimiter strings have the correct encoding.
132
+ #
133
+ # Although I don't think it likely, this may raise encoding
134
+ # errors if an especially exotic input encoding is introduced.
135
+ # As of Ruby 1.9.2 all non-dummy encodings work fine though.
136
+ #
137
+ if opening_delim.respond_to?(:encode!)
138
+ opening_delim.encode!(input.encoding)
139
+ closing_delim.encode!(input.encoding)
146
140
  end
147
141
 
148
- return '' if input.nil?
142
+ # Get the positions of the opening/closing delimiters. If there is
143
+ # no pair of opening/closing delimiters, return the empty string.
144
+ (start_pos = input.index(opening_delim)) or return ''
145
+ (end_pos = input.index(closing_delim, start_pos + 2)) or return ''
149
146
 
150
- # Get the matched data as String
151
- input = input.captures.first
147
+ # Get the string inside the delimiter-pair
148
+ input = input[(start_pos + 2)...end_pos]
152
149
 
153
150
  # Decode
151
+ word = 0
152
+ count = 0
154
153
  result = []
155
154
 
156
- count = 0
157
- word = 0
158
-
159
155
  input.each_byte do |c|
160
156
 
161
157
  case c.chr
162
- when /[ \t\r\n\f\0]/
158
+ when " ", "\t", "\r", "\n", "\f", "\0"
163
159
  # Ignore whitespace
164
160
  next
165
161
 
@@ -173,7 +169,7 @@ module Ascii85
173
169
 
174
170
  when '!'..'u'
175
171
  # Decode 5 characters into a 4-byte word
176
- word += (c - 33) * 85**(4 - count)
172
+ word += (c - 33) * 85**(4 - count)
177
173
  count += 1
178
174
 
179
175
  if count == 5
@@ -184,7 +180,8 @@ module Ascii85
184
180
  end
185
181
 
186
182
  result << word
187
- word = 0
183
+
184
+ word = 0
188
185
  count = 0
189
186
  end
190
187
 
@@ -207,7 +204,7 @@ module Ascii85
207
204
  end
208
205
 
209
206
  count -= 1
210
- word += 85**(4 - count)
207
+ word += 85**(4 - count)
211
208
 
212
209
  result << ((word >> 24) & 255).chr if count >= 1
213
210
  result << ((word >> 16) & 255).chr if count >= 2
@@ -1,9 +1,15 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.join(File.dirname(__FILE__), '..', 'spec_helper')
3
+ require 'rubygems'
4
+ require 'minitest/autorun'
5
+
6
+ # Require implementation
7
+ require File.expand_path('../../../lib/ascii85', __FILE__)
4
8
 
5
9
  describe Ascii85 do
6
10
 
11
+ UNSUPPORTED_MSG = "This version of Ruby does not support encodings"
12
+
7
13
  TEST_CASES = {
8
14
 
9
15
  "" => "",
@@ -42,28 +48,32 @@ describe Ascii85 do
42
48
  # Generate a random string
43
49
  test_str = ""
44
50
  (1 + rand(255)).times do
45
- test_str += rand(256).chr
51
+ test_str << rand(256).chr
46
52
  end
47
53
 
48
54
  encoded = Ascii85.encode(test_str)
49
55
  decoded = Ascii85.decode(encoded)
50
56
 
51
- decoded.should == test_str
57
+ decoded.must_equal test_str
52
58
  end
53
59
 
54
60
  describe "#encode" do
55
61
 
56
62
  it "should encode all specified test-cases correctly" do
57
63
  TEST_CASES.each_pair do |input, encoded|
58
- Ascii85.encode(input).should == encoded
64
+ Ascii85.encode(input).must_equal encoded
59
65
  end
60
66
  end
61
67
 
62
- it "should encode Strings in different encodings correctly", :ruby => 1.9 do
68
+ it "should encode Strings in different encodings correctly" do
69
+ unless String.new.respond_to?(:encoding)
70
+ skip(UNSUPPORTED_MSG)
71
+ end
72
+
63
73
  input_EUC_JP = 'どうもありがとうミスターロボット'.encode('EUC-JP')
64
74
  input_binary = input_EUC_JP.force_encoding('ASCII-8BIT')
65
75
 
66
- Ascii85.encode(input_EUC_JP).should == Ascii85.encode(input_binary)
76
+ Ascii85.encode(input_EUC_JP).must_equal Ascii85.encode(input_binary)
67
77
  end
68
78
 
69
79
  it "should produce output lines no longer than specified" do
@@ -72,7 +82,7 @@ describe Ascii85 do
72
82
  #
73
83
  # No wrap
74
84
  #
75
- Ascii85.encode(test_str, false).count("\n").should == 0
85
+ Ascii85.encode(test_str, false).count("\n").must_equal 0
76
86
 
77
87
  #
78
88
  # x characters per line, except for the last one
@@ -97,30 +107,31 @@ describe Ascii85 do
97
107
  count_arr.delete_if { |len| len == x }
98
108
 
99
109
  # Now count_arr should be empty
100
- count_arr.should be_empty
110
+ count_arr.must_be_empty
101
111
  end
102
112
 
103
113
  it "should not split the end-marker to achieve correct line length" do
104
- Ascii85.encode("\0" * 4, 4).should == "<~z\n~>"
114
+ Ascii85.encode("\0" * 4, 4).must_equal "<~z\n~>"
105
115
  end
106
116
 
107
117
  end
108
118
 
109
119
  describe "#decode" do
110
120
 
111
- it "should decode all specified test-cases correctly", :ruby => 1.8 do
121
+ it "should decode all specified test-cases correctly" do
112
122
  TEST_CASES.each_pair do |decoded, input|
113
- Ascii85.decode(input).should == decoded
123
+ if String.new.respond_to?(:encoding)
124
+ Ascii85.decode(input).must_equal decoded.dup.force_encoding('ASCII-8BIT')
125
+ else
126
+ Ascii85.decode(input).must_equal decoded
127
+ end
114
128
  end
115
129
  end
116
130
 
117
- it "should decode all specified test-cases correctly", :ruby => 1.9 do
118
- TEST_CASES.each_pair do |decoded, input|
119
- Ascii85.decode(input).should == decoded.dup.force_encoding('ASCII-8BIT')
131
+ it "should accept valid input in encodings other than the default" do
132
+ unless String.new.respond_to?(:encoding)
133
+ skip(UNSUPPORTED_MSG)
120
134
  end
121
- end
122
-
123
- it "should accept valid input in encodings other than the default", :ruby => 1.9 do
124
135
 
125
136
  input = "Ragnarök τέχνη русский язык I ♥ Ruby"
126
137
  input_ascii85 = Ascii85.encode(input)
@@ -129,56 +140,62 @@ describe Ascii85 do
129
140
  # do the right thing in #decode.
130
141
  Encoding.list.each do |encoding|
131
142
  next if encoding.dummy?
132
-
133
- to_test = input_ascii85.encode(encoding)
134
-
135
- lambda {
136
- Ascii85.decode(to_test).force_encoding('UTF-8').should == input
137
- }.should_not raise_error
143
+ next unless encoding.ascii_compatible?
144
+
145
+ # CP949 is a Microsoft Codepage for Korean, which apparently does not
146
+ # include a backslash, even though #ascii_compatible? returns true. This
147
+ # leads to an Ascii85::DecodingError, so we simply skip the encoding.
148
+ next if encoding.name == "CP949"
149
+
150
+ begin
151
+ to_test = input_ascii85.encode(encoding)
152
+ Ascii85.decode(to_test).force_encoding('UTF-8').must_equal input
153
+ rescue Encoding::ConverterNotFoundError
154
+ # Ignore this encoding
155
+ end
138
156
  end
139
157
  end
140
158
 
141
159
  it "should only process data within delimiters" do
142
- Ascii85.decode("<~~>").should == ''
143
- Ascii85.decode("Doesn't contain delimiters").should == ''
144
- Ascii85.decode("FooBar<~z~>BazQux").should == ("\0" * 4)
145
- Ascii85.decode("<~;KZGo~><~z~>").should == "Ruby"
146
- Ascii85.decode("foo~>bar<~baz").should == ''
160
+ Ascii85.decode("<~~>").must_be_empty
161
+ Ascii85.decode("Doesn't contain delimiters").must_be_empty
162
+ Ascii85.decode("Mismatched ~> delimiters 1").must_be_empty
163
+ Ascii85.decode("Mismatched <~ delimiters 2").must_be_empty
164
+ Ascii85.decode("Mismatched ~><~ delimiters 3").must_be_empty
165
+
166
+ Ascii85.decode("<~;KZGo~><~z~>").must_equal "Ruby"
167
+ Ascii85.decode("FooBar<~z~>BazQux").must_equal "\0\0\0\0"
147
168
  end
148
169
 
149
170
  it "should ignore whitespace" do
150
171
  decoded = Ascii85.decode("<~6 #LdYA\r\08\n \n\n- *rF*(i\"Ch[s \t(D.RU,@ <-\'jDJ=0\f/~>")
151
- decoded.should == 'Antidisestablishmentarianism'
172
+ decoded.must_equal 'Antidisestablishmentarianism'
152
173
  end
153
174
 
154
- it "should return ASCII-8BIT encoded strings", :ruby => 1.9 do
155
- Ascii85.decode("<~;KZGo~>").encoding.name.should == "ASCII-8BIT"
175
+ it "should return ASCII-8BIT encoded strings" do
176
+ unless String.new.respond_to?(:encoding)
177
+ skip(UNSUPPORTED_MSG)
178
+ end
179
+
180
+ Ascii85.decode("<~;KZGo~>").encoding.name.must_equal "ASCII-8BIT"
156
181
  end
157
182
 
158
183
  describe "Error conditions" do
159
184
 
160
185
  it "should raise DecodingError if it encounters a word >= 2**32" do
161
- lambda {
162
- Ascii85.decode('<~s8W-#~>')
163
- }.should raise_error Ascii85::DecodingError
186
+ lambda { Ascii85.decode('<~s8W-#~>') }.must_raise(Ascii85::DecodingError)
164
187
  end
165
188
 
166
189
  it "should raise DecodingError if it encounters an invalid character" do
167
- lambda {
168
- Ascii85.decode('<~!!y!!~>')
169
- }.should raise_error Ascii85::DecodingError
190
+ lambda { Ascii85.decode('<~!!y!!~>') }.must_raise(Ascii85::DecodingError)
170
191
  end
171
192
 
172
193
  it "should raise DecodingError if the last tuple consists of a single character" do
173
- lambda {
174
- Ascii85.decode('<~!~>')
175
- }.should raise_error Ascii85::DecodingError
194
+ lambda { Ascii85.decode('<~!~>') }.must_raise(Ascii85::DecodingError)
176
195
  end
177
196
 
178
197
  it "should raise DecodingError if a z is found inside a 5-tuple" do
179
- lambda {
180
- Ascii85.decode('<~!!z!!~>')
181
- }.should raise_error Ascii85::DecodingError
198
+ lambda { Ascii85.decode('<~!!z!!~>') }.must_raise Ascii85::DecodingError
182
199
  end
183
200
 
184
201
  end
metadata CHANGED
@@ -2,85 +2,97 @@
2
2
  name: Ascii85
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.1
5
+ version: 1.0.2
6
6
  platform: ruby
7
7
  authors:
8
- - "Johannes Holzfu\xC3\x9F"
8
+ - "Johannes Holzfu\xC3\x9F"
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-05 00:00:00 Z
13
+ date: 2012-09-16 00:00:00 Z
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: bundler
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.0.0
24
- type: :development
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: rspec
28
- prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
30
- none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: 2.4.0
35
- type: :development
36
- version_requirements: *id002
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.0
24
+ type: :development
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: minitest
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.6.0
35
+ type: :development
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: rake
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.9.2
46
+ type: :development
47
+ version_requirements: *id003
37
48
  description: Ascii85 provides methods to encode/decode Adobe's binary-to-text encoding of the same name.
38
49
  email: DataWraith@web.de
39
50
  executables:
40
- - ascii85
51
+ - ascii85
41
52
  extensions: []
42
53
 
43
54
  extra_rdoc_files:
44
- - README.rdoc
55
+ - README.rdoc
56
+ - LICENSE
45
57
  files:
46
- - .gitignore
47
- - Ascii85.gemspec
48
- - Gemfile
49
- - History.txt
50
- - README.rdoc
51
- - Rakefile
52
- - bin/ascii85
53
- - lib/Ascii85/version.rb
54
- - lib/ascii85.rb
55
- - spec/lib/ascii85_spec.rb
56
- - spec/spec_helper.rb
58
+ - .gemtest
59
+ - Ascii85.gemspec
60
+ - Gemfile
61
+ - History.txt
62
+ - LICENSE
63
+ - README.rdoc
64
+ - Rakefile
65
+ - bin/ascii85
66
+ - lib/Ascii85/version.rb
67
+ - lib/ascii85.rb
68
+ - spec/lib/ascii85_spec.rb
57
69
  homepage: http://rubyforge.org/projects/ascii85/
58
70
  licenses:
59
- - MIT
71
+ - MIT
60
72
  post_install_message:
61
73
  rdoc_options: []
62
74
 
63
75
  require_paths:
64
- - lib
76
+ - lib
65
77
  required_ruby_version: !ruby/object:Gem::Requirement
66
78
  none: false
67
79
  requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- version: "0"
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
71
83
  required_rubygems_version: !ruby/object:Gem::Requirement
72
84
  none: false
73
85
  requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: "0"
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
77
89
  requirements: []
78
90
 
79
91
  rubyforge_project: Ascii85
80
- rubygems_version: 1.8.0
92
+ rubygems_version: 1.8.24
81
93
  signing_key:
82
94
  specification_version: 3
83
95
  summary: Ascii85 encoder/decoder
84
96
  test_files:
85
- - spec/lib/ascii85_spec.rb
86
- - spec/spec_helper.rb
97
+ - spec/lib/ascii85_spec.rb
98
+ has_rdoc:
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- doc/
5
- pkg/*
@@ -1,12 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.join(File.dirname(__FILE__), '..', 'lib', 'ascii85')
4
-
5
- RSpec.configure do |c|
6
- # Filter tests based on ruby version
7
- c.exclusion_filter = {
8
- :ruby => lambda { |version|
9
- !(RUBY_VERSION.to_s =~ /^#{version.to_s}/)
10
- }
11
- }
12
- end