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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
# encoding: utf-8
require 'pathname'
require 'kconv'
require(Pathname.new(__FILE__).parent + 'lib/common.rb')
describe 'Internal encoding specification:' do
specify "utf-8 bom check" do
src = '日本語'.kconv(Kconv::SJIS, Kconv::UTF8)
BlueFeather::Util.utf8_bom?(src).should be_falsey
bom_src = "\xef\xbb\xbf日本語"
BlueFeather::Util.utf8_bom?(bom_src).should be_truthy
end
specify "'shift-jis' is available:" do
src = '日本語'.kconv(Kconv::SJIS, Kconv::UTF8)
BlueFeather.parse_document(src, 'shift_jis')
BlueFeather.parse_document(src, 'shift-jis')
end
end
describe 'Encoding of files:' do
before(:each) do
@html = BlueFeather.parse_document_file(Pathname.new(__FILE__).parent + 'text/' + @src_name)
@doc = Nokogiri(@html)
end
shared_context 'base' do
it 'header parse - css' do
@doc.should have_element('link[@rel="stylesheet"][@href="style.css"]')
end
it 'header parse - encoding' do
@doc.should have_element(%Q|meta[@http-equiv="Content-Type"][@content="text/html; charset=#{@charset}"]|)
end
it 'header parse - title' do
base = '日本語の題名'.kconv(@kconv_encoding, Kconv::UTF8)
@doc.at('title').inner_html.should == base
end
it 'content parse - p' do
base = 'このテキストファイルは、エンコーディングテスト用のテキストファイルです。'.kconv(@kconv_encoding, Kconv::UTF8)
@doc.at('p').inner_html.should == base
end
it 'content parse - ul' do
@doc.should have_elements(1, 'ul')
items = @doc.search('ul li')
%w(項目1 項目2 項目3).each_with_index do |str, i|
items[i].inner_html.should == str.kconv(@kconv_encoding, Kconv::UTF8)
end
end
end
describe 'Default:' do
include_context 'base'
before(:all) do
@src_name = 'encoding_sample_default.bfdoc'
@charset = 'utf-8'
@kconv_encoding = Kconv::UTF8
end
end
describe 'UTF-8 (BOM):' do
include_context 'base'
before(:all) do
@src_name = 'encoding_sample_utf-8.bfdoc'
@charset = 'utf-8'
@kconv_encoding = Kconv::UTF8
end
end
describe 'UTF-8N:' do
include_context 'base'
before(:all) do
@src_name = 'encoding_sample_utf-8n.bfdoc'
@charset = 'utf-8'
@kconv_encoding = Kconv::UTF8
end
end
describe 'Shift_JIS:' do
include_context 'base'
before(:all) do
@src_name = 'encoding_sample_shift-jis.bfdoc'
@charset = 'shift_jis'
@kconv_encoding = Kconv::SJIS
end
end
describe 'EUC-JP:' do
include_context 'base'
before(:all) do
@src_name = 'encoding_sample_euc-jp.bfdoc'
@charset = 'euc-jp'
@kconv_encoding = Kconv::EUC
end
end
end
|