File: test_node_encoding.rb

package info (click to toggle)
ruby-nokogiri 1.6.3.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,132 kB
  • ctags: 2,605
  • sloc: xml: 26,397; ruby: 14,634; ansic: 4,855; yacc: 244; sh: 122; makefile: 11
file content (27 lines) | stat: -rw-r--r-- 711 bytes parent folder | download | duplicates (4)
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
# -*- coding: utf-8 -*-
require "helper"

module Nokogiri
  module HTML
    if RUBY_VERSION =~ /^1\.9/
      class TestNodeEncoding < Nokogiri::TestCase
        def test_inner_html
          doc = Nokogiri::HTML File.open(SHIFT_JIS_HTML, 'rb')

          hello = "こんにちは"

          contents = doc.at('h2').inner_html
          assert_equal doc.encoding, contents.encoding.name
          assert_match hello.encode('Shift_JIS'), contents

          contents = doc.at('h2').inner_html(:encoding => 'UTF-8')
          assert_match hello, contents

          doc.encoding = 'UTF-8'
          contents = doc.at('h2').inner_html
          assert_match hello, contents
        end
      end
    end
  end
end