File: test_encoding.rb

package info (click to toggle)
libfeedtools-ruby 0.2.29%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,004 kB
  • ctags: 1,385
  • sloc: ruby: 18,815; sql: 39; makefile: 6
file content (35 lines) | stat: -rw-r--r-- 1,066 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require File.join(File.dirname(__FILE__), 'preamble')

require 'html5/inputstream'

class Html5EncodingTestCase < Test::Unit::TestCase
  include HTML5
  include TestSupport

  begin
    require 'rubygems'
    require 'UniversalDetector'

    def test_chardet #TODO: can we get rid of this?
      file = File.open(File.join(TESTDATA_DIR, 'encoding', 'chardet', 'test_big5.txt'), 'r')
      stream = HTML5::HTMLInputStream.new(file, :chardet => true)
      assert_equal 'big5', stream.char_encoding.downcase
    rescue LoadError
      puts "chardet not found, skipping chardet tests"
    end
  end

  html5_test_files('encoding').each do |test_file|        
    test_name = File.basename(test_file).sub('.dat', '').tr('-', '')

    TestData.new(test_file, %w(data encoding)).
      each_with_index do |(input, encoding), index|

      define_method 'test_%s_%d' % [ test_name, index + 1 ] do
        stream = HTML5::HTMLInputStream.new(input, :chardet => false)
        assert_equal encoding.downcase, stream.char_encoding.downcase, input
      end
    end
  end

end