filter_io 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  *.gemspec
2
2
  pkg
3
3
  coverage
4
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source :gemcutter
2
+
3
+ gem 'jeweler'
4
+ gem 'activesupport', '>=2.3.9'
5
+ gem 'i18n', '>=0.4.1'
6
+ gem 'test-unit'
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.0.0)
5
+ gemcutter (0.6.1)
6
+ git (1.2.5)
7
+ i18n (0.4.1)
8
+ jeweler (1.4.0)
9
+ gemcutter (>= 0.1.0)
10
+ git (>= 1.2.5)
11
+ rubyforge (>= 2.0.0)
12
+ json_pure (1.4.6)
13
+ rubyforge (2.0.4)
14
+ json_pure (>= 1.1.7)
15
+ test-unit (2.1.1)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ activesupport (>= 2.3.9)
22
+ i18n (>= 0.4.1)
23
+ jeweler
24
+ test-unit
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
data/lib/filter_io.rb CHANGED
@@ -279,6 +279,11 @@ class FilterIO
279
279
 
280
280
  data = [data] unless data.is_a? Array
281
281
  raise 'Block must have 1 or 2 values' unless data.size <= 2
282
+ if @buffer.respond_to?(:encoding) && @buffer.encoding != data[0].encoding
283
+ if [@buffer, data[0]].any? { |x| x.encoding.to_s == 'ASCII-8BIT' }
284
+ data[0] = data[0].dup.force_encoding @buffer.encoding
285
+ end
286
+ end
282
287
  @buffer << data[0]
283
288
  if data[1]
284
289
  if @io.respond_to?(:internal_encoding) && @io.internal_encoding
@@ -242,6 +242,16 @@ class FilterIOTest < ActiveSupport::TestCase
242
242
  end
243
243
  end
244
244
 
245
+ test "block returning mix of UTF-8 and ASCII-8BIT" do
246
+ input = "X\xE2\x80\x94Y\xe2\x80\x99"
247
+ input.force_encoding 'ASCII-8BIT'
248
+ io = FilterIO.new(StringIO.new(input), :block_size => 4) do |data, state|
249
+ data.force_encoding data[0] == 'Y' ? 'UTF-8' : 'ASCII-8BIT'
250
+ data
251
+ end
252
+ assert_equal input, io.read
253
+ end
254
+
245
255
  end
246
256
 
247
257
  test "read" do
@@ -431,7 +441,7 @@ class FilterIOTest < ActiveSupport::TestCase
431
441
 
432
442
  test "need more data" do
433
443
  input = '1ab123456cde78f9ghij0'
434
- expected = input.gsub /\d+/, '[\0]'
444
+ expected = input.gsub(/\d+/, '[\0]')
435
445
  (1..5).each do |block_size|
436
446
  expected_size = 0
437
447
  io = FilterIO.new(StringIO.new(input), :block_size => block_size) do |data, state|
@@ -439,7 +449,7 @@ class FilterIOTest < ActiveSupport::TestCase
439
449
  raise FilterIO::NeedMoreData if data =~ /\d\z/ && !state.eof?
440
450
  assert_equal expected_size, data.size unless state.eof?
441
451
  expected_size = 0
442
- data.gsub /\d+/, '[\0]'
452
+ data.gsub(/\d+/, '[\0]')
443
453
  end
444
454
  assert_equal expected, io.read
445
455
  end
@@ -451,7 +461,7 @@ class FilterIOTest < ActiveSupport::TestCase
451
461
  (1..5).each do |block_size|
452
462
  io = FilterIO.new(StringIO.new(input), :block_size => block_size) do |data, state|
453
463
  raise FilterIO::NeedMoreData if data =~ /[\r\n]\z/ && !state.eof?
454
- data.gsub /\r\n|\r|\n/, "\n"
464
+ data.gsub(/\r\n|\r|\n/, "\n")
455
465
  end
456
466
  assert_equal expected, io.read
457
467
  end
@@ -459,10 +469,10 @@ class FilterIOTest < ActiveSupport::TestCase
459
469
 
460
470
  test "dropping characters" do
461
471
  input = "ab1cde23f1g4hijklmno567pqr8stu9vw0xyz"
462
- expected = input.gsub /\d+/, ''
472
+ expected = input.gsub(/\d+/, '')
463
473
  (1..5).each do |block_size|
464
474
  io = FilterIO.new(StringIO.new(input), :block_size => block_size) do |data|
465
- data.gsub /\d+/, ''
475
+ data.gsub(/\d+/, '')
466
476
  end
467
477
  assert_equal 0, io.pos
468
478
  assert_equal expected, io.read
@@ -621,19 +631,19 @@ class FilterIOTest < ActiveSupport::TestCase
621
631
  assert_equal 'c', io.read(1)
622
632
  assert_equal 3, io.pos
623
633
  assert_raise Errno::EINVAL do
624
- io.seek -1, IO::SEEK_CUR
634
+ io.seek(-1, IO::SEEK_CUR)
625
635
  end
626
636
  assert_equal 3, io.pos
627
637
 
628
638
  # forwards fail
629
639
  assert_equal 3, io.pos
630
640
  assert_raise Errno::EINVAL do
631
- io.seek 2, IO::SEEK_CUR
641
+ io.seek(2, IO::SEEK_CUR)
632
642
  end
633
643
  assert_equal 3, io.pos
634
644
 
635
645
  # beginning
636
- io.seek -io.pos, IO::SEEK_CUR
646
+ io.seek(-io.pos, IO::SEEK_CUR)
637
647
  assert_equal 0, io.pos
638
648
 
639
649
  end
@@ -641,13 +651,13 @@ class FilterIOTest < ActiveSupport::TestCase
641
651
  test "seek end" do
642
652
  io = FilterIO.new(StringIO.new("abcdef"))
643
653
  assert_raise Errno::EINVAL do
644
- io.seek 0, IO::SEEK_END
654
+ io.seek(0, IO::SEEK_END)
645
655
  end
646
656
  assert_raise Errno::EINVAL do
647
- io.seek 6, IO::SEEK_END
657
+ io.seek(6, IO::SEEK_END)
648
658
  end
649
659
  assert_raise Errno::EINVAL do
650
- io.seek -6, IO::SEEK_END
660
+ io.seek(-6, IO::SEEK_END)
651
661
  end
652
662
  end
653
663
 
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filter_io
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 1
9
- - 4
10
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
11
10
  platform: ruby
12
11
  authors:
13
12
  - Jason Weathered
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-07-13 00:00:00 +10:00
17
+ date: 2010-09-13 00:00:00 +10:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
@@ -43,6 +41,8 @@ extra_rdoc_files:
43
41
  - README.markdown
44
42
  files:
45
43
  - .gitignore
44
+ - Gemfile
45
+ - Gemfile.lock
46
46
  - LICENSE
47
47
  - README.markdown
48
48
  - Rakefile
@@ -64,7 +64,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
- hash: 3
68
67
  segments:
69
68
  - 0
70
69
  version: "0"
@@ -73,7 +72,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
72
  requirements:
74
73
  - - ">="
75
74
  - !ruby/object:Gem::Version
76
- hash: 3
77
75
  segments:
78
76
  - 0
79
77
  version: "0"