Skip to content
Browse files

Add regression tests for guessing encodings.

  • Loading branch information...
1 parent bad4fb0 commit bfc9783e619c46906f8d3ec2038a273d929c77ae @Manfred committed
Showing with 27 additions and 6 deletions.
  1. +1 −1 .kick
  2. +5 −5 Rakefile
  3. +21 −0 spec/regression/guess_encoding_spec.rb
View
2 .kick
@@ -8,7 +8,7 @@ process do |files|
Ruby.run_tests(files.take_and_map do |file|
case file
when %r{lib/(.*)\.rb}
- Dir.glob('spec/api/**/*.rb')
+ Dir.glob('spec/**/*_spec.rb')
end
end)
end
View
10 Rakefile
@@ -7,12 +7,12 @@ end
require 'rake/testtask'
-desc 'Run tests by default'
-task :default => :test
+desc 'Run specs by default'
+task :default => :spec
-desc 'Test encoding utilities'
-Rake::TestTask.new(:test) do |t|
+desc 'Run all specs'
+Rake::TestTask.new(:spec) do |t|
t.libs << 'lib'
- t.pattern = 'test/*_test.rb'
+ t.pattern = 'spec/**/*_spec.rb'
t.verbose = true
end
View
21 spec/regression/guess_encoding_spec.rb
@@ -0,0 +1,21 @@
+# encoding: utf-8
+
+require File.expand_path('../../start', __FILE__)
+
+describe "Ensure::Encoding, concerning guess_encoding" do
+ it "should guess the first encoding from the list in which the data is valid" do
+ [
+ ['UTF-8', ['ASCII-8BIT', 'UTF-8'], Encoding::ASCII_8BIT],
+ ['UTF-8', ['US-ASCII', 'UTF-8'], Encoding::UTF_8],
+ ['UTF-8', ['ISO-8859-1', 'UTF-8'], Encoding::ISO_8859_1],
+ ['UTF-8', ['US-ASCII', 'US-ASCII'], nil],
+ ['Shift_JIS', ['ASCII-8BIT', 'Shift_JIS'], Encoding::ASCII_8BIT],
+ ['Shift_JIS', ['US-ASCII', 'Shift_JIS'], Encoding::Shift_JIS],
+ ['UTF-16LE', ['UTF-8', 'UTF-16LE'], Encoding::UTF_16LE],
+ ['UTF-16BE', ['UTF-8', 'UTF-16BE'], Encoding::UTF_16BE]
+ ].each do |source, guesses, expected|
+ e, _ = example(source)
+ Ensure::Encoding.guess_encoding(e, guesses).should == expected
+ end
+ end
+end

0 comments on commit bfc9783

Please sign in to comment.
Something went wrong with that request. Please try again.