2007-05-26 03:52:27 +02:00
|
|
|
require File.join(File.dirname(__FILE__), 'preamble')
|
|
|
|
|
2007-07-05 00:36:59 +02:00
|
|
|
require 'html5/inputstream'
|
2007-05-26 03:52:27 +02:00
|
|
|
|
|
|
|
class Html5EncodingTestCase < Test::Unit::TestCase
|
2007-07-05 00:36:59 +02:00
|
|
|
include HTML5
|
|
|
|
include TestSupport
|
2007-05-26 03:52:27 +02:00
|
|
|
|
2007-06-05 23:34:49 +02:00
|
|
|
begin
|
2007-05-26 03:52:27 +02:00
|
|
|
require 'rubygems'
|
|
|
|
require 'UniversalDetector'
|
|
|
|
|
2007-09-10 05:26:19 +02:00
|
|
|
def test_chardet #TODO: can we get rid of this?
|
2007-06-12 06:33:06 +02:00
|
|
|
file = File.open(File.join(TESTDATA_DIR, 'encoding', 'chardet', 'test_big5.txt'), 'r')
|
2007-07-05 00:36:59 +02:00
|
|
|
stream = HTML5::HTMLInputStream.new(file, :chardet => true)
|
2007-06-12 06:33:06 +02:00
|
|
|
assert_equal 'big5', stream.char_encoding.downcase
|
|
|
|
rescue LoadError
|
|
|
|
puts "chardet not found, skipping chardet tests"
|
2007-05-26 03:52:27 +02:00
|
|
|
end
|
2007-06-05 23:34:49 +02:00
|
|
|
end
|
2007-05-26 03:52:27 +02:00
|
|
|
|
2007-07-05 00:36:59 +02:00
|
|
|
html5_test_files('encoding').each do |test_file|
|
2007-06-05 23:34:49 +02:00
|
|
|
test_name = File.basename(test_file).sub('.dat', '').tr('-', '')
|
2007-05-26 03:52:27 +02:00
|
|
|
|
2007-07-05 00:36:59 +02:00
|
|
|
TestData.new(test_file, %w(data encoding)).
|
|
|
|
each_with_index do |(input, encoding), index|
|
2007-05-26 03:52:27 +02:00
|
|
|
|
2007-06-05 23:34:49 +02:00
|
|
|
define_method 'test_%s_%d' % [ test_name, index + 1 ] do
|
2007-07-05 00:36:59 +02:00
|
|
|
stream = HTML5::HTMLInputStream.new(input, :chardet => false)
|
2007-06-05 23:34:49 +02:00
|
|
|
assert_equal encoding.downcase, stream.char_encoding.downcase, input
|
|
|
|
end
|
2007-05-26 03:52:27 +02:00
|
|
|
end
|
2007-06-05 23:34:49 +02:00
|
|
|
end
|
2007-05-26 03:52:27 +02:00
|
|
|
|
|
|
|
end
|