File: test-text.rb

package info (click to toggle)
ruby-htree 0.8%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 520 kB
  • sloc: ruby: 5,928; makefile: 23
file content (43 lines) | stat: -rw-r--r-- 959 bytes parent folder | download | duplicates (6)
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
require 'test/unit'
require 'htree/text'

class TestText < Test::Unit::TestCase
  def test_new
    assert_equal("abc&amp;amp;def", HTree::Text.new("abc&amp;def").rcdata)
  end

=begin
  def test_parse
    assert_equal("abc&amp;def", HTree::Text.parse("abc&amp;def").rcdata)
  end

  def test_to_s
    assert_equal("abc&def", HTree::Text.parse("abc&amp;def").to_s)
  end
=end

  def kcode(kc)
    if "".respond_to? :force_encoding
      if HTree::Encoder.internal_charset.start_with?(kc.upcase)
        yield
      end
    else
      old = $KCODE
      begin
        $KCODE = kc
        yield
      ensure
        $KCODE = old
      end
    end
  end

  def test_normalize
    kcode('EUC') {
      expected = "<ABC&#38;&#38;&#160;\xa6\xc1"
      expected.force_encoding("euc-jp") if expected.respond_to? :force_encoding
      assert_equal(expected,
        HTree::Text.new_internal("&lt;&#65;&#x42;C&amp;&#38;&nbsp;&alpha;").normalized_rcdata)
    }
  end
end